blob: 5d7b58f1fe42a38596072ba9355d619ffcfd54a2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Fabian Godehardtb6e49132009-06-11 14:53:18 +010011 * Copyright (C) 2009 emlix GmbH
12 * Author: Fabian Godehardt (added IrDA support for iMX)
13 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 * [29-Mar-2005] Mike Lee
29 * Added hardware handshake
30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#if defined(CONFIG_SERIAL_IMX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
33#define SUPPORT_SYSRQ
34#endif
35
36#include <linux/module.h>
37#include <linux/ioport.h>
38#include <linux/init.h>
39#include <linux/console.h>
40#include <linux/sysrq.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010041#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/tty.h>
43#include <linux/tty_flip.h>
44#include <linux/serial_core.h>
45#include <linux/serial.h>
Sascha Hauer38a41fd2008-07-05 10:02:46 +020046#include <linux/clk.h>
Fabian Godehardtb6e49132009-06-11 14:53:18 +010047#include <linux/delay.h>
Oskar Schirmer534fca02009-06-11 14:52:23 +010048#include <linux/rational.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/io.h>
51#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010052#include <mach/hardware.h>
53#include <mach/imx-uart.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Sascha Hauerff4bfb22007-04-26 08:26:13 +010055/* Register definitions */
56#define URXD0 0x0 /* Receiver Register */
57#define URTX0 0x40 /* Transmitter Register */
58#define UCR1 0x80 /* Control Register 1 */
59#define UCR2 0x84 /* Control Register 2 */
60#define UCR3 0x88 /* Control Register 3 */
61#define UCR4 0x8c /* Control Register 4 */
62#define UFCR 0x90 /* FIFO Control Register */
63#define USR1 0x94 /* Status Register 1 */
64#define USR2 0x98 /* Status Register 2 */
65#define UESC 0x9c /* Escape Character Register */
66#define UTIM 0xa0 /* Escape Timer Register */
67#define UBIR 0xa4 /* BRM Incremental Register */
68#define UBMR 0xa8 /* BRM Modulator Register */
69#define UBRC 0xac /* Baud Rate Count Register */
Sascha Hauer604cbad2008-07-05 10:02:58 +020070#if defined CONFIG_ARCH_MX3 || defined CONFIG_ARCH_MX2
Sascha Hauere3d13ff2008-07-05 10:02:48 +020071#define ONEMS 0xb0 /* One Millisecond register */
72#define UTS 0xb4 /* UART Test Register */
73#endif
Sascha Hauer8c8fdbc2009-04-01 12:40:15 +020074#ifdef CONFIG_ARCH_MX1
Sascha Hauerff4bfb22007-04-26 08:26:13 +010075#define BIPR1 0xb0 /* Incremental Preset Register 1 */
76#define BIPR2 0xb4 /* Incremental Preset Register 2 */
77#define BIPR3 0xb8 /* Incremental Preset Register 3 */
78#define BIPR4 0xbc /* Incremental Preset Register 4 */
79#define BMPR1 0xc0 /* BRM Modulator Register 1 */
80#define BMPR2 0xc4 /* BRM Modulator Register 2 */
81#define BMPR3 0xc8 /* BRM Modulator Register 3 */
82#define BMPR4 0xcc /* BRM Modulator Register 4 */
83#define UTS 0xd0 /* UART Test Register */
Sascha Hauere3d13ff2008-07-05 10:02:48 +020084#endif
Sascha Hauerff4bfb22007-04-26 08:26:13 +010085
86/* UART Control Register Bit Fields.*/
87#define URXD_CHARRDY (1<<15)
88#define URXD_ERR (1<<14)
89#define URXD_OVRRUN (1<<13)
90#define URXD_FRMERR (1<<12)
91#define URXD_BRK (1<<11)
92#define URXD_PRERR (1<<10)
93#define UCR1_ADEN (1<<15) /* Auto dectect interrupt */
94#define UCR1_ADBR (1<<14) /* Auto detect baud rate */
95#define UCR1_TRDYEN (1<<13) /* Transmitter ready interrupt enable */
96#define UCR1_IDEN (1<<12) /* Idle condition interrupt */
97#define UCR1_RRDYEN (1<<9) /* Recv ready interrupt enable */
98#define UCR1_RDMAEN (1<<8) /* Recv ready DMA enable */
99#define UCR1_IREN (1<<7) /* Infrared interface enable */
100#define UCR1_TXMPTYEN (1<<6) /* Transimitter empty interrupt enable */
101#define UCR1_RTSDEN (1<<5) /* RTS delta interrupt enable */
102#define UCR1_SNDBRK (1<<4) /* Send break */
103#define UCR1_TDMAEN (1<<3) /* Transmitter ready DMA enable */
Sascha Hauer8c8fdbc2009-04-01 12:40:15 +0200104#ifdef CONFIG_ARCH_MX1
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100105#define UCR1_UARTCLKEN (1<<2) /* UART clock enabled */
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200106#endif
Sascha Hauer604cbad2008-07-05 10:02:58 +0200107#if defined CONFIG_ARCH_MX3 || defined CONFIG_ARCH_MX2
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200108#define UCR1_UARTCLKEN (0) /* not present on mx2/mx3 */
109#endif
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100110#define UCR1_DOZE (1<<1) /* Doze */
111#define UCR1_UARTEN (1<<0) /* UART enabled */
112#define UCR2_ESCI (1<<15) /* Escape seq interrupt enable */
113#define UCR2_IRTS (1<<14) /* Ignore RTS pin */
114#define UCR2_CTSC (1<<13) /* CTS pin control */
115#define UCR2_CTS (1<<12) /* Clear to send */
116#define UCR2_ESCEN (1<<11) /* Escape enable */
117#define UCR2_PREN (1<<8) /* Parity enable */
118#define UCR2_PROE (1<<7) /* Parity odd/even */
119#define UCR2_STPB (1<<6) /* Stop */
120#define UCR2_WS (1<<5) /* Word size */
121#define UCR2_RTSEN (1<<4) /* Request to send interrupt enable */
122#define UCR2_TXEN (1<<2) /* Transmitter enabled */
123#define UCR2_RXEN (1<<1) /* Receiver enabled */
124#define UCR2_SRST (1<<0) /* SW reset */
125#define UCR3_DTREN (1<<13) /* DTR interrupt enable */
126#define UCR3_PARERREN (1<<12) /* Parity enable */
127#define UCR3_FRAERREN (1<<11) /* Frame error interrupt enable */
128#define UCR3_DSR (1<<10) /* Data set ready */
129#define UCR3_DCD (1<<9) /* Data carrier detect */
130#define UCR3_RI (1<<8) /* Ring indicator */
131#define UCR3_TIMEOUTEN (1<<7) /* Timeout interrupt enable */
132#define UCR3_RXDSEN (1<<6) /* Receive status interrupt enable */
133#define UCR3_AIRINTEN (1<<5) /* Async IR wake interrupt enable */
134#define UCR3_AWAKEN (1<<4) /* Async wake interrupt enable */
Sascha Hauer8c8fdbc2009-04-01 12:40:15 +0200135#ifdef CONFIG_ARCH_MX1
Marc Kleine-Budde44118052008-07-28 12:10:34 +0200136#define UCR3_REF25 (1<<3) /* Ref freq 25 MHz, only on mx1 */
137#define UCR3_REF30 (1<<2) /* Ref Freq 30 MHz, only on mx1 */
138#endif
139#if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3
140#define UCR3_RXDMUXSEL (1<<2) /* RXD Muxed Input Select, on mx2/mx3 */
141#endif
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100142#define UCR3_INVT (1<<1) /* Inverted Infrared transmission */
143#define UCR3_BPEN (1<<0) /* Preset registers enable */
144#define UCR4_CTSTL_32 (32<<10) /* CTS trigger level (32 chars) */
145#define UCR4_INVR (1<<9) /* Inverted infrared reception */
146#define UCR4_ENIRI (1<<8) /* Serial infrared interrupt enable */
147#define UCR4_WKEN (1<<7) /* Wake interrupt enable */
148#define UCR4_REF16 (1<<6) /* Ref freq 16 MHz */
149#define UCR4_IRSC (1<<5) /* IR special case */
150#define UCR4_TCEN (1<<3) /* Transmit complete interrupt enable */
151#define UCR4_BKEN (1<<2) /* Break condition interrupt enable */
152#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */
153#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
154#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
155#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100156#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7)
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100157#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */
158#define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */
159#define USR1_RTSS (1<<14) /* RTS pin status */
160#define USR1_TRDY (1<<13) /* Transmitter ready interrupt/dma flag */
161#define USR1_RTSD (1<<12) /* RTS delta */
162#define USR1_ESCF (1<<11) /* Escape seq interrupt flag */
163#define USR1_FRAMERR (1<<10) /* Frame error interrupt flag */
164#define USR1_RRDY (1<<9) /* Receiver ready interrupt/dma flag */
165#define USR1_TIMEOUT (1<<7) /* Receive timeout interrupt status */
166#define USR1_RXDS (1<<6) /* Receiver idle interrupt flag */
167#define USR1_AIRINT (1<<5) /* Async IR wake interrupt flag */
168#define USR1_AWAKE (1<<4) /* Aysnc wake interrupt flag */
169#define USR2_ADET (1<<15) /* Auto baud rate detect complete */
170#define USR2_TXFE (1<<14) /* Transmit buffer FIFO empty */
171#define USR2_DTRF (1<<13) /* DTR edge interrupt flag */
172#define USR2_IDLE (1<<12) /* Idle condition */
173#define USR2_IRINT (1<<8) /* Serial infrared interrupt flag */
174#define USR2_WAKE (1<<7) /* Wake */
175#define USR2_RTSF (1<<4) /* RTS edge interrupt flag */
176#define USR2_TXDC (1<<3) /* Transmitter complete */
177#define USR2_BRCD (1<<2) /* Break condition */
178#define USR2_ORE (1<<1) /* Overrun error */
179#define USR2_RDR (1<<0) /* Recv data ready */
180#define UTS_FRCPERR (1<<13) /* Force parity error */
181#define UTS_LOOP (1<<12) /* Loop tx and rx */
182#define UTS_TXEMPTY (1<<6) /* TxFIFO empty */
183#define UTS_RXEMPTY (1<<5) /* RxFIFO empty */
184#define UTS_TXFULL (1<<4) /* TxFIFO full */
185#define UTS_RXFULL (1<<3) /* RxFIFO full */
186#define UTS_SOFTRST (1<<0) /* Software reset */
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/* We've been assigned a range on the "Low-density serial ports" major */
Paulius Zaleckasbd006a92008-11-14 11:01:39 +0100189#ifdef CONFIG_ARCH_MXC
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200190#define SERIAL_IMX_MAJOR 207
191#define MINOR_START 16
192#define DEV_NAME "ttymxc"
Sascha Hauer9d631b82008-12-18 11:08:55 +0100193#define MAX_INTERNAL_IRQ MXC_INTERNAL_IRQS
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200194#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 * This determines how often we check the modem status signals
198 * for any change. They generally aren't connected to an IRQ
199 * so we have to poll them. We also check immediately before
200 * filling the TX fifo incase CTS has been dropped.
201 */
202#define MCTRL_TIMEOUT (250*HZ/1000)
203
204#define DRIVER_NAME "IMX-uart"
205
Sascha Hauerdbff4e92008-07-05 10:02:45 +0200206#define UART_NR 8
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208struct imx_port {
209 struct uart_port port;
210 struct timer_list timer;
211 unsigned int old_status;
Sascha Hauer5b802342006-05-04 14:07:42 +0100212 int txirq,rxirq,rtsirq;
Daniel Glöckner26bbb3f2009-06-11 14:36:29 +0100213 unsigned int have_rtscts:1;
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100214 unsigned int use_irda:1;
215 unsigned int irda_inv_rx:1;
216 unsigned int irda_inv_tx:1;
217 unsigned short trcv_delay; /* transceiver delay */
Sascha Hauer38a41fd2008-07-05 10:02:46 +0200218 struct clk *clk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100221#ifdef CONFIG_IRDA
222#define USE_IRDA(sport) ((sport)->use_irda)
223#else
224#define USE_IRDA(sport) (0)
225#endif
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/*
228 * Handle any change of modem status signal since we were last called.
229 */
230static void imx_mctrl_check(struct imx_port *sport)
231{
232 unsigned int status, changed;
233
234 status = sport->port.ops->get_mctrl(&sport->port);
235 changed = status ^ sport->old_status;
236
237 if (changed == 0)
238 return;
239
240 sport->old_status = status;
241
242 if (changed & TIOCM_RI)
243 sport->port.icount.rng++;
244 if (changed & TIOCM_DSR)
245 sport->port.icount.dsr++;
246 if (changed & TIOCM_CAR)
247 uart_handle_dcd_change(&sport->port, status & TIOCM_CAR);
248 if (changed & TIOCM_CTS)
249 uart_handle_cts_change(&sport->port, status & TIOCM_CTS);
250
251 wake_up_interruptible(&sport->port.info->delta_msr_wait);
252}
253
254/*
255 * This is our per-port timeout handler, for checking the
256 * modem status signals.
257 */
258static void imx_timeout(unsigned long data)
259{
260 struct imx_port *sport = (struct imx_port *)data;
261 unsigned long flags;
262
263 if (sport->port.info) {
264 spin_lock_irqsave(&sport->port.lock, flags);
265 imx_mctrl_check(sport);
266 spin_unlock_irqrestore(&sport->port.lock, flags);
267
268 mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT);
269 }
270}
271
272/*
273 * interrupts disabled on entry
274 */
Russell Kingb129a8c2005-08-31 10:12:14 +0100275static void imx_stop_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
277 struct imx_port *sport = (struct imx_port *)port;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100278 unsigned long temp;
279
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100280 if (USE_IRDA(sport)) {
281 /* half duplex - wait for end of transmission */
282 int n = 256;
283 while ((--n > 0) &&
284 !(readl(sport->port.membase + USR2) & USR2_TXDC)) {
285 udelay(5);
286 barrier();
287 }
288 /*
289 * irda transceiver - wait a bit more to avoid
290 * cutoff, hardware dependent
291 */
292 udelay(sport->trcv_delay);
293
294 /*
295 * half duplex - reactivate receive mode,
296 * flush receive pipe echo crap
297 */
298 if (readl(sport->port.membase + USR2) & USR2_TXDC) {
299 temp = readl(sport->port.membase + UCR1);
300 temp &= ~(UCR1_TXMPTYEN | UCR1_TRDYEN);
301 writel(temp, sport->port.membase + UCR1);
302
303 temp = readl(sport->port.membase + UCR4);
304 temp &= ~(UCR4_TCEN);
305 writel(temp, sport->port.membase + UCR4);
306
307 while (readl(sport->port.membase + URXD0) &
308 URXD_CHARRDY)
309 barrier();
310
311 temp = readl(sport->port.membase + UCR1);
312 temp |= UCR1_RRDYEN;
313 writel(temp, sport->port.membase + UCR1);
314
315 temp = readl(sport->port.membase + UCR4);
316 temp |= UCR4_DREN;
317 writel(temp, sport->port.membase + UCR4);
318 }
319 return;
320 }
321
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100322 temp = readl(sport->port.membase + UCR1);
323 writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
326/*
327 * interrupts disabled on entry
328 */
329static void imx_stop_rx(struct uart_port *port)
330{
331 struct imx_port *sport = (struct imx_port *)port;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100332 unsigned long temp;
333
334 temp = readl(sport->port.membase + UCR2);
335 writel(temp &~ UCR2_RXEN, sport->port.membase + UCR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338/*
339 * Set the modem control timer to fire immediately.
340 */
341static void imx_enable_ms(struct uart_port *port)
342{
343 struct imx_port *sport = (struct imx_port *)port;
344
345 mod_timer(&sport->timer, jiffies);
346}
347
348static inline void imx_transmit_buffer(struct imx_port *sport)
349{
350 struct circ_buf *xmit = &sport->port.info->xmit;
351
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100352 while (!(readl(sport->port.membase + UTS) & UTS_TXFULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 /* send xmit->buf[xmit->tail]
354 * out the port here */
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100355 writel(xmit->buf[xmit->tail], sport->port.membase + URTX0);
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100356 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 sport->port.icount.tx++;
358 if (uart_circ_empty(xmit))
359 break;
Sascha Hauer8c0b2542007-02-05 16:10:16 -0800360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Fabian Godehardt977757312009-06-11 14:37:19 +0100362 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
363 uart_write_wakeup(&sport->port);
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (uart_circ_empty(xmit))
Russell Kingb129a8c2005-08-31 10:12:14 +0100366 imx_stop_tx(&sport->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
368
369/*
370 * interrupts disabled on entry
371 */
Russell Kingb129a8c2005-08-31 10:12:14 +0100372static void imx_start_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 struct imx_port *sport = (struct imx_port *)port;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100375 unsigned long temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100377 if (USE_IRDA(sport)) {
378 /* half duplex in IrDA mode; have to disable receive mode */
379 temp = readl(sport->port.membase + UCR4);
380 temp &= ~(UCR4_DREN);
381 writel(temp, sport->port.membase + UCR4);
382
383 temp = readl(sport->port.membase + UCR1);
384 temp &= ~(UCR1_RRDYEN);
385 writel(temp, sport->port.membase + UCR1);
386 }
387
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100388 temp = readl(sport->port.membase + UCR1);
389 writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100391 if (USE_IRDA(sport)) {
392 temp = readl(sport->port.membase + UCR1);
393 temp |= UCR1_TRDYEN;
394 writel(temp, sport->port.membase + UCR1);
395
396 temp = readl(sport->port.membase + UCR4);
397 temp |= UCR4_TCEN;
398 writel(temp, sport->port.membase + UCR4);
399 }
400
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100401 if (readl(sport->port.membase + UTS) & UTS_TXEMPTY)
402 imx_transmit_buffer(sport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
David Howells7d12e782006-10-05 14:55:46 +0100405static irqreturn_t imx_rtsint(int irq, void *dev_id)
Sascha Hauerceca6292005-10-12 19:58:08 +0100406{
Jeff Garzik15aafa22008-02-06 01:36:20 -0800407 struct imx_port *sport = dev_id;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100408 unsigned int val = readl(sport->port.membase + USR1) & USR1_RTSS;
Sascha Hauerceca6292005-10-12 19:58:08 +0100409 unsigned long flags;
410
411 spin_lock_irqsave(&sport->port.lock, flags);
412
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100413 writel(USR1_RTSD, sport->port.membase + USR1);
Sascha Hauerceca6292005-10-12 19:58:08 +0100414 uart_handle_cts_change(&sport->port, !!val);
415 wake_up_interruptible(&sport->port.info->delta_msr_wait);
416
417 spin_unlock_irqrestore(&sport->port.lock, flags);
418 return IRQ_HANDLED;
419}
420
David Howells7d12e782006-10-05 14:55:46 +0100421static irqreturn_t imx_txint(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Jeff Garzik15aafa22008-02-06 01:36:20 -0800423 struct imx_port *sport = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 struct circ_buf *xmit = &sport->port.info->xmit;
425 unsigned long flags;
426
427 spin_lock_irqsave(&sport->port.lock,flags);
428 if (sport->port.x_char)
429 {
430 /* Send next char */
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100431 writel(sport->port.x_char, sport->port.membase + URTX0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 goto out;
433 }
434
435 if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) {
Russell Kingb129a8c2005-08-31 10:12:14 +0100436 imx_stop_tx(&sport->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 goto out;
438 }
439
440 imx_transmit_buffer(sport);
441
442 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
443 uart_write_wakeup(&sport->port);
444
445out:
446 spin_unlock_irqrestore(&sport->port.lock,flags);
447 return IRQ_HANDLED;
448}
449
David Howells7d12e782006-10-05 14:55:46 +0100450static irqreturn_t imx_rxint(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 struct imx_port *sport = dev_id;
453 unsigned int rx,flg,ignored = 0;
Takashi Iwaia88487c2008-07-16 21:54:42 +0100454 struct tty_struct *tty = sport->port.info->port.tty;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100455 unsigned long flags, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 spin_lock_irqsave(&sport->port.lock,flags);
458
Sascha Hauer0d3c3932008-04-17 08:43:14 +0100459 while (readl(sport->port.membase + USR2) & USR2_RDR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 flg = TTY_NORMAL;
461 sport->port.icount.rx++;
462
Sascha Hauer0d3c3932008-04-17 08:43:14 +0100463 rx = readl(sport->port.membase + URXD0);
464
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100465 temp = readl(sport->port.membase + USR2);
Sascha Hauer864eeed2008-04-17 08:39:22 +0100466 if (temp & USR2_BRCD) {
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100467 writel(temp | USR2_BRCD, sport->port.membase + USR2);
Sascha Hauer864eeed2008-04-17 08:39:22 +0100468 if (uart_handle_break(&sport->port))
469 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 }
471
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100472 if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
Sascha Hauer864eeed2008-04-17 08:39:22 +0100473 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Sascha Hauer864eeed2008-04-17 08:39:22 +0100475 if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) {
476 if (rx & URXD_PRERR)
477 sport->port.icount.parity++;
478 else if (rx & URXD_FRMERR)
479 sport->port.icount.frame++;
480 if (rx & URXD_OVRRUN)
481 sport->port.icount.overrun++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Sascha Hauer864eeed2008-04-17 08:39:22 +0100483 if (rx & sport->port.ignore_status_mask) {
484 if (++ignored > 100)
485 goto out;
486 continue;
487 }
488
489 rx &= sport->port.read_status_mask;
490
491 if (rx & URXD_PRERR)
492 flg = TTY_PARITY;
493 else if (rx & URXD_FRMERR)
494 flg = TTY_FRAME;
495 if (rx & URXD_OVRRUN)
496 flg = TTY_OVERRUN;
497
498#ifdef SUPPORT_SYSRQ
499 sport->port.sysrq = 0;
500#endif
501 }
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 tty_insert_flip_char(tty, rx, flg);
Sascha Hauer864eeed2008-04-17 08:39:22 +0100504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506out:
507 spin_unlock_irqrestore(&sport->port.lock,flags);
508 tty_flip_buffer_push(tty);
509 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
511
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200512static irqreturn_t imx_int(int irq, void *dev_id)
513{
514 struct imx_port *sport = dev_id;
515 unsigned int sts;
516
517 sts = readl(sport->port.membase + USR1);
518
519 if (sts & USR1_RRDY)
520 imx_rxint(irq, dev_id);
521
522 if (sts & USR1_TRDY &&
523 readl(sport->port.membase + UCR1) & UCR1_TXMPTYEN)
524 imx_txint(irq, dev_id);
525
Marc Kleine-Budde9fbe6042008-07-28 21:26:01 +0200526 if (sts & USR1_RTSD)
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200527 imx_rtsint(irq, dev_id);
528
529 return IRQ_HANDLED;
530}
531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532/*
533 * Return TIOCSER_TEMT when transmitter is not busy.
534 */
535static unsigned int imx_tx_empty(struct uart_port *port)
536{
537 struct imx_port *sport = (struct imx_port *)port;
538
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100539 return (readl(sport->port.membase + USR2) & USR2_TXDC) ? TIOCSER_TEMT : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
Sascha Hauer0f302dc2005-08-31 21:48:47 +0100542/*
543 * We have a modem side uart, so the meanings of RTS and CTS are inverted.
544 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545static unsigned int imx_get_mctrl(struct uart_port *port)
546{
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100547 struct imx_port *sport = (struct imx_port *)port;
548 unsigned int tmp = TIOCM_DSR | TIOCM_CAR;
Sascha Hauer0f302dc2005-08-31 21:48:47 +0100549
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100550 if (readl(sport->port.membase + USR1) & USR1_RTSS)
551 tmp |= TIOCM_CTS;
Sascha Hauer0f302dc2005-08-31 21:48:47 +0100552
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100553 if (readl(sport->port.membase + UCR2) & UCR2_CTS)
554 tmp |= TIOCM_RTS;
Sascha Hauer0f302dc2005-08-31 21:48:47 +0100555
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100556 return tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
559static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl)
560{
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100561 struct imx_port *sport = (struct imx_port *)port;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100562 unsigned long temp;
563
564 temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS;
Sascha Hauer0f302dc2005-08-31 21:48:47 +0100565
Oskar Schirmerd3810cd2009-06-11 14:35:01 +0100566 if (mctrl & TIOCM_RTS)
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100567 temp |= UCR2_CTS;
568
569 writel(temp, sport->port.membase + UCR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
572/*
573 * Interrupts always disabled.
574 */
575static void imx_break_ctl(struct uart_port *port, int break_state)
576{
577 struct imx_port *sport = (struct imx_port *)port;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100578 unsigned long flags, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 spin_lock_irqsave(&sport->port.lock, flags);
581
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100582 temp = readl(sport->port.membase + UCR1) & ~UCR1_SNDBRK;
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if ( break_state != 0 )
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100585 temp |= UCR1_SNDBRK;
586
587 writel(temp, sport->port.membase + UCR1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 spin_unlock_irqrestore(&sport->port.lock, flags);
590}
591
592#define TXTL 2 /* reset default */
593#define RXTL 1 /* reset default */
594
Sascha Hauer587897f2005-04-29 22:46:40 +0100595static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
596{
597 unsigned int val;
598 unsigned int ufcr_rfdiv;
599
600 /* set receiver / transmitter trigger level.
601 * RFDIV is set such way to satisfy requested uartclk value
602 */
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100603 val = TXTL << 10 | RXTL;
Sascha Hauer38a41fd2008-07-05 10:02:46 +0200604 ufcr_rfdiv = (clk_get_rate(sport->clk) + sport->port.uartclk / 2)
605 / sport->port.uartclk;
Sascha Hauer587897f2005-04-29 22:46:40 +0100606
607 if(!ufcr_rfdiv)
608 ufcr_rfdiv = 1;
609
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100610 val |= UFCR_RFDIV_REG(ufcr_rfdiv);
Sascha Hauer587897f2005-04-29 22:46:40 +0100611
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100612 writel(val, sport->port.membase + UFCR);
Sascha Hauer587897f2005-04-29 22:46:40 +0100613
614 return 0;
615}
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617static int imx_startup(struct uart_port *port)
618{
619 struct imx_port *sport = (struct imx_port *)port;
620 int retval;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100621 unsigned long flags, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Sascha Hauer587897f2005-04-29 22:46:40 +0100623 imx_setup_ufcr(sport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 /* disable the DREN bit (Data Ready interrupt enable) before
626 * requesting IRQs
627 */
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100628 temp = readl(sport->port.membase + UCR4);
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100629
630 if (USE_IRDA(sport))
631 temp |= UCR4_IRSC;
632
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100633 writel(temp & ~UCR4_DREN, sport->port.membase + UCR4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100635 if (USE_IRDA(sport)) {
636 /* reset fifo's and state machines */
637 int i = 100;
638 temp = readl(sport->port.membase + UCR2);
639 temp &= ~UCR2_SRST;
640 writel(temp, sport->port.membase + UCR2);
641 while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) &&
642 (--i > 0)) {
643 udelay(1);
644 }
645 }
646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 /*
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200648 * Allocate the IRQ(s) i.MX1 has three interrupts whereas later
649 * chips only have one interrupt.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 */
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200651 if (sport->txirq > 0) {
652 retval = request_irq(sport->rxirq, imx_rxint, 0,
653 DRIVER_NAME, sport);
654 if (retval)
655 goto error_out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200657 retval = request_irq(sport->txirq, imx_txint, 0,
658 DRIVER_NAME, sport);
659 if (retval)
660 goto error_out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100662 /* do not use RTS IRQ on IrDA */
663 if (!USE_IRDA(sport)) {
664 retval = request_irq(sport->rtsirq, imx_rtsint,
665 (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 :
666 IRQF_TRIGGER_FALLING |
667 IRQF_TRIGGER_RISING,
668 DRIVER_NAME, sport);
669 if (retval)
670 goto error_out3;
671 }
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200672 } else {
673 retval = request_irq(sport->port.irq, imx_int, 0,
674 DRIVER_NAME, sport);
675 if (retval) {
676 free_irq(sport->port.irq, sport);
677 goto error_out1;
678 }
679 }
Sascha Hauerceca6292005-10-12 19:58:08 +0100680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 /*
682 * Finally, clear and enable interrupts
683 */
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100684 writel(USR1_RTSD, sport->port.membase + USR1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100686 temp = readl(sport->port.membase + UCR1);
Sascha Hauer789d5252008-04-17 08:44:47 +0100687 temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN;
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100688
689 if (USE_IRDA(sport)) {
690 temp |= UCR1_IREN;
691 temp &= ~(UCR1_RTSDEN);
692 }
693
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100694 writel(temp, sport->port.membase + UCR1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100696 temp = readl(sport->port.membase + UCR2);
697 temp |= (UCR2_RXEN | UCR2_TXEN);
698 writel(temp, sport->port.membase + UCR2);
699
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100700 if (USE_IRDA(sport)) {
701 /* clear RX-FIFO */
702 int i = 64;
703 while ((--i > 0) &&
704 (readl(sport->port.membase + URXD0) & URXD_CHARRDY)) {
705 barrier();
706 }
707 }
708
Marc Kleine-Budde44118052008-07-28 12:10:34 +0200709#if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3
710 temp = readl(sport->port.membase + UCR3);
711 temp |= UCR3_RXDMUXSEL;
712 writel(temp, sport->port.membase + UCR3);
713#endif
714
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100715 if (USE_IRDA(sport)) {
716 temp = readl(sport->port.membase + UCR4);
717 if (sport->irda_inv_rx)
718 temp |= UCR4_INVR;
719 else
720 temp &= ~(UCR4_INVR);
721 writel(temp | UCR4_DREN, sport->port.membase + UCR4);
722
723 temp = readl(sport->port.membase + UCR3);
724 if (sport->irda_inv_tx)
725 temp |= UCR3_INVT;
726 else
727 temp &= ~(UCR3_INVT);
728 writel(temp, sport->port.membase + UCR3);
729 }
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 /*
732 * Enable modem status interrupts
733 */
734 spin_lock_irqsave(&sport->port.lock,flags);
735 imx_enable_ms(&sport->port);
736 spin_unlock_irqrestore(&sport->port.lock,flags);
737
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100738 if (USE_IRDA(sport)) {
739 struct imxuart_platform_data *pdata;
740 pdata = sport->port.dev->platform_data;
741 sport->irda_inv_rx = pdata->irda_inv_rx;
742 sport->irda_inv_tx = pdata->irda_inv_tx;
743 sport->trcv_delay = pdata->transceiver_delay;
744 if (pdata->irda_enable)
745 pdata->irda_enable(1);
746 }
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 return 0;
749
Sascha Hauerceca6292005-10-12 19:58:08 +0100750error_out3:
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200751 if (sport->txirq)
752 free_irq(sport->txirq, sport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753error_out2:
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200754 if (sport->rxirq)
755 free_irq(sport->rxirq, sport);
Sascha Hauer86371d02005-10-10 10:17:42 +0100756error_out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 return retval;
758}
759
760static void imx_shutdown(struct uart_port *port)
761{
762 struct imx_port *sport = (struct imx_port *)port;
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100763 unsigned long temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Fabian Godehardt2e146392009-06-11 14:38:38 +0100765 temp = readl(sport->port.membase + UCR2);
766 temp &= ~(UCR2_TXEN);
767 writel(temp, sport->port.membase + UCR2);
768
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100769 if (USE_IRDA(sport)) {
770 struct imxuart_platform_data *pdata;
771 pdata = sport->port.dev->platform_data;
772 if (pdata->irda_enable)
773 pdata->irda_enable(0);
774 }
775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 /*
777 * Stop our timer.
778 */
779 del_timer_sync(&sport->timer);
780
781 /*
782 * Free the interrupts
783 */
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200784 if (sport->txirq > 0) {
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100785 if (!USE_IRDA(sport))
786 free_irq(sport->rtsirq, sport);
Sascha Hauere3d13ff2008-07-05 10:02:48 +0200787 free_irq(sport->txirq, sport);
788 free_irq(sport->rxirq, sport);
789 } else
790 free_irq(sport->port.irq, sport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 /*
793 * Disable all interrupts, port and break condition.
794 */
795
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100796 temp = readl(sport->port.membase + UCR1);
797 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN);
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100798 if (USE_IRDA(sport))
799 temp &= ~(UCR1_IREN);
800
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100801 writel(temp, sport->port.membase + UCR1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802}
803
804static void
Alan Cox606d0992006-12-08 02:38:45 -0800805imx_set_termios(struct uart_port *port, struct ktermios *termios,
806 struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
808 struct imx_port *sport = (struct imx_port *)port;
809 unsigned long flags;
810 unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
811 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
Oskar Schirmer534fca02009-06-11 14:52:23 +0100812 unsigned int div, ufcr;
813 unsigned long num, denom;
Oskar Schirmerd7f8d432009-06-11 14:55:22 +0100814 uint64_t tdiv64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 /*
817 * If we don't support modem control lines, don't allow
818 * these to be set.
819 */
820 if (0) {
821 termios->c_cflag &= ~(HUPCL | CRTSCTS | CMSPAR);
822 termios->c_cflag |= CLOCAL;
823 }
824
825 /*
826 * We only support CS7 and CS8.
827 */
828 while ((termios->c_cflag & CSIZE) != CS7 &&
829 (termios->c_cflag & CSIZE) != CS8) {
830 termios->c_cflag &= ~CSIZE;
831 termios->c_cflag |= old_csize;
832 old_csize = CS8;
833 }
834
835 if ((termios->c_cflag & CSIZE) == CS8)
836 ucr2 = UCR2_WS | UCR2_SRST | UCR2_IRTS;
837 else
838 ucr2 = UCR2_SRST | UCR2_IRTS;
839
840 if (termios->c_cflag & CRTSCTS) {
Sascha Hauer5b802342006-05-04 14:07:42 +0100841 if( sport->have_rtscts ) {
842 ucr2 &= ~UCR2_IRTS;
843 ucr2 |= UCR2_CTSC;
844 } else {
845 termios->c_cflag &= ~CRTSCTS;
846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848
849 if (termios->c_cflag & CSTOPB)
850 ucr2 |= UCR2_STPB;
851 if (termios->c_cflag & PARENB) {
852 ucr2 |= UCR2_PREN;
Matt Reimer3261e362006-01-13 20:51:44 +0000853 if (termios->c_cflag & PARODD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 ucr2 |= UCR2_PROE;
855 }
856
857 /*
858 * Ask the core to calculate the divisor for us.
859 */
Sascha Hauer036bb152008-07-05 10:02:44 +0200860 baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 quot = uart_get_divisor(port, baud);
862
863 spin_lock_irqsave(&sport->port.lock, flags);
864
865 sport->port.read_status_mask = 0;
866 if (termios->c_iflag & INPCK)
867 sport->port.read_status_mask |= (URXD_FRMERR | URXD_PRERR);
868 if (termios->c_iflag & (BRKINT | PARMRK))
869 sport->port.read_status_mask |= URXD_BRK;
870
871 /*
872 * Characters to ignore
873 */
874 sport->port.ignore_status_mask = 0;
875 if (termios->c_iflag & IGNPAR)
876 sport->port.ignore_status_mask |= URXD_PRERR;
877 if (termios->c_iflag & IGNBRK) {
878 sport->port.ignore_status_mask |= URXD_BRK;
879 /*
880 * If we're ignoring parity and break indicators,
881 * ignore overruns too (for real raw support).
882 */
883 if (termios->c_iflag & IGNPAR)
884 sport->port.ignore_status_mask |= URXD_OVRRUN;
885 }
886
887 del_timer_sync(&sport->timer);
888
889 /*
890 * Update the per-port timeout.
891 */
892 uart_update_timeout(port, termios->c_cflag, baud);
893
894 /*
895 * disable interrupts and drain transmitter
896 */
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100897 old_ucr1 = readl(sport->port.membase + UCR1);
898 writel(old_ucr1 & ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN),
899 sport->port.membase + UCR1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100901 while ( !(readl(sport->port.membase + USR2) & USR2_TXDC))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 barrier();
903
904 /* then, disable everything */
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100905 old_txrxen = readl(sport->port.membase + UCR2);
906 writel(old_txrxen & ~( UCR2_TXEN | UCR2_RXEN),
907 sport->port.membase + UCR2);
908 old_txrxen &= (UCR2_TXEN | UCR2_RXEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100910 if (USE_IRDA(sport)) {
911 /*
912 * use maximum available submodule frequency to
913 * avoid missing short pulses due to low sampling rate
914 */
Sascha Hauer036bb152008-07-05 10:02:44 +0200915 div = 1;
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100916 } else {
917 div = sport->port.uartclk / (baud * 16);
918 if (div > 7)
919 div = 7;
920 if (!div)
921 div = 1;
922 }
Sascha Hauer036bb152008-07-05 10:02:44 +0200923
Oskar Schirmer534fca02009-06-11 14:52:23 +0100924 rational_best_approximation(16 * div * baud, sport->port.uartclk,
925 1 << 16, 1 << 16, &num, &denom);
Sascha Hauer036bb152008-07-05 10:02:44 +0200926
Sascha Hauer1a2c4b32009-06-16 17:02:15 +0100927 if (port->info && port->info->port.tty) {
928 tdiv64 = sport->port.uartclk;
929 tdiv64 *= num;
930 do_div(tdiv64, denom * 16 * div);
931 tty_encode_baud_rate(sport->port.info->port.tty,
932 (speed_t)tdiv64, (speed_t)tdiv64);
933 }
Oskar Schirmerd7f8d432009-06-11 14:55:22 +0100934
Oskar Schirmer534fca02009-06-11 14:52:23 +0100935 num -= 1;
936 denom -= 1;
Sascha Hauer036bb152008-07-05 10:02:44 +0200937
938 ufcr = readl(sport->port.membase + UFCR);
Fabian Godehardtb6e49132009-06-11 14:53:18 +0100939 ufcr = (ufcr & (~UFCR_RFDIV)) | UFCR_RFDIV_REG(div);
Sascha Hauer036bb152008-07-05 10:02:44 +0200940 writel(ufcr, sport->port.membase + UFCR);
941
Oskar Schirmer534fca02009-06-11 14:52:23 +0100942 writel(num, sport->port.membase + UBIR);
943 writel(denom, sport->port.membase + UBMR);
944
Sascha Hauer036bb152008-07-05 10:02:44 +0200945#ifdef ONEMS
946 writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
947#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Sascha Hauerff4bfb22007-04-26 08:26:13 +0100949 writel(old_ucr1, sport->port.membase + UCR1);
950
951 /* set the parity, stop bits and data size */
952 writel(ucr2 | old_txrxen, sport->port.membase + UCR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 if (UART_ENABLE_MS(&sport->port, termios->c_cflag))
955 imx_enable_ms(&sport->port);
956
957 spin_unlock_irqrestore(&sport->port.lock, flags);
958}
959
960static const char *imx_type(struct uart_port *port)
961{
962 struct imx_port *sport = (struct imx_port *)port;
963
964 return sport->port.type == PORT_IMX ? "IMX" : NULL;
965}
966
967/*
968 * Release the memory region(s) being used by 'port'.
969 */
970static void imx_release_port(struct uart_port *port)
971{
Sascha Hauer3d454442008-04-17 08:47:32 +0100972 struct platform_device *pdev = to_platform_device(port->dev);
973 struct resource *mmres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Sascha Hauer3d454442008-04-17 08:47:32 +0100975 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
976 release_mem_region(mmres->start, mmres->end - mmres->start + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977}
978
979/*
980 * Request the memory region(s) being used by 'port'.
981 */
982static int imx_request_port(struct uart_port *port)
983{
Sascha Hauer3d454442008-04-17 08:47:32 +0100984 struct platform_device *pdev = to_platform_device(port->dev);
985 struct resource *mmres;
986 void *ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Sascha Hauer3d454442008-04-17 08:47:32 +0100988 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
989 if (!mmres)
990 return -ENODEV;
991
992 ret = request_mem_region(mmres->start, mmres->end - mmres->start + 1,
993 "imx-uart");
994
995 return ret ? 0 : -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
998/*
999 * Configure/autoconfigure the port.
1000 */
1001static void imx_config_port(struct uart_port *port, int flags)
1002{
1003 struct imx_port *sport = (struct imx_port *)port;
1004
1005 if (flags & UART_CONFIG_TYPE &&
1006 imx_request_port(&sport->port) == 0)
1007 sport->port.type = PORT_IMX;
1008}
1009
1010/*
1011 * Verify the new serial_struct (for TIOCSSERIAL).
1012 * The only change we allow are to the flags and type, and
1013 * even then only between PORT_IMX and PORT_UNKNOWN
1014 */
1015static int
1016imx_verify_port(struct uart_port *port, struct serial_struct *ser)
1017{
1018 struct imx_port *sport = (struct imx_port *)port;
1019 int ret = 0;
1020
1021 if (ser->type != PORT_UNKNOWN && ser->type != PORT_IMX)
1022 ret = -EINVAL;
1023 if (sport->port.irq != ser->irq)
1024 ret = -EINVAL;
1025 if (ser->io_type != UPIO_MEM)
1026 ret = -EINVAL;
1027 if (sport->port.uartclk / 16 != ser->baud_base)
1028 ret = -EINVAL;
1029 if ((void *)sport->port.mapbase != ser->iomem_base)
1030 ret = -EINVAL;
1031 if (sport->port.iobase != ser->port)
1032 ret = -EINVAL;
1033 if (ser->hub6 != 0)
1034 ret = -EINVAL;
1035 return ret;
1036}
1037
1038static struct uart_ops imx_pops = {
1039 .tx_empty = imx_tx_empty,
1040 .set_mctrl = imx_set_mctrl,
1041 .get_mctrl = imx_get_mctrl,
1042 .stop_tx = imx_stop_tx,
1043 .start_tx = imx_start_tx,
1044 .stop_rx = imx_stop_rx,
1045 .enable_ms = imx_enable_ms,
1046 .break_ctl = imx_break_ctl,
1047 .startup = imx_startup,
1048 .shutdown = imx_shutdown,
1049 .set_termios = imx_set_termios,
1050 .type = imx_type,
1051 .release_port = imx_release_port,
1052 .request_port = imx_request_port,
1053 .config_port = imx_config_port,
1054 .verify_port = imx_verify_port,
1055};
1056
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001057static struct imx_port *imx_ports[UART_NR];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059#ifdef CONFIG_SERIAL_IMX_CONSOLE
Russell Kingd3587882006-03-20 20:00:09 +00001060static void imx_console_putchar(struct uart_port *port, int ch)
1061{
1062 struct imx_port *sport = (struct imx_port *)port;
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001063
1064 while (readl(sport->port.membase + UTS) & UTS_TXFULL)
Russell Kingd3587882006-03-20 20:00:09 +00001065 barrier();
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001066
1067 writel(ch, sport->port.membase + URTX0);
Russell Kingd3587882006-03-20 20:00:09 +00001068}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070/*
1071 * Interrupts are disabled on entering
1072 */
1073static void
1074imx_console_write(struct console *co, const char *s, unsigned int count)
1075{
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001076 struct imx_port *sport = imx_ports[co->index];
Russell Kingd3587882006-03-20 20:00:09 +00001077 unsigned int old_ucr1, old_ucr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
1079 /*
1080 * First, save UCR1/2 and then disable interrupts
1081 */
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001082 old_ucr1 = readl(sport->port.membase + UCR1);
1083 old_ucr2 = readl(sport->port.membase + UCR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001085 writel((old_ucr1 | UCR1_UARTCLKEN | UCR1_UARTEN) &
1086 ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN),
1087 sport->port.membase + UCR1);
1088
1089 writel(old_ucr2 | UCR2_TXEN, sport->port.membase + UCR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Russell Kingd3587882006-03-20 20:00:09 +00001091 uart_console_write(&sport->port, s, count, imx_console_putchar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 /*
1094 * Finally, wait for transmitter to become empty
1095 * and restore UCR1/2
1096 */
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001097 while (!(readl(sport->port.membase + USR2) & USR2_TXDC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001099 writel(old_ucr1, sport->port.membase + UCR1);
1100 writel(old_ucr2, sport->port.membase + UCR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
1103/*
1104 * If the port was already initialised (eg, by a boot loader),
1105 * try to determine the current setup.
1106 */
1107static void __init
1108imx_console_get_options(struct imx_port *sport, int *baud,
1109 int *parity, int *bits)
1110{
Sascha Hauer587897f2005-04-29 22:46:40 +01001111
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001112 if ( readl(sport->port.membase + UCR1) | UCR1_UARTEN ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 /* ok, the port was enabled */
1114 unsigned int ucr2, ubir,ubmr, uartclk;
Sascha Hauer587897f2005-04-29 22:46:40 +01001115 unsigned int baud_raw;
1116 unsigned int ucfr_rfdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001118 ucr2 = readl(sport->port.membase + UCR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120 *parity = 'n';
1121 if (ucr2 & UCR2_PREN) {
1122 if (ucr2 & UCR2_PROE)
1123 *parity = 'o';
1124 else
1125 *parity = 'e';
1126 }
1127
1128 if (ucr2 & UCR2_WS)
1129 *bits = 8;
1130 else
1131 *bits = 7;
1132
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001133 ubir = readl(sport->port.membase + UBIR) & 0xffff;
1134 ubmr = readl(sport->port.membase + UBMR) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Sascha Hauerff4bfb22007-04-26 08:26:13 +01001136 ucfr_rfdiv = (readl(sport->port.membase + UFCR) & UFCR_RFDIV) >> 7;
Sascha Hauer587897f2005-04-29 22:46:40 +01001137 if (ucfr_rfdiv == 6)
1138 ucfr_rfdiv = 7;
1139 else
1140 ucfr_rfdiv = 6 - ucfr_rfdiv;
1141
Sascha Hauer38a41fd2008-07-05 10:02:46 +02001142 uartclk = clk_get_rate(sport->clk);
Sascha Hauer587897f2005-04-29 22:46:40 +01001143 uartclk /= ucfr_rfdiv;
1144
1145 { /*
1146 * The next code provides exact computation of
1147 * baud_raw = round(((uartclk/16) * (ubir + 1)) / (ubmr + 1))
1148 * without need of float support or long long division,
1149 * which would be required to prevent 32bit arithmetic overflow
1150 */
1151 unsigned int mul = ubir + 1;
1152 unsigned int div = 16 * (ubmr + 1);
1153 unsigned int rem = uartclk % div;
1154
1155 baud_raw = (uartclk / div) * mul;
1156 baud_raw += (rem * mul + div / 2) / div;
1157 *baud = (baud_raw + 50) / 100 * 100;
1158 }
1159
1160 if(*baud != baud_raw)
1161 printk(KERN_INFO "Serial: Console IMX rounded baud rate from %d to %d\n",
1162 baud_raw, *baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164}
1165
1166static int __init
1167imx_console_setup(struct console *co, char *options)
1168{
1169 struct imx_port *sport;
1170 int baud = 9600;
1171 int bits = 8;
1172 int parity = 'n';
1173 int flow = 'n';
1174
1175 /*
1176 * Check whether an invalid uart number has been specified, and
1177 * if so, search for the first available port that does have
1178 * console support.
1179 */
1180 if (co->index == -1 || co->index >= ARRAY_SIZE(imx_ports))
1181 co->index = 0;
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001182 sport = imx_ports[co->index];
Eric Lammertse76afc42009-05-19 20:53:20 -04001183 if(sport == NULL)
1184 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
1186 if (options)
1187 uart_parse_options(options, &baud, &parity, &bits, &flow);
1188 else
1189 imx_console_get_options(sport, &baud, &parity, &bits);
1190
Sascha Hauer587897f2005-04-29 22:46:40 +01001191 imx_setup_ufcr(sport, 0);
1192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 return uart_set_options(&sport->port, co, baud, parity, bits, flow);
1194}
1195
Vincent Sanders9f4426d2005-10-01 22:56:34 +01001196static struct uart_driver imx_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197static struct console imx_console = {
Sascha Hauere3d13ff2008-07-05 10:02:48 +02001198 .name = DEV_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 .write = imx_console_write,
1200 .device = uart_console_device,
1201 .setup = imx_console_setup,
1202 .flags = CON_PRINTBUFFER,
1203 .index = -1,
1204 .data = &imx_reg,
1205};
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207#define IMX_CONSOLE &imx_console
1208#else
1209#define IMX_CONSOLE NULL
1210#endif
1211
1212static struct uart_driver imx_reg = {
1213 .owner = THIS_MODULE,
1214 .driver_name = DRIVER_NAME,
Sascha Hauere3d13ff2008-07-05 10:02:48 +02001215 .dev_name = DEV_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 .major = SERIAL_IMX_MAJOR,
1217 .minor = MINOR_START,
1218 .nr = ARRAY_SIZE(imx_ports),
1219 .cons = IMX_CONSOLE,
1220};
1221
Russell King3ae5eae2005-11-09 22:32:44 +00001222static int serial_imx_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001224 struct imx_port *sport = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001226 if (sport)
1227 uart_suspend_port(&imx_reg, &sport->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001229 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Russell King3ae5eae2005-11-09 22:32:44 +00001232static int serial_imx_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001234 struct imx_port *sport = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001236 if (sport)
1237 uart_resume_port(&imx_reg, &sport->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001239 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001242static int serial_imx_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001244 struct imx_port *sport;
Sascha Hauer5b802342006-05-04 14:07:42 +01001245 struct imxuart_platform_data *pdata;
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001246 void __iomem *base;
1247 int ret = 0;
1248 struct resource *res;
Sascha Hauer5b802342006-05-04 14:07:42 +01001249
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001250 sport = kzalloc(sizeof(*sport), GFP_KERNEL);
1251 if (!sport)
1252 return -ENOMEM;
1253
1254 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1255 if (!res) {
1256 ret = -ENODEV;
1257 goto free;
1258 }
1259
1260 base = ioremap(res->start, PAGE_SIZE);
1261 if (!base) {
1262 ret = -ENOMEM;
1263 goto free;
1264 }
1265
1266 sport->port.dev = &pdev->dev;
1267 sport->port.mapbase = res->start;
1268 sport->port.membase = base;
1269 sport->port.type = PORT_IMX,
1270 sport->port.iotype = UPIO_MEM;
1271 sport->port.irq = platform_get_irq(pdev, 0);
1272 sport->rxirq = platform_get_irq(pdev, 0);
1273 sport->txirq = platform_get_irq(pdev, 1);
1274 sport->rtsirq = platform_get_irq(pdev, 2);
1275 sport->port.fifosize = 32;
1276 sport->port.ops = &imx_pops;
1277 sport->port.flags = UPF_BOOT_AUTOCONF;
1278 sport->port.line = pdev->id;
1279 init_timer(&sport->timer);
1280 sport->timer.function = imx_timeout;
1281 sport->timer.data = (unsigned long)sport;
Sascha Hauer38a41fd2008-07-05 10:02:46 +02001282
Sascha Hauere65fb002009-02-16 14:29:10 +01001283 sport->clk = clk_get(&pdev->dev, "uart");
Sascha Hauer38a41fd2008-07-05 10:02:46 +02001284 if (IS_ERR(sport->clk)) {
1285 ret = PTR_ERR(sport->clk);
1286 goto unmap;
1287 }
1288 clk_enable(sport->clk);
1289
1290 sport->port.uartclk = clk_get_rate(sport->clk);
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001291
1292 imx_ports[pdev->id] = sport;
Sascha Hauer5b802342006-05-04 14:07:42 +01001293
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001294 pdata = pdev->dev.platform_data;
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001295 if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS))
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001296 sport->have_rtscts = 1;
Sascha Hauer5b802342006-05-04 14:07:42 +01001297
Fabian Godehardtb6e49132009-06-11 14:53:18 +01001298#ifdef CONFIG_IRDA
1299 if (pdata && (pdata->flags & IMXUART_IRDA))
1300 sport->use_irda = 1;
1301#endif
1302
Darius Augulisc45e7d72008-09-02 10:19:29 +02001303 if (pdata->init) {
1304 ret = pdata->init(pdev);
1305 if (ret)
1306 goto clkput;
1307 }
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001308
Daniel Glöckner9f322ad2009-06-11 14:39:21 +01001309 ret = uart_add_one_port(&imx_reg, &sport->port);
1310 if (ret)
1311 goto deinit;
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001312 platform_set_drvdata(pdev, &sport->port);
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 return 0;
Daniel Glöckner9f322ad2009-06-11 14:39:21 +01001315deinit:
1316 if (pdata->exit)
1317 pdata->exit(pdev);
Darius Augulisc45e7d72008-09-02 10:19:29 +02001318clkput:
1319 clk_put(sport->clk);
1320 clk_disable(sport->clk);
Sascha Hauer38a41fd2008-07-05 10:02:46 +02001321unmap:
1322 iounmap(sport->port.membase);
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001323free:
1324 kfree(sport);
1325
1326 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
1328
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001329static int serial_imx_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001331 struct imxuart_platform_data *pdata;
1332 struct imx_port *sport = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001334 pdata = pdev->dev.platform_data;
1335
1336 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Sascha Hauer38a41fd2008-07-05 10:02:46 +02001338 if (sport) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 uart_remove_one_port(&imx_reg, &sport->port);
Sascha Hauer38a41fd2008-07-05 10:02:46 +02001340 clk_put(sport->clk);
1341 }
1342
1343 clk_disable(sport->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Sascha Hauer2582d8c2008-07-05 10:02:45 +02001345 if (pdata->exit)
1346 pdata->exit(pdev);
1347
Sascha Hauerdbff4e92008-07-05 10:02:45 +02001348 iounmap(sport->port.membase);
1349 kfree(sport);
1350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 return 0;
1352}
1353
Russell King3ae5eae2005-11-09 22:32:44 +00001354static struct platform_driver serial_imx_driver = {
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001355 .probe = serial_imx_probe,
1356 .remove = serial_imx_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358 .suspend = serial_imx_suspend,
1359 .resume = serial_imx_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001360 .driver = {
Oskar Schirmerd3810cd2009-06-11 14:35:01 +01001361 .name = "imx-uart",
Kay Sieverse169c132008-04-15 14:34:35 -07001362 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +00001363 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364};
1365
1366static int __init imx_serial_init(void)
1367{
1368 int ret;
1369
1370 printk(KERN_INFO "Serial: IMX driver\n");
1371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 ret = uart_register_driver(&imx_reg);
1373 if (ret)
1374 return ret;
1375
Russell King3ae5eae2005-11-09 22:32:44 +00001376 ret = platform_driver_register(&serial_imx_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 if (ret != 0)
1378 uart_unregister_driver(&imx_reg);
1379
1380 return 0;
1381}
1382
1383static void __exit imx_serial_exit(void)
1384{
Russell Kingc889b892005-11-21 17:05:21 +00001385 platform_driver_unregister(&serial_imx_driver);
Sascha Hauer4b300c32007-07-17 13:35:46 +01001386 uart_unregister_driver(&imx_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
1389module_init(imx_serial_init);
1390module_exit(imx_serial_exit);
1391
1392MODULE_AUTHOR("Sascha Hauer");
1393MODULE_DESCRIPTION("IMX generic serial port driver");
1394MODULE_LICENSE("GPL");
Kay Sieverse169c132008-04-15 14:34:35 -07001395MODULE_ALIAS("platform:imx-uart");