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