Merge branch 'org.openembedded.dev' of git@git.openembedded.net:openembedded into...
[openembedded.git] / recipes / linux / opensimpad / simpad-serial.patch
1
2 #
3 # Patch managed by http://www.holgerschurig.de/patcher.html
4 #
5
6 --- linux-2.4.27/include/asm-arm/arch-sa1100/simpad.h~simpad-serial
7 +++ linux-2.4.27/include/asm-arm/arch-sa1100/simpad.h
8 @@ -16,7 +16,7 @@
9  #error "include <asm/hardware.h> instead"
10  #endif
11  
12 -#define GPIO_UART1_RTS GPIO_GPIO14
13 +#define GPIO_UART1_RTS GPIO_GPIO9
14  #define GPIO_UART1_DTR GPIO_GPIO7
15  #define GPIO_UART1_CTS GPIO_GPIO8
16  #define GPIO_UART1_DCD GPIO_GPIO23
17 @@ -31,12 +31,12 @@
18  #define GPIO_POWER_BUTTON       GPIO_GPIO0
19  #define GPIO_UCB1300_IRQ       GPIO_GPIO (22)  /* UCB GPIO and touchscreen */
20  
21 -#define IRQ_UART1_CTS  IRQ_GPIO15
22 -#define IRQ_UART1_DCD  GPIO_GPIO23
23 -#define IRQ_UART1_DSR  GPIO_GPIO6
24 -#define IRQ_UART3_CTS  GPIO_GPIO13
25 -#define IRQ_UART3_DCD  GPIO_GPIO18
26 -#define IRQ_UART3_DSR  GPIO_GPIO17
27 +#define IRQ_GPIO_UART1_CTS     IRQ_GPIO8
28 +#define IRQ_GPIO_UART1_DCD     IRQ_GPIO23
29 +#define IRQ_GPIO_UART1_DSR     IRQ_GPIO6
30 +#define IRQ_GPIO_UART3_CTS     IRQ_GPIO13
31 +#define IRQ_GPIO_UART3_DCD     IRQ_GPIO18
32 +#define IRQ_GPIO_UART3_DSR     IRQ_GPIO17
33  
34  #define IRQ_GPIO_UCB1300_IRQ IRQ_GPIO22
35  #define IRQ_GPIO_POWER_BUTTON    IRQ_GPIO0
36 --- linux-2.4.27/arch/arm/mach-sa1100/simpad.c~simpad-serial
37 +++ linux-2.4.27/arch/arm/mach-sa1100/simpad.c
38 @@ -22,9 +22,11 @@
39  
40  #include "generic.h"
41  
42 +#undef SIMPAD_UART_USE_IRQ  // irq handling on CTS/DCD doesn't work yet
43 +
44  long cs3_shadow;
45  
46 -long get_cs3_shadow()
47 +long get_cs3_shadow(void)
48  {
49         return cs3_shadow;
50  }
51 @@ -107,18 +109,170 @@
52    LAST_DESC
53  };
54  
55 +#define SER_INFO(fmt, arg...) printk(KERN_INFO fmt "\n" , ## arg)
56 +
57 +static void simpad_uart_set_mctrl(struct uart_port *port, u_int mctrl)
58 +{
59 +       if (port->mapbase == _Ser1UTCR0) {
60 +               /* internal serial port (ttySA1, DECT/Bluetooth) */
61 +               if (mctrl & TIOCM_RTS)  GPCR = GPIO_UART1_RTS;
62 +               else                    GPSR = GPIO_UART1_RTS;
63 +
64 +               if (mctrl & TIOCM_DTR)  GPCR = GPIO_UART1_DTR;
65 +               else                    GPSR = GPIO_UART1_DTR;
66 +       }
67 +
68 +       else if (port->mapbase == _Ser3UTCR0) {
69 +               /* external serial port (ttySA0, RS232) */
70 +               if (mctrl & TIOCM_RTS)  GPCR = GPIO_UART3_RTS;
71 +               else                    GPSR = GPIO_UART3_RTS;
72 +
73 +               if (mctrl & TIOCM_DTR)  GPCR = GPIO_UART3_DTR;
74 +               else                    GPSR = GPIO_UART3_DTR;
75 +       }
76 +}
77 +
78 +static u_int simpad_uart_get_mctrl(struct uart_port *port)
79 +{
80 +       u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
81 +
82 +       if (port->mapbase == _Ser1UTCR0) {
83 +               /* internal serial port (ttySA1, DECT/Bluetooth) */
84 +               int gplr = GPLR;
85 +               if (gplr & GPIO_UART1_DCD) ret &= ~TIOCM_CD;
86 +               if (gplr & GPIO_UART1_CTS) ret &= ~TIOCM_CTS;
87 +               if (gplr & GPIO_UART1_DSR) ret &= ~TIOCM_DSR;
88 +       }
89 +
90 +       else if (port->mapbase == _Ser3UTCR0) {
91 +               /* external serial port (ttySA0, RS232) */
92 +               int gplr = GPLR;
93 +               if (gplr & GPIO_UART3_DCD) ret &= ~TIOCM_CD;
94 +               if (gplr & GPIO_UART3_CTS) ret &= ~TIOCM_CTS;
95 +               if (gplr & GPIO_UART3_DSR) ret &= ~TIOCM_DSR;
96 +       }
97 +       return ret;
98 +}
99 +
100  static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
101  {
102 -       if (port->mapbase == (u_int)&Ser1UTCR0) {
103 +       if (port->mapbase == (u_int)&Ser3UTCR0) {
104                 if (state)
105                         clear_cs3_bit(RS232_ON);
106                 else
107                         set_cs3_bit(RS232_ON);
108         }
109  }
110 +/*
111 + * Enable/Disable wake up events for this serial port.
112 + * Obviously, we only support this on the normal COM port.
113 + */
114 +static int simpad_uart_set_wake(struct uart_port *port, u_int enable)
115 +{
116 +       int err = -EINVAL;
117 +
118 +#if 0  // TODO: port management
119 +       if (port->mapbase == _Ser3UTCR0) {
120 +               if (enable)
121 +                       PWER |= PWER_GPIO23 | PWER_GPIO25 ; /* DCD and CTS */
122 +               else
123 +                       PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
124 +               err = 0;
125 +       }
126 +#endif
127 +
128 +       return err;
129 +}
130 +
131 +#ifdef SIMPAD_UART_USE_IRQ
132 +static void simpad_uart1_dcd_intr(int irq, void *dev_id, struct pt_regs *regs)
133 +{
134 +       struct uart_port *port = dev_id;
135 +       /* Note: should only call this if something has changed */
136 +       uart_handle_dcd_change(port, !(GPLR & GPIO_UART1_DCD));
137 +}
138 +
139 +static void simpad_uart1_cts_intr(int irq, void *dev_id, struct pt_regs *regs)
140 +{
141 +       struct uart_port *port = dev_id;
142 +       /* Note: should only call this if something has changed */
143 +       uart_handle_cts_change(port, !(GPLR & GPIO_UART1_CTS));
144 +}
145 +
146 +static void simpad_uart3_dcd_intr(int irq, void *dev_id, struct pt_regs *regs)
147 +{
148 +       struct uart_port *port = dev_id;
149 +       /* Note: should only call this if something has changed */
150 +       uart_handle_dcd_change(port, !(GPLR & GPIO_UART3_DCD));
151 +}
152 +
153 +static void simpad_uart3_cts_intr(int irq, void *dev_id, struct pt_regs *regs)
154 +{
155 +       struct uart_port *port = dev_id;
156 +       /* Note: should only call this if something has changed */
157 +       uart_handle_cts_change(port, !(GPLR & GPIO_UART3_CTS));
158 +}
159 +#endif
160 +
161 +static int simpad_uart_open(struct uart_port *port)
162 +{
163 +       int ret = 0;
164 +#ifdef SIMPAD_UART_USE_IRQ
165 +       if (port->mapbase == _Ser1UTCR0) {
166 +               set_GPIO_IRQ_edge(GPIO_UART1_DCD|GPIO_UART1_CTS,
167 +                                 GPIO_BOTH_EDGES);
168 +
169 +               ret = request_irq(IRQ_GPIO_UART1_DCD, simpad_uart1_dcd_intr,
170 +                                 0, "UART1 DCD", port);
171 +               if (ret)
172 +                       return ret;
173 +
174 +               ret = request_irq(IRQ_GPIO_UART1_CTS, simpad_uart1_cts_intr,
175 +                                 0, "UART1 CTS", port);
176 +               if (ret)
177 +                       free_irq(IRQ_GPIO_UART1_DCD, port);
178 +       }
179 +
180 +       else if (port->mapbase == _Ser3UTCR0) {
181 +               set_GPIO_IRQ_edge(GPIO_UART3_DCD|GPIO_UART3_CTS,
182 +                                 GPIO_BOTH_EDGES);
183 +
184 +               ret = request_irq(IRQ_GPIO_UART3_DCD, simpad_uart3_dcd_intr,
185 +                                 0, "UART3 DCD", port);
186 +               if (ret)
187 +                       return ret;
188 +
189 +               ret = request_irq(IRQ_GPIO_UART3_CTS, simpad_uart3_cts_intr,
190 +                                 0, "UART3 CTS", port);
191 +               if (ret)
192 +                       free_irq(IRQ_GPIO_UART3_DCD, port);
193 +       }
194 +#endif
195 +       return ret;
196 +}
197 +
198 +static void simpad_uart_close(struct uart_port *port)
199 +{
200 +#ifdef SIMPAD_UART_USE_IRQ
201 +       if (port->mapbase == _Ser1UTCR0) {
202 +               free_irq(IRQ_GPIO_UART1_DCD, port);
203 +               free_irq(IRQ_GPIO_UART1_CTS, port);
204 +       }
205 +
206 +       else if (port->mapbase == _Ser3UTCR0) {
207 +               free_irq(IRQ_GPIO_UART3_DCD, port);
208 +               free_irq(IRQ_GPIO_UART3_CTS, port);
209 +       }
210 +#endif
211 +}
212  
213  static struct sa1100_port_fns simpad_port_fns __initdata = {
214 -       .pm     = simpad_uart_pm,
215 +       .set_mctrl      = simpad_uart_set_mctrl,
216 +       .get_mctrl      = simpad_uart_get_mctrl,
217 +       .pm             = simpad_uart_pm,
218 +       .set_wake       = simpad_uart_set_wake,
219 +       .open           = simpad_uart_open,
220 +       .close          = simpad_uart_close,
221  };
222  
223  static void __init simpad_map_io(void)
224 @@ -129,13 +283,32 @@
225          set_cs3_bit (EN1 | EN0 | LED2_ON | DISPLAY_ON | RS232_ON |
226                        ENABLE_5V | nRESET_SIMCARD);
227  
228 +       sa1100_register_uart_fns(&simpad_port_fns);
229 +
230          //It is only possible to register 3 UART in serial_sa1100.c
231          sa1100_register_uart(0, 3);
232          sa1100_register_uart(1, 1);
233  
234 +       // txd and rxd use their alternate function
235         GAFR |= (GPIO_UART_TXD | GPIO_UART_RXD);
236 +
237 +       // the control lines are gpio
238 +       GAFR &= ~(GPIO_UART1_RTS | GPIO_UART1_CTS | GPIO_UART1_DCD);
239 +       GAFR &= ~(GPIO_UART1_DSR | GPIO_UART1_DTR);
240 +       GAFR &= ~(GPIO_UART3_RTS | GPIO_UART3_CTS | GPIO_UART3_DCD);
241 +       GAFR &= ~(GPIO_UART3_DSR | GPIO_UART3_DTR);
242 +
243 +       // txd, rts and dtr are outputs
244         GPDR |= GPIO_UART_TXD;
245 +       GPDR |= GPIO_UART1_RTS | GPIO_UART3_RTS;
246 +       GPDR |= GPIO_UART1_DTR | GPIO_UART3_DTR;
247 +
248 +       // cts, dcd, dsr and rxd are inputs
249 +       GPDR &= ~(GPIO_UART1_CTS | GPIO_UART3_CTS);
250 +       GPDR &= ~(GPIO_UART1_DCD | GPIO_UART3_DCD);
251 +       GPDR &= ~(GPIO_UART1_DSR | GPIO_UART3_DSR);
252         GPDR &= ~GPIO_UART_RXD;
253 +
254         PPAR |= PPAR_UPR;
255  
256          set_GPIO_IRQ_edge(GPIO_UCB1300_IRQ, GPIO_RISING_EDGE);
257 --- linux-2.4.27/drivers/video/mq200fb.c~simpad-serial
258 +++ linux-2.4.27/drivers/video/mq200fb.c
259 @@ -672,7 +672,7 @@
260  
261  #ifdef CONFIG_SA1100_SIMPAD
262      GPDR |=   (1<<3);
263 -    GAFR |=  ~(1<<3);
264 +    GAFR &=  ~(1<<3);
265      GPSR |=   (1<<3);
266  #endif
267