Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/2235079/?format=api
{ "id": 2235079, "url": "http://patchwork.ozlabs.org/api/1.2/patches/2235079/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-pci/patch/20260508143910.14673-3-hurryman2212@gmail.com/", "project": { "id": 28, "url": "http://patchwork.ozlabs.org/api/1.2/projects/28/?format=api", "name": "Linux PCI development", "link_name": "linux-pci", "list_id": "linux-pci.vger.kernel.org", "list_email": "linux-pci@vger.kernel.org", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260508143910.14673-3-hurryman2212@gmail.com>", "list_archive_url": null, "date": "2026-05-08T14:39:10", "name": "[v4,2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor support", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "6ac13992aa7bb25dc196ba375558f884e959c6ca", "submitter": { "id": 93349, "url": "http://patchwork.ozlabs.org/api/1.2/people/93349/?format=api", "name": "Jihong Min", "email": "hurryman2212@gmail.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linux-pci/patch/20260508143910.14673-3-hurryman2212@gmail.com/mbox/", "series": [ { "id": 503404, "url": "http://patchwork.ozlabs.org/api/1.2/series/503404/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-pci/list/?series=503404", "date": "2026-05-08T14:39:08", "name": "AMD Promontory 21 xHCI temperature sensor support", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/503404/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2235079/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2235079/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linux-pci+bounces-54259-incoming=patchwork.ozlabs.org@vger.kernel.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "linux-pci@vger.kernel.org" ], "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=g4OHZ0G6;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-54259-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)", "smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"g4OHZ0G6\"", "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.210.173", "smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com", "smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com" ], "Received": [ "from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gBsP1528Qz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 09 May 2026 00:45:41 +1000 (AEST)", "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 40A4730D227E\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 8 May 2026 14:40:05 +0000 (UTC)", "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 08CA93F54C5;\n\tFri, 8 May 2026 14:39:49 +0000 (UTC)", "from mail-pf1-f173.google.com (mail-pf1-f173.google.com\n [209.85.210.173])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id DDB0B3F7898\n\tfor <linux-pci@vger.kernel.org>; Fri, 8 May 2026 14:39:44 +0000 (UTC)", "by mail-pf1-f173.google.com with SMTP id\n d2e1a72fcca58-837cd669be0so1604049b3a.0\n for <linux-pci@vger.kernel.org>; Fri, 08 May 2026 07:39:44 -0700 (PDT)", "from mincom1 ([115.4.79.42])\n by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-839679c8462sm12395499b3a.38.2026.05.08.07.39.40\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 08 May 2026 07:39:43 -0700 (PDT)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778251188; cv=none;\n b=TbhAzb224m5IMOd9rAe4w+67vp6B8yKtYlgm6FucionzpnmE9tL3DWefe1i31lo9qpb3CkwEX25wPLWiSopAjaXYtf49GvqVPWblSZeeNYt5xD8LDAsHOcuSet38VN6ETvi4qUNj6iZd/5D3W/jMfoiTLM8LQYFVCWTZbAwo570=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778251188; c=relaxed/simple;\n\tbh=itEiIvS5IQdmPyKV4TM5/IWsSeVIbKhHBAPSr//nzw4=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=f+/qZ+M9zU6DgR0ZD0DLWWw4TzOu4PltWlZ+BiEwgIijL7kEAMnyPTVVgkgqKvX9km9ObL4FDeatBv1QoNRgG7SaIk6OB0nL2xGsWhrNV6XUPwzLiiUyTOx1GhRgGzB13XHab+b+vE4ooteINapZDwZvwKlCqAiTXyYmy3F97bs=", "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=g4OHZ0G6; arc=none smtp.client-ip=209.85.210.173", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1778251184; x=1778855984;\n darn=vger.kernel.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=z2HYUShWSK5X7dHT+11XldOT0jiE1N/UTPrbF9SDaeE=;\n b=g4OHZ0G64/MsIt/6SsNwYhk88nPo2OfaVz6WyaXMf+bek8AyP2mWmJN1qmCD9OMFXr\n hdsXSn1GYUdT65SG0lpQoIhB4l1qW89hYWm1jB1A7WTMvE3FgYup7MFRdvsZu3b4luWK\n NVSS8F2J/C7B8bpoHNT2r0ZoBBvWeCDbfmC8czg9QOvmAlhx8vO0hL3Mao9X/BvMVPM8\n Uk2bHLqoCHlkm+B30QmAfCIA0QOIjO6qE0rt+of3R3nVcxYkrf8sK9PN0AF3bWl8H8Js\n ltbN4NvJm7MrWHUPmVd4KbifBpyptmkaG8Qnu0pCIDw4Bmo0fg/OaMV/fK3hOp0zT9dd\n uLkQ==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1778251184; x=1778855984;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=z2HYUShWSK5X7dHT+11XldOT0jiE1N/UTPrbF9SDaeE=;\n b=KSwsiJbkgFD3CvxTE6TIYmFbSQBWqYdXAUidJ8u9UoE+I78eySz6INfHGkvL/af3kA\n XJy2KYk+mKjvHy+H0zUyQwRtR2nQpChiQG9wG9v6lKG7J/S4y4uXYciQub4es1QK04r8\n FMDo4ELLzuEiGv1A2A96ytdCrSi0fi5YyqXyIATFR9IfBE4woBxMDKu0oftGajZKptvj\n KI6JvY0PwlLhz+Q5RDvCtjfwRU564zAwbY9Q9shP4ETgD4dxqcTwUQBzeF5EhuQgT20K\n gE+h3ScMo+XCpw1/SY3aL3ZsqJeFp4+aIhEiaXnzmuNmXKkzR04eA1110UGuJ+DWFWD6\n xAmQ==", "X-Forwarded-Encrypted": "i=1;\n AFNElJ8n33pDpKf/VSExy4rMFQB58R5Kzj4xiPl7yKt3Ar7i+U45Druhbqms0585wyOGjvgY/gDP57K6sZI=@vger.kernel.org", "X-Gm-Message-State": "AOJu0YwA1DbJ+OrAtSWgEH0vflX5b+76SgSVMBiDKr/Nds7bdYzNl9lY\n\tp9X49mYhbkrIQHShqcZgGPinEVHS7TuL028inUcFJPxaDFu5yZn+tL/G", "X-Gm-Gg": "Acq92OFZLo4FSTsFlcxPDDxnWzL9+tK1YhFT4TmhCzBfkg8gsqzm1s6/4nz7mhAn6ZO\n\tS7vKgAx9Aue9kQjedm+VcarevBCRZBXmlfsFS1tU2mb6iPypT5TYzNFPQmJXaDu7bVkPGBBCEec\n\t0/E9a8l2qksLJxt4688gt9KG7PgvWRRs4V15BTOUKHsUgxobxvA4Z/D9UKuy7Kk7eOpZ3qsCeAC\n\tlcjpNn2AtiAxoBTHvilGuITwj2StHSuG0hrvK64tbcbe3xeHkWbHp6RXWG2l1i3SMEZ92rUlmIU\n\tg0qeqKGGPBo0NWp84iEUFpndtFEsb4wSQIxV94gsj+ArKSsD7+gQn7A+LOhExTdNPPKt1ZpEQqb\n\teiswL6ddzQGVGXiowd4XJbPx08QI0zcIJ2Jf6DAXy62WCvdzJLGhHRuRia6VufVvtLgIn3Qjo1h\n\toUMqFF47tN4pOG6KiZCvo=", "X-Received": "by 2002:aa7:98c6:0:b0:83b:c487:43d2 with SMTP id\n d2e1a72fcca58-83bc4874759mr5837605b3a.36.1778251183526;\n Fri, 08 May 2026 07:39:43 -0700 (PDT)", "From": "Jihong Min <hurryman2212@gmail.com>", "To": "Greg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tMathias Nyman <mathias.nyman@intel.com>", "Cc": "Guenter Roeck <linux@roeck-us.net>,\n\tJonathan Corbet <corbet@lwn.net>,\n\tShuah Khan <skhan@linuxfoundation.org>,\n\tMario Limonciello <mario.limonciello@amd.com>,\n\tBasavaraj Natikar <Basavaraj.Natikar@amd.com>,\n\tlinux-usb@vger.kernel.org,\n\tlinux-hwmon@vger.kernel.org,\n\tlinux-doc@vger.kernel.org,\n\tlinux-pci@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tJihong Min <hurryman2212@gmail.com>", "Subject": "[PATCH v4 2/2] hwmon: add AMD Promontory 21 xHCI temperature sensor\n support", "Date": "Fri, 8 May 2026 23:39:10 +0900", "Message-ID": "<20260508143910.14673-3-hurryman2212@gmail.com>", "X-Mailer": "git-send-email 2.53.0", "In-Reply-To": "<20260508143910.14673-1-hurryman2212@gmail.com>", "References": "<20260508143910.14673-1-hurryman2212@gmail.com>", "Precedence": "bulk", "X-Mailing-List": "linux-pci@vger.kernel.org", "List-Id": "<linux-pci.vger.kernel.org>", "List-Subscribe": "<mailto:linux-pci+subscribe@vger.kernel.org>", "List-Unsubscribe": "<mailto:linux-pci+unsubscribe@vger.kernel.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit" }, "content": "Add an auxiliary-bus hwmon driver for the temperature sensor exposed by\nAMD Promontory 21 (PROM21) xHCI PCI functions. The driver binds to the\n\"hwmon\" auxiliary device published by the PROM21 xHCI PCI glue and\nexposes the sensor as temp1_input under the prom21_xhci hwmon device.\n\nThe sensor is accessed through a PROM21 vendor index/data register pair\nin the xHCI PCI MMIO BAR. The read path restores the previous vendor\nindex value after sampling and does not runtime-resume the parent PCI\ndevice; reads from a suspended parent return -ENODATA.\n\nDocument the supported device, register access, runtime PM behavior, and\nsysfs lookup method. The documentation also records the observation\nmethod used to identify the register pair and derive the conversion\nformula.\n\nAssisted-by: Codex:gpt-5.5\nSigned-off-by: Jihong Min <hurryman2212@gmail.com>\n---\n Documentation/hwmon/index.rst | 1 +\n Documentation/hwmon/prom21-xhci.rst | 99 +++++++++++\n drivers/hwmon/Kconfig | 10 ++\n drivers/hwmon/Makefile | 1 +\n drivers/hwmon/prom21-xhci.c | 250 ++++++++++++++++++++++++++++\n 5 files changed, 361 insertions(+)\n create mode 100644 Documentation/hwmon/prom21-xhci.rst\n create mode 100644 drivers/hwmon/prom21-xhci.c", "diff": "diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst\nindex 8b655e5d6b68..324208f1faa2 100644\n--- a/Documentation/hwmon/index.rst\n+++ b/Documentation/hwmon/index.rst\n@@ -216,6 +216,7 @@ Hardware Monitoring Kernel Drivers\n pmbus\n powerz\n powr1220\n+ prom21-xhci\n pt5161l\n pxe1610\n pwm-fan\ndiff --git a/Documentation/hwmon/prom21-xhci.rst b/Documentation/hwmon/prom21-xhci.rst\nnew file mode 100644\nindex 000000000000..10d03c4476c3\n--- /dev/null\n+++ b/Documentation/hwmon/prom21-xhci.rst\n@@ -0,0 +1,99 @@\n+.. SPDX-License-Identifier: GPL-2.0\n+\n+Kernel driver prom21-xhci\n+=========================\n+\n+Supported chips:\n+\n+ * AMD Promontory 21 (PROM21) xHCI\n+\n+ Prefix: 'prom21_xhci'\n+\n+ PCI ID: 1022:43fd\n+\n+Author:\n+\n+ - Jihong Min <hurryman2212@gmail.com>\n+\n+Description\n+-----------\n+\n+This driver exposes the temperature sensor in AMD PROM21 xHCI controllers.\n+\n+The driver binds to an auxiliary device created by the xHCI PCI driver for\n+supported controllers. The sensor value is accessed through a vendor-specific\n+index/data register pair in the controller's PCI MMIO BAR.\n+The auxiliary device is created by the ``xhci-pci-prom21`` PCI glue driver.\n+USB host operation is otherwise delegated to the common ``xhci-pci`` code.\n+\n+PROM21 is an AMD chipset IP used in single-chip or daisy-chained configurations\n+to build AMD 6xx/8xx series chipsets. Since the xHCI controllers are\n+integrated in PROM21, this temperature can also be used as a monitor for a\n+temperature close to the AMD chipset temperature.\n+\n+Register access\n+---------------\n+\n+The temperature value is read through a vendor-specific index/data register\n+pair in the xHCI PCI MMIO BAR. The driver uses the following byte offsets from\n+the MMIO BAR base:\n+\n+======================= =====================================================\n+0x3000\t\t\tVendor index register\n+0x3008\t\t\tVendor data register\n+======================= =====================================================\n+\n+The driver saves the current vendor index register value, writes the\n+temperature selector ``0x0001e520`` to the vendor index register, reads the\n+vendor data register, and restores the previous vendor index value before\n+returning. The raw temperature value is the low 8 bits of the vendor data\n+register value.\n+\n+No public AMD reference is available for the register pair or the raw value.\n+The register pair was identified on an X870E system with two PROM21 xHCI\n+controllers. One controller was passed through to a Windows VM, and the same\n+controller's PCI MMIO BAR was observed from the Linux host while HWiNFO64 was\n+reporting the PROM21 xHCI temperature. In the test environment, the reported\n+temperature was very stable at idle and the displayed sensor resolution was\n+low, which made it possible to look for a consistently repeating MMIO response\n+for the same reported temperature. During observation, offset 0x3000 repeatedly\n+contained selector ``0x0001e520``. Writing the same selector to offset 0x3000\n+from Linux and then reading offset 0x3008 reproduced the same raw value, so the\n+offsets are treated as a vendor index/data register pair.\n+\n+The conversion formula was empirically inferred by matching observed raw\n+8-bit values against HWiNFO64's reported PROM21 xHCI temperature for the same\n+controller. The observed mapping is:\n+\n+ temp[C] = raw * 0.9066 - 78.624\n+\n+Runtime PM\n+----------\n+\n+The driver does not wake the xHCI PCI device for hwmon reads. It reads the\n+temperature only when the parent device is already active. A read from a\n+suspended device returns ``-ENODATA``. Sensor reads do not mark the xHCI PCI\n+device as busy or schedule autosuspend, so polling the sensor does not delay\n+runtime suspend.\n+\n+Sysfs entries\n+-------------\n+\n+======================= =====================================================\n+temp1_input\t\tTemperature in millidegrees Celsius\n+======================= =====================================================\n+\n+The hwmon device name is ``prom21_xhci``. The sysfs path depends on the hwmon\n+device number assigned by the kernel. Userspace can locate the device by\n+matching the ``name`` attribute:\n+\n+.. code-block:: sh\n+\n+ for hwmon in /sys/class/hwmon/hwmon*; do\n+ [ \"$(cat \"$hwmon/name\")\" = \"prom21_xhci\" ] || continue\n+ cat \"$hwmon/temp1_input\"\n+ done\n+\n+``temp1_input`` reports millidegrees Celsius, so a value of ``50113`` means\n+50.113 degrees Celsius. If the raw register value is invalid, ``temp1_input``\n+returns ``-ENODATA``.\ndiff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig\nindex 14e4cea48acc..fe0f14e247b5 100644\n--- a/drivers/hwmon/Kconfig\n+++ b/drivers/hwmon/Kconfig\n@@ -951,6 +951,16 @@ config SENSORS_POWR1220\n \t This driver can also be built as a module. If so, the module\n \t will be called powr1220.\n \n+config SENSORS_PROM21_XHCI\n+\ttristate \"AMD Promontory 21 xHCI temperature sensor\"\n+\tdepends on USB_XHCI_PCI_PROM21\n+\thelp\n+\t If you say yes here you get support for the AMD Promontory 21\n+\t (PROM21) xHCI temperature sensor.\n+\n+\t This driver can also be built as a module. If so, the module\n+\t will be called prom21-xhci.\n+\n config SENSORS_LAN966X\n \ttristate \"Microchip LAN966x Hardware Monitoring\"\n \tdepends on SOC_LAN966 || COMPILE_TEST\ndiff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile\nindex 4788996aa137..0bda542e8e2b 100644\n--- a/drivers/hwmon/Makefile\n+++ b/drivers/hwmon/Makefile\n@@ -196,6 +196,7 @@ obj-$(CONFIG_SENSORS_PC87427)\t+= pc87427.o\n obj-$(CONFIG_SENSORS_PCF8591)\t+= pcf8591.o\n obj-$(CONFIG_SENSORS_POWERZ)\t+= powerz.o\n obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o\n+obj-$(CONFIG_SENSORS_PROM21_XHCI)\t+= prom21-xhci.o\n obj-$(CONFIG_SENSORS_PT5161L)\t+= pt5161l.o\n obj-$(CONFIG_SENSORS_PWM_FAN)\t+= pwm-fan.o\n obj-$(CONFIG_SENSORS_QNAP_MCU_HWMON)\t+= qnap-mcu-hwmon.o\ndiff --git a/drivers/hwmon/prom21-xhci.c b/drivers/hwmon/prom21-xhci.c\nnew file mode 100644\nindex 000000000000..f91303ce3428\n--- /dev/null\n+++ b/drivers/hwmon/prom21-xhci.c\n@@ -0,0 +1,250 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * AMD Promontory 21 xHCI Hwmon Implementation\n+ * (only temperature monitoring is supported)\n+ *\n+ * This can be effectively used as the alternative chipset temperature monitor.\n+ *\n+ * Copyright (C) 2026 Jihong Min <hurryman2212@gmail.com>\n+ */\n+\n+#include <linux/auxiliary_bus.h>\n+#include <linux/device.h>\n+#include <linux/err.h>\n+#include <linux/errno.h>\n+#include <linux/hwmon.h>\n+#include <linux/io.h>\n+#include <linux/math.h>\n+#include <linux/module.h>\n+#include <linux/mutex.h>\n+#include <linux/pci.h>\n+#include <linux/pm_runtime.h>\n+#include <linux/slab.h>\n+#include <linux/usb.h>\n+#include <linux/usb/hcd.h>\n+\n+#define PROM21_INDEX 0x3000\n+#define PROM21_DATA 0x3008\n+#define PROM21_TEMP_REG 0x0001e520\n+\n+struct prom21_xhci {\n+\tstruct pci_dev *pdev;\n+\tstruct device *hwmon_dev;\n+\tvoid __iomem *regs;\n+\tstruct mutex lock; /* serializes index/data register access */\n+};\n+\n+static int prom21_xhci_pm_get(struct prom21_xhci *hwmon, bool *pm_ref)\n+{\n+\tstruct device *dev = &hwmon->pdev->dev;\n+\tint ret;\n+\n+\t*pm_ref = false;\n+\n+\t/*\n+\t * PROM21 temperature register access does not return a valid value while\n+\t * the parent xHCI PCI function is suspended. Do not wake the device from\n+\t * a hwmon read; only read when runtime PM reports the device as active,\n+\t * or when runtime PM is disabled and the device is not marked as\n+\t * suspended.\n+\t */\n+\tret = pm_runtime_get_if_active(dev);\n+\tif (ret > 0) {\n+\t\t*pm_ref = true;\n+\t\treturn 0;\n+\t}\n+\n+\tif (ret == -EINVAL && !pm_runtime_status_suspended(dev))\n+\t\treturn 0;\n+\n+\tif (!ret || pm_runtime_status_suspended(dev))\n+\t\treturn -ENODATA;\n+\n+\treturn ret;\n+}\n+\n+/*\n+ * This is not a pure MMIO read. The PROM21 vendor data register is selected\n+ * by temporarily writing PROM21_TEMP_REG to the vendor index register.\n+ * Serialize the sequence, keep it short, and restore the previous index before\n+ * returning so this driver does not leave the vendor index/data register pair\n+ * in a different state for other possible users.\n+ */\n+static int prom21_xhci_read_temp_raw_restore_index(struct prom21_xhci *hwmon,\n+\t\t\t\t\t\t u8 *raw)\n+{\n+\tstruct device *dev = &hwmon->pdev->dev;\n+\tbool pm_ref;\n+\tu32 index;\n+\tu32 data;\n+\tint ret;\n+\n+\tret = prom21_xhci_pm_get(hwmon, &pm_ref);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tmutex_lock(&hwmon->lock);\n+\tindex = readl(hwmon->regs + PROM21_INDEX);\n+\t/* Select the PROM21 temperature register through the vendor index. */\n+\twritel(PROM21_TEMP_REG, hwmon->regs + PROM21_INDEX);\n+\tdata = readl(hwmon->regs + PROM21_DATA);\n+\t/* Restore the previous vendor index register value. */\n+\twritel(index, hwmon->regs + PROM21_INDEX);\n+\treadl(hwmon->regs + PROM21_INDEX);\n+\tmutex_unlock(&hwmon->lock);\n+\n+\tif (pm_ref) {\n+\t\t/*\n+\t\t * Drop only the reference taken by pm_runtime_get_if_active().\n+\t\t * Do not mark the device busy or schedule autosuspend from the\n+\t\t * hwmon path; sensor polling must not keep the xHCI PCI device\n+\t\t * active.\n+\t\t */\n+\t\tpm_runtime_put_noidle(dev);\n+\t}\n+\n+\t*raw = data & 0xff;\n+\tif (!*raw || *raw == 0xff)\n+\t\treturn -ENODATA;\n+\n+\treturn 0;\n+}\n+\n+static long prom21_xhci_raw_to_millicelsius(u8 raw)\n+{\n+\t/*\n+\t * No public AMD reference is available for this value.\n+\t * The scale was derived from observed PROM21 xHCI temperature readings:\n+\t * temp[C] = raw * 0.9066 - 78.624\n+\t */\n+\treturn DIV_ROUND_CLOSEST(raw * 9066, 10) - 78624;\n+}\n+\n+static umode_t prom21_xhci_is_visible(const void *drvdata,\n+\t\t\t\t enum hwmon_sensor_types type, u32 attr,\n+\t\t\t\t int channel)\n+{\n+\tif (type != hwmon_temp || channel)\n+\t\treturn 0;\n+\n+\tswitch (attr) {\n+\tcase hwmon_temp_input:\n+\t\treturn 0444;\n+\tdefault:\n+\t\treturn 0;\n+\t}\n+}\n+\n+static int prom21_xhci_read(struct device *dev, enum hwmon_sensor_types type,\n+\t\t\t u32 attr, int channel, long *val)\n+{\n+\tstruct prom21_xhci *hwmon = dev_get_drvdata(dev);\n+\tu8 raw;\n+\tint ret;\n+\n+\tif (type != hwmon_temp || attr != hwmon_temp_input || channel)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tret = prom21_xhci_read_temp_raw_restore_index(hwmon, &raw);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t*val = prom21_xhci_raw_to_millicelsius(raw);\n+\treturn 0;\n+}\n+\n+static const struct hwmon_ops prom21_xhci_ops = {\n+\t.is_visible = prom21_xhci_is_visible,\n+\t.read = prom21_xhci_read,\n+};\n+\n+static const struct hwmon_channel_info *const prom21_xhci_info[] = {\n+\tHWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),\n+\tNULL,\n+};\n+\n+static const struct hwmon_chip_info prom21_xhci_chip_info = {\n+\t.ops = &prom21_xhci_ops,\n+\t.info = prom21_xhci_info,\n+};\n+\n+static int prom21_xhci_probe(struct auxiliary_device *auxdev,\n+\t\t\t const struct auxiliary_device_id *id)\n+{\n+\tstruct device *dev = &auxdev->dev;\n+\tstruct device *parent = dev->parent;\n+\tstruct prom21_xhci *hwmon;\n+\tstruct pci_dev *pdev;\n+\tstruct usb_hcd *hcd;\n+\tint ret;\n+\n+\tif (!parent || !dev_is_pci(parent))\n+\t\treturn -ENODEV;\n+\n+\tpdev = to_pci_dev(parent);\n+\thcd = pci_get_drvdata(pdev);\n+\tif (!hcd)\n+\t\treturn dev_err_probe(dev, -ENODEV,\n+\t\t\t\t \"xHCI HCD data unavailable\\n\");\n+\n+\tif (!hcd->regs || hcd->rsrc_len < PROM21_DATA + sizeof(u32))\n+\t\treturn dev_err_probe(dev, -ENODEV, \"invalid MMIO resource\\n\");\n+\n+\thwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL);\n+\tif (!hwmon)\n+\t\treturn -ENOMEM;\n+\n+\tret = devm_mutex_init(dev, &hwmon->lock);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\thwmon->pdev = pdev;\n+\thwmon->regs = hcd->regs;\n+\tauxiliary_set_drvdata(auxdev, hwmon);\n+\n+\t/*\n+\t * Use the PCI function as the hwmon parent so user space reports it as\n+\t * a PCI adapter. Lifetime is still owned by this auxiliary driver;\n+\t * remove() unregisters the hwmon device before xhci-pci tears down the\n+\t * HCD.\n+\t */\n+\thwmon->hwmon_dev =\n+\t\thwmon_device_register_with_info(&pdev->dev, \"prom21_xhci\",\n+\t\t\t\t\t\thwmon, &prom21_xhci_chip_info,\n+\t\t\t\t\t\tNULL);\n+\tif (IS_ERR(hwmon->hwmon_dev))\n+\t\treturn PTR_ERR(hwmon->hwmon_dev);\n+\n+\treturn 0;\n+}\n+\n+static void prom21_xhci_remove(struct auxiliary_device *auxdev)\n+{\n+\tstruct prom21_xhci *hwmon = auxiliary_get_drvdata(auxdev);\n+\n+\t/*\n+\t * The PROM21 PCI glue destroys the auxiliary device before HCD teardown.\n+\t * Unregister the hwmon device here so sysfs removes the attributes,\n+\t * stops new reads, and drains active hwmon callbacks before the xHCI\n+\t * MMIO mapping is released.\n+\t */\n+\thwmon_device_unregister(hwmon->hwmon_dev);\n+}\n+\n+static const struct auxiliary_device_id prom21_xhci_id_table[] = {\n+\t{ .name = \"xhci_pci_prom21.hwmon\" },\n+\t{}\n+};\n+MODULE_DEVICE_TABLE(auxiliary, prom21_xhci_id_table);\n+\n+static struct auxiliary_driver prom21_xhci_driver = {\n+\t.name = \"prom21-xhci\",\n+\t.probe = prom21_xhci_probe,\n+\t.remove = prom21_xhci_remove,\n+\t.id_table = prom21_xhci_id_table,\n+};\n+module_auxiliary_driver(prom21_xhci_driver);\n+\n+MODULE_AUTHOR(\"Jihong Min <hurryman2212@gmail.com>\");\n+MODULE_DESCRIPTION(\"AMD Promontory 21 xHCI temperature sensor driver\");\n+MODULE_LICENSE(\"GPL\");\n", "prefixes": [ "v4", "2/2" ] }