2 * linux/drivers/serial/imx.c
4 * Driver for Motorola IMX serial ports
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
8 * Author: Sascha Hauer <sascha@saschahauer.de>
9 * Copyright (C) 2004 Pengutronix
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * [29-Mar-2005] Mike Lee
26 * Added hardware handshake
28 #include <linux/config.h>
30 #if defined(CONFIG_SERIAL_IMX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
34 #include <linux/module.h>
35 #include <linux/ioport.h>
36 #include <linux/init.h>
37 #include <linux/console.h>
38 #include <linux/sysrq.h>
39 #include <linux/platform_device.h>
40 #include <linux/tty.h>
41 #include <linux/tty_flip.h>
42 #include <linux/serial_core.h>
43 #include <linux/serial.h>
47 #include <asm/hardware.h>
48 #include <asm/arch/imx-uart.h>
50 /* We've been assigned a range on the "Low-density serial ports" major */
51 #define SERIAL_IMX_MAJOR 204
52 #define MINOR_START 41
56 #define IMX_ISR_PASS_LIMIT 256
59 * This is the size of our serial port register set.
61 #define UART_PORT_SIZE 0x100
64 * This determines how often we check the modem status signals
65 * for any change. They generally aren't connected to an IRQ
66 * so we have to poll them. We also check immediately before
67 * filling the TX fifo incase CTS has been dropped.
69 #define MCTRL_TIMEOUT (250*HZ/1000)
71 #define DRIVER_NAME "IMX-uart"
74 struct uart_port port
;
75 struct timer_list timer
;
76 unsigned int old_status
;
77 int txirq
,rxirq
,rtsirq
;
82 * Handle any change of modem status signal since we were last called.
84 static void imx_mctrl_check(struct imx_port
*sport
)
86 unsigned int status
, changed
;
88 status
= sport
->port
.ops
->get_mctrl(&sport
->port
);
89 changed
= status
^ sport
->old_status
;
94 sport
->old_status
= status
;
96 if (changed
& TIOCM_RI
)
97 sport
->port
.icount
.rng
++;
98 if (changed
& TIOCM_DSR
)
99 sport
->port
.icount
.dsr
++;
100 if (changed
& TIOCM_CAR
)
101 uart_handle_dcd_change(&sport
->port
, status
& TIOCM_CAR
);
102 if (changed
& TIOCM_CTS
)
103 uart_handle_cts_change(&sport
->port
, status
& TIOCM_CTS
);
105 wake_up_interruptible(&sport
->port
.info
->delta_msr_wait
);
109 * This is our per-port timeout handler, for checking the
110 * modem status signals.
112 static void imx_timeout(unsigned long data
)
114 struct imx_port
*sport
= (struct imx_port
*)data
;
117 if (sport
->port
.info
) {
118 spin_lock_irqsave(&sport
->port
.lock
, flags
);
119 imx_mctrl_check(sport
);
120 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
122 mod_timer(&sport
->timer
, jiffies
+ MCTRL_TIMEOUT
);
127 * interrupts disabled on entry
129 static void imx_stop_tx(struct uart_port
*port
)
131 struct imx_port
*sport
= (struct imx_port
*)port
;
132 UCR1((u32
)sport
->port
.membase
) &= ~UCR1_TXMPTYEN
;
136 * interrupts disabled on entry
138 static void imx_stop_rx(struct uart_port
*port
)
140 struct imx_port
*sport
= (struct imx_port
*)port
;
141 UCR2((u32
)sport
->port
.membase
) &= ~UCR2_RXEN
;
145 * Set the modem control timer to fire immediately.
147 static void imx_enable_ms(struct uart_port
*port
)
149 struct imx_port
*sport
= (struct imx_port
*)port
;
151 mod_timer(&sport
->timer
, jiffies
);
154 static inline void imx_transmit_buffer(struct imx_port
*sport
)
156 struct circ_buf
*xmit
= &sport
->port
.info
->xmit
;
159 /* send xmit->buf[xmit->tail]
160 * out the port here */
161 URTX0((u32
)sport
->port
.membase
) = xmit
->buf
[xmit
->tail
];
162 xmit
->tail
= (xmit
->tail
+ 1) &
163 (UART_XMIT_SIZE
- 1);
164 sport
->port
.icount
.tx
++;
165 if (uart_circ_empty(xmit
))
167 } while (!(UTS((u32
)sport
->port
.membase
) & UTS_TXFULL
));
169 if (uart_circ_empty(xmit
))
170 imx_stop_tx(&sport
->port
);
174 * interrupts disabled on entry
176 static void imx_start_tx(struct uart_port
*port
)
178 struct imx_port
*sport
= (struct imx_port
*)port
;
180 UCR1((u32
)sport
->port
.membase
) |= UCR1_TXMPTYEN
;
182 if(UTS((u32
)sport
->port
.membase
) & UTS_TXEMPTY
)
183 imx_transmit_buffer(sport
);
186 static irqreturn_t
imx_rtsint(int irq
, void *dev_id
, struct pt_regs
*regs
)
188 struct imx_port
*sport
= (struct imx_port
*)dev_id
;
189 unsigned int val
= USR1((u32
)sport
->port
.membase
)&USR1_RTSS
;
192 spin_lock_irqsave(&sport
->port
.lock
, flags
);
194 USR1((u32
)sport
->port
.membase
) = USR1_RTSD
;
195 uart_handle_cts_change(&sport
->port
, !!val
);
196 wake_up_interruptible(&sport
->port
.info
->delta_msr_wait
);
198 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
202 static irqreturn_t
imx_txint(int irq
, void *dev_id
, struct pt_regs
*regs
)
204 struct imx_port
*sport
= (struct imx_port
*)dev_id
;
205 struct circ_buf
*xmit
= &sport
->port
.info
->xmit
;
208 spin_lock_irqsave(&sport
->port
.lock
,flags
);
209 if (sport
->port
.x_char
)
212 URTX0((u32
)sport
->port
.membase
) = sport
->port
.x_char
;
216 if (uart_circ_empty(xmit
) || uart_tx_stopped(&sport
->port
)) {
217 imx_stop_tx(&sport
->port
);
221 imx_transmit_buffer(sport
);
223 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
224 uart_write_wakeup(&sport
->port
);
227 spin_unlock_irqrestore(&sport
->port
.lock
,flags
);
231 static irqreturn_t
imx_rxint(int irq
, void *dev_id
, struct pt_regs
*regs
)
233 struct imx_port
*sport
= dev_id
;
234 unsigned int rx
,flg
,ignored
= 0;
235 struct tty_struct
*tty
= sport
->port
.info
->tty
;
238 rx
= URXD0((u32
)sport
->port
.membase
);
239 spin_lock_irqsave(&sport
->port
.lock
,flags
);
243 sport
->port
.icount
.rx
++;
245 if( USR2((u32
)sport
->port
.membase
) & USR2_BRCD
) {
246 USR2((u32
)sport
->port
.membase
) |= USR2_BRCD
;
247 if(uart_handle_break(&sport
->port
))
251 if (uart_handle_sysrq_char
252 (&sport
->port
, (unsigned char)rx
, regs
))
255 if( rx
& (URXD_PRERR
| URXD_OVRRUN
| URXD_FRMERR
) )
259 tty_insert_flip_char(tty
, rx
, flg
);
262 rx
= URXD0((u32
)sport
->port
.membase
);
263 } while(rx
& URXD_CHARRDY
);
266 spin_unlock_irqrestore(&sport
->port
.lock
,flags
);
267 tty_flip_buffer_push(tty
);
272 sport
->port
.icount
.parity
++;
273 else if (rx
& URXD_FRMERR
)
274 sport
->port
.icount
.frame
++;
275 if (rx
& URXD_OVRRUN
)
276 sport
->port
.icount
.overrun
++;
278 if (rx
& sport
->port
.ignore_status_mask
) {
284 rx
&= sport
->port
.read_status_mask
;
288 else if (rx
& URXD_FRMERR
)
290 if (rx
& URXD_OVRRUN
)
294 sport
->port
.sysrq
= 0;
300 * Return TIOCSER_TEMT when transmitter is not busy.
302 static unsigned int imx_tx_empty(struct uart_port
*port
)
304 struct imx_port
*sport
= (struct imx_port
*)port
;
306 return USR2((u32
)sport
->port
.membase
) & USR2_TXDC
? TIOCSER_TEMT
: 0;
310 * We have a modem side uart, so the meanings of RTS and CTS are inverted.
312 static unsigned int imx_get_mctrl(struct uart_port
*port
)
314 struct imx_port
*sport
= (struct imx_port
*)port
;
315 unsigned int tmp
= TIOCM_DSR
| TIOCM_CAR
;
317 if (USR1((u32
)sport
->port
.membase
) & USR1_RTSS
)
320 if (UCR2((u32
)sport
->port
.membase
) & UCR2_CTS
)
326 static void imx_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
328 struct imx_port
*sport
= (struct imx_port
*)port
;
330 if (mctrl
& TIOCM_RTS
)
331 UCR2((u32
)sport
->port
.membase
) |= UCR2_CTS
;
333 UCR2((u32
)sport
->port
.membase
) &= ~UCR2_CTS
;
337 * Interrupts always disabled.
339 static void imx_break_ctl(struct uart_port
*port
, int break_state
)
341 struct imx_port
*sport
= (struct imx_port
*)port
;
344 spin_lock_irqsave(&sport
->port
.lock
, flags
);
346 if ( break_state
!= 0 )
347 UCR1((u32
)sport
->port
.membase
) |= UCR1_SNDBRK
;
349 UCR1((u32
)sport
->port
.membase
) &= ~UCR1_SNDBRK
;
351 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
354 #define TXTL 2 /* reset default */
355 #define RXTL 1 /* reset default */
357 static int imx_setup_ufcr(struct imx_port
*sport
, unsigned int mode
)
360 unsigned int ufcr_rfdiv
;
362 /* set receiver / transmitter trigger level.
363 * RFDIV is set such way to satisfy requested uartclk value
365 val
= TXTL
<<10 | RXTL
;
366 ufcr_rfdiv
= (imx_get_perclk1() + sport
->port
.uartclk
/ 2) / sport
->port
.uartclk
;
374 ufcr_rfdiv
= 6 - ufcr_rfdiv
;
376 val
|= UFCR_RFDIV
& (ufcr_rfdiv
<< 7);
378 UFCR((u32
)sport
->port
.membase
) = val
;
383 static int imx_startup(struct uart_port
*port
)
385 struct imx_port
*sport
= (struct imx_port
*)port
;
389 imx_setup_ufcr(sport
, 0);
391 /* disable the DREN bit (Data Ready interrupt enable) before
394 UCR4((u32
)sport
->port
.membase
) &= ~UCR4_DREN
;
399 retval
= request_irq(sport
->rxirq
, imx_rxint
, 0,
401 if (retval
) goto error_out1
;
403 retval
= request_irq(sport
->txirq
, imx_txint
, 0,
405 if (retval
) goto error_out2
;
407 retval
= request_irq(sport
->rtsirq
, imx_rtsint
,
408 SA_TRIGGER_FALLING
| SA_TRIGGER_RISING
,
410 if (retval
) goto error_out3
;
413 * Finally, clear and enable interrupts
416 USR1((u32
)sport
->port
.membase
) = USR1_RTSD
;
417 UCR1((u32
)sport
->port
.membase
) |=
418 (UCR1_TXMPTYEN
| UCR1_RRDYEN
| UCR1_RTSDEN
| UCR1_UARTEN
);
420 UCR2((u32
)sport
->port
.membase
) |= (UCR2_RXEN
| UCR2_TXEN
);
422 * Enable modem status interrupts
424 spin_lock_irqsave(&sport
->port
.lock
,flags
);
425 imx_enable_ms(&sport
->port
);
426 spin_unlock_irqrestore(&sport
->port
.lock
,flags
);
431 free_irq(sport
->txirq
, sport
);
433 free_irq(sport
->rxirq
, sport
);
438 static void imx_shutdown(struct uart_port
*port
)
440 struct imx_port
*sport
= (struct imx_port
*)port
;
445 del_timer_sync(&sport
->timer
);
448 * Free the interrupts
450 free_irq(sport
->rtsirq
, sport
);
451 free_irq(sport
->txirq
, sport
);
452 free_irq(sport
->rxirq
, sport
);
455 * Disable all interrupts, port and break condition.
458 UCR1((u32
)sport
->port
.membase
) &=
459 ~(UCR1_TXMPTYEN
| UCR1_RRDYEN
| UCR1_RTSDEN
| UCR1_UARTEN
);
463 imx_set_termios(struct uart_port
*port
, struct termios
*termios
,
466 struct imx_port
*sport
= (struct imx_port
*)port
;
468 unsigned int ucr2
, old_ucr1
, old_txrxen
, baud
, quot
;
469 unsigned int old_csize
= old
? old
->c_cflag
& CSIZE
: CS8
;
472 * If we don't support modem control lines, don't allow
476 termios
->c_cflag
&= ~(HUPCL
| CRTSCTS
| CMSPAR
);
477 termios
->c_cflag
|= CLOCAL
;
481 * We only support CS7 and CS8.
483 while ((termios
->c_cflag
& CSIZE
) != CS7
&&
484 (termios
->c_cflag
& CSIZE
) != CS8
) {
485 termios
->c_cflag
&= ~CSIZE
;
486 termios
->c_cflag
|= old_csize
;
490 if ((termios
->c_cflag
& CSIZE
) == CS8
)
491 ucr2
= UCR2_WS
| UCR2_SRST
| UCR2_IRTS
;
493 ucr2
= UCR2_SRST
| UCR2_IRTS
;
495 if (termios
->c_cflag
& CRTSCTS
) {
496 if( sport
->have_rtscts
) {
500 termios
->c_cflag
&= ~CRTSCTS
;
504 if (termios
->c_cflag
& CSTOPB
)
506 if (termios
->c_cflag
& PARENB
) {
508 if (termios
->c_cflag
& PARODD
)
513 * Ask the core to calculate the divisor for us.
515 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
516 quot
= uart_get_divisor(port
, baud
);
518 spin_lock_irqsave(&sport
->port
.lock
, flags
);
520 sport
->port
.read_status_mask
= 0;
521 if (termios
->c_iflag
& INPCK
)
522 sport
->port
.read_status_mask
|= (URXD_FRMERR
| URXD_PRERR
);
523 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
524 sport
->port
.read_status_mask
|= URXD_BRK
;
527 * Characters to ignore
529 sport
->port
.ignore_status_mask
= 0;
530 if (termios
->c_iflag
& IGNPAR
)
531 sport
->port
.ignore_status_mask
|= URXD_PRERR
;
532 if (termios
->c_iflag
& IGNBRK
) {
533 sport
->port
.ignore_status_mask
|= URXD_BRK
;
535 * If we're ignoring parity and break indicators,
536 * ignore overruns too (for real raw support).
538 if (termios
->c_iflag
& IGNPAR
)
539 sport
->port
.ignore_status_mask
|= URXD_OVRRUN
;
542 del_timer_sync(&sport
->timer
);
545 * Update the per-port timeout.
547 uart_update_timeout(port
, termios
->c_cflag
, baud
);
550 * disable interrupts and drain transmitter
552 old_ucr1
= UCR1((u32
)sport
->port
.membase
);
553 UCR1((u32
)sport
->port
.membase
) &= ~(UCR1_TXMPTYEN
| UCR1_RRDYEN
| UCR1_RTSDEN
);
555 while ( !(USR2((u32
)sport
->port
.membase
) & USR2_TXDC
))
558 /* then, disable everything */
559 old_txrxen
= UCR2((u32
)sport
->port
.membase
) & ( UCR2_TXEN
| UCR2_RXEN
);
560 UCR2((u32
)sport
->port
.membase
) &= ~( UCR2_TXEN
| UCR2_RXEN
);
562 /* set the parity, stop bits and data size */
563 UCR2((u32
)sport
->port
.membase
) = ucr2
;
565 /* set the baud rate. We assume uartclk = 16 MHz
568 * --------- = --------
571 UBIR((u32
)sport
->port
.membase
) = (baud
/ 100) - 1;
572 UBMR((u32
)sport
->port
.membase
) = 10000 - 1;
574 UCR1((u32
)sport
->port
.membase
) = old_ucr1
;
575 UCR2((u32
)sport
->port
.membase
) |= old_txrxen
;
577 if (UART_ENABLE_MS(&sport
->port
, termios
->c_cflag
))
578 imx_enable_ms(&sport
->port
);
580 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
583 static const char *imx_type(struct uart_port
*port
)
585 struct imx_port
*sport
= (struct imx_port
*)port
;
587 return sport
->port
.type
== PORT_IMX
? "IMX" : NULL
;
591 * Release the memory region(s) being used by 'port'.
593 static void imx_release_port(struct uart_port
*port
)
595 struct imx_port
*sport
= (struct imx_port
*)port
;
597 release_mem_region(sport
->port
.mapbase
, UART_PORT_SIZE
);
601 * Request the memory region(s) being used by 'port'.
603 static int imx_request_port(struct uart_port
*port
)
605 struct imx_port
*sport
= (struct imx_port
*)port
;
607 return request_mem_region(sport
->port
.mapbase
, UART_PORT_SIZE
,
608 "imx-uart") != NULL
? 0 : -EBUSY
;
612 * Configure/autoconfigure the port.
614 static void imx_config_port(struct uart_port
*port
, int flags
)
616 struct imx_port
*sport
= (struct imx_port
*)port
;
618 if (flags
& UART_CONFIG_TYPE
&&
619 imx_request_port(&sport
->port
) == 0)
620 sport
->port
.type
= PORT_IMX
;
624 * Verify the new serial_struct (for TIOCSSERIAL).
625 * The only change we allow are to the flags and type, and
626 * even then only between PORT_IMX and PORT_UNKNOWN
629 imx_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
631 struct imx_port
*sport
= (struct imx_port
*)port
;
634 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_IMX
)
636 if (sport
->port
.irq
!= ser
->irq
)
638 if (ser
->io_type
!= UPIO_MEM
)
640 if (sport
->port
.uartclk
/ 16 != ser
->baud_base
)
642 if ((void *)sport
->port
.mapbase
!= ser
->iomem_base
)
644 if (sport
->port
.iobase
!= ser
->port
)
651 static struct uart_ops imx_pops
= {
652 .tx_empty
= imx_tx_empty
,
653 .set_mctrl
= imx_set_mctrl
,
654 .get_mctrl
= imx_get_mctrl
,
655 .stop_tx
= imx_stop_tx
,
656 .start_tx
= imx_start_tx
,
657 .stop_rx
= imx_stop_rx
,
658 .enable_ms
= imx_enable_ms
,
659 .break_ctl
= imx_break_ctl
,
660 .startup
= imx_startup
,
661 .shutdown
= imx_shutdown
,
662 .set_termios
= imx_set_termios
,
664 .release_port
= imx_release_port
,
665 .request_port
= imx_request_port
,
666 .config_port
= imx_config_port
,
667 .verify_port
= imx_verify_port
,
670 static struct imx_port imx_ports
[] = {
672 .txirq
= UART1_MINT_TX
,
673 .rxirq
= UART1_MINT_RX
,
674 .rtsirq
= UART1_MINT_RTS
,
678 .membase
= (void *)IMX_UART1_BASE
,
679 .mapbase
= IMX_UART1_BASE
, /* FIXME */
680 .irq
= UART1_MINT_RX
,
683 .flags
= UPF_BOOT_AUTOCONF
,
688 .txirq
= UART2_MINT_TX
,
689 .rxirq
= UART2_MINT_RX
,
690 .rtsirq
= UART2_MINT_RTS
,
694 .membase
= (void *)IMX_UART2_BASE
,
695 .mapbase
= IMX_UART2_BASE
, /* FIXME */
696 .irq
= UART2_MINT_RX
,
699 .flags
= UPF_BOOT_AUTOCONF
,
707 * Setup the IMX serial ports.
708 * Note also that we support "console=ttySMXx" where "x" is either 0 or 1.
709 * Which serial port this ends up being depends on the machine you're
710 * running this kernel on. I'm not convinced that this is a good idea,
711 * but that's the way it traditionally works.
714 static void __init
imx_init_ports(void)
716 static int first
= 1;
723 for (i
= 0; i
< ARRAY_SIZE(imx_ports
); i
++) {
724 init_timer(&imx_ports
[i
].timer
);
725 imx_ports
[i
].timer
.function
= imx_timeout
;
726 imx_ports
[i
].timer
.data
= (unsigned long)&imx_ports
[i
];
730 #ifdef CONFIG_SERIAL_IMX_CONSOLE
731 static void imx_console_putchar(struct uart_port
*port
, int ch
)
733 struct imx_port
*sport
= (struct imx_port
*)port
;
734 while ((UTS((u32
)sport
->port
.membase
) & UTS_TXFULL
))
736 URTX0((u32
)sport
->port
.membase
) = ch
;
740 * Interrupts are disabled on entering
743 imx_console_write(struct console
*co
, const char *s
, unsigned int count
)
745 struct imx_port
*sport
= &imx_ports
[co
->index
];
746 unsigned int old_ucr1
, old_ucr2
;
749 * First, save UCR1/2 and then disable interrupts
751 old_ucr1
= UCR1((u32
)sport
->port
.membase
);
752 old_ucr2
= UCR2((u32
)sport
->port
.membase
);
754 UCR1((u32
)sport
->port
.membase
) =
755 (old_ucr1
| UCR1_UARTCLKEN
| UCR1_UARTEN
)
756 & ~(UCR1_TXMPTYEN
| UCR1_RRDYEN
| UCR1_RTSDEN
);
757 UCR2((u32
)sport
->port
.membase
) = old_ucr2
| UCR2_TXEN
;
759 uart_console_write(&sport
->port
, s
, count
, imx_console_putchar
);
762 * Finally, wait for transmitter to become empty
765 while (!(USR2((u32
)sport
->port
.membase
) & USR2_TXDC
));
767 UCR1((u32
)sport
->port
.membase
) = old_ucr1
;
768 UCR2((u32
)sport
->port
.membase
) = old_ucr2
;
772 * If the port was already initialised (eg, by a boot loader),
773 * try to determine the current setup.
776 imx_console_get_options(struct imx_port
*sport
, int *baud
,
777 int *parity
, int *bits
)
780 if ( UCR1((u32
)sport
->port
.membase
) | UCR1_UARTEN
) {
781 /* ok, the port was enabled */
782 unsigned int ucr2
, ubir
,ubmr
, uartclk
;
783 unsigned int baud_raw
;
784 unsigned int ucfr_rfdiv
;
786 ucr2
= UCR2((u32
)sport
->port
.membase
);
789 if (ucr2
& UCR2_PREN
) {
790 if (ucr2
& UCR2_PROE
)
801 ubir
= UBIR((u32
)sport
->port
.membase
) & 0xffff;
802 ubmr
= UBMR((u32
)sport
->port
.membase
) & 0xffff;
805 ucfr_rfdiv
= (UFCR((u32
)sport
->port
.membase
) & UFCR_RFDIV
) >> 7;
809 ucfr_rfdiv
= 6 - ucfr_rfdiv
;
811 uartclk
= imx_get_perclk1();
812 uartclk
/= ucfr_rfdiv
;
815 * The next code provides exact computation of
816 * baud_raw = round(((uartclk/16) * (ubir + 1)) / (ubmr + 1))
817 * without need of float support or long long division,
818 * which would be required to prevent 32bit arithmetic overflow
820 unsigned int mul
= ubir
+ 1;
821 unsigned int div
= 16 * (ubmr
+ 1);
822 unsigned int rem
= uartclk
% div
;
824 baud_raw
= (uartclk
/ div
) * mul
;
825 baud_raw
+= (rem
* mul
+ div
/ 2) / div
;
826 *baud
= (baud_raw
+ 50) / 100 * 100;
829 if(*baud
!= baud_raw
)
830 printk(KERN_INFO
"Serial: Console IMX rounded baud rate from %d to %d\n",
836 imx_console_setup(struct console
*co
, char *options
)
838 struct imx_port
*sport
;
845 * Check whether an invalid uart number has been specified, and
846 * if so, search for the first available port that does have
849 if (co
->index
== -1 || co
->index
>= ARRAY_SIZE(imx_ports
))
851 sport
= &imx_ports
[co
->index
];
854 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
856 imx_console_get_options(sport
, &baud
, &parity
, &bits
);
858 imx_setup_ufcr(sport
, 0);
860 return uart_set_options(&sport
->port
, co
, baud
, parity
, bits
, flow
);
863 static struct uart_driver imx_reg
;
864 static struct console imx_console
= {
866 .write
= imx_console_write
,
867 .device
= uart_console_device
,
868 .setup
= imx_console_setup
,
869 .flags
= CON_PRINTBUFFER
,
874 static int __init
imx_rs_console_init(void)
877 register_console(&imx_console
);
880 console_initcall(imx_rs_console_init
);
882 #define IMX_CONSOLE &imx_console
884 #define IMX_CONSOLE NULL
887 static struct uart_driver imx_reg
= {
888 .owner
= THIS_MODULE
,
889 .driver_name
= DRIVER_NAME
,
890 .dev_name
= "ttySMX",
891 .major
= SERIAL_IMX_MAJOR
,
892 .minor
= MINOR_START
,
893 .nr
= ARRAY_SIZE(imx_ports
),
897 static int serial_imx_suspend(struct platform_device
*dev
, pm_message_t state
)
899 struct imx_port
*sport
= platform_get_drvdata(dev
);
902 uart_suspend_port(&imx_reg
, &sport
->port
);
907 static int serial_imx_resume(struct platform_device
*dev
)
909 struct imx_port
*sport
= platform_get_drvdata(dev
);
912 uart_resume_port(&imx_reg
, &sport
->port
);
917 static int serial_imx_probe(struct platform_device
*dev
)
919 struct imxuart_platform_data
*pdata
;
921 imx_ports
[dev
->id
].port
.dev
= &dev
->dev
;
923 pdata
= (struct imxuart_platform_data
*)dev
->dev
.platform_data
;
924 if(pdata
&& (pdata
->flags
& IMXUART_HAVE_RTSCTS
))
925 imx_ports
[dev
->id
].have_rtscts
= 1;
927 uart_add_one_port(&imx_reg
, &imx_ports
[dev
->id
].port
);
928 platform_set_drvdata(dev
, &imx_ports
[dev
->id
]);
932 static int serial_imx_remove(struct platform_device
*dev
)
934 struct imx_port
*sport
= platform_get_drvdata(dev
);
936 platform_set_drvdata(dev
, NULL
);
939 uart_remove_one_port(&imx_reg
, &sport
->port
);
944 static struct platform_driver serial_imx_driver
= {
945 .probe
= serial_imx_probe
,
946 .remove
= serial_imx_remove
,
948 .suspend
= serial_imx_suspend
,
949 .resume
= serial_imx_resume
,
955 static int __init
imx_serial_init(void)
959 printk(KERN_INFO
"Serial: IMX driver\n");
963 ret
= uart_register_driver(&imx_reg
);
967 ret
= platform_driver_register(&serial_imx_driver
);
969 uart_unregister_driver(&imx_reg
);
974 static void __exit
imx_serial_exit(void)
976 uart_unregister_driver(&imx_reg
);
977 platform_driver_unregister(&serial_imx_driver
);
980 module_init(imx_serial_init
);
981 module_exit(imx_serial_exit
);
983 MODULE_AUTHOR("Sascha Hauer");
984 MODULE_DESCRIPTION("IMX generic serial port driver");
985 MODULE_LICENSE("GPL");