summaryrefslogtreecommitdiff
path: root/packages/linux/linux-jlime-arm-2.6.17/Mach-Sa1100-Jornada720.patch
blob: cbbb98f2bb2f0c1e0ee30c7b93c891907d949a03 (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
--- linux-2.6.17/arch/arm/mach-sa1100/jornada720.c_orig	2006-07-02 20:54:55.000000000 +0000
+++ linux-2.6.17/arch/arm/mach-sa1100/jornada720.c	2006-07-02 23:12:58.000000000 +0000
@@ -22,11 +22,139 @@
 #include <asm/mach/map.h>
 #include <asm/mach/serial_sa1100.h>
 
+#include <linux/lcd.h>
+#include <linux/backlight.h>
+#include <linux/fb.h>
 #include "generic.h"
 
 
 #define JORTUCR_VAL	0x20000400
 
+/* Jornada 720 MCU functions */
+#define MCU_REVERSE(i) ((unsigned char)(((0x80 & i) >> 7) | ((0x40 & i) >> 5) \
+                       | ((0x20 & i) >> 3) | ((0x10 & i) >> 1) | ((0x08 & i) << 1) \
+		       | ((0x04 & i) << 3) | ((0x02 & i) << 5) | ((0x01 & i) << 7)))
+
+void jornada720_init_ser(void)
+{
+      int i;
+      
+      GPSR = GPIO_GPIO25;
+      Ser4SSCR0 = 0x0307;
+      Ser4MCCR0 = 0;
+      Ser4SSCR1 = 0x18;
+      Ser4SSCR0 = 0x0387;
+      while (Ser4SSSR & SSSR_RNE)
+             i = Ser4SSDR;
+}
+
+int jornada720_mcu_byte(int arg_data)
+{
+      int i;
+      
+      while ((Ser4SSSR & SSSR_TNF) == 0);
+      i = 0;
+      while ((GPLR & 0x400) && i++ < 400000);
+             /* wait for MCU */
+      
+      if (i >= 400000) {
+               printk("jornada 720_mcu_byte: timed out\n");
+	       return -1;
+      }
+      Ser4SSDR = MCU_rEVERSE(arg_data) << 8;
+      udelay(100);
+      while ((Ser4SSSR & SSSR_RNE) == 0);
+      i = Ser4SSDR;
+      if (i > 0xff)
+            printk("jornada720 mcu_byte: read %x\n". i):
+      return MCU_REVERSE(i & 0xff) & 0xff;
+}
+              
+int jornada720_mcu_start(int arg_data)
+{
+      int i;
+      
+      GPCR = GPIO_GPIO25;  /* clear -> enable */
+      udelay(100);
+      i = jornada720_mcu_byte(arg_data);
+      if (i != MCU_TxDummy)
+      {
+              printk("jornada720_mcu_start: sent %x got %x\n",  arg_data, i);
+	      for (i = 0; i < 256; i++)
+	          if (jornada720_mcu_read() == -1)
+		           break;
+		
+	      jornada720_init_ser();
+	      return -1;
+      }
+      
+      return 0;
+}
+
+
+void jornada720_mcu_end(void)
+{
+     udelay(100);
+     GPSR = GPIO_GPIO25; /* set */
+}
+
+void jornada720_mcu_init(void)
+{
+
+     int i;
+     
+     if (state) {
+                 PPSR &= ~PPC_LDD1;
+                 PPDR &= PPC_LDD1;
+     }
+     else {
+                 PPSR |= PPC_LDD1;
+     }
+     return 0;
+}
+
+static int jornada720_backlight_get_power(struct backlight_device *bd)
+{
+
+     return  ~(PPSR&PPC_LDD1);
+}
+
+static int jornada720_backlight_get_brightness(struct  backlight_device *bd)
+{
+     int brightness;
+     jornada720_mcu_start(MCU_GetBrightness);
+     brightness = jornada720_mcu_read();
+     jornada720_mcu_end();
+     return brightness;
+}
+
+static int jornada720_backlight_set_brightness(struct backlight_device *bd)
+{
+     int brightness = 255 - value;
+     jornada720_mcu_start(MCU_SetBrightness);
+     jornada720_mcu_byte(brightness);
+     jornada720_mcu_end();
+     return 0;
+}
+
+static struct backlight_properties jornada720_backlight_properties = {
+       .owner                   =  THIS_MODULE,
+       .set_power               =  jornada720_backlight_set_power,
+       .get_power               =  jornada720_backlight_get_power,
+       .get_brightness          =  jornada720_backlight_get_brightness,
+       .set_brightness          =  jornada720_backlight_set_brightness,
+       .max_brightness          =  255,
+}
+
+static struct lcd_properties jornada 720_lcd_properties = {
+       .owner                   = THIS_MODULE,
+       .set_power               = jornada720_lcd_set_power,
+       .get_power               = jornada720_lcd_get_power,
+       .set_contrast            = jornada720_lcd_set_contrast,
+       .get_contrast            = jornada720_lcd_set_contrast,
+       .max_contrast            = 255,
+}
+
 static struct resource sa1111_resources[] = {
 	[0] = {
 		.start		= 0x40000000,
@@ -77,6 +205,10 @@
 		PPDR |= PPC_LDD3 | PPC_LDD4;
 
 		ret = platform_add_devices(devices, ARRAY_SIZE(devices));
+
+                jornada720_mcu_init();
+		backlight_device_register("e1356fb", 0, &jornada720_backlight_properties);
+		ldc_device_register("e1356fb", 0, &jornada720_lcd_properties);
 	}
 	return ret;
 }