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
7 Signed-off-by: Harald Welte <laforge@openmoko.org>
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
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
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.
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
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
47 index 0000000..c2bf0c9
49 +++ b/drivers/video/backlight/gta01_bl.c
52 + * Backlight Driver for FIC GTA01 (Neo1973) GSM Phone
54 + * Copyright (C) 2006-2007 by OpenMoko, Inc.
55 + * Author: Harald Welte <laforge@openmoko.org>
56 + * All rights reserved.
58 + * based on corgi_cl.c, Copyright (c) 2004-2006 Richard Purdie
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.
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.
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,
74 + * Javi Roman <javiroman@kernel-labs.org>:
75 + * implement PWM, instead of simple on/off switching
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>
88 +#include <asm/arch/hardware.h>
89 +#include <asm/arch/gta01.h>
90 +#include <asm/arch/pwm.h>
92 +#include <asm/plat-s3c/regs-timer.h>
94 +static struct backlight_properties gta01bl_prop;
95 +static struct backlight_device *gta01_backlight_device;
96 +static struct gta01bl_machinfo *bl_machinfo;
98 +static unsigned long gta01bl_flags;
100 +struct gta01bl_data {
102 + struct mutex mutex;
104 + struct s3c2410_pwm pwm;
107 +static struct gta01bl_data gta01bl;
109 +#define GTA01BL_SUSPENDED 0x01
110 +#define GTA01BL_BATTLOW 0x02
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
120 +static int gta01bl_send_intensity(struct backlight_device *bd)
122 + int intensity = bd->props.brightness;
124 + if (bd->props.power != FB_BLANK_UNBLANK)
126 + if (bd->props.fb_blank != FB_BLANK_UNBLANK)
128 + if (gta01bl_flags & GTA01BL_SUSPENDED)
130 + if (gta01bl_flags & GTA01BL_BATTLOW)
131 + intensity &= bl_machinfo->limit_mask;
133 + mutex_lock(>a01bl.mutex);
134 +#ifdef GTA01_BACKLIGHT_ONOFF_ONLY
136 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
138 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 0);
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);
144 + s3c2410_pwm_duty_cycle(intensity & 0xffff, >a01bl.pwm);
145 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPB0_TOUT0);
148 + mutex_unlock(>a01bl.mutex);
150 + gta01bl.intensity = intensity;
154 +static int gta01bl_init_hw(void)
158 + rc = s3c2410_pwm_init(>a01bl.pwm);
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;
168 + rc = s3c2410_pwm_enable(>a01bl.pwm);
172 + s3c2410_pwm_start(>a01bl.pwm);
174 + gta01bl_prop.max_brightness = gta01bl.pwm.counter;
180 +static int gta01bl_suspend(struct platform_device *dev, pm_message_t state)
182 + gta01bl_flags |= GTA01BL_SUSPENDED;
183 + gta01bl_send_intensity(gta01_backlight_device);
187 +static int gta01bl_resume(struct platform_device *dev)
189 + mutex_lock(>a01bl.mutex);
191 + mutex_unlock(>a01bl.mutex);
193 + gta01bl_flags &= ~GTA01BL_SUSPENDED;
194 + gta01bl_send_intensity(gta01_backlight_device);
198 +#define gta01bl_suspend NULL
199 +#define gta01bl_resume NULL
202 +static int gta01bl_get_intensity(struct backlight_device *bd)
204 + return gta01bl.intensity;
207 +static int gta01bl_set_intensity(struct backlight_device *bd)
209 + gta01bl_send_intensity(gta01_backlight_device);
214 + * Called when the battery is low to limit the backlight intensity.
215 + * If limit==0 clear any limit, otherwise limit the intensity
217 +void gta01bl_limit_intensity(int limit)
220 + gta01bl_flags |= GTA01BL_BATTLOW;
222 + gta01bl_flags &= ~GTA01BL_BATTLOW;
223 + gta01bl_send_intensity(gta01_backlight_device);
225 +EXPORT_SYMBOL_GPL(gta01bl_limit_intensity);
228 +static struct backlight_ops gta01bl_ops = {
229 + .get_brightness = gta01bl_get_intensity,
230 + .update_status = gta01bl_set_intensity,
233 +static int __init gta01bl_probe(struct platform_device *pdev)
235 + struct gta01bl_machinfo *machinfo = pdev->dev.platform_data;
238 +#ifdef GTA01_BACKLIGHT_ONOFF_ONLY
239 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
240 + gta01bl_prop.max_brightness = 1;
242 + rc = gta01bl_init_hw();
246 + mutex_init(>a01bl.mutex);
248 + if (!machinfo->limit_mask)
249 + machinfo->limit_mask = -1;
251 + gta01_backlight_device = backlight_device_register("gta01-bl",
254 + if (IS_ERR(gta01_backlight_device))
255 + return PTR_ERR(gta01_backlight_device);
257 + gta01bl_prop.power = FB_BLANK_UNBLANK;
258 + gta01bl_prop.brightness = gta01bl_prop.max_brightness;
259 + memcpy(>a01_backlight_device->props,
260 + >a01bl_prop, sizeof(gta01bl_prop));
261 + gta01bl_send_intensity(gta01_backlight_device);
266 +static int gta01bl_remove(struct platform_device *dev)
268 +#ifndef GTA01_BACKLIGHT_ONOFF_ONLY
269 + s3c2410_pwm_disable(>a01bl.pwm);
271 + backlight_device_unregister(gta01_backlight_device);
272 + mutex_destroy(>a01bl.mutex);
274 + s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPIO_OUTPUT);
275 + s3c2410_gpio_setpin(GTA01_GPIO_BACKLIGHT, 1);
280 +static struct platform_driver gta01bl_driver = {
281 + .probe = gta01bl_probe,
282 + .remove = gta01bl_remove,
283 + .suspend = gta01bl_suspend,
284 + .resume = gta01bl_resume,
286 + .name = "gta01-bl",
290 +static int __init gta01bl_init(void)
292 + return platform_driver_register(>a01bl_driver);
295 +static void __exit gta01bl_exit(void)
297 + platform_driver_unregister(>a01bl_driver);
300 +module_init(gta01bl_init);
301 +module_exit(gta01bl_exit);
303 +MODULE_DESCRIPTION("FIC GTA01 (Neo1973) Backlight Driver");
304 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
305 +MODULE_LICENSE("GPL");