changed Makefile and profiles, added patches for kernel 2.6.24 (stable-branch of...
[openwrt/staging/florian.git] / target / linux / s3c24xx / patches-2.6.24 / 1017-gta01-backlight.patch.patch
1 From e6e1c20bc96cc397812ab07f0ccd0a16360f2e24 Mon Sep 17 00:00:00 2001
2 From: mokopatches <mokopatches@openmoko.org>
3 Date: Fri, 4 Apr 2008 11:32:08 +0100
4 Subject: [PATCH] gta01-backlight.patch
5 This is a backlight driver for the FIC/OpenMoko Neo1973 GTA01 GSM Phone
6
7 Signed-off-by: Harald Welte <laforge@openmoko.org>
8 ---
9 drivers/video/backlight/Kconfig | 8 +
10 drivers/video/backlight/Makefile | 1 +
11 drivers/video/backlight/gta01_bl.c | 255 ++++++++++++++++++++++++++++++++++++
12 3 files changed, 264 insertions(+), 0 deletions(-)
13 create mode 100644 drivers/video/backlight/gta01_bl.c
14
15 diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
16 index 9609a6c..b954d15 100644
17 --- a/drivers/video/backlight/Kconfig
18 +++ b/drivers/video/backlight/Kconfig
19 @@ -67,6 +67,14 @@ config BACKLIGHT_LOCOMO
20 If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to
21 enable the LCD/backlight driver.
22
23 +config BACKLIGHT_GTA01
24 + tristate "FIC Neo1973 GTA01 Backlight Driver"
25 + depends on BACKLIGHT_CLASS_DEVICE && MACH_NEO1973_GTA01
26 + default y
27 + help
28 + If you have a FIC Neo1973 GTA01, say y to enable the backlight driver.
29 +
30 +
31 config BACKLIGHT_HP680
32 tristate "HP Jornada 680 Backlight Driver"
33 depends on BACKLIGHT_CLASS_DEVICE && SH_HP6XX
34 diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
35 index 965a78b..8b489f2 100644
36 --- a/drivers/video/backlight/Makefile
37 +++ b/drivers/video/backlight/Makefile
38 @@ -5,6 +5,7 @@ obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
39
40 obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
41 obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
42 +obj-$(CONFIG_BACKLIGHT_GTA01) += gta01_bl.o
43 obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
44 obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
45 obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
46 diff --git a/drivers/video/backlight/gta01_bl.c b/drivers/video/backlight/gta01_bl.c
47 new file mode 100644
48 index 0000000..c2bf0c9
49 --- /dev/null
50 +++ b/drivers/video/backlight/gta01_bl.c
51 @@ -0,0 +1,255 @@
52 +/*
53 + * Backlight Driver for FIC GTA01 (Neo1973) GSM Phone
54 + *
55 + * Copyright (C) 2006-2007 by OpenMoko, Inc.
56 + * Author: Harald Welte <laforge@openmoko.org>
57 + * All rights reserved.
58 + *
59 + * based on corgi_cl.c, Copyright (c) 2004-2006 Richard Purdie
60 + *
61 + * This program is free software; you can redistribute it and/or
62 + * modify it under the terms of the GNU General Public License as
63 + * published by the Free Software Foundation, version 2.
64 + *
65 + * This program is distributed in the hope that it will be useful,
66 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
67 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 + * GNU General Public License for more details.
69 + *
70 + * You should have received a copy of the GNU General Public License
71 + * along with this program; if not, write to the Free Software
72 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
73 + * MA 02111-1307 USA
74 + *
75 + * Javi Roman <javiroman@kernel-labs.org>:
76 + * implement PWM, instead of simple on/off switching
77 + *
78 + */
79 +
80 +#include <linux/module.h>
81 +#include <linux/kernel.h>
82 +#include <linux/init.h>
83 +#include <linux/platform_device.h>
84 +#include <linux/mutex.h>
85 +#include <linux/fb.h>
86 +#include <linux/backlight.h>
87 +#include <linux/clk.h>
88 +
89 +#include <asm/arch/hardware.h>
90 +#include <asm/arch/gta01.h>
91 +#include <asm/arch/pwm.h>
92 +
93 +#include <asm/plat-s3c/regs-timer.h>
94 +
95 +static struct backlight_properties gta01bl_prop;
96 +static struct backlight_device *gta01_backlight_device;
97 +static struct gta01bl_machinfo *bl_machinfo;
98 +
99 +static unsigned long gta01bl_flags;
100 +
101 +struct gta01bl_data {
102 + int intensity;
103 + struct mutex mutex;
104 + struct clk *clk;
105 + struct s3c2410_pwm pwm;
106 +};
107 +
108 +static struct gta01bl_data gta01bl;
109 +
110 +#define GTA01BL_SUSPENDED 0x01
111 +#define GTA01BL_BATTLOW 0x02
112 +
113 +/* On the GTA01 / Neo1973, we use a 50 or 66MHz PCLK, which gives
114 + * us a 6.25..8.25MHz DIV8 clock, which is further divided by a
115 + * prescaler of 4, resulting in a 1.56..2.06MHz tick. This results in a
116 + * minimum frequency of 24..31Hz. At 400Hz, we need to set the count
117 + * to something like 3906..5156, providing us a way sufficient resolution
118 + * for display brightness adjustment. */
119 +#define GTA01BL_COUNTER 5156
120 +
121 +static int gta01bl_send_intensity(struct backlight_device *bd)
122 +{
123 + int intensity = bd->props.brightness;
124 +
125 + if (bd->props.power != FB_BLANK_UNBLANK)
126 + intensity = 0;
127 + if (bd->props.fb_blank != FB_BLANK_UNBLANK)
128 + intensity = 0;
129 + if (gta01bl_flags & GTA01BL_SUSPENDED)
130 + intensity = 0;
131 + if (gta01bl_flags & GTA01BL_BATTLOW)
132 + intensity &= bl_machinfo->limit_mask;
133 +
134 + mutex_lock(&gta01bl.mutex);
135 +#ifdef GTA01_BACKLIGHT_ONOFF_ONLY
136 + if (intensity)
137 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
138 + else
139 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 0);
140 +#else
141 + if (intensity == bd->props.max_brightness) {
142 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
143 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
144 + } else {
145 + s3c2410_pwm_duty_cycle(intensity & 0xffff, &gta01bl.pwm);
146 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPB0_TOUT0);
147 + }
148 +#endif
149 + mutex_unlock(&gta01bl.mutex);
150 +
151 + gta01bl.intensity = intensity;
152 + return 0;
153 +}
154 +
155 +static int gta01bl_init_hw(void)
156 +{
157 + int rc;
158 +
159 + rc = s3c2410_pwm_init(&gta01bl.pwm);
160 + if (rc)
161 + return rc;
162 +
163 + gta01bl.pwm.timerid = PWM0;
164 + gta01bl.pwm.prescaler = (4 - 1);
165 + gta01bl.pwm.divider = S3C2410_TCFG1_MUX0_DIV8;
166 + gta01bl.pwm.counter = GTA01BL_COUNTER;
167 + gta01bl.pwm.comparer = gta01bl.pwm.counter;
168 +
169 + rc = s3c2410_pwm_enable(&gta01bl.pwm);
170 + if (rc)
171 + return rc;
172 +
173 + s3c2410_pwm_start(&gta01bl.pwm);
174 +
175 + gta01bl_prop.max_brightness = gta01bl.pwm.counter;
176 +
177 + return 0;
178 +}
179 +
180 +#ifdef CONFIG_PM
181 +static int gta01bl_suspend(struct platform_device *dev, pm_message_t state)
182 +{
183 + gta01bl_flags |= GTA01BL_SUSPENDED;
184 + gta01bl_send_intensity(gta01_backlight_device);
185 + return 0;
186 +}
187 +
188 +static int gta01bl_resume(struct platform_device *dev)
189 +{
190 + mutex_lock(&gta01bl.mutex);
191 + gta01bl_init_hw();
192 + mutex_unlock(&gta01bl.mutex);
193 +
194 + gta01bl_flags &= ~GTA01BL_SUSPENDED;
195 + gta01bl_send_intensity(gta01_backlight_device);
196 + return 0;
197 +}
198 +#else
199 +#define gta01bl_suspend NULL
200 +#define gta01bl_resume NULL
201 +#endif
202 +
203 +static int gta01bl_get_intensity(struct backlight_device *bd)
204 +{
205 + return gta01bl.intensity;
206 +}
207 +
208 +static int gta01bl_set_intensity(struct backlight_device *bd)
209 +{
210 + gta01bl_send_intensity(gta01_backlight_device);
211 + return 0;
212 +}
213 +
214 +/*
215 + * Called when the battery is low to limit the backlight intensity.
216 + * If limit==0 clear any limit, otherwise limit the intensity
217 + */
218 +void gta01bl_limit_intensity(int limit)
219 +{
220 + if (limit)
221 + gta01bl_flags |= GTA01BL_BATTLOW;
222 + else
223 + gta01bl_flags &= ~GTA01BL_BATTLOW;
224 + gta01bl_send_intensity(gta01_backlight_device);
225 +}
226 +EXPORT_SYMBOL_GPL(gta01bl_limit_intensity);
227 +
228 +
229 +static struct backlight_ops gta01bl_ops = {
230 + .get_brightness = gta01bl_get_intensity,
231 + .update_status = gta01bl_set_intensity,
232 +};
233 +
234 +static int __init gta01bl_probe(struct platform_device *pdev)
235 +{
236 + struct gta01bl_machinfo *machinfo = pdev->dev.platform_data;
237 + int rc;
238 +
239 +#ifdef GTA01_BACKLIGHT_ONOFF_ONLY
240 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
241 + gta01bl_prop.max_brightness = 1;
242 +#else
243 + rc = gta01bl_init_hw();
244 + if (rc < 0)
245 + return rc;
246 +#endif
247 + mutex_init(&gta01bl.mutex);
248 +
249 + if (!machinfo->limit_mask)
250 + machinfo->limit_mask = -1;
251 +
252 + gta01_backlight_device = backlight_device_register("gta01-bl",
253 + &pdev->dev, NULL,
254 + &gta01bl_ops);
255 + if (IS_ERR(gta01_backlight_device))
256 + return PTR_ERR(gta01_backlight_device);
257 +
258 + gta01bl_prop.power = FB_BLANK_UNBLANK;
259 + gta01bl_prop.brightness = gta01bl_prop.max_brightness;
260 + memcpy(&gta01_backlight_device->props,
261 + &gta01bl_prop, sizeof(gta01bl_prop));
262 + gta01bl_send_intensity(gta01_backlight_device);
263 +
264 + return 0;
265 +}
266 +
267 +static int gta01bl_remove(struct platform_device *dev)
268 +{
269 +#ifndef GTA01_BACKLIGHT_ONOFF_ONLY
270 + s3c2410_pwm_disable(&gta01bl.pwm);
271 +#endif
272 + backlight_device_unregister(gta01_backlight_device);
273 + mutex_destroy(&gta01bl.mutex);
274 +
275 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
276 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
277 +
278 + return 0;
279 +}
280 +
281 +static struct platform_driver gta01bl_driver = {
282 + .probe = gta01bl_probe,
283 + .remove = gta01bl_remove,
284 + .suspend = gta01bl_suspend,
285 + .resume = gta01bl_resume,
286 + .driver = {
287 + .name = "gta01-bl",
288 + },
289 +};
290 +
291 +static int __init gta01bl_init(void)
292 +{
293 + return platform_driver_register(&gta01bl_driver);
294 +}
295 +
296 +static void __exit gta01bl_exit(void)
297 +{
298 + platform_driver_unregister(&gta01bl_driver);
299 +}
300 +
301 +module_init(gta01bl_init);
302 +module_exit(gta01bl_exit);
303 +
304 +MODULE_DESCRIPTION("FIC GTA01 (Neo1973) Backlight Driver");
305 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
306 +MODULE_LICENSE("GPL");
307 --
308 1.5.6.5
309