Commit 51d53e5b authored by Sam Ravnborg's avatar Sam Ravnborg Committed by Lee Jones

backlight: Use backlight_get_brightness() throughout

Introduce the backlight_get_brightness() helper in all
video/backlight/* drivers. This simplifies the code and align the
implementation of the update_status() operation across the different
backlight drivers.

Some of the drivers gains a little extra functionality by the change
as they now respect the fb_blank() ioctl.
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent a00a5feb
...@@ -121,18 +121,7 @@ static int pm860x_backlight_set(struct backlight_device *bl, int brightness) ...@@ -121,18 +121,7 @@ static int pm860x_backlight_set(struct backlight_device *bl, int brightness)
static int pm860x_backlight_update_status(struct backlight_device *bl) static int pm860x_backlight_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return pm860x_backlight_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.state & BL_CORE_SUSPENDED)
brightness = 0;
return pm860x_backlight_set(bl, brightness);
} }
static int pm860x_backlight_get_brightness(struct backlight_device *bl) static int pm860x_backlight_get_brightness(struct backlight_device *bl)
......
...@@ -65,15 +65,7 @@ static int adp5520_bl_set(struct backlight_device *bl, int brightness) ...@@ -65,15 +65,7 @@ static int adp5520_bl_set(struct backlight_device *bl, int brightness)
static int adp5520_bl_update_status(struct backlight_device *bl) static int adp5520_bl_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return adp5520_bl_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
return adp5520_bl_set(bl, brightness);
} }
static int adp5520_bl_get_brightness(struct backlight_device *bl) static int adp5520_bl_get_brightness(struct backlight_device *bl)
......
...@@ -361,15 +361,7 @@ static int adp8860_bl_set(struct backlight_device *bl, int brightness) ...@@ -361,15 +361,7 @@ static int adp8860_bl_set(struct backlight_device *bl, int brightness)
static int adp8860_bl_update_status(struct backlight_device *bl) static int adp8860_bl_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return adp8860_bl_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
return adp8860_bl_set(bl, brightness);
} }
static int adp8860_bl_get_brightness(struct backlight_device *bl) static int adp8860_bl_get_brightness(struct backlight_device *bl)
......
...@@ -399,15 +399,7 @@ static int adp8870_bl_set(struct backlight_device *bl, int brightness) ...@@ -399,15 +399,7 @@ static int adp8870_bl_set(struct backlight_device *bl, int brightness)
static int adp8870_bl_update_status(struct backlight_device *bl) static int adp8870_bl_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return adp8870_bl_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
return adp8870_bl_set(bl, brightness);
} }
static int adp8870_bl_get_brightness(struct backlight_device *bl) static int adp8870_bl_get_brightness(struct backlight_device *bl)
......
...@@ -82,12 +82,7 @@ static int bd6107_write(struct bd6107 *bd, u8 reg, u8 data) ...@@ -82,12 +82,7 @@ static int bd6107_write(struct bd6107 *bd, u8 reg, u8 data)
static int bd6107_backlight_update_status(struct backlight_device *backlight) static int bd6107_backlight_update_status(struct backlight_device *backlight)
{ {
struct bd6107 *bd = bl_get_data(backlight); struct bd6107 *bd = bl_get_data(backlight);
int brightness = backlight->props.brightness; int brightness = backlight_get_brightness(backlight);
if (backlight->props.power != FB_BLANK_UNBLANK ||
backlight->props.fb_blank != FB_BLANK_UNBLANK ||
backlight->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
brightness = 0;
if (brightness) { if (brightness) {
bd6107_write(bd, BD6107_PORTSEL, BD6107_PORTSEL_LEDM(2) | bd6107_write(bd, BD6107_PORTSEL, BD6107_PORTSEL_LEDM(2) |
......
...@@ -420,13 +420,7 @@ static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity) ...@@ -420,13 +420,7 @@ static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity)
static int corgi_bl_update_status(struct backlight_device *bd) static int corgi_bl_update_status(struct backlight_device *bd)
{ {
struct corgi_lcd *lcd = bl_get_data(bd); struct corgi_lcd *lcd = bl_get_data(bd);
int intensity = bd->props.brightness; int intensity = backlight_get_brightness(bd);
if (bd->props.power != FB_BLANK_UNBLANK)
intensity = 0;
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
intensity = 0;
if (corgibl_flags & CORGIBL_SUSPENDED) if (corgibl_flags & CORGIBL_SUSPENDED)
intensity = 0; intensity = 0;
......
...@@ -77,18 +77,7 @@ static int da903x_backlight_set(struct backlight_device *bl, int brightness) ...@@ -77,18 +77,7 @@ static int da903x_backlight_set(struct backlight_device *bl, int brightness)
static int da903x_backlight_update_status(struct backlight_device *bl) static int da903x_backlight_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return da903x_backlight_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.state & BL_CORE_SUSPENDED)
brightness = 0;
return da903x_backlight_set(bl, brightness);
} }
static int da903x_backlight_get_brightness(struct backlight_device *bl) static int da903x_backlight_get_brightness(struct backlight_device *bl)
......
...@@ -36,13 +36,7 @@ static int ep93xxbl_set(struct backlight_device *bl, int brightness) ...@@ -36,13 +36,7 @@ static int ep93xxbl_set(struct backlight_device *bl, int brightness)
static int ep93xxbl_update_status(struct backlight_device *bl) static int ep93xxbl_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return ep93xxbl_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK ||
bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
return ep93xxbl_set(bl, brightness);
} }
static int ep93xxbl_get_brightness(struct backlight_device *bl) static int ep93xxbl_get_brightness(struct backlight_device *bl)
......
...@@ -33,12 +33,8 @@ static void hp680bl_send_intensity(struct backlight_device *bd) ...@@ -33,12 +33,8 @@ static void hp680bl_send_intensity(struct backlight_device *bd)
{ {
unsigned long flags; unsigned long flags;
u16 v; u16 v;
int intensity = bd->props.brightness; int intensity = backlight_get_brightness(bd);
if (bd->props.power != FB_BLANK_UNBLANK)
intensity = 0;
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
intensity = 0;
if (hp680bl_suspended) if (hp680bl_suspended)
intensity = 0; intensity = 0;
......
...@@ -87,12 +87,8 @@ static const struct dmi_system_id kb3886bl_device_table[] __initconst = { ...@@ -87,12 +87,8 @@ static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
static int kb3886bl_send_intensity(struct backlight_device *bd) static int kb3886bl_send_intensity(struct backlight_device *bd)
{ {
int intensity = bd->props.brightness; int intensity = backlight_get_brightness(bd);
if (bd->props.power != FB_BLANK_UNBLANK)
intensity = 0;
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
intensity = 0;
if (kb3886bl_flags & KB3886BL_SUSPENDED) if (kb3886bl_flags & KB3886BL_SUSPENDED)
intensity = 0; intensity = 0;
......
...@@ -54,12 +54,7 @@ static void led_bl_power_off(struct led_bl_data *priv) ...@@ -54,12 +54,7 @@ static void led_bl_power_off(struct led_bl_data *priv)
static int led_bl_update_status(struct backlight_device *bl) static int led_bl_update_status(struct backlight_device *bl)
{ {
struct led_bl_data *priv = bl_get_data(bl); struct led_bl_data *priv = bl_get_data(bl);
int brightness = bl->props.brightness; int brightness = backlight_get_brightness(bl);
if (bl->props.power != FB_BLANK_UNBLANK ||
bl->props.fb_blank != FB_BLANK_UNBLANK ||
bl->props.state & BL_CORE_FBBLANK)
brightness = 0;
if (brightness > 0) if (brightness > 0)
led_bl_set_brightness(priv, brightness); led_bl_set_brightness(priv, brightness);
......
...@@ -39,14 +39,8 @@ static inline int lm3533_bl_get_ctrlbank_id(struct lm3533_bl *bl) ...@@ -39,14 +39,8 @@ static inline int lm3533_bl_get_ctrlbank_id(struct lm3533_bl *bl)
static int lm3533_bl_update_status(struct backlight_device *bd) static int lm3533_bl_update_status(struct backlight_device *bd)
{ {
struct lm3533_bl *bl = bl_get_data(bd); struct lm3533_bl *bl = bl_get_data(bd);
int brightness = bd->props.brightness;
if (bd->props.power != FB_BLANK_UNBLANK) return lm3533_ctrlbank_set_brightness(&bl->cb, backlight_get_brightness(bd));
brightness = 0;
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
return lm3533_ctrlbank_set_brightness(&bl->cb, (u8)brightness);
} }
static int lm3533_bl_get_brightness(struct backlight_device *bd) static int lm3533_bl_get_brightness(struct backlight_device *bd)
......
...@@ -111,12 +111,8 @@ static int current_intensity; ...@@ -111,12 +111,8 @@ static int current_intensity;
static int locomolcd_set_intensity(struct backlight_device *bd) static int locomolcd_set_intensity(struct backlight_device *bd)
{ {
int intensity = bd->props.brightness; int intensity = backlight_get_brightness(bd);
if (bd->props.power != FB_BLANK_UNBLANK)
intensity = 0;
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
intensity = 0;
if (locomolcd_flags & LOCOMOLCD_SUSPENDED) if (locomolcd_flags & LOCOMOLCD_SUSPENDED)
intensity = 0; intensity = 0;
......
...@@ -46,12 +46,7 @@ static int lv5207lp_write(struct lv5207lp *lv, u8 reg, u8 data) ...@@ -46,12 +46,7 @@ static int lv5207lp_write(struct lv5207lp *lv, u8 reg, u8 data)
static int lv5207lp_backlight_update_status(struct backlight_device *backlight) static int lv5207lp_backlight_update_status(struct backlight_device *backlight)
{ {
struct lv5207lp *lv = bl_get_data(backlight); struct lv5207lp *lv = bl_get_data(backlight);
int brightness = backlight->props.brightness; int brightness = backlight_get_brightness(backlight);
if (backlight->props.power != FB_BLANK_UNBLANK ||
backlight->props.fb_blank != FB_BLANK_UNBLANK ||
backlight->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
brightness = 0;
if (brightness) { if (brightness) {
lv5207lp_write(lv, LV5207LP_CTRL1, lv5207lp_write(lv, LV5207LP_CTRL1,
......
...@@ -64,18 +64,7 @@ static int max8925_backlight_set(struct backlight_device *bl, int brightness) ...@@ -64,18 +64,7 @@ static int max8925_backlight_set(struct backlight_device *bl, int brightness)
static int max8925_backlight_update_status(struct backlight_device *bl) static int max8925_backlight_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return max8925_backlight_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.state & BL_CORE_SUSPENDED)
brightness = 0;
return max8925_backlight_set(bl, brightness);
} }
static int max8925_backlight_get_brightness(struct backlight_device *bl) static int max8925_backlight_get_brightness(struct backlight_device *bl)
......
...@@ -108,14 +108,9 @@ static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) ...@@ -108,14 +108,9 @@ static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness)
static int pwm_backlight_update_status(struct backlight_device *bl) static int pwm_backlight_update_status(struct backlight_device *bl)
{ {
struct pwm_bl_data *pb = bl_get_data(bl); struct pwm_bl_data *pb = bl_get_data(bl);
int brightness = bl->props.brightness; int brightness = backlight_get_brightness(bl);
struct pwm_state state; struct pwm_state state;
if (bl->props.power != FB_BLANK_UNBLANK ||
bl->props.fb_blank != FB_BLANK_UNBLANK ||
bl->props.state & BL_CORE_FBBLANK)
brightness = 0;
if (pb->notify) if (pb->notify)
brightness = pb->notify(pb->dev, brightness); brightness = pb->notify(pb->dev, brightness);
......
...@@ -433,14 +433,9 @@ static int wled5_ovp_delay(struct wled *wled) ...@@ -433,14 +433,9 @@ static int wled5_ovp_delay(struct wled *wled)
static int wled_update_status(struct backlight_device *bl) static int wled_update_status(struct backlight_device *bl)
{ {
struct wled *wled = bl_get_data(bl); struct wled *wled = bl_get_data(bl);
u16 brightness = bl->props.brightness; u16 brightness = backlight_get_brightness(bl);
int rc = 0; int rc = 0;
if (bl->props.power != FB_BLANK_UNBLANK ||
bl->props.fb_blank != FB_BLANK_UNBLANK ||
bl->props.state & BL_CORE_FBBLANK)
brightness = 0;
mutex_lock(&wled->lock); mutex_lock(&wled->lock);
if (brightness) { if (brightness) {
rc = wled->wled_set_brightness(wled, brightness); rc = wled->wled_set_brightness(wled, brightness);
......
...@@ -77,15 +77,7 @@ static int tps65217_bl_update_status(struct backlight_device *bl) ...@@ -77,15 +77,7 @@ static int tps65217_bl_update_status(struct backlight_device *bl)
{ {
struct tps65217_bl *tps65217_bl = bl_get_data(bl); struct tps65217_bl *tps65217_bl = bl_get_data(bl);
int rc; int rc;
int brightness = bl->props.brightness; int brightness = backlight_get_brightness(bl);
if (bl->props.state & BL_CORE_SUSPENDED)
brightness = 0;
if ((bl->props.power != FB_BLANK_UNBLANK) ||
(bl->props.fb_blank != FB_BLANK_UNBLANK))
/* framebuffer in low power mode or blanking active */
brightness = 0;
if (brightness > 0) { if (brightness > 0) {
rc = tps65217_reg_write(tps65217_bl->tps, rc = tps65217_reg_write(tps65217_bl->tps,
......
...@@ -91,18 +91,7 @@ static int wm831x_backlight_set(struct backlight_device *bl, int brightness) ...@@ -91,18 +91,7 @@ static int wm831x_backlight_set(struct backlight_device *bl, int brightness)
static int wm831x_backlight_update_status(struct backlight_device *bl) static int wm831x_backlight_update_status(struct backlight_device *bl)
{ {
int brightness = bl->props.brightness; return wm831x_backlight_set(bl, backlight_get_brightness(bl));
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0;
if (bl->props.state & BL_CORE_SUSPENDED)
brightness = 0;
return wm831x_backlight_set(bl, brightness);
} }
static int wm831x_backlight_get_brightness(struct backlight_device *bl) static int wm831x_backlight_get_brightness(struct backlight_device *bl)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment