2 * linux/drivers/serial/imx.c
4 * Driver for Motorola IMX serial ports
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
8 * Author: Sascha Hauer <sascha@saschahauer.de>
9 * Copyright (C) 2004 Pengutronix
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * [29-Mar-2005] Mike Lee
26 * Added hardware handshake
28 #include <linux/config.h>
30 #if defined(CONFIG_SERIAL_IMX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
34 #include <linux/module.h>
35 #include <linux/ioport.h>
36 #include <linux/init.h>
37 #include <linux/console.h>
38 #include <linux/sysrq.h>
39 #include <linux/platform_device.h>
40 #include <linux/tty.h>
41 #include <linux/tty_flip.h>
42 #include <linux/serial_core.h>
43 #include <linux/serial.h>
47 #include <asm/hardware.h>
49 /* We've been assigned a range on the "Low-density serial ports" major */
50 #define SERIAL_IMX_MAJOR 204
51 #define MINOR_START 41
55 #define IMX_ISR_PASS_LIMIT 256
58 * This is the size of our serial port register set.
60 #define UART_PORT_SIZE 0x100
63 * This determines how often we check the modem status signals
64 * for any change. They generally aren't connected to an IRQ
65 * so we have to poll them. We also check immediately before
66 * filling the TX fifo incase CTS has been dropped.
68 #define MCTRL_TIMEOUT (250*HZ/1000)
70 #define DRIVER_NAME "IMX-uart"
73 struct uart_port port;
74 struct timer_list timer;
75 unsigned int old_status;
76 int txirq,rxirq,rtsirq;
80 * Handle any change of modem status signal since we were last called.
82 static void imx_mctrl_check(struct imx_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.info->delta_msr_wait);
107 * This is our per-port timeout handler, for checking the
108 * modem status signals.
110 static void imx_timeout(unsigned long data)
112 struct imx_port *sport = (struct imx_port *)data;
115 if (sport->port.info) {
116 spin_lock_irqsave(&sport->port.lock, flags);
117 imx_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 imx_stop_tx(struct uart_port *port)
129 struct imx_port *sport = (struct imx_port *)port;
130 UCR1((u32)sport->port.membase) &= ~UCR1_TXMPTYEN;
134 * interrupts disabled on entry
136 static void imx_stop_rx(struct uart_port *port)
138 struct imx_port *sport = (struct imx_port *)port;
139 UCR2((u32)sport->port.membase) &= ~UCR2_RXEN;
143 * Set the modem control timer to fire immediately.
145 static void imx_enable_ms(struct uart_port *port)
147 struct imx_port *sport = (struct imx_port *)port;
149 mod_timer(&sport->timer, jiffies);
152 static inline void imx_transmit_buffer(struct imx_port *sport)
154 struct circ_buf *xmit = &sport->port.info->xmit;
157 /* send xmit->buf[xmit->tail]
158 * out the port here */
159 URTX0((u32)sport->port.membase) = xmit->buf[xmit->tail];
160 xmit->tail = (xmit->tail + 1) &
161 (UART_XMIT_SIZE - 1);
162 sport->port.icount.tx++;
163 if (uart_circ_empty(xmit))
165 } while (!(UTS((u32)sport->port.membase) & UTS_TXFULL));
167 if (uart_circ_empty(xmit))
168 imx_stop_tx(&sport->port);
172 * interrupts disabled on entry
174 static void imx_start_tx(struct uart_port *port)
176 struct imx_port *sport = (struct imx_port *)port;
178 UCR1((u32)sport->port.membase) |= UCR1_TXMPTYEN;
180 if(UTS((u32)sport->port.membase) & UTS_TXEMPTY)
181 imx_transmit_buffer(sport);
184 static irqreturn_t imx_rtsint(int irq, void *dev_id, struct pt_regs *regs)
186 struct imx_port *sport = (struct imx_port *)dev_id;
187 unsigned int val = USR1((u32)sport->port.membase)&USR1_RTSS;
190 spin_lock_irqsave(&sport->port.lock, flags);
192 USR1((u32)sport->port.membase) = USR1_RTSD;
193 uart_handle_cts_change(&sport->port, !!val);
194 wake_up_interruptible(&sport->port.info->delta_msr_wait);
196 spin_unlock_irqrestore(&sport->port.lock, flags);
200 static irqreturn_t imx_txint(int irq, void *dev_id, struct pt_regs *regs)
202 struct imx_port *sport = (struct imx_port *)dev_id;
203 struct circ_buf *xmit = &sport->port.info->xmit;
206 spin_lock_irqsave(&sport->port.lock,flags);
207 if (sport->port.x_char)
210 URTX0((u32)sport->port.membase) = sport->port.x_char;
214 if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) {
215 imx_stop_tx(&sport->port);
219 imx_transmit_buffer(sport);
221 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
222 uart_write_wakeup(&sport->port);
225 spin_unlock_irqrestore(&sport->port.lock,flags);
229 static irqreturn_t imx_rxint(int irq, void *dev_id, struct pt_regs *regs)
231 struct imx_port *sport = dev_id;
232 unsigned int rx,flg,ignored = 0;
233 struct tty_struct *tty = sport->port.info->tty;
236 rx = URXD0((u32)sport->port.membase);
237 spin_lock_irqsave(&sport->port.lock,flags);
241 sport->port.icount.rx++;
243 if( USR2((u32)sport->port.membase) & USR2_BRCD ) {
244 USR2((u32)sport->port.membase) |= USR2_BRCD;
245 if(uart_handle_break(&sport->port))
249 if (uart_handle_sysrq_char
250 (&sport->port, (unsigned char)rx, regs))
253 if( rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) )
257 tty_insert_flip_char(tty, rx, flg);
259 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
263 rx = URXD0((u32)sport->port.membase);
264 } while(rx & URXD_CHARRDY);
267 spin_unlock_irqrestore(&sport->port.lock,flags);
268 tty_flip_buffer_push(tty);
273 sport->port.icount.parity++;
274 else if (rx & URXD_FRMERR)
275 sport->port.icount.frame++;
276 if (rx & URXD_OVRRUN)
277 sport->port.icount.overrun++;
279 if (rx & sport->port.ignore_status_mask) {
285 rx &= sport->port.read_status_mask;
289 else if (rx & URXD_FRMERR)
291 if (rx & URXD_OVRRUN)
295 sport->port.sysrq = 0;
301 * Return TIOCSER_TEMT when transmitter is not busy.
303 static unsigned int imx_tx_empty(struct uart_port *port)
305 struct imx_port *sport = (struct imx_port *)port;
307 return USR2((u32)sport->port.membase) & USR2_TXDC ? TIOCSER_TEMT : 0;
311 * We have a modem side uart, so the meanings of RTS and CTS are inverted.
313 static unsigned int imx_get_mctrl(struct uart_port *port)
315 struct imx_port *sport = (struct imx_port *)port;
316 unsigned int tmp = TIOCM_DSR | TIOCM_CAR;
318 if (USR1((u32)sport->port.membase) & USR1_RTSS)
321 if (UCR2((u32)sport->port.membase) & UCR2_CTS)
327 static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl)
329 struct imx_port *sport = (struct imx_port *)port;
331 if (mctrl & TIOCM_RTS)
332 UCR2((u32)sport->port.membase) |= UCR2_CTS;
334 UCR2((u32)sport->port.membase) &= ~UCR2_CTS;
338 * Interrupts always disabled.
340 static void imx_break_ctl(struct uart_port *port, int break_state)
342 struct imx_port *sport = (struct imx_port *)port;
345 spin_lock_irqsave(&sport->port.lock, flags);
347 if ( break_state != 0 )
348 UCR1((u32)sport->port.membase) |= UCR1_SNDBRK;
350 UCR1((u32)sport->port.membase) &= ~UCR1_SNDBRK;
352 spin_unlock_irqrestore(&sport->port.lock, flags);
355 #define TXTL 2 /* reset default */
356 #define RXTL 1 /* reset default */
358 static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
361 unsigned int ufcr_rfdiv;
363 /* set receiver / transmitter trigger level.
364 * RFDIV is set such way to satisfy requested uartclk value
366 val = TXTL<<10 | RXTL;
367 ufcr_rfdiv = (imx_get_perclk1() + sport->port.uartclk / 2) / sport->port.uartclk;
375 ufcr_rfdiv = 6 - ufcr_rfdiv;
377 val |= UFCR_RFDIV & (ufcr_rfdiv << 7);
379 UFCR((u32)sport->port.membase) = val;
384 static int imx_startup(struct uart_port *port)
386 struct imx_port *sport = (struct imx_port *)port;
390 imx_setup_ufcr(sport, 0);
392 /* disable the DREN bit (Data Ready interrupt enable) before
395 UCR4((u32)sport->port.membase) &= ~UCR4_DREN;
400 retval = request_irq(sport->rxirq, imx_rxint, 0,
402 if (retval) goto error_out1;
404 retval = request_irq(sport->txirq, imx_txint, 0,
406 if (retval) goto error_out2;
408 retval = request_irq(sport->rtsirq, imx_rtsint, 0,
410 if (retval) goto error_out3;
411 set_irq_type(sport->rtsirq, IRQT_BOTHEDGE);
414 * Finally, clear and enable interrupts
417 USR1((u32)sport->port.membase) = USR1_RTSD;
418 UCR1((u32)sport->port.membase) |=
419 (UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN);
421 UCR2((u32)sport->port.membase) |= (UCR2_RXEN | UCR2_TXEN);
423 * Enable modem status interrupts
425 spin_lock_irqsave(&sport->port.lock,flags);
426 imx_enable_ms(&sport->port);
427 spin_unlock_irqrestore(&sport->port.lock,flags);
432 free_irq(sport->txirq, sport);
434 free_irq(sport->rxirq, sport);
439 static void imx_shutdown(struct uart_port *port)
441 struct imx_port *sport = (struct imx_port *)port;
446 del_timer_sync(&sport->timer);
449 * Free the interrupts
451 free_irq(sport->rtsirq, sport);
452 free_irq(sport->txirq, sport);
453 free_irq(sport->rxirq, sport);
456 * Disable all interrupts, port and break condition.
459 UCR1((u32)sport->port.membase) &=
460 ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN);
464 imx_set_termios(struct uart_port *port, struct termios *termios,
467 struct imx_port *sport = (struct imx_port *)port;
469 unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
470 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
473 * If we don't support modem control lines, don't allow
477 termios->c_cflag &= ~(HUPCL | CRTSCTS | CMSPAR);
478 termios->c_cflag |= CLOCAL;
482 * We only support CS7 and CS8.
484 while ((termios->c_cflag & CSIZE) != CS7 &&
485 (termios->c_cflag & CSIZE) != CS8) {
486 termios->c_cflag &= ~CSIZE;
487 termios->c_cflag |= old_csize;
491 if ((termios->c_cflag & CSIZE) == CS8)
492 ucr2 = UCR2_WS | UCR2_SRST | UCR2_IRTS;
494 ucr2 = UCR2_SRST | UCR2_IRTS;
496 if (termios->c_cflag & CRTSCTS) {
501 if (termios->c_cflag & CSTOPB)
503 if (termios->c_cflag & PARENB) {
505 if (!(termios->c_cflag & PARODD))
510 * Ask the core to calculate the divisor for us.
512 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
513 quot = uart_get_divisor(port, baud);
515 spin_lock_irqsave(&sport->port.lock, flags);
517 sport->port.read_status_mask = 0;
518 if (termios->c_iflag & INPCK)
519 sport->port.read_status_mask |= (URXD_FRMERR | URXD_PRERR);
520 if (termios->c_iflag & (BRKINT | PARMRK))
521 sport->port.read_status_mask |= URXD_BRK;
524 * Characters to ignore
526 sport->port.ignore_status_mask = 0;
527 if (termios->c_iflag & IGNPAR)
528 sport->port.ignore_status_mask |= URXD_PRERR;
529 if (termios->c_iflag & IGNBRK) {
530 sport->port.ignore_status_mask |= URXD_BRK;
532 * If we're ignoring parity and break indicators,
533 * ignore overruns too (for real raw support).
535 if (termios->c_iflag & IGNPAR)
536 sport->port.ignore_status_mask |= URXD_OVRRUN;
539 del_timer_sync(&sport->timer);
542 * Update the per-port timeout.
544 uart_update_timeout(port, termios->c_cflag, baud);
547 * disable interrupts and drain transmitter
549 old_ucr1 = UCR1((u32)sport->port.membase);
550 UCR1((u32)sport->port.membase) &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN);
552 while ( !(USR2((u32)sport->port.membase) & USR2_TXDC))
555 /* then, disable everything */
556 old_txrxen = UCR2((u32)sport->port.membase) & ( UCR2_TXEN | UCR2_RXEN );
557 UCR2((u32)sport->port.membase) &= ~( UCR2_TXEN | UCR2_RXEN);
559 /* set the parity, stop bits and data size */
560 UCR2((u32)sport->port.membase) = ucr2;
562 /* set the baud rate. We assume uartclk = 16 MHz
565 * --------- = --------
568 UBIR((u32)sport->port.membase) = (baud / 100) - 1;
569 UBMR((u32)sport->port.membase) = 10000 - 1;
571 UCR1((u32)sport->port.membase) = old_ucr1;
572 UCR2((u32)sport->port.membase) |= old_txrxen;
574 if (UART_ENABLE_MS(&sport->port, termios->c_cflag))
575 imx_enable_ms(&sport->port);
577 spin_unlock_irqrestore(&sport->port.lock, flags);
580 static const char *imx_type(struct uart_port *port)
582 struct imx_port *sport = (struct imx_port *)port;
584 return sport->port.type == PORT_IMX ? "IMX" : NULL;
588 * Release the memory region(s) being used by 'port'.
590 static void imx_release_port(struct uart_port *port)
592 struct imx_port *sport = (struct imx_port *)port;
594 release_mem_region(sport->port.mapbase, UART_PORT_SIZE);
598 * Request the memory region(s) being used by 'port'.
600 static int imx_request_port(struct uart_port *port)
602 struct imx_port *sport = (struct imx_port *)port;
604 return request_mem_region(sport->port.mapbase, UART_PORT_SIZE,
605 "imx-uart") != NULL ? 0 : -EBUSY;
609 * Configure/autoconfigure the port.
611 static void imx_config_port(struct uart_port *port, int flags)
613 struct imx_port *sport = (struct imx_port *)port;
615 if (flags & UART_CONFIG_TYPE &&
616 imx_request_port(&sport->port) == 0)
617 sport->port.type = PORT_IMX;
621 * Verify the new serial_struct (for TIOCSSERIAL).
622 * The only change we allow are to the flags and type, and
623 * even then only between PORT_IMX and PORT_UNKNOWN
626 imx_verify_port(struct uart_port *port, struct serial_struct *ser)
628 struct imx_port *sport = (struct imx_port *)port;
631 if (ser->type != PORT_UNKNOWN && ser->type != PORT_IMX)
633 if (sport->port.irq != ser->irq)
635 if (ser->io_type != UPIO_MEM)
637 if (sport->port.uartclk / 16 != ser->baud_base)
639 if ((void *)sport->port.mapbase != ser->iomem_base)
641 if (sport->port.iobase != ser->port)
648 static struct uart_ops imx_pops = {
649 .tx_empty = imx_tx_empty,
650 .set_mctrl = imx_set_mctrl,
651 .get_mctrl = imx_get_mctrl,
652 .stop_tx = imx_stop_tx,
653 .start_tx = imx_start_tx,
654 .stop_rx = imx_stop_rx,
655 .enable_ms = imx_enable_ms,
656 .break_ctl = imx_break_ctl,
657 .startup = imx_startup,
658 .shutdown = imx_shutdown,
659 .set_termios = imx_set_termios,
661 .release_port = imx_release_port,
662 .request_port = imx_request_port,
663 .config_port = imx_config_port,
664 .verify_port = imx_verify_port,
667 static struct imx_port imx_ports[] = {
669 .txirq = UART1_MINT_TX,
670 .rxirq = UART1_MINT_RX,
671 .rtsirq = UART1_MINT_RTS,
674 .iotype = SERIAL_IO_MEM,
675 .membase = (void *)IMX_UART1_BASE,
676 .mapbase = IMX_UART1_BASE, /* FIXME */
677 .irq = UART1_MINT_RX,
680 .flags = ASYNC_BOOT_AUTOCONF,
685 .txirq = UART2_MINT_TX,
686 .rxirq = UART2_MINT_RX,
687 .rtsirq = UART2_MINT_RTS,
690 .iotype = SERIAL_IO_MEM,
691 .membase = (void *)IMX_UART2_BASE,
692 .mapbase = IMX_UART2_BASE, /* FIXME */
693 .irq = UART2_MINT_RX,
696 .flags = ASYNC_BOOT_AUTOCONF,
704 * Setup the IMX serial ports.
705 * Note also that we support "console=ttySMXx" where "x" is either 0 or 1.
706 * Which serial port this ends up being depends on the machine you're
707 * running this kernel on. I'm not convinced that this is a good idea,
708 * but that's the way it traditionally works.
711 static void __init imx_init_ports(void)
713 static int first = 1;
720 for (i = 0; i < ARRAY_SIZE(imx_ports); i++) {
721 init_timer(&imx_ports[i].timer);
722 imx_ports[i].timer.function = imx_timeout;
723 imx_ports[i].timer.data = (unsigned long)&imx_ports[i];
726 imx_gpio_mode(PC9_PF_UART1_CTS);
727 imx_gpio_mode(PC10_PF_UART1_RTS);
728 imx_gpio_mode(PC11_PF_UART1_TXD);
729 imx_gpio_mode(PC12_PF_UART1_RXD);
730 imx_gpio_mode(PB28_PF_UART2_CTS);
731 imx_gpio_mode(PB29_PF_UART2_RTS);
733 imx_gpio_mode(PB30_PF_UART2_TXD);
734 imx_gpio_mode(PB31_PF_UART2_RXD);
736 #if 0 /* We don't need these, on the mx1 the _modem_ side of the uart
739 imx_gpio_mode(PD7_AF_UART2_DTR);
740 imx_gpio_mode(PD8_AF_UART2_DCD);
741 imx_gpio_mode(PD9_AF_UART2_RI);
742 imx_gpio_mode(PD10_AF_UART2_DSR);
748 #ifdef CONFIG_SERIAL_IMX_CONSOLE
751 * Interrupts are disabled on entering
754 imx_console_write(struct console *co, const char *s, unsigned int count)
756 struct imx_port *sport = &imx_ports[co->index];
757 unsigned int old_ucr1, old_ucr2, i;
760 * First, save UCR1/2 and then disable interrupts
762 old_ucr1 = UCR1((u32)sport->port.membase);
763 old_ucr2 = UCR2((u32)sport->port.membase);
765 UCR1((u32)sport->port.membase) =
766 (old_ucr1 | UCR1_UARTCLKEN | UCR1_UARTEN)
767 & ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN);
768 UCR2((u32)sport->port.membase) = old_ucr2 | UCR2_TXEN;
771 * Now, do each character
773 for (i = 0; i < count; i++) {
775 while ((UTS((u32)sport->port.membase) & UTS_TXFULL))
778 URTX0((u32)sport->port.membase) = s[i];
781 while ((UTS((u32)sport->port.membase) & UTS_TXFULL))
783 URTX0((u32)sport->port.membase) = '\r';
788 * Finally, wait for transmitter to become empty
791 while (!(USR2((u32)sport->port.membase) & USR2_TXDC));
793 UCR1((u32)sport->port.membase) = old_ucr1;
794 UCR2((u32)sport->port.membase) = old_ucr2;
798 * If the port was already initialised (eg, by a boot loader),
799 * try to determine the current setup.
802 imx_console_get_options(struct imx_port *sport, int *baud,
803 int *parity, int *bits)
806 if ( UCR1((u32)sport->port.membase) | UCR1_UARTEN ) {
807 /* ok, the port was enabled */
808 unsigned int ucr2, ubir,ubmr, uartclk;
809 unsigned int baud_raw;
810 unsigned int ucfr_rfdiv;
812 ucr2 = UCR2((u32)sport->port.membase);
815 if (ucr2 & UCR2_PREN) {
816 if (ucr2 & UCR2_PROE)
827 ubir = UBIR((u32)sport->port.membase) & 0xffff;
828 ubmr = UBMR((u32)sport->port.membase) & 0xffff;
831 ucfr_rfdiv = (UFCR((u32)sport->port.membase) & UFCR_RFDIV) >> 7;
835 ucfr_rfdiv = 6 - ucfr_rfdiv;
837 uartclk = imx_get_perclk1();
838 uartclk /= ucfr_rfdiv;
841 * The next code provides exact computation of
842 * baud_raw = round(((uartclk/16) * (ubir + 1)) / (ubmr + 1))
843 * without need of float support or long long division,
844 * which would be required to prevent 32bit arithmetic overflow
846 unsigned int mul = ubir + 1;
847 unsigned int div = 16 * (ubmr + 1);
848 unsigned int rem = uartclk % div;
850 baud_raw = (uartclk / div) * mul;
851 baud_raw += (rem * mul + div / 2) / div;
852 *baud = (baud_raw + 50) / 100 * 100;
855 if(*baud != baud_raw)
856 printk(KERN_INFO "Serial: Console IMX rounded baud rate from %d to %d\n",
862 imx_console_setup(struct console *co, char *options)
864 struct imx_port *sport;
871 * Check whether an invalid uart number has been specified, and
872 * if so, search for the first available port that does have
875 if (co->index == -1 || co->index >= ARRAY_SIZE(imx_ports))
877 sport = &imx_ports[co->index];
880 uart_parse_options(options, &baud, &parity, &bits, &flow);
882 imx_console_get_options(sport, &baud, &parity, &bits);
884 imx_setup_ufcr(sport, 0);
886 return uart_set_options(&sport->port, co, baud, parity, bits, flow);
889 static struct uart_driver imx_reg;
890 static struct console imx_console = {
892 .write = imx_console_write,
893 .device = uart_console_device,
894 .setup = imx_console_setup,
895 .flags = CON_PRINTBUFFER,
900 static int __init imx_rs_console_init(void)
903 register_console(&imx_console);
906 console_initcall(imx_rs_console_init);
908 #define IMX_CONSOLE &imx_console
910 #define IMX_CONSOLE NULL
913 static struct uart_driver imx_reg = {
914 .owner = THIS_MODULE,
915 .driver_name = DRIVER_NAME,
916 .dev_name = "ttySMX",
917 .devfs_name = "ttsmx/",
918 .major = SERIAL_IMX_MAJOR,
919 .minor = MINOR_START,
920 .nr = ARRAY_SIZE(imx_ports),
924 static int serial_imx_suspend(struct device *_dev, pm_message_t state)
926 struct imx_port *sport = dev_get_drvdata(_dev);
929 uart_suspend_port(&imx_reg, &sport->port);
934 static int serial_imx_resume(struct device *_dev)
936 struct imx_port *sport = dev_get_drvdata(_dev);
939 uart_resume_port(&imx_reg, &sport->port);
944 static int serial_imx_probe(struct device *_dev)
946 struct platform_device *dev = to_platform_device(_dev);
948 imx_ports[dev->id].port.dev = _dev;
949 uart_add_one_port(&imx_reg, &imx_ports[dev->id].port);
950 dev_set_drvdata(_dev, &imx_ports[dev->id]);
954 static int serial_imx_remove(struct device *_dev)
956 struct imx_port *sport = dev_get_drvdata(_dev);
958 dev_set_drvdata(_dev, NULL);
961 uart_remove_one_port(&imx_reg, &sport->port);
966 static struct device_driver serial_imx_driver = {
968 .bus = &platform_bus_type,
969 .probe = serial_imx_probe,
970 .remove = serial_imx_remove,
972 .suspend = serial_imx_suspend,
973 .resume = serial_imx_resume,
976 static int __init imx_serial_init(void)
980 printk(KERN_INFO "Serial: IMX driver\n");
984 ret = uart_register_driver(&imx_reg);
988 ret = driver_register(&serial_imx_driver);
990 uart_unregister_driver(&imx_reg);
995 static void __exit imx_serial_exit(void)
997 uart_unregister_driver(&imx_reg);
998 driver_unregister(&serial_imx_driver);
1001 module_init(imx_serial_init);
1002 module_exit(imx_serial_exit);
1004 MODULE_AUTHOR("Sascha Hauer");
1005 MODULE_DESCRIPTION("IMX generic serial port driver");
1006 MODULE_LICENSE("GPL");