[PATCH v2 2/3] hwmon: emc2305: Add device tree support for polarity and pwm output
florin.leotescu at oss.nxp.com
florin.leotescu at oss.nxp.com
Wed Feb 19 05:32:20 PST 2025
From: Florin Leotescu <florin.leotescu at nxp.com>
The patch enhances emc2305 driver by adding support for configuring
pwm output and polarity via Device Tree properties.
Signed-off-by: Florin Leotescu <florin.leotescu at nxp.com>
---
drivers/hwmon/emc2305.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c
index 5d8fb7526e23..e646221ab65d 100644
--- a/drivers/hwmon/emc2305.c
+++ b/drivers/hwmon/emc2305.c
@@ -23,6 +23,8 @@
#define EMC2305_TACH_REGS_UNUSE_BITS 3
#define EMC2305_TACH_CNT_MULTIPLIER 0x02
#define EMC2305_TACH_RANGE_MIN 480
+#define EMC2305_REG_DRIVE_PWM_OUT_CONFIG 0x2b
+#define EMC2305_REG_POLARITY 0x2a
#define EMC2305_PWM_DUTY2STATE(duty, max_state, pwm_max) \
DIV_ROUND_CLOSEST((duty) * (max_state), (pwm_max))
@@ -523,6 +525,8 @@ static int emc2305_probe(struct i2c_client *client)
int vendor;
int ret;
int i;
+ int pwm_polarity;
+ int pwm_output;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV;
@@ -576,6 +580,29 @@ static int emc2305_probe(struct i2c_client *client)
return ret;
}
+ if (!of_property_read_u32(dev->of_node, "pwm_output", &pwm_output)) {
+ dev_dbg(dev, "Configuring pwm output\n");
+ if (pwm_output >= 0 && pwm_output <= ((1 << data->pwm_num) - 1)) {
+ ret = i2c_smbus_write_byte_data(client, EMC2305_REG_DRIVE_PWM_OUT_CONFIG,
+ pwm_output);
+ if (ret < 0)
+ dev_err(dev, "Failed to configure pwm output, using default\n");
+ } else {
+ dev_err(dev, "Wrong PWM output config provided: %u\n", pwm_output);
+ }
+ }
+
+ if (!of_property_read_u32(dev->of_node, "pwm_polarity", &pwm_polarity)) {
+ dev_dbg(dev, "Configuring pwm polarity\n");
+ if (pwm_polarity >= 0 && pwm_polarity <= ((1 << data->pwm_num) - 1)) {
+ ret = i2c_smbus_write_byte_data(client, EMC2305_REG_POLARITY, pwm_polarity);
+ if (ret < 0)
+ dev_err(dev, "Failed to configure pwm polarity, using default\n");
+ } else {
+ dev_err(dev, "Wrong PWM polarity config provided: %u\n", pwm_polarity);
+ }
+ }
+
for (i = 0; i < data->pwm_num; i++) {
ret = i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_MIN_DRIVE(i),
data->pwm_min[i]);
--
2.34.1
More information about the linux-arm-kernel
mailing list