diff options
author | Corentin Chary <corentincj@iksaif.net> | 2011-02-26 04:20:37 -0500 |
---|---|---|
committer | Matthew Garrett <mjg@redhat.com> | 2011-03-28 06:07:21 -0400 |
commit | 8fbea019a1a70e0fb01e0f98c963e6042fbe94ab (patch) | |
tree | 4a8372c7765808b33d64b28ae6e1408741b80cb7 /drivers/platform | |
parent | 1d070f89a723bd296865dd7eb61c8050763e6e3b (diff) |
asus-wmi: fix and clean backlight code
Signed-off-by: Corentin Chary <corentincj@iksaif.net>
Signed-off-by: Matthew Garrett <mjg@redhat.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r-- | drivers/platform/x86/asus-wmi.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index fd5b08eecf1e..adf7b05c9aef 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c | |||
@@ -765,9 +765,8 @@ static int read_backlight_power(struct asus_wmi *asus) | |||
765 | return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; | 765 | return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; |
766 | } | 766 | } |
767 | 767 | ||
768 | static int read_brightness(struct backlight_device *bd) | 768 | static int read_brightness_max(struct asus_wmi *asus) |
769 | { | 769 | { |
770 | struct asus_wmi *asus = bl_get_data(bd); | ||
771 | u32 retval; | 770 | u32 retval; |
772 | int err; | 771 | int err; |
773 | 772 | ||
@@ -776,6 +775,25 @@ static int read_brightness(struct backlight_device *bd) | |||
776 | if (err < 0) | 775 | if (err < 0) |
777 | return err; | 776 | return err; |
778 | 777 | ||
778 | retval = retval & ASUS_WMI_DSTS_MAX_BRIGTH_MASK; | ||
779 | retval >>= 8; | ||
780 | |||
781 | if (!retval) | ||
782 | return -ENODEV; | ||
783 | |||
784 | return retval; | ||
785 | } | ||
786 | |||
787 | static int read_brightness(struct backlight_device *bd) | ||
788 | { | ||
789 | struct asus_wmi *asus = bl_get_data(bd); | ||
790 | u32 retval, err; | ||
791 | |||
792 | err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval); | ||
793 | |||
794 | if (err < 0) | ||
795 | return err; | ||
796 | |||
779 | return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK; | 797 | return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK; |
780 | } | 798 | } |
781 | 799 | ||
@@ -799,7 +817,7 @@ static int update_bl_status(struct backlight_device *bd) | |||
799 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, | 817 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, |
800 | ctrl_param, NULL); | 818 | ctrl_param, NULL); |
801 | } | 819 | } |
802 | return 0; | 820 | return err; |
803 | } | 821 | } |
804 | 822 | ||
805 | static const struct backlight_ops asus_wmi_bl_ops = { | 823 | static const struct backlight_ops asus_wmi_bl_ops = { |
@@ -832,23 +850,19 @@ static int asus_wmi_backlight_init(struct asus_wmi *asus) | |||
832 | int max; | 850 | int max; |
833 | int power; | 851 | int power; |
834 | 852 | ||
835 | max = asus_wmi_get_devstate_bits(asus, ASUS_WMI_DEVID_BRIGHTNESS, | 853 | max = read_brightness_max(asus); |
836 | ASUS_WMI_DSTS_MAX_BRIGTH_MASK); | ||
837 | power = read_backlight_power(asus); | ||
838 | 854 | ||
839 | if (max < 0 && power < 0) { | ||
840 | /* Try to keep the original error */ | ||
841 | if (max == -ENODEV && power == -ENODEV) | ||
842 | return -ENODEV; | ||
843 | if (max != -ENODEV) | ||
844 | return max; | ||
845 | else | ||
846 | return power; | ||
847 | } | ||
848 | if (max == -ENODEV) | 855 | if (max == -ENODEV) |
849 | max = 0; | 856 | max = 0; |
857 | else if (max < 0) | ||
858 | return max; | ||
859 | |||
860 | power = read_backlight_power(asus); | ||
861 | |||
850 | if (power == -ENODEV) | 862 | if (power == -ENODEV) |
851 | power = FB_BLANK_UNBLANK; | 863 | power = FB_BLANK_UNBLANK; |
864 | else if (power < 0) | ||
865 | return power; | ||
852 | 866 | ||
853 | memset(&props, 0, sizeof(struct backlight_properties)); | 867 | memset(&props, 0, sizeof(struct backlight_properties)); |
854 | props.max_brightness = max; | 868 | props.max_brightness = max; |