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
7 Signed-off-by: Harald Welte <laforge@openmoko.org>
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
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.
23 +config BACKLIGHT_GTA01
24 + tristate "FIC Neo1973 GTA01 Backlight Driver"
25 + depends on BACKLIGHT_CLASS_DEVICE && MACH_NEO1973_GTA01
28 + If you have a FIC Neo1973 GTA01, say y to enable the backlight driver.
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
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
48 index 0000000..c2bf0c9
50 +++ b/drivers/video/backlight/gta01_bl.c
53 + * Backlight Driver for FIC GTA01 (Neo1973) GSM Phone
55 + * Copyright (C) 2006-2007 by OpenMoko, Inc.
56 + * Author: Harald Welte <laforge@openmoko.org>
57 + * All rights reserved.
59 + * based on corgi_cl.c, Copyright (c) 2004-2006 Richard Purdie
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.
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.
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,
75 + * Javi Roman <javiroman@kernel-labs.org>:
76 + * implement PWM, instead of simple on/off switching
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>
89 +#include <asm/arch/hardware.h>
90 +#include <asm/arch/gta01.h>
91 +#include <asm/arch/pwm.h>
93 +#include <asm/plat-s3c/regs-timer.h>
95 +static struct backlight_properties gta01bl_prop;
96 +static struct backlight_device *gta01_backlight_device;
97 +static struct gta01bl_machinfo *bl_machinfo;
99 +static unsigned long gta01bl_flags;
101 +struct gta01bl_data {
103 + struct mutex mutex;
105 + struct s3c2410_pwm pwm;
108 +static struct gta01bl_data gta01bl;
110 +#define GTA01BL_SUSPENDED 0x01
111 +#define GTA01BL_BATTLOW 0x02
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
121 +static int gta01bl_send_intensity(struct backlight_device *bd)
123 + int intensity = bd->props.brightness;
125 + if (bd->props.power != FB_BLANK_UNBLANK)
127 + if (bd->props.fb_blank != FB_BLANK_UNBLANK)
129 + if (gta01bl_flags & GTA01BL_SUSPENDED)
131 + if (gta01bl_flags & GTA01BL_BATTLOW)
132 + intensity &= bl_machinfo->limit_mask;
134 + mutex_lock(>a01bl.mutex);
135 +#ifdef GTA01_BACKLIGHT_ONOFF_ONLY
137 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
139 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 0);
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);
145 + s3c2410_pwm_duty_cycle(intensity & 0xffff, >a01bl.pwm);
146 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPB0_TOUT0);
149 + mutex_unlock(>a01bl.mutex);
151 + gta01bl.intensity = intensity;
155 +static int gta01bl_init_hw(void)
159 + rc = s3c2410_pwm_init(>a01bl.pwm);
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;
169 + rc = s3c2410_pwm_enable(>a01bl.pwm);
173 + s3c2410_pwm_start(>a01bl.pwm);
175 + gta01bl_prop.max_brightness = gta01bl.pwm.counter;
181 +static int gta01bl_suspend(struct platform_device *dev, pm_message_t state)
183 + gta01bl_flags |= GTA01BL_SUSPENDED;
184 + gta01bl_send_intensity(gta01_backlight_device);
188 +static int gta01bl_resume(struct platform_device *dev)
190 + mutex_lock(>a01bl.mutex);
192 + mutex_unlock(>a01bl.mutex);
194 + gta01bl_flags &= ~GTA01BL_SUSPENDED;
195 + gta01bl_send_intensity(gta01_backlight_device);
199 +#define gta01bl_suspend NULL
200 +#define gta01bl_resume NULL
203 +static int gta01bl_get_intensity(struct backlight_device *bd)
205 + return gta01bl.intensity;
208 +static int gta01bl_set_intensity(struct backlight_device *bd)
210 + gta01bl_send_intensity(gta01_backlight_device);
215 + * Called when the battery is low to limit the backlight intensity.
216 + * If limit==0 clear any limit, otherwise limit the intensity
218 +void gta01bl_limit_intensity(int limit)
221 + gta01bl_flags |= GTA01BL_BATTLOW;
223 + gta01bl_flags &= ~GTA01BL_BATTLOW;
224 + gta01bl_send_intensity(gta01_backlight_device);
226 +EXPORT_SYMBOL_GPL(gta01bl_limit_intensity);
229 +static struct backlight_ops gta01bl_ops = {
230 + .get_brightness = gta01bl_get_intensity,
231 + .update_status = gta01bl_set_intensity,
234 +static int __init gta01bl_probe(struct platform_device *pdev)
236 + struct gta01bl_machinfo *machinfo = pdev->dev.platform_data;
239 +#ifdef GTA01_BACKLIGHT_ONOFF_ONLY
240 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
241 + gta01bl_prop.max_brightness = 1;
243 + rc = gta01bl_init_hw();
247 + mutex_init(>a01bl.mutex);
249 + if (!machinfo->limit_mask)
250 + machinfo->limit_mask = -1;
252 + gta01_backlight_device = backlight_device_register("gta01-bl",
255 + if (IS_ERR(gta01_backlight_device))
256 + return PTR_ERR(gta01_backlight_device);
258 + gta01bl_prop.power = FB_BLANK_UNBLANK;
259 + gta01bl_prop.brightness = gta01bl_prop.max_brightness;
260 + memcpy(>a01_backlight_device->props,
261 + >a01bl_prop, sizeof(gta01bl_prop));
262 + gta01bl_send_intensity(gta01_backlight_device);
267 +static int gta01bl_remove(struct platform_device *dev)
269 +#ifndef GTA01_BACKLIGHT_ONOFF_ONLY
270 + s3c2410_pwm_disable(>a01bl.pwm);
272 + backlight_device_unregister(gta01_backlight_device);
273 + mutex_destroy(>a01bl.mutex);
275 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
276 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
281 +static struct platform_driver gta01bl_driver = {
282 + .probe = gta01bl_probe,
283 + .remove = gta01bl_remove,
284 + .suspend = gta01bl_suspend,
285 + .resume = gta01bl_resume,
287 + .name = "gta01-bl",
291 +static int __init gta01bl_init(void)
293 + return platform_driver_register(>a01bl_driver);
296 +static void __exit gta01bl_exit(void)
298 + platform_driver_unregister(>a01bl_driver);
301 +module_init(gta01bl_init);
302 +module_exit(gta01bl_exit);
304 +MODULE_DESCRIPTION("FIC GTA01 (Neo1973) Backlight Driver");
305 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
306 +MODULE_LICENSE("GPL");