cros_ec: Add cros_ec_build_info and callback

Wilco does not expose the fw version via the RO or RW version like a
standard CROS EC. Instead we will use the build info.

The function is marked as unused because it will be used in the next cl.

BUG=b:130438917
TEST=mosys ish info on Sarien

Change-Id: I3500b076d0c8ba63a732e0fd4b636a2a92e3f9da
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1625451
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
diff --git a/drivers/google/cros_ec.c b/drivers/google/cros_ec.c
index 16fea43..f0d7434 100644
--- a/drivers/google/cros_ec.c
+++ b/drivers/google/cros_ec.c
@@ -117,6 +117,27 @@
 	return ret;
 }
 
+const char *cros_ec_build_info(struct platform_intf *intf, struct ec_cb *ec)
+{
+	const int max_size = 128;
+	char *ret = mosys_zalloc(max_size);
+	struct cros_ec_priv *priv;
+
+	MOSYS_CHECK(ec && ec->priv);
+	priv = ec->priv;
+
+	MOSYS_CHECK(priv->cmd);
+	if (priv->cmd(intf, ec, EC_CMD_GET_BUILD_INFO, 0, ret, max_size - 1,
+		      NULL, 0)) {
+		free(ret);
+		return NULL;
+	}
+
+	lprintf(LOG_DEBUG, "Build Info: %s\n", ret);
+
+	return ret;
+}
+
 int cros_ec_board_version(struct platform_intf *intf, struct ec_cb *ec)
 {
 	struct cros_ec_priv *priv;
diff --git a/drivers/google/cros_ec_cb.c b/drivers/google/cros_ec_cb.c
index 5bef5e0..e5ac09b 100644
--- a/drivers/google/cros_ec_cb.c
+++ b/drivers/google/cros_ec_cb.c
@@ -84,6 +84,20 @@
 	return version;
 }
 
+__attribute__((unused)) static const char *
+cros_ec_build_info_cb(struct platform_intf *intf, struct ec_cb *ec)
+{
+	static const char *build_info = NULL;
+
+	if (build_info)
+		return build_info;
+
+	build_info = cros_ec_build_info(intf, ec);
+	if (build_info)
+		add_destroy_callback(free, (void *)build_info);
+	return build_info;
+}
+
 struct ec_cb cros_ec_cb = {
 	.vendor		= cros_ec_vendor,
 	.name		= cros_ec_name,
diff --git a/include/drivers/google/cros_ec.h b/include/drivers/google/cros_ec.h
index 79639b7..164c68a 100644
--- a/include/drivers/google/cros_ec.h
+++ b/include/drivers/google/cros_ec.h
@@ -90,6 +90,7 @@
 /* EC commands */
 int cros_ec_hello(struct platform_intf *intf, struct ec_cb *ec);
 const char *cros_ec_version(struct platform_intf *intf, struct ec_cb *ec);
+const char *cros_ec_build_info(struct platform_intf *intf, struct ec_cb *ec);
 int cros_ec_chip_info(struct platform_intf *intf, struct ec_cb *ec,
 		         struct ec_response_get_chip_info *info);
 int cros_ec_flash_info(struct platform_intf *intf, struct ec_cb *ec,