Skip to contentSkip to conversation

Add support for EMC2305 Fan Speed Controller.

PATCH Superseded [email protected] 2 participants 5 messages Aug 2, 2022 – Aug 10, 2022

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

v5 cover Add support for EMC2305 Fan Speed Controller.

From: Michael Shych <[email protected]>

Introduce EMC2305 RPM-based PWM Fan Speed Controller
The EMC2305 is an SMBus compliant fan controller with up to five controlled PWM fan drivers. All fan drivers are controlled by a programmable frequency PWM driver and Fan Speed Control algorithm that operates as a directly PWM-controlled device.

The closed-loop Fan Speed Control algorithm (FSC) has the capability to detect aging fans and alert the system. It will likewise detect stalled or locked fans and trigger an interrupt.

EMC2305 offers a clock output so that multiple devices may be chained and slaved to the same clock source for optimal performance in large distributed systems.

Patch set includes:
Patch#1 - define platform data for EMC2305 driver.
Patch#2 - add support for EMC2301/2/3/5 RPM-based PWM Fan Speed Controller. Patch#3 - add emc2305.rst into docs.

Michael Shych (3):
platform_data/emc2305: define platform data for EMC2305 driver
hwmon: (emc2305) add support for EMC2301/2/3/5 RPM-based PWM Fan Speed
Controller.
docs: hwmon: add emc2305.rst to docs

 Documentation/hwmon/emc2305.rst       |  40 +++
 Documentation/hwmon/index.rst         |   1 +
 drivers/hwmon/Kconfig                 |  13 +
 drivers/hwmon/Makefile                |   1 +
 drivers/hwmon/emc2305.c               | 624 ++++++++++++++++++++++++++++++++++
 include/linux/platform_data/emc2305.h |  22 ++
 6 files changed, 701 insertions(+)
 create mode 100644 Documentation/hwmon/emc2305.rst
 create mode 100644 drivers/hwmon/emc2305.c
 create mode 100644 include/linux/platform_data/emc2305.h
Signature · 1 line
2.14.1
#1 lore raw

PATCH v5 1/3 platform_data/emc2305: define platform data for EMC2305 driver

From: Michael Shych <[email protected]>

Introduce platform data structure for EM2305 driver to allow configuration device PWMs and thermal zones by passing required platform data to the driver. If no platform data is provided, the driver is supposed to work with default settings.

---
 include/linux/platform_data/emc2305.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 include/linux/platform_data/emc2305.h
include/linux/platform_data/emc2305.h new file +22 -0
new file mode 100644
index 000000000000..54d672dd6f7d
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_PLATFORM_DATA_EMC2305__
+#define __LINUX_PLATFORM_DATA_EMC2305__
+
+#define EMC2305_PWM_MAX	5
+
+/**
+ * struct emc2305_platform_data - EMC2305 driver platform data
+ * @max_state: maximum cooling state of the cooling device;
+ * @pwm_num: number of active channels;
+ * @pwm_separate: separate PWM settings for every channel;
+ * @pwm_min: array of minimum PWM per channel;
+ */
+struct emc2305_platform_data {
+	u8 max_state;
+	u8 pwm_num;
+	bool pwm_separate;
+	u8 pwm_min[EMC2305_PWM_MAX];
+};
+
+#endif
Signature · 1 line
2.14.1
#2 lore raw

PATCH v5 2/3 hwmon: (emc2305) add support for EMC2301/2/3/5 RPM-based PWM Fan Speed Controller.

In reply to [email protected]

From: Michael Shych <[email protected]>

Add driver for Microchip EMC2301/2/3/5 RPM-based PWM Fan Speed Controller. Modify Makefile and Kconfig to support Microchip EMC2305 RPM-based PWM Fan Speed Controller.

---
v5->v4
Changes added by Michael Shych:
- Remove OF interface;
- Add optional way to pass info to the driver through platform data;
- Fix 0 RPM report.
v3->v4
Changes pointed out by Guenter Roeck:
- Add error check in functions returns;
- Typo fix;
- Change error code in return;
- Change if case.
v2->v3
Change pointed out by Guenter Roeck:
- Change casting from const pointer;
- Remove pwm_max per channel parameter.
Changes added by Michael Shych:
- Add pwm_separate field instead using of a special case of pwm_channel;
- Change the mechanism of obtaining a number of pwm channels. v1->v2
Changes pointed out by Guenter Roeck:
- Remove unnecessary include;
- Standard multi-line comments form;
- Defines indentation;
- Remove unnecessary returns;
- Add validation of received dt parameters;
- Remove unnecessary brackets;
Changes added by Michael Shych:
- Fix initial PWM settings;
- Change PWM write in case of common PWM channel;
- Separate pwm-min, pwm-max per PWM channel.

---
 drivers/hwmon/Kconfig   |  13 +
 drivers/hwmon/Makefile  |   1 +
 drivers/hwmon/emc2305.c | 624 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 638 insertions(+)
 create mode 100644 drivers/hwmon/emc2305.c
drivers/hwmon/Kconfig +13 -0
index e70d9614bec2..1ebc8e6c86f1 100644
@@ -1785,6 +1785,19 @@ config SENSORS_EMC2103
 	  This driver can also be built as a module. If so, the module
 	  will be called emc2103.
 
+config SENSORS_EMC2305
+	tristate "Microchip EMC2305 and compatible EMC2301/2/3"
+	depends on I2C
+	imply THERMAL
+	help
+	  If you say yes here you get support for the Microchip EMC2305
+	  fan controller chips.
+	  The Microchip EMC2305 is a fan controller for up to 5 fans.
+	  Fan rotation speeds are reported in RPM.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called emc2305.
+
 config SENSORS_EMC6W201
 	tristate "SMSC EMC6W201"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index 007e829d1d0d..7706557dfa86 100644
@@ -70,6 +70,7 @@ obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
+obj-$(CONFIG_SENSORS_EMC2305)	+= emc2305.o
 obj-$(CONFIG_SENSORS_EMC6W201)	+= emc6w201.o
 obj-$(CONFIG_SENSORS_F71805F)	+= f71805f.o
 obj-$(CONFIG_SENSORS_F71882FG)	+= f71882fg.o
drivers/hwmon/emc2305.c new file +624 -0

624 lines not on this page · raw message

Signature · 1 line
2.14.1
#3 lore raw

PATCH v5 3/3 docs: hwmon: add emc2305.rst to docs

In reply to [email protected]

From: Michael Shych <[email protected]>

Add description of emc2305 driver.

---
v1->v2
- Add document to index.rst

---
 Documentation/hwmon/emc2305.rst | 40 ++++++++++++++++++++++++++++++++++++++++
 Documentation/hwmon/index.rst   |  1 +
 2 files changed, 41 insertions(+)
 create mode 100644 Documentation/hwmon/emc2305.rst
Documentation/hwmon/emc2305.rst new file +40 -0
new file mode 100644
index 000000000000..258da49d18f9
@@ -0,0 +1,40 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver emc2305
+=====================
+
+Supported chips:
+   Microchip EMC2305, EMC2303, EMC2302, EMC2301
+
+   Addresses scanned: I2C 0x27, 0x2c, 0x2d, 0x2e, 0x2f, 0x4c, 0x4d
+   Prefixes: 'emc2305'
+
+   Datasheet: Publicly available at the Microchip website :
+      https://www.microchip.com/en-us/product/EMC2305
+
+Description:
+-----------
+This driver implements support for Microchip EMC2301/2/3/5 RPM-based PWM Fan Controller.
+The EMC2305 Fan Controller supports up to 5 independently controlled PWM fan drives.
+Fan rotation speeds are reported in RPM.
+The driver supports the RPM-based PWM control to keep a fan at the desired speed.
+The driver provides the possibility to have one common PWM interface for all FANs
+or up to the maximum available or configured independent PWMs.
+
+The driver provides the following sysfs interfaces in hwmon subsystem:
+
+================= == ===================================================
+fan[1-5]_fault    RO files for tachometers TACH1-TACH5 fault indication
+fan[1-5]_input    RO files for tachometers TACH1-TACH5 input (in RPM)
+pwm[1-5]          RW file for fan[1-5] target duty cycle (0..255)
+================= == ===================================================
+
+sysfs interfaces in thermal subsystem:
+
+================= == ========================================================================
+cur_state         RW file for the current cooling state of the cooling device (0..max_state)
+max_state         RO file for the maximum cooling state of the cooling device
+================= == ========================================================================
+
+Configuration is possible via device tree:
+Documentation/devicetree/bindings/hwmon/microchip,emc2305.yaml
Documentation/hwmon/index.rst +1 -0
index f7113b0f8b2a..83b082d222af 100644
@@ -63,6 +63,7 @@ Hardware Monitoring Kernel Drivers
    ds620
    emc1403
    emc2103
+   emc2305
    emc6w201
    f71805f
    f71882fg
Signature · 1 line
2.14.1
maintainer
#4 lore raw
In reply to [email protected]
Quoted 34 lines · On 8/2/22 01:18, [email protected] wrote:

From: Michael Shych <[email protected]>

Introduce EMC2305 RPM-based PWM Fan Speed Controller
The EMC2305 is an SMBus compliant fan controller with up to five controlled PWM fan drivers. All fan drivers are controlled by a programmable frequency PWM driver and Fan Speed Control algorithm that operates as a directly PWM-controlled device.

The closed-loop Fan Speed Control algorithm (FSC) has the capability to detect aging fans and alert the system. It will likewise detect stalled or locked fans and trigger an interrupt.

EMC2305 offers a clock output so that multiple devices may be chained and slaved to the same clock source for optimal performance in large distributed systems.

Patch set includes:
Patch#1 - define platform data for EMC2305 driver.
Patch#2 - add support for EMC2301/2/3/5 RPM-based PWM Fan Speed Controller. Patch#3 - add emc2305.rst into docs.

Michael Shych (3):
platform_data/emc2305: define platform data for EMC2305 driver
hwmon: (emc2305) add support for EMC2301/2/3/5 RPM-based PWM Fan Speed
Controller.
docs: hwmon: add emc2305.rst to docs

  Documentation/hwmon/emc2305.rst       |  40 +++
  Documentation/hwmon/index.rst         |   1 +
  drivers/hwmon/Kconfig                 |  13 +
  drivers/hwmon/Makefile                |   1 +
  drivers/hwmon/emc2305.c               | 624 ++++++++++++++++++++++++++++++++++
  include/linux/platform_data/emc2305.h |  22 ++
  6 files changed, 701 insertions(+)
Quoted 4 lines

create mode 100644 Documentation/hwmon/emc2305.rst create mode 100644 drivers/hwmon/emc2305.c create mode 100644 include/linux/platform_data/emc2305.h

Please provide a change log.

Guenter