patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / serial / pxa.c
1 /*
2  *  linux/drivers/serial/pxa.c
3  *
4  *  Based on drivers/serial/8250.c by Russell King.
5  *
6  *  Author:     Nicolas Pitre
7  *  Created:    Feb 20, 2003
8  *  Copyright:  (C) 2003 Monta Vista Software, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * Note 1: This driver is made separate from the already too overloaded
16  * 8250.c because it needs some kirks of its own and that'll make it
17  * easier to add DMA support.
18  *
19  * Note 2: I'm too sick of device allocation policies for serial ports.
20  * If someone else wants to request an "official" allocation of major/minor
21  * for this driver please be my guest.  And don't forget that new hardware
22  * to come from Intel might have more than 3 or 4 of those UARTs.  Let's
23  * hope for a better port registration and dynamic device allocation scheme
24  * with the serial core maintainer satisfaction to appear soon.
25  */
26
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/tty.h>
30 #include <linux/ioport.h>
31 #include <linux/init.h>
32 #include <linux/console.h>
33 #include <linux/sysrq.h>
34 #include <linux/serial_reg.h>
35 #include <linux/circ_buf.h>
36 #include <linux/delay.h>
37 #include <linux/interrupt.h>
38
39 #include <asm/io.h>
40 #include <asm/hardware.h>
41 #include <asm/irq.h>
42
43 #if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
44 #define SUPPORT_SYSRQ
45 #endif
46
47 #include <linux/serial_core.h>
48
49
50 struct uart_pxa_port {
51         struct uart_port        port;
52         unsigned char           ier;
53         unsigned char           lcr;
54         unsigned char           mcr;
55         unsigned int            lsr_break_flag;
56         unsigned int            cken;
57         char                    *name;
58 };
59
60 static inline unsigned int serial_in(struct uart_pxa_port *up, int offset)
61 {
62         offset <<= 2;
63         return readl(up->port.membase + offset);
64 }
65
66 static inline void serial_out(struct uart_pxa_port *up, int offset, int value)
67 {
68         offset <<= 2;
69         writel(value, up->port.membase + offset);
70 }
71
72 static void serial_pxa_enable_ms(struct uart_port *port)
73 {
74         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
75
76         up->ier |= UART_IER_MSI;
77         serial_out(up, UART_IER, up->ier);
78 }
79
80 static void serial_pxa_stop_tx(struct uart_port *port, unsigned int tty_stop)
81 {
82         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
83
84         if (up->ier & UART_IER_THRI) {
85                 up->ier &= ~UART_IER_THRI;
86                 serial_out(up, UART_IER, up->ier);
87         }
88 }
89
90 static void serial_pxa_stop_rx(struct uart_port *port)
91 {
92         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
93
94         up->ier &= ~UART_IER_RLSI;
95         up->port.read_status_mask &= ~UART_LSR_DR;
96         serial_out(up, UART_IER, up->ier);
97 }
98
99 static inline void
100 receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs)
101 {
102         struct tty_struct *tty = up->port.info->tty;
103         unsigned char ch;
104         int max_count = 256;
105
106         do {
107                 if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
108                         /*
109                          * FIXME: Deadlock can happen here if we're a
110                          * low-latency port.  We're holding the per-port
111                          * spinlock, and we call flush_to_ldisc->
112                          * n_tty_receive_buf->n_tty_receive_char->
113                          * opost->uart_put_char.
114                          */
115                         tty->flip.work.func((void *)tty);
116                         if (tty->flip.count >= TTY_FLIPBUF_SIZE)
117                                 return; // if TTY_DONT_FLIP is set
118                 }
119                 ch = serial_in(up, UART_RX);
120                 *tty->flip.char_buf_ptr = ch;
121                 *tty->flip.flag_buf_ptr = TTY_NORMAL;
122                 up->port.icount.rx++;
123
124                 if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
125                                        UART_LSR_FE | UART_LSR_OE))) {
126                         /*
127                          * For statistics only
128                          */
129                         if (*status & UART_LSR_BI) {
130                                 *status &= ~(UART_LSR_FE | UART_LSR_PE);
131                                 up->port.icount.brk++;
132                                 /*
133                                  * We do the SysRQ and SAK checking
134                                  * here because otherwise the break
135                                  * may get masked by ignore_status_mask
136                                  * or read_status_mask.
137                                  */
138                                 if (uart_handle_break(&up->port))
139                                         goto ignore_char;
140                         } else if (*status & UART_LSR_PE)
141                                 up->port.icount.parity++;
142                         else if (*status & UART_LSR_FE)
143                                 up->port.icount.frame++;
144                         if (*status & UART_LSR_OE)
145                                 up->port.icount.overrun++;
146
147                         /*
148                          * Mask off conditions which should be ignored.
149                          */
150                         *status &= up->port.read_status_mask;
151
152 #ifdef CONFIG_SERIAL_PXA_CONSOLE
153                         if (up->port.line == up->port.cons->index) {
154                                 /* Recover the break flag from console xmit */
155                                 *status |= up->lsr_break_flag;
156                                 up->lsr_break_flag = 0;
157                         }
158 #endif
159                         if (*status & UART_LSR_BI) {
160                                 *tty->flip.flag_buf_ptr = TTY_BREAK;
161                         } else if (*status & UART_LSR_PE)
162                                 *tty->flip.flag_buf_ptr = TTY_PARITY;
163                         else if (*status & UART_LSR_FE)
164                                 *tty->flip.flag_buf_ptr = TTY_FRAME;
165                 }
166                 if (uart_handle_sysrq_char(&up->port, ch, regs))
167                         goto ignore_char;
168                 if ((*status & up->port.ignore_status_mask) == 0) {
169                         tty->flip.flag_buf_ptr++;
170                         tty->flip.char_buf_ptr++;
171                         tty->flip.count++;
172                 }
173                 if ((*status & UART_LSR_OE) &&
174                     tty->flip.count < TTY_FLIPBUF_SIZE) {
175                         /*
176                          * Overrun is special, since it's reported
177                          * immediately, and doesn't affect the current
178                          * character.
179                          */
180                         *tty->flip.flag_buf_ptr = TTY_OVERRUN;
181                         tty->flip.flag_buf_ptr++;
182                         tty->flip.char_buf_ptr++;
183                         tty->flip.count++;
184                 }
185         ignore_char:
186                 *status = serial_in(up, UART_LSR);
187         } while ((*status & UART_LSR_DR) && (max_count-- > 0));
188         tty_flip_buffer_push(tty);
189 }
190
191 static void transmit_chars(struct uart_pxa_port *up)
192 {
193         struct circ_buf *xmit = &up->port.info->xmit;
194         int count;
195
196         if (up->port.x_char) {
197                 serial_out(up, UART_TX, up->port.x_char);
198                 up->port.icount.tx++;
199                 up->port.x_char = 0;
200                 return;
201         }
202         if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
203                 serial_pxa_stop_tx(&up->port, 0);
204                 return;
205         }
206
207         count = up->port.fifosize / 2;
208         do {
209                 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
210                 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
211                 up->port.icount.tx++;
212                 if (uart_circ_empty(xmit))
213                         break;
214         } while (--count > 0);
215
216         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
217                 uart_write_wakeup(&up->port);
218
219
220         if (uart_circ_empty(xmit))
221                 serial_pxa_stop_tx(&up->port, 0);
222 }
223
224 static void serial_pxa_start_tx(struct uart_port *port, unsigned int tty_start)
225 {
226         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
227
228         if (!(up->ier & UART_IER_THRI)) {
229                 up->ier |= UART_IER_THRI;
230                 serial_out(up, UART_IER, up->ier);
231         }
232 }
233
234 static inline void check_modem_status(struct uart_pxa_port *up)
235 {
236         int status;
237
238         status = serial_in(up, UART_MSR);
239
240         if ((status & UART_MSR_ANY_DELTA) == 0)
241                 return;
242
243         if (status & UART_MSR_TERI)
244                 up->port.icount.rng++;
245         if (status & UART_MSR_DDSR)
246                 up->port.icount.dsr++;
247         if (status & UART_MSR_DDCD)
248                 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
249         if (status & UART_MSR_DCTS)
250                 uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
251
252         wake_up_interruptible(&up->port.info->delta_msr_wait);
253 }
254
255 /*
256  * This handles the interrupt from one port.
257  */
258 static inline irqreturn_t
259 serial_pxa_irq(int irq, void *dev_id, struct pt_regs *regs)
260 {
261         struct uart_pxa_port *up = (struct uart_pxa_port *)dev_id;
262         unsigned int iir, lsr;
263
264         iir = serial_in(up, UART_IIR);
265         if (iir & UART_IIR_NO_INT)
266                 return IRQ_NONE;
267         lsr = serial_in(up, UART_LSR);
268         if (lsr & UART_LSR_DR)
269                 receive_chars(up, &lsr, regs);
270         check_modem_status(up);
271         if (lsr & UART_LSR_THRE)
272                 transmit_chars(up);
273         return IRQ_HANDLED;
274 }
275
276 static unsigned int serial_pxa_tx_empty(struct uart_port *port)
277 {
278         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
279         unsigned long flags;
280         unsigned int ret;
281
282         spin_lock_irqsave(&up->port.lock, flags);
283         ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
284         spin_unlock_irqrestore(&up->port.lock, flags);
285
286         return ret;
287 }
288
289 static unsigned int serial_pxa_get_mctrl(struct uart_port *port)
290 {
291         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
292         unsigned long flags;
293         unsigned char status;
294         unsigned int ret;
295
296 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
297         spin_lock_irqsave(&up->port.lock, flags);
298         status = serial_in(up, UART_MSR);
299         spin_unlock_irqrestore(&up->port.lock, flags);
300
301         ret = 0;
302         if (status & UART_MSR_DCD)
303                 ret |= TIOCM_CAR;
304         if (status & UART_MSR_RI)
305                 ret |= TIOCM_RNG;
306         if (status & UART_MSR_DSR)
307                 ret |= TIOCM_DSR;
308         if (status & UART_MSR_CTS)
309                 ret |= TIOCM_CTS;
310         return ret;
311 }
312
313 static void serial_pxa_set_mctrl(struct uart_port *port, unsigned int mctrl)
314 {
315         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
316         unsigned char mcr = 0;
317
318         if (mctrl & TIOCM_RTS)
319                 mcr |= UART_MCR_RTS;
320         if (mctrl & TIOCM_DTR)
321                 mcr |= UART_MCR_DTR;
322         if (mctrl & TIOCM_OUT1)
323                 mcr |= UART_MCR_OUT1;
324         if (mctrl & TIOCM_OUT2)
325                 mcr |= UART_MCR_OUT2;
326         if (mctrl & TIOCM_LOOP)
327                 mcr |= UART_MCR_LOOP;
328
329         mcr |= up->mcr;
330
331         serial_out(up, UART_MCR, mcr);
332 }
333
334 static void serial_pxa_break_ctl(struct uart_port *port, int break_state)
335 {
336         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
337         unsigned long flags;
338
339         spin_lock_irqsave(&up->port.lock, flags);
340         if (break_state == -1)
341                 up->lcr |= UART_LCR_SBC;
342         else
343                 up->lcr &= ~UART_LCR_SBC;
344         serial_out(up, UART_LCR, up->lcr);
345         spin_unlock_irqrestore(&up->port.lock, flags);
346 }
347
348 #if 0
349 static void serial_pxa_dma_init(struct pxa_uart *up)
350 {
351         up->rxdma =
352                 pxa_request_dma(up->name, DMA_PRIO_LOW, pxa_receive_dma, up);
353         if (up->rxdma < 0)
354                 goto out;
355         up->txdma =
356                 pxa_request_dma(up->name, DMA_PRIO_LOW, pxa_transmit_dma, up);
357         if (up->txdma < 0)
358                 goto err_txdma;
359         up->dmadesc = kmalloc(4 * sizeof(pxa_dma_desc), GFP_KERNEL);
360         if (!up->dmadesc)
361                 goto err_alloc;
362
363         /* ... */
364 err_alloc:
365         pxa_free_dma(up->txdma);
366 err_rxdma:
367         pxa_free_dma(up->rxdma);
368 out:
369         return;
370 }
371 #endif
372
373 static int serial_pxa_startup(struct uart_port *port)
374 {
375         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
376         unsigned long flags;
377         int retval;
378
379         up->mcr = 0;
380
381         /*
382          * Allocate the IRQ
383          */
384         retval = request_irq(up->port.irq, serial_pxa_irq, 0, up->name, up);
385         if (retval)
386                 return retval;
387
388         /*
389          * Clear the FIFO buffers and disable them.
390          * (they will be reenabled in set_termios())
391          */
392         serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
393         serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
394                         UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
395         serial_out(up, UART_FCR, 0);
396
397         /*
398          * Clear the interrupt registers.
399          */
400         (void) serial_in(up, UART_LSR);
401         (void) serial_in(up, UART_RX);
402         (void) serial_in(up, UART_IIR);
403         (void) serial_in(up, UART_MSR);
404
405         /*
406          * Now, initialize the UART
407          */
408         serial_out(up, UART_LCR, UART_LCR_WLEN8);
409
410         spin_lock_irqsave(&up->port.lock, flags);
411         up->port.mctrl |= TIOCM_OUT2;
412         serial_pxa_set_mctrl(&up->port, up->port.mctrl);
413         spin_unlock_irqrestore(&up->port.lock, flags);
414
415         /*
416          * Finally, enable interrupts.  Note: Modem status interrupts
417          * are set via set_termios(), which will be occuring imminently
418          * anyway, so we don't enable them here.
419          */
420         up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE;
421         serial_out(up, UART_IER, up->ier);
422
423         /*
424          * And clear the interrupt registers again for luck.
425          */
426         (void) serial_in(up, UART_LSR);
427         (void) serial_in(up, UART_RX);
428         (void) serial_in(up, UART_IIR);
429         (void) serial_in(up, UART_MSR);
430
431         return 0;
432 }
433
434 static void serial_pxa_shutdown(struct uart_port *port)
435 {
436         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
437         unsigned long flags;
438
439         free_irq(up->port.irq, up);
440
441         /*
442          * Disable interrupts from this port
443          */
444         up->ier = 0;
445         serial_out(up, UART_IER, 0);
446
447         spin_lock_irqsave(&up->port.lock, flags);
448         up->port.mctrl &= ~TIOCM_OUT2;
449         serial_pxa_set_mctrl(&up->port, up->port.mctrl);
450         spin_unlock_irqrestore(&up->port.lock, flags);
451
452         /*
453          * Disable break condition and FIFOs
454          */
455         serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC);
456         serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
457                                   UART_FCR_CLEAR_RCVR |
458                                   UART_FCR_CLEAR_XMIT);
459         serial_out(up, UART_FCR, 0);
460 }
461
462 static void
463 serial_pxa_set_termios(struct uart_port *port, struct termios *termios,
464                        struct termios *old)
465 {
466         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
467         unsigned char cval, fcr = 0;
468         unsigned long flags;
469         unsigned int baud, quot;
470
471         switch (termios->c_cflag & CSIZE) {
472         case CS5:
473                 cval = 0x00;
474                 break;
475         case CS6:
476                 cval = 0x01;
477                 break;
478         case CS7:
479                 cval = 0x02;
480                 break;
481         default:
482         case CS8:
483                 cval = 0x03;
484                 break;
485         }
486
487         if (termios->c_cflag & CSTOPB)
488                 cval |= 0x04;
489         if (termios->c_cflag & PARENB)
490                 cval |= UART_LCR_PARITY;
491         if (!(termios->c_cflag & PARODD))
492                 cval |= UART_LCR_EPAR;
493
494         /*
495          * Ask the core to calculate the divisor for us.
496          */
497         baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
498         quot = uart_get_divisor(port, baud);
499
500         if ((up->port.uartclk / quot) < (2400 * 16))
501                 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR1;
502         else
503                 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR8;
504
505         /*
506          * Ok, we're now changing the port state.  Do it with
507          * interrupts disabled.
508          */
509         spin_lock_irqsave(&up->port.lock, flags);
510
511         /*
512          * Ensure the port will be enabled.
513          * This is required especially for serial console.
514          */
515         up->ier |= IER_UUE;
516
517         /*
518          * Update the per-port timeout.
519          */
520         uart_update_timeout(port, termios->c_cflag, quot);
521
522         up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
523         if (termios->c_iflag & INPCK)
524                 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
525         if (termios->c_iflag & (BRKINT | PARMRK))
526                 up->port.read_status_mask |= UART_LSR_BI;
527
528         /*
529          * Characters to ignore
530          */
531         up->port.ignore_status_mask = 0;
532         if (termios->c_iflag & IGNPAR)
533                 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
534         if (termios->c_iflag & IGNBRK) {
535                 up->port.ignore_status_mask |= UART_LSR_BI;
536                 /*
537                  * If we're ignoring parity and break indicators,
538                  * ignore overruns too (for real raw support).
539                  */
540                 if (termios->c_iflag & IGNPAR)
541                         up->port.ignore_status_mask |= UART_LSR_OE;
542         }
543
544         /*
545          * ignore all characters if CREAD is not set
546          */
547         if ((termios->c_cflag & CREAD) == 0)
548                 up->port.ignore_status_mask |= UART_LSR_DR;
549
550         /*
551          * CTS flow control flag and modem status interrupts
552          */
553         up->ier &= ~UART_IER_MSI;
554         if (UART_ENABLE_MS(&up->port, termios->c_cflag))
555                 up->ier |= UART_IER_MSI;
556
557         serial_out(up, UART_IER, up->ier);
558
559         serial_out(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
560         serial_out(up, UART_DLL, quot & 0xff);          /* LS of divisor */
561         serial_out(up, UART_DLM, quot >> 8);            /* MS of divisor */
562         serial_out(up, UART_LCR, cval);         /* reset DLAB */
563         up->lcr = cval;                                 /* Save LCR */
564         serial_pxa_set_mctrl(&up->port, up->port.mctrl);
565         serial_out(up, UART_FCR, fcr);
566         spin_unlock_irqrestore(&up->port.lock, flags);
567 }
568
569 static void
570 serial_pxa_pm(struct uart_port *port, unsigned int state,
571               unsigned int oldstate)
572 {
573         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
574         if (state) {
575                 /* sleep */
576                 CKEN &= ~up->cken;
577         } else {
578                 /* wake */
579                 CKEN |= up->cken;
580                 udelay(1);
581         }
582 }
583
584 static void serial_pxa_release_port(struct uart_port *port)
585 {
586 }
587
588 static int serial_pxa_request_port(struct uart_port *port)
589 {
590         return 0;
591 }
592
593 static void serial_pxa_config_port(struct uart_port *port, int flags)
594 {
595         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
596         up->port.type = PORT_PXA;
597 }
598
599 static int
600 serial_pxa_verify_port(struct uart_port *port, struct serial_struct *ser)
601 {
602         /* we don't want the core code to modify any port params */
603         return -EINVAL;
604 }
605
606 static const char *
607 serial_pxa_type(struct uart_port *port)
608 {
609         struct uart_pxa_port *up = (struct uart_pxa_port *)port;
610         return up->name;
611 }
612
613 #ifdef CONFIG_SERIAL_PXA_CONSOLE
614
615 extern struct uart_pxa_port serial_pxa_ports[];
616 extern struct uart_driver serial_pxa_reg;
617
618 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
619
620 /*
621  *      Wait for transmitter & holding register to empty
622  */
623 static inline void wait_for_xmitr(struct uart_pxa_port *up)
624 {
625         unsigned int status, tmout = 10000;
626
627         /* Wait up to 10ms for the character(s) to be sent. */
628         do {
629                 status = serial_in(up, UART_LSR);
630
631                 if (status & UART_LSR_BI)
632                         up->lsr_break_flag = UART_LSR_BI;
633
634                 if (--tmout == 0)
635                         break;
636                 udelay(1);
637         } while ((status & BOTH_EMPTY) != BOTH_EMPTY);
638
639         /* Wait up to 1s for flow control if necessary */
640         if (up->port.flags & UPF_CONS_FLOW) {
641                 tmout = 1000000;
642                 while (--tmout &&
643                        ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
644                         udelay(1);
645         }
646 }
647
648 /*
649  * Print a string to the serial port trying not to disturb
650  * any possible real use of the port...
651  *
652  *      The console_lock must be held when we get here.
653  */
654 static void
655 serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
656 {
657         struct uart_pxa_port *up = &serial_pxa_ports[co->index];
658         unsigned int ier;
659         int i;
660
661         /*
662          *      First save the UER then disable the interrupts
663          */
664         ier = serial_in(up, UART_IER);
665         serial_out(up, UART_IER, UART_IER_UUE);
666
667         /*
668          *      Now, do each character
669          */
670         for (i = 0; i < count; i++, s++) {
671                 wait_for_xmitr(up);
672
673                 /*
674                  *      Send the character out.
675                  *      If a LF, also do CR...
676                  */
677                 serial_out(up, UART_TX, *s);
678                 if (*s == 10) {
679                         wait_for_xmitr(up);
680                         serial_out(up, UART_TX, 13);
681                 }
682         }
683
684         /*
685          *      Finally, wait for transmitter to become empty
686          *      and restore the IER
687          */
688         wait_for_xmitr(up);
689         serial_out(up, UART_IER, ier);
690 }
691
692 static int __init
693 serial_pxa_console_setup(struct console *co, char *options)
694 {
695         struct uart_pxa_port *up;
696         int baud = 9600;
697         int bits = 8;
698         int parity = 'n';
699         int flow = 'n';
700
701         if (co->index == -1 || co->index >= serial_pxa_reg.nr)
702                 co->index = 0;
703         up = &serial_pxa_ports[co->index];
704
705         if (options)
706                 uart_parse_options(options, &baud, &parity, &bits, &flow);
707
708         return uart_set_options(&up->port, co, baud, parity, bits, flow);
709 }
710
711 static struct console serial_pxa_console = {
712         .name           = "ttyS",
713         .write          = serial_pxa_console_write,
714         .device         = uart_console_device,
715         .setup          = serial_pxa_console_setup,
716         .flags          = CON_PRINTBUFFER,
717         .index          = -1,
718         .data           = &serial_pxa_reg,
719 };
720
721 static int __init
722 serial_pxa_console_init(void)
723 {
724         register_console(&serial_pxa_console);
725         return 0;
726 }
727
728 console_initcall(serial_pxa_console_init);
729
730 #define PXA_CONSOLE     &serial_pxa_console
731 #else
732 #define PXA_CONSOLE     NULL
733 #endif
734
735 struct uart_ops serial_pxa_pops = {
736         .tx_empty       = serial_pxa_tx_empty,
737         .set_mctrl      = serial_pxa_set_mctrl,
738         .get_mctrl      = serial_pxa_get_mctrl,
739         .stop_tx        = serial_pxa_stop_tx,
740         .start_tx       = serial_pxa_start_tx,
741         .stop_rx        = serial_pxa_stop_rx,
742         .enable_ms      = serial_pxa_enable_ms,
743         .break_ctl      = serial_pxa_break_ctl,
744         .startup        = serial_pxa_startup,
745         .shutdown       = serial_pxa_shutdown,
746         .set_termios    = serial_pxa_set_termios,
747         .pm             = serial_pxa_pm,
748         .type           = serial_pxa_type,
749         .release_port   = serial_pxa_release_port,
750         .request_port   = serial_pxa_request_port,
751         .config_port    = serial_pxa_config_port,
752         .verify_port    = serial_pxa_verify_port,
753 };
754
755 static struct uart_pxa_port serial_pxa_ports[] = {
756      {  /* FFUART */
757         .name   = "FFUART",
758         .cken   = CKEN6_FFUART,
759         .port   = {
760                 .type           = PORT_PXA,
761                 .iotype         = UPIO_MEM,
762                 .membase        = (void *)&FFUART,
763                 .mapbase        = __PREG(FFUART),
764                 .irq            = IRQ_FFUART,
765                 .uartclk        = 921600 * 16,
766                 .fifosize       = 64,
767                 .ops            = &serial_pxa_pops,
768                 .line           = 0,
769         },
770   }, {  /* BTUART */
771         .name   = "BTUART",
772         .cken   = CKEN7_BTUART,
773         .port   = {
774                 .type           = PORT_PXA,
775                 .iotype         = UPIO_MEM,
776                 .membase        = (void *)&BTUART,
777                 .mapbase        = __PREG(BTUART),
778                 .irq            = IRQ_BTUART,
779                 .uartclk        = 921600 * 16,
780                 .fifosize       = 64,
781                 .ops            = &serial_pxa_pops,
782                 .line           = 1,
783         },
784   }, {  /* STUART */
785         .name   = "STUART",
786         .cken   = CKEN5_STUART,
787         .port   = {
788                 .type           = PORT_PXA,
789                 .iotype         = UPIO_MEM,
790                 .membase        = (void *)&STUART,
791                 .mapbase        = __PREG(STUART),
792                 .irq            = IRQ_STUART,
793                 .uartclk        = 921600 * 16,
794                 .fifosize       = 64,
795                 .ops            = &serial_pxa_pops,
796                 .line           = 2,
797         },
798   }
799 };
800
801 static struct uart_driver serial_pxa_reg = {
802         .owner          = THIS_MODULE,
803         .driver_name    = "PXA serial",
804         .devfs_name     = "tts/",
805         .dev_name       = "ttyS",
806         .major          = TTY_MAJOR,
807         .minor          = 64,
808         .nr             = ARRAY_SIZE(serial_pxa_ports),
809         .cons           = PXA_CONSOLE,
810 };
811
812 static int __init serial_pxa_init(void)
813 {
814         int i, ret;
815
816         ret = uart_register_driver(&serial_pxa_reg);
817         if (ret)
818                 return ret;
819
820         for (i = 0; i < ARRAY_SIZE(serial_pxa_ports); i++)
821                 uart_add_one_port(&serial_pxa_reg, &serial_pxa_ports[i].port);
822
823         return 0;
824 }
825
826 static void __exit serial_pxa_exit(void)
827 {
828         int i;
829
830         for (i = 0; i < ARRAY_SIZE(serial_pxa_ports); i++)
831                 uart_remove_one_port(&serial_pxa_reg, &serial_pxa_ports[i].port);
832         uart_unregister_driver(&serial_pxa_reg);
833 }
834
835 module_init(serial_pxa_init);
836 module_exit(serial_pxa_exit);
837
838 MODULE_LICENSE("GPL");
839