Skip to contentSkip to conversation

hwmon: add Microchip EMC230X fan controller driver

PATCH In review Mathew McBride 2 participants 6 messages Sep 14, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover hwmon: add Microchip EMC230X fan controller driver

The Microchip EMC230X (formerly made by SMSC) family of fan controllers provide PWM control for up to 5 fans (in the EMC2305). The EMC230X is capable of maintaining (closed-loop) a target RPM speed through PWM.

This driver has been tested with the EMC2301 (on our Traverse Ten64 appliance) and with the EMC2305 demo board (ADM00879).

The driver is by no means complete, for example, further work would be required to support the different PWM output frequencies for voltage-based fan speed control. (So far this driver has only been tested with direct PWM capable fans, like the 4 pin fans found in recent PCs)

The emc230x driver also has thermal subsystem integration which allows the emc230x-controlled fan(s) to be used as cooling devices.

Mathew McBride (3):
hwmon: (emc230x) add Microchip (SMSC) EMC230X fan controller support
dt-bindings: add binding for Microchip EMC230X fan controller family
arm64: dts: ten64: add configuration for fan controller

 .../bindings/hwmon/microchip,emc2301.yaml     |  83 +++
 MAINTAINERS                                   |   7 +
 .../boot/dts/freescale/fsl-ls1088a-ten64.dts  |  43 ++
 drivers/hwmon/Kconfig                         |  13 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/emc230x.c                       | 587 ++++++++++++++++++
 6 files changed, 734 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/microchip,emc2301.yaml
 create mode 100644 drivers/hwmon/emc230x.c
Signature · 1 line
2.30.1
#1 lore raw

PATCH 1/3 hwmon: (emc230x) add Microchip (SMSC) EMC230X fan controller support

The EMC230X is a family of RPM-based RPM fan controllers from Microchip (and SMSC before that) available in 1 (EMC2301), 2, 3 and 5 (EMC2305) channel variants.

This driver supports being used as a thermal cooling device, with RPM control when configured from a device tree.

At the moment this driver assumes the 'default' PWM configuration in the controller (open-drain, 20kHz PWM), other configurations will require further development.

---
 MAINTAINERS             |   6 +
 drivers/hwmon/Kconfig   |  13 +
 drivers/hwmon/Makefile  |   1 +
 drivers/hwmon/emc230x.c | 587 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 607 insertions(+)
 create mode 100644 drivers/hwmon/emc230x.c
MAINTAINERS +6 -0
index 936490dcc97b..bf3c6c3c0492 100644
@@ -8042,6 +8042,12 @@ S:	Maintained
 F:	Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-sec-update
 F:	drivers/fpga/intel-m10-bmc-sec-update.c
 
+MICROCHIP EMC230X PWM-FAN CONTROLLER DRIVERS
+M:	Mathew McBride <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/hwmon/emc230x.c
+
 MICROCHIP POLARFIRE FPGA DRIVERS
 M:	Conor Dooley <[email protected]>
 R:	Ivan Bornyakov <[email protected]>
drivers/hwmon/Kconfig +13 -0
index e70d9614bec2..e8da7793367c 100644
@@ -1775,6 +1775,19 @@ config SENSORS_EMC1403
 	  Threshold values can be configured using sysfs.
 	  Data from the different diodes are accessible via sysfs.
 
+config SENSORS_EMC230X
+	tristate "Microchip EMC230X fan controllers"
+	depends on I2C
+	help
+	  If you say yes here you get support for the Microchip (SMSC)
+	  EMC230x family of RPM-PWM fan controllers.
+
+	  When the thermal subsystem is enabled, this driver can
+	  be used as a cooling-device for a thermal zone.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called emc230x.
+
 config SENSORS_EMC2103
 	tristate "SMSC EMC2103"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index 007e829d1d0d..f87f8323493b 100644
@@ -69,6 +69,7 @@ obj-$(CONFIG_SENSORS_DRIVETEMP)	+= drivetemp.o
 obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
+obj-$(CONFIG_SENSORS_EMC230X)	+= emc230x.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
 obj-$(CONFIG_SENSORS_EMC6W201)	+= emc6w201.o
 obj-$(CONFIG_SENSORS_F71805F)	+= f71805f.o
drivers/hwmon/emc230x.c new file +587 -0

587 lines not on this page · raw message

Signature · 1 line
2.30.1
#2 lore raw

PATCH 2/3 dt-bindings: add binding for Microchip EMC230X fan controller family

In reply to Mathew McBride

Add a binding for the Microchip EMC230X fan controller family, which is supported by the new "emc230x" hwmon driver.

---
 .../bindings/hwmon/microchip,emc2301.yaml     | 83 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/microchip,emc2301.yaml
Documentation/devicetree/bindings/hwmon/microchip,emc2301.yaml new file +83 -0
new file mode 100644
index 000000000000..1e5c7072caee
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/microchip,emc2301.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip EMC230X family RPM fan controller
+
+maintainers:
+  - Mathew McBride <[email protected]>
+
+description: |
+  The Microchip EMC230X family (formerly produced by SMSC) is a family
+  of fan controllers which can drive via a set PWM period or
+  to a target RPM speed. They are available in variants from 1 to 5
+  independent channels.
+
+  Product information:
+  https://www.microchip.com/en-us/product/EMC2301
+  https://www.microchip.com/en-us/product/EMC2302
+  https://www.microchip.com/en-us/product/EMC2303
+  https://www.microchip.com/en-us/product/EMC2305
+
+
+properties:
+  compatible:
+    enum:
+      - microchip,emc2301
+      - microchip,emc2302
+      - microchip,emc2303
+      - microchip,emc2305
+  reg:
+    maxItems: 1
+
+  "#address-cells": true
+
+  "#size-cells": true
+
+required:
+  - compatible
+  - reg
+
+patternProperties:
+  "fan@[0-9]+$":
+    type: object
+    description: Fan channel properties for use as a thermal cooling device
+
+    properties:
+      min-rpm:
+        description: Minimum fan RPM when used as a cooling device
+        maxItems: 1
+      max-rpm:
+        description: Maximum fan RPM when used as a cooling device
+        maxItems: 1
+      reg:
+        description: Channel number on EMC230X device the fan is attached to
+        maxItems: 1
+      "#cooling-cells":
+        const: 2
+    required:
+      - reg
+      - min-rpm
+      - max-rpm
+      - "#cooling-cells"
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        fanctrl@2f {
+            compatible = "microchip,emc2301";
+            reg = <0x2f>;
+
+            fan@0 {
+              min-rpm = /bits/ 16 <3500>;
+              max-rpm = /bits/ 16 <5000>;
+              reg = <0>;
+            }
+        };
+    };
MAINTAINERS +1 -0
index bf3c6c3c0492..5938780abe20 100644
@@ -8046,6 +8046,7 @@ MICROCHIP EMC230X PWM-FAN CONTROLLER DRIVERS
 M:	Mathew McBride <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/hwmon/microchip,emc2301.yaml
 F:	drivers/hwmon/emc230x.c
 
 MICROCHIP POLARFIRE FPGA DRIVERS
Signature · 1 line
2.30.1
#3 lore raw

PATCH 3/3 arm64: dts: ten64: add configuration for fan controller

In reply to Mathew McBride

The Ten64 desktop appliance has a Noctua NF-A4x20 PWM fan, controlled by a Microchip EMC2301 PWM fan controller.

This binding allows the fan speed to be slowed to a quieter level when the system is not busy.

Reference: https://ten64doc.traverse.com.au/hardware/fan-control/

---
 .../boot/dts/freescale/fsl-ls1088a-ten64.dts  | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1088a-ten64.dts +43 -0
index ef6c8967533e..fd8261c9a186 100644
@@ -87,6 +87,35 @@ sfp_xg1: dpmac1-sfp {
 		los-gpios = <&sfpgpio 7 GPIO_ACTIVE_HIGH>;
 		maximum-power-milliwatt = <2000>;
 	};
+
+	thermal-zones {
+		soc {
+			trips {
+				fanmid0: fanmid0 {
+					temperature = <60000>;
+					hysteresis = <2000>;
+					type = "active";
+				};
+
+				fanmax0: fanmax0 {
+					temperature = <70000>;
+					hysteresis = <2000>;
+					type = "active";
+				};
+			};
+
+			cooling-maps {
+				map2 {
+					trip = <&fanmid0>;
+					cooling-device = <&case_fan 0 6>;
+				};
+				map3 {
+					trip = <&fanmax0>;
+					cooling-device = <&case_fan 7 THERMAL_NO_LIMIT>;
+				};
+			};
+		};
+	};
 };
 
 /* XG1 - Upper SFP */
@@ -231,6 +260,20 @@ at97sc: tpm@29 {
 		compatible = "atmel,at97sc3204t";
 		reg = <0x29>;
 	};
+
+	fanctrl: emc2301@2f {
+		reg = <0x2f>;
+		compatible = "microchip,emc2301";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		case_fan: fan@0 {
+			reg = <0>;
+			min-rpm = /bits/ 16 <3000>;
+			max-rpm = /bits/ 16 <5500>;
+			#cooling-cells = <2>;
+		};
+	};
 };
 
 &i2c2 {
Signature · 1 line
2.30.1
maintainer
#4 lore raw
In reply to Mathew McBride
Quoted 7 lines · Mathew McBride

The Microchip EMC230X (formerly made by SMSC) family of fan controllers provide PWM control for up to 5 fans (in the EMC2305). The EMC230X is capable of maintaining (closed-loop) a target RPM speed through PWM.

This driver has been tested with the EMC2301 (on our Traverse Ten64 appliance) and with the EMC2305 demo board (ADM00879).

Quoted 8 lines

The driver is by no means complete, for example, further work would be required to support the different PWM output frequencies for voltage-based fan speed control. (So far this driver has only been tested with direct PWM capable fans, like the 4 pin fans found in recent PCs)

The emc230x driver also has thermal subsystem integration which allows the emc230x-controlled fan(s) to be used as cooling devices.

I just accepted a driver or emc2301/2/3/5. Please submit improvements on top of that driver if needed; we won't have competing drivers for the same chip in the kernel, and replacing a just accepted driver smply does not make any sense.

Guenter

#5 lore raw
Quoted 14 lines · Guenter Roeck
Quoted 13 lines · Mathew McBride

The Microchip EMC230X (formerly made by SMSC) family of fan controllers provide PWM control for up to 5 fans (in the EMC2305). The EMC230X is capable of maintaining (closed-loop) a target RPM speed through PWM.

This driver has been tested with the EMC2301 (on our Traverse Ten64 appliance) and with the EMC2305 demo board (ADM00879).

The driver is by no means complete, for example, further work would be required to support the different PWM output frequencies for voltage-based fan speed control. (So far this driver has only been tested with direct PWM capable fans, like the 4 pin fans found in recent PCs)

Quoted 7 lines
Quoted 2 lines

The emc230x driver also has thermal subsystem integration which allows the emc230x-controlled fan(s) to be used as cooling devices.

I just accepted a driver or emc2301/2/3/5. Please submit improvements on top of that driver if needed; we won't have competing drivers for the same chip in the kernel, and replacing a just accepted driver smply does not make any sense.

My apologies, I was unaware of the separate effort!
Mine has been out of tree for a long time and I finally had time to work on it recently.

There are several changes I can see that need to be made to the accepted one to work for our usecase.

Quoted 2 lines

Guenter