2 * UART driver for PNX8XXX SoCs
4 * Author: Per Hallsmark per.hallsmark@mvista.com
5 * Ported to 2.6 kernel by EmbeddedAlley
6 * Reworked by Vitaly Wool <vitalywool@gmail.com>
8 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
9 * Copyright (C) 2000 Deep Blue Solutions Ltd.
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of
13 * any kind, whether express or implied.
17 #if defined(CONFIG_SERIAL_PNX8XXX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
21 #include <linux/module.h>
22 #include <linux/ioport.h>
23 #include <linux/init.h>
24 #include <linux/console.h>
25 #include <linux/sysrq.h>
26 #include <linux/device.h>
27 #include <linux/platform_device.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
30 #include <linux/serial_core.h>
31 #include <linux/serial.h>
32 #include <linux/serial_pnx8xxx.h>
37 /* We'll be using StrongARM sa1100 serial port major/minor */
38 #define SERIAL_PNX8XXX_MAJOR 204
43 #define PNX8XXX_ISR_PASS_LIMIT 256
46 * Convert from ignore_status_mask or read_status_mask to FIFO
47 * and interrupt status bits
49 #define SM_TO_FIFO(x) ((x) >> 10)
50 #define SM_TO_ISTAT(x) ((x) & 0x000001ff)
51 #define FIFO_TO_SM(x) ((x) << 10)
52 #define ISTAT_TO_SM(x) ((x) & 0x000001ff)
55 * This is the size of our serial port register set.
57 #define UART_PORT_SIZE 0x1000
60 * This determines how often we check the modem status signals
61 * for any change. They generally aren't connected to an IRQ
62 * so we have to poll them. We also check immediately before
63 * filling the TX fifo incase CTS has been dropped.
65 #define MCTRL_TIMEOUT (250*HZ/1000)
67 extern struct pnx8xxx_port pnx8xxx_ports
[];
69 static inline int serial_in(struct pnx8xxx_port
*sport
, int offset
)
71 return (__raw_readl(sport
->port
.membase
+ offset
));
74 static inline void serial_out(struct pnx8xxx_port
*sport
, int offset
, int value
)
76 __raw_writel(value
, sport
->port
.membase
+ offset
);
80 * Handle any change of modem status signal since we were last called.
82 static void pnx8xxx_mctrl_check(struct pnx8xxx_port
*sport
)
84 unsigned int status
, changed
;
86 status
= sport
->port
.ops
->get_mctrl(&sport
->port
);
87 changed
= status
^ sport
->old_status
;
92 sport
->old_status
= status
;
94 if (changed
& TIOCM_RI
)
95 sport
->port
.icount
.rng
++;
96 if (changed
& TIOCM_DSR
)
97 sport
->port
.icount
.dsr
++;
98 if (changed
& TIOCM_CAR
)
99 uart_handle_dcd_change(&sport
->port
, status
& TIOCM_CAR
);
100 if (changed
& TIOCM_CTS
)
101 uart_handle_cts_change(&sport
->port
, status
& TIOCM_CTS
);
103 wake_up_interruptible(&sport
->port
.state
->port
.delta_msr_wait
);
107 * This is our per-port timeout handler, for checking the
108 * modem status signals.
110 static void pnx8xxx_timeout(unsigned long data
)
112 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)data
;
115 if (sport
->port
.state
) {
116 spin_lock_irqsave(&sport
->port
.lock
, flags
);
117 pnx8xxx_mctrl_check(sport
);
118 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
120 mod_timer(&sport
->timer
, jiffies
+ MCTRL_TIMEOUT
);
125 * interrupts disabled on entry
127 static void pnx8xxx_stop_tx(struct uart_port
*port
)
129 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
132 /* Disable TX intr */
133 ien
= serial_in(sport
, PNX8XXX_IEN
);
134 serial_out(sport
, PNX8XXX_IEN
, ien
& ~PNX8XXX_UART_INT_ALLTX
);
136 /* Clear all pending TX intr */
137 serial_out(sport
, PNX8XXX_ICLR
, PNX8XXX_UART_INT_ALLTX
);
141 * interrupts may not be disabled on entry
143 static void pnx8xxx_start_tx(struct uart_port
*port
)
145 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
148 /* Clear all pending TX intr */
149 serial_out(sport
, PNX8XXX_ICLR
, PNX8XXX_UART_INT_ALLTX
);
152 ien
= serial_in(sport
, PNX8XXX_IEN
);
153 serial_out(sport
, PNX8XXX_IEN
, ien
| PNX8XXX_UART_INT_ALLTX
);
159 static void pnx8xxx_stop_rx(struct uart_port
*port
)
161 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
164 /* Disable RX intr */
165 ien
= serial_in(sport
, PNX8XXX_IEN
);
166 serial_out(sport
, PNX8XXX_IEN
, ien
& ~PNX8XXX_UART_INT_ALLRX
);
168 /* Clear all pending RX intr */
169 serial_out(sport
, PNX8XXX_ICLR
, PNX8XXX_UART_INT_ALLRX
);
173 * Set the modem control timer to fire immediately.
175 static void pnx8xxx_enable_ms(struct uart_port
*port
)
177 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
179 mod_timer(&sport
->timer
, jiffies
);
182 static void pnx8xxx_rx_chars(struct pnx8xxx_port
*sport
)
184 struct tty_struct
*tty
= sport
->port
.state
->port
.tty
;
185 unsigned int status
, ch
, flg
;
187 status
= FIFO_TO_SM(serial_in(sport
, PNX8XXX_FIFO
)) |
188 ISTAT_TO_SM(serial_in(sport
, PNX8XXX_ISTAT
));
189 while (status
& FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFIFO
)) {
190 ch
= serial_in(sport
, PNX8XXX_FIFO
) & 0xff;
192 sport
->port
.icount
.rx
++;
197 * note that the error handling code is
198 * out of the main execution path
200 if (status
& (FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE
|
201 PNX8XXX_UART_FIFO_RXPAR
|
202 PNX8XXX_UART_FIFO_RXBRK
) |
203 ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN
))) {
204 if (status
& FIFO_TO_SM(PNX8XXX_UART_FIFO_RXBRK
)) {
205 status
&= ~(FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE
) |
206 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR
));
207 sport
->port
.icount
.brk
++;
208 if (uart_handle_break(&sport
->port
))
210 } else if (status
& FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR
))
211 sport
->port
.icount
.parity
++;
212 else if (status
& FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE
))
213 sport
->port
.icount
.frame
++;
214 if (status
& ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN
))
215 sport
->port
.icount
.overrun
++;
217 status
&= sport
->port
.read_status_mask
;
219 if (status
& FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR
))
221 else if (status
& FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE
))
225 sport
->port
.sysrq
= 0;
229 if (uart_handle_sysrq_char(&sport
->port
, ch
))
232 uart_insert_char(&sport
->port
, status
,
233 ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN
), ch
, flg
);
236 serial_out(sport
, PNX8XXX_LCR
, serial_in(sport
, PNX8XXX_LCR
) |
237 PNX8XXX_UART_LCR_RX_NEXT
);
238 status
= FIFO_TO_SM(serial_in(sport
, PNX8XXX_FIFO
)) |
239 ISTAT_TO_SM(serial_in(sport
, PNX8XXX_ISTAT
));
241 tty_flip_buffer_push(tty
);
244 static void pnx8xxx_tx_chars(struct pnx8xxx_port
*sport
)
246 struct circ_buf
*xmit
= &sport
->port
.state
->xmit
;
248 if (sport
->port
.x_char
) {
249 serial_out(sport
, PNX8XXX_FIFO
, sport
->port
.x_char
);
250 sport
->port
.icount
.tx
++;
251 sport
->port
.x_char
= 0;
256 * Check the modem control lines before
257 * transmitting anything.
259 pnx8xxx_mctrl_check(sport
);
261 if (uart_circ_empty(xmit
) || uart_tx_stopped(&sport
->port
)) {
262 pnx8xxx_stop_tx(&sport
->port
);
267 * TX while bytes available
269 while (((serial_in(sport
, PNX8XXX_FIFO
) &
270 PNX8XXX_UART_FIFO_TXFIFO
) >> 16) < 16) {
271 serial_out(sport
, PNX8XXX_FIFO
, xmit
->buf
[xmit
->tail
]);
272 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
273 sport
->port
.icount
.tx
++;
274 if (uart_circ_empty(xmit
))
278 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
279 uart_write_wakeup(&sport
->port
);
281 if (uart_circ_empty(xmit
))
282 pnx8xxx_stop_tx(&sport
->port
);
285 static irqreturn_t
pnx8xxx_int(int irq
, void *dev_id
)
287 struct pnx8xxx_port
*sport
= dev_id
;
290 spin_lock(&sport
->port
.lock
);
291 /* Get the interrupts */
292 status
= serial_in(sport
, PNX8XXX_ISTAT
) & serial_in(sport
, PNX8XXX_IEN
);
294 /* Byte or break signal received */
295 if (status
& (PNX8XXX_UART_INT_RX
| PNX8XXX_UART_INT_BREAK
))
296 pnx8xxx_rx_chars(sport
);
298 /* TX holding register empty - transmit a byte */
299 if (status
& PNX8XXX_UART_INT_TX
)
300 pnx8xxx_tx_chars(sport
);
302 /* Clear the ISTAT register */
303 serial_out(sport
, PNX8XXX_ICLR
, status
);
305 spin_unlock(&sport
->port
.lock
);
310 * Return TIOCSER_TEMT when transmitter is not busy.
312 static unsigned int pnx8xxx_tx_empty(struct uart_port
*port
)
314 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
316 return serial_in(sport
, PNX8XXX_FIFO
) & PNX8XXX_UART_FIFO_TXFIFO_STA
? 0 : TIOCSER_TEMT
;
319 static unsigned int pnx8xxx_get_mctrl(struct uart_port
*port
)
321 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
322 unsigned int mctrl
= TIOCM_DSR
;
327 msr
= serial_in(sport
, PNX8XXX_MCR
);
329 mctrl
|= msr
& PNX8XXX_UART_MCR_CTS
? TIOCM_CTS
: 0;
330 mctrl
|= msr
& PNX8XXX_UART_MCR_DCD
? TIOCM_CAR
: 0;
335 static void pnx8xxx_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
338 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
344 * Interrupts always disabled.
346 static void pnx8xxx_break_ctl(struct uart_port
*port
, int break_state
)
348 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
352 spin_lock_irqsave(&sport
->port
.lock
, flags
);
353 lcr
= serial_in(sport
, PNX8XXX_LCR
);
354 if (break_state
== -1)
355 lcr
|= PNX8XXX_UART_LCR_TXBREAK
;
357 lcr
&= ~PNX8XXX_UART_LCR_TXBREAK
;
358 serial_out(sport
, PNX8XXX_LCR
, lcr
);
359 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
362 static int pnx8xxx_startup(struct uart_port
*port
)
364 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
370 retval
= request_irq(sport
->port
.irq
, pnx8xxx_int
, 0,
371 "pnx8xxx-uart", sport
);
376 * Finally, clear and enable interrupts
379 serial_out(sport
, PNX8XXX_ICLR
, PNX8XXX_UART_INT_ALLRX
|
380 PNX8XXX_UART_INT_ALLTX
);
382 serial_out(sport
, PNX8XXX_IEN
, serial_in(sport
, PNX8XXX_IEN
) |
383 PNX8XXX_UART_INT_ALLRX
|
384 PNX8XXX_UART_INT_ALLTX
);
387 * Enable modem status interrupts
389 spin_lock_irq(&sport
->port
.lock
);
390 pnx8xxx_enable_ms(&sport
->port
);
391 spin_unlock_irq(&sport
->port
.lock
);
396 static void pnx8xxx_shutdown(struct uart_port
*port
)
398 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
404 del_timer_sync(&sport
->timer
);
407 * Disable all interrupts
409 serial_out(sport
, PNX8XXX_IEN
, 0);
412 * Reset the Tx and Rx FIFOS, disable the break condition
414 lcr
= serial_in(sport
, PNX8XXX_LCR
);
415 lcr
&= ~PNX8XXX_UART_LCR_TXBREAK
;
416 lcr
|= PNX8XXX_UART_LCR_TX_RST
| PNX8XXX_UART_LCR_RX_RST
;
417 serial_out(sport
, PNX8XXX_LCR
, lcr
);
420 * Clear all interrupts
422 serial_out(sport
, PNX8XXX_ICLR
, PNX8XXX_UART_INT_ALLRX
|
423 PNX8XXX_UART_INT_ALLTX
);
428 free_irq(sport
->port
.irq
, sport
);
432 pnx8xxx_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
433 struct ktermios
*old
)
435 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
437 unsigned int lcr_fcr
, old_ien
, baud
, quot
;
438 unsigned int old_csize
= old
? old
->c_cflag
& CSIZE
: CS8
;
441 * We only support CS7 and CS8.
443 while ((termios
->c_cflag
& CSIZE
) != CS7
&&
444 (termios
->c_cflag
& CSIZE
) != CS8
) {
445 termios
->c_cflag
&= ~CSIZE
;
446 termios
->c_cflag
|= old_csize
;
450 if ((termios
->c_cflag
& CSIZE
) == CS8
)
451 lcr_fcr
= PNX8XXX_UART_LCR_8BIT
;
455 if (termios
->c_cflag
& CSTOPB
)
456 lcr_fcr
|= PNX8XXX_UART_LCR_2STOPB
;
457 if (termios
->c_cflag
& PARENB
) {
458 lcr_fcr
|= PNX8XXX_UART_LCR_PAREN
;
459 if (!(termios
->c_cflag
& PARODD
))
460 lcr_fcr
|= PNX8XXX_UART_LCR_PAREVN
;
464 * Ask the core to calculate the divisor for us.
466 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
467 quot
= uart_get_divisor(port
, baud
);
469 spin_lock_irqsave(&sport
->port
.lock
, flags
);
471 sport
->port
.read_status_mask
= ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN
) |
472 ISTAT_TO_SM(PNX8XXX_UART_INT_EMPTY
) |
473 ISTAT_TO_SM(PNX8XXX_UART_INT_RX
);
474 if (termios
->c_iflag
& INPCK
)
475 sport
->port
.read_status_mask
|=
476 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE
) |
477 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR
);
478 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
479 sport
->port
.read_status_mask
|=
480 ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK
);
483 * Characters to ignore
485 sport
->port
.ignore_status_mask
= 0;
486 if (termios
->c_iflag
& IGNPAR
)
487 sport
->port
.ignore_status_mask
|=
488 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE
) |
489 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR
);
490 if (termios
->c_iflag
& IGNBRK
) {
491 sport
->port
.ignore_status_mask
|=
492 ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK
);
494 * If we're ignoring parity and break indicators,
495 * ignore overruns too (for real raw support).
497 if (termios
->c_iflag
& IGNPAR
)
498 sport
->port
.ignore_status_mask
|=
499 ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN
);
503 * ignore all characters if CREAD is not set
505 if ((termios
->c_cflag
& CREAD
) == 0)
506 sport
->port
.ignore_status_mask
|=
507 ISTAT_TO_SM(PNX8XXX_UART_INT_RX
);
509 del_timer_sync(&sport
->timer
);
512 * Update the per-port timeout.
514 uart_update_timeout(port
, termios
->c_cflag
, baud
);
517 * disable interrupts and drain transmitter
519 old_ien
= serial_in(sport
, PNX8XXX_IEN
);
520 serial_out(sport
, PNX8XXX_IEN
, old_ien
& ~(PNX8XXX_UART_INT_ALLTX
|
521 PNX8XXX_UART_INT_ALLRX
));
523 while (serial_in(sport
, PNX8XXX_FIFO
) & PNX8XXX_UART_FIFO_TXFIFO_STA
)
526 /* then, disable everything */
527 serial_out(sport
, PNX8XXX_IEN
, 0);
529 /* Reset the Rx and Tx FIFOs too */
530 lcr_fcr
|= PNX8XXX_UART_LCR_TX_RST
;
531 lcr_fcr
|= PNX8XXX_UART_LCR_RX_RST
;
533 /* set the parity, stop bits and data size */
534 serial_out(sport
, PNX8XXX_LCR
, lcr_fcr
);
536 /* set the baud rate */
538 serial_out(sport
, PNX8XXX_BAUD
, quot
);
540 serial_out(sport
, PNX8XXX_ICLR
, -1);
542 serial_out(sport
, PNX8XXX_IEN
, old_ien
);
544 if (UART_ENABLE_MS(&sport
->port
, termios
->c_cflag
))
545 pnx8xxx_enable_ms(&sport
->port
);
547 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
550 static const char *pnx8xxx_type(struct uart_port
*port
)
552 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
554 return sport
->port
.type
== PORT_PNX8XXX
? "PNX8XXX" : NULL
;
558 * Release the memory region(s) being used by 'port'.
560 static void pnx8xxx_release_port(struct uart_port
*port
)
562 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
564 release_mem_region(sport
->port
.mapbase
, UART_PORT_SIZE
);
568 * Request the memory region(s) being used by 'port'.
570 static int pnx8xxx_request_port(struct uart_port
*port
)
572 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
573 return request_mem_region(sport
->port
.mapbase
, UART_PORT_SIZE
,
574 "pnx8xxx-uart") != NULL
? 0 : -EBUSY
;
578 * Configure/autoconfigure the port.
580 static void pnx8xxx_config_port(struct uart_port
*port
, int flags
)
582 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
584 if (flags
& UART_CONFIG_TYPE
&&
585 pnx8xxx_request_port(&sport
->port
) == 0)
586 sport
->port
.type
= PORT_PNX8XXX
;
590 * Verify the new serial_struct (for TIOCSSERIAL).
591 * The only change we allow are to the flags and type, and
592 * even then only between PORT_PNX8XXX and PORT_UNKNOWN
595 pnx8xxx_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
597 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
600 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_PNX8XXX
)
602 if (sport
->port
.irq
!= ser
->irq
)
604 if (ser
->io_type
!= SERIAL_IO_MEM
)
606 if (sport
->port
.uartclk
/ 16 != ser
->baud_base
)
608 if ((void *)sport
->port
.mapbase
!= ser
->iomem_base
)
610 if (sport
->port
.iobase
!= ser
->port
)
617 static struct uart_ops pnx8xxx_pops
= {
618 .tx_empty
= pnx8xxx_tx_empty
,
619 .set_mctrl
= pnx8xxx_set_mctrl
,
620 .get_mctrl
= pnx8xxx_get_mctrl
,
621 .stop_tx
= pnx8xxx_stop_tx
,
622 .start_tx
= pnx8xxx_start_tx
,
623 .stop_rx
= pnx8xxx_stop_rx
,
624 .enable_ms
= pnx8xxx_enable_ms
,
625 .break_ctl
= pnx8xxx_break_ctl
,
626 .startup
= pnx8xxx_startup
,
627 .shutdown
= pnx8xxx_shutdown
,
628 .set_termios
= pnx8xxx_set_termios
,
629 .type
= pnx8xxx_type
,
630 .release_port
= pnx8xxx_release_port
,
631 .request_port
= pnx8xxx_request_port
,
632 .config_port
= pnx8xxx_config_port
,
633 .verify_port
= pnx8xxx_verify_port
,
638 * Setup the PNX8XXX serial ports.
640 * Note also that we support "console=ttySx" where "x" is either 0 or 1.
642 static void __init
pnx8xxx_init_ports(void)
644 static int first
= 1;
651 for (i
= 0; i
< NR_PORTS
; i
++) {
652 init_timer(&pnx8xxx_ports
[i
].timer
);
653 pnx8xxx_ports
[i
].timer
.function
= pnx8xxx_timeout
;
654 pnx8xxx_ports
[i
].timer
.data
= (unsigned long)&pnx8xxx_ports
[i
];
655 pnx8xxx_ports
[i
].port
.ops
= &pnx8xxx_pops
;
659 #ifdef CONFIG_SERIAL_PNX8XXX_CONSOLE
661 static void pnx8xxx_console_putchar(struct uart_port
*port
, int ch
)
663 struct pnx8xxx_port
*sport
= (struct pnx8xxx_port
*)port
;
667 /* Wait for UART_TX register to empty */
668 status
= serial_in(sport
, PNX8XXX_FIFO
);
669 } while (status
& PNX8XXX_UART_FIFO_TXFIFO
);
670 serial_out(sport
, PNX8XXX_FIFO
, ch
);
674 * Interrupts are disabled on entering
676 pnx8xxx_console_write(struct console
*co
, const char *s
, unsigned int count
)
678 struct pnx8xxx_port
*sport
= &pnx8xxx_ports
[co
->index
];
679 unsigned int old_ien
, status
;
682 * First, save IEN and then disable interrupts
684 old_ien
= serial_in(sport
, PNX8XXX_IEN
);
685 serial_out(sport
, PNX8XXX_IEN
, old_ien
& ~(PNX8XXX_UART_INT_ALLTX
|
686 PNX8XXX_UART_INT_ALLRX
));
688 uart_console_write(&sport
->port
, s
, count
, pnx8xxx_console_putchar
);
691 * Finally, wait for transmitter to become empty
695 /* Wait for UART_TX register to empty */
696 status
= serial_in(sport
, PNX8XXX_FIFO
);
697 } while (status
& PNX8XXX_UART_FIFO_TXFIFO
);
699 /* Clear TX and EMPTY interrupt */
700 serial_out(sport
, PNX8XXX_ICLR
, PNX8XXX_UART_INT_TX
|
701 PNX8XXX_UART_INT_EMPTY
);
703 serial_out(sport
, PNX8XXX_IEN
, old_ien
);
707 pnx8xxx_console_setup(struct console
*co
, char *options
)
709 struct pnx8xxx_port
*sport
;
716 * Check whether an invalid uart number has been specified, and
717 * if so, search for the first available port that does have
720 if (co
->index
== -1 || co
->index
>= NR_PORTS
)
722 sport
= &pnx8xxx_ports
[co
->index
];
725 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
727 return uart_set_options(&sport
->port
, co
, baud
, parity
, bits
, flow
);
730 static struct uart_driver pnx8xxx_reg
;
731 static struct console pnx8xxx_console
= {
733 .write
= pnx8xxx_console_write
,
734 .device
= uart_console_device
,
735 .setup
= pnx8xxx_console_setup
,
736 .flags
= CON_PRINTBUFFER
,
738 .data
= &pnx8xxx_reg
,
741 static int __init
pnx8xxx_rs_console_init(void)
743 pnx8xxx_init_ports();
744 register_console(&pnx8xxx_console
);
747 console_initcall(pnx8xxx_rs_console_init
);
749 #define PNX8XXX_CONSOLE &pnx8xxx_console
751 #define PNX8XXX_CONSOLE NULL
754 static struct uart_driver pnx8xxx_reg
= {
755 .owner
= THIS_MODULE
,
756 .driver_name
= "ttyS",
758 .major
= SERIAL_PNX8XXX_MAJOR
,
759 .minor
= MINOR_START
,
761 .cons
= PNX8XXX_CONSOLE
,
764 static int pnx8xxx_serial_suspend(struct platform_device
*pdev
, pm_message_t state
)
766 struct pnx8xxx_port
*sport
= platform_get_drvdata(pdev
);
768 return uart_suspend_port(&pnx8xxx_reg
, &sport
->port
);
771 static int pnx8xxx_serial_resume(struct platform_device
*pdev
)
773 struct pnx8xxx_port
*sport
= platform_get_drvdata(pdev
);
775 return uart_resume_port(&pnx8xxx_reg
, &sport
->port
);
778 static int pnx8xxx_serial_probe(struct platform_device
*pdev
)
780 struct resource
*res
= pdev
->resource
;
783 for (i
= 0; i
< pdev
->num_resources
; i
++, res
++) {
784 if (!(res
->flags
& IORESOURCE_MEM
))
787 for (i
= 0; i
< NR_PORTS
; i
++) {
788 if (pnx8xxx_ports
[i
].port
.mapbase
!= res
->start
)
791 pnx8xxx_ports
[i
].port
.dev
= &pdev
->dev
;
792 uart_add_one_port(&pnx8xxx_reg
, &pnx8xxx_ports
[i
].port
);
793 platform_set_drvdata(pdev
, &pnx8xxx_ports
[i
]);
801 static int pnx8xxx_serial_remove(struct platform_device
*pdev
)
803 struct pnx8xxx_port
*sport
= platform_get_drvdata(pdev
);
805 platform_set_drvdata(pdev
, NULL
);
808 uart_remove_one_port(&pnx8xxx_reg
, &sport
->port
);
813 static struct platform_driver pnx8xxx_serial_driver
= {
815 .name
= "pnx8xxx-uart",
816 .owner
= THIS_MODULE
,
818 .probe
= pnx8xxx_serial_probe
,
819 .remove
= pnx8xxx_serial_remove
,
820 .suspend
= pnx8xxx_serial_suspend
,
821 .resume
= pnx8xxx_serial_resume
,
824 static int __init
pnx8xxx_serial_init(void)
828 printk(KERN_INFO
"Serial: PNX8XXX driver\n");
830 pnx8xxx_init_ports();
832 ret
= uart_register_driver(&pnx8xxx_reg
);
834 ret
= platform_driver_register(&pnx8xxx_serial_driver
);
836 uart_unregister_driver(&pnx8xxx_reg
);
841 static void __exit
pnx8xxx_serial_exit(void)
843 platform_driver_unregister(&pnx8xxx_serial_driver
);
844 uart_unregister_driver(&pnx8xxx_reg
);
847 module_init(pnx8xxx_serial_init
);
848 module_exit(pnx8xxx_serial_exit
);
850 MODULE_AUTHOR("Embedded Alley Solutions, Inc.");
851 MODULE_DESCRIPTION("PNX8XXX SoCs serial port driver");
852 MODULE_LICENSE("GPL");
853 MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_PNX8XXX_MAJOR
);
854 MODULE_ALIAS("platform:pnx8xxx-uart");