[ar71xx] remove duplicated includes
[openwrt.git] / target / linux / s3c24xx / patches-2.6.24 / 1039-gta02-leds.patch.patch
1 From b265be540c1169a5d6c32c5b09bb3f7b72a96a9d Mon Sep 17 00:00:00 2001
2 From: mokopatches <mokopatches@openmoko.org>
3 Date: Fri, 4 Apr 2008 11:35:53 +0100
4 Subject: [PATCH] gta02-leds.patch
5
6 ---
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
12
13 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
14 index 4579a88..2f95707 100644
15 --- a/drivers/leds/Kconfig
16 +++ b/drivers/leds/Kconfig
17 @@ -120,6 +120,12 @@ config LEDS_NEO1973_VIBRATOR
18 help
19 This option enables support for the vibrator on the FIC Neo1973.
20
21 +config LEDS_NEO1973_GTA02
22 + tristate "LED Support for the FIC Neo1973 (GTA02)"
23 + depends on LEDS_CLASS && MACH_NEO1973_GTA02
24 + help
25 + This option enables support for the LEDs on the FIC Neo1973.
26 +
27 comment "LED Triggers"
28
29 config LEDS_TRIGGERS
30 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
31 index f64332d..c4ff826 100644
32 --- a/drivers/leds/Makefile
33 +++ b/drivers/leds/Makefile
34 @@ -20,6 +20,7 @@ obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
35 obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
36 obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o
37 obj-$(CONFIG_LEDS_NEO1973_VIBRATOR) += leds-neo1973-vibrator.o
38 +obj-$(CONFIG_LEDS_NEO1973_GTA02) += leds-neo1973-gta02.o
39
40 # LED Triggers
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
43 new file mode 100644
44 index 0000000..bf1d540
45 --- /dev/null
46 +++ b/drivers/leds/leds-neo1973-gta02.c
47 @@ -0,0 +1,226 @@
48 +/*
49 + * LED driver for the FIC Neo1973 GTA02 GSM phone
50 + *
51 + * (C) 2006-2007 by OpenMoko, Inc.
52 + * Author: Harald Welte <laforge@openmoko.org>
53 + * All rights reserved.
54 + *
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.
58 + *
59 + */
60 +
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>
70 +
71 +#define MAX_LEDS 3
72 +#define COUNTER 256
73 +
74 +struct gta02_led_priv
75 +{
76 + struct mutex mutex;
77 + struct led_classdev cdev;
78 + struct s3c2410_pwm pwm;
79 + unsigned int gpio;
80 + unsigned int has_pwm;
81 +};
82 +
83 +struct gta02_led_bundle
84 +{
85 + int num_leds;
86 + struct gta02_led_priv led[MAX_LEDS];
87 +};
88 +
89 +static inline struct gta02_led_priv *to_priv(struct led_classdev *led_cdev)
90 +{
91 + return container_of(led_cdev, struct gta02_led_priv, cdev);
92 +}
93 +
94 +static inline struct gta02_led_bundle *to_bundle(struct led_classdev *led_cdev)
95 +{
96 + return dev_get_drvdata(led_cdev->dev);
97 +}
98 +
99 +static void gta02led_set(struct led_classdev *led_cdev,
100 + enum led_brightness value)
101 +{
102 + struct gta02_led_priv *lp = to_priv(led_cdev);
103 +
104 + /*
105 + * value == 255 -> 99% duty cycle (full power)
106 + * value == 128 -> 50% duty cycle (medium power)
107 + * value == 0 -> 0% duty cycle (zero power)
108 + */
109 + mutex_lock(&lp->mutex);
110 + if (lp->has_pwm) {
111 + s3c2410_pwm_duty_cycle(value, &lp->pwm);
112 + } else {
113 + if (value)
114 + s3c2410_gpio_setpin(lp->gpio, 1);
115 + else
116 + s3c2410_gpio_setpin(lp->gpio, 0);
117 + }
118 + mutex_unlock(&lp->mutex);
119 +}
120 +
121 +#ifdef CONFIG_PM
122 +static int gta02led_suspend(struct platform_device *pdev, pm_message_t state)
123 +{
124 + struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
125 + int i;
126 +
127 + for (i = 0; i < bundle->num_leds; i++)
128 + led_classdev_suspend(&bundle->led[i].cdev);
129 +
130 + return 0;
131 +}
132 +
133 +static int gta02led_resume(struct platform_device *pdev)
134 +{
135 + struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
136 + int i;
137 +
138 + for (i = 0; i < bundle->num_leds; i++)
139 + led_classdev_resume(&bundle->led[i].cdev);
140 +
141 + return 0;
142 +}
143 +#endif
144 +
145 +static int __init gta02led_probe(struct platform_device *pdev)
146 +{
147 + int i, rc;
148 + struct gta02_led_bundle *bundle;
149 +
150 + if (!machine_is_neo1973_gta02())
151 + return -EIO;
152 +
153 + bundle = kzalloc(sizeof(struct gta02_led_bundle), GFP_KERNEL);
154 + if (!bundle)
155 + return -ENOMEM;
156 + platform_set_drvdata(pdev, bundle);
157 +
158 + for (i = 0; i < pdev->num_resources; i++) {
159 + struct gta02_led_priv *lp;
160 + struct resource *r;
161 +
162 + if (i >= MAX_LEDS)
163 + break;
164 +
165 + r = platform_get_resource(pdev, 0, i);
166 + if (!r || !r->start || !r->name)
167 + continue;
168 +
169 + lp = &bundle->led[i];
170 +
171 + lp->gpio = r->start;
172 + lp->cdev.name = r->name;
173 + lp->cdev.brightness_set = gta02led_set;
174 +
175 + switch (lp->gpio) {
176 + case S3C2410_GPB0:
177 + lp->has_pwm = 1;
178 + lp->pwm.timerid = PWM0;
179 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB0_TOUT0);
180 + break;
181 + case S3C2410_GPB1:
182 + lp->has_pwm = 1;
183 + lp->pwm.timerid = PWM1;
184 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB1_TOUT1);
185 + break;
186 + case S3C2410_GPB2:
187 + lp->has_pwm = 1;
188 + lp->pwm.timerid = PWM2;
189 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB2_TOUT2);
190 + break;
191 + case S3C2410_GPB3:
192 + lp->has_pwm = 1;
193 + lp->pwm.timerid = PWM3;
194 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB3_TOUT3);
195 + break;
196 + default:
197 + break;
198 + }
199 +
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);
206 +
207 + switch (lp->gpio) {
208 + case S3C2410_GPB0:
209 + case S3C2410_GPB1:
210 + case S3C2410_GPB2:
211 + lp->has_pwm = 0;
212 + s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPIO_OUTPUT);
213 + s3c2410_gpio_setpin(lp->gpio, 0);
214 + break;
215 + default:
216 + break;
217 + }
218 +
219 + mutex_init(&lp->mutex);
220 + rc = led_classdev_register(&pdev->dev, &lp->cdev);
221 + }
222 +
223 + return 0;
224 +}
225 +
226 +static int gta02led_remove(struct platform_device *pdev)
227 +{
228 + struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
229 + int i;
230 +
231 + for (i = 0; i < bundle->num_leds; i++) {
232 + struct gta02_led_priv *lp = &bundle->led[i];
233 + if (lp->has_pwm)
234 + s3c2410_pwm_disable(&lp->pwm);
235 +
236 + led_classdev_unregister(&lp->cdev);
237 + mutex_destroy(&lp->mutex);
238 + }
239 +
240 + platform_set_drvdata(pdev, NULL);
241 + kfree(bundle);
242 +
243 + return 0;
244 +}
245 +
246 +static struct platform_driver gta02led_driver = {
247 + .probe = gta02led_probe,
248 + .remove = gta02led_remove,
249 +#ifdef CONFIG_PM
250 + .suspend = gta02led_suspend,
251 + .resume = gta02led_resume,
252 +#endif
253 + .driver = {
254 + .name = "gta02-led",
255 + },
256 +};
257 +
258 +static int __init gta02led_init(void)
259 +{
260 + return platform_driver_register(&gta02led_driver);
261 +}
262 +
263 +static void __exit gta02led_exit(void)
264 +{
265 + platform_driver_unregister(&gta02led_driver);
266 +}
267 +
268 +module_init(gta02led_init);
269 +module_exit(gta02led_exit);
270 +
271 +MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
272 +MODULE_DESCRIPTION("FIC Neo1973 GTA02 LED driver");
273 +MODULE_LICENSE("GPL");
274 --
275 1.5.6.5
276
This page took 0.076098 seconds and 5 git commands to generate.