Skip to content

Commit 50f1607

Browse files
ukleinekgroeck
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/b5cc994cbe74095e39468fd694c721d7c879db78.1750361514.git.u.kleine-koenig@baylibre.com Signed-off-by: Guenter Roeck <[email protected]>
1 parent 75ca1e5 commit 50f1607

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

drivers/hwmon/adt7475.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,12 +1704,15 @@ static int adt7475_pwm_properties_parse_reference_args(struct fwnode_handle *fwn
17041704
if (ret)
17051705
return ret;
17061706

1707-
if (rargs.nargs != 4) {
1707+
if (rargs.nargs != 3 && rargs.nargs != 4) {
17081708
fwnode_handle_put(rargs.fwnode);
17091709
return -EINVAL;
17101710
}
17111711

1712-
for (i = 0; i < 4; i++)
1712+
/* Let duty_cycle default to period */
1713+
args[3] = rargs.args[1];
1714+
1715+
for (i = 0; i < rargs.nargs; i++)
17131716
args[i] = rargs.args[i];
17141717

17151718
ret = _adt7475_pwm_properties_parse_args(args, cfg);
@@ -1724,11 +1727,22 @@ static int adt7475_pwm_properties_parse_args(struct fwnode_handle *fwnode,
17241727
{
17251728
int ret;
17261729
u32 args[4] = {};
1730+
size_t n_vals = fwnode_property_count_u32(fwnode, "pwms");
1731+
1732+
if (n_vals != 3 && n_vals != 4)
1733+
return -EOVERFLOW;
17271734

1728-
ret = fwnode_property_read_u32_array(fwnode, "pwms", args, ARRAY_SIZE(args));
1735+
ret = fwnode_property_read_u32_array(fwnode, "pwms", args, n_vals);
17291736
if (ret)
17301737
return ret;
17311738

1739+
/*
1740+
* If there are no item to define the duty_cycle, default it to the
1741+
* period.
1742+
*/
1743+
if (n_vals == 3)
1744+
args[3] = args[1];
1745+
17321746
return _adt7475_pwm_properties_parse_args(args, cfg);
17331747
}
17341748

0 commit comments

Comments
 (0)