summaryrefslogtreecommitdiff
path: root/target/linux/s3c24xx/patches-2.6.26/1032-gta02-leds.patch.patch
blob: 5645c007205544b8841535e6672d664226fb69c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
From fc22d87d11df9053f1a1b41b7b450c3af07b5059 Mon Sep 17 00:00:00 2001
From: mokopatches <mokopatches@openmoko.org>
Date: Wed, 16 Jul 2008 14:46:56 +0100
Subject: [PATCH] gta02-leds.patch

---
 drivers/leds/Kconfig              |    6 +
 drivers/leds/Makefile             |    1 +
 drivers/leds/leds-neo1973-gta02.c |  226 +++++++++++++++++++++++++++++++++++++
 3 files changed, 233 insertions(+), 0 deletions(-)
 create mode 100644 drivers/leds/leds-neo1973-gta02.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 8c7d949..b6b1211 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -153,6 +153,12 @@ config LEDS_NEO1973_VIBRATOR
 	help
 	  This option enables support for the vibrator on the FIC Neo1973.
 
+config LEDS_NEO1973_GTA02
+	tristate "LED Support for the FIC Neo1973 (GTA02)"
+	depends on LEDS_CLASS && MACH_NEO1973_GTA02
+	help
+	  This option enables support for the LEDs on the FIC Neo1973.
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 148fe51..3a9df6a 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_LEDS_CLEVO_MAIL)		+= leds-clevo-mail.o
 obj-$(CONFIG_LEDS_HP6XX)		+= leds-hp6xx.o
 obj-$(CONFIG_LEDS_FSG)			+= leds-fsg.o
 obj-$(CONFIG_LEDS_NEO1973_VIBRATOR)	+= leds-neo1973-vibrator.o
+obj-$(CONFIG_LEDS_NEO1973_GTA02)	+= leds-neo1973-gta02.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
diff --git a/drivers/leds/leds-neo1973-gta02.c b/drivers/leds/leds-neo1973-gta02.c
new file mode 100644
index 0000000..bf1d540
--- /dev/null
+++ b/drivers/leds/leds-neo1973-gta02.c
@@ -0,0 +1,226 @@
+/*
+ * LED driver for the FIC Neo1973 GTA02 GSM phone
+ *
+ * (C) 2006-2007 by OpenMoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/arch/pwm.h>
+#include <asm/arch/gta02.h>
+#include <asm/plat-s3c/regs-timer.h>
+
+#define MAX_LEDS 3
+#define COUNTER 256
+
+struct gta02_led_priv
+{
+	struct mutex mutex;
+	struct led_classdev cdev;
+	struct s3c2410_pwm pwm;
+	unsigned int gpio;
+	unsigned int has_pwm;
+};
+
+struct gta02_led_bundle
+{
+	int num_leds;
+	struct gta02_led_priv led[MAX_LEDS];
+};
+
+static inline struct gta02_led_priv *to_priv(struct led_classdev *led_cdev)
+{
+	return container_of(led_cdev, struct gta02_led_priv, cdev);
+}
+
+static inline struct gta02_led_bundle *to_bundle(struct led_classdev *led_cdev)
+{
+	return dev_get_drvdata(led_cdev->dev);
+}
+
+static void gta02led_set(struct led_classdev *led_cdev,
+		enum led_brightness value)
+{
+	struct gta02_led_priv *lp = to_priv(led_cdev);
+
+	/*
+ 	 * value == 255 -> 99% duty cycle (full power)
+ 	 * value == 128 -> 50% duty cycle (medium power)
+ 	 * value == 0 -> 0% duty cycle (zero power)
+ 	 */
+ 	mutex_lock(&lp->mutex);
+	if (lp->has_pwm) {
+			s3c2410_pwm_duty_cycle(value, &lp->pwm);
+	} else {
+		if (value)
+			s3c2410_gpio_setpin(lp->gpio, 1);
+		else
+			s3c2410_gpio_setpin(lp->gpio, 0);
+	}
+	mutex_unlock(&lp->mutex);
+}
+
+#ifdef CONFIG_PM
+static int gta02led_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
+	int i;
+
+	for (i = 0; i < bundle->num_leds; i++)
+		led_classdev_suspend(&bundle->led[i].cdev);
+
+	return 0;
+}
+
+static int gta02led_resume(struct platform_device *pdev)
+{
+	struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
+	int i;
+
+	for (i = 0; i < bundle->num_leds; i++)
+		led_classdev_resume(&bundle->led[i].cdev);
+
+	return 0;
+}
+#endif
+
+static int __init gta02led_probe(struct platform_device *pdev)
+{
+	int i, rc;
+	struct gta02_led_bundle *bundle;
+
+	if (!machine_is_neo1973_gta02())
+		return -EIO;
+
+	bundle = kzalloc(sizeof(struct gta02_led_bundle), GFP_KERNEL);
+	if (!bundle)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, bundle);
+
+	for (i = 0; i < pdev->num_resources; i++) {
+		struct gta02_led_priv *lp;
+		struct resource *r;
+
+		if (i >= MAX_LEDS)
+			break;
+
+		r = platform_get_resource(pdev, 0, i);
+		if (!r || !r->start || !r->name)
+			continue;
+
+		lp = &bundle->led[i];
+
+		lp->gpio = r->start;
+		lp->cdev.name = r->name;
+		lp->cdev.brightness_set = gta02led_set;
+
+		switch (lp->gpio) {
+		case S3C2410_GPB0:
+			lp->has_pwm = 1;
+			lp->pwm.timerid = PWM0;
+			s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB0_TOUT0);
+			break;
+		case S3C2410_GPB1:
+			lp->has_pwm = 1;
+			lp->pwm.timerid = PWM1;
+			s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB1_TOUT1);
+			break;
+		case S3C2410_GPB2:
+			lp->has_pwm = 1;
+			lp->pwm.timerid = PWM2;
+			s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB2_TOUT2);
+			break;
+		case S3C2410_GPB3:
+			lp->has_pwm = 1;
+			lp->pwm.timerid = PWM3;
+			s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPB3_TOUT3);
+			break;
+		default:
+			break;
+		}
+
+		lp->pwm.prescaler = 0;
+		lp->pwm.divider = S3C2410_TCFG1_MUX3_DIV8;
+		lp->pwm.counter = COUNTER;
+		lp->pwm.comparer = COUNTER;
+		s3c2410_pwm_enable(&lp->pwm);
+		s3c2410_pwm_start(&lp->pwm);
+
+		switch (lp->gpio) {
+		case S3C2410_GPB0:
+		case S3C2410_GPB1:
+		case S3C2410_GPB2:
+			lp->has_pwm = 0;
+			s3c2410_gpio_cfgpin(lp->gpio, S3C2410_GPIO_OUTPUT);
+			s3c2410_gpio_setpin(lp->gpio, 0);
+			break;
+		default:
+			break;
+		}
+
+		mutex_init(&lp->mutex);
+		rc = led_classdev_register(&pdev->dev, &lp->cdev);
+	}
+
+	return 0;
+}
+
+static int gta02led_remove(struct platform_device *pdev)
+{
+	struct gta02_led_bundle *bundle = platform_get_drvdata(pdev);
+	int i;
+
+	for (i = 0; i < bundle->num_leds; i++) {
+		struct gta02_led_priv *lp = &bundle->led[i];
+		if (lp->has_pwm)
+			s3c2410_pwm_disable(&lp->pwm);
+
+		led_classdev_unregister(&lp->cdev);
+		mutex_destroy(&lp->mutex);
+	}
+
+	platform_set_drvdata(pdev, NULL);
+	kfree(bundle);
+
+	return 0;
+}
+
+static struct platform_driver gta02led_driver = {
+	.probe		= gta02led_probe,
+	.remove		= gta02led_remove,
+#ifdef CONFIG_PM
+	.suspend	= gta02led_suspend,
+	.resume		= gta02led_resume,
+#endif
+	.driver		= {
+		.name		= "gta02-led",
+	},
+};
+
+static int __init gta02led_init(void)
+{
+	return platform_driver_register(&gta02led_driver);
+}
+
+static void __exit gta02led_exit(void)
+{
+ 	platform_driver_unregister(&gta02led_driver);
+}
+
+module_init(gta02led_init);
+module_exit(gta02led_exit);
+
+MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
+MODULE_DESCRIPTION("FIC Neo1973 GTA02 LED driver");
+MODULE_LICENSE("GPL");
-- 
1.5.6.3