Introduce cros_ec power monitoring
v2 cover Introduce cros_ec power monitoring
This series adds the ChromeOS EC On-Device Power Monitoring (cros_ec_pwrmon) driver to read onboard power-monitoring ADCs, such as PAC194x, wired through the embedded controller (EC).
Several ChromeOS platforms are equipped with onboard ADCs connected to the EC via I2C. The driver interfaces with the EC via the existing EC_CMD_PWRMON host command API and EC_MKBP_EVENT_PWRMON events to manage ADC accumulation and expose per-rail accumulated energy through IIO energy channels and a triggered buffer. The driver is only loaded when EC_FEATURE_PWRMON is advertised by the EC.
This is a borderline case between IIO and hwmon. IIO is used rather than hwmon [1] because userspace queries all rails (up to 64) together as a coherent frame -- for example, to compare per-rail drain contributions across device-state transitions (such as screen on/off triggering a snapshot) and to correlate fine-grained ODPM frames with other timestamped system diagnostics for off-device per-process, per-rail energy attribution, where relative deltas across channels are as important as absolute values. Since a single EC latch and MKBP delivery takes non-trivial bus time, latching per sysfs read across 64 files would introduce significant inter-channel skid and redundant EC work. While driver-side caching in hwmon could avoid per-read latching, hwmon has neither an on-demand trigger ABI to force a fresh latch nor a timestamp ABI to report the actual latch time (or expose whether a read hit cached data or crossed a mid-sweep cache expiry), making IIO's explicit trigger, latch timestamp, and single buffer read a cleaner fit.
Reference to detailed v1 discussion:
[1] https://lore.kernel.org/linux-iio/[email protected]/
Changes in v2:
- Dropped v1 patch 1/3 ("platform/chrome: cros_ec: fix alignment of ec_params_pwrmon"), already applied to chrome-platform/for-next (346739bcdf65).
- Replaced custom multi-value energy_value sysfs attribute and its ABI doc with standard buffer-only IIO_ENERGY channels (.read_label, scale) and an IIO triggered buffer with IIO_CHAN_SOFT_TIMESTAMP (CLOCK_BOOTTIME); selected IIO_BUFFER and IIO_TRIGGERED_BUFFER in Kconfig.
- Replaced wait_queue_head_t with struct completion.
- Grouped per-channel state into struct cros_ec_pwrmon_chan, and used aligned_u64 scan buffer.
- Switched EC host commands from legacy cros_ec_cmd_xref_status() to cros_ec_cmd(), which manages msg buffers and cleanup automatically.
- Dropped redundant st->ec and st->msg fields, used local params/resp variables instead of casts.
- Added an event_size check in the MKBP notifier.
- Fixed signed/unsigned energy integration and channel counting for duplicate/out-of-range MKBP events; returned -EINVAL for missing channel labels.
- Switched probe error paths to dev_err_probe(), clamped channel count with min(), hardcoded indio_dev->name to "cros-ec-pwrmon", switched to devm_blocking_notifier_chain_register(), dropped direct <linux/mod_devicetable.h> include, and used named initializer with "{ }" sentinel in cros_ec_pwrmon_id[].
- Capitalized "Load" in the mfd patch subject.
Daniel Balint (2):
iio: adc: add cros_ec_pwrmon driver
mfd: cros_ec: Load cros_ec_pwrmon on supported ECs
MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 13 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/cros_ec_pwrmon.c | 370 +++++++++++++++++++++++++++++++ drivers/mfd/cros_ec_dev.c | 9 + 5 files changed, 400 insertions(+) create mode 100644 drivers/iio/adc/cros_ec_pwrmon.c
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH v2 1/2 iio: adc: add cros_ec_pwrmon driver
Add the ChromeOS EC On-Device Power Monitoring (ODPM) driver to read onboard power-monitoring ADCs (such as PAC194x) wired through the EC.
The driver interfaces with the EC via the existing EC_CMD_PWRMON host command API and EC_MKBP_EVENT_PWRMON events to start/stop accumulation, latch ADC accumulators, and expose cumulative per-rail energy through IIO energy channels and a triggered buffer.
The driver is intentionally buffer-only (no single-shot RAW reads), as EC_PWRMON_LATCH snapshots all rails simultaneously into a timestamped frame.
--- MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 13 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/cros_ec_pwrmon.c | 370 +++++++++++++++++++++++++++++++ 4 files changed, 391 insertions(+) create mode 100644 drivers/iio/adc/cros_ec_pwrmon.c
MAINTAINERS +7 -0
@@ -6335,6 +6335,13 @@ M: Thomas Weißschuh <[email protected]> S: Maintained F: drivers/leds/leds-cros_ec.c +CHROMEOS EC POWER MONITORING +M: Daniel Balint <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: drivers/iio/adc/cros_ec_pwrmon.c + CHROMEOS EC SUBDRIVERS M: Benson Leung <[email protected]> R: Guenter Roeck <[email protected]>
drivers/iio/adc/Kconfig +13 -0
@@ -743,6 +743,19 @@ config CPCAP_ADC This driver can also be built as a module. If so, the module will be called cpcap-adc. +config CROS_EC_PWRMON + tristate "ChromeOS EC Power Monitor Driver" + depends on MFD_CROS_EC_DEV + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + default MFD_CROS_EC_DEV + help + Say yes here to build support for the ChromeOS EC On-Device Power + Monitoring (ODPM) driver. + + To compile this driver as a module, choose M here: the module will be + called cros_ec_pwrmon. + config DA9150_GPADC tristate "Dialog DA9150 GPADC driver support" depends on MFD_DA9150
drivers/iio/adc/Makefile +1 -0
@@ -63,6 +63,7 @@ obj-$(CONFIG_BCM_IPROC_ADC) += bcm_iproc_adc.o obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o obj-$(CONFIG_CPCAP_ADC) += cpcap-adc.o +obj-$(CONFIG_CROS_EC_PWRMON) += cros_ec_pwrmon.o obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o obj-$(CONFIG_DLN2_ADC) += dln2-adc.o obj-$(CONFIG_ENVELOPE_DETECTOR) += envelope-detector.o
drivers/iio/adc/cros_ec_pwrmon.c new file +370 -0
370 lines not on this page · raw message
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH v2 2/2 mfd: cros_ec: Load cros_ec_pwrmon on supported ECs
In reply to Daniel BalintLoad cros_ec_pwrmon driver when the ChromeOS EC advertises EC_FEATURE_PWRMON.
--- drivers/mfd/cros_ec_dev.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/mfd/cros_ec_dev.c +9 -0
@@ -115,6 +115,10 @@ static const struct mfd_cell cros_ec_charge_control_cells[] = { { .name = "cros-charge-control", }, }; +static const struct mfd_cell cros_ec_pwrmon_cells[] = { + { .name ="cros-ec-pwrmon" , }, +}; +static const struct cros_feature_to_cells cros_subdevices[] = { { .id =EC_FEATURE_CEC ,
@@ -151,6 +155,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_ec_charge_control_cells, .num_cells = ARRAY_SIZE(cros_ec_charge_control_cells), }, + { + .id = EC_FEATURE_PWRMON, + .mfd_cells = cros_ec_pwrmon_cells, + .num_cells = ARRAY_SIZE(cros_ec_pwrmon_cells), + }, };static const struct mfd_cell cros_ec_platform_cells[] = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
[email protected]
AI reviewSashiko has reviewed this 2-patch series and found no issues.
Sashiko has reviewed this 2-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]