pwm: make the PWM_POLARITY flag optional
authorLothar Waßmann <LW@KARO-electronics.de>
Tue, 3 Nov 2015 10:20:06 +0000 (11:20 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 3 Nov 2015 10:20:06 +0000 (11:20 +0100)
drivers/pwm/core.c

index 3f9df3e..c118515 100644 (file)
@@ -136,9 +136,14 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
 {
        struct pwm_device *pwm;
 
+       /* check, whether the driver supports a third cell for flags */
        if (pc->of_pwm_n_cells < 3)
                return ERR_PTR(-EINVAL);
 
+       /* flags in the third cell are optional */
+       if (args->args_count < 2)
+               return ERR_PTR(-EINVAL);
+
        if (args->args[0] >= pc->npwm)
                return ERR_PTR(-EINVAL);
 
@@ -148,10 +153,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
 
        pwm_set_period(pwm, args->args[1]);
 
-       if (args->args[2] & PWM_POLARITY_INVERTED)
-               pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
-       else
-               pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+       if (args->args_count > 2) {
+               if (args->args[2] & PWM_POLARITY_INVERTED)
+                       pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
+               else
+                       pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+       }
 
        return pwm;
 }
@@ -162,9 +169,14 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
 {
        struct pwm_device *pwm;
 
+       /* sanity check driver support */
        if (pc->of_pwm_n_cells < 2)
                return ERR_PTR(-EINVAL);
 
+       /* all cells are required */
+       if (args->args_count != pc->of_pwm_n_cells)
+               return ERR_PTR(-EINVAL);
+
        if (args->args[0] >= pc->npwm)
                return ERR_PTR(-EINVAL);
 
@@ -576,13 +588,6 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
                goto put;
        }
 
-       if (args.args_count != pc->of_pwm_n_cells) {
-               pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
-                        args.np->full_name);
-               pwm = ERR_PTR(-EINVAL);
-               goto put;
-       }
-
        pwm = pc->of_xlate(pc, &args);
        if (IS_ERR(pwm))
                goto put;