summaryrefslogtreecommitdiffstats
path: root/drivers/platform/chrome
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2024-05-29 08:27:11 +0200
committerTzung-Bi Shih <tzungbi@kernel.org>2024-06-03 03:14:42 +0200
commita14a569a9918a0c7e340257a17dbc088bb27db72 (patch)
tree932f1901daaf478d5951c8b0a197be318e5c1eb5 /drivers/platform/chrome
parentplatform/chrome: cros_ec_debugfs: Make log polling period a parameter (diff)
downloadlinux-a14a569a9918a0c7e340257a17dbc088bb27db72.tar.xz
linux-a14a569a9918a0c7e340257a17dbc088bb27db72.zip
platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem()
To read from the EC memory different mechanism are possible. ECs connected via LPC expose their memory via a ->cmd_readmem operation. Other protocols require the usage of EC_CMD_READ_MEMMAP, which on the other hand is not implemented by LPC ECs. Provide a helper that automatically selects the correct mechanism. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20240529-cros_ec-hwmon-v4-1-5cdf0c5db50a@weissschuh.net Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Diffstat (limited to 'drivers/platform/chrome')
-rw-r--r--drivers/platform/chrome/cros_ec_proto.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index dcfc18fe1cdf..2ad1b8221ec0 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -1033,3 +1033,30 @@ error:
return ret;
}
EXPORT_SYMBOL_GPL(cros_ec_cmd);
+
+/**
+ * cros_ec_cmd_readmem - Read from EC memory.
+ *
+ * @ec_dev: EC device
+ * @offset: Is within EC_LPC_ADDR_MEMMAP region.
+ * @size: Number of bytes to read.
+ * @dest: EC command output data
+ *
+ * Return: >= 0 on success, negative error number on failure.
+ */
+int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest)
+{
+ struct ec_params_read_memmap params = {};
+
+ if (!size)
+ return -EINVAL;
+
+ if (ec_dev->cmd_readmem)
+ return ec_dev->cmd_readmem(ec_dev, offset, size, dest);
+
+ params.offset = offset;
+ params.size = size;
+ return cros_ec_cmd(ec_dev, 0, EC_CMD_READ_MEMMAP,
+ &params, sizeof(params), dest, size);
+}
+EXPORT_SYMBOL_GPL(cros_ec_cmd_readmem);