2024-05-29 06:28:11

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v4 0/3] ChromeOS Embedded controller hwmon driver

Add a hwmon driver that reports fan and temperature readings from the
ChromeOS Embedded controller.

There was an earlier effort in 2017 to add such a driver [0], but there
was no followup after v1.
The new driver is complete reimplementation based on newer APIs and with
more features (temp sensor names).

It only works on LPC-connected ECs, as only those implement direct
memory-map access.
For other busses the data would need to be read with a command.
Adding some helpers was discussed in the previous patchset [1].

The EC protocols also support reading and writing fan curves but that is
not implemented.

Tested on a Framework 13 AMD, Firmware 3.05.

[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/

---
Changes in v4:
- Don't try to support variable-length reading in cros_ec_cmd_readmem()
(Tzung-Bi)
- Stylistic changes (Tzung-Bi)
- Return -EOPNOTSUPP from read callbacks by default
- Use nested if-blocks in read callback
- Only allocate priv data after checking thermal version in memmap
- Simplify calling protocol of _read() functions
- Replace cros_ec_hwmon_read_temp_sensor_info() with cros_ec_cmd()
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Drop Mario's Reviewed-by tag, as the code has changed
- Introduce cros_ec_cmd_readmem() for non-LPC compatibility
- Report fault state for fans and temp sensors
- Avoid adding unnecessary space characters to channel label
- Drop thermal_version from priv data
- Read fans during probing only once
- Don't include linux/kernel.h
- Move _read_temp_sensor_info to similar functions
- Insert MFD entry alphabetically
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- drop unnecessary range checks (Guenter)
- only validate thermal_version during probing
- reorder some variable declarations
- validate thermal_version directly in cros_ec_hwmon_probe (Mario)
- drop return value from probe_temp_sensors as it can't fail anymore
- fail with -ENODEV if cmd_readmem is missing to avoid spurious warnings
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Thomas Weißschuh (3):
platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem()
hwmon: add ChromeOS EC driver
mfd: cros_ec: Register hardware monitoring subdevice

Documentation/hwmon/cros_ec_hwmon.rst | 26 +++
Documentation/hwmon/index.rst | 1 +
MAINTAINERS | 8 +
drivers/hwmon/Kconfig | 11 ++
drivers/hwmon/Makefile | 1 +
drivers/hwmon/cros_ec_hwmon.c | 286 ++++++++++++++++++++++++++++
drivers/mfd/cros_ec_dev.c | 1 +
drivers/platform/chrome/cros_ec_proto.c | 27 +++
include/linux/platform_data/cros_ec_proto.h | 2 +
9 files changed, 363 insertions(+)
---
base-commit: 2bfcfd584ff5ccc8bb7acde19b42570414bf880b
change-id: 20240506-cros_ec-hwmon-24634b07cf6f

Best regards,
--
Thomas Weißschuh <[email protected]>



2024-05-29 06:28:15

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v4 1/3] 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]>
---
drivers/platform/chrome/cros_ec_proto.c | 27 +++++++++++++++++++++++++++
include/linux/platform_data/cros_ec_proto.h | 2 ++
2 files changed, 29 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 945b1b15a04c..daddc8731cef 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -1035,3 +1035,30 @@ int cros_ec_cmd(struct cros_ec_device *ec_dev,
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);
diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
index 8865e350c12a..1ddc52603f9a 100644
--- a/include/linux/platform_data/cros_ec_proto.h
+++ b/include/linux/platform_data/cros_ec_proto.h
@@ -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.
*

--
2.45.1


2024-05-31 21:32:15

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem()

On 5/28/24 23:27, Thomas Weißschuh wrote:
> 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]>


Subject: Re: [PATCH v4 0/3] ChromeOS Embedded controller hwmon driver

Hello:

This series was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <[email protected]>:

On Wed, 29 May 2024 08:27:10 +0200 you wrote:
> Add a hwmon driver that reports fan and temperature readings from the
> ChromeOS Embedded controller.
>
> There was an earlier effort in 2017 to add such a driver [0], but there
> was no followup after v1.
> The new driver is complete reimplementation based on newer APIs and with
> more features (temp sensor names).
>
> [...]

Here is the summary with links:
- [v4,1/3] platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem()
https://git.kernel.org/chrome-platform/c/a14a569a9918
- [v4,2/3] hwmon: add ChromeOS EC driver
https://git.kernel.org/chrome-platform/c/e8665a172378
- [v4,3/3] mfd: cros_ec: Register hardware monitoring subdevice
(no matching commit)

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



Subject: Re: [PATCH v4 0/3] ChromeOS Embedded controller hwmon driver

Hello:

This series was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <[email protected]>:

On Wed, 29 May 2024 08:27:10 +0200 you wrote:
> Add a hwmon driver that reports fan and temperature readings from the
> ChromeOS Embedded controller.
>
> There was an earlier effort in 2017 to add such a driver [0], but there
> was no followup after v1.
> The new driver is complete reimplementation based on newer APIs and with
> more features (temp sensor names).
>
> [...]

Here is the summary with links:
- [v4,1/3] platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem()
https://git.kernel.org/chrome-platform/c/a14a569a9918
- [v4,2/3] hwmon: add ChromeOS EC driver
https://git.kernel.org/chrome-platform/c/e8665a172378
- [v4,3/3] mfd: cros_ec: Register hardware monitoring subdevice
(no matching commit)

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html