]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (adt7475) Implement support for #pwm-cells = <3>
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Thu, 19 Jun 2025 19:37:45 +0000 (21:37 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 20 Jul 2025 23:38:34 +0000 (16:38 -0700)
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 <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/b5cc994cbe74095e39468fd694c721d7c879db78.1750361514.git.u.kleine-koenig@baylibre.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/adt7475.c

index 5f2541c11fe9ba25cc97aa9046e65fb6ab0293b4..8cefa14e1633b96e72b06eab21962d8b2306f9ba 100644 (file)
@@ -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);
 }