Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Introduce cros_ec power monitoring
@ 2026-11-26 10:47 Daniel Balint
  2026-11-26 10:47 ` [PATCH v2 1/2] iio: adc: add cros_ec_pwrmon driver Daniel Balint
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Daniel Balint @ 2026-11-26 10:47 UTC (permalink / raw)
  To: Jonathan Cameron, Lee Jones
  Cc: linux-iio, mfd, linux-hwmon, linux-kernel, mwojtas, Daniel Balint

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/20261120091022.1459658-1-dbalint@google.com/

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
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-26 10:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 10:47 [PATCH v2 0/2] Introduce cros_ec power monitoring Daniel Balint
2026-11-26 10:47 ` [PATCH v2 1/2] iio: adc: add cros_ec_pwrmon driver Daniel Balint
2026-11-26 10:47 ` [PATCH v2 2/2] mfd: cros_ec: Load cros_ec_pwrmon on supported ECs Daniel Balint
2026-11-26 10:59 ` [PATCH v2 0/2] Introduce cros_ec power monitoring sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox