Support to config PWM as TACH in MAX31790 driver.
Add binding document for MAX31790 driver.
---
Changelog:
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 (2):
hwmon: max31790: support to config PWM as TACH
dt-bindings: hwmon: add MAX31790
.../bindings/hwmon/maxim,max31790.yaml | 89 +++++++++++++++++++
MAINTAINERS | 6 ++
drivers/hwmon/max31790.c | 83 +++++++++++++++++
3 files changed, 178 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
--
2.25.1
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.
Signed-off-by: Delphine CC Chiu <[email protected]>
---
Changelog:
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(+)
diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
index 0cd44c1e998a..378ff32c7c1e 100644
--- a/drivers/hwmon/max31790.c
+++ b/drivers/hwmon/max31790.c
@@ -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
*/
--
2.25.1
Add dt-bindings for the MAXIM MAX31790.
Signed-off-by: Delphine CC Chiu <[email protected]>
---
Changelog:
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
diff --git a/Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml b/Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
new file mode 100644
index 000000000000..7f717ab4caac
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
@@ -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";
+ };
+ };
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index c8fdd0d03907..21be46200343 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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
--
2.25.1