aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/powermac/backlight.c
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2006-07-31 20:37:25 -0400
committerPaul Mackerras <paulus@samba.org>2006-07-31 20:37:25 -0400
commit57cad8084e0837e0f2c97da789ec9b3f36809be9 (patch)
treee9c790afb4286f78cb08d9664f58baa7e876fe55 /arch/powerpc/platforms/powermac/backlight.c
parentcb18bd40030c879cd93fef02fd579f74dbab473d (diff)
parent49b1e3ea19b1c95c2f012b8331ffb3b169e4c042 (diff)
Merge branch 'merge'
Diffstat (limited to 'arch/powerpc/platforms/powermac/backlight.c')
-rw-r--r--arch/powerpc/platforms/powermac/backlight.c85
1 files changed, 75 insertions, 10 deletions
diff --git a/arch/powerpc/platforms/powermac/backlight.c b/arch/powerpc/platforms/powermac/backlight.c
index 205b4a392862..afa593a8544a 100644
--- a/arch/powerpc/platforms/powermac/backlight.c
+++ b/arch/powerpc/platforms/powermac/backlight.c
@@ -10,11 +10,33 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/fb.h> 11#include <linux/fb.h>
12#include <linux/backlight.h> 12#include <linux/backlight.h>
13#include <linux/adb.h>
14#include <linux/pmu.h>
15#include <asm/atomic.h>
13#include <asm/prom.h> 16#include <asm/prom.h>
14#include <asm/backlight.h> 17#include <asm/backlight.h>
15 18
16#define OLD_BACKLIGHT_MAX 15 19#define OLD_BACKLIGHT_MAX 15
17 20
21static void pmac_backlight_key_worker(void *data);
22static void pmac_backlight_set_legacy_worker(void *data);
23
24static DECLARE_WORK(pmac_backlight_key_work, pmac_backlight_key_worker, NULL);
25static DECLARE_WORK(pmac_backlight_set_legacy_work, pmac_backlight_set_legacy_worker, NULL);
26
27/* Although these variables are used in interrupt context, it makes no sense to
28 * protect them. No user is able to produce enough key events per second and
29 * notice the errors that might happen.
30 */
31static int pmac_backlight_key_queued;
32static int pmac_backlight_set_legacy_queued;
33
34/* The via-pmu code allows the backlight to be grabbed, in which case the
35 * in-kernel control of the brightness needs to be disabled. This should
36 * only be used by really old PowerBooks.
37 */
38static atomic_t kernel_backlight_disabled = ATOMIC_INIT(0);
39
18/* Protect the pmac_backlight variable */ 40/* Protect the pmac_backlight variable */
19DEFINE_MUTEX(pmac_backlight_mutex); 41DEFINE_MUTEX(pmac_backlight_mutex);
20 42
@@ -72,8 +94,11 @@ int pmac_backlight_curve_lookup(struct fb_info *info, int value)
72 return level; 94 return level;
73} 95}
74 96
75static void pmac_backlight_key(int direction) 97static void pmac_backlight_key_worker(void *data)
76{ 98{
99 if (atomic_read(&kernel_backlight_disabled))
100 return;
101
77 mutex_lock(&pmac_backlight_mutex); 102 mutex_lock(&pmac_backlight_mutex);
78 if (pmac_backlight) { 103 if (pmac_backlight) {
79 struct backlight_properties *props; 104 struct backlight_properties *props;
@@ -83,7 +108,8 @@ static void pmac_backlight_key(int direction)
83 props = pmac_backlight->props; 108 props = pmac_backlight->props;
84 109
85 brightness = props->brightness + 110 brightness = props->brightness +
86 ((direction?-1:1) * (props->max_brightness / 15)); 111 ((pmac_backlight_key_queued?-1:1) *
112 (props->max_brightness / 15));
87 113
88 if (brightness < 0) 114 if (brightness < 0)
89 brightness = 0; 115 brightness = 0;
@@ -98,17 +124,20 @@ static void pmac_backlight_key(int direction)
98 mutex_unlock(&pmac_backlight_mutex); 124 mutex_unlock(&pmac_backlight_mutex);
99} 125}
100 126
101void pmac_backlight_key_up() 127/* This function is called in interrupt context */
128void pmac_backlight_key(int direction)
102{ 129{
103 pmac_backlight_key(0); 130 if (atomic_read(&kernel_backlight_disabled))
131 return;
132
133 /* we can receive multiple interrupts here, but the scheduled work
134 * will run only once, with the last value
135 */
136 pmac_backlight_key_queued = direction;
137 schedule_work(&pmac_backlight_key_work);
104} 138}
105 139
106void pmac_backlight_key_down() 140static int __pmac_backlight_set_legacy_brightness(int brightness)
107{
108 pmac_backlight_key(1);
109}
110
111int pmac_backlight_set_legacy_brightness(int brightness)
112{ 141{
113 int error = -ENXIO; 142 int error = -ENXIO;
114 143
@@ -137,6 +166,28 @@ int pmac_backlight_set_legacy_brightness(int brightness)
137 return error; 166 return error;
138} 167}
139 168
169static void pmac_backlight_set_legacy_worker(void *data)
170{
171 if (atomic_read(&kernel_backlight_disabled))
172 return;
173
174 __pmac_backlight_set_legacy_brightness(pmac_backlight_set_legacy_queued);
175}
176
177/* This function is called in interrupt context */
178void pmac_backlight_set_legacy_brightness_pmu(int brightness) {
179 if (atomic_read(&kernel_backlight_disabled))
180 return;
181
182 pmac_backlight_set_legacy_queued = brightness;
183 schedule_work(&pmac_backlight_set_legacy_work);
184}
185
186int pmac_backlight_set_legacy_brightness(int brightness)
187{
188 return __pmac_backlight_set_legacy_brightness(brightness);
189}
190
140int pmac_backlight_get_legacy_brightness() 191int pmac_backlight_get_legacy_brightness()
141{ 192{
142 int result = -ENXIO; 193 int result = -ENXIO;
@@ -158,3 +209,17 @@ int pmac_backlight_get_legacy_brightness()
158 209
159 return result; 210 return result;
160} 211}
212
213void pmac_backlight_disable()
214{
215 atomic_inc(&kernel_backlight_disabled);
216}
217
218void pmac_backlight_enable()
219{
220 atomic_dec(&kernel_backlight_disabled);
221}
222
223EXPORT_SYMBOL_GPL(pmac_backlight);
224EXPORT_SYMBOL_GPL(pmac_backlight_mutex);
225EXPORT_SYMBOL_GPL(pmac_has_backlight_type);