From: Uwe Kleine-König Date: Thu, 19 Jun 2025 19:37:45 +0000 (+0200) Subject: hwmon: (adt7475) Implement support for #pwm-cells = <3> X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50f16073d175670f41f3f64ae64ab66a745fd58b;p=thirdparty%2Fkernel%2Flinux.git hwmon: (adt7475) Implement support for #pwm-cells = <3> The adt7475 driver and binding are outliers requiring 4 pwm-cells. The typical value is 3, there are a few devices that use a lesser value for historical reasons, no other uses a value bigger than 3. Implement support for 3 cells to make the adt7475 binding match the usual PWM binding. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/b5cc994cbe74095e39468fd694c721d7c879db78.1750361514.git.u.kleine-koenig@baylibre.com Signed-off-by: Guenter Roeck --- diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 5f2541c11fe9b..8cefa14e1633b 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1704,12 +1704,15 @@ static int adt7475_pwm_properties_parse_reference_args(struct fwnode_handle *fwn if (ret) return ret; - if (rargs.nargs != 4) { + if (rargs.nargs != 3 && rargs.nargs != 4) { fwnode_handle_put(rargs.fwnode); return -EINVAL; } - for (i = 0; i < 4; i++) + /* Let duty_cycle default to period */ + args[3] = rargs.args[1]; + + for (i = 0; i < rargs.nargs; i++) args[i] = rargs.args[i]; ret = _adt7475_pwm_properties_parse_args(args, cfg); @@ -1724,11 +1727,22 @@ static int adt7475_pwm_properties_parse_args(struct fwnode_handle *fwnode, { int ret; u32 args[4] = {}; + size_t n_vals = fwnode_property_count_u32(fwnode, "pwms"); + + if (n_vals != 3 && n_vals != 4) + return -EOVERFLOW; - ret = fwnode_property_read_u32_array(fwnode, "pwms", args, ARRAY_SIZE(args)); + ret = fwnode_property_read_u32_array(fwnode, "pwms", args, n_vals); if (ret) return ret; + /* + * If there are no item to define the duty_cycle, default it to the + * period. + */ + if (n_vals == 3) + args[3] = args[1]; + return _adt7475_pwm_properties_parse_args(args, cfg); }