Merge tag 'backlight-next-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 14 Jan 2019 18:21:10 +0000 (06:21 +1200)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 14 Jan 2019 18:21:10 +0000 (06:21 +1200)
Pull backlight updates from Lee Jones:
 "Fix-ups:
   - Use new of_node_name_eq() API call

  Bug Fixes:
   - Internally track 'enabled' state in pwm_bl
   - Fix auto-generated pwm_bl brightness tables parsed by DT

* tag 'backlight-next-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight:
  backlight: 88pm860x_bl: Use of_node_name_eq for node name comparisons
  backlight: pwm_bl: Fix devicetree parsing with auto-generated brightness tables
  backlight: pwm_bl: Re-add driver internal enabled tracking

1  2 
drivers/video/backlight/pwm_bl.c

index f9ef0673a083cb63c776ca58631710e659329ee3,b7b5b31f382443fd05582521692a54d40f3a8052..feb90764a8117d2818960267a608c270024a2e07
@@@ -30,6 -30,7 +30,7 @@@ struct pwm_bl_data 
        struct device           *dev;
        unsigned int            lth_brightness;
        unsigned int            *levels;
+       bool                    enabled;
        struct regulator        *power_supply;
        struct gpio_desc        *enable_gpio;
        unsigned int            scale;
@@@ -50,7 -51,7 +51,7 @@@ static void pwm_backlight_power_on(stru
        int err;
  
        pwm_get_state(pb->pwm, &state);
-       if (state.enabled)
+       if (pb->enabled)
                return;
  
        err = regulator_enable(pb->power_supply);
@@@ -65,6 -66,8 +66,8 @@@
  
        if (pb->enable_gpio)
                gpiod_set_value_cansleep(pb->enable_gpio, 1);
+       pb->enabled = true;
  }
  
  static void pwm_backlight_power_off(struct pwm_bl_data *pb)
@@@ -72,7 -75,7 +75,7 @@@
        struct pwm_state state;
  
        pwm_get_state(pb->pwm, &state);
-       if (!state.enabled)
+       if (!pb->enabled)
                return;
  
        if (pb->enable_gpio)
@@@ -86,6 -89,7 +89,7 @@@
        pwm_apply_state(pb->pwm, &state);
  
        regulator_disable(pb->power_supply);
+       pb->enabled = false;
  }
  
  static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness)
@@@ -268,6 -272,16 +272,16 @@@ static int pwm_backlight_parse_dt(struc
  
        memset(data, 0, sizeof(*data));
  
+       /*
+        * These values are optional and set as 0 by default, the out values
+        * are modified only if a valid u32 value can be decoded.
+        */
+       of_property_read_u32(node, "post-pwm-on-delay-ms",
+                            &data->post_pwm_on_delay);
+       of_property_read_u32(node, "pwm-off-delay-ms", &data->pwm_off_delay);
+       data->enable_gpio = -EINVAL;
        /*
         * Determine the number of brightness levels, if this property is not
         * set a default table of brightness levels will be used.
                data->max_brightness--;
        }
  
-       /*
-        * These values are optional and set as 0 by default, the out values
-        * are modified only if a valid u32 value can be decoded.
-        */
-       of_property_read_u32(node, "post-pwm-on-delay-ms",
-                            &data->post_pwm_on_delay);
-       of_property_read_u32(node, "pwm-off-delay-ms", &data->pwm_off_delay);
-       data->enable_gpio = -EINVAL;
        return 0;
  }
  
@@@ -483,6 -488,7 +488,7 @@@ static int pwm_backlight_probe(struct p
        pb->check_fb = data->check_fb;
        pb->exit = data->exit;
        pb->dev = &pdev->dev;
+       pb->enabled = false;
        pb->post_pwm_on_delay = data->post_pwm_on_delay;
        pb->pwm_off_delay = data->pwm_off_delay;
  
                goto err_alloc;
        }
  
 -      if (!data->levels) {
 +      if (data->levels) {
 +              /*
 +               * For the DT case, only when brightness levels is defined
 +               * data->levels is filled. For the non-DT case, data->levels
 +               * can come from platform data, however is not usual.
 +               */
 +              for (i = 0; i <= data->max_brightness; i++) {
 +                      if (data->levels[i] > pb->scale)
 +                              pb->scale = data->levels[i];
 +
 +                      pb->levels = data->levels;
 +              }
 +      } else if (!data->max_brightness) {
 +              /*
 +               * If no brightness levels are provided and max_brightness is
 +               * not set, use the default brightness table. For the DT case,
 +               * max_brightness is set to 0 when brightness levels is not
 +               * specified. For the non-DT case, max_brightness is usually
 +               * set to some value.
 +               */
 +
 +              /* Get the PWM period (in nanoseconds) */
 +              pwm_get_state(pb->pwm, &state);
 +
                ret = pwm_backlight_brightness_default(&pdev->dev, data,
                                                       state.period);
                if (ret < 0) {
                                "failed to setup default brightness table\n");
                        goto err_alloc;
                }
 -      }
  
 -      for (i = 0; i <= data->max_brightness; i++) {
 -              if (data->levels[i] > pb->scale)
 -                      pb->scale = data->levels[i];
 +              for (i = 0; i <= data->max_brightness; i++) {
 +                      if (data->levels[i] > pb->scale)
 +                              pb->scale = data->levels[i];
  
 -              pb->levels = data->levels;
 +                      pb->levels = data->levels;
 +              }
 +      } else {
 +              /*
 +               * That only happens for the non-DT case, where platform data
 +               * sets the max_brightness value.
 +               */
 +              pb->scale = data->max_brightness;
        }
  
        pb->lth_brightness = data->lth_brightness * (state.period / pb->scale);