Commit 8fbea019 authored by Corentin Chary's avatar Corentin Chary Committed by Matthew Garrett

asus-wmi: fix and clean backlight code

Signed-off-by: default avatarCorentin Chary <corentincj@iksaif.net>
Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
parent 1d070f89
...@@ -765,14 +765,32 @@ static int read_backlight_power(struct asus_wmi *asus) ...@@ -765,14 +765,32 @@ static int read_backlight_power(struct asus_wmi *asus)
return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
} }
static int read_brightness(struct backlight_device *bd) static int read_brightness_max(struct asus_wmi *asus)
{ {
struct asus_wmi *asus = bl_get_data(bd);
u32 retval; u32 retval;
int err; int err;
err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval); err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
if (err < 0)
return err;
retval = retval & ASUS_WMI_DSTS_MAX_BRIGTH_MASK;
retval >>= 8;
if (!retval)
return -ENODEV;
return retval;
}
static int read_brightness(struct backlight_device *bd)
{
struct asus_wmi *asus = bl_get_data(bd);
u32 retval, err;
err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
if (err < 0) if (err < 0)
return err; return err;
...@@ -799,7 +817,7 @@ static int update_bl_status(struct backlight_device *bd) ...@@ -799,7 +817,7 @@ static int update_bl_status(struct backlight_device *bd)
err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT,
ctrl_param, NULL); ctrl_param, NULL);
} }
return 0; return err;
} }
static const struct backlight_ops asus_wmi_bl_ops = { static const struct backlight_ops asus_wmi_bl_ops = {
...@@ -832,23 +850,19 @@ static int asus_wmi_backlight_init(struct asus_wmi *asus) ...@@ -832,23 +850,19 @@ static int asus_wmi_backlight_init(struct asus_wmi *asus)
int max; int max;
int power; int power;
max = asus_wmi_get_devstate_bits(asus, ASUS_WMI_DEVID_BRIGHTNESS, max = read_brightness_max(asus);
ASUS_WMI_DSTS_MAX_BRIGTH_MASK);
power = read_backlight_power(asus);
if (max < 0 && power < 0) {
/* Try to keep the original error */
if (max == -ENODEV && power == -ENODEV)
return -ENODEV;
if (max != -ENODEV)
return max;
else
return power;
}
if (max == -ENODEV) if (max == -ENODEV)
max = 0; max = 0;
else if (max < 0)
return max;
power = read_backlight_power(asus);
if (power == -ENODEV) if (power == -ENODEV)
power = FB_BLANK_UNBLANK; power = FB_BLANK_UNBLANK;
else if (power < 0)
return power;
memset(&props, 0, sizeof(struct backlight_properties)); memset(&props, 0, sizeof(struct backlight_properties));
props.max_brightness = max; props.max_brightness = max;
......
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