Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/serial/imx.c |
| 3 | * |
| 4 | * Driver for Motorola IMX serial ports |
| 5 | * |
| 6 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. |
| 7 | * |
| 8 | * Author: Sascha Hauer <sascha@saschahauer.de> |
| 9 | * Copyright (C) 2004 Pengutronix |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | * |
| 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 |
| 24 | * |
| 25 | * [29-Mar-2005] Mike Lee |
| 26 | * Added hardware handshake |
| 27 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #if defined(CONFIG_SERIAL_IMX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 30 | #define SUPPORT_SYSRQ |
| 31 | #endif |
| 32 | |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/ioport.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/console.h> |
| 37 | #include <linux/sysrq.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 38 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/tty.h> |
| 40 | #include <linux/tty_flip.h> |
| 41 | #include <linux/serial_core.h> |
| 42 | #include <linux/serial.h> |
| 43 | |
| 44 | #include <asm/io.h> |
| 45 | #include <asm/irq.h> |
| 46 | #include <asm/hardware.h> |
Sascha Hauer | 5b80234 | 2006-05-04 14:07:42 +0100 | [diff] [blame] | 47 | #include <asm/arch/imx-uart.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 49 | /* Register definitions */ |
| 50 | #define URXD0 0x0 /* Receiver Register */ |
| 51 | #define URTX0 0x40 /* Transmitter Register */ |
| 52 | #define UCR1 0x80 /* Control Register 1 */ |
| 53 | #define UCR2 0x84 /* Control Register 2 */ |
| 54 | #define UCR3 0x88 /* Control Register 3 */ |
| 55 | #define UCR4 0x8c /* Control Register 4 */ |
| 56 | #define UFCR 0x90 /* FIFO Control Register */ |
| 57 | #define USR1 0x94 /* Status Register 1 */ |
| 58 | #define USR2 0x98 /* Status Register 2 */ |
| 59 | #define UESC 0x9c /* Escape Character Register */ |
| 60 | #define UTIM 0xa0 /* Escape Timer Register */ |
| 61 | #define UBIR 0xa4 /* BRM Incremental Register */ |
| 62 | #define UBMR 0xa8 /* BRM Modulator Register */ |
| 63 | #define UBRC 0xac /* Baud Rate Count Register */ |
| 64 | #define BIPR1 0xb0 /* Incremental Preset Register 1 */ |
| 65 | #define BIPR2 0xb4 /* Incremental Preset Register 2 */ |
| 66 | #define BIPR3 0xb8 /* Incremental Preset Register 3 */ |
| 67 | #define BIPR4 0xbc /* Incremental Preset Register 4 */ |
| 68 | #define BMPR1 0xc0 /* BRM Modulator Register 1 */ |
| 69 | #define BMPR2 0xc4 /* BRM Modulator Register 2 */ |
| 70 | #define BMPR3 0xc8 /* BRM Modulator Register 3 */ |
| 71 | #define BMPR4 0xcc /* BRM Modulator Register 4 */ |
| 72 | #define UTS 0xd0 /* UART Test Register */ |
| 73 | |
| 74 | /* UART Control Register Bit Fields.*/ |
| 75 | #define URXD_CHARRDY (1<<15) |
| 76 | #define URXD_ERR (1<<14) |
| 77 | #define URXD_OVRRUN (1<<13) |
| 78 | #define URXD_FRMERR (1<<12) |
| 79 | #define URXD_BRK (1<<11) |
| 80 | #define URXD_PRERR (1<<10) |
| 81 | #define UCR1_ADEN (1<<15) /* Auto dectect interrupt */ |
| 82 | #define UCR1_ADBR (1<<14) /* Auto detect baud rate */ |
| 83 | #define UCR1_TRDYEN (1<<13) /* Transmitter ready interrupt enable */ |
| 84 | #define UCR1_IDEN (1<<12) /* Idle condition interrupt */ |
| 85 | #define UCR1_RRDYEN (1<<9) /* Recv ready interrupt enable */ |
| 86 | #define UCR1_RDMAEN (1<<8) /* Recv ready DMA enable */ |
| 87 | #define UCR1_IREN (1<<7) /* Infrared interface enable */ |
| 88 | #define UCR1_TXMPTYEN (1<<6) /* Transimitter empty interrupt enable */ |
| 89 | #define UCR1_RTSDEN (1<<5) /* RTS delta interrupt enable */ |
| 90 | #define UCR1_SNDBRK (1<<4) /* Send break */ |
| 91 | #define UCR1_TDMAEN (1<<3) /* Transmitter ready DMA enable */ |
| 92 | #define UCR1_UARTCLKEN (1<<2) /* UART clock enabled */ |
| 93 | #define UCR1_DOZE (1<<1) /* Doze */ |
| 94 | #define UCR1_UARTEN (1<<0) /* UART enabled */ |
| 95 | #define UCR2_ESCI (1<<15) /* Escape seq interrupt enable */ |
| 96 | #define UCR2_IRTS (1<<14) /* Ignore RTS pin */ |
| 97 | #define UCR2_CTSC (1<<13) /* CTS pin control */ |
| 98 | #define UCR2_CTS (1<<12) /* Clear to send */ |
| 99 | #define UCR2_ESCEN (1<<11) /* Escape enable */ |
| 100 | #define UCR2_PREN (1<<8) /* Parity enable */ |
| 101 | #define UCR2_PROE (1<<7) /* Parity odd/even */ |
| 102 | #define UCR2_STPB (1<<6) /* Stop */ |
| 103 | #define UCR2_WS (1<<5) /* Word size */ |
| 104 | #define UCR2_RTSEN (1<<4) /* Request to send interrupt enable */ |
| 105 | #define UCR2_TXEN (1<<2) /* Transmitter enabled */ |
| 106 | #define UCR2_RXEN (1<<1) /* Receiver enabled */ |
| 107 | #define UCR2_SRST (1<<0) /* SW reset */ |
| 108 | #define UCR3_DTREN (1<<13) /* DTR interrupt enable */ |
| 109 | #define UCR3_PARERREN (1<<12) /* Parity enable */ |
| 110 | #define UCR3_FRAERREN (1<<11) /* Frame error interrupt enable */ |
| 111 | #define UCR3_DSR (1<<10) /* Data set ready */ |
| 112 | #define UCR3_DCD (1<<9) /* Data carrier detect */ |
| 113 | #define UCR3_RI (1<<8) /* Ring indicator */ |
| 114 | #define UCR3_TIMEOUTEN (1<<7) /* Timeout interrupt enable */ |
| 115 | #define UCR3_RXDSEN (1<<6) /* Receive status interrupt enable */ |
| 116 | #define UCR3_AIRINTEN (1<<5) /* Async IR wake interrupt enable */ |
| 117 | #define UCR3_AWAKEN (1<<4) /* Async wake interrupt enable */ |
| 118 | #define UCR3_REF25 (1<<3) /* Ref freq 25 MHz */ |
| 119 | #define UCR3_REF30 (1<<2) /* Ref Freq 30 MHz */ |
| 120 | #define UCR3_INVT (1<<1) /* Inverted Infrared transmission */ |
| 121 | #define UCR3_BPEN (1<<0) /* Preset registers enable */ |
| 122 | #define UCR4_CTSTL_32 (32<<10) /* CTS trigger level (32 chars) */ |
| 123 | #define UCR4_INVR (1<<9) /* Inverted infrared reception */ |
| 124 | #define UCR4_ENIRI (1<<8) /* Serial infrared interrupt enable */ |
| 125 | #define UCR4_WKEN (1<<7) /* Wake interrupt enable */ |
| 126 | #define UCR4_REF16 (1<<6) /* Ref freq 16 MHz */ |
| 127 | #define UCR4_IRSC (1<<5) /* IR special case */ |
| 128 | #define UCR4_TCEN (1<<3) /* Transmit complete interrupt enable */ |
| 129 | #define UCR4_BKEN (1<<2) /* Break condition interrupt enable */ |
| 130 | #define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */ |
| 131 | #define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ |
| 132 | #define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ |
| 133 | #define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ |
| 134 | #define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ |
| 135 | #define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */ |
| 136 | #define USR1_RTSS (1<<14) /* RTS pin status */ |
| 137 | #define USR1_TRDY (1<<13) /* Transmitter ready interrupt/dma flag */ |
| 138 | #define USR1_RTSD (1<<12) /* RTS delta */ |
| 139 | #define USR1_ESCF (1<<11) /* Escape seq interrupt flag */ |
| 140 | #define USR1_FRAMERR (1<<10) /* Frame error interrupt flag */ |
| 141 | #define USR1_RRDY (1<<9) /* Receiver ready interrupt/dma flag */ |
| 142 | #define USR1_TIMEOUT (1<<7) /* Receive timeout interrupt status */ |
| 143 | #define USR1_RXDS (1<<6) /* Receiver idle interrupt flag */ |
| 144 | #define USR1_AIRINT (1<<5) /* Async IR wake interrupt flag */ |
| 145 | #define USR1_AWAKE (1<<4) /* Aysnc wake interrupt flag */ |
| 146 | #define USR2_ADET (1<<15) /* Auto baud rate detect complete */ |
| 147 | #define USR2_TXFE (1<<14) /* Transmit buffer FIFO empty */ |
| 148 | #define USR2_DTRF (1<<13) /* DTR edge interrupt flag */ |
| 149 | #define USR2_IDLE (1<<12) /* Idle condition */ |
| 150 | #define USR2_IRINT (1<<8) /* Serial infrared interrupt flag */ |
| 151 | #define USR2_WAKE (1<<7) /* Wake */ |
| 152 | #define USR2_RTSF (1<<4) /* RTS edge interrupt flag */ |
| 153 | #define USR2_TXDC (1<<3) /* Transmitter complete */ |
| 154 | #define USR2_BRCD (1<<2) /* Break condition */ |
| 155 | #define USR2_ORE (1<<1) /* Overrun error */ |
| 156 | #define USR2_RDR (1<<0) /* Recv data ready */ |
| 157 | #define UTS_FRCPERR (1<<13) /* Force parity error */ |
| 158 | #define UTS_LOOP (1<<12) /* Loop tx and rx */ |
| 159 | #define UTS_TXEMPTY (1<<6) /* TxFIFO empty */ |
| 160 | #define UTS_RXEMPTY (1<<5) /* RxFIFO empty */ |
| 161 | #define UTS_TXFULL (1<<4) /* TxFIFO full */ |
| 162 | #define UTS_RXFULL (1<<3) /* RxFIFO full */ |
| 163 | #define UTS_SOFTRST (1<<0) /* Software reset */ |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* We've been assigned a range on the "Low-density serial ports" major */ |
| 166 | #define SERIAL_IMX_MAJOR 204 |
| 167 | #define MINOR_START 41 |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* |
| 170 | * This is the size of our serial port register set. |
| 171 | */ |
| 172 | #define UART_PORT_SIZE 0x100 |
| 173 | |
| 174 | /* |
| 175 | * This determines how often we check the modem status signals |
| 176 | * for any change. They generally aren't connected to an IRQ |
| 177 | * so we have to poll them. We also check immediately before |
| 178 | * filling the TX fifo incase CTS has been dropped. |
| 179 | */ |
| 180 | #define MCTRL_TIMEOUT (250*HZ/1000) |
| 181 | |
| 182 | #define DRIVER_NAME "IMX-uart" |
| 183 | |
| 184 | struct imx_port { |
| 185 | struct uart_port port; |
| 186 | struct timer_list timer; |
| 187 | unsigned int old_status; |
Sascha Hauer | 5b80234 | 2006-05-04 14:07:42 +0100 | [diff] [blame] | 188 | int txirq,rxirq,rtsirq; |
| 189 | int have_rtscts:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | /* |
| 193 | * Handle any change of modem status signal since we were last called. |
| 194 | */ |
| 195 | static void imx_mctrl_check(struct imx_port *sport) |
| 196 | { |
| 197 | unsigned int status, changed; |
| 198 | |
| 199 | status = sport->port.ops->get_mctrl(&sport->port); |
| 200 | changed = status ^ sport->old_status; |
| 201 | |
| 202 | if (changed == 0) |
| 203 | return; |
| 204 | |
| 205 | sport->old_status = status; |
| 206 | |
| 207 | if (changed & TIOCM_RI) |
| 208 | sport->port.icount.rng++; |
| 209 | if (changed & TIOCM_DSR) |
| 210 | sport->port.icount.dsr++; |
| 211 | if (changed & TIOCM_CAR) |
| 212 | uart_handle_dcd_change(&sport->port, status & TIOCM_CAR); |
| 213 | if (changed & TIOCM_CTS) |
| 214 | uart_handle_cts_change(&sport->port, status & TIOCM_CTS); |
| 215 | |
| 216 | wake_up_interruptible(&sport->port.info->delta_msr_wait); |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * This is our per-port timeout handler, for checking the |
| 221 | * modem status signals. |
| 222 | */ |
| 223 | static void imx_timeout(unsigned long data) |
| 224 | { |
| 225 | struct imx_port *sport = (struct imx_port *)data; |
| 226 | unsigned long flags; |
| 227 | |
| 228 | if (sport->port.info) { |
| 229 | spin_lock_irqsave(&sport->port.lock, flags); |
| 230 | imx_mctrl_check(sport); |
| 231 | spin_unlock_irqrestore(&sport->port.lock, flags); |
| 232 | |
| 233 | mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * interrupts disabled on entry |
| 239 | */ |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 240 | static void imx_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
| 242 | struct imx_port *sport = (struct imx_port *)port; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 243 | unsigned long temp; |
| 244 | |
| 245 | temp = readl(sport->port.membase + UCR1); |
| 246 | writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /* |
| 250 | * interrupts disabled on entry |
| 251 | */ |
| 252 | static void imx_stop_rx(struct uart_port *port) |
| 253 | { |
| 254 | struct imx_port *sport = (struct imx_port *)port; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 255 | unsigned long temp; |
| 256 | |
| 257 | temp = readl(sport->port.membase + UCR2); |
| 258 | writel(temp &~ UCR2_RXEN, sport->port.membase + UCR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Set the modem control timer to fire immediately. |
| 263 | */ |
| 264 | static void imx_enable_ms(struct uart_port *port) |
| 265 | { |
| 266 | struct imx_port *sport = (struct imx_port *)port; |
| 267 | |
| 268 | mod_timer(&sport->timer, jiffies); |
| 269 | } |
| 270 | |
| 271 | static inline void imx_transmit_buffer(struct imx_port *sport) |
| 272 | { |
| 273 | struct circ_buf *xmit = &sport->port.info->xmit; |
| 274 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 275 | while (!(readl(sport->port.membase + UTS) & UTS_TXFULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* send xmit->buf[xmit->tail] |
| 277 | * out the port here */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 278 | writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | xmit->tail = (xmit->tail + 1) & |
| 280 | (UART_XMIT_SIZE - 1); |
| 281 | sport->port.icount.tx++; |
| 282 | if (uart_circ_empty(xmit)) |
| 283 | break; |
Sascha Hauer | 8c0b254 | 2007-02-05 16:10:16 -0800 | [diff] [blame] | 284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | if (uart_circ_empty(xmit)) |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 287 | imx_stop_tx(&sport->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /* |
| 291 | * interrupts disabled on entry |
| 292 | */ |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 293 | static void imx_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
| 295 | struct imx_port *sport = (struct imx_port *)port; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 296 | unsigned long temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 298 | temp = readl(sport->port.membase + UCR1); |
| 299 | writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 301 | if (readl(sport->port.membase + UTS) & UTS_TXEMPTY) |
| 302 | imx_transmit_buffer(sport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 305 | static irqreturn_t imx_rtsint(int irq, void *dev_id) |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 306 | { |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 307 | struct imx_port *sport = dev_id; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 308 | unsigned int val = readl(sport->port.membase + USR1) & USR1_RTSS; |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 309 | unsigned long flags; |
| 310 | |
| 311 | spin_lock_irqsave(&sport->port.lock, flags); |
| 312 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 313 | writel(USR1_RTSD, sport->port.membase + USR1); |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 314 | uart_handle_cts_change(&sport->port, !!val); |
| 315 | wake_up_interruptible(&sport->port.info->delta_msr_wait); |
| 316 | |
| 317 | spin_unlock_irqrestore(&sport->port.lock, flags); |
| 318 | return IRQ_HANDLED; |
| 319 | } |
| 320 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 321 | static irqreturn_t imx_txint(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 323 | struct imx_port *sport = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | struct circ_buf *xmit = &sport->port.info->xmit; |
| 325 | unsigned long flags; |
| 326 | |
| 327 | spin_lock_irqsave(&sport->port.lock,flags); |
| 328 | if (sport->port.x_char) |
| 329 | { |
| 330 | /* Send next char */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 331 | writel(sport->port.x_char, sport->port.membase + URTX0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | goto out; |
| 333 | } |
| 334 | |
| 335 | if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 336 | imx_stop_tx(&sport->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | goto out; |
| 338 | } |
| 339 | |
| 340 | imx_transmit_buffer(sport); |
| 341 | |
| 342 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 343 | uart_write_wakeup(&sport->port); |
| 344 | |
| 345 | out: |
| 346 | spin_unlock_irqrestore(&sport->port.lock,flags); |
| 347 | return IRQ_HANDLED; |
| 348 | } |
| 349 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 350 | static irqreturn_t imx_rxint(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
| 352 | struct imx_port *sport = dev_id; |
| 353 | unsigned int rx,flg,ignored = 0; |
| 354 | struct tty_struct *tty = sport->port.info->tty; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 355 | unsigned long flags, temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | spin_lock_irqsave(&sport->port.lock,flags); |
| 358 | |
Sascha Hauer | 0d3c393 | 2008-04-17 08:43:14 +0100 | [diff] [blame^] | 359 | while (readl(sport->port.membase + USR2) & USR2_RDR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | flg = TTY_NORMAL; |
| 361 | sport->port.icount.rx++; |
| 362 | |
Sascha Hauer | 0d3c393 | 2008-04-17 08:43:14 +0100 | [diff] [blame^] | 363 | rx = readl(sport->port.membase + URXD0); |
| 364 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 365 | temp = readl(sport->port.membase + USR2); |
Sascha Hauer | 864eeed | 2008-04-17 08:39:22 +0100 | [diff] [blame] | 366 | if (temp & USR2_BRCD) { |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 367 | writel(temp | USR2_BRCD, sport->port.membase + USR2); |
Sascha Hauer | 864eeed | 2008-04-17 08:39:22 +0100 | [diff] [blame] | 368 | if (uart_handle_break(&sport->port)) |
| 369 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | if (uart_handle_sysrq_char |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 373 | (&sport->port, (unsigned char)rx)) |
Sascha Hauer | 864eeed | 2008-04-17 08:39:22 +0100 | [diff] [blame] | 374 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Sascha Hauer | 864eeed | 2008-04-17 08:39:22 +0100 | [diff] [blame] | 376 | if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { |
| 377 | if (rx & URXD_PRERR) |
| 378 | sport->port.icount.parity++; |
| 379 | else if (rx & URXD_FRMERR) |
| 380 | sport->port.icount.frame++; |
| 381 | if (rx & URXD_OVRRUN) |
| 382 | sport->port.icount.overrun++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Sascha Hauer | 864eeed | 2008-04-17 08:39:22 +0100 | [diff] [blame] | 384 | if (rx & sport->port.ignore_status_mask) { |
| 385 | if (++ignored > 100) |
| 386 | goto out; |
| 387 | continue; |
| 388 | } |
| 389 | |
| 390 | rx &= sport->port.read_status_mask; |
| 391 | |
| 392 | if (rx & URXD_PRERR) |
| 393 | flg = TTY_PARITY; |
| 394 | else if (rx & URXD_FRMERR) |
| 395 | flg = TTY_FRAME; |
| 396 | if (rx & URXD_OVRRUN) |
| 397 | flg = TTY_OVERRUN; |
| 398 | |
| 399 | #ifdef SUPPORT_SYSRQ |
| 400 | sport->port.sysrq = 0; |
| 401 | #endif |
| 402 | } |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | tty_insert_flip_char(tty, rx, flg); |
Sascha Hauer | 864eeed | 2008-04-17 08:39:22 +0100 | [diff] [blame] | 405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | out: |
| 408 | spin_unlock_irqrestore(&sport->port.lock,flags); |
| 409 | tty_flip_buffer_push(tty); |
| 410 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Return TIOCSER_TEMT when transmitter is not busy. |
| 415 | */ |
| 416 | static unsigned int imx_tx_empty(struct uart_port *port) |
| 417 | { |
| 418 | struct imx_port *sport = (struct imx_port *)port; |
| 419 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 420 | return (readl(sport->port.membase + USR2) & USR2_TXDC) ? TIOCSER_TEMT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Sascha Hauer | 0f302dc | 2005-08-31 21:48:47 +0100 | [diff] [blame] | 423 | /* |
| 424 | * We have a modem side uart, so the meanings of RTS and CTS are inverted. |
| 425 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | static unsigned int imx_get_mctrl(struct uart_port *port) |
| 427 | { |
Sascha Hauer | 0f302dc | 2005-08-31 21:48:47 +0100 | [diff] [blame] | 428 | struct imx_port *sport = (struct imx_port *)port; |
| 429 | unsigned int tmp = TIOCM_DSR | TIOCM_CAR; |
| 430 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 431 | if (readl(sport->port.membase + USR1) & USR1_RTSS) |
Sascha Hauer | 0f302dc | 2005-08-31 21:48:47 +0100 | [diff] [blame] | 432 | tmp |= TIOCM_CTS; |
| 433 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 434 | if (readl(sport->port.membase + UCR2) & UCR2_CTS) |
Sascha Hauer | 0f302dc | 2005-08-31 21:48:47 +0100 | [diff] [blame] | 435 | tmp |= TIOCM_RTS; |
| 436 | |
| 437 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 441 | { |
Sascha Hauer | 0f302dc | 2005-08-31 21:48:47 +0100 | [diff] [blame] | 442 | struct imx_port *sport = (struct imx_port *)port; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 443 | unsigned long temp; |
| 444 | |
| 445 | temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS; |
Sascha Hauer | 0f302dc | 2005-08-31 21:48:47 +0100 | [diff] [blame] | 446 | |
| 447 | if (mctrl & TIOCM_RTS) |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 448 | temp |= UCR2_CTS; |
| 449 | |
| 450 | writel(temp, sport->port.membase + UCR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Interrupts always disabled. |
| 455 | */ |
| 456 | static void imx_break_ctl(struct uart_port *port, int break_state) |
| 457 | { |
| 458 | struct imx_port *sport = (struct imx_port *)port; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 459 | unsigned long flags, temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | spin_lock_irqsave(&sport->port.lock, flags); |
| 462 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 463 | temp = readl(sport->port.membase + UCR1) & ~UCR1_SNDBRK; |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if ( break_state != 0 ) |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 466 | temp |= UCR1_SNDBRK; |
| 467 | |
| 468 | writel(temp, sport->port.membase + UCR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | spin_unlock_irqrestore(&sport->port.lock, flags); |
| 471 | } |
| 472 | |
| 473 | #define TXTL 2 /* reset default */ |
| 474 | #define RXTL 1 /* reset default */ |
| 475 | |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 476 | static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode) |
| 477 | { |
| 478 | unsigned int val; |
| 479 | unsigned int ufcr_rfdiv; |
| 480 | |
| 481 | /* set receiver / transmitter trigger level. |
| 482 | * RFDIV is set such way to satisfy requested uartclk value |
| 483 | */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 484 | val = TXTL << 10 | RXTL; |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 485 | ufcr_rfdiv = (imx_get_perclk1() + sport->port.uartclk / 2) / sport->port.uartclk; |
| 486 | |
| 487 | if(!ufcr_rfdiv) |
| 488 | ufcr_rfdiv = 1; |
| 489 | |
| 490 | if(ufcr_rfdiv >= 7) |
| 491 | ufcr_rfdiv = 6; |
| 492 | else |
| 493 | ufcr_rfdiv = 6 - ufcr_rfdiv; |
| 494 | |
| 495 | val |= UFCR_RFDIV & (ufcr_rfdiv << 7); |
| 496 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 497 | writel(val, sport->port.membase + UFCR); |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | static int imx_startup(struct uart_port *port) |
| 503 | { |
| 504 | struct imx_port *sport = (struct imx_port *)port; |
| 505 | int retval; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 506 | unsigned long flags, temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 508 | imx_setup_ufcr(sport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | /* disable the DREN bit (Data Ready interrupt enable) before |
| 511 | * requesting IRQs |
| 512 | */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 513 | temp = readl(sport->port.membase + UCR4); |
| 514 | writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
| 516 | /* |
| 517 | * Allocate the IRQ |
| 518 | */ |
| 519 | retval = request_irq(sport->rxirq, imx_rxint, 0, |
| 520 | DRIVER_NAME, sport); |
Sascha Hauer | 86371d0 | 2005-10-10 10:17:42 +0100 | [diff] [blame] | 521 | if (retval) goto error_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | retval = request_irq(sport->txirq, imx_txint, 0, |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 524 | DRIVER_NAME, sport); |
Sascha Hauer | 86371d0 | 2005-10-10 10:17:42 +0100 | [diff] [blame] | 525 | if (retval) goto error_out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Russell King | f43aaba | 2006-01-19 12:26:57 +0000 | [diff] [blame] | 527 | retval = request_irq(sport->rtsirq, imx_rtsint, |
Pavel Pisa | d7ea10d | 2007-02-05 16:10:20 -0800 | [diff] [blame] | 528 | (sport->rtsirq < IMX_IRQS) ? 0 : |
| 529 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 530 | DRIVER_NAME, sport); |
| 531 | if (retval) goto error_out3; |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /* |
| 534 | * Finally, clear and enable interrupts |
| 535 | */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 536 | writel(USR1_RTSD, sport->port.membase + USR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 538 | temp = readl(sport->port.membase + UCR1); |
| 539 | temp |= (UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); |
| 540 | writel(temp, sport->port.membase + UCR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 542 | temp = readl(sport->port.membase + UCR2); |
| 543 | temp |= (UCR2_RXEN | UCR2_TXEN); |
| 544 | writel(temp, sport->port.membase + UCR2); |
| 545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | /* |
| 547 | * Enable modem status interrupts |
| 548 | */ |
| 549 | spin_lock_irqsave(&sport->port.lock,flags); |
| 550 | imx_enable_ms(&sport->port); |
| 551 | spin_unlock_irqrestore(&sport->port.lock,flags); |
| 552 | |
| 553 | return 0; |
| 554 | |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 555 | error_out3: |
| 556 | free_irq(sport->txirq, sport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | error_out2: |
Sascha Hauer | 86371d0 | 2005-10-10 10:17:42 +0100 | [diff] [blame] | 558 | free_irq(sport->rxirq, sport); |
| 559 | error_out1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | return retval; |
| 561 | } |
| 562 | |
| 563 | static void imx_shutdown(struct uart_port *port) |
| 564 | { |
| 565 | struct imx_port *sport = (struct imx_port *)port; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 566 | unsigned long temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | /* |
| 569 | * Stop our timer. |
| 570 | */ |
| 571 | del_timer_sync(&sport->timer); |
| 572 | |
| 573 | /* |
| 574 | * Free the interrupts |
| 575 | */ |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 576 | free_irq(sport->rtsirq, sport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | free_irq(sport->txirq, sport); |
| 578 | free_irq(sport->rxirq, sport); |
| 579 | |
| 580 | /* |
| 581 | * Disable all interrupts, port and break condition. |
| 582 | */ |
| 583 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 584 | temp = readl(sport->port.membase + UCR1); |
| 585 | temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); |
| 586 | writel(temp, sport->port.membase + UCR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | static void |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 590 | imx_set_termios(struct uart_port *port, struct ktermios *termios, |
| 591 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
| 593 | struct imx_port *sport = (struct imx_port *)port; |
| 594 | unsigned long flags; |
| 595 | unsigned int ucr2, old_ucr1, old_txrxen, baud, quot; |
| 596 | unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; |
| 597 | |
| 598 | /* |
| 599 | * If we don't support modem control lines, don't allow |
| 600 | * these to be set. |
| 601 | */ |
| 602 | if (0) { |
| 603 | termios->c_cflag &= ~(HUPCL | CRTSCTS | CMSPAR); |
| 604 | termios->c_cflag |= CLOCAL; |
| 605 | } |
| 606 | |
| 607 | /* |
| 608 | * We only support CS7 and CS8. |
| 609 | */ |
| 610 | while ((termios->c_cflag & CSIZE) != CS7 && |
| 611 | (termios->c_cflag & CSIZE) != CS8) { |
| 612 | termios->c_cflag &= ~CSIZE; |
| 613 | termios->c_cflag |= old_csize; |
| 614 | old_csize = CS8; |
| 615 | } |
| 616 | |
| 617 | if ((termios->c_cflag & CSIZE) == CS8) |
| 618 | ucr2 = UCR2_WS | UCR2_SRST | UCR2_IRTS; |
| 619 | else |
| 620 | ucr2 = UCR2_SRST | UCR2_IRTS; |
| 621 | |
| 622 | if (termios->c_cflag & CRTSCTS) { |
Sascha Hauer | 5b80234 | 2006-05-04 14:07:42 +0100 | [diff] [blame] | 623 | if( sport->have_rtscts ) { |
| 624 | ucr2 &= ~UCR2_IRTS; |
| 625 | ucr2 |= UCR2_CTSC; |
| 626 | } else { |
| 627 | termios->c_cflag &= ~CRTSCTS; |
| 628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | if (termios->c_cflag & CSTOPB) |
| 632 | ucr2 |= UCR2_STPB; |
| 633 | if (termios->c_cflag & PARENB) { |
| 634 | ucr2 |= UCR2_PREN; |
Matt Reimer | 3261e36 | 2006-01-13 20:51:44 +0000 | [diff] [blame] | 635 | if (termios->c_cflag & PARODD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | ucr2 |= UCR2_PROE; |
| 637 | } |
| 638 | |
| 639 | /* |
| 640 | * Ask the core to calculate the divisor for us. |
| 641 | */ |
| 642 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); |
| 643 | quot = uart_get_divisor(port, baud); |
| 644 | |
| 645 | spin_lock_irqsave(&sport->port.lock, flags); |
| 646 | |
| 647 | sport->port.read_status_mask = 0; |
| 648 | if (termios->c_iflag & INPCK) |
| 649 | sport->port.read_status_mask |= (URXD_FRMERR | URXD_PRERR); |
| 650 | if (termios->c_iflag & (BRKINT | PARMRK)) |
| 651 | sport->port.read_status_mask |= URXD_BRK; |
| 652 | |
| 653 | /* |
| 654 | * Characters to ignore |
| 655 | */ |
| 656 | sport->port.ignore_status_mask = 0; |
| 657 | if (termios->c_iflag & IGNPAR) |
| 658 | sport->port.ignore_status_mask |= URXD_PRERR; |
| 659 | if (termios->c_iflag & IGNBRK) { |
| 660 | sport->port.ignore_status_mask |= URXD_BRK; |
| 661 | /* |
| 662 | * If we're ignoring parity and break indicators, |
| 663 | * ignore overruns too (for real raw support). |
| 664 | */ |
| 665 | if (termios->c_iflag & IGNPAR) |
| 666 | sport->port.ignore_status_mask |= URXD_OVRRUN; |
| 667 | } |
| 668 | |
| 669 | del_timer_sync(&sport->timer); |
| 670 | |
| 671 | /* |
| 672 | * Update the per-port timeout. |
| 673 | */ |
| 674 | uart_update_timeout(port, termios->c_cflag, baud); |
| 675 | |
| 676 | /* |
| 677 | * disable interrupts and drain transmitter |
| 678 | */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 679 | old_ucr1 = readl(sport->port.membase + UCR1); |
| 680 | writel(old_ucr1 & ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN), |
| 681 | sport->port.membase + UCR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 683 | while ( !(readl(sport->port.membase + USR2) & USR2_TXDC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | barrier(); |
| 685 | |
| 686 | /* then, disable everything */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 687 | old_txrxen = readl(sport->port.membase + UCR2); |
| 688 | writel(old_txrxen & ~( UCR2_TXEN | UCR2_RXEN), |
| 689 | sport->port.membase + UCR2); |
| 690 | old_txrxen &= (UCR2_TXEN | UCR2_RXEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
| 692 | /* set the baud rate. We assume uartclk = 16 MHz |
| 693 | * |
| 694 | * baud * 16 UBIR - 1 |
| 695 | * --------- = -------- |
| 696 | * uartclk UBMR - 1 |
| 697 | */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 698 | writel((baud / 100) - 1, sport->port.membase + UBIR); |
| 699 | writel(10000 - 1, sport->port.membase + UBMR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 701 | writel(old_ucr1, sport->port.membase + UCR1); |
| 702 | |
| 703 | /* set the parity, stop bits and data size */ |
| 704 | writel(ucr2 | old_txrxen, sport->port.membase + UCR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
| 706 | if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) |
| 707 | imx_enable_ms(&sport->port); |
| 708 | |
| 709 | spin_unlock_irqrestore(&sport->port.lock, flags); |
| 710 | } |
| 711 | |
| 712 | static const char *imx_type(struct uart_port *port) |
| 713 | { |
| 714 | struct imx_port *sport = (struct imx_port *)port; |
| 715 | |
| 716 | return sport->port.type == PORT_IMX ? "IMX" : NULL; |
| 717 | } |
| 718 | |
| 719 | /* |
| 720 | * Release the memory region(s) being used by 'port'. |
| 721 | */ |
| 722 | static void imx_release_port(struct uart_port *port) |
| 723 | { |
| 724 | struct imx_port *sport = (struct imx_port *)port; |
| 725 | |
| 726 | release_mem_region(sport->port.mapbase, UART_PORT_SIZE); |
| 727 | } |
| 728 | |
| 729 | /* |
| 730 | * Request the memory region(s) being used by 'port'. |
| 731 | */ |
| 732 | static int imx_request_port(struct uart_port *port) |
| 733 | { |
| 734 | struct imx_port *sport = (struct imx_port *)port; |
| 735 | |
| 736 | return request_mem_region(sport->port.mapbase, UART_PORT_SIZE, |
| 737 | "imx-uart") != NULL ? 0 : -EBUSY; |
| 738 | } |
| 739 | |
| 740 | /* |
| 741 | * Configure/autoconfigure the port. |
| 742 | */ |
| 743 | static void imx_config_port(struct uart_port *port, int flags) |
| 744 | { |
| 745 | struct imx_port *sport = (struct imx_port *)port; |
| 746 | |
| 747 | if (flags & UART_CONFIG_TYPE && |
| 748 | imx_request_port(&sport->port) == 0) |
| 749 | sport->port.type = PORT_IMX; |
| 750 | } |
| 751 | |
| 752 | /* |
| 753 | * Verify the new serial_struct (for TIOCSSERIAL). |
| 754 | * The only change we allow are to the flags and type, and |
| 755 | * even then only between PORT_IMX and PORT_UNKNOWN |
| 756 | */ |
| 757 | static int |
| 758 | imx_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 759 | { |
| 760 | struct imx_port *sport = (struct imx_port *)port; |
| 761 | int ret = 0; |
| 762 | |
| 763 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_IMX) |
| 764 | ret = -EINVAL; |
| 765 | if (sport->port.irq != ser->irq) |
| 766 | ret = -EINVAL; |
| 767 | if (ser->io_type != UPIO_MEM) |
| 768 | ret = -EINVAL; |
| 769 | if (sport->port.uartclk / 16 != ser->baud_base) |
| 770 | ret = -EINVAL; |
| 771 | if ((void *)sport->port.mapbase != ser->iomem_base) |
| 772 | ret = -EINVAL; |
| 773 | if (sport->port.iobase != ser->port) |
| 774 | ret = -EINVAL; |
| 775 | if (ser->hub6 != 0) |
| 776 | ret = -EINVAL; |
| 777 | return ret; |
| 778 | } |
| 779 | |
| 780 | static struct uart_ops imx_pops = { |
| 781 | .tx_empty = imx_tx_empty, |
| 782 | .set_mctrl = imx_set_mctrl, |
| 783 | .get_mctrl = imx_get_mctrl, |
| 784 | .stop_tx = imx_stop_tx, |
| 785 | .start_tx = imx_start_tx, |
| 786 | .stop_rx = imx_stop_rx, |
| 787 | .enable_ms = imx_enable_ms, |
| 788 | .break_ctl = imx_break_ctl, |
| 789 | .startup = imx_startup, |
| 790 | .shutdown = imx_shutdown, |
| 791 | .set_termios = imx_set_termios, |
| 792 | .type = imx_type, |
| 793 | .release_port = imx_release_port, |
| 794 | .request_port = imx_request_port, |
| 795 | .config_port = imx_config_port, |
| 796 | .verify_port = imx_verify_port, |
| 797 | }; |
| 798 | |
| 799 | static struct imx_port imx_ports[] = { |
| 800 | { |
| 801 | .txirq = UART1_MINT_TX, |
| 802 | .rxirq = UART1_MINT_RX, |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 803 | .rtsirq = UART1_MINT_RTS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | .port = { |
| 805 | .type = PORT_IMX, |
Russell King | 9b4a161 | 2006-02-05 10:48:10 +0000 | [diff] [blame] | 806 | .iotype = UPIO_MEM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | .membase = (void *)IMX_UART1_BASE, |
| 808 | .mapbase = IMX_UART1_BASE, /* FIXME */ |
| 809 | .irq = UART1_MINT_RX, |
| 810 | .uartclk = 16000000, |
Sascha Hauer | 8c0b254 | 2007-02-05 16:10:16 -0800 | [diff] [blame] | 811 | .fifosize = 32, |
Russell King | ce8337c | 2006-01-21 19:28:15 +0000 | [diff] [blame] | 812 | .flags = UPF_BOOT_AUTOCONF, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | .ops = &imx_pops, |
| 814 | .line = 0, |
| 815 | }, |
| 816 | }, { |
| 817 | .txirq = UART2_MINT_TX, |
| 818 | .rxirq = UART2_MINT_RX, |
Sascha Hauer | ceca629 | 2005-10-12 19:58:08 +0100 | [diff] [blame] | 819 | .rtsirq = UART2_MINT_RTS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | .port = { |
| 821 | .type = PORT_IMX, |
Russell King | 9b4a161 | 2006-02-05 10:48:10 +0000 | [diff] [blame] | 822 | .iotype = UPIO_MEM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | .membase = (void *)IMX_UART2_BASE, |
| 824 | .mapbase = IMX_UART2_BASE, /* FIXME */ |
| 825 | .irq = UART2_MINT_RX, |
| 826 | .uartclk = 16000000, |
Sascha Hauer | 8c0b254 | 2007-02-05 16:10:16 -0800 | [diff] [blame] | 827 | .fifosize = 32, |
Russell King | ce8337c | 2006-01-21 19:28:15 +0000 | [diff] [blame] | 828 | .flags = UPF_BOOT_AUTOCONF, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | .ops = &imx_pops, |
| 830 | .line = 1, |
| 831 | }, |
| 832 | } |
| 833 | }; |
| 834 | |
| 835 | /* |
| 836 | * Setup the IMX serial ports. |
| 837 | * Note also that we support "console=ttySMXx" where "x" is either 0 or 1. |
| 838 | * Which serial port this ends up being depends on the machine you're |
| 839 | * running this kernel on. I'm not convinced that this is a good idea, |
| 840 | * but that's the way it traditionally works. |
| 841 | * |
| 842 | */ |
| 843 | static void __init imx_init_ports(void) |
| 844 | { |
| 845 | static int first = 1; |
| 846 | int i; |
| 847 | |
| 848 | if (!first) |
| 849 | return; |
| 850 | first = 0; |
| 851 | |
| 852 | for (i = 0; i < ARRAY_SIZE(imx_ports); i++) { |
| 853 | init_timer(&imx_ports[i].timer); |
| 854 | imx_ports[i].timer.function = imx_timeout; |
| 855 | imx_ports[i].timer.data = (unsigned long)&imx_ports[i]; |
| 856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | #ifdef CONFIG_SERIAL_IMX_CONSOLE |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 860 | static void imx_console_putchar(struct uart_port *port, int ch) |
| 861 | { |
| 862 | struct imx_port *sport = (struct imx_port *)port; |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 863 | |
| 864 | while (readl(sport->port.membase + UTS) & UTS_TXFULL) |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 865 | barrier(); |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 866 | |
| 867 | writel(ch, sport->port.membase + URTX0); |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | /* |
| 871 | * Interrupts are disabled on entering |
| 872 | */ |
| 873 | static void |
| 874 | imx_console_write(struct console *co, const char *s, unsigned int count) |
| 875 | { |
| 876 | struct imx_port *sport = &imx_ports[co->index]; |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 877 | unsigned int old_ucr1, old_ucr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
| 879 | /* |
| 880 | * First, save UCR1/2 and then disable interrupts |
| 881 | */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 882 | old_ucr1 = readl(sport->port.membase + UCR1); |
| 883 | old_ucr2 = readl(sport->port.membase + UCR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 885 | writel((old_ucr1 | UCR1_UARTCLKEN | UCR1_UARTEN) & |
| 886 | ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN), |
| 887 | sport->port.membase + UCR1); |
| 888 | |
| 889 | writel(old_ucr2 | UCR2_TXEN, sport->port.membase + UCR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 891 | uart_console_write(&sport->port, s, count, imx_console_putchar); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | /* |
| 894 | * Finally, wait for transmitter to become empty |
| 895 | * and restore UCR1/2 |
| 896 | */ |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 897 | while (!(readl(sport->port.membase + USR2) & USR2_TXDC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 899 | writel(old_ucr1, sport->port.membase + UCR1); |
| 900 | writel(old_ucr2, sport->port.membase + UCR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | /* |
| 904 | * If the port was already initialised (eg, by a boot loader), |
| 905 | * try to determine the current setup. |
| 906 | */ |
| 907 | static void __init |
| 908 | imx_console_get_options(struct imx_port *sport, int *baud, |
| 909 | int *parity, int *bits) |
| 910 | { |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 911 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 912 | if ( readl(sport->port.membase + UCR1) | UCR1_UARTEN ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | /* ok, the port was enabled */ |
| 914 | unsigned int ucr2, ubir,ubmr, uartclk; |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 915 | unsigned int baud_raw; |
| 916 | unsigned int ucfr_rfdiv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 918 | ucr2 = readl(sport->port.membase + UCR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
| 920 | *parity = 'n'; |
| 921 | if (ucr2 & UCR2_PREN) { |
| 922 | if (ucr2 & UCR2_PROE) |
| 923 | *parity = 'o'; |
| 924 | else |
| 925 | *parity = 'e'; |
| 926 | } |
| 927 | |
| 928 | if (ucr2 & UCR2_WS) |
| 929 | *bits = 8; |
| 930 | else |
| 931 | *bits = 7; |
| 932 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 933 | ubir = readl(sport->port.membase + UBIR) & 0xffff; |
| 934 | ubmr = readl(sport->port.membase + UBMR) & 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Sascha Hauer | ff4bfb2 | 2007-04-26 08:26:13 +0100 | [diff] [blame] | 936 | ucfr_rfdiv = (readl(sport->port.membase + UFCR) & UFCR_RFDIV) >> 7; |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 937 | if (ucfr_rfdiv == 6) |
| 938 | ucfr_rfdiv = 7; |
| 939 | else |
| 940 | ucfr_rfdiv = 6 - ucfr_rfdiv; |
| 941 | |
| 942 | uartclk = imx_get_perclk1(); |
| 943 | uartclk /= ucfr_rfdiv; |
| 944 | |
| 945 | { /* |
| 946 | * The next code provides exact computation of |
| 947 | * baud_raw = round(((uartclk/16) * (ubir + 1)) / (ubmr + 1)) |
| 948 | * without need of float support or long long division, |
| 949 | * which would be required to prevent 32bit arithmetic overflow |
| 950 | */ |
| 951 | unsigned int mul = ubir + 1; |
| 952 | unsigned int div = 16 * (ubmr + 1); |
| 953 | unsigned int rem = uartclk % div; |
| 954 | |
| 955 | baud_raw = (uartclk / div) * mul; |
| 956 | baud_raw += (rem * mul + div / 2) / div; |
| 957 | *baud = (baud_raw + 50) / 100 * 100; |
| 958 | } |
| 959 | |
| 960 | if(*baud != baud_raw) |
| 961 | printk(KERN_INFO "Serial: Console IMX rounded baud rate from %d to %d\n", |
| 962 | baud_raw, *baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
| 966 | static int __init |
| 967 | imx_console_setup(struct console *co, char *options) |
| 968 | { |
| 969 | struct imx_port *sport; |
| 970 | int baud = 9600; |
| 971 | int bits = 8; |
| 972 | int parity = 'n'; |
| 973 | int flow = 'n'; |
| 974 | |
| 975 | /* |
| 976 | * Check whether an invalid uart number has been specified, and |
| 977 | * if so, search for the first available port that does have |
| 978 | * console support. |
| 979 | */ |
| 980 | if (co->index == -1 || co->index >= ARRAY_SIZE(imx_ports)) |
| 981 | co->index = 0; |
| 982 | sport = &imx_ports[co->index]; |
| 983 | |
| 984 | if (options) |
| 985 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 986 | else |
| 987 | imx_console_get_options(sport, &baud, &parity, &bits); |
| 988 | |
Sascha Hauer | 587897f | 2005-04-29 22:46:40 +0100 | [diff] [blame] | 989 | imx_setup_ufcr(sport, 0); |
| 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | return uart_set_options(&sport->port, co, baud, parity, bits, flow); |
| 992 | } |
| 993 | |
Vincent Sanders | 9f4426d | 2005-10-01 22:56:34 +0100 | [diff] [blame] | 994 | static struct uart_driver imx_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | static struct console imx_console = { |
| 996 | .name = "ttySMX", |
| 997 | .write = imx_console_write, |
| 998 | .device = uart_console_device, |
| 999 | .setup = imx_console_setup, |
| 1000 | .flags = CON_PRINTBUFFER, |
| 1001 | .index = -1, |
| 1002 | .data = &imx_reg, |
| 1003 | }; |
| 1004 | |
| 1005 | static int __init imx_rs_console_init(void) |
| 1006 | { |
| 1007 | imx_init_ports(); |
| 1008 | register_console(&imx_console); |
| 1009 | return 0; |
| 1010 | } |
| 1011 | console_initcall(imx_rs_console_init); |
| 1012 | |
| 1013 | #define IMX_CONSOLE &imx_console |
| 1014 | #else |
| 1015 | #define IMX_CONSOLE NULL |
| 1016 | #endif |
| 1017 | |
| 1018 | static struct uart_driver imx_reg = { |
| 1019 | .owner = THIS_MODULE, |
| 1020 | .driver_name = DRIVER_NAME, |
| 1021 | .dev_name = "ttySMX", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | .major = SERIAL_IMX_MAJOR, |
| 1023 | .minor = MINOR_START, |
| 1024 | .nr = ARRAY_SIZE(imx_ports), |
| 1025 | .cons = IMX_CONSOLE, |
| 1026 | }; |
| 1027 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1028 | static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1030 | struct imx_port *sport = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1032 | if (sport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | uart_suspend_port(&imx_reg, &sport->port); |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1038 | static int serial_imx_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1040 | struct imx_port *sport = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1042 | if (sport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | uart_resume_port(&imx_reg, &sport->port); |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1048 | static int serial_imx_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | { |
Sascha Hauer | 5b80234 | 2006-05-04 14:07:42 +0100 | [diff] [blame] | 1050 | struct imxuart_platform_data *pdata; |
| 1051 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1052 | imx_ports[dev->id].port.dev = &dev->dev; |
Sascha Hauer | 5b80234 | 2006-05-04 14:07:42 +0100 | [diff] [blame] | 1053 | |
| 1054 | pdata = (struct imxuart_platform_data *)dev->dev.platform_data; |
| 1055 | if(pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) |
| 1056 | imx_ports[dev->id].have_rtscts = 1; |
| 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | uart_add_one_port(&imx_reg, &imx_ports[dev->id].port); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1059 | platform_set_drvdata(dev, &imx_ports[dev->id]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | return 0; |
| 1061 | } |
| 1062 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1063 | static int serial_imx_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1065 | struct imx_port *sport = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1067 | platform_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
| 1069 | if (sport) |
| 1070 | uart_remove_one_port(&imx_reg, &sport->port); |
| 1071 | |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1075 | static struct platform_driver serial_imx_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | .probe = serial_imx_probe, |
| 1077 | .remove = serial_imx_remove, |
| 1078 | |
| 1079 | .suspend = serial_imx_suspend, |
| 1080 | .resume = serial_imx_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1081 | .driver = { |
| 1082 | .name = "imx-uart", |
| 1083 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | }; |
| 1085 | |
| 1086 | static int __init imx_serial_init(void) |
| 1087 | { |
| 1088 | int ret; |
| 1089 | |
| 1090 | printk(KERN_INFO "Serial: IMX driver\n"); |
| 1091 | |
| 1092 | imx_init_ports(); |
| 1093 | |
| 1094 | ret = uart_register_driver(&imx_reg); |
| 1095 | if (ret) |
| 1096 | return ret; |
| 1097 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1098 | ret = platform_driver_register(&serial_imx_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | if (ret != 0) |
| 1100 | uart_unregister_driver(&imx_reg); |
| 1101 | |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
| 1105 | static void __exit imx_serial_exit(void) |
| 1106 | { |
Russell King | c889b89 | 2005-11-21 17:05:21 +0000 | [diff] [blame] | 1107 | platform_driver_unregister(&serial_imx_driver); |
Sascha Hauer | 4b300c3 | 2007-07-17 13:35:46 +0100 | [diff] [blame] | 1108 | uart_unregister_driver(&imx_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | module_init(imx_serial_init); |
| 1112 | module_exit(imx_serial_exit); |
| 1113 | |
| 1114 | MODULE_AUTHOR("Sascha Hauer"); |
| 1115 | MODULE_DESCRIPTION("IMX generic serial port driver"); |
| 1116 | MODULE_LICENSE("GPL"); |