[PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API

From: Stephen Boyd
Date: Thu Apr 14 2022 - 20:33:03 EST


Add a peripheral charger count API similar to the one implemented in the
ChromeOS PCHG driver so we can use it to decide whether or not to
register the PCHG device in the cros_ec MFD driver.

Cc: Lee Jones <lee.jones@xxxxxxxxxx>
Cc: Daisuke Nojiri <dnojiri@xxxxxxxxxxxx>
Cc: Benson Leung <bleung@xxxxxxxxxxxx>
Cc: Guenter Roeck <groeck@xxxxxxxxxxxx>
Cc: <chrome-platform@xxxxxxxxxxxxxxx>
Signed-off-by: Stephen Boyd <swboyd@xxxxxxxxxxxx>
---
drivers/platform/chrome/cros_ec_proto.c | 31 +++++++++++++++++++++
include/linux/platform_data/cros_ec_proto.h | 1 +
2 files changed, 32 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index c4caf2e2de82..42269703ca6c 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -832,6 +832,37 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
}
EXPORT_SYMBOL_GPL(cros_ec_check_features);

+/**
+ * cros_ec_pchg_port_count() - Return the number of peripheral charger ports.
+ * @ec: EC device.
+ *
+ * Return: Number of peripheral charger ports, or 0 in case of error.
+ */
+unsigned int cros_ec_pchg_port_count(struct cros_ec_dev *ec)
+{
+ struct cros_ec_command *msg;
+ const struct ec_response_pchg_count *rsp;
+ struct cros_ec_device *ec_dev = ec->ec_dev;
+ int ret, count = 0;
+
+ msg = kzalloc(sizeof(*msg) + sizeof(*rsp), GFP_KERNEL);
+ if (!msg)
+ return 0;
+
+ msg->command = EC_CMD_PCHG_COUNT + ec->cmd_offset;
+ msg->insize = sizeof(*rsp);
+
+ ret = cros_ec_cmd_xfer_status(ec_dev, msg);
+ if (ret >= 0) {
+ rsp = (const struct ec_response_pchg_count *)msg->data;
+ count = rsp->port_count;
+ }
+ kfree(msg);
+
+ return count;
+}
+EXPORT_SYMBOL_GPL(cros_ec_pchg_port_count);
+
/**
* cros_ec_get_sensor_count() - Return the number of MEMS sensors supported.
*
diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
index df3c78c92ca2..8f5781bc2d7a 100644
--- a/include/linux/platform_data/cros_ec_proto.h
+++ b/include/linux/platform_data/cros_ec_proto.h
@@ -230,6 +230,7 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
bool cros_ec_check_features(struct cros_ec_dev *ec, int feature);

int cros_ec_get_sensor_count(struct cros_ec_dev *ec);
+unsigned int cros_ec_pchg_port_count(struct cros_ec_dev *ec);

int cros_ec_command(struct cros_ec_device *ec_dev, unsigned int version, int command, void *outdata,
int outsize, void *indata, int insize);
--
https://chromeos.dev