1 /****************************************************************************/
4 * mcf.c -- Freescale ColdFire UART driver
6 * (C) Copyright 2003-2006, Greg Ungerer <gerg@snapgear.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 /****************************************************************************/
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/interrupt.h>
19 #include <linux/module.h>
20 #include <linux/console.h>
21 #include <linux/tty.h>
22 #include <linux/tty_flip.h>
23 #include <linux/serial.h>
24 #include <linux/serial_core.h>
26 #include <asm/coldfire.h>
27 #include <asm/mcfsim.h>
28 #include <asm/mcfuart.h>
29 #include <asm/nettel.h>
32 /****************************************************************************/
35 #define dprintk(x...) printk(x)
37 #define dprintk(...) do { } while (0)
40 /****************************************************************************/
43 * On some ColdFire parts the IRQs for serial use are completely
44 * software programmable. On others they are pretty much fixed.
45 * On the programmed CPU's we arbitarily choose 73 (known not to
46 * interfere with anything else programed).
48 #if defined(MCFINT_VECBASE) && defined(MCFINT_UART0)
49 #define IRQBASE (MCFINT_VECBASE + MCFINT_UART0)
55 * Some boards implement the DTR/DCD lines using GPIO lines, most
56 * don't. Dummy out the access macros for those that don't. Those
57 * that do should define these macros somewhere in there board
58 * specific inlude files.
60 #if !defined(mcf_getppdcd)
61 #define mcf_getppdcd(p) (1)
63 #if !defined(mcf_getppdtr)
64 #define mcf_getppdtr(p) (1)
66 #if !defined(mcf_setppdtr)
67 #define mcf_setppdtr(p,v) do { } while (0)
70 /****************************************************************************/
73 * Local per-uart structure.
76 struct uart_port port
;
77 unsigned int sigs
; /* Local copy of line sigs */
78 unsigned char imr
; /* Local IMR mirror */
81 /****************************************************************************/
83 static inline unsigned int mcf_getreg(struct uart_port
*port
, unsigned int reg
)
85 return readb(port
->membase
+ reg
);
88 static inline void mcf_setreg(struct uart_port
*port
, unsigned int reg
, unsigned int val
)
90 writeb(val
, port
->membase
+ reg
);
93 /****************************************************************************/
95 unsigned int mcf_tx_empty(struct uart_port
*port
)
97 dprintk("mcf_tx_empty(port=%x)\n", (int)port
);
99 return (mcf_getreg(port
, MCFUART_USR
) & MCFUART_USR_TXEMPTY
) ? TIOCSER_TEMT
: 0;
102 /****************************************************************************/
104 unsigned int mcf_get_mctrl(struct uart_port
*port
)
106 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
110 dprintk(" mcf_get_mctrl(port=%x)\n", (int)port
);
112 spin_lock_irqsave(&port
->lock
, flags
);
113 sigs
= (mcf_getreg(port
, MCFUART_UIPR
) & MCFUART_UIPR_CTS
) ? 0 : TIOCM_CTS
;
114 sigs
|= (pp
->sigs
& TIOCM_RTS
);
115 sigs
|= (mcf_getppdcd(port
->line
) ? TIOCM_CD
: 0);
116 sigs
|= (mcf_getppdtr(port
->line
) ? TIOCM_DTR
: 0);
117 spin_unlock_irqrestore(&port
->lock
, flags
);
121 /****************************************************************************/
123 void mcf_set_mctrl(struct uart_port
*port
, unsigned int sigs
)
125 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
128 dprintk("mcf_set_mctrl(port=%x,sigs=%x)\n", (int)port
, sigs
);
130 spin_lock_irqsave(&port
->lock
, flags
);
132 mcf_setppdtr(port
->line
, (sigs
& TIOCM_DTR
));
133 if (sigs
& TIOCM_RTS
)
134 mcf_setreg(port
, MCFUART_UOP1
, MCFUART_UOP_RTS
);
136 mcf_setreg(port
, MCFUART_UOP0
, MCFUART_UOP_RTS
);
137 spin_unlock_irqrestore(&port
->lock
, flags
);
140 /****************************************************************************/
142 void mcf_start_tx(struct uart_port
*port
)
144 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
147 dprintk("mcf_start_tx(port=%x)\n", (int)port
);
149 spin_lock_irqsave(&port
->lock
, flags
);
150 pp
->imr
|= MCFUART_UIR_TXREADY
;
151 mcf_setreg(port
, MCFUART_UIMR
, pp
->imr
);
152 spin_unlock_irqrestore(&port
->lock
, flags
);
155 /****************************************************************************/
157 void mcf_stop_tx(struct uart_port
*port
)
159 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
162 dprintk("mcf_stop_tx(port=%x)\n", (int)port
);
164 spin_lock_irqsave(&port
->lock
, flags
);
165 pp
->imr
&= ~MCFUART_UIR_TXREADY
;
166 mcf_setreg(port
, MCFUART_UIMR
, pp
->imr
);
167 spin_unlock_irqrestore(&port
->lock
, flags
);
170 /****************************************************************************/
172 void mcf_start_rx(struct uart_port
*port
)
174 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
177 dprintk("mcf_start_rx(port=%x)\n", (int)port
);
179 spin_lock_irqsave(&port
->lock
, flags
);
180 pp
->imr
|= MCFUART_UIR_RXREADY
;
181 mcf_setreg(port
, MCFUART_UIMR
, pp
->imr
);
182 spin_unlock_irqrestore(&port
->lock
, flags
);
185 /****************************************************************************/
187 void mcf_stop_rx(struct uart_port
*port
)
189 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
192 dprintk("mcf_stop_rx(port=%x)\n", (int)port
);
194 spin_lock_irqsave(&port
->lock
, flags
);
195 pp
->imr
&= ~MCFUART_UIR_RXREADY
;
196 mcf_setreg(port
, MCFUART_UIMR
, pp
->imr
);
197 spin_unlock_irqrestore(&port
->lock
, flags
);
200 /****************************************************************************/
202 void mcf_break_ctl(struct uart_port
*port
, int break_state
)
206 dprintk("mcf_break_ctl(port=%x,break_state=%x)\n", (int)port
, break_state
);
208 spin_lock_irqsave(&port
->lock
, flags
);
209 if (break_state
== -1)
210 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDBREAKSTART
);
212 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDBREAKSTOP
);
213 spin_unlock_irqrestore(&port
->lock
, flags
);
216 /****************************************************************************/
218 void mcf_enable_ms(struct uart_port
*port
)
220 dprintk("mcf_enable_ms(port=%x)\n", (int)port
);
223 /****************************************************************************/
225 int mcf_startup(struct uart_port
*port
)
227 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
230 dprintk("mcf_startup(port=%x)\n", (int)port
);
232 spin_lock_irqsave(&port
->lock
, flags
);
234 /* Reset UART, get it into known state... */
235 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETRX
);
236 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETTX
);
238 /* Enable the UART transmitter and receiver */
239 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
);
241 /* Enable RX interrupts now */
242 pp
->imr
= MCFUART_UIR_RXREADY
;
243 mcf_setreg(port
, MCFUART_UIMR
, pp
->imr
);
245 spin_unlock_irqrestore(&port
->lock
, flags
);
250 /****************************************************************************/
252 void mcf_shutdown(struct uart_port
*port
)
254 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
257 dprintk("mcf_shutdown(port=%x)\n", (int)port
);
259 spin_lock_irqsave(&port
->lock
, flags
);
261 /* Disable all interrupts now */
263 mcf_setreg(port
, MCFUART_UIMR
, pp
->imr
);
265 /* Disable UART transmitter and receiver */
266 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETRX
);
267 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETTX
);
269 spin_unlock_irqrestore(&port
->lock
, flags
);
272 /****************************************************************************/
274 void mcf_set_termios(struct uart_port
*port
, struct termios
*termios
,
278 unsigned int baud
, baudclk
;
279 unsigned char mr1
, mr2
;
281 dprintk("mcf_set_termios(port=%x,termios=%x,old=%x)\n", (int)port
, (int)termios
, (int)old
);
283 baud
= uart_get_baud_rate(port
, termios
, old
, 0, 230400);
284 baudclk
= ((MCF_BUSCLK
/ baud
) + 16) / 32;
286 mr1
= MCFUART_MR1_RXIRQRDY
| MCFUART_MR1_RXERRCHAR
;
289 switch (termios
->c_cflag
& CSIZE
) {
290 case CS5
: mr1
|= MCFUART_MR1_CS5
; break;
291 case CS6
: mr1
|= MCFUART_MR1_CS6
; break;
292 case CS7
: mr1
|= MCFUART_MR1_CS7
; break;
294 default: mr1
|= MCFUART_MR1_CS8
; break;
297 if (termios
->c_cflag
& PARENB
) {
298 if (termios
->c_cflag
& CMSPAR
) {
299 if (termios
->c_cflag
& PARODD
)
300 mr1
|= MCFUART_MR1_PARITYMARK
;
302 mr1
|= MCFUART_MR1_PARITYSPACE
;
304 if (termios
->c_cflag
& PARODD
)
305 mr1
|= MCFUART_MR1_PARITYODD
;
307 mr1
|= MCFUART_MR1_PARITYEVEN
;
310 mr1
|= MCFUART_MR1_PARITYNONE
;
313 if (termios
->c_cflag
& CSTOPB
)
314 mr2
|= MCFUART_MR2_STOP2
;
316 mr2
|= MCFUART_MR2_STOP1
;
318 if (termios
->c_cflag
& CRTSCTS
) {
319 mr1
|= MCFUART_MR1_RXRTS
;
320 mr2
|= MCFUART_MR2_TXCTS
;
324 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__
, __LINE__
,
327 spin_lock_irqsave(&port
->lock
, flags
);
328 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETRX
);
329 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETTX
);
330 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETMRPTR
);
331 mcf_setreg(port
, MCFUART_UMR
, mr1
);
332 mcf_setreg(port
, MCFUART_UMR
, mr2
);
333 mcf_setreg(port
, MCFUART_UBG1
, (baudclk
& 0xff00) >> 8);
334 mcf_setreg(port
, MCFUART_UBG2
, (baudclk
& 0xff));
335 mcf_setreg(port
, MCFUART_UCSR
, MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
);
336 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
);
337 spin_unlock_irqrestore(&port
->lock
, flags
);
340 /****************************************************************************/
342 static void mcf_rx_chars(struct mcf_uart
*pp
)
344 struct uart_port
*port
= (struct uart_port
*) pp
;
345 unsigned char status
, ch
, flag
;
347 while ((status
= mcf_getreg(port
, MCFUART_USR
)) & MCFUART_USR_RXREADY
) {
348 ch
= mcf_getreg(port
, MCFUART_URB
);
352 if (status
& MCFUART_USR_RXERR
) {
353 mcf_setreg(port
, MCFUART_UCR
, MCFUART_UCR_CMDRESETERR
);
354 if (status
& MCFUART_USR_RXBREAK
) {
356 if (uart_handle_break(port
))
358 } else if (status
& MCFUART_USR_RXPARITY
) {
359 port
->icount
.parity
++;
360 } else if (status
& MCFUART_USR_RXOVERRUN
) {
361 port
->icount
.overrun
++;
362 } else if (status
& MCFUART_USR_RXFRAMING
) {
363 port
->icount
.frame
++;
366 status
&= port
->read_status_mask
;
368 if (status
& MCFUART_USR_RXBREAK
)
370 else if (status
& MCFUART_USR_RXPARITY
)
372 else if (status
& MCFUART_USR_RXFRAMING
)
376 if (uart_handle_sysrq_char(port
, ch
))
378 uart_insert_char(port
, status
, MCFUART_USR_RXOVERRUN
, ch
, flag
);
381 tty_flip_buffer_push(port
->info
->tty
);
384 /****************************************************************************/
386 static void mcf_tx_chars(struct mcf_uart
*pp
)
388 struct uart_port
*port
= (struct uart_port
*) pp
;
389 struct circ_buf
*xmit
= &port
->info
->xmit
;
392 /* Send special char - probably flow control */
393 mcf_setreg(port
, MCFUART_UTB
, port
->x_char
);
399 while (mcf_getreg(port
, MCFUART_USR
) & MCFUART_USR_TXREADY
) {
400 if (xmit
->head
== xmit
->tail
)
402 mcf_setreg(port
, MCFUART_UTB
, xmit
->buf
[xmit
->tail
]);
403 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
-1);
407 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
408 uart_write_wakeup(port
);
410 if (xmit
->head
== xmit
->tail
) {
411 pp
->imr
&= ~MCFUART_UIR_TXREADY
;
412 mcf_setreg(port
, MCFUART_UIMR
, pp
->imr
);
416 /****************************************************************************/
418 static irqreturn_t
mcf_interrupt(int irq
, void *data
)
420 struct uart_port
*port
= data
;
421 struct mcf_uart
*pp
= (struct mcf_uart
*) port
;
424 isr
= mcf_getreg(port
, MCFUART_UISR
) & pp
->imr
;
425 if (isr
& MCFUART_UIR_RXREADY
)
427 if (isr
& MCFUART_UIR_TXREADY
)
432 /****************************************************************************/
434 void mcf_config_port(struct uart_port
*port
, int flags
)
436 #if defined(CONFIG_M5272)
439 switch (port
->line
) {
441 writel(0xe0000000, (MCF_MBAR
+ MCFSIM_ICR2
));
444 writel(0x0e000000, (MCF_MBAR
+ MCFSIM_ICR2
));;
447 printk("MCF: don't know how to handle UART %d interrupt?\n",
452 /* Enable the output lines for the serial ports */
453 iop
= readl(MCF_MBAR
+ MCFSIM_PBCNT
);
454 iop
= (iop
& ~0x000000ff) | 0x00000055;
455 writel(iop
, MCF_MBAR
+ MCFSIM_PBCNT
);
457 iop
= readl(MCF_MBAR
+ MCFSIM_PDCNT
);
458 iop
= (iop
& ~0x000003fc) | 0x000002a8;
459 writel(iop
, MCF_MBAR
+ MCFSIM_PBCNT
);
461 #elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
464 /* level 6, line based priority */
465 writeb(0x30 + port
->line
, MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_ICR0
+ MCFINT_UART0
+ port
->line
);
467 imr
= readl(MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_IMRL
);
468 imr
&= ~((1 << (port
->irq
- 64)) | 1);
469 writel(imr
, MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_IMRL
);
471 #elif defined(CONFIG_M527x)
475 /* level 6, line based priority */
476 writeb(0x30 + port
->line
, MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_ICR0
+ MCFINT_UART0
+ port
->line
);
478 imr
= readl(MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_IMRL
);
479 imr
&= ~((1 << (port
->irq
- 64)) | 1);
480 writel(imr
, MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_IMRL
);
482 sem
= readw(MCF_IPSBAR
+ MCF_GPIO_PAR_UART
);
484 sem
|= UART0_ENABLE_MASK
;
485 else if (port
->line
== 1)
486 sem
|= UART1_ENABLE_MASK
;
487 else if (port
->line
== 2)
488 sem
|= UART2_ENABLE_MASK
;
489 writew(sem
, MCF_IPSBAR
+ MCF_GPIO_PAR_UART
);
491 #elif defined(CONFIG_M520x)
496 writeb(0x03, MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_ICR0
+ MCFINT_UART0
+ port
->line
);
498 imr
= readl(MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_IMRL
);
499 imr
&= ~((1 << (port
->irq
- MCFINT_VECBASE
)) | 1);
500 writel(imr
, MCF_MBAR
+ MCFICM_INTC0
+ MCFINTC_IMRL
);
502 switch (port
->line
) {
504 par
= readw(MCF_IPSBAR
+ MCF_GPIO_PAR_UART
);
505 par
|= MCF_GPIO_PAR_UART_PAR_UTXD0
|
506 MCF_GPIO_PAR_UART_PAR_URXD0
;
507 writew(par
, MCF_IPSBAR
+ MCF_GPIO_PAR_UART
);
510 par
= readw(MCF_IPSBAR
+ MCF_GPIO_PAR_UART
);
511 par
|= MCF_GPIO_PAR_UART_PAR_UTXD1
|
512 MCF_GPIO_PAR_UART_PAR_URXD1
;
513 writew(par
, MCF_IPSBAR
+ MCF_GPIO_PAR_UART
);
516 par2
= readb(MCF_IPSBAR
+ MCF_GPIO_PAR_FECI2C
);
518 par2
|= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2
|
519 MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2
;
520 writeb(par2
, MCF_IPSBAR
+ MCF_GPIO_PAR_FECI2C
);
523 printk("MCF: don't know how to handle UART %d interrupt?\n",
528 #elif defined(CONFIG_M532x)
529 switch (port
->line
) {
531 MCF_INTC0_ICR26
= 0x3;
533 /* GPIO initialization */
534 MCF_GPIO_PAR_UART
|= 0x000F;
537 MCF_INTC0_ICR27
= 0x3;
539 /* GPIO initialization */
540 MCF_GPIO_PAR_UART
|= 0x0FF0;
543 MCF_INTC0_ICR28
= 0x3;
545 /* GPIOs also must be initalized, depends on board */
550 volatile unsigned char *icrp
;
552 switch (port
->line
) {
554 writel(MCFSIM_ICR_LEVEL6
| MCFSIM_ICR_PRI1
, MCF_MBAR
+ MCFSIM_UART1ICR
);
557 writel(MCFSIM_ICR_LEVEL6
| MCFSIM_ICR_PRI2
, MCF_MBAR
+ MCFSIM_UART2ICR
);
558 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2
);
561 printk("MCF: don't know how to handle UART %d interrupt?\n",
566 mcfsetreg(port
, MCFUART_UIVR
, port
->irq
);
569 port
->type
= PORT_MCF
;
571 /* Clear mask, so no surprise interrupts. */
572 mcf_setreg(port
, MCFUART_UIMR
, 0);
574 if (request_irq(port
->irq
, mcf_interrupt
, SA_INTERRUPT
,
575 "ColdFire UART", port
)) {
576 printk("MCF: Unable to attach ColdFire UART %d interrupt "
577 "vector=%d\n", port
->line
, port
->irq
);
582 /****************************************************************************/
584 static const char *mcf_type(struct uart_port
*port
)
586 dprintk("mcf_type()\n");
587 return ((port
->type
== PORT_MCF
) ? "ColdFire UART" : NULL
);
590 /****************************************************************************/
592 int mcf_request_port(struct uart_port
*port
)
594 /* UARTs always present */
595 dprintk("mcf_request_port()\n");
599 /****************************************************************************/
601 void mcf_release_port(struct uart_port
*port
)
603 /* Nothing to release... */
604 dprintk("mcf_release_port()\n");
607 /****************************************************************************/
609 int mcf_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
611 dprintk("mcf_verify_port()\n");
612 if ((ser
->type
!= PORT_UNKNOWN
) && (ser
->type
!= PORT_MCF
))
617 /****************************************************************************/
620 * Define the basic serial functions we support.
622 static struct uart_ops mcf_uart_ops
= {
623 .tx_empty
= mcf_tx_empty
,
624 .get_mctrl
= mcf_get_mctrl
,
625 .set_mctrl
= mcf_set_mctrl
,
626 .start_tx
= mcf_start_tx
,
627 .stop_tx
= mcf_stop_tx
,
628 .stop_rx
= mcf_stop_rx
,
629 .enable_ms
= mcf_enable_ms
,
630 .break_ctl
= mcf_break_ctl
,
631 .startup
= mcf_startup
,
632 .shutdown
= mcf_shutdown
,
633 .set_termios
= mcf_set_termios
,
635 .request_port
= mcf_request_port
,
636 .release_port
= mcf_release_port
,
637 .config_port
= mcf_config_port
,
638 .verify_port
= mcf_verify_port
,
642 * Define the port structures, 1 per port/uart.
644 static struct mcf_uart mcf_ports
[] = {
649 .membase
= (void *) MCF_MBAR
+ MCFUART_BASE1
,
650 .mapbase
= MCF_MBAR
+ MCFUART_BASE1
,
651 .iotype
= SERIAL_IO_MEM
,
653 .uartclk
= MCF_BUSCLK
,
654 .ops
= &mcf_uart_ops
,
655 .flags
= ASYNC_BOOT_AUTOCONF
,
658 #if defined(MCFUART_BASE2)
663 .membase
= (void *) MCF_MBAR
+ MCFUART_BASE2
,
664 .mapbase
= MCF_MBAR
+ MCFUART_BASE2
,
665 .iotype
= SERIAL_IO_MEM
,
667 .uartclk
= MCF_BUSCLK
,
668 .ops
= &mcf_uart_ops
,
669 .flags
= ASYNC_BOOT_AUTOCONF
,
673 #if defined(MCFUART_BASE3)
678 .membase
= (void *) MCF_MBAR
+ MCFUART_BASE3
,
679 .mapbase
= MCF_MBAR
+ MCFUART_BASE3
,
680 .iotype
= SERIAL_IO_MEM
,
682 .uartclk
= MCF_BUSCLK
,
683 .ops
= &mcf_uart_ops
,
684 .flags
= ASYNC_BOOT_AUTOCONF
,
690 #define MCF_MAXPORTS (sizeof(mcf_ports) / sizeof(struct mcf_uart))
692 /****************************************************************************/
693 #if defined(CONFIG_SERIAL_MCF_CONSOLE)
694 /****************************************************************************/
696 static void mcf_console_putc(struct console
*co
, const char c
)
698 struct uart_port
*port
= &(mcf_ports
+ co
->index
)->port
;
701 for (i
= 0; (i
< 0x10000); i
++) {
702 if (mcf_getreg(port
, MCFUART_USR
) & MCFUART_USR_TXREADY
)
705 mcf_setreg(port
, MCFUART_UTB
, c
);
706 for (i
= 0; (i
< 0x10000); i
++) {
707 if (mcf_getreg(port
, MCFUART_USR
) & MCFUART_USR_TXREADY
)
712 /****************************************************************************/
714 static void mcf_console_write(struct console
*co
, const char *s
, unsigned int count
)
716 for ( ; (count
); count
--, s
++) {
717 mcf_console_putc(co
, *s
);
719 mcf_console_putc(co
, '\r');
723 /****************************************************************************/
725 static int __init
mcf_console_setup(struct console
*co
, char *options
)
727 struct uart_port
*port
;
728 int baud
= CONFIG_SERIAL_MCF_BAUDRATE
;
733 if ((co
->index
>= 0) && (co
->index
<= MCF_MAXPORTS
))
735 port
= &mcf_ports
[co
->index
].port
;
738 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
740 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
743 /****************************************************************************/
745 static struct uart_driver mcf_driver
;
747 static struct console mcf_console
= {
749 .write
= mcf_console_write
,
750 .device
= uart_console_device
,
751 .setup
= mcf_console_setup
,
752 .flags
= CON_PRINTBUFFER
,
757 static int __init
mcf_console_init(void)
759 register_console(&mcf_console
);
763 console_initcall(mcf_console_init
);
765 #define MCF_CONSOLE &mcf_console
767 /****************************************************************************/
769 /****************************************************************************/
771 #define MCF_CONSOLE NULL
773 /****************************************************************************/
774 #endif /* CONFIG_MCF_CONSOLE */
775 /****************************************************************************/
778 * Define the mcf UART driver structure.
780 static struct uart_driver mcf_driver
= {
781 .owner
= THIS_MODULE
,
782 .driver_name
= "mcf",
790 /****************************************************************************/
792 static int __init
mcf_init(void)
796 printk("ColdFire internal UART serial driver\n");
798 if ((rc
= uart_register_driver(&mcf_driver
)))
801 for (i
= 0; (i
< MCF_MAXPORTS
); i
++) {
802 if ((rc
= uart_add_one_port(&mcf_driver
, &mcf_ports
[i
].port
)) < 0)
803 printk("mcf: failed to add UART, %d\n", rc
);
808 /****************************************************************************/
810 static void __exit
mcf_exit(void)
814 for (i
= 0; (i
< MCF_MAXPORTS
); i
++)
815 uart_remove_one_port(&mcf_driver
, &mcf_ports
[i
].port
);
816 uart_unregister_driver(&mcf_driver
);
819 /****************************************************************************/
821 module_init(mcf_init
);
822 module_exit(mcf_exit
);
824 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
825 MODULE_DESCRIPTION("Freescale ColdFire UART driver");
826 MODULE_LICENSE("GPL");
828 /****************************************************************************/