Skip to content

Commit a14a569

Browse files
t-8chTzung-Bi Shih
authored andcommitted
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 <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent 7b44d53 commit a14a569

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,3 +1033,30 @@ int cros_ec_cmd(struct cros_ec_device *ec_dev,
10331033
return ret;
10341034
}
10351035
EXPORT_SYMBOL_GPL(cros_ec_cmd);
1036+
1037+
/**
1038+
* cros_ec_cmd_readmem - Read from EC memory.
1039+
*
1040+
* @ec_dev: EC device
1041+
* @offset: Is within EC_LPC_ADDR_MEMMAP region.
1042+
* @size: Number of bytes to read.
1043+
* @dest: EC command output data
1044+
*
1045+
* Return: >= 0 on success, negative error number on failure.
1046+
*/
1047+
int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest)
1048+
{
1049+
struct ec_params_read_memmap params = {};
1050+
1051+
if (!size)
1052+
return -EINVAL;
1053+
1054+
if (ec_dev->cmd_readmem)
1055+
return ec_dev->cmd_readmem(ec_dev, offset, size, dest);
1056+
1057+
params.offset = offset;
1058+
params.size = size;
1059+
return cros_ec_cmd(ec_dev, 0, EC_CMD_READ_MEMMAP,
1060+
&params, sizeof(params), dest, size);
1061+
}
1062+
EXPORT_SYMBOL_GPL(cros_ec_cmd_readmem);

include/linux/platform_data/cros_ec_proto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec);
261261
int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command, const void *outdata,
262262
size_t outsize, void *indata, size_t insize);
263263

264+
int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest);
265+
264266
/**
265267
* cros_ec_get_time_ns() - Return time in ns.
266268
*

0 commit comments

Comments
 (0)