]> www.infradead.org Git - users/hch/configfs.git/commitdiff
platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem()
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 29 May 2024 06:27:11 +0000 (08:27 +0200)
committerTzung-Bi Shih <tzungbi@kernel.org>
Mon, 3 Jun 2024 01:14:42 +0000 (01:14 +0000)
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>
drivers/platform/chrome/cros_ec_proto.c
include/linux/platform_data/cros_ec_proto.h

index dcfc18fe1cdf78ccffcb841630958d568a1f5fb4..2ad1b8221ec0dc1883ed02dede8a521c7a3ee6f3 100644 (file)
@@ -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);
index 8865e350c12a5f687f1f7dd0f09d96fb8fb22db3..1ddc52603f9ae27bd1d187ae8690ed072285b1b4 100644 (file)
@@ -261,6 +261,8 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec);
 int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command, const void *outdata,
                    size_t outsize, void *indata, size_t insize);
 
+int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest);
+
 /**
  * cros_ec_get_time_ns() - Return time in ns.
  *