mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] hwmon: (adt7475) Add thermal sensor and PWM provider support
@ 2026-11-14  0:41 Davíð Steinn Geirsson
  2026-11-14  0:41 ` [PATCH 1/4] dt-bindings: hwmon: adt7475: Add #thermal-sensor-cells Davíð Steinn Geirsson
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Davíð Steinn Geirsson @ 2026-11-14  0:41 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, linux-hwmon
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	Uwe Kleine-König, linux-pwm, Jonathan Corbet, Shuah Khan,
	Randy Dunlap, linux-doc, linux-kernel,
	Davíð Steinn Geirsson


This series lets boards use the temperature channels of the ADT7473,
ADT7475, ADT7476 and ADT7490 as thermal zone sensors, and drive their
PWM outputs with a PWM consumer such as pwm-fan. The kernel thermal
framework can then control the fans. It follows the ADT7470 series [1],
merged for v7.3.

The board it is for is the Ubiquiti UniFi USW Pro XG 8 PoE, a switch
with a Realtek RTL9313 (MIPS) SoC. Its ADT7475 drives both fans and
reads the CPU and SFP area temperatures. The fans must also follow
eight PHY temperatures that the ADT7475 cannot read, so the chip's
automatic mode does not fit.

Patch 1 adds "#thermal-sensor-cells" to the binding. Patch 2 converts
the driver to hwmon_device_register_with_info(), through which the
hwmon core registers thermal sensors. Patch 3 registers them. Patch 4
registers a PWM chip when the node has "#pwm-cells".

Differences from ADT7470:
- While a PWM consumer holds a channel, writes to that channel's hwmon
  PWM attributes fail with -EBUSY. ADT7470 hides its PWM attributes
  when "#pwm-cells" is present. The ADT7475 binding has documented
  "#pwm-cells" for fan-N children since v6.12, and device trees that
  follow it must keep their attributes. If preferred, the attributes
  could instead be hidden when "#pwm-cells" is present and there are
  no fan-N children.
- The period of each supported frequency is 1 s divided by the
  frequency, rounded down, so the 44444 ns the binding documents
  selects 22.5 kHz exactly. ADT7470 rounds up.
- No warning about "#pwm-cells" without CONFIG_PWM, because fan-N
  children use the property too.

duty_offset_ns is ignored: the chip has no offset, and 0 is the
round-down result for any requested offset.

Testing on hwmon-next, the base of this series:
- checkpatch.pl --strict and dt_binding_check are clean. W=1 builds of
  adt7475.o after each patch, with CONFIG_PWM and CONFIG_THERMAL_OF
  each on and off, give no warnings. sparse reports nothing for
  adt7475.c, and the hwmon htmldocs build gives no warning for
  adt7475.rst.
- x86_64 QEMU guest with i2c-stub, all four chip types, five register
  images each: the attribute list, every value read and written, and
  the final register contents are identical before and after patch 2,
  apart from the two -ERANGE cases its message lists. The same
  comparison between patches 3 and 4, with and without "#pwm-cells"
  and with no PWM consumer, is identical too.
- The same guest with PWM_DEBUG and PROVE_LOCKING runs the PWM sysfs
  interface and pwm-fan as consumers, including unbinding the chip
  under them. No PWM core or lockdep warning.

Testing on hardware, on the switch above running OpenWrt with this
series backported to 6.18. The backported driver differs from this
series only where 6.18 and hwmon-next differ:
- Ten thermal zones (the ADT7475's two remote channels and the eight
  PHYs) drive both fans through pwm-fan at 22.5 kHz. The fan curve
  was stepped through with emul_temp on three zones, and the first
  trip on the other seven; fan state and duty registers matched the
  expected values.
- Unloading and reloading pwm-fan and adt7475: the fans stay at full
  speed while pwm-fan is unloaded, and thermal control resumes after
  the reload.
- Writes to the hwmon attributes of the held channels return -EBUSY
  and leave the registers unchanged; pwm3 stays writable.
The hwmon-next version itself has not run on hardware.

This patch was written with Claude Code, using the models Claude
Opus 5.5 and Claude Fable 5.2. They wrote the code and the initial
commit message draft, which I cleaned up. I directed the design,
reviewed the result, compared against the datasheet as far as I
could, and ran tests including on actual hardware.

Davíð Steinn Geirsson (4):
  dt-bindings: hwmon: adt7475: Add #thermal-sensor-cells
  hwmon: (adt7475) Convert to hwmon_device_register_with_info()
  hwmon: (adt7475) Add thermal zone sensor support
  hwmon: (adt7475) Expose fan control via PWM framework

 .../devicetree/bindings/hwmon/adt7475.yaml    |   16 +
 Documentation/hwmon/adt7475.rst               |   18 +
 drivers/hwmon/adt7475.c                       | 1266 ++++++++++-------
 3 files changed, 809 insertions(+), 491 deletions(-)


base-commit: f9f5501d60c77c71f60bf5b273375e3777d66080
-- 
2.56.0


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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14  0:41 [PATCH 0/4] hwmon: (adt7475) Add thermal sensor and PWM provider support Davíð Steinn Geirsson
2026-11-14  0:41 ` [PATCH 1/4] dt-bindings: hwmon: adt7475: Add #thermal-sensor-cells Davíð Steinn Geirsson
2026-11-14  0:41 ` [PATCH 2/4] hwmon: (adt7475) Convert to hwmon_device_register_with_info() Davíð Steinn Geirsson
2026-11-14  6:07   ` Guenter Roeck
2026-11-14  0:41 ` [PATCH 3/4] hwmon: (adt7475) Add thermal zone sensor support Davíð Steinn Geirsson
2026-11-14  0:41 ` [PATCH 4/4] hwmon: (adt7475) Expose fan control via PWM framework Davíð Steinn Geirsson
2026-11-14  6:10   ` Guenter Roeck
2026-11-14  1:03 ` [PATCH 0/4] hwmon: (adt7475) Add thermal sensor and PWM provider support Guenter Roeck

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

all inboxes | Powered by JetHome®