Skip to contentSkip to conversation

hwmon: max31790: support to config PWM as TACH

PATCH New Delphine CC Chiu 1 participant 3 messages Sep 21, 2023

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

cover hwmon: max31790: support to config PWM as TACH

Support to config PWM as TACH in MAX31790 driver.
Add binding document for MAX31790 driver.

Delphine CC Chiu (2):
hwmon: max31790: support to config PWM as TACH
dt-bindings: hwmon: add MAX31790

 .../bindings/hwmon/maxim,max31790.yaml        | 59 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 drivers/hwmon/max31790.c                      | 58 ++++++++++++++++++
 3 files changed, 123 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 hwmon: max31790: support to config PWM as TACH

The PWM outputs of max31790 could be used as tachometer inputs by setting the fan configuration register, but the driver doesn't support to config the PWM outputs as tachometer inputs currently.

Add a function to get properties of the setting of max31790 to config PWM outputs as tachometer inputs before initializing max31790. For example: set pwm-as-tach = <2 5> in DTS for max31790 and the driver will config PWMOUT2 and PWMOUT5 as TACH8 and TACH11.

---
 drivers/hwmon/max31790.c | 58 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
drivers/hwmon/max31790.c +58 -0
index 20bf5ffadefe..2a59415e6776 100644
@@ -480,6 +480,60 @@ static const struct hwmon_chip_info max31790_chip_info = {
 	.info = max31790_info,
 };
 
+static int max31790_config_pwm_as_tach(struct device *dev,
+				       struct i2c_client *client)
+{
+	struct device_node *np = dev->of_node;
+	int i, ret, size, channel;
+	u32 pwm_index[NR_CHANNEL] = { 0 };
+	u8 fan_config;
+
+	size = of_property_count_u32_elems(np, "pwm-as-tach");
+
+	if (size > 0 && size <= NR_CHANNEL) {
+		ret = of_property_read_u32_array(np, "pwm-as-tach", pwm_index,
+						 size);
+		if (ret) {
+			dev_err(dev,
+				"Property 'pwm-as-tach' cannot be read.\n");
+			return ret;
+		}
+
+		for (i = 0; i < size; i++) {
+			if (pwm_index[i] == 0 || pwm_index[i] > NR_CHANNEL) {
+				dev_err(dev, "Not support to config PWM %x.\n",
+					pwm_index[i]);
+				return -EOPNOTSUPP;
+			}
+
+			channel = pwm_index[i] - 1;
+			ret = i2c_smbus_read_byte_data(
+				client, MAX31790_REG_FAN_CONFIG(channel));
+			if (ret < 0) {
+				dev_err(dev,
+					"Read fan config for channel %d failed.\n",
+					channel);
+				return ret;
+			}
+			fan_config = ret;
+			fan_config |= (MAX31790_FAN_CFG_CTRL_MON |
+				       MAX31790_FAN_CFG_TACH_INPUT);
+
+			ret = i2c_smbus_write_byte_data(
+				client, MAX31790_REG_FAN_CONFIG(channel),
+				fan_config);
+			if (ret < 0) {
+				dev_err(dev,
+					"Write fan config for channel %d failed.\n",
+					channel);
+				return ret;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int max31790_init_client(struct i2c_client *client,
 				struct max31790_data *data)
 {
@@ -521,6 +575,10 @@ static int max31790_probe(struct i2c_client *client)
 	data->client = client;
 	mutex_init(&data->update_lock);
 
+	err = max31790_config_pwm_as_tach(dev, client);
+	if (err)
+		dev_crit(dev, "Config PWM as TACH failed.\n");
+
 	/*
 	 * Initialize the max31790 chip
 	 */
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 dt-bindings: hwmon: add MAX31790

In reply to Delphine CC Chiu

Add dt-bindings for the MAXIM MAX31790.

---
 .../bindings/hwmon/maxim,max31790.yaml        | 59 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml new file +59 -0
new file mode 100644
index 000000000000..2bd455b36b3f
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/maxim,max31790.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim max31790
+
+maintainers:
+  - Delphine CC Chiu  <[email protected]>
+
+description: |
+  The MAX31790 controls the speeds of up to six fans using
+  six independent PWM outputs. The desired fan speeds (or PWM duty cycles)
+  are written through the I2C	interface.
+  The outputs drive “4-wire” fans directly, or can be used to modulate
+  the fan’s power terminals using an external pass transistor.
+
+  Datasheets:
+    https://datasheets.maximintegrated.com/en/ds/MAX31790.pdf
+
+properties:
+  compatible:
+    enum:
+      - maxim,max31790
+
+  reg:
+    maxItems: 1
+
+  pwm-as-tach:
+    description: |
+      There are 6 PWM output channel in MAX31790 that allows to be configured
+      as a TACH input by setting the Fan Configuration register.
+      Config PWM output channels in the array as tachometer inputs.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    maxItems: 6
+    items:
+      enum: [1, 2, 3, 4, 5, 6]
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      pwm@20 {
+        compatible = "maxim,max31790";
+        reg = <0x20>;
+        pwm-as-tach = <2 5>;
+      };
+    };
MAINTAINERS +6 -0
index c772c88b6e05..88cc08a887ad 100644
@@ -1362,6 +1362,12 @@ F:	Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
 F:	Documentation/hwmon/max31760.rst
 F:	drivers/hwmon/max31760.c
 
+ANALOG DEVICES INC MAX31790 DRIVER
+M:	Delphine CC Chiu  <[email protected]>
+S:	Odd Fixes
+F:	Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
+F:	drivers/hwmon/max31790.c
+
 ANALOGBITS PLL LIBRARIES
 M:	Paul Walmsley <[email protected]>
 S:	Supported
Signature · 1 line
2.25.1