AMD Promontory 21 xHCI temperature sensor support
Subsystems (5)
v4 cover AMD Promontory 21 xHCI temperature sensor support
This series adds temperature monitoring for AMD Promontory 21 (PROM21) xHCI PCI functions.
Patch 1 adds a small PROM21-specific xHCI PCI glue driver. USB host operation is delegated to common xhci-pci code; the PROM21 glue only owns the PCI binding and publishes an auxiliary "hwmon" child device for optional sensor support. The glue is built-in only when enabled, matching built-in xhci-pci, so PROM21 controllers are not left unbound during early boot if an optional module is absent.
Patch 2 adds the auxiliary hwmon driver. It exposes temp1_input as prom21_xhci, does not wake the parent PCI device for sensor reads, and documents the register access and empirical observation method used to identify the register pair and conversion formula.
Changes in v4:
- Move PROM21 PCI handling into a PROM21-specific xHCI PCI glue driver.
- Make USB_XHCI_PCI_PROM21 built-in only when enabled.
- Rename the hwmon driver/config/name to prom21-xhci, SENSORS_PROM21_XHCI, and prom21_xhci.
- Return -ENODATA for suspended parent devices and invalid raw values.
- Remove temp1_label and the runtime PM module parameter.
- Simplify hwmon remove/read lifetime handling.
- Expand hwmon documentation with register access, runtime PM behavior, sysfs lookup, and observation details.
Jihong Min (2):
usb: xhci-pci: add AMD Promontory 21 PCI glue
hwmon: add AMD Promontory 21 xHCI temperature sensor support
Documentation/hwmon/index.rst | 1 + Documentation/hwmon/prom21-xhci.rst | 99 +++++++++++ drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/prom21-xhci.c | 250 ++++++++++++++++++++++++++++ drivers/usb/host/Kconfig | 18 ++ drivers/usb/host/Makefile | 1 + drivers/usb/host/xhci-pci-prom21.c | 111 ++++++++++++ drivers/usb/host/xhci-pci.c | 11 ++ 9 files changed, 502 insertions(+) create mode 100644 Documentation/hwmon/prom21-xhci.rst create mode 100644 drivers/hwmon/prom21-xhci.c create mode 100644 drivers/usb/host/xhci-pci-prom21.c
Signature · 1 line
2.53.0
PATCH v4 1/2 usb: xhci-pci: add AMD Promontory 21 PCI glue
AMD Promontory 21 (PROM21) xHCI controllers use generic xHCI operation, but the PCI function also exposes optional controller-specific sensor functionality. Add a small PROM21 PCI glue driver for AMD 1022:43fd controllers.
The driver delegates USB host operation to the common xhci-pci core and creates a "hwmon" auxiliary device for optional child drivers. Failure to create the auxiliary device is logged but does not fail the xHCI probe, since the auxiliary device is only needed for sensor support.
Keep the PROM21 PCI glue built-in only when enabled because it owns the PCI binding for PROM21 xHCI controllers and must be available whenever the common built-in xhci-pci driver hands those controllers off. This avoids an early boot case where generic xhci-pci rejects a PROM21 controller but a modular xhci-pci-prom21 driver is not available in the initramfs, leaving USB devices behind that controller unavailable.
--- drivers/usb/host/Kconfig | 18 +++++ drivers/usb/host/Makefile | 1 + drivers/usb/host/xhci-pci-prom21.c | 111 +++++++++++++++++++++++++++++ drivers/usb/host/xhci-pci.c | 11 +++ 4 files changed, 141 insertions(+) create mode 100644 drivers/usb/host/xhci-pci-prom21.c
drivers/usb/host/Kconfig +18 -0
@@ -42,6 +42,24 @@ config USB_XHCI_PCI depends on USB_PCI default y +config USB_XHCI_PCI_PROM21 + bool "AMD Promontory 21 xHCI PCI support" + depends on USB_XHCI_PCI=y + select AUXILIARY_BUS + help + Say 'Y' to enable support for the AMD Promontory 21 xHCI PCI + controller with optional sensor support. This driver does not add + PROM21-specific USB or xHCI operation. It binds PROM21 xHCI PCI + functions, delegates USB host operation to the common xHCI PCI core, + and creates auxiliary devices for optional sensor drivers. + + This driver is built-in only because it owns the PCI binding for + PROM21 xHCI controllers when enabled and must be available whenever + the common xHCI PCI driver is available. The optional sensor driver + can still be built as a module. + + If unsure, say 'N'. + config USB_XHCI_PCI_RENESAS tristate "Support for additional Renesas xHCI controller with firmware" depends on USB_XHCI_PCI
drivers/usb/host/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o obj-$(CONFIG_USB_FHCI_HCD) += fhci.o obj-$(CONFIG_USB_XHCI_HCD) += xhci-hcd.o obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o +obj-$(CONFIG_USB_XHCI_PCI_PROM21) += xhci-pci-prom21.o obj-$(CONFIG_USB_XHCI_PCI_RENESAS) += xhci-pci-renesas.o obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o obj-$(CONFIG_USB_XHCI_HISTB) += xhci-histb.o
drivers/usb/host/xhci-pci-prom21.c new file +111 -0
111 lines not on this page · raw message
drivers/usb/host/xhci-pci.c +11 -0
@@ -84,6 +84,7 @@#define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba#define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb#define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc +#define PCI_DEVICE_ID_AMD_PROM21_XHCI 0x43fd#define PCI_DEVICE_ID_ATI_NAVI10_7316_XHCI 0x7316
@@ -696,12 +697,22 @@ static const struct pci_device_id pci_ids_renesas[] = { {/* end: all zeroes */ } }; +/* handled by xhci-pci-prom21 if enabled */ +static const struct pci_device_id pci_ids_prom21[] = { + {PCI_DEVICE (PCI_VENDOR_ID_AMD ,PCI_DEVICE_ID_AMD_PROM21_XHCI ) }, + {/* end: all zeroes */ } +}; +static int xhci_pci_probe (struct pci_dev *dev,const struct pci_device_id *id) {if (IS_ENABLED (CONFIG_USB_XHCI_PCI_RENESAS ) &&pci_match_id (pci_ids_renesas, dev))return -ENODEV ; +if (IS_ENABLED (CONFIG_USB_XHCI_PCI_PROM21 ) && +pci_match_id (pci_ids_prom21, dev)) +return -ENODEV ; +return xhci_pci_common_probe (dev, id); }
Signature · 1 line
2.53.0
PATCH v4 2/2 hwmon: add AMD Promontory 21 xHCI temperature sensor support
In reply to Jihong MinAdd an auxiliary-bus hwmon driver for the temperature sensor exposed by AMD Promontory 21 (PROM21) xHCI PCI functions. The driver binds to the "hwmon" auxiliary device published by the PROM21 xHCI PCI glue and exposes the sensor as temp1_input under the prom21_xhci hwmon device.
The sensor is accessed through a PROM21 vendor index/data register pair in the xHCI PCI MMIO BAR. The read path restores the previous vendor index value after sampling and does not runtime-resume the parent PCI device; reads from a suspended parent return -ENODATA.
Document the supported device, register access, runtime PM behavior, and sysfs lookup method. The documentation also records the observation method used to identify the register pair and derive the conversion formula.
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/prom21-xhci.rst | 99 +++++++++++ drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/prom21-xhci.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 361 insertions(+) create mode 100644 Documentation/hwmon/prom21-xhci.rst create mode 100644 drivers/hwmon/prom21-xhci.c
Documentation/hwmon/index.rst +1 -0
@@ -216,6 +216,7 @@ Hardware Monitoring Kernel Drivers pmbus powerz powr1220 + prom21-xhci pt5161l pxe1610 pwm-fan
Documentation/hwmon/prom21-xhci.rst new file +99 -0
99 lines not on this page · raw message
drivers/hwmon/Kconfig +10 -0
@@ -951,6 +951,16 @@ config SENSORS_POWR1220 This driver can also be built as a module. If so, the module will be called powr1220. +config SENSORS_PROM21_XHCI + tristate "AMD Promontory 21 xHCI temperature sensor" + depends on USB_XHCI_PCI_PROM21 + help + If you say yes here you get support for the AMD Promontory 21 + (PROM21) xHCI temperature sensor. + + This driver can also be built as a module. If so, the module + will be called prom21-xhci. + config SENSORS_LAN966X tristate "Microchip LAN966x Hardware Monitoring" depends on SOC_LAN966 || COMPILE_TEST
drivers/hwmon/Makefile +1 -0
@@ -196,6 +196,7 @@ obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_POWERZ) += powerz.o obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o +obj-$(CONFIG_SENSORS_PROM21_XHCI) += prom21-xhci.o obj-$(CONFIG_SENSORS_PT5161L) += pt5161l.o obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o obj-$(CONFIG_SENSORS_QNAP_MCU_HWMON) += qnap-mcu-hwmon.o
drivers/hwmon/prom21-xhci.c new file +250 -0
250 lines not on this page · raw message
Signature · 1 line
2.53.0
Guenter Roeck
maintainerRe: [PATCH v4 2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor support
Quoted 86 lines · Jihong Min
Add an auxiliary-bus hwmon driver for the temperature sensor exposed by AMD Promontory 21 (PROM21) xHCI PCI functions. The driver binds to the "hwmon" auxiliary device published by the PROM21 xHCI PCI glue and exposes the sensor as
temp1_inputunder theprom21_xhcihwmon device.The sensor is accessed through a PROM21 vendor index/data register pair in the xHCI PCI MMIO BAR. The read path restores the previous vendor index value after sampling and does not runtime-resume the parent PCI device; reads from a suspended parent return
-ENODATA.Document the supported device, register access, runtime PM behavior, and sysfs lookup method. The documentation also records the observation method used to identify the register pair and derive the conversion formula.
Assisted-by Codex:gpt-5.5Signed-off-by Jihong Min <[email protected]>--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/prom21-xhci.rst | 99 +++++++++++ drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/prom21-xhci.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 361 insertions(+)create mode 100644
Documentation/hwmon/prom21-xhci.rstcreate mode 100644drivers/hwmon/prom21-xhci.cDocumentation/hwmon/index.rst +1
-0@@ -216,6 +216,7 @@ Hardware Monitoring Kernel Drivers pmbus powerz powr1220 + prom21-xhci pt5161l pxe1610 pwm-fanDocumentation/hwmon/prom21-xhci.rst new file +41
-0@@ -0,0 +1,99 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver prom21-xhci +========================= + +Supported chips: + + * AMD Promontory 21 (PROM21) xHCI + + Prefix: 'prom21_xhci' + + PCI ID: 1022:43fd + +Author: + + - Jihong Min <[email protected]> + +Description +----------- + +This driver exposes the temperature sensor in AMD PROM21 xHCI controllers. + +The driver binds to an auxiliary device created by the xHCI PCI driver for +supported controllers. The sensor value is accessed through a vendor-specific +index/data register pair in the controller's PCI MMIO BAR. +The auxiliary device is created by the ``xhci-pci-prom21`` PCI glue driver. +USB host operation is otherwise delegated to the common ``xhci-pci`` code. + +PROM21 is an AMD chipset IP used in single-chip or daisy-chained configurations +to build AMD 6xx/8xx series chipsets. Since the xHCI controllers are +integrated in PROM21, this temperature can also be used as a monitor for a +temperature close to the AMD chipset temperature. + +Register access +--------------- + +The temperature value is read through a vendor-specific index/data register +pair in the xHCI PCI MMIO BAR. The driver uses the following byte offsets from +the MMIO BAR base: + +======================= =====================================================
Documentation/hwmon/prom21-xhci.rst line 51
Quoted 10 lines
Documentation/hwmon/prom21-xhci.rst new file +10
-0+0x3000 Vendor index register +0x3008 Vendor data register +======================= ===================================================== + +The driver saves the current vendor index register value, writes the +temperature selector ``0x0001e520`` to the vendor index register, reads the +vendor data register, and restores the previous vendor index value before +returning. The raw temperature value is the low 8 bits of the vendor data +register value. +
I am a bis concerned about this. Any mutex protection only applies to this driver, but not to any other drivers or ACPI code accessing the vendor registers. What if ACPI reads from the same register set ?
Quoted 37 lines
Documentation/hwmon/prom21-xhci.rst new file +37
-0+No public AMD reference is available for the register pair or the raw value. +The register pair was identified on an X870E system with two PROM21 xHCI +controllers. One controller was passed through to a Windows VM, and the same +controller's PCI MMIO BAR was observed from the Linux host while HWiNFO64 was +reporting the PROM21 xHCI temperature. In the test environment, the reported +temperature was very stable at idle and the displayed sensor resolution was +low, which made it possible to look for a consistently repeating MMIO response +for the same reported temperature. During observation, offset 0x3000 repeatedly +contained selector ``0x0001e520``. Writing the same selector to offset 0x3000 +from Linux and then reading offset 0x3008 reproduced the same raw value, so the +offsets are treated as a vendor index/data register pair. + +The conversion formula was empirically inferred by matching observed raw +8-bit values against HWiNFO64's reported PROM21 xHCI temperature for the same +controller. The observed mapping is: + + temp[C] = raw * 0.9066 - 78.624 + +Runtime PM +---------- + +The driver does not wake the xHCI PCI device for hwmon reads. It reads the +temperature only when the parent device is already active. A read from a +suspended device returns ``-ENODATA``. Sensor reads do not mark the xHCI PCI +device as busy or schedule autosuspend, so polling the sensor does not delay +runtime suspend. + +Sysfs entries +------------- + +======================= ===================================================== +temp1_input Temperature in millidegrees Celsius +======================= ===================================================== + +The hwmon device name is ``prom21_xhci``. The sysfs path depends on the hwmon +device number assigned by the kernel. Userspace can locate the device by +matching the ``name`` attribute:
Documentation/hwmon/prom21-xhci.rst
Quoted 10 lines
Documentation/hwmon/prom21-xhci.rst new file +10
-0+ +.. code-block:: sh + + for hwmon in /sys/class/hwmon/hwmon*; do + [ "$(cat "$hwmon/name")" = "prom21_xhci" ] || continue + cat "$hwmon/temp1_input" + done + +``temp1_input`` reports millidegrees Celsius, so a value of ``50113`` means +50.113 degrees Celsius.
The above reflects the hardware monitoring ABI and is pointless to repeat here. Please drop.
If the raw register value is invalid, ``temp1_input``
Quoted 47 lines
Documentation/hwmon/prom21-xhci.rst new file +1
-0+returns ``-ENODATA``.drivers/hwmon/Kconfig +10
-0@@ -951,6 +951,16 @@ config SENSORS_POWR1220 This driver can also be built as a module. If so, the module will be called powr1220. +config SENSORS_PROM21_XHCI + tristate "AMD Promontory 21 xHCI temperature sensor" + depends on USB_XHCI_PCI_PROM21 + help + If you say yes here you get support for the AMD Promontory 21 + (PROM21) xHCI temperature sensor. + + This driver can also be built as a module. If so, the module + will be called prom21-xhci. + config SENSORS_LAN966X tristate "Microchip LAN966x Hardware Monitoring" depends on SOC_LAN966 || COMPILE_TESTdrivers/hwmon/Makefile +1
-0@@ -196,6 +196,7 @@ obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_POWERZ) += powerz.o obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o +obj-$(CONFIG_SENSORS_PROM21_XHCI) += prom21-xhci.o obj-$(CONFIG_SENSORS_PT5161L) += pt5161l.o obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o obj-$(CONFIG_SENSORS_QNAP_MCU_HWMON) += qnap-mcu-hwmon.odrivers/hwmon/prom21-xhci.c new file +7
-0@@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* AMD Promontory 21 xHCI Hwmon Implementation +* (only temperature monitoring is supported) +* +* This can be effectively used as the alternative chipset temperature monitor. +*
drivers/hwmon/prom21-xhci.c line 17
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+* Copyright (C) 2026 Jihong Min <[email protected]> +*/ + +#include <linux/auxiliary_bus.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/hwmon.h> +#include <linux/io.h> +#include <linux/math.h>
Is this needed ?
drivers/hwmon/prom21-xhci.c line 28
Quoted 11 lines
drivers/hwmon/prom21-xhci.c new file +11
-0+#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/pm_runtime.h> +#include <linux/slab.h> +#include <linux/usb.h> +#include <linux/usb/hcd.h> + +#define PROM21_INDEX 0x3000 +#define PROM21_DATA 0x3008 +#define PROM21_TEMP_REG 0x0001e520
Please use
#define<space>NAME<tab>value
and align the value column.
drivers/hwmon/prom21-xhci.c line 34
Quoted 6 lines
drivers/hwmon/prom21-xhci.c new file +6
-0+ +struct prom21_xhci { +struct pci_dev *pdev; +struct device *hwmon_dev; +void __iomem *regs; +struct mutex lock;/* serializes index/data register access */
Why is this lock still needed on top of the hwmon subsystem lock ?
Quoted 83 lines
drivers/hwmon/prom21-xhci.c new file +83
-0+}; + +static int prom21_xhci_pm_get (struct prom21_xhci *hwmon,bool *pm_ref) +{ +struct device *dev = &hwmon->pdev->dev; +int ret; + + *pm_ref = false; + +/* +* PROM21 temperature register access does not return a valid value while +* the parent xHCI PCI function is suspended. Do not wake the device from +* a hwmon read; only read when runtime PM reports the device as active, +* or when runtime PM is disabled and the device is not marked as +* suspended. +*/ + ret =pm_runtime_get_if_active (dev); +if (ret >0 ) { + *pm_ref = true; +return 0 ; + } + +if (ret == -EINVAL && !pm_runtime_status_suspended (dev)) +return 0 ; + +if (!ret ||pm_runtime_status_suspended (dev)) +return -ENODATA ; + +return ret; +} + +/* +* This is not a pure MMIO read. The PROM21 vendor data register is selected +* by temporarily writing PROM21_TEMP_REG to the vendor index register. +* Serialize the sequence, keep it short, and restore the previous index before +* returning so this driver does not leave the vendor index/data register pair +* in a different state for other possible users. +*/ +static int prom21_xhci_read_temp_raw_restore_index (struct prom21_xhci *hwmon, +u8 *raw) +{ +struct device *dev = &hwmon->pdev->dev; +bool pm_ref; +u32 index; +u32 data; +int ret; + + ret =prom21_xhci_pm_get (hwmon, &pm_ref); +if (ret) +return ret; + +mutex_lock (&hwmon->lock); + index =readl (hwmon->regs +PROM21_INDEX ); +/* Select the PROM21 temperature register through the vendor index. */ +writel (PROM21_TEMP_REG , hwmon->regs +PROM21_INDEX ); + data =readl (hwmon->regs +PROM21_DATA ); +/* Restore the previous vendor index register value. */ +writel (index, hwmon->regs +PROM21_INDEX ); +readl (hwmon->regs +PROM21_INDEX ); +mutex_unlock (&hwmon->lock); + +if (pm_ref) { +/* +* Drop only the reference taken by pm_runtime_get_if_active(). +* Do not mark the device busy or schedule autosuspend from the +* hwmon path; sensor polling must not keep the xHCI PCI device +* active. +*/ +pm_runtime_put_noidle (dev); + } + + *raw = data &0xff ; +if (!*raw || *raw ==0xff ) +return -ENODATA ; + +return 0 ; +} + +static long prom21_xhci_raw_to_millicelsius (u8 raw) +{ +/* +* No public AMD reference is available for this value. +* The scale was derived from observed PROM21 xHCI temperature readings:
drivers/hwmon/prom21-xhci.c line 127
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+* temp[C] = raw * 0.9066 - 78.624 +*/ +return DIV_ROUND_CLOSEST (raw *9066 ,10 ) -78624 ; +} + +static umode_t prom21_xhci_is_visible (const void *drvdata, +enum hwmon_sensor_types type,u32 attr, +int channel) +{ +if (type != hwmon_temp || channel)
Drop as unnecessary.
Quoted 9 lines
drivers/hwmon/prom21-xhci.c new file +9
-0+return 0 ; + +switch (attr) { +case hwmon_temp_input: +return 0444 ; +default : +return 0 ; + } +}
drivers/hwmon/prom21-xhci.c line 146
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+ +static int prom21_xhci_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct prom21_xhci *hwmon =dev_get_drvdata (dev); +u8 raw; +int ret; + +if (type != hwmon_temp || attr != hwmon_temp_input || channel) +return -EOPNOTSUPP ;
I am ok with the type and attr checks, but the channel check is really unnecessary. Please drop.
Quoted 26 lines
drivers/hwmon/prom21-xhci.c new file +26
-0+ + ret =prom21_xhci_read_temp_raw_restore_index (hwmon, &raw); +if (ret) +return ret; + + *val =prom21_xhci_raw_to_millicelsius (raw); +return 0 ; +} + +static const struct hwmon_ops prom21_xhci_ops = { + .is_visible = prom21_xhci_is_visible, + .read = prom21_xhci_read, +}; + +static const struct hwmon_channel_info *const prom21_xhci_info[] = { +HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT ), +NULL , +}; + +static const struct hwmon_chip_info prom21_xhci_chip_info = { + .ops = &prom21_xhci_ops, + .info = prom21_xhci_info, +}; + +static int prom21_xhci_probe (struct auxiliary_device *auxdev, +const struct auxiliary_device_id *id)
drivers/hwmon/prom21-xhci.c line 182
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+{ +struct device *dev = &auxdev->dev; +struct device *parent = dev->parent; +struct prom21_xhci *hwmon; +struct pci_dev *pdev; +struct usb_hcd *hcd; +int ret; + +if (!parent || !dev_is_pci (parent)) +return -ENODEV ;
How would this ever happen ?
drivers/hwmon/prom21-xhci.c line 192
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+ + pdev =to_pci_dev (parent); + hcd =pci_get_drvdata (pdev); +if (!hcd) +return dev_err_probe (dev, -ENODEV , +"xHCI HCD data unavailable\n" ); + +if (!hcd->regs || hcd->rsrc_len <PROM21_DATA +sizeof (u32)) +return dev_err_probe (dev, -ENODEV ,"invalid MMIO resource\n" ); +
Isn't that a bit fragile ? Can a driver like this really make assumptions about the contents of struct usb_hcd and the content of the parent's driver data ?
Quoted 8 lines
drivers/hwmon/prom21-xhci.c new file +8
-0+ hwmon =devm_kzalloc (dev,sizeof (*hwmon),GFP_KERNEL ); +if (!hwmon) +return -ENOMEM ; + + ret =devm_mutex_init (dev, &hwmon->lock); +if (ret) +return ret; +
drivers/hwmon/prom21-xhci.c line 210
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+ hwmon->pdev = pdev; + hwmon->regs = hcd->regs; +auxiliary_set_drvdata (auxdev, hwmon); + +/* +* Use the PCI function as the hwmon parent so user space reports it as +* a PCI adapter. Lifetime is still owned by this auxiliary driver; +* remove() unregisters the hwmon device before xhci-pci tears down the +* HCD. +*/
I am sure I understand the reasoning here. What is the problem if it is attached to the auxiliary device ? Other drivers do that, so I don't immediate see why that would be a problem here.
Quoted 40 lines
drivers/hwmon/prom21-xhci.c new file +40
-0+ hwmon->hwmon_dev = +hwmon_device_register_with_info (&pdev->dev,"prom21_xhci" , + hwmon, &prom21_xhci_chip_info, +NULL ); +if (IS_ERR (hwmon->hwmon_dev)) +return PTR_ERR (hwmon->hwmon_dev); + +return 0 ; +} + +static void prom21_xhci_remove (struct auxiliary_device *auxdev) +{ +struct prom21_xhci *hwmon =auxiliary_get_drvdata (auxdev); + +/* +* The PROM21 PCI glue destroys the auxiliary device before HCD teardown. +* Unregister the hwmon device here so sysfs removes the attributes, +* stops new reads, and drains active hwmon callbacks before the xHCI +* MMIO mapping is released. +*/ +hwmon_device_unregister (hwmon->hwmon_dev); +} + +static const struct auxiliary_device_id prom21_xhci_id_table[] = { + { .name ="xhci_pci_prom21.hwmon" }, + {} +}; +MODULE_DEVICE_TABLE (auxiliary, prom21_xhci_id_table); + +static struct auxiliary_driver prom21_xhci_driver = { + .name ="prom21-xhci" , + .probe = prom21_xhci_probe, + .remove = prom21_xhci_remove, + .id_table = prom21_xhci_id_table, +}; +module_auxiliary_driver (prom21_xhci_driver); + +MODULE_AUTHOR ("Jihong Min <[email protected]>" ); +MODULE_DESCRIPTION ("AMD Promontory 21 xHCI temperature sensor driver" ); +MODULE_LICENSE ("GPL" );
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
In reply to Jihong MinQuoted 190 lines · Jihong Min
AMD Promontory 21 (PROM21) xHCI controllers use generic xHCI operation, but the PCI function also exposes optional controller-specific sensor functionality. Add a small PROM21 PCI glue driver for AMD 1022:43fd controllers.
The driver delegates USB host operation to the common xhci-pci core and creates a "hwmon" auxiliary device for optional child drivers. Failure to create the auxiliary device is logged but does not fail the xHCI probe, since the auxiliary device is only needed for sensor support.
Keep the PROM21 PCI glue built-in only when enabled because it owns the PCI binding for PROM21 xHCI controllers and must be available whenever the common built-in xhci-pci driver hands those controllers off. This avoids an early boot case where generic xhci-pci rejects a PROM21 controller but a modular xhci-pci-prom21 driver is not available in the initramfs, leaving USB devices behind that controller unavailable.
Assisted-by Codex:gpt-5.5Signed-off-by Jihong Min <[email protected]>--- drivers/usb/host/Kconfig | 18 +++++ drivers/usb/host/Makefile | 1 + drivers/usb/host/xhci-pci-prom21.c | 111 +++++++++++++++++++++++++++++ drivers/usb/host/xhci-pci.c | 11 +++ 4 files changed, 141 insertions(+)create mode 100644
drivers/usb/host/xhci-pci-prom21.cdrivers/usb/host/Kconfig +18
-0@@ -42,6 +42,24 @@ config USB_XHCI_PCI depends on USB_PCI default y +config USB_XHCI_PCI_PROM21 + bool "AMD Promontory 21 xHCI PCI support" + depends on USB_XHCI_PCI=y + select AUXILIARY_BUS + help + Say 'Y' to enable support for the AMD Promontory 21 xHCI PCI + controller with optional sensor support. This driver does not add + PROM21-specific USB or xHCI operation. It binds PROM21 xHCI PCI + functions, delegates USB host operation to the common xHCI PCI core, + and creates auxiliary devices for optional sensor drivers. + + This driver is built-in only because it owns the PCI binding for + PROM21 xHCI controllers when enabled and must be available whenever + the common xHCI PCI driver is available. The optional sensor driver + can still be built as a module. + + If unsure, say 'N'. + config USB_XHCI_PCI_RENESAS tristate "Support for additional Renesas xHCI controller with firmware" depends on USB_XHCI_PCIdrivers/usb/host/Makefile +1
-0@@ -71,6 +71,7 @@ obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o obj-$(CONFIG_USB_FHCI_HCD) += fhci.o obj-$(CONFIG_USB_XHCI_HCD) += xhci-hcd.o obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o +obj-$(CONFIG_USB_XHCI_PCI_PROM21) += xhci-pci-prom21.o obj-$(CONFIG_USB_XHCI_PCI_RENESAS) += xhci-pci-renesas.o obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o obj-$(CONFIG_USB_XHCI_HISTB) += xhci-histb.odrivers/usb/host/xhci-pci-prom21.c new file +111
-0@@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* AMD Promontory 21 xHCI host controller PCI Bus Glue. +* +* This does not add any PROM21-specific USB or xHCI operation. It exists only +* to publish an auxiliary device for integrated temperature sensor support. +* +* Copyright (C) 2026 Jihong Min <[email protected]> +*/ + +#include <linux/auxiliary_bus.h> +#include <linux/device/devres.h> +#include <linux/errno.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/slab.h> +#include <linux/usb.h> +#include <linux/usb/hcd.h> + +#include "xhci-pci.h" + +struct prom21_xhci_auxdev { +struct auxiliary_device *auxdev; +}; + +static void prom21_xhci_auxdev_release (struct device *dev,void *res) +{ +struct prom21_xhci_auxdev *prom21_auxdev = res; + +auxiliary_device_destroy (prom21_auxdev->auxdev); +} + +static int prom21_xhci_create_auxdev (struct pci_dev *pdev) +{ +struct prom21_xhci_auxdev *prom21_auxdev; + + prom21_auxdev =devres_alloc (prom21_xhci_auxdev_release, +sizeof (*prom21_auxdev),GFP_KERNEL ); +if (!prom21_auxdev) +return -ENOMEM ; + + prom21_auxdev->auxdev = +auxiliary_device_create (&pdev->dev,KBUILD_MODNAME ,"hwmon" , +NULL , (pci_domain_nr (pdev->bus) <<16 ) | +pci_dev_id (pdev)); +if (!prom21_auxdev->auxdev) { +devres_free (prom21_auxdev); +return -ENOMEM ; + } + +devres_add (&pdev->dev, prom21_auxdev); +return 0 ; +} + +static void prom21_xhci_destroy_auxdev (struct pci_dev *pdev) +{ +devres_release (&pdev->dev, prom21_xhci_auxdev_release,NULL ,NULL ); +} + +static int prom21_xhci_probe (struct pci_dev *dev, +const struct pci_device_id *id) +{ +int retval; + + retval =xhci_pci_common_probe (dev, id); +if (retval) +return retval; + + retval =prom21_xhci_create_auxdev (dev); +if (retval) { +/* +* The auxiliary device only provides optional temperature sensor +* support. Keep the xHCI controller usable if it fails. +*/ +dev_err (&dev->dev, +"failed to create PROM21 hwmon auxiliary device: %d\n" , + retval); + } + +return 0 ; +} + +static void prom21_xhci_remove (struct pci_dev *dev) +{ +prom21_xhci_destroy_auxdev (dev); +xhci_pci_remove (dev); +} + +static const struct pci_device_id pci_ids[] = { + {PCI_DEVICE (PCI_VENDOR_ID_AMD ,0x43fd ) },/* PROM21 xHCI */ + {/* end: all zeroes */ } +}; +MODULE_DEVICE_TABLE (pci, pci_ids); + +static struct pci_driver prom21_xhci_driver = { + .name ="xhci-pci-prom21" , + .id_table = pci_ids, + + .probe = prom21_xhci_probe, + .remove = prom21_xhci_remove, + + .shutdown = usb_hcd_pci_shutdown, + .driver = { + .pm =pm_ptr (&usb_hcd_pci_pm_ops), + }, +}; +module_pci_driver (prom21_xhci_driver); + +MODULE_DESCRIPTION ("AMD Promontory 21 xHCI PCI Host Controller Driver" ); +MODULE_IMPORT_NS ("xhci" ); +MODULE_LICENSE ("GPL" );drivers/usb/host/xhci-pci.c +0
-0
drivers/usb/host/xhci-pci.c line 87
Quoted 4 lines
drivers/usb/host/xhci-pci.c +1
-0@@ -84,6 +84,7 @@#define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba#define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb#define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc +#define PCI_DEVICE_ID_AMD_PROM21_XHCI 0x43fd
This define should be in a common header used by xhci-pci.c and xhci-pci-prom21.c both.
Quoted 26 lines
drivers/usb/host/xhci-pci.c +10
-0#define PCI_DEVICE_ID_ATI_NAVI10_7316_XHCI 0x7316@@ -696,12 +697,22 @@ static const struct pci_device_id pci_ids_renesas[] = { {/* end: all zeroes */ } }; +/* handled by xhci-pci-prom21 if enabled */ +static const struct pci_device_id pci_ids_prom21[] = { + {PCI_DEVICE (PCI_VENDOR_ID_AMD ,PCI_DEVICE_ID_AMD_PROM21_XHCI ) }, + {/* end: all zeroes */ } +}; +static int xhci_pci_probe (struct pci_dev *dev,const struct pci_device_id *id) {if (IS_ENABLED (CONFIG_USB_XHCI_PCI_RENESAS ) &&pci_match_id (pci_ids_renesas, dev))return -ENODEV ; +if (IS_ENABLED (CONFIG_USB_XHCI_PCI_PROM21 ) && +pci_match_id (pci_ids_prom21, dev)) +return -ENODEV ; +return xhci_pci_common_probe (dev, id); }
Re: [PATCH v4 2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor support
In reply to Jihong MinQuoted 257 lines · Jihong Min
Add an auxiliary-bus hwmon driver for the temperature sensor exposed by AMD Promontory 21 (PROM21) xHCI PCI functions. The driver binds to the "hwmon" auxiliary device published by the PROM21 xHCI PCI glue and exposes the sensor as
temp1_inputunder theprom21_xhcihwmon device.The sensor is accessed through a PROM21 vendor index/data register pair in the xHCI PCI MMIO BAR. The read path restores the previous vendor index value after sampling and does not runtime-resume the parent PCI device; reads from a suspended parent return
-ENODATA.Document the supported device, register access, runtime PM behavior, and sysfs lookup method. The documentation also records the observation method used to identify the register pair and derive the conversion formula.
Assisted-by Codex:gpt-5.5Signed-off-by Jihong Min <[email protected]>--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/prom21-xhci.rst | 99 +++++++++++ drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/prom21-xhci.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 361 insertions(+)create mode 100644
Documentation/hwmon/prom21-xhci.rstcreate mode 100644drivers/hwmon/prom21-xhci.cDocumentation/hwmon/index.rst +1
-0@@ -216,6 +216,7 @@ Hardware Monitoring Kernel Drivers pmbus powerz powr1220 + prom21-xhci pt5161l pxe1610 pwm-fanDocumentation/hwmon/prom21-xhci.rst new file +99
-0@@ -0,0 +1,99 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver prom21-xhci +========================= + +Supported chips: + + * AMD Promontory 21 (PROM21) xHCI + + Prefix: 'prom21_xhci' + + PCI ID: 1022:43fd + +Author: + + - Jihong Min <[email protected]> + +Description +----------- + +This driver exposes the temperature sensor in AMD PROM21 xHCI controllers. + +The driver binds to an auxiliary device created by the xHCI PCI driver for +supported controllers. The sensor value is accessed through a vendor-specific +index/data register pair in the controller's PCI MMIO BAR. +The auxiliary device is created by the ``xhci-pci-prom21`` PCI glue driver. +USB host operation is otherwise delegated to the common ``xhci-pci`` code. + +PROM21 is an AMD chipset IP used in single-chip or daisy-chained configurations +to build AMD 6xx/8xx series chipsets. Since the xHCI controllers are +integrated in PROM21, this temperature can also be used as a monitor for a +temperature close to the AMD chipset temperature. + +Register access +--------------- + +The temperature value is read through a vendor-specific index/data register +pair in the xHCI PCI MMIO BAR. The driver uses the following byte offsets from +the MMIO BAR base: + +======================= ===================================================== +0x3000 Vendor index register +0x3008 Vendor data register +======================= ===================================================== + +The driver saves the current vendor index register value, writes the +temperature selector ``0x0001e520`` to the vendor index register, reads the +vendor data register, and restores the previous vendor index value before +returning. The raw temperature value is the low 8 bits of the vendor data +register value. + +No public AMD reference is available for the register pair or the raw value. +The register pair was identified on an X870E system with two PROM21 xHCI +controllers. One controller was passed through to a Windows VM, and the same +controller's PCI MMIO BAR was observed from the Linux host while HWiNFO64 was +reporting the PROM21 xHCI temperature. In the test environment, the reported +temperature was very stable at idle and the displayed sensor resolution was +low, which made it possible to look for a consistently repeating MMIO response +for the same reported temperature. During observation, offset 0x3000 repeatedly +contained selector ``0x0001e520``. Writing the same selector to offset 0x3000 +from Linux and then reading offset 0x3008 reproduced the same raw value, so the +offsets are treated as a vendor index/data register pair. + +The conversion formula was empirically inferred by matching observed raw +8-bit values against HWiNFO64's reported PROM21 xHCI temperature for the same +controller. The observed mapping is: + + temp[C] = raw * 0.9066 - 78.624 + +Runtime PM +---------- + +The driver does not wake the xHCI PCI device for hwmon reads. It reads the +temperature only when the parent device is already active. A read from a +suspended device returns ``-ENODATA``. Sensor reads do not mark the xHCI PCI +device as busy or schedule autosuspend, so polling the sensor does not delay +runtime suspend. + +Sysfs entries +------------- + +======================= ===================================================== +temp1_input Temperature in millidegrees Celsius +======================= ===================================================== + +The hwmon device name is ``prom21_xhci``. The sysfs path depends on the hwmon +device number assigned by the kernel. Userspace can locate the device by +matching the ``name`` attribute: + +.. code-block:: sh + + for hwmon in /sys/class/hwmon/hwmon*; do + [ "$(cat "$hwmon/name")" = "prom21_xhci" ] || continue + cat "$hwmon/temp1_input" + done + +``temp1_input`` reports millidegrees Celsius, so a value of ``50113`` means +50.113 degrees Celsius. If the raw register value is invalid, ``temp1_input`` +returns ``-ENODATA``.drivers/hwmon/Kconfig +10
-0@@ -951,6 +951,16 @@ config SENSORS_POWR1220 This driver can also be built as a module. If so, the module will be called powr1220. +config SENSORS_PROM21_XHCI + tristate "AMD Promontory 21 xHCI temperature sensor" + depends on USB_XHCI_PCI_PROM21 + help + If you say yes here you get support for the AMD Promontory 21 + (PROM21) xHCI temperature sensor. + + This driver can also be built as a module. If so, the module + will be called prom21-xhci. + config SENSORS_LAN966X tristate "Microchip LAN966x Hardware Monitoring" depends on SOC_LAN966 || COMPILE_TESTdrivers/hwmon/Makefile +1
-0@@ -196,6 +196,7 @@ obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_POWERZ) += powerz.o obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o +obj-$(CONFIG_SENSORS_PROM21_XHCI) += prom21-xhci.o obj-$(CONFIG_SENSORS_PT5161L) += pt5161l.o obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o obj-$(CONFIG_SENSORS_QNAP_MCU_HWMON) += qnap-mcu-hwmon.odrivers/hwmon/prom21-xhci.c new file +74
-0@@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* AMD Promontory 21 xHCI Hwmon Implementation +* (only temperature monitoring is supported) +* +* This can be effectively used as the alternative chipset temperature monitor. +* +* Copyright (C) 2026 Jihong Min <[email protected]> +*/ + +#include <linux/auxiliary_bus.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/hwmon.h> +#include <linux/io.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/pm_runtime.h> +#include <linux/slab.h> +#include <linux/usb.h> +#include <linux/usb/hcd.h> + +#define PROM21_INDEX 0x3000 +#define PROM21_DATA 0x3008 +#define PROM21_TEMP_REG 0x0001e520 + +struct prom21_xhci { +struct pci_dev *pdev; +struct device *hwmon_dev; +void __iomem *regs; +struct mutex lock;/* serializes index/data register access */ +}; + +static int prom21_xhci_pm_get (struct prom21_xhci *hwmon,bool *pm_ref) +{ +struct device *dev = &hwmon->pdev->dev; +int ret; + + *pm_ref = false; + +/* +* PROM21 temperature register access does not return a valid value while +* the parent xHCI PCI function is suspended. Do not wake the device from +* a hwmon read; only read when runtime PM reports the device as active, +* or when runtime PM is disabled and the device is not marked as +* suspended. +*/ + ret =pm_runtime_get_if_active (dev); +if (ret >0 ) { + *pm_ref = true; +return 0 ; + } + +if (ret == -EINVAL && !pm_runtime_status_suspended (dev)) +return 0 ; + +if (!ret ||pm_runtime_status_suspended (dev)) +return -ENODATA ; + +return ret; +} + +/* +* This is not a pure MMIO read. The PROM21 vendor data register is selected +* by temporarily writing PROM21_TEMP_REG to the vendor index register. +* Serialize the sequence, keep it short, and restore the previous index before +* returning so this driver does not leave the vendor index/data register pair +* in a different state for other possible users. +*/ +static int prom21_xhci_read_temp_raw_restore_index (struct prom21_xhci *hwmon, +u8 *raw)
drivers/hwmon/prom21-xhci.c line 84
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+{ +struct device *dev = &hwmon->pdev->dev; +bool pm_ref; +u32 index; +u32 data; +int ret; + + ret =prom21_xhci_pm_get (hwmon, &pm_ref); +if (ret) +return ret;
Rather than using pm_ref as an output variable to indicate whether you took a ref - how about you instead always take a ref on success and return an error on fail? This would feel more logical to me.
drivers/hwmon/prom21-xhci.c line 86
Quoted 2 lines
drivers/hwmon/prom21-xhci.c new file +2
-0+ +mutex_lock (&hwmon->lock);
guard(mutex) perhaps?
drivers/hwmon/prom21-xhci.c line 90
Quoted 4 lines
drivers/hwmon/prom21-xhci.c new file +4
-0+ index =readl (hwmon->regs +PROM21_INDEX ); +/* Select the PROM21 temperature register through the vendor index. */ +writel (PROM21_TEMP_REG , hwmon->regs +PROM21_INDEX ); + data =readl (hwmon->regs +PROM21_DATA );
You only care about the first byte, right? Just use readb() and make data a u8.
Quoted 6 lines
drivers/hwmon/prom21-xhci.c new file +6
-0+/* Restore the previous vendor index register value. */ +writel (index, hwmon->regs +PROM21_INDEX ); +readl (hwmon->regs +PROM21_INDEX ); +mutex_unlock (&hwmon->lock); + +if (pm_ref) {
drivers/hwmon/prom21-xhci.c line 106
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+/* +* Drop only the reference taken by pm_runtime_get_if_active(). +* Do not mark the device busy or schedule autosuspend from the +* hwmon path; sensor polling must not keep the xHCI PCI device +* active. +*/ +pm_runtime_put_noidle (dev); + } + + *raw = data &0xff ;
I personally don't really like changing the pointer when there is potentially an error case with it for -ENODATA.
drivers/hwmon/prom21-xhci.c line 107
Quoted 1 line
drivers/hwmon/prom21-xhci.c new file +1
-0+if (!*raw || *raw ==0xff )
Does 0xff actually happen with your runtime PM handling? Between my suggestion above to use readb() this can turn into:
if (!data)
return -ENODDATA;
*raw = data;
return 0;
Quoted 143 lines
drivers/hwmon/prom21-xhci.c new file +143
-0+return -ENODATA ; + +return 0 ; +} + +static long prom21_xhci_raw_to_millicelsius (u8 raw) +{ +/* +* No public AMD reference is available for this value. +* The scale was derived from observed PROM21 xHCI temperature readings: +* temp[C] = raw * 0.9066 - 78.624 +*/ +return DIV_ROUND_CLOSEST (raw *9066 ,10 ) -78624 ; +} + +static umode_t prom21_xhci_is_visible (const void *drvdata, +enum hwmon_sensor_types type,u32 attr, +int channel) +{ +if (type != hwmon_temp || channel) +return 0 ; + +switch (attr) { +case hwmon_temp_input: +return 0444 ; +default : +return 0 ; + } +} + +static int prom21_xhci_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct prom21_xhci *hwmon =dev_get_drvdata (dev); +u8 raw; +int ret; + +if (type != hwmon_temp || attr != hwmon_temp_input || channel) +return -EOPNOTSUPP ; + + ret =prom21_xhci_read_temp_raw_restore_index (hwmon, &raw); +if (ret) +return ret; + + *val =prom21_xhci_raw_to_millicelsius (raw); +return 0 ; +} + +static const struct hwmon_ops prom21_xhci_ops = { + .is_visible = prom21_xhci_is_visible, + .read = prom21_xhci_read, +}; + +static const struct hwmon_channel_info *const prom21_xhci_info[] = { +HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT ), +NULL , +}; + +static const struct hwmon_chip_info prom21_xhci_chip_info = { + .ops = &prom21_xhci_ops, + .info = prom21_xhci_info, +}; + +static int prom21_xhci_probe (struct auxiliary_device *auxdev, +const struct auxiliary_device_id *id) +{ +struct device *dev = &auxdev->dev; +struct device *parent = dev->parent; +struct prom21_xhci *hwmon; +struct pci_dev *pdev; +struct usb_hcd *hcd; +int ret; + +if (!parent || !dev_is_pci (parent)) +return -ENODEV ; + + pdev =to_pci_dev (parent); + hcd =pci_get_drvdata (pdev); +if (!hcd) +return dev_err_probe (dev, -ENODEV , +"xHCI HCD data unavailable\n" ); + +if (!hcd->regs || hcd->rsrc_len <PROM21_DATA +sizeof (u32)) +return dev_err_probe (dev, -ENODEV ,"invalid MMIO resource\n" ); + + hwmon =devm_kzalloc (dev,sizeof (*hwmon),GFP_KERNEL ); +if (!hwmon) +return -ENOMEM ; + + ret =devm_mutex_init (dev, &hwmon->lock); +if (ret) +return ret; + + hwmon->pdev = pdev; + hwmon->regs = hcd->regs; +auxiliary_set_drvdata (auxdev, hwmon); + +/* +* Use the PCI function as the hwmon parent so user space reports it as +* a PCI adapter. Lifetime is still owned by this auxiliary driver; +* remove() unregisters the hwmon device before xhci-pci tears down the +* HCD. +*/ + hwmon->hwmon_dev = +hwmon_device_register_with_info (&pdev->dev,"prom21_xhci" , + hwmon, &prom21_xhci_chip_info, +NULL ); +if (IS_ERR (hwmon->hwmon_dev)) +return PTR_ERR (hwmon->hwmon_dev); + +return 0 ; +} + +static void prom21_xhci_remove (struct auxiliary_device *auxdev) +{ +struct prom21_xhci *hwmon =auxiliary_get_drvdata (auxdev); + +/* +* The PROM21 PCI glue destroys the auxiliary device before HCD teardown. +* Unregister the hwmon device here so sysfs removes the attributes, +* stops new reads, and drains active hwmon callbacks before the xHCI +* MMIO mapping is released. +*/ +hwmon_device_unregister (hwmon->hwmon_dev); +} + +static const struct auxiliary_device_id prom21_xhci_id_table[] = { + { .name ="xhci_pci_prom21.hwmon" }, + {} +}; +MODULE_DEVICE_TABLE (auxiliary, prom21_xhci_id_table); + +static struct auxiliary_driver prom21_xhci_driver = { + .name ="prom21-xhci" , + .probe = prom21_xhci_probe, + .remove = prom21_xhci_remove, + .id_table = prom21_xhci_id_table, +}; +module_auxiliary_driver (prom21_xhci_driver); + +MODULE_AUTHOR ("Jihong Min <[email protected]>" ); +MODULE_DESCRIPTION ("AMD Promontory 21 xHCI temperature sensor driver" ); +MODULE_LICENSE ("GPL" );
Re: [PATCH v4 2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor support
In reply to Guenter RoeckQuoted 3 lines
I am sure I understand the reasoning here. What is the problem if it is attached to the auxiliary device ? Other drivers do that, so I don't immediate see why that would be a problem here.
I kept the hwmon device parented to the PCI function intentionally because the temperature value is read from that PCI function's MMIO BAR, and systems may have more than one PROM21 xHCI PCI function.
If the hwmon device is parented to the auxiliary device, userspace may report it as a virtual adapter. Parenting it to the PCI function lets userspace identify which PCI endpoint each reading belongs to, which is useful on systems with multiple PROM21 xHCI functions.
The auxiliary driver still owns the hwmon lifetime. Its remove path unregisters the hwmon device before the PROM21 xHCI PCI glue tears down the HCD/MMIO mapping.
Quoted 3 lines
+#include <
linux/math.h>Is this needed ?
Yes. It is used for DIV_ROUND_CLOSEST() in the raw-to-millicelsius conversion.
The other review comments have been addressed locally, including dropping the extra mutex, removing the unnecessary channel checks, passing the MMIO resource through platform data instead of looking at the parent's driver data, removing the redundant hwmon ABI wording from the documentation, and the small style cleanups.
Following Mario's advice from the v3 discussion, I will wait for the current review discussion to settle before sending v5. I am keeping the current work-in-progress branch here for reference only:
https://github.com/hurryman2212/linux/tree/prom21_hwmon
Sincerely,
Jihong Min
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
In reply to Mario LimoncielloQuoted 2 lines
This define should be in a common header used by
xhci-pci.candxhci-pci-prom21.cboth.
Agreed. I moved PCI_DEVICE_ID_AMD_PROM21_XHCI to xhci-pci.h so both xhci-pci.c and xhci-pci-prom21.c use the same definition.
Sincerely,
Jihong Min
Re: [PATCH v4 2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor support
In reply to Mario LimoncielloQuoted 3 lines
Rather than using
pm_refas an output variable to indicate whether you took a ref - how about you instead always take a ref on success and return an error on fail? This would feel more logical to me.
Agreed. I changed the PM helper so success always means that a usage reference is held, and the caller now unconditionally drops it with pm_runtime_put_noidle() after the register access.
For the runtime PM disabled case, pm_runtime_get_if_active() returns -EINVAL. In that case the helper now allows the read if the device is not marked suspended, and uses pm_runtime_get_noresume() so the same success/put contract is preserved without changing the runtime PM state.
Quoted 1 line
guard(mutex) perhaps?
The private mutex is gone. Guenter pointed out that the hwmon core already serializes the callbacks, so I removed the extra lock instead of converting it.
Quoted 2 lines
You only care about the first byte, right? Just use
readb()and make data a u8.
Done. The data register read now uses readb(), and the local data variable is u8.
Quoted 2 lines
I personally don't really like changing the pointer when there is potentially an error case with it for
-ENODATA.
Done. The raw output pointer is only written after validating the read value.
Quoted 8 lines
Does
0xffactually happen with your runtime PM handling? Between my suggestion above to usereadb()this can turn into:if (!data)
return-ENODDATA;
*raw = data;return 0;
Done. I removed the 0xff invalid check. Suspended devices are rejected before the MMIO access, so the read path now only treats zero as invalid and assigns *raw after that check.
Sincerely,
Jihong Min
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
In reply to Jihong MinQuoted 9 lines · Jihong Min
Quoted 2 lines
This define should be in a common header used by
xhci-pci.candxhci-pci-prom21.cboth.Agreed. I moved
PCI_DEVICE_ID_AMD_PROM21_XHCItoxhci-pci.hso bothxhci-pci.candxhci-pci-prom21.cuse the same definition.Sincerely,
Jihong Min
Something else I was thinking about while reviewing this series.
Promontory 21 is only on AMD platforms and AMD platforms are only x86. I think the Kconfig should be conditional on AMD CPU support being enabled and X86 architecture so that we don't bloat other architectures with dead code that will never run.
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
Quoted 3 lines
Something else I was thinking about while reviewing this series.
Promontory 21 is only on AMD platforms and AMD platforms are only x86. I think the
Kconfigshould be conditional on AMD CPU support being enabled and X86 architecture so that we don't bloat other architectures with dead code that will never run.
Agreed. PROM21 is AMD x86 platform-specific, so I will add X86 and CPU_SUP_AMD dependencies to USB_XHCI_PCI_PROM21 for v5.
Sincerely,
Jihong Min
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
Quoted 3 lines
Quoted 3 lines
Something else I was thinking about while reviewing this series.
Promontory 21 is only on AMD platforms and AMD platforms are only x86. I think the
Kconfigshould be conditional on AMD CPU support being enabled and X86 architecture so that we don't bloat other architectures with dead code that will never run.
One related Kconfig question: would it be acceptable to make USB_XHCI_PCI_PROM21 default y with the X86 && CPU_SUP_AMD dependency?
This would only default-enable the PROM21 xHCI PCI glue. The hwmon driver would still be controlled separately by SENSORS_PROM21_XHCI and would remain opt-in, so the undocumented temperature register polling would not be enabled by default.
The concern is that, without default y, distribution configs may miss the PROM21 PCI glue and then SENSORS_PROM21_XHCI can not bind even if the hwmon driver itself is enabled or available as a module.
Would you prefer this, or should USB_XHCI_PCI_PROM21 remain explicitly enabled by distributions?
Sincerely,
Jihong Min
Guenter Roeck
maintainerRe: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
Quoted 11 lines · Jihong Min
Quoted 3 lines
Quoted 3 lines
Something else I was thinking about while reviewing this series.
Promontory 21 is only on AMD platforms and AMD platforms are only x86. I think the
Kconfigshould be conditional on AMD CPU support being enabled and X86 architecture so that we don't bloat other architectures with dead code that will never run.One related
Kconfigquestion: would it be acceptable to makeUSB_XHCI_PCI_PROM21default y with the X86 &&CPU_SUP_AMDdependency?This would only default-enable the PROM21 xHCI PCI glue. The hwmon driver would still be controlled separately by
SENSORS_PROM21_XHCIand would remain opt-in, so the undocumented temperature register polling would not be enabled by default.
Quoted 7 lines
The concern is that, without default y, distribution configs may miss the PROM21 PCI glue and then
SENSORS_PROM21_XHCIcan not bind even if the hwmon driver itself is enabled or available as a module.Would you prefer this, or should
USB_XHCI_PCI_PROM21remain explicitly enabled by distributions?
How about "default USB_XHCI_PCI" ?
Guenter
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
Quoted 3 lines
How about "default
USB_XHCI_PCI" ?Guenter
That makes sense. I changed USB_XHCI_PCI_PROM21 to use
default USB_XHCI_PCI
locally.
Sincerely,
Jihong Min
[email protected]
AI reviewRe: [PATCH v4 2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor support
In reply to Jihong MinThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Using pm_runtime_put_noidle() can permanently prevent the PCI device from runtime-suspending.…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Using pm_runtime_put_noidle() can permanently prevent the PCI device from runtime-suspending.
- [Low] The local hwmon->lock mutex is redundant and violates the hwmon subsystem locking architecture. --
commit 62e33fab546f8b14b0cd80683aa504672db60e64
Author: Jihong Min <[email protected]>
hwmon: add AMD Promontory 21 xHCI temperature sensor support
This commit adds an auxiliary-bus hwmon driver to expose the temperature sensor on AMD Promontory 21 xHCI controllers. It reads the sensor value through a vendor-specific index/data register pair in the PCI MMIO BAR.
Quoted 6 lines
drivers/hwmon/prom21-xhci.c new file +0
-0@@ -0,0 +1,250 @@
[ ... ]
Quoted 4 lines
drivers/hwmon/prom21-xhci.c new file +4
-0+static int prom21_xhci_read_temp_raw_restore_index (struct prom21_xhci *hwmon, +u8 *raw) +{ +struct device *dev = &hwmon->pdev->dev;
drivers/hwmon/prom21-xhci.c line 86
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+bool pm_ref; +u32 index; +u32 data; +int ret; + + ret =prom21_xhci_pm_get (hwmon, &pm_ref); +if (ret) +return ret; + +mutex_lock (&hwmon->lock);
Is this private mutex redundant here?
According to the hardware monitoring subsystem guidelines, the hwmon core automatically serializes sysfs operations for attributes registered via the info parameter of hwmon_device_register_with_info().
Since this driver registers its only attribute (temp1_input) via the info parameter and does not access the hardware from interrupt handlers or other asynchronous paths, does it need its own serialization?
Quoted 7 lines
drivers/hwmon/prom21-xhci.c new file +7
-0+ index =readl (hwmon->regs +PROM21_INDEX ); +/* Select the PROM21 temperature register through the vendor index. */ +writel (PROM21_TEMP_REG , hwmon->regs +PROM21_INDEX ); + data =readl (hwmon->regs +PROM21_DATA ); +/* Restore the previous vendor index register value. */ +writel (index, hwmon->regs +PROM21_INDEX ); +readl (hwmon->regs +PROM21_INDEX );
drivers/hwmon/prom21-xhci.c line 103
Quoted 10 lines
drivers/hwmon/prom21-xhci.c new file +10
-0+mutex_unlock (&hwmon->lock); + +if (pm_ref) { +/* +* Drop only the reference taken by pm_runtime_get_if_active(). +* Do not mark the device busy or schedule autosuspend from the +* hwmon path; sensor polling must not keep the xHCI PCI device +* active. +*/ +pm_runtime_put_noidle (dev);
Can using pm_runtime_put_noidle() permanently prevent the PCI device from runtime-suspending?
If the xHCI driver drops its own runtime PM reference concurrently (e.g., via pm_runtime_put_autosuspend()), the PM core's idle check sees usage_count > 0, returns -EAGAIN, and skips scheduling the autosuspend timer.
This code then calls pm_runtime_put_noidle(), which decrements usage_count to 0 but intentionally bypasses queueing an idle check or notifying the PM core.
Could this leave the xHCI controller permanently in the RPM_ACTIVE state with a usage_count of 0 and no pending autosuspend timer until the next PM state change?
To safely drop the reference without resetting the autosuspend timer, should this use pm_runtime_put() instead, which properly queues an asynchronous idle check?
Quoted 8 lines
drivers/hwmon/prom21-xhci.c new file +8
-0+ } + + *raw = data &0xff ; +if (!*raw || *raw ==0xff ) +return -ENODATA ; + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v4 2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor support
Quoted 4 lines · On 5/9/26 06:52, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Usingpm_runtime_put_noidle()can permanently prevent the PCI device from runtime-suspending.
- [Low] The localhwmon->lockmutex is redundant and violates the hwmon subsystem locking architecture. --
Both points make sense.
Quoted 9 lines
Is this private mutex redundant here?
According to the hardware monitoring subsystem guidelines, the hwmon core automatically serializes sysfs operations for attributes registered via the info parameter of
hwmon_device_register_with_info().Since this driver registers its only attribute (
temp1_input) via the info parameter and does not access the hardware from interrupt handlers or other asynchronous paths, does it need its own serialization?
This was already removed locally after Guenter's review. The driver now relies on hwmon core serialization for its own callbacks.
I also updated the comment around the PROM21 vendor index/data access to avoid implying that the driver can synchronize with firmware, SMM, ACPI, or other possible users outside this driver.
Quoted 7 lines
Can using
pm_runtime_put_noidle()permanently prevent the PCI device from runtime-suspending?If the xHCI driver drops its own runtime PM reference concurrently (e.g., via
pm_runtime_put_autosuspend()), the PM core's idle check seesusage_count> 0, returns-EAGAIN, and skips scheduling the autosuspend timer.
Quoted 7 lines
This code then calls
pm_runtime_put_noidle(), which decrementsusage_countto 0 but intentionally bypasses queueing an idle check or notifying the PM core.Could this leave the xHCI controller permanently in the
RPM_ACTIVEstate with ausage_countof 0 and no pending autosuspend timer until the next PM state change?
Yes, that is a good point. I changed the successful read path to use pm_runtime_put() instead.
The driver still does not runtime-resume the parent device for a hwmon read:
it only reads when pm_runtime_get_if_active() succeeds. But after a successful read, pm_runtime_put() lets the PM core re-evaluate the idle state after the active-only runtime PM reference is dropped.
I also updated the runtime PM documentation accordingly.
Quoted 3 lines
To safely drop the reference without resetting the autosuspend timer, should this use
pm_runtime_put()instead, which properly queues an asynchronous idle check?
Yes. That is what I changed locally.
These changes are already in my v5 work-in-progress branch:
https://github.com/hurryman2212/linux/tree/prom21_hwmon
Following Mario's advice, I will defer posting v5 to the mailing list for a few days while waiting for more review feedback and doing additional self-review.
Sincerely,
Jihong Min
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
In reply to Mario LimoncielloQuoted 4 lines · Mario Limonciello
Promontory 21 is only on AMD platforms and AMD platforms are only x86. I think the
Kconfigshould be conditional on AMD CPU support being enabled and X86 architecture so that we don't bloat other architectures with dead code that will never run.
I agree with limiting this to x86, and I changed the current branch in that direction.
One detail I would like to double-check is whether CPU_SUP_AMD should also be part of the dependency, or whether X86 alone would be more accurate for the PCI glue.
The PROM21 xHCI function is still a PCI device. I found one public example of a B650/PROM21-based PCIe add-in card design which is reported to work in both AMD and Intel systems:
That is clearly a niche/community hardware case, not a normal AMD platform, and I do not want to over-weight it. But it made me wonder if:
depends on X86
would be the more accurate dependency than:
depends on X86 && CPU_SUP_AMD
for a PCI-attached PROM21 xHCI controller. The option would still use:
default USB_XHCI_PCI
and the hwmon sensor driver would still stay behind its own SENSORS_PROM21_XHCI option.
I am fine keeping CPU_SUP_AMD if you prefer; I just wanted to check before locking that part in for v5.
Sincerely,
Jihong Min
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
Quoted 32 lines · Jihong Min
Quoted 4 lines · Mario Limonciello
Promontory 21 is only on AMD platforms and AMD platforms are only x86. I think the
Kconfigshould be conditional on AMD CPU support being enabled and X86 architecture so that we don't bloat other architectures with dead code that will never run.I agree with limiting this to x86, and I changed the current branch in that direction.
One detail I would like to double-check is whether
CPU_SUP_AMDshould also be part of the dependency, or whether X86 alone would be more accurate for the PCI glue.The PROM21 xHCI function is still a PCI device. I found one public example of a B650/PROM21-based PCIe add-in card design which is reported to work in both AMD and Intel systems:
https://www.tomshardware.com/pc-components/chipsets/pcie-card-unlocks- amd-chipset-power-on-intel-motherboards-or-you-can-turn-any-b650- motherboard-into-an-x670-one
That is clearly a niche/community hardware case, not a normal AMD platform, and I do not want to over-weight it. But it made me wonder if:
depends on X86
would be the more accurate dependency than:
depends on X86 &&
CPU_SUP_AMDfor a PCI-attached PROM21 xHCI controller. The option would still use:
default
USB_XHCI_PCI
Quoted 9 lines
and the hwmon sensor driver would still stay behind its own
SENSORS_PROM21_XHCIoption.I am fine keeping
CPU_SUP_AMDif you prefer; I just wanted to check before locking that part in for v5.Sincerely,
Jihong Min
Fine by me either way.
Re: [PATCH v4 1/2] usb: xhci-pci: add AMD Promontory 21 PCI glue
Quoted 3 lines · Mario Limonciello
Fine by me either way.
Thanks. I changed the current branch to:
depends on X86
default USB_XHCI_PCI
and removed the CPU_SUP_AMD-specific help text.
Sincerely,
Jihong Min