1 From fc22d87d11df9053f1a1b41b7b450c3af07b5059 Mon Sep 17 00:00:00 2001
2 From: mokopatches <mokopatches@openmoko.org>
3 Date: Wed, 16 Jul 2008 14:46:56 +0100
4 Subject: [PATCH] gta02-leds.patch
7 drivers/leds/Kconfig | 6 +
8 drivers/leds/Makefile | 1 +
9 drivers/leds/leds-neo1973-gta02.c | 226 +++++++++++++++++++++++++++++++++++++
10 3 files changed, 233 insertions(+), 0 deletions(-)
11 create mode 100644 drivers/leds/leds-neo1973-gta02.c
13 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
14 index 8c7d949..b6b1211 100644
15 --- a/drivers/leds/Kconfig
16 +++ b/drivers/leds/Kconfig
17 @@ -153,6 +153,12 @@ config LEDS_NEO1973_VIBRATOR
19 This option enables support for the vibrator on the FIC Neo1973.
21 +config LEDS_NEO1973_GTA02
22 + tristate "LED Support for the FIC Neo1973 (GTA02)"
23 + depends on LEDS_CLASS && MACH_NEO1973_GTA02
25 + This option enables support for the LEDs on the FIC Neo1973.
27 comment "LED Triggers"
30 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
31 index 148fe51..3a9df6a 100644
32 --- a/drivers/leds/Makefile
33 +++ b/drivers/leds/Makefile
34 @@ -22,6 +22,7 @@ obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
35 obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
36 obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
37 obj-$(CONFIG_LEDS_NEO1973_VIBRATOR) += leds-neo1973-vibrator.o
38 +obj-$(CONFIG_LEDS_NEO1973_GTA02) += leds-neo1973-gta02.o
41 obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
42 diff --git a/drivers/leds/leds-neo1973-gta02.c b/drivers/leds/leds-neo1973-gta02.c
44 index 0000000..bf1d540
46 +++ b/drivers/leds/leds-neo1973-gta02.c
49 + * LED driver for the FIC Neo1973 GTA02 GSM phone
51 + * (C) 2006-2007 by OpenMoko, Inc.
52 + * Author: Harald Welte <laforge@openmoko.org>
53 + * All rights reserved.
55 + * This program is free software; you can redistribute it and/or modify
56 + * it under the terms of the GNU General Public License version 2 as
57 + * published by the Free Software Foundation.
61 +#include <linux/kernel.h>
62 +#include <linux/init.h>
63 +#include <linux/platform_device.h>
64 +#include <linux/leds.h>
65 +#include <asm/hardware.h>
66 +#include <asm/mach-types.h>
67 +#include <asm/arch/pwm.h>
68 +#include <asm/arch/gta02.h>
69 +#include <asm/plat-s3c/regs-timer.h>
74 +struct gta02_led_priv
77 + struct led_classdev cdev;
78 + struct s3c2410_pwm pwm;
80 + unsigned int has_pwm;
83 +struct gta02_led_bundle
86 + struct gta02_led_priv led[MAX_LEDS];
89 +static inline struct gta02_led_priv *to_priv(struct led_classdev *led_cdev)
91 + return container_of(led_cdev, struct gta02_led_priv, cdev);
94 +static inline struct gta02_led_bundle *to_bundle(struct led_classdev *led_cdev)
96 + return dev_get_drvdata(led_cdev->dev);
99 +static void gta02led_set(struct led_classdev *led_cdev,
100 + enum led_brightness value)
102 + struct gta02_led_priv *lp = to_priv(led_cdev);
105 + * value == 255 -> 99% duty cycle (full power)
106 + * value == 128 -> 50% duty cycle (medium power)
107 + * value == 0 -> 0% duty cycle (zero power)
109 + mutex_lock(&lp->mutex);
111 + s3c2410_pwm_duty_cycle(value, &lp->pwm);
114 + s3c2410_gpio_setpin(lp->gpio, 1);
116 + s3c2410_gpio_setpin(lp->gpio, 0);
118 + mutex_unlock(&lp->mutex);
122 +static int gta02led_suspend(struct platform_device *pdev, pm_message_t state)
124 + struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
127 + for (i = 0; i < bundle->num_leds; i++)
128 + led_classdev_suspend(&bundle->led[i].cdev);
133 +static int gta02led_resume(struct platform_device *pdev)
135 + struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
138 + for (i = 0; i < bundle->num_leds; i++)
139 + led_classdev_resume(&bundle->led[i].cdev);
145 +static int __init gta02led_probe(struct platform_device *pdev)
148 + struct gta02_led_bundle *bundle;
150 + if (!machine_is_neo1973_gta02())
153 + bundle = kzalloc(sizeof(struct gta02_led_bundle), GFP_KERNEL);
156 + platform_set_drvdata(pdev, bundle);
158 + for (i = 0; i < pdev->num_resources; i++) {
159 + struct gta02_led_priv *lp;
160 + struct resource *r;
165 + r = platform_get_resource(pdev, 0, i);
166 + if (!r || !r->start || !r->name)
169 + lp = &bundle->led[i];
171 + lp->gpio = r->start;
172 + lp->cdev.name = r->name;
173 + lp->cdev.brightness_set = gta02led_set;
175 + switch (lp->gpio) {
178 + lp->pwm.timerid = PWM0;
179 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB0_TOUT0);
183 + lp->pwm.timerid = PWM1;
184 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB1_TOUT1);
188 + lp->pwm.timerid = PWM2;
189 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB2_TOUT2);
193 + lp->pwm.timerid = PWM3;
194 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB3_TOUT3);
200 + lp->pwm.prescaler = 0;
201 + lp->pwm.divider = S3C2410_TCFG1_MUX3_DIV8;
202 + lp->pwm.counter = COUNTER;
203 + lp->pwm.comparer = COUNTER;
204 + s3c2410_pwm_enable(&lp->pwm);
205 + s3c2410_pwm_start(&lp->pwm);
207 + switch (lp->gpio) {
212 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPIO_OUTPUT);
213 + s3c2410_gpio_setpin(lp->gpio, 0);
219 + mutex_init(&lp->mutex);
220 + rc = led_classdev_register(&pdev->dev, &lp->cdev);
226 +static int gta02led_remove(struct platform_device *pdev)
228 + struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
231 + for (i = 0; i < bundle->num_leds; i++) {
232 + struct gta02_led_priv *lp = &bundle->led[i];
234 + s3c2410_pwm_disable(&lp->pwm);
236 + led_classdev_unregister(&lp->cdev);
237 + mutex_destroy(&lp->mutex);
240 + platform_set_drvdata(pdev, NULL);
246 +static struct platform_driver gta02led_driver = {
247 + .probe = gta02led_probe,
248 + .remove = gta02led_remove,
250 + .suspend = gta02led_suspend,
251 + .resume = gta02led_resume,
254 + .name = "gta02-led",
258 +static int __init gta02led_init(void)
260 + return platform_driver_register(>a02led_driver);
263 +static void __exit gta02led_exit(void)
265 + platform_driver_unregister(>a02led_driver);
268 +module_init(gta02led_init);
269 +module_exit(gta02led_exit);
271 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
272 +MODULE_DESCRIPTION("FIC Neo1973 GTA02 LED driver");
273 +MODULE_LICENSE("GPL");