summaryrefslogtreecommitdiff
path: root/packages/linux/linux-ezx-2.6.24/patches/e680-leds.patch
blob: 9de1f0fa8f34e72b61fe4999c4d98cdee88591fa (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

#
# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
#

Index: linux-2.6.24/drivers/leds/Kconfig
===================================================================
--- linux-2.6.24.orig/drivers/leds/Kconfig
+++ linux-2.6.24/drivers/leds/Kconfig
@@ -130,6 +130,13 @@
 	  This option enables support for the LEDs on the
 	  Motorola A780 GSM Phone.
 
+config LEDS_E680
+	tristate "LED Support for the Motorola E680(i) GSM Phone"
+	depends on LEDS_CLASS && PXA_EZX_E680
+	help
+	  This options enables support for the LEDs on the
+	  Motorola E680(i) GSM Phone.
+
 config LEDS_TRIGGER_TIMER
 	tristate "LED Timer Trigger"
 	depends on LEDS_TRIGGERS
Index: linux-2.6.24/drivers/leds/Makefile
===================================================================
--- linux-2.6.24.orig/drivers/leds/Makefile
+++ linux-2.6.24/drivers/leds/Makefile
@@ -20,6 +20,7 @@
 obj-$(CONFIG_LEDS_GPIO)			+= leds-gpio.o
 obj-$(CONFIG_LEDS_CM_X270)              += leds-cm-x270.o
 obj-$(CONFIG_LEDS_A780)		+= leds-a780.o
+obj-$(CONFIG_LEDS_E680)		+= leds-e680.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
Index: linux-2.6.24/drivers/leds/leds-e680.c
===================================================================
--- /dev/null
+++ linux-2.6.24/drivers/leds/leds-e680.c
@@ -0,0 +1,235 @@
+/*
+ * EZX Platform LED Driver for the Motorola E680(i) GSM Phone
+ *
+ * Copyright 2006 Vanille-Media
+ *
+ * Author: Michael Lauer <mickey@Vanille.de>
+ *
+ * Based on the Motorola 2.4 leds-e680.c and leds-corgi.c by Richard Purdie
+ *
+ * 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/delay.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <asm/mach-types.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/ezx-pcap.h>
+
+//FIXME move defines to a common header file
+#define IND_CNTL_R_BUL     46
+#define IND_CNTL_G_BUL     47
+#define SSP_PCAP_LED_MASK  0x000fffe0
+#define SSP_PCAP_LED_SHIFT 5
+#define GPIO_TC_MM_EN      99
+
+extern int ezx_pcap_read(u_int8_t, u_int32_t *);
+extern int ezx_pcap_write(u_int8_t, u_int32_t);
+
+typedef struct {
+	u_int8_t ind_GPIO_red;    /*Indicator Red control GPIO 46: 0 active, 1 inactive */
+	u_int8_t ind_GPIO_green;  /*Indicator Green control GPIO 47: 0 inactive, 1 active */
+	u_int8_t pcap_LEDR_en;    /*pcap LEDR_EN bit value: 1 =Red LED(&Green) sink circuit enabled*/
+	u_int8_t pcap_LEDG_en;    /*pcap LEDG_EN bit value:1 =Green(->Blue)LED sink circuit enabled*/
+	u_int8_t pcap_LEDR_CTRL; /* 4bits Sets the timing for the red(&Green) LED sink circuit*/
+	u_int8_t pcap_LEDG_CTRL; /* 4bits Sets the timing for the GREEN (->Blue) LED sink circuit*/
+	u_int8_t pcap_LEDR_I;   /* 2 bits 00 3mA,01 4mA, 10 5mA, 11 9mA, sets the pulsed current level for LEDR*/
+	u_int8_t pcap_LEDG_I;   /* 2 bits 00 3mA,01 4mA, 10 5mA, 11 9mA, sets the pulsed current level for LEDG*/
+//	u_int8_t pcap_SKIP_on;  /*1=The ON timing sequence defined by LEDx_CTRL is executed on every other cycle*/
+} PCAP2_LED_REGISTER_VALUE;
+
+const PCAP2_LED_REGISTER_VALUE led_register_value[]=
+{
+	{0x1,0x0, 0x0,0x0, 0x0,0x0, 0x1,0x0}, /* 0 OFF */
+
+	{0x0,0x0, 0x1,0x0, 0xf,0x0, 0x1,0x0}, /* 1 RED */
+	{0x1,0x1, 0x1,0x0, 0xf,0x0, 0x1,0x0}, /* 2 GREEN */
+	{0x0,0x1, 0x1,0x0, 0xf,0x0, 0x1,0x0}, /* 3 ORANGE */
+	{0x1,0x0, 0x0,0x1, 0x0,0xf, 0x0,0x0}, /* 4 BLUE */
+	{0x0,0x0, 0x1,0x1, 0xf,0xf, 0x1,0x0}, /* 5 MAGENTA */
+	{0x1,0x1, 0x1,0x1, 0xf,0xf, 0x1,0x0}, /* 6 CYAN */
+	{0x0,0x1, 0x1,0x1, 0xf,0xf, 0x1,0x0}, /* 7 WHITE */
+};
+
+static void e680led_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	unsigned int tempValue;
+	unsigned char gpio_red, gpio_green, ledr_en, ledg_en, ledr_ctrl,
+			ledg_ctrl, ledr_i, ledg_i, skip, t, color;
+	unsigned char t_mask[2] = { 0xc, 0xc };
+
+	skip = 0;
+	if (value & 128) {
+		value &= (~128);
+		skip = 1;
+	}
+
+	/* 7 colors - simple on */
+	if (value <= 7)
+		color = value;
+	/* 4 colors - 11 timed on */
+	else if (value <= 51) {
+		value -= 7;
+		color = ((value-1)%4)+1;
+		t = ((value-1)/4)+1;
+		t_mask[0] = t;
+		t_mask[1] = t;
+	}
+	/* 3 colors - 22 change color */
+	else if (value <= 84) {
+		value -= 51;
+		color = ((value-1)%3)+5;
+		t = ((value-1)/3)+1;
+		t_mask[1] = t;
+	}
+	else if (value <= 117) {
+		value -= 84;
+		color = ((value-1)%3)+5;
+		t = ((value-1)/3)+1;
+		t_mask[0] = t;
+	}
+	/* 3 colors - alternate with blue */
+	else if (value <= 120) {
+		color = value-113;
+		t_mask[0] = 0xa;
+		t_mask[1] = 0xb;
+	}
+	/* invalid value */
+	else
+		color = 1;
+
+	gpio_red   = led_register_value[color].ind_GPIO_red;
+	gpio_green = led_register_value[color].ind_GPIO_green;
+	ledr_en    = led_register_value[color].pcap_LEDR_en;
+	ledg_en    = led_register_value[color].pcap_LEDG_en;
+	ledr_ctrl  = led_register_value[color].pcap_LEDR_CTRL & t_mask[0];
+	ledg_ctrl  = led_register_value[color].pcap_LEDG_CTRL & t_mask[1];
+	ledr_i     = led_register_value[color].pcap_LEDR_I;
+	ledg_i     = led_register_value[color].pcap_LEDG_I;
+
+	ezx_pcap_read(PCAP_REG_PERIPH,&tempValue);
+
+	tempValue &= (~SSP_PCAP_LED_MASK);
+
+	pxa_gpio_set_value(IND_CNTL_R_BUL, gpio_red);
+	pxa_gpio_set_value(IND_CNTL_G_BUL, gpio_green);
+
+	/* Write PCAP LED Peripheral Control Register*/
+	tempValue = ((ledr_en | (ledg_en << 1) | (ledr_ctrl << 2) |
+		(ledg_ctrl << 6) | (ledr_i << 10) | (ledg_i << 12) |
+		(skip << 14)) & 0x7fff) << SSP_PCAP_LED_SHIFT;
+
+	ezx_pcap_write(PCAP_REG_PERIPH,tempValue);
+}
+
+static void e680led_keypad_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	/* this is not working yet, as there is something else missing */
+#if 0
+	printk( KERN_DEBUG "e680led_keypad_set: %d\n", value );
+
+	pxa_gpio_mode(GPIO_TC_MM_EN);
+	GPDR(GPIO_TC_MM_EN)   |= GPIO_bit(GPIO_TC_MM_EN);
+	GPSR(GPIO_TC_MM_EN)   = GPIO_bit(GPIO_TC_MM_EN);
+
+	udelay( 100 );
+
+    if ( value ) {
+		GPCR(GPIO_TC_MM_EN)   = GPIO_bit(GPIO_TC_MM_EN);
+		PGSR3 &= ~GPIO_bit(GPIO_TC_MM_EN);
+    } else {
+		GPSR(GPIO_TC_MM_EN)   = GPIO_bit(GPIO_TC_MM_EN);
+		PGSR3 |= GPIO_bit(GPIO_TC_MM_EN);
+    }
+#endif
+}
+
+static struct led_classdev e680_led = {
+	.name			= "e680:led",
+	.default_trigger	= "none",
+	.brightness_set		= e680led_set,
+};
+
+static struct led_classdev e680_keypad = {
+	.name			= "e680:keypad",
+	.default_trigger	= "none",
+	.brightness_set		= e680led_keypad_set,
+};
+
+#ifdef CONFIG_PM
+static int e680led_suspend(struct platform_device *dev, pm_message_t state)
+{
+	led_classdev_suspend(&e680_led);
+	led_classdev_suspend(&e680_keypad);
+	return 0;
+}
+
+static int e680led_resume(struct platform_device *dev)
+{
+	led_classdev_resume(&e680_led);
+	led_classdev_resume(&e680_keypad);
+	return 0;
+}
+#endif
+
+static int e680led_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	/* configure GPIOs as output */
+	pxa_gpio_mode(IND_CNTL_R_BUL | GPIO_OUT);
+	pxa_gpio_mode(IND_CNTL_G_BUL | GPIO_OUT);
+
+	ret = led_classdev_register(&pdev->dev, &e680_led);
+	if (ret < 0)
+		return ret;
+
+	ret = led_classdev_register(&pdev->dev, &e680_keypad);
+	if (ret < 0) {
+		led_classdev_unregister(&e680_led);
+	}
+	return ret;
+}
+
+static int e680led_remove(struct platform_device *pdev)
+{
+	led_classdev_unregister(&e680_led);
+	led_classdev_unregister(&e680_keypad);
+	return 0;
+}
+
+static struct platform_driver e680led_driver = {
+	.probe		= e680led_probe,
+	.remove		= e680led_remove,
+#ifdef CONFIG_PM
+	.suspend	= e680led_suspend,
+	.resume		= e680led_resume,
+#endif
+	.driver		= {
+		.name		= "e680-led",
+	},
+};
+
+static int __init e680led_init(void)
+{
+	return platform_driver_register(&e680led_driver);
+}
+
+static void __exit e680led_exit(void)
+{
+	platform_driver_unregister(&e680led_driver);
+}
+
+module_init(e680led_init);
+module_exit(e680led_exit);
+
+MODULE_AUTHOR("Michael Lauer <mickey@Vanille.de>");
+MODULE_DESCRIPTION("Motorola E680 LED driver");
+MODULE_LICENSE("GPL");
Index: linux-2.6.24/arch/arm/mach-pxa/ezx-e680.c
===================================================================
--- linux-2.6.24.orig/arch/arm/mach-pxa/ezx-e680.c
+++ linux-2.6.24/arch/arm/mach-pxa/ezx-e680.c
@@ -337,11 +337,20 @@
        },
 };
 
+static struct platform_device e680led_device = {
+	.name		= "e680-led",
+	.id		= -1,
+	.dev		= {
+		.parent = &e680_pcap_device.dev,
+	},
+};
+
 static struct platform_device *devices[] __initdata = {
 	&e680_pcap_device,
 	&e680_emu_device,
 	&pcap_ts_device,
 	&e680locksw_device,
+	&e680led_device,
 };
 
 static void __init e680_init(void)