summaryrefslogtreecommitdiff
path: root/packages/linux/linux-ezx/e680-leds-r0.patch
blob: b6d2413dc18c10e68cda161358d70ac148d09447 (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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

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

--- linux-2.6.16/arch/arm/mach-pxa/ezx.c~led_ezx-r0.patch	2006-06-03 15:17:43.000000000 +0200
+++ linux-2.6.16/arch/arm/mach-pxa/ezx.c	2006-06-05 15:14:59.000000000 +0200
@@ -357,6 +357,17 @@
 	.num_resources	= ARRAY_SIZE(ezx_backlight_resources),
 };
 
+#ifdef CONFIG_PXA_EZX_E680
+/*
+ * E680 LEDs
+ */
+static struct platform_device e680led_device = {
+	.name		= "e680-led",
+	.id		= -1,
+};
+#endif
+
+
 /* keyboard */
 
 #if defined(CONFIG_PXA_EZX_V700)
@@ -770,6 +781,9 @@
 
 static struct platform_device *devices[] __initdata = {
 	&ezx_bp_device,
+#ifdef CONFIG_PXA_EZX_E680
+	&e680led_device,
+#endif
 };
 
 static void __init
--- linux-2.6.16/drivers/leds/Kconfig~led_ezx-r0.patch	2006-06-03 15:17:47.000000000 +0200
+++ linux-2.6.16/drivers/leds/Kconfig	2006-06-03 15:17:47.000000000 +0200
@@ -59,6 +59,13 @@
 	  This option enables support for the LEDs on Sharp Zaurus
 	  SL-6000 series.
 
+config LEDS_E680
+	tristate "LED Support for the Motorola E680(i) GSM Phone"
+	depends 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 LEDS_TRIGGERS
--- linux-2.6.16/drivers/leds/Makefile~led_ezx-r0.patch	2006-06-03 15:17:47.000000000 +0200
+++ linux-2.6.16/drivers/leds/Makefile	2006-06-03 15:17:47.000000000 +0200
@@ -10,7 +10,8 @@
 obj-$(CONFIG_LEDS_SPITZ)		+= leds-spitz.o
 obj-$(CONFIG_LEDS_IXP4XX)		+= leds-ixp4xx-gpio.o
 obj-$(CONFIG_LEDS_TOSA)			+= leds-tosa.o
+obj-$(CONFIG_LEDS_E680)		+= leds-e680.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
-obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK)	+= ledtrig-ide-disk.o
\ Kein Zeilenumbruch am Dateiende.
+obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK)	+= ledtrig-ide-disk.o
--- /dev/null	2006-06-05 13:59:28.329930680 +0200
+++ linux-2.6.16/drivers/leds/leds-e680.c	2006-06-05 15:11:42.000000000 +0200
@@ -0,0 +1,269 @@
+/*
+ * 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/config.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>
+//FIXME this belongs to somewhere else, please
+//      adjust when ssp_pcap.h reached its final destination
+#include "../misc/ezx/ssp_pcap.h"
+
+//FIXME move defines to 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
+
+static enum led_brightness old_red;
+static enum led_brightness old_green;
+static enum led_brightness old_blue;
+
+typedef struct {
+	unsigned char ind_GPIO_red;    /*Indicator Red control GPIO 46: 0 active, 1 disactive*/
+	unsigned char ind_GPIO_green;  /*Indicator Green control GPIO 47: 0 active, 1 disactive*/
+	unsigned char pcap_LEDR_en;    /*pcap LEDR_EN bit value: 1 =Red LED(&Green) sink circuit enabled*/
+	unsigned char pcap_LEDG_en;    /*pcap LEDG_EN bit value:1 =Green(->Blue)LED sink circuit enabled*/
+	unsigned char pcap_LEDR_CTRL; /* 4bits Sets the timing for the red(&Green) LED sink circuit*/
+	unsigned char pcap_LEDG_CTRL; /* 4bits Sets the timing for the GREEN (->Blue) LED sink circuit*/
+	unsigned char pcap_LEDR_I;   /* 2 bits 00 3mA,01 4mA, 10 5mA, 11 9mA, sets the pulsed current level for LEDR*/
+	unsigned char pcap_LEDG_I;   /* 2 bits 00 3mA,01 4mA, 10 5mA, 11 9mA, sets the pulsed current level for LEDG*/
+	unsigned char 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[]=
+{
+  /*  on/off pulsepower  timing  intensity */
+	{0x1,0x1, 0x0,0x0, 0x0,0x0, 0x0,0x0,0x0}, /* OFF */
+	{0x0,0x1, 0x1,0x0, 0xc,0x0, 0x1,0x0,0x0}, /* RED */
+	{0x1,0x0, 0x1,0x0, 0xc,0x0, 0x1,0x0,0x0}, /* GREEN */
+	{0x0,0x0, 0x1,0x0, 0xc,0x0, 0x1,0x0,0x0}, /* ORANGE = RED + GREEN */
+	{0x1,0x1, 0x0,0x1, 0x0,0xc, 0x0,0x0,0x0}, /* BLUE */
+	{0x0,0x1, 0x1,0x1, 0xc,0xc, 0x1,0x0,0x0}, /* LIGHT_RED = RED + BLUE */
+	{0x1,0x0, 0x1,0x1, 0xc,0xc, 0x1,0x0,0x0}, /* LIGHT_GREEN = GREEN + BLUE */
+	{0x0,0x0, 0x1,0x1, 0xc,0xc, 0x1,0x0,0x0}, /* WHITE = RED + GREEN + BLUE */
+};
+
+static void e680led_led_set( enum led_brightness red, enum led_brightness green, enum led_brightness blue )
+{
+	printk( KERN_DEBUG "e680led_led_set: red=%d, green=%d, blue=%d", red, green, blue );
+	unsigned int tempValue = 0;
+	unsigned int value = 0;
+	unsigned int stateIndex = 0;
+	unsigned char gpio_red, gpio_green, ledr_en, ledg_en, ledr_ctrl, ledg_ctrl, ledr_i, ledg_i,skip;
+
+	stateIndex = ( ( blue << 2 ) | ( green << 1 ) | ( red ) )   & 0x7;
+	printk( KERN_DEBUG "LED stateIndex is %d", stateIndex );
+	gpio_red   = led_register_value[stateIndex].ind_GPIO_red    & 0x1;
+	gpio_green = led_register_value[stateIndex].ind_GPIO_green  & 0x1;
+	ledr_en    = led_register_value[stateIndex].pcap_LEDR_en    & 0x1;
+	ledg_en    = led_register_value[stateIndex].pcap_LEDG_en    & 0x1;
+	ledr_ctrl  = led_register_value[stateIndex].pcap_LEDR_CTRL  & 0xf;
+	ledg_ctrl  = led_register_value[stateIndex].pcap_LEDG_CTRL  & 0xf;
+	ledr_i     = led_register_value[stateIndex].pcap_LEDR_I     & 0x3;
+	ledg_i     = led_register_value[stateIndex].pcap_LEDG_I     & 0x3;
+	skip       = led_register_value[stateIndex].pcap_SKIP_on    & 0x1;
+
+	/* disable LEDs */
+	if( ezx_pcap_read(SSP_PCAP_ADJ_PERIPH_REGISTER,&tempValue) != SSP_PCAP_SUCCESS )
+	{
+		printk( KERN_WARNING "LED PCAP Read Failed\n" );
+		return;
+	}
+	tempValue &= (~SSP_PCAP_LED_MASK);
+	if( ezx_pcap_write(SSP_PCAP_ADJ_PERIPH_REGISTER,tempValue) != SSP_PCAP_SUCCESS )
+	{
+		printk( KERN_WARNING "LED PCAP Write Failed (Clear Data)\n" );
+		return;
+	}
+	
+	/* configure GPIOs as output */
+	pxa_gpio_mode(IND_CNTL_R_BUL | GPIO_OUT);
+	pxa_gpio_mode(IND_CNTL_G_BUL | GPIO_OUT);
+
+	//FIXME: Simplify this logic
+	if ( (gpio_green && gpio_red) )
+	{
+		/*Disable Red & Green signal*/
+		set_GPIO(IND_CNTL_R_BUL); /*IND_CNTL_R_BUL Low active*/
+		PGSR(IND_CNTL_R_BUL) = PGSR(IND_CNTL_R_BUL) | GPIO_bit(IND_CNTL_R_BUL);
+		
+		clr_GPIO(IND_CNTL_G_BUL); /*IND_CNTL_G_BUL High active*/
+		PGSR(IND_CNTL_G_BUL) = PGSR(IND_CNTL_G_BUL) & (~GPIO_bit(IND_CNTL_G_BUL));
+		
+		printk( KERN_DEBUG "LED GPIO Green & Red Disable\n");
+	} else if ( gpio_green && !gpio_red )
+	{
+		/*Green Disable, Red Enable*/
+		clr_GPIO(IND_CNTL_R_BUL);
+		PGSR(IND_CNTL_R_BUL) = PGSR(IND_CNTL_R_BUL) & (~GPIO_bit(IND_CNTL_R_BUL));
+		
+		clr_GPIO(IND_CNTL_G_BUL);
+		PGSR(IND_CNTL_G_BUL) = PGSR(IND_CNTL_G_BUL) & (~GPIO_bit(IND_CNTL_G_BUL));
+	
+		printk( KERN_DEBUG "LED GPIO Green Disable, Red Enable\n");
+	} else if (gpio_red && !gpio_green )
+	{
+		/*Red Disable, Green Enable*/
+		set_GPIO(IND_CNTL_R_BUL);
+		PGSR(IND_CNTL_R_BUL) = PGSR(IND_CNTL_R_BUL) | GPIO_bit(IND_CNTL_R_BUL);
+		
+		set_GPIO(IND_CNTL_G_BUL);
+		PGSR(IND_CNTL_G_BUL) = PGSR(IND_CNTL_G_BUL) | GPIO_bit(IND_CNTL_G_BUL);
+		printk( KERN_DEBUG "LED GPIO Red Disable, Green Enable");
+	}else
+	{
+		/*Red & Green enable*/
+		clr_GPIO(IND_CNTL_R_BUL);
+		PGSR(IND_CNTL_R_BUL) = PGSR(IND_CNTL_R_BUL) & (~GPIO_bit(IND_CNTL_R_BUL));
+		
+		set_GPIO(IND_CNTL_G_BUL);
+		PGSR(IND_CNTL_G_BUL) = PGSR(IND_CNTL_G_BUL) | GPIO_bit(IND_CNTL_G_BUL);
+		printk( KERN_DEBUG "LED GPIO Red & Green Enable\n");
+	}
+	
+	/* Write PCAP LED Peripheral Control Register*/
+	value = ( ledr_en | (ledg_en <<1) | (ledr_ctrl <<2) | (ledg_ctrl <<6) |
+		(ledr_i << 10) | (ledg_i <<12) | (skip <<14) ) & 0x7fff;
+	tempValue |= (value <<SSP_PCAP_LED_SHIFT);
+	
+	if ( ezx_pcap_write(SSP_PCAP_ADJ_PERIPH_REGISTER,tempValue) == SSP_PCAP_SUCCESS )
+	{
+		printk( KERN_DEBUG "LED PCAP Write Success (0x%x :0x%x)\n",tempValue,value);
+		old_red = red;
+		old_green = green;
+		old_blue = blue;
+		return;
+	} else {
+		printk( KERN_DEBUG "LED PCAP Write Failed (State Change)\n");
+		return;
+	}
+}
+
+static void e680led_red_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	printk( KERN_DEBUG "e680led_red_set: %d\n", value );
+	e680led_led_set( 1 && value, old_green, old_blue );
+}
+
+static void e680led_green_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	printk( KERN_DEBUG "e680led_green_set: %d\n", value );
+	e680led_led_set( old_red, 1 && value, old_blue );
+}
+
+static void e680led_blue_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	printk( KERN_DEBUG "e680led_blue_set: %d\n", value );
+	e680led_led_set( old_red, old_green, 1 && value );
+}
+
+static struct led_classdev e680_red_led = {
+	.name			= "e680:red",
+	.default_trigger	= "none",
+	.brightness_set		= e680led_red_set,
+};
+
+static struct led_classdev e680_green_led = {
+	.name			= "e680:green",
+	.default_trigger	= "none",
+	.brightness_set		= e680led_green_set,
+};
+
+static struct led_classdev e680_blue_led = {
+	.name			= "e680:blue",
+	.default_trigger	= "none",
+	.brightness_set		= e680led_blue_set,
+};
+
+#ifdef CONFIG_PM
+static int e680led_suspend(struct platform_device *dev, pm_message_t state)
+{
+	led_classdev_suspend(&e680_red_led);
+	led_classdev_suspend(&e680_green_led);
+	led_classdev_suspend(&e680_blue_led);
+	return 0;
+}
+
+static int e680led_resume(struct platform_device *dev)
+{
+	led_classdev_resume(&e680_red_led);
+	led_classdev_resume(&e680_green_led);
+	led_classdev_resume(&e680_blue_led);
+	return 0;
+}
+#endif
+
+static int e680led_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = led_classdev_register(&pdev->dev, &e680_red_led);
+	if (ret < 0)
+		return ret;
+
+	ret = led_classdev_register(&pdev->dev, &e680_green_led);
+	if (ret < 0)
+		led_classdev_unregister(&e680_red_led);
+
+	ret = led_classdev_register(&pdev->dev, &e680_blue_led);
+	if (ret < 0) {
+		led_classdev_unregister(&e680_red_led);
+		led_classdev_unregister(&e680_green_led);
+	}
+	return ret;
+}
+
+static int e680led_remove(struct platform_device *pdev)
+{
+	led_classdev_unregister(&e680_red_led);
+	led_classdev_unregister(&e680_green_led);
+	led_classdev_unregister(&e680_blue_led);
+	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)
+{
+	e680led_led_set( 0, 0, 0 );
+	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");