diff options
Diffstat (limited to 'drivers/video/nvidia/nv_backlight.c')
-rw-r--r-- | drivers/video/nvidia/nv_backlight.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c index 1c1c10c699c5..5b75ae4e9457 100644 --- a/drivers/video/nvidia/nv_backlight.c +++ b/drivers/video/nvidia/nv_backlight.c | |||
@@ -26,9 +26,11 @@ | |||
26 | */ | 26 | */ |
27 | #define MIN_LEVEL 0x158 | 27 | #define MIN_LEVEL 0x158 |
28 | #define MAX_LEVEL 0x534 | 28 | #define MAX_LEVEL 0x534 |
29 | #define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX) | ||
29 | 30 | ||
30 | static struct backlight_properties nvidia_bl_data; | 31 | static struct backlight_properties nvidia_bl_data; |
31 | 32 | ||
33 | /* Call with fb_info->bl_mutex held */ | ||
32 | static int nvidia_bl_get_level_brightness(struct nvidia_par *par, | 34 | static int nvidia_bl_get_level_brightness(struct nvidia_par *par, |
33 | int level) | 35 | int level) |
34 | { | 36 | { |
@@ -36,9 +38,7 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par, | |||
36 | int nlevel; | 38 | int nlevel; |
37 | 39 | ||
38 | /* Get and convert the value */ | 40 | /* Get and convert the value */ |
39 | mutex_lock(&info->bl_mutex); | 41 | nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP; |
40 | nlevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL; | ||
41 | mutex_unlock(&info->bl_mutex); | ||
42 | 42 | ||
43 | if (nlevel < 0) | 43 | if (nlevel < 0) |
44 | nlevel = 0; | 44 | nlevel = 0; |
@@ -50,7 +50,8 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par, | |||
50 | return nlevel; | 50 | return nlevel; |
51 | } | 51 | } |
52 | 52 | ||
53 | static int nvidia_bl_update_status(struct backlight_device *bd) | 53 | /* Call with fb_info->bl_mutex held */ |
54 | static int __nvidia_bl_update_status(struct backlight_device *bd) | ||
54 | { | 55 | { |
55 | struct nvidia_par *par = class_get_devdata(&bd->class_dev); | 56 | struct nvidia_par *par = class_get_devdata(&bd->class_dev); |
56 | u32 tmp_pcrt, tmp_pmc, fpcontrol; | 57 | u32 tmp_pcrt, tmp_pmc, fpcontrol; |
@@ -84,6 +85,19 @@ static int nvidia_bl_update_status(struct backlight_device *bd) | |||
84 | return 0; | 85 | return 0; |
85 | } | 86 | } |
86 | 87 | ||
88 | static int nvidia_bl_update_status(struct backlight_device *bd) | ||
89 | { | ||
90 | struct nvidia_par *par = class_get_devdata(&bd->class_dev); | ||
91 | struct fb_info *info = pci_get_drvdata(par->pci_dev); | ||
92 | int ret; | ||
93 | |||
94 | mutex_lock(&info->bl_mutex); | ||
95 | ret = __nvidia_bl_update_status(bd); | ||
96 | mutex_unlock(&info->bl_mutex); | ||
97 | |||
98 | return ret; | ||
99 | } | ||
100 | |||
87 | static int nvidia_bl_get_brightness(struct backlight_device *bd) | 101 | static int nvidia_bl_get_brightness(struct backlight_device *bd) |
88 | { | 102 | { |
89 | return bd->props->brightness; | 103 | return bd->props->brightness; |
@@ -96,6 +110,20 @@ static struct backlight_properties nvidia_bl_data = { | |||
96 | .max_brightness = (FB_BACKLIGHT_LEVELS - 1), | 110 | .max_brightness = (FB_BACKLIGHT_LEVELS - 1), |
97 | }; | 111 | }; |
98 | 112 | ||
113 | void nvidia_bl_set_power(struct fb_info *info, int power) | ||
114 | { | ||
115 | mutex_lock(&info->bl_mutex); | ||
116 | |||
117 | if (info->bl_dev) { | ||
118 | down(&info->bl_dev->sem); | ||
119 | info->bl_dev->props->power = power; | ||
120 | __nvidia_bl_update_status(info->bl_dev); | ||
121 | up(&info->bl_dev->sem); | ||
122 | } | ||
123 | |||
124 | mutex_unlock(&info->bl_mutex); | ||
125 | } | ||
126 | |||
99 | void nvidia_bl_init(struct nvidia_par *par) | 127 | void nvidia_bl_init(struct nvidia_par *par) |
100 | { | 128 | { |
101 | struct fb_info *info = pci_get_drvdata(par->pci_dev); | 129 | struct fb_info *info = pci_get_drvdata(par->pci_dev); |
@@ -116,7 +144,7 @@ void nvidia_bl_init(struct nvidia_par *par) | |||
116 | bd = backlight_device_register(name, par, &nvidia_bl_data); | 144 | bd = backlight_device_register(name, par, &nvidia_bl_data); |
117 | if (IS_ERR(bd)) { | 145 | if (IS_ERR(bd)) { |
118 | info->bl_dev = NULL; | 146 | info->bl_dev = NULL; |
119 | printk("nvidia: Backlight registration failed\n"); | 147 | printk(KERN_WARNING "nvidia: Backlight registration failed\n"); |
120 | goto error; | 148 | goto error; |
121 | } | 149 | } |
122 | 150 | ||
@@ -127,11 +155,11 @@ void nvidia_bl_init(struct nvidia_par *par) | |||
127 | 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL); | 155 | 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL); |
128 | mutex_unlock(&info->bl_mutex); | 156 | mutex_unlock(&info->bl_mutex); |
129 | 157 | ||
130 | up(&bd->sem); | 158 | down(&bd->sem); |
131 | bd->props->brightness = nvidia_bl_data.max_brightness; | 159 | bd->props->brightness = nvidia_bl_data.max_brightness; |
132 | bd->props->power = FB_BLANK_UNBLANK; | 160 | bd->props->power = FB_BLANK_UNBLANK; |
133 | bd->props->update_status(bd); | 161 | bd->props->update_status(bd); |
134 | down(&bd->sem); | 162 | up(&bd->sem); |
135 | 163 | ||
136 | #ifdef CONFIG_PMAC_BACKLIGHT | 164 | #ifdef CONFIG_PMAC_BACKLIGHT |
137 | mutex_lock(&pmac_backlight_mutex); | 165 | mutex_lock(&pmac_backlight_mutex); |