hwmon: max31790: support to config PWM as TACH
Subsystems (3)
v4 cover hwmon: max31790: support to config PWM as TACH
Support to config PWM as TACH in MAX31790 driver. Add binding document for MAX31790 driver. Add fanN_enable for all fans
---
Changelog:
v4 - Add fanN_enable for all fans.
v3 - Use 'sensor-type' in 'channel' node to config pwm as tach.
- Changed the status in MAINTAINERS to 'Maintained'.
v2 - Remove unnecessary parentheses.
- Add more error handling.
- Change the type of "pwm-as-tach" from u8 to u32 to match binding document.
- Add dt-bindings for the MAXIM MAX31790.
v1 - Support to config PWM as TACH
Delphine CC Chiu (3):
hwmon: max31790: support to config PWM as TACH
dt-bindings: hwmon: add MAX31790
hwmon: max31790: add fanN_enable for all fans
.../bindings/hwmon/maxim,max31790.yaml | 89 +++++++++++ Documentation/hwmon/max31790.rst | 2 +- MAINTAINERS | 6 + drivers/hwmon/max31790.c | 140 ++++++++++++++---- 4 files changed, 210 insertions(+), 27 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
Signature · 1 line
2.25.1
PATCH v4 1/3 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.
---
Changelog:
v4 - No change.
v3 - Use 'sensor-type' in 'channel' node to config pwm as tach. v2 - Remove unnecessary parentheses.
- Add more error handling.
- Change the type of "pwm-as-tach" from u8 to u32 to match binding document.
v1 - Support to config PWM as TACH
--- drivers/hwmon/max31790.c | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
drivers/hwmon/max31790.c +83 -0
@@ -480,6 +480,85 @@ static const struct hwmon_chip_info max31790_chip_info = { .info = max31790_info, }; +static int max31790_config_pwm_as_tach (struct i2c_client *client, +struct device *dev, +struct device_node *node) +{ +int ret, channel; +u32 reg; +u8 fan_config; +const char *type_str; + +if (!node->name ||of_node_cmp (node->name,"channel" )) +return 0 ; + +if (of_property_read_u32 (node,"reg" , ®)) { +dev_err (dev,"Could not read reg value for '%s'\n" , + node->full_name); +return -EINVAL ; + } + +if (reg >NR_CHANNEL || reg ==0 ) { +dev_err (dev,"Invalid reg (%u) in '%s'\n" , reg, + node->full_name); +return -EINVAL ; + } + + channel = (int )reg -1 ; + +if (of_property_read_string (node,"sensor-type" , &type_str)) { +dev_info ( + dev, +"No sensor-type for '%s', use default setting as PWM output.\n" , + node->full_name); +return 0 ; + } + +if (!strcmp (type_str,"TACH" )) { + 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_configure_channels (struct i2c_client *client, +struct device *dev) +{ +struct device_node *node; +int err; + +if (dev->of_node) { +for_each_child_of_node (dev->of_node, node) { + err =max31790_config_pwm_as_tach (client, dev, node); +if (err) { +dev_err (dev,"Configure for %s failed.\n" , + node->full_name); +return err; + } + } + } + +return 0 ; +} +static int max31790_init_client (struct i2c_client *client,struct max31790_data *data) {
@@ -521,6 +600,10 @@ static int max31790_probe(struct i2c_client *client) data->client = client;mutex_init (&data->update_lock); + err =max31790_configure_channels (client, dev); +if (err) +dev_crit (dev,"Config PWM as TACH failed.\n" ); +/* * Initialize the max31790 chip */
Signature · 1 line
2.25.1
PATCH v4 2/3 dt-bindings: hwmon: add MAX31790
In reply to Delphine CC ChiuAdd dt-bindings for the MAXIM MAX31790.
---
Changelog:
v4 - No change.
v3 - Use 'sensor-type' in 'channel' node to config pwm as tach.
- Changed the status in MAINTAINERS to 'Maintained'.
v2 - Add dt-bindings for the MAXIM MAX31790.
--- .../bindings/hwmon/maxim,max31790.yaml | 89 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 95 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml new file +89 -0
@@ -0,0 +1,89 @@ +# 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 + +additionalProperties: false + +properties: + compatible: + enum: + - maxim,max31790 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^channel@[1-6]$": + type: object + + additionalProperties: false + + properties: + reg: + items: + - enum: [1, 2, 3, 4, 5, 6] + + # There are 6 PWM output channel in MAX31790 that allows to be configured + # as a TACH input by setting the Fan Configuration register. + # The default setting will be PWM output. + sensor-type: + items: + - enum: + - PWM + - TACH + + required: + - reg + +required: + - compatible + - reg + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pwm@20 { + compatible = "maxim,max31790"; + reg = <0x20>; + + #address-cells = <1>; + #size-cells = <0>; + + channel@3 { + reg = <3>; + sensor-type = "TACH"; + }; + + channel@6 { + reg = <6>; + sensor-type = "TACH"; + }; + }; + };
MAINTAINERS +6 -0
@@ -1371,6 +1371,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: Maintained +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
PATCH v4 3/3 hwmon: max31790: add fanN_enable for all fans
In reply to Delphine CC ChiuThe fanN_enable will be set in dbus-sensors service according to the index of TACH that filled in the configuration of entity-manager. Add fanN_enable for all fans to prevent dbus-sensors service couldn't find the corresponding fanN_enable for fanN_input.
---
Changelog:
v4 - Add fanN_enable for all fans.
--- Documentation/hwmon/max31790.rst | 2 +- drivers/hwmon/max31790.c | 57 +++++++++++++++++--------------- 2 files changed, 32 insertions(+), 27 deletions(-)
Documentation/hwmon/max31790.rst +1 -1
@@ -38,7 +38,7 @@ Sysfs entries fan[1-12]_input RO fan tachometer speed in RPM fan[1-12]_fault RO fan experienced fault fan[1-6]_target RW desired fan speed in RPM -fan[1-6]_enable RW enable or disable the tachometer input +fan[1-12]_enable RW enable or disable the tachometer input pwm[1-6]_enable RW regulator mode, 0=disabled (duty cycle=0%), 1=manual mode, 2=rpm mode pwm[1-6] RW read: current pwm duty cycle, write: target pwm duty cycle (0-255)
drivers/hwmon/max31790.c +31 -26
90 lines not on this page · raw message
Signature · 1 line
2.25.1