Skip to contentSkip to conversation

hwmon: Add StarFive JH71X0 temperature sensor

PATCH Superseded Hal Feng 2 participants 5 messages Feb 27, 2023 – Feb 28, 2023

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Hal Feng

author maintainer
#0 lore raw

v5 cover hwmon: Add StarFive JH71X0 temperature sensor

This adds a driver for the temperature sensor on the JH7100 and JH7110, RISC-V SoCs by StarFive Technology Co. Ltd.. The JH7100 is used on the BeagleV Starlight board and StarFive VisionFive board. The JH7110 is used on the StarFive VisionFive 2 board.

v5:
* Dropp the "interrupts" property in dt-bindings.
* Reword the commit message of patch 2.
* Use continuous mode instead of single mode and drop the interrupt related code used in the single mode.
* Add the missing "default:" statements in the driver.
* Change the device name to "sfctemp" which avoids a warning when startup.

v4:
* Change the node name from "tmon" to "temperature-sensor" in dt-binding example, which is more generic.
* Add support for StarFive JH7110 SoC besides JH7100.
* Add clock and reset support in the dt-bindings and driver.
* Add the missing headers in patch 2.
* Use devm_platform_ioremap_resource() to remap instead of platform_get_resource() and devm_ioremap_resource().
* Use dev_err_probe() instead of dev_err().
* Add Signed-off-by tag for Hal Feng. Add Co-developed-by tag for Samin Guo in patch 2.

v3:
* Handle timeouts from wait_for_completion_interruptible_timeout properly.

v2:
* Fix checkpatch.pl --strict warnings
- Add myself to MAINTAINERS
- Fix multiline comments
- Use proper case and whitespace for #defines
- Add comment to sfctemp::lock mutex.
* Remaining comments by Guenter Roeck
- Add Documentation/hwmon/sfctemp.rst
- Use devm_add_action() and devm_hwmon_device_register_with_info() instead of a driver .remove function.
- Don't do test conversion at probe time.
- #include <linux/io.h>
- Remove unused #defines
- Use int return variable in sfctemp_convert().
* Add Samin's Signed-off-by to patch 2/2

History:
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Emil Renner Berthing (2):
dt-bindings: hwmon: Add starfive,jh71x0-temp
hwmon: (sfctemp) Add StarFive JH71x0 temperature sensor

 .../bindings/hwmon/starfive,jh71x0-temp.yaml  |  70 ++++
 Documentation/hwmon/index.rst                 |   1 +
 Documentation/hwmon/sfctemp.rst               |  33 ++
 MAINTAINERS                                   |   8 +
 drivers/hwmon/Kconfig                         |  10 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/sfctemp.c                       | 331 ++++++++++++++++++
 7 files changed, 454 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/starfive,jh71x0-temp.yaml
 create mode 100644 Documentation/hwmon/sfctemp.rst
 create mode 100644 drivers/hwmon/sfctemp.c
Signature · 1 line
2.38.1
author maintainer
#1 lore raw

PATCH v5 1/2 dt-bindings: hwmon: Add starfive,jh71x0-temp

From: Emil Renner Berthing <[email protected]>

Add bindings for the temperature sensor on the StarFive JH7100 and JH7110 SoCs.

---
 .../bindings/hwmon/starfive,jh71x0-temp.yaml  | 70 +++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/starfive,jh71x0-temp.yaml
Documentation/devicetree/bindings/hwmon/starfive,jh71x0-temp.yaml new file +70 -0
new file mode 100644
index 000000000000..f5b34528928d
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/starfive,jh71x0-temp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive JH71x0 Temperature Sensor
+
+maintainers:
+  - Emil Renner Berthing <[email protected]>
+
+description: |
+  StarFive Technology Co. JH71x0 embedded temperature sensor
+
+properties:
+  compatible:
+    enum:
+      - starfive,jh7100-temp
+      - starfive,jh7110-temp
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    minItems: 2
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: "sense"
+      - const: "bus"
+
+  '#thermal-sensor-cells':
+    const: 0
+
+  resets:
+    minItems: 2
+    maxItems: 2
+
+  reset-names:
+    items:
+      - const: "sense"
+      - const: "bus"
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/starfive-jh7100.h>
+    #include <dt-bindings/reset/starfive-jh7100.h>
+
+    temperature-sensor@124a0000 {
+        compatible = "starfive,jh7100-temp";
+        reg = <0x124a0000 0x10000>;
+        clocks = <&clkgen JH7100_CLK_TEMP_SENSE>,
+                 <&clkgen JH7100_CLK_TEMP_APB>;
+        clock-names = "sense", "bus";
+        #thermal-sensor-cells = <0>;
+        resets = <&rstgen JH7100_RSTN_TEMP_SENSE>,
+                 <&rstgen JH7100_RSTN_TEMP_APB>;
+        reset-names = "sense", "bus";
+    };
Signature · 1 line
2.38.1
author maintainer
#2 lore raw

PATCH v5 2/2 hwmon: (sfctemp) Add StarFive JH71x0 temperature sensor

In reply to Hal Feng

From: Emil Renner Berthing <[email protected]>

Add driver for the StarFive JH71x0 temperature sensor. You can enable/disable it and read temperature in milli Celcius through sysfs.

---
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/sfctemp.rst |  33 ++++
 MAINTAINERS                     |   8 +
 drivers/hwmon/Kconfig           |  10 +
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/sfctemp.c         | 331 ++++++++++++++++++++++++++++++++
 6 files changed, 384 insertions(+)
 create mode 100644 Documentation/hwmon/sfctemp.rst
 create mode 100644 drivers/hwmon/sfctemp.c
Documentation/hwmon/index.rst +1 -0
index fe2cc6b73634..a666e3706ea2 100644
@@ -180,6 +180,7 @@ Hardware Monitoring Kernel Drivers
    sch5627
    sch5636
    scpi-hwmon
+   sfctemp
    sht15
    sht21
    sht3x
Documentation/hwmon/sfctemp.rst new file +33 -0
new file mode 100644
index 000000000000..9fbd5bb1f356
@@ -0,0 +1,33 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver sfctemp
+=====================
+
+Supported chips:
+ - StarFive JH7100
+ - StarFive JH7110
+
+Authors:
+ - Emil Renner Berthing <[email protected]>
+
+Description
+-----------
+
+This driver adds support for reading the built-in temperature sensor on the
+JH7100 and JH7110 RISC-V SoCs by StarFive Technology Co. Ltd.
+
+``sysfs`` interface
+-------------------
+
+The temperature sensor can be enabled, disabled and queried via the standard
+hwmon interface in sysfs under ``/sys/class/hwmon/hwmonX`` for some value of
+``X``:
+
+================ ==== =============================================
+Name             Perm Description
+================ ==== =============================================
+temp1_enable     RW   Enable or disable temperature sensor.
+                      Automatically enabled by the driver,
+                      but may be disabled to save power.
+temp1_input      RO   Temperature reading in milli-degrees Celsius.
+================ ==== =============================================
MAINTAINERS +8 -0
index ac151975d0d3..f5345b1ee27c 100644
@@ -18917,6 +18917,14 @@ L:	[email protected]
 S:	Supported
 F:	drivers/net/ethernet/sfc/
 
+SFCTEMP HWMON DRIVER
+M:	Emil Renner Berthing <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/hwmon/starfive,jh71x0-temp.yaml
+F:	Documentation/hwmon/sfctemp.rst
+F:	drivers/hwmon/sfctemp.c
+
 SFF/SFP/SFP+ MODULE SUPPORT
 M:	Russell King <[email protected]>
 L:	[email protected]
drivers/hwmon/Kconfig +10 -0
index 3176c33af6c6..572e1b2541bb 100644
@@ -1930,6 +1930,16 @@ config SENSORS_STTS751
 	  This driver can also be built as a module. If so, the module
 	  will be called stts751.
 
+config SENSORS_SFCTEMP
+	tristate "Starfive JH71x0 temperature sensor"
+	depends on SOC_STARFIVE || COMPILE_TEST
+	help
+	  If you say yes here you get support for temperature sensor
+	  on the Starfive JH71x0 SoCs.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sfctemp.
+
 config SENSORS_SMM665
 	tristate "Summit Microelectronics SMM665"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index e2e4e87b282f..337e1b19678a 100644
@@ -180,6 +180,7 @@ obj-$(CONFIG_SENSORS_SBRMI)	+= sbrmi.o
 obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o
 obj-$(CONFIG_SENSORS_SCH5627)	+= sch5627.o
 obj-$(CONFIG_SENSORS_SCH5636)	+= sch5636.o
+obj-$(CONFIG_SENSORS_SFCTEMP)	+= sfctemp.o
 obj-$(CONFIG_SENSORS_SL28CPLD)	+= sl28cpld-hwmon.o
 obj-$(CONFIG_SENSORS_SHT15)	+= sht15.o
 obj-$(CONFIG_SENSORS_SHT21)	+= sht21.o
drivers/hwmon/sfctemp.c new file +331 -0

331 lines not on this page · raw message

Signature · 1 line
2.38.1
#3 lore raw

Re: [PATCH v5 2/2] hwmon: (sfctemp) Add StarFive JH71x0 temperature sensor

Quoted 11 lines · Hal Feng

From: Emil Renner Berthing <[email protected]>

Add driver for the StarFive JH71x0 temperature sensor. You can enable/disable it and read temperature in milli Celcius through sysfs.

drivers/hwmon/Kconfig config SENSORS_STTS751 · line 1935

Quoted 3 lines
drivers/hwmon/Kconfig +3 -0
+config SENSORS_SFCTEMP
+	tristate "Starfive JH71x0 temperature sensor"
+	depends on SOC_STARFIVE || COMPILE_TEST

We (or I?) am trying to homogenise RISC-V with the rest of the kernel by using ARCH_FOO rather than SOC_FOO. We've currently got a mix of both, due to companies that started out with RISC-V having SOC_ symbols & those with history in other archs having ARCH_ ones.
The ARCH_ definitions landed in mainline this week, so if you end up resubmitting this driver, it'd save me a conversion if you were to use the ARCH_ variant.

Thanks,
Conor.

Quoted 6 lines
drivers/hwmon/Kconfig +6 -0
+	help
+	  If you say yes here you get support for temperature sensor
+	  on the Starfive JH71x0 SoCs.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sfctemp.
author maintainer
#4 lore raw

Re: [PATCH v5 2/2] hwmon: (sfctemp) Add StarFive JH71x0 temperature sensor

Quoted 12 lines · Conor Dooley
Quoted 10 lines · Hal Feng

From: Emil Renner Berthing <[email protected]>

Add driver for the StarFive JH71x0 temperature sensor. You can enable/disable it and read temperature in milli Celcius through sysfs.

Quoted 11 lines

drivers/hwmon/Kconfig config SENSORS_STTS751 · line 1935

Quoted 3 lines
drivers/hwmon/Kconfig +3 -0
+config SENSORS_SFCTEMP
+	tristate "Starfive JH71x0 temperature sensor"
+	depends on SOC_STARFIVE || COMPILE_TEST

We (or I?) am trying to homogenise RISC-V with the rest of the kernel by using ARCH_FOO rather than SOC_FOO. We've currently got a mix of both, due to companies that started out with RISC-V having SOC_ symbols & those with history in other archs having ARCH_ ones.
The ARCH_ definitions landed in mainline this week, so if you end up resubmitting this driver, it'd save me a conversion if you were to use the ARCH_ variant.

Got it. I will use the ARCH_ symbol instead in the next version. Thanks.

Best regards,
Hal

Quoted 7 lines
Quoted 7 lines
drivers/hwmon/Kconfig +6 -0
+	help
+	  If you say yes here you get support for temperature sensor
+	  on the Starfive JH71x0 SoCs.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sfctemp.