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 =
130 container_of(port, struct pnx8xxx_port, port);
133 /* Disable TX intr */
134 ien = serial_in(sport, PNX8XXX_IEN);
135 serial_out(sport, PNX8XXX_IEN, ien & ~PNX8XXX_UART_INT_ALLTX);
137 /* Clear all pending TX intr */
138 serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLTX);
142 * interrupts may not be disabled on entry
144 static void pnx8xxx_start_tx(struct uart_port *port)
146 struct pnx8xxx_port *sport =
147 container_of(port, struct pnx8xxx_port, port);
150 /* Clear all pending TX intr */
151 serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLTX);
154 ien = serial_in(sport, PNX8XXX_IEN);
155 serial_out(sport, PNX8XXX_IEN, ien | PNX8XXX_UART_INT_ALLTX);
161 static void pnx8xxx_stop_rx(struct uart_port *port)
163 struct pnx8xxx_port *sport =
164 container_of(port, struct pnx8xxx_port, port);
167 /* Disable RX intr */
168 ien = serial_in(sport, PNX8XXX_IEN);
169 serial_out(sport, PNX8XXX_IEN, ien & ~PNX8XXX_UART_INT_ALLRX);
171 /* Clear all pending RX intr */
172 serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLRX);
176 * Set the modem control timer to fire immediately.
178 static void pnx8xxx_enable_ms(struct uart_port *port)
180 struct pnx8xxx_port *sport =
181 container_of(port, struct pnx8xxx_port, port);
183 mod_timer(&sport->timer, jiffies);
186 static void pnx8xxx_rx_chars(struct pnx8xxx_port *sport)
188 unsigned int status, ch, flg;
190 status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) |
191 ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT));
192 while (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFIFO)) {
193 ch = serial_in(sport, PNX8XXX_FIFO) & 0xff;
195 sport->port.icount.rx++;
200 * note that the error handling code is
201 * out of the main execution path
203 if (status & (FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE |
204 PNX8XXX_UART_FIFO_RXPAR |
205 PNX8XXX_UART_FIFO_RXBRK) |
206 ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN))) {
207 if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXBRK)) {
208 status &= ~(FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) |
209 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR));
210 sport->port.icount.brk++;
211 if (uart_handle_break(&sport->port))
213 } else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR))
214 sport->port.icount.parity++;
215 else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE))
216 sport->port.icount.frame++;
217 if (status & ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN))
218 sport->port.icount.overrun++;
220 status &= sport->port.read_status_mask;
222 if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR))
224 else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE))
228 sport->port.sysrq = 0;
232 if (uart_handle_sysrq_char(&sport->port, ch))
235 uart_insert_char(&sport->port, status,
236 ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN), ch, flg);
239 serial_out(sport, PNX8XXX_LCR, serial_in(sport, PNX8XXX_LCR) |
240 PNX8XXX_UART_LCR_RX_NEXT);
241 status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) |
242 ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT));
245 spin_unlock(&sport->port.lock);
246 tty_flip_buffer_push(&sport->port.state->port);
247 spin_lock(&sport->port.lock);
250 static void pnx8xxx_tx_chars(struct pnx8xxx_port *sport)
252 struct circ_buf *xmit = &sport->port.state->xmit;
254 if (sport->port.x_char) {
255 serial_out(sport, PNX8XXX_FIFO, sport->port.x_char);
256 sport->port.icount.tx++;
257 sport->port.x_char = 0;
262 * Check the modem control lines before
263 * transmitting anything.
265 pnx8xxx_mctrl_check(sport);
267 if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) {
268 pnx8xxx_stop_tx(&sport->port);
273 * TX while bytes available
275 while (((serial_in(sport, PNX8XXX_FIFO) &
276 PNX8XXX_UART_FIFO_TXFIFO) >> 16) < 16) {
277 serial_out(sport, PNX8XXX_FIFO, xmit->buf[xmit->tail]);
278 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
279 sport->port.icount.tx++;
280 if (uart_circ_empty(xmit))
284 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
285 uart_write_wakeup(&sport->port);
287 if (uart_circ_empty(xmit))
288 pnx8xxx_stop_tx(&sport->port);
291 static irqreturn_t pnx8xxx_int(int irq, void *dev_id)
293 struct pnx8xxx_port *sport = dev_id;
296 spin_lock(&sport->port.lock);
297 /* Get the interrupts */
298 status = serial_in(sport, PNX8XXX_ISTAT) & serial_in(sport, PNX8XXX_IEN);
300 /* Byte or break signal received */
301 if (status & (PNX8XXX_UART_INT_RX | PNX8XXX_UART_INT_BREAK))
302 pnx8xxx_rx_chars(sport);
304 /* TX holding register empty - transmit a byte */
305 if (status & PNX8XXX_UART_INT_TX)
306 pnx8xxx_tx_chars(sport);
308 /* Clear the ISTAT register */
309 serial_out(sport, PNX8XXX_ICLR, status);
311 spin_unlock(&sport->port.lock);
316 * Return TIOCSER_TEMT when transmitter is not busy.
318 static unsigned int pnx8xxx_tx_empty(struct uart_port *port)
320 struct pnx8xxx_port *sport =
321 container_of(port, struct pnx8xxx_port, port);
323 return serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA ? 0 : TIOCSER_TEMT;
326 static unsigned int pnx8xxx_get_mctrl(struct uart_port *port)
328 struct pnx8xxx_port *sport =
329 container_of(port, struct pnx8xxx_port, port);
330 unsigned int mctrl = TIOCM_DSR;
335 msr = serial_in(sport, PNX8XXX_MCR);
337 mctrl |= msr & PNX8XXX_UART_MCR_CTS ? TIOCM_CTS : 0;
338 mctrl |= msr & PNX8XXX_UART_MCR_DCD ? TIOCM_CAR : 0;
343 static void pnx8xxx_set_mctrl(struct uart_port *port, unsigned int mctrl)
346 struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
352 * Interrupts always disabled.
354 static void pnx8xxx_break_ctl(struct uart_port *port, int break_state)
356 struct pnx8xxx_port *sport =
357 container_of(port, struct pnx8xxx_port, port);
361 spin_lock_irqsave(&sport->port.lock, flags);
362 lcr = serial_in(sport, PNX8XXX_LCR);
363 if (break_state == -1)
364 lcr |= PNX8XXX_UART_LCR_TXBREAK;
366 lcr &= ~PNX8XXX_UART_LCR_TXBREAK;
367 serial_out(sport, PNX8XXX_LCR, lcr);
368 spin_unlock_irqrestore(&sport->port.lock, flags);
371 static int pnx8xxx_startup(struct uart_port *port)
373 struct pnx8xxx_port *sport =
374 container_of(port, struct pnx8xxx_port, port);
380 retval = request_irq(sport->port.irq, pnx8xxx_int, 0,
381 "pnx8xxx-uart", sport);
386 * Finally, clear and enable interrupts
389 serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLRX |
390 PNX8XXX_UART_INT_ALLTX);
392 serial_out(sport, PNX8XXX_IEN, serial_in(sport, PNX8XXX_IEN) |
393 PNX8XXX_UART_INT_ALLRX |
394 PNX8XXX_UART_INT_ALLTX);
397 * Enable modem status interrupts
399 spin_lock_irq(&sport->port.lock);
400 pnx8xxx_enable_ms(&sport->port);
401 spin_unlock_irq(&sport->port.lock);
406 static void pnx8xxx_shutdown(struct uart_port *port)
408 struct pnx8xxx_port *sport =
409 container_of(port, struct pnx8xxx_port, port);
415 del_timer_sync(&sport->timer);
418 * Disable all interrupts
420 serial_out(sport, PNX8XXX_IEN, 0);
423 * Reset the Tx and Rx FIFOS, disable the break condition
425 lcr = serial_in(sport, PNX8XXX_LCR);
426 lcr &= ~PNX8XXX_UART_LCR_TXBREAK;
427 lcr |= PNX8XXX_UART_LCR_TX_RST | PNX8XXX_UART_LCR_RX_RST;
428 serial_out(sport, PNX8XXX_LCR, lcr);
431 * Clear all interrupts
433 serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLRX |
434 PNX8XXX_UART_INT_ALLTX);
439 free_irq(sport->port.irq, sport);
443 pnx8xxx_set_termios(struct uart_port *port, struct ktermios *termios,
444 struct ktermios *old)
446 struct pnx8xxx_port *sport =
447 container_of(port, struct pnx8xxx_port, port);
449 unsigned int lcr_fcr, old_ien, baud, quot;
450 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
453 * We only support CS7 and CS8.
455 while ((termios->c_cflag & CSIZE) != CS7 &&
456 (termios->c_cflag & CSIZE) != CS8) {
457 termios->c_cflag &= ~CSIZE;
458 termios->c_cflag |= old_csize;
462 if ((termios->c_cflag & CSIZE) == CS8)
463 lcr_fcr = PNX8XXX_UART_LCR_8BIT;
467 if (termios->c_cflag & CSTOPB)
468 lcr_fcr |= PNX8XXX_UART_LCR_2STOPB;
469 if (termios->c_cflag & PARENB) {
470 lcr_fcr |= PNX8XXX_UART_LCR_PAREN;
471 if (!(termios->c_cflag & PARODD))
472 lcr_fcr |= PNX8XXX_UART_LCR_PAREVN;
476 * Ask the core to calculate the divisor for us.
478 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
479 quot = uart_get_divisor(port, baud);
481 spin_lock_irqsave(&sport->port.lock, flags);
483 sport->port.read_status_mask = ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN) |
484 ISTAT_TO_SM(PNX8XXX_UART_INT_EMPTY) |
485 ISTAT_TO_SM(PNX8XXX_UART_INT_RX);
486 if (termios->c_iflag & INPCK)
487 sport->port.read_status_mask |=
488 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) |
489 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR);
490 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
491 sport->port.read_status_mask |=
492 ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK);
495 * Characters to ignore
497 sport->port.ignore_status_mask = 0;
498 if (termios->c_iflag & IGNPAR)
499 sport->port.ignore_status_mask |=
500 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) |
501 FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR);
502 if (termios->c_iflag & IGNBRK) {
503 sport->port.ignore_status_mask |=
504 ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK);
506 * If we're ignoring parity and break indicators,
507 * ignore overruns too (for real raw support).
509 if (termios->c_iflag & IGNPAR)
510 sport->port.ignore_status_mask |=
511 ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN);
515 * ignore all characters if CREAD is not set
517 if ((termios->c_cflag & CREAD) == 0)
518 sport->port.ignore_status_mask |=
519 ISTAT_TO_SM(PNX8XXX_UART_INT_RX);
521 del_timer_sync(&sport->timer);
524 * Update the per-port timeout.
526 uart_update_timeout(port, termios->c_cflag, baud);
529 * disable interrupts and drain transmitter
531 old_ien = serial_in(sport, PNX8XXX_IEN);
532 serial_out(sport, PNX8XXX_IEN, old_ien & ~(PNX8XXX_UART_INT_ALLTX |
533 PNX8XXX_UART_INT_ALLRX));
535 while (serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA)
538 /* then, disable everything */
539 serial_out(sport, PNX8XXX_IEN, 0);
541 /* Reset the Rx and Tx FIFOs too */
542 lcr_fcr |= PNX8XXX_UART_LCR_TX_RST;
543 lcr_fcr |= PNX8XXX_UART_LCR_RX_RST;
545 /* set the parity, stop bits and data size */
546 serial_out(sport, PNX8XXX_LCR, lcr_fcr);
548 /* set the baud rate */
550 serial_out(sport, PNX8XXX_BAUD, quot);
552 serial_out(sport, PNX8XXX_ICLR, -1);
554 serial_out(sport, PNX8XXX_IEN, old_ien);
556 if (UART_ENABLE_MS(&sport->port, termios->c_cflag))
557 pnx8xxx_enable_ms(&sport->port);
559 spin_unlock_irqrestore(&sport->port.lock, flags);
562 static const char *pnx8xxx_type(struct uart_port *port)
564 struct pnx8xxx_port *sport =
565 container_of(port, struct pnx8xxx_port, port);
567 return sport->port.type == PORT_PNX8XXX ? "PNX8XXX" : NULL;
571 * Release the memory region(s) being used by 'port'.
573 static void pnx8xxx_release_port(struct uart_port *port)
575 struct pnx8xxx_port *sport =
576 container_of(port, struct pnx8xxx_port, port);
578 release_mem_region(sport->port.mapbase, UART_PORT_SIZE);
582 * Request the memory region(s) being used by 'port'.
584 static int pnx8xxx_request_port(struct uart_port *port)
586 struct pnx8xxx_port *sport =
587 container_of(port, struct pnx8xxx_port, port);
588 return request_mem_region(sport->port.mapbase, UART_PORT_SIZE,
589 "pnx8xxx-uart") != NULL ? 0 : -EBUSY;
593 * Configure/autoconfigure the port.
595 static void pnx8xxx_config_port(struct uart_port *port, int flags)
597 struct pnx8xxx_port *sport =
598 container_of(port, struct pnx8xxx_port, port);
600 if (flags & UART_CONFIG_TYPE &&
601 pnx8xxx_request_port(&sport->port) == 0)
602 sport->port.type = PORT_PNX8XXX;
606 * Verify the new serial_struct (for TIOCSSERIAL).
607 * The only change we allow are to the flags and type, and
608 * even then only between PORT_PNX8XXX and PORT_UNKNOWN
611 pnx8xxx_verify_port(struct uart_port *port, struct serial_struct *ser)
613 struct pnx8xxx_port *sport =
614 container_of(port, struct pnx8xxx_port, port);
617 if (ser->type != PORT_UNKNOWN && ser->type != PORT_PNX8XXX)
619 if (sport->port.irq != ser->irq)
621 if (ser->io_type != SERIAL_IO_MEM)
623 if (sport->port.uartclk / 16 != ser->baud_base)
625 if ((void *)sport->port.mapbase != ser->iomem_base)
627 if (sport->port.iobase != ser->port)
634 static struct uart_ops pnx8xxx_pops = {
635 .tx_empty = pnx8xxx_tx_empty,
636 .set_mctrl = pnx8xxx_set_mctrl,
637 .get_mctrl = pnx8xxx_get_mctrl,
638 .stop_tx = pnx8xxx_stop_tx,
639 .start_tx = pnx8xxx_start_tx,
640 .stop_rx = pnx8xxx_stop_rx,
641 .enable_ms = pnx8xxx_enable_ms,
642 .break_ctl = pnx8xxx_break_ctl,
643 .startup = pnx8xxx_startup,
644 .shutdown = pnx8xxx_shutdown,
645 .set_termios = pnx8xxx_set_termios,
646 .type = pnx8xxx_type,
647 .release_port = pnx8xxx_release_port,
648 .request_port = pnx8xxx_request_port,
649 .config_port = pnx8xxx_config_port,
650 .verify_port = pnx8xxx_verify_port,
655 * Setup the PNX8XXX serial ports.
657 * Note also that we support "console=ttySx" where "x" is either 0 or 1.
659 static void __init pnx8xxx_init_ports(void)
661 static int first = 1;
668 for (i = 0; i < NR_PORTS; i++) {
669 init_timer(&pnx8xxx_ports[i].timer);
670 pnx8xxx_ports[i].timer.function = pnx8xxx_timeout;
671 pnx8xxx_ports[i].timer.data = (unsigned long)&pnx8xxx_ports[i];
672 pnx8xxx_ports[i].port.ops = &pnx8xxx_pops;
676 #ifdef CONFIG_SERIAL_PNX8XXX_CONSOLE
678 static void pnx8xxx_console_putchar(struct uart_port *port, int ch)
680 struct pnx8xxx_port *sport =
681 container_of(port, struct pnx8xxx_port, port);
685 /* Wait for UART_TX register to empty */
686 status = serial_in(sport, PNX8XXX_FIFO);
687 } while (status & PNX8XXX_UART_FIFO_TXFIFO);
688 serial_out(sport, PNX8XXX_FIFO, ch);
692 * Interrupts are disabled on entering
694 pnx8xxx_console_write(struct console *co, const char *s, unsigned int count)
696 struct pnx8xxx_port *sport = &pnx8xxx_ports[co->index];
697 unsigned int old_ien, status;
700 * First, save IEN and then disable interrupts
702 old_ien = serial_in(sport, PNX8XXX_IEN);
703 serial_out(sport, PNX8XXX_IEN, old_ien & ~(PNX8XXX_UART_INT_ALLTX |
704 PNX8XXX_UART_INT_ALLRX));
706 uart_console_write(&sport->port, s, count, pnx8xxx_console_putchar);
709 * Finally, wait for transmitter to become empty
713 /* Wait for UART_TX register to empty */
714 status = serial_in(sport, PNX8XXX_FIFO);
715 } while (status & PNX8XXX_UART_FIFO_TXFIFO);
717 /* Clear TX and EMPTY interrupt */
718 serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_TX |
719 PNX8XXX_UART_INT_EMPTY);
721 serial_out(sport, PNX8XXX_IEN, old_ien);
725 pnx8xxx_console_setup(struct console *co, char *options)
727 struct pnx8xxx_port *sport;
734 * Check whether an invalid uart number has been specified, and
735 * if so, search for the first available port that does have
738 if (co->index == -1 || co->index >= NR_PORTS)
740 sport = &pnx8xxx_ports[co->index];
743 uart_parse_options(options, &baud, &parity, &bits, &flow);
745 return uart_set_options(&sport->port, co, baud, parity, bits, flow);
748 static struct uart_driver pnx8xxx_reg;
749 static struct console pnx8xxx_console = {
751 .write = pnx8xxx_console_write,
752 .device = uart_console_device,
753 .setup = pnx8xxx_console_setup,
754 .flags = CON_PRINTBUFFER,
756 .data = &pnx8xxx_reg,
759 static int __init pnx8xxx_rs_console_init(void)
761 pnx8xxx_init_ports();
762 register_console(&pnx8xxx_console);
765 console_initcall(pnx8xxx_rs_console_init);
767 #define PNX8XXX_CONSOLE &pnx8xxx_console
769 #define PNX8XXX_CONSOLE NULL
772 static struct uart_driver pnx8xxx_reg = {
773 .owner = THIS_MODULE,
774 .driver_name = "ttyS",
776 .major = SERIAL_PNX8XXX_MAJOR,
777 .minor = MINOR_START,
779 .cons = PNX8XXX_CONSOLE,
782 static int pnx8xxx_serial_suspend(struct platform_device *pdev, pm_message_t state)
784 struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
786 return uart_suspend_port(&pnx8xxx_reg, &sport->port);
789 static int pnx8xxx_serial_resume(struct platform_device *pdev)
791 struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
793 return uart_resume_port(&pnx8xxx_reg, &sport->port);
796 static int pnx8xxx_serial_probe(struct platform_device *pdev)
798 struct resource *res = pdev->resource;
801 for (i = 0; i < pdev->num_resources; i++, res++) {
802 if (!(res->flags & IORESOURCE_MEM))
805 for (i = 0; i < NR_PORTS; i++) {
806 if (pnx8xxx_ports[i].port.mapbase != res->start)
809 pnx8xxx_ports[i].port.dev = &pdev->dev;
810 uart_add_one_port(&pnx8xxx_reg, &pnx8xxx_ports[i].port);
811 platform_set_drvdata(pdev, &pnx8xxx_ports[i]);
819 static int pnx8xxx_serial_remove(struct platform_device *pdev)
821 struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
824 uart_remove_one_port(&pnx8xxx_reg, &sport->port);
829 static struct platform_driver pnx8xxx_serial_driver = {
831 .name = "pnx8xxx-uart",
833 .probe = pnx8xxx_serial_probe,
834 .remove = pnx8xxx_serial_remove,
835 .suspend = pnx8xxx_serial_suspend,
836 .resume = pnx8xxx_serial_resume,
839 static int __init pnx8xxx_serial_init(void)
843 printk(KERN_INFO "Serial: PNX8XXX driver\n");
845 pnx8xxx_init_ports();
847 ret = uart_register_driver(&pnx8xxx_reg);
849 ret = platform_driver_register(&pnx8xxx_serial_driver);
851 uart_unregister_driver(&pnx8xxx_reg);
856 static void __exit pnx8xxx_serial_exit(void)
858 platform_driver_unregister(&pnx8xxx_serial_driver);
859 uart_unregister_driver(&pnx8xxx_reg);
862 module_init(pnx8xxx_serial_init);
863 module_exit(pnx8xxx_serial_exit);
865 MODULE_AUTHOR("Embedded Alley Solutions, Inc.");
866 MODULE_DESCRIPTION("PNX8XXX SoCs serial port driver");
867 MODULE_LICENSE("GPL");
868 MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_PNX8XXX_MAJOR);
869 MODULE_ALIAS("platform:pnx8xxx-uart");