* [PATCH v4 1/3] hwmon: max31790: support to config PWM as TACH
2023-11-02 3:28 [PATCH v4 0/3] hwmon: max31790: support to config PWM as TACH Delphine CC Chiu
@ 2023-11-02 3:28 ` Delphine CC Chiu
2023-11-02 3:28 ` [PATCH v4 2/3] dt-bindings: hwmon: add MAX31790 Delphine CC Chiu
2023-11-02 3:28 ` [PATCH v4 3/3] hwmon: max31790: add fanN_enable for all fans Delphine CC Chiu
2 siblings, 0 replies; 4+ messages in thread
From: Delphine CC Chiu @ 2023-11-02 3:28 UTC (permalink / raw)
To: patrick, Delphine CC Chiu, Jean Delvare, Guenter Roeck
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
linux-hwmon, devicetree, linux-kernel, linux-doc
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 <Delphine_CC_Chiu@wiwynn.com>
---
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(+)
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
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v4 2/3] dt-bindings: hwmon: add MAX31790
2023-11-02 3:28 [PATCH v4 0/3] hwmon: max31790: support to config PWM as TACH Delphine CC Chiu
2023-11-02 3:28 ` [PATCH v4 1/3] " Delphine CC Chiu
@ 2023-11-02 3:28 ` Delphine CC Chiu
2023-11-02 3:28 ` [PATCH v4 3/3] hwmon: max31790: add fanN_enable for all fans Delphine CC Chiu
2 siblings, 0 replies; 4+ messages in thread
From: Delphine CC Chiu @ 2023-11-02 3:28 UTC (permalink / raw)
To: patrick, Delphine CC Chiu, Jean Delvare, Guenter Roeck,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Jonathan Corbet, linux-hwmon, devicetree, linux-kernel, linux-doc
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3325 bytes --]
Add dt-bindings for the MAXIM MAX31790.
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
---
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
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 <Delphine_CC_Chiu@wiwynn.com>
+
+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 43c5ed3c4508..707f1b903f60 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 <Delphine_CC_Chiu@wiwynn.com>
+S: Maintained
+F: Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml
+F: drivers/hwmon/max31790.c
+
ANALOGBITS PLL LIBRARIES
M: Paul Walmsley <paul.walmsley@sifive.com>
S: Supported
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v4 3/3] hwmon: max31790: add fanN_enable for all fans
2023-11-02 3:28 [PATCH v4 0/3] hwmon: max31790: support to config PWM as TACH Delphine CC Chiu
2023-11-02 3:28 ` [PATCH v4 1/3] " Delphine CC Chiu
2023-11-02 3:28 ` [PATCH v4 2/3] dt-bindings: hwmon: add MAX31790 Delphine CC Chiu
@ 2023-11-02 3:28 ` Delphine CC Chiu
2 siblings, 0 replies; 4+ messages in thread
From: Delphine CC Chiu @ 2023-11-02 3:28 UTC (permalink / raw)
To: patrick, Jean Delvare, Guenter Roeck, Jonathan Corbet, Delphine CC Chiu
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-hwmon,
devicetree, linux-kernel, linux-doc
The 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.
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
---
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(-)
diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst
index 33c5c7330efc..510d5691b18b 100644
--- a/Documentation/hwmon/max31790.rst
+++ b/Documentation/hwmon/max31790.rst
@@ -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)
diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
index 378ff32c7c1e..fa31e108c7ce 100644
--- a/drivers/hwmon/max31790.c
+++ b/drivers/hwmon/max31790.c
@@ -203,7 +203,8 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel,
mutex_unlock(&data->update_lock);
return 0;
case hwmon_fan_enable:
- *val = !!(data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT_EN);
+ *val = !!(data->fan_config[channel % NR_CHANNEL] &
+ MAX31790_FAN_CFG_TACH_INPUT_EN);
return 0;
default:
return -EOPNOTSUPP;
@@ -242,12 +243,12 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel,
data->target_count[channel] = target_count << 5;
- err = i2c_smbus_write_word_swapped(client,
- MAX31790_REG_TARGET_COUNT(channel),
- data->target_count[channel]);
+ err = i2c_smbus_write_word_swapped(
+ client, MAX31790_REG_TARGET_COUNT(channel),
+ data->target_count[channel]);
break;
case hwmon_fan_enable:
- fan_config = data->fan_config[channel];
+ fan_config = data->fan_config[channel % NR_CHANNEL];
if (val == 0) {
fan_config &= ~MAX31790_FAN_CFG_TACH_INPUT_EN;
} else if (val == 1) {
@@ -256,11 +257,14 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel,
err = -EINVAL;
break;
}
- if (fan_config != data->fan_config[channel]) {
- err = i2c_smbus_write_byte_data(client, MAX31790_REG_FAN_CONFIG(channel),
- fan_config);
+ if (fan_config != data->fan_config[channel % NR_CHANNEL]) {
+ err = i2c_smbus_write_byte_data(
+ client,
+ MAX31790_REG_FAN_CONFIG(channel % NR_CHANNEL),
+ fan_config);
if (!err)
- data->fan_config[channel] = fan_config;
+ data->fan_config[channel % NR_CHANNEL] =
+ fan_config;
}
break;
default:
@@ -291,7 +295,8 @@ static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel)
return 0644;
return 0;
case hwmon_fan_enable:
- if (channel < NR_CHANNEL)
+ if (channel < NR_CHANNEL ||
+ (fan_config & MAX31790_FAN_CFG_TACH_INPUT))
return 0644;
return 0;
default:
@@ -445,22 +450,22 @@ static umode_t max31790_is_visible(const void *data,
}
}
-static const struct hwmon_channel_info * const max31790_info[] = {
- HWMON_CHANNEL_INFO(fan,
- HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
- HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
- HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
- HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
- HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
- HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
- HWMON_F_INPUT | HWMON_F_FAULT,
- HWMON_F_INPUT | HWMON_F_FAULT,
- HWMON_F_INPUT | HWMON_F_FAULT,
- HWMON_F_INPUT | HWMON_F_FAULT,
- HWMON_F_INPUT | HWMON_F_FAULT,
- HWMON_F_INPUT | HWMON_F_FAULT),
- HWMON_CHANNEL_INFO(pwm,
- HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+static const struct hwmon_channel_info *const max31790_info[] = {
+ HWMON_CHANNEL_INFO(
+ fan,
+ HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+ HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE),
+ HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread