diff options
author | Paul Mackerras <paulus@samba.org> | 2006-07-31 20:37:25 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-07-31 20:37:25 -0400 |
commit | 57cad8084e0837e0f2c97da789ec9b3f36809be9 (patch) | |
tree | e9c790afb4286f78cb08d9664f58baa7e876fe55 /arch/powerpc/platforms/powermac/backlight.c | |
parent | cb18bd40030c879cd93fef02fd579f74dbab473d (diff) | |
parent | 49b1e3ea19b1c95c2f012b8331ffb3b169e4c042 (diff) |
Merge branch 'merge'
Diffstat (limited to 'arch/powerpc/platforms/powermac/backlight.c')
-rw-r--r-- | arch/powerpc/platforms/powermac/backlight.c | 85 |
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 | ||
21 | static void pmac_backlight_key_worker(void *data); | ||
22 | static void pmac_backlight_set_legacy_worker(void *data); | ||
23 | |||
24 | static DECLARE_WORK(pmac_backlight_key_work, pmac_backlight_key_worker, NULL); | ||
25 | static 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 | */ | ||
31 | static int pmac_backlight_key_queued; | ||
32 | static 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 | */ | ||
38 | static atomic_t kernel_backlight_disabled = ATOMIC_INIT(0); | ||
39 | |||
18 | /* Protect the pmac_backlight variable */ | 40 | /* Protect the pmac_backlight variable */ |
19 | DEFINE_MUTEX(pmac_backlight_mutex); | 41 | DEFINE_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 | ||
75 | static void pmac_backlight_key(int direction) | 97 | static 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 | ||
101 | void pmac_backlight_key_up() | 127 | /* This function is called in interrupt context */ |
128 | void 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 | ||
106 | void pmac_backlight_key_down() | 140 | static int __pmac_backlight_set_legacy_brightness(int brightness) |
107 | { | ||
108 | pmac_backlight_key(1); | ||
109 | } | ||
110 | |||
111 | int 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 | ||
169 | static 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 */ | ||
178 | void 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 | |||
186 | int pmac_backlight_set_legacy_brightness(int brightness) | ||
187 | { | ||
188 | return __pmac_backlight_set_legacy_brightness(brightness); | ||
189 | } | ||
190 | |||
140 | int pmac_backlight_get_legacy_brightness() | 191 | int 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 | |||
213 | void pmac_backlight_disable() | ||
214 | { | ||
215 | atomic_inc(&kernel_backlight_disabled); | ||
216 | } | ||
217 | |||
218 | void pmac_backlight_enable() | ||
219 | { | ||
220 | atomic_dec(&kernel_backlight_disabled); | ||
221 | } | ||
222 | |||
223 | EXPORT_SYMBOL_GPL(pmac_backlight); | ||
224 | EXPORT_SYMBOL_GPL(pmac_backlight_mutex); | ||
225 | EXPORT_SYMBOL_GPL(pmac_has_backlight_type); | ||