1 /* MN10300 On-chip serial port UART driver
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 static const char serial_name
[] = "MN10300 Serial driver";
13 static const char serial_version
[] = "mn10300_serial-1.0";
14 static const char serial_revdate
[] = "2007-11-06";
16 #if defined(CONFIG_MN10300_TTYSM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
20 #include <linux/module.h>
21 #include <linux/serial.h>
22 #include <linux/circ_buf.h>
23 #include <linux/errno.h>
24 #include <linux/signal.h>
25 #include <linux/sched.h>
26 #include <linux/timer.h>
27 #include <linux/interrupt.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
30 #include <linux/major.h>
31 #include <linux/string.h>
32 #include <linux/ioport.h>
34 #include <linux/slab.h>
35 #include <linux/init.h>
36 #include <linux/console.h>
37 #include <linux/sysrq.h>
39 #include <asm/system.h>
42 #include <asm/bitops.h>
43 #include <asm/serial-regs.h>
44 #include <unit/timex.h>
45 #include "mn10300-serial.h"
49 #define GxICR(X) CROSS_GxICR(X, 0)
50 #endif /* CONFIG_SMP */
52 #define kenter(FMT, ...) \
53 printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
54 #define _enter(FMT, ...) \
55 no_printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
56 #define kdebug(FMT, ...) \
57 printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
58 #define _debug(FMT, ...) \
59 no_printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
60 #define kproto(FMT, ...) \
61 printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
62 #define _proto(FMT, ...) \
63 no_printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
66 /* c_cflag bit meaning */
67 #define CODMSB 004000000000 /* change Transfer bit-order */
72 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
73 static void mn10300_serial_console_write(struct console
*co
,
74 const char *s
, unsigned count
);
75 static int __init
mn10300_serial_console_setup(struct console
*co
,
78 static struct uart_driver mn10300_serial_driver
;
79 static struct console mn10300_serial_console
= {
81 .write
= mn10300_serial_console_write
,
82 .device
= uart_console_device
,
83 .setup
= mn10300_serial_console_setup
,
84 .flags
= CON_PRINTBUFFER
,
86 .data
= &mn10300_serial_driver
,
90 static struct uart_driver mn10300_serial_driver
= {
92 .driver_name
= "mn10300-serial",
97 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
98 .cons
= &mn10300_serial_console
,
102 static unsigned int mn10300_serial_tx_empty(struct uart_port
*);
103 static void mn10300_serial_set_mctrl(struct uart_port
*, unsigned int mctrl
);
104 static unsigned int mn10300_serial_get_mctrl(struct uart_port
*);
105 static void mn10300_serial_stop_tx(struct uart_port
*);
106 static void mn10300_serial_start_tx(struct uart_port
*);
107 static void mn10300_serial_send_xchar(struct uart_port
*, char ch
);
108 static void mn10300_serial_stop_rx(struct uart_port
*);
109 static void mn10300_serial_enable_ms(struct uart_port
*);
110 static void mn10300_serial_break_ctl(struct uart_port
*, int ctl
);
111 static int mn10300_serial_startup(struct uart_port
*);
112 static void mn10300_serial_shutdown(struct uart_port
*);
113 static void mn10300_serial_set_termios(struct uart_port
*,
114 struct ktermios
*new,
115 struct ktermios
*old
);
116 static const char *mn10300_serial_type(struct uart_port
*);
117 static void mn10300_serial_release_port(struct uart_port
*);
118 static int mn10300_serial_request_port(struct uart_port
*);
119 static void mn10300_serial_config_port(struct uart_port
*, int);
120 static int mn10300_serial_verify_port(struct uart_port
*,
121 struct serial_struct
*);
123 static const struct uart_ops mn10300_serial_ops
= {
124 .tx_empty
= mn10300_serial_tx_empty
,
125 .set_mctrl
= mn10300_serial_set_mctrl
,
126 .get_mctrl
= mn10300_serial_get_mctrl
,
127 .stop_tx
= mn10300_serial_stop_tx
,
128 .start_tx
= mn10300_serial_start_tx
,
129 .send_xchar
= mn10300_serial_send_xchar
,
130 .stop_rx
= mn10300_serial_stop_rx
,
131 .enable_ms
= mn10300_serial_enable_ms
,
132 .break_ctl
= mn10300_serial_break_ctl
,
133 .startup
= mn10300_serial_startup
,
134 .shutdown
= mn10300_serial_shutdown
,
135 .set_termios
= mn10300_serial_set_termios
,
136 .type
= mn10300_serial_type
,
137 .release_port
= mn10300_serial_release_port
,
138 .request_port
= mn10300_serial_request_port
,
139 .config_port
= mn10300_serial_config_port
,
140 .verify_port
= mn10300_serial_verify_port
,
143 static irqreturn_t
mn10300_serial_interrupt(int irq
, void *dev_id
);
146 * the first on-chip serial port: ttySM0 (aka SIF0)
148 #ifdef CONFIG_MN10300_TTYSM0
149 struct mn10300_serial_port mn10300_serial_port_sif0
= {
150 .uart
.ops
= &mn10300_serial_ops
,
151 .uart
.membase
= (void __iomem
*) &SC0CTR
,
152 .uart
.mapbase
= (unsigned long) &SC0CTR
,
153 .uart
.iotype
= UPIO_MEM
,
155 .uart
.uartclk
= 0, /* MN10300_IOCLK, */
157 .uart
.flags
= UPF_BOOT_AUTOCONF
,
159 .uart
.type
= PORT_MN10300
,
161 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif0
.uart
.lock
),
165 ._status
= (volatile u8
*)&SC0STR
,
169 .rx_name
= "ttySM0:Rx",
170 .tx_name
= "ttySM0:Tx",
171 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
172 .tm_name
= "ttySM0:Timer8",
177 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
178 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
179 .tm_name
= "ttySM0:Timer0",
181 ._tmxbr
= (volatile u16
*)&TM0BR
,
184 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
185 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
186 .tm_name
= "ttySM0:Timer2",
188 ._tmxbr
= (volatile u16
*)&TM2BR
,
191 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
193 #error "Unknown config for ttySM0"
197 .rx_icr
= &GxICR(SC0RXIRQ
),
198 .tx_icr
= &GxICR(SC0TXIRQ
),
199 .clock_src
= MNSCx_CLOCK_SRC_IOCLK
,
201 #ifdef CONFIG_GDBSTUB_ON_TTYSM0
205 #endif /* CONFIG_MN10300_TTYSM0 */
208 * the second on-chip serial port: ttySM1 (aka SIF1)
210 #ifdef CONFIG_MN10300_TTYSM1
211 struct mn10300_serial_port mn10300_serial_port_sif1
= {
212 .uart
.ops
= &mn10300_serial_ops
,
213 .uart
.membase
= (void __iomem
*) &SC1CTR
,
214 .uart
.mapbase
= (unsigned long) &SC1CTR
,
215 .uart
.iotype
= UPIO_MEM
,
217 .uart
.uartclk
= 0, /* MN10300_IOCLK, */
219 .uart
.flags
= UPF_BOOT_AUTOCONF
,
221 .uart
.type
= PORT_MN10300
,
223 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif1
.uart
.lock
),
227 ._status
= (volatile u8
*)&SC1STR
,
231 .rx_name
= "ttySM1:Rx",
232 .tx_name
= "ttySM1:Tx",
233 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
234 .tm_name
= "ttySM1:Timer9",
239 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
240 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
241 .tm_name
= "ttySM1:Timer3",
243 ._tmxbr
= (volatile u16
*)&TM3BR
,
246 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
247 #elif defined(CONFIG_MN10300_TTYSM1_TIMER12)
248 .tm_name
= "ttySM1/Timer12",
253 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
255 #error "Unknown config for ttySM1"
259 .rx_icr
= &GxICR(SC1RXIRQ
),
260 .tx_icr
= &GxICR(SC1TXIRQ
),
261 .clock_src
= MNSCx_CLOCK_SRC_IOCLK
,
263 #ifdef CONFIG_GDBSTUB_ON_TTYSM1
267 #endif /* CONFIG_MN10300_TTYSM1 */
270 * the third on-chip serial port: ttySM2 (aka SIF2)
272 #ifdef CONFIG_MN10300_TTYSM2
273 struct mn10300_serial_port mn10300_serial_port_sif2
= {
274 .uart
.ops
= &mn10300_serial_ops
,
275 .uart
.membase
= (void __iomem
*) &SC2CTR
,
276 .uart
.mapbase
= (unsigned long) &SC2CTR
,
277 .uart
.iotype
= UPIO_MEM
,
279 .uart
.uartclk
= 0, /* MN10300_IOCLK, */
281 .uart
.flags
= UPF_BOOT_AUTOCONF
,
283 #ifdef CONFIG_MN10300_TTYSM2_CTS
284 .uart
.type
= PORT_MN10300_CTS
,
286 .uart
.type
= PORT_MN10300
,
289 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif2
.uart
.lock
),
293 ._status
= (volatile u8
*)&SC2STR
,
297 .rx_name
= "ttySM2:Rx",
298 .tx_name
= "ttySM2:Tx",
299 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
300 .tm_name
= "ttySM2/Timer10",
305 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
306 #elif defined(CONFIG_MN10300_TTYSM2_TIMER9)
307 .tm_name
= "ttySM2/Timer9",
312 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
313 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
314 .tm_name
= "ttySM2/Timer1",
316 ._tmxbr
= (volatile u16
*)&TM1BR
,
319 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
320 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
321 .tm_name
= "ttySM2/Timer3",
323 ._tmxbr
= (volatile u16
*)&TM3BR
,
326 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
328 #error "Unknown config for ttySM2"
332 .rx_icr
= &GxICR(SC2RXIRQ
),
333 .tx_icr
= &GxICR(SC2TXIRQ
),
334 .clock_src
= MNSCx_CLOCK_SRC_IOCLK
,
335 #ifdef CONFIG_MN10300_TTYSM2_CTS
336 .options
= MNSCx_OPT_CTS
,
340 #ifdef CONFIG_GDBSTUB_ON_TTYSM2
344 #endif /* CONFIG_MN10300_TTYSM2 */
348 * list of available serial ports
350 struct mn10300_serial_port
*mn10300_serial_ports
[NR_UARTS
+ 1] = {
351 #ifdef CONFIG_MN10300_TTYSM0
352 [0] = &mn10300_serial_port_sif0
,
354 #ifdef CONFIG_MN10300_TTYSM1
355 [1] = &mn10300_serial_port_sif1
,
357 #ifdef CONFIG_MN10300_TTYSM2
358 [2] = &mn10300_serial_port_sif2
,
365 * we abuse the serial ports' baud timers' interrupt lines to get the ability
366 * to deliver interrupts to userspace as we use the ports' interrupt lines to
367 * do virtual DMA on account of the ports having no hardware FIFOs
369 * we can generate an interrupt manually in the assembly stubs by writing to
370 * the enable and detect bits in the interrupt control register, so all we need
371 * to do here is disable the interrupt line
373 * note that we can't just leave the line enabled as the baud rate timer *also*
374 * generates interrupts
376 static void mn10300_serial_mask_ack(unsigned int irq
)
381 flags
= arch_local_cli_save();
382 GxICR(irq
) = GxICR_LEVEL_6
;
383 tmp
= GxICR(irq
); /* flush write buffer */
384 arch_local_irq_restore(flags
);
387 static void mn10300_serial_chip_mask_ack(struct irq_data
*d
)
389 mn10300_serial_mask_ack(d
->irq
);
392 static void mn10300_serial_nop(struct irq_data
*d
)
396 static struct irq_chip mn10300_serial_pic
= {
398 .irq_ack
= mn10300_serial_chip_mask_ack
,
399 .irq_mask
= mn10300_serial_chip_mask_ack
,
400 .irq_mask_ack
= mn10300_serial_chip_mask_ack
,
401 .irq_unmask
= mn10300_serial_nop
,
406 * serial virtual DMA interrupt jump table
408 struct mn10300_serial_int mn10300_serial_int_tbl
[NR_IRQS
];
410 static void mn10300_serial_dis_tx_intr(struct mn10300_serial_port
*port
)
415 flags
= arch_local_cli_save();
416 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
418 arch_local_irq_restore(flags
);
421 static void mn10300_serial_en_tx_intr(struct mn10300_serial_port
*port
)
426 flags
= arch_local_cli_save();
428 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
) | GxICR_ENABLE
;
430 arch_local_irq_restore(flags
);
433 static void mn10300_serial_dis_rx_intr(struct mn10300_serial_port
*port
)
438 flags
= arch_local_cli_save();
439 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
441 arch_local_irq_restore(flags
);
445 * multi-bit equivalent of test_and_clear_bit()
447 static int mask_test_and_clear(volatile u8
*ptr
, u8 mask
)
450 asm volatile(" bclr %1,(%2) \n"
452 : "=d"(epsw
) : "d"(mask
), "a"(ptr
)
454 return !(epsw
& EPSW_FLAG_Z
);
458 * receive chars from the ring buffer for this serial port
459 * - must do break detection here (not done in the UART)
461 static void mn10300_serial_receive_interrupt(struct mn10300_serial_port
*port
)
463 struct uart_icount
*icount
= &port
->uart
.icount
;
464 struct tty_struct
*tty
= port
->uart
.state
->port
.tty
;
467 u8 st
, ch
, push
, status
, overrun
;
469 _enter("%s", port
->name
);
473 count
= CIRC_CNT(port
->rx_inp
, port
->rx_outp
, MNSC_BUFFER_SIZE
);
474 count
= tty_buffer_request_room(tty
, count
);
476 if (!tty
->low_latency
)
477 tty_flip_buffer_push(tty
);
482 /* pull chars out of the hat */
484 if (ix
== port
->rx_inp
) {
485 if (push
&& !tty
->low_latency
)
486 tty_flip_buffer_push(tty
);
490 ch
= port
->rx_buffer
[ix
++];
491 st
= port
->rx_buffer
[ix
++];
493 port
->rx_outp
= ix
& (MNSC_BUFFER_SIZE
- 1);
494 port
->uart
.icount
.rx
++;
496 st
&= SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
;
500 /* the UART doesn't detect BREAK, so we have to do that ourselves
501 * - it starts as a framing error on a NUL character
502 * - then we count another two NUL characters before issuing TTY_BREAK
503 * - then we end on a normal char or one that has all the bottom bits
504 * zero and the top bits set
506 switch (port
->rx_brk
) {
508 /* not breaking at the moment */
512 if (st
& SC01STR_FEF
&& ch
== 0) {
519 if (st
& SC01STR_FEF
&& ch
== 0) {
521 _proto("Rx Break Detected");
523 if (uart_handle_break(&port
->uart
))
525 status
|= 1 << TTY_BREAK
;
531 if (st
& (SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
))
532 goto try_again
; /* still breaking */
534 port
->rx_brk
= 0; /* end of the break */
546 /* discard char at probable break end */
553 /* handle framing error */
554 if (st
& SC01STR_FEF
) {
556 /* framing error with NUL char is probably a BREAK */
561 _proto("Rx Framing Error");
563 status
|= 1 << TTY_FRAME
;
566 /* handle parity error */
567 if (st
& SC01STR_PEF
) {
568 _proto("Rx Parity Error");
573 /* handle normal char */
575 if (uart_handle_sysrq_char(&port
->uart
, ch
))
577 status
= (1 << TTY_NORMAL
);
580 /* handle overrun error */
581 if (st
& SC01STR_OEF
) {
585 _proto("Rx Overrun Error");
591 status
&= port
->uart
.read_status_mask
;
593 if (!overrun
&& !(status
& port
->uart
.ignore_status_mask
)) {
596 if (status
& (1 << TTY_BREAK
))
598 else if (status
& (1 << TTY_PARITY
))
600 else if (status
& (1 << TTY_FRAME
))
605 tty_insert_flip_char(tty
, ch
, flag
);
608 /* overrun is special, since it's reported immediately, and doesn't
609 * affect the current character
612 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
616 if (!tty
->low_latency
)
617 tty_flip_buffer_push(tty
);
631 * handle an interrupt from the serial transmission "virtual DMA" driver
632 * - note: the interrupt routine will disable its own interrupts when the Tx
635 static void mn10300_serial_transmit_interrupt(struct mn10300_serial_port
*port
)
637 _enter("%s", port
->name
);
639 if (!port
->uart
.state
|| !port
->uart
.state
->port
.tty
) {
640 mn10300_serial_dis_tx_intr(port
);
644 if (uart_tx_stopped(&port
->uart
) ||
645 uart_circ_empty(&port
->uart
.state
->xmit
))
646 mn10300_serial_dis_tx_intr(port
);
648 if (uart_circ_chars_pending(&port
->uart
.state
->xmit
) < WAKEUP_CHARS
)
649 uart_write_wakeup(&port
->uart
);
653 * deal with a change in the status of the CTS line
655 static void mn10300_serial_cts_changed(struct mn10300_serial_port
*port
, u8 st
)
660 port
->uart
.icount
.cts
++;
662 /* flip the CTS state selector flag to interrupt when it changes
664 ctr
= *port
->_control
;
666 *port
->_control
= ctr
;
668 uart_handle_cts_change(&port
->uart
, st
& SC2STR_CTS
);
669 wake_up_interruptible(&port
->uart
.state
->port
.delta_msr_wait
);
673 * handle a virtual interrupt generated by the lower level "virtual DMA"
674 * routines (irq is the baud timer interrupt)
676 static irqreturn_t
mn10300_serial_interrupt(int irq
, void *dev_id
)
678 struct mn10300_serial_port
*port
= dev_id
;
681 spin_lock(&port
->uart
.lock
);
683 if (port
->intr_flags
) {
684 _debug("INT %s: %x", port
->name
, port
->intr_flags
);
686 if (mask_test_and_clear(&port
->intr_flags
, MNSCx_RX_AVAIL
))
687 mn10300_serial_receive_interrupt(port
);
689 if (mask_test_and_clear(&port
->intr_flags
,
690 MNSCx_TX_SPACE
| MNSCx_TX_EMPTY
))
691 mn10300_serial_transmit_interrupt(port
);
694 /* the only modem control line amongst the whole lot is CTS on
696 if (port
->type
== PORT_MN10300_CTS
) {
698 if ((port
->tx_cts
^ st
) & SC2STR_CTS
)
699 mn10300_serial_cts_changed(port
, st
);
702 spin_unlock(&port
->uart
.lock
);
708 * return indication of whether the hardware transmit buffer is empty
710 static unsigned int mn10300_serial_tx_empty(struct uart_port
*_port
)
712 struct mn10300_serial_port
*port
=
713 container_of(_port
, struct mn10300_serial_port
, uart
);
715 _enter("%s", port
->name
);
717 return (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
)) ?
722 * set the modem control lines (we don't have any)
724 static void mn10300_serial_set_mctrl(struct uart_port
*_port
,
727 struct mn10300_serial_port
*port
__attribute__ ((unused
)) =
728 container_of(_port
, struct mn10300_serial_port
, uart
);
730 _enter("%s,%x", port
->name
, mctrl
);
734 * get the modem control line statuses
736 static unsigned int mn10300_serial_get_mctrl(struct uart_port
*_port
)
738 struct mn10300_serial_port
*port
=
739 container_of(_port
, struct mn10300_serial_port
, uart
);
741 _enter("%s", port
->name
);
743 if (port
->type
== PORT_MN10300_CTS
&& !(*port
->_status
& SC2STR_CTS
))
744 return TIOCM_CAR
| TIOCM_DSR
;
746 return TIOCM_CAR
| TIOCM_CTS
| TIOCM_DSR
;
750 * stop transmitting characters
752 static void mn10300_serial_stop_tx(struct uart_port
*_port
)
754 struct mn10300_serial_port
*port
=
755 container_of(_port
, struct mn10300_serial_port
, uart
);
757 _enter("%s", port
->name
);
759 /* disable the virtual DMA */
760 mn10300_serial_dis_tx_intr(port
);
764 * start transmitting characters
765 * - jump-start transmission if it has stalled
766 * - enable the serial Tx interrupt (used by the virtual DMA controller)
767 * - force an interrupt to happen if necessary
769 static void mn10300_serial_start_tx(struct uart_port
*_port
)
771 struct mn10300_serial_port
*port
=
772 container_of(_port
, struct mn10300_serial_port
, uart
);
778 CIRC_CNT(&port
->uart
.state
->xmit
.head
,
779 &port
->uart
.state
->xmit
.tail
,
782 /* kick the virtual DMA controller */
787 if (*port
->_status
& SC01STR_TBF
)
788 x
&= ~(GxICR_REQUEST
| GxICR_DETECT
);
790 x
|= GxICR_REQUEST
| GxICR_DETECT
;
792 _debug("CTR=%04hx ICR=%02hx STR=%04x TMD=%02hx TBR=%04hx ICR=%04hx",
793 *port
->_control
, *port
->_intr
, *port
->_status
,
795 (port
->div_timer
== MNSCx_DIV_TIMER_8BIT
) ?
796 *(volatile u8
*)port
->_tmxbr
: *port
->_tmxbr
,
805 * transmit a high-priority XON/XOFF character
807 static void mn10300_serial_send_xchar(struct uart_port
*_port
, char ch
)
809 struct mn10300_serial_port
*port
=
810 container_of(_port
, struct mn10300_serial_port
, uart
);
812 _enter("%s,%02x", port
->name
, ch
);
814 if (likely(port
->gdbstub
)) {
817 mn10300_serial_en_tx_intr(port
);
822 * stop receiving characters
823 * - called whilst the port is being closed
825 static void mn10300_serial_stop_rx(struct uart_port
*_port
)
827 struct mn10300_serial_port
*port
=
828 container_of(_port
, struct mn10300_serial_port
, uart
);
832 _enter("%s", port
->name
);
834 ctr
= *port
->_control
;
836 *port
->_control
= ctr
;
838 mn10300_serial_dis_rx_intr(port
);
842 * enable modem status interrupts
844 static void mn10300_serial_enable_ms(struct uart_port
*_port
)
846 struct mn10300_serial_port
*port
=
847 container_of(_port
, struct mn10300_serial_port
, uart
);
851 _enter("%s", port
->name
);
853 if (port
->type
== PORT_MN10300_CTS
) {
854 /* want to interrupt when CTS goes low if CTS is now high and
857 port
->tx_cts
= *port
->_status
;
859 cts
= (port
->tx_cts
& SC2STR_CTS
) ?
860 SC2CTR_TWE
: SC2CTR_TWE
| SC2CTR_TWS
;
862 ctr
= *port
->_control
;
865 *port
->_control
= ctr
;
867 mn10300_serial_en_tx_intr(port
);
872 * transmit or cease transmitting a break signal
874 static void mn10300_serial_break_ctl(struct uart_port
*_port
, int ctl
)
876 struct mn10300_serial_port
*port
=
877 container_of(_port
, struct mn10300_serial_port
, uart
);
879 _enter("%s,%d", port
->name
, ctl
);
882 /* tell the virtual DMA handler to assert BREAK */
884 mn10300_serial_en_tx_intr(port
);
887 *port
->_control
&= ~SC01CTR_BKE
;
888 mn10300_serial_en_tx_intr(port
);
893 * grab the interrupts and enable the port for reception
895 static int mn10300_serial_startup(struct uart_port
*_port
)
897 struct mn10300_serial_port
*port
=
898 container_of(_port
, struct mn10300_serial_port
, uart
);
899 struct mn10300_serial_int
*pint
;
901 _enter("%s{%d}", port
->name
, port
->gdbstub
);
903 if (unlikely(port
->gdbstub
))
906 /* allocate an Rx buffer for the virtual DMA handler */
907 port
->rx_buffer
= kmalloc(MNSC_BUFFER_SIZE
, GFP_KERNEL
);
908 if (!port
->rx_buffer
)
911 port
->rx_inp
= port
->rx_outp
= 0;
913 /* finally, enable the device */
914 *port
->_intr
= SC01ICR_TI
;
915 *port
->_control
|= SC01CTR_TXE
| SC01CTR_RXE
;
917 pint
= &mn10300_serial_int_tbl
[port
->rx_irq
];
919 pint
->vdma
= mn10300_serial_vdma_rx_handler
;
920 pint
= &mn10300_serial_int_tbl
[port
->tx_irq
];
922 pint
->vdma
= mn10300_serial_vdma_tx_handler
;
924 set_intr_level(port
->rx_irq
,
925 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
));
926 set_intr_level(port
->tx_irq
,
927 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
));
928 set_irq_chip(port
->tm_irq
, &mn10300_serial_pic
);
930 if (request_irq(port
->rx_irq
, mn10300_serial_interrupt
,
931 IRQF_DISABLED
, port
->rx_name
, port
) < 0)
934 if (request_irq(port
->tx_irq
, mn10300_serial_interrupt
,
935 IRQF_DISABLED
, port
->tx_name
, port
) < 0)
938 if (request_irq(port
->tm_irq
, mn10300_serial_interrupt
,
939 IRQF_DISABLED
, port
->tm_name
, port
) < 0)
941 mn10300_serial_mask_ack(port
->tm_irq
);
946 free_irq(port
->tx_irq
, port
);
948 free_irq(port
->rx_irq
, port
);
950 kfree(port
->rx_buffer
);
951 port
->rx_buffer
= NULL
;
956 * shutdown the port and release interrupts
958 static void mn10300_serial_shutdown(struct uart_port
*_port
)
961 struct mn10300_serial_port
*port
=
962 container_of(_port
, struct mn10300_serial_port
, uart
);
964 _enter("%s", port
->name
);
966 /* disable the serial port and its baud rate timer */
968 *port
->_control
&= ~(SC01CTR_TXE
| SC01CTR_RXE
| SC01CTR_BKE
);
971 if (port
->rx_buffer
) {
972 void *buf
= port
->rx_buffer
;
973 port
->rx_buffer
= NULL
;
977 /* disable all intrs */
978 free_irq(port
->tm_irq
, port
);
979 free_irq(port
->rx_irq
, port
);
980 free_irq(port
->tx_irq
, port
);
983 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
985 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
991 * this routine is called to set the UART divisor registers to match the
992 * specified baud rate for a serial port.
994 static void mn10300_serial_change_speed(struct mn10300_serial_port
*port
,
995 struct ktermios
*new,
996 struct ktermios
*old
)
999 unsigned long ioclk
= port
->ioclk
;
1001 int baud
, bits
, xdiv
, tmp
;
1004 u8 div_timer
= port
->div_timer
;
1006 _enter("%s{%lu}", port
->name
, ioclk
);
1008 /* byte size and parity */
1009 cflag
= new->c_cflag
;
1010 switch (cflag
& CSIZE
) {
1011 case CS7
: scxctr
= SC01CTR_CLN_7BIT
; bits
= 9; break;
1012 case CS8
: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1013 default: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1016 if (cflag
& CSTOPB
) {
1017 scxctr
|= SC01CTR_STB_2BIT
;
1021 if (cflag
& PARENB
) {
1024 scxctr
|= SC01CTR_PB_ODD
;
1026 else if (cflag
& CMSPAR
)
1027 scxctr
|= SC01CTR_PB_FIXED0
;
1030 scxctr
|= SC01CTR_PB_EVEN
;
1033 /* Determine divisor based on baud rate */
1036 switch (port
->uart
.line
) {
1037 #ifdef CONFIG_MN10300_TTYSM0
1038 case 0: /* ttySM0 */
1039 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
1040 scxctr
|= SC0CTR_CK_TM8UFLOW_8
;
1041 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
1042 scxctr
|= SC0CTR_CK_TM0UFLOW_8
;
1043 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
1044 scxctr
|= SC0CTR_CK_TM2UFLOW_8
;
1046 #error "Unknown config for ttySM0"
1049 #endif /* CONFIG_MN10300_TTYSM0 */
1051 #ifdef CONFIG_MN10300_TTYSM1
1052 case 1: /* ttySM1 */
1053 #if defined(CONFIG_AM33_2) || defined(CONFIG_AM33_3)
1054 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
1055 scxctr
|= SC1CTR_CK_TM9UFLOW_8
;
1056 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
1057 scxctr
|= SC1CTR_CK_TM3UFLOW_8
;
1059 #error "Unknown config for ttySM1"
1061 #else /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1062 #if defined(CONFIG_MN10300_TTYSM1_TIMER12)
1063 scxctr
|= SC1CTR_CK_TM12UFLOW_8
;
1065 #error "Unknown config for ttySM1"
1067 #endif /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1069 #endif /* CONFIG_MN10300_TTYSM1 */
1071 #ifdef CONFIG_MN10300_TTYSM2
1072 case 2: /* ttySM2 */
1073 #if defined(CONFIG_AM33_2)
1074 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
1075 scxctr
|= SC2CTR_CK_TM10UFLOW
;
1077 #error "Unknown config for ttySM2"
1079 #else /* CONFIG_AM33_2 */
1080 #if defined(CONFIG_MN10300_TTYSM2_TIMER9)
1081 scxctr
|= SC2CTR_CK_TM9UFLOW_8
;
1082 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
1083 scxctr
|= SC2CTR_CK_TM1UFLOW_8
;
1084 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
1085 scxctr
|= SC2CTR_CK_TM3UFLOW_8
;
1087 #error "Unknown config for ttySM2"
1089 #endif /* CONFIG_AM33_2 */
1091 #endif /* CONFIG_MN10300_TTYSM2 */
1098 baud
= uart_get_baud_rate(&port
->uart
, new, old
, 0,
1101 _debug("ALT %d [baud %d]", battempt
, baud
);
1104 baud
= 9600; /* B0 transition handled in rs_set_termios */
1107 baud
= 269; /* 134 is really 134.5 */
1111 if (baud
== 38400 &&
1112 (port
->uart
.flags
& UPF_SPD_MASK
) == UPF_SPD_CUST
1114 _debug("CUSTOM %u", port
->uart
.custom_divisor
);
1116 if (div_timer
== MNSCx_DIV_TIMER_16BIT
) {
1117 if (port
->uart
.custom_divisor
<= 65535) {
1118 tmxmd
= TM8MD_SRC_IOCLK
;
1119 tmxbr
= port
->uart
.custom_divisor
;
1120 port
->uart
.uartclk
= ioclk
;
1123 if (port
->uart
.custom_divisor
/ 8 <= 65535) {
1124 tmxmd
= TM8MD_SRC_IOCLK_8
;
1125 tmxbr
= port
->uart
.custom_divisor
/ 8;
1126 port
->uart
.custom_divisor
= tmxbr
* 8;
1127 port
->uart
.uartclk
= ioclk
/ 8;
1130 if (port
->uart
.custom_divisor
/ 32 <= 65535) {
1131 tmxmd
= TM8MD_SRC_IOCLK_32
;
1132 tmxbr
= port
->uart
.custom_divisor
/ 32;
1133 port
->uart
.custom_divisor
= tmxbr
* 32;
1134 port
->uart
.uartclk
= ioclk
/ 32;
1138 } else if (div_timer
== MNSCx_DIV_TIMER_8BIT
) {
1139 if (port
->uart
.custom_divisor
<= 255) {
1140 tmxmd
= TM2MD_SRC_IOCLK
;
1141 tmxbr
= port
->uart
.custom_divisor
;
1142 port
->uart
.uartclk
= ioclk
;
1145 if (port
->uart
.custom_divisor
/ 8 <= 255) {
1146 tmxmd
= TM2MD_SRC_IOCLK_8
;
1147 tmxbr
= port
->uart
.custom_divisor
/ 8;
1148 port
->uart
.custom_divisor
= tmxbr
* 8;
1149 port
->uart
.uartclk
= ioclk
/ 8;
1152 if (port
->uart
.custom_divisor
/ 32 <= 255) {
1153 tmxmd
= TM2MD_SRC_IOCLK_32
;
1154 tmxbr
= port
->uart
.custom_divisor
/ 32;
1155 port
->uart
.custom_divisor
= tmxbr
* 32;
1156 port
->uart
.uartclk
= ioclk
/ 32;
1162 switch (div_timer
) {
1163 case MNSCx_DIV_TIMER_16BIT
:
1164 port
->uart
.uartclk
= ioclk
;
1165 tmxmd
= TM8MD_SRC_IOCLK
;
1166 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1167 if (tmp
> 0 && tmp
<= 65535)
1170 port
->uart
.uartclk
= ioclk
/ 8;
1171 tmxmd
= TM8MD_SRC_IOCLK_8
;
1172 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1173 if (tmp
> 0 && tmp
<= 65535)
1176 port
->uart
.uartclk
= ioclk
/ 32;
1177 tmxmd
= TM8MD_SRC_IOCLK_32
;
1178 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1179 if (tmp
> 0 && tmp
<= 65535)
1183 case MNSCx_DIV_TIMER_8BIT
:
1184 port
->uart
.uartclk
= ioclk
;
1185 tmxmd
= TM2MD_SRC_IOCLK
;
1186 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1187 if (tmp
> 0 && tmp
<= 255)
1190 port
->uart
.uartclk
= ioclk
/ 8;
1191 tmxmd
= TM2MD_SRC_IOCLK_8
;
1192 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1193 if (tmp
> 0 && tmp
<= 255)
1196 port
->uart
.uartclk
= ioclk
/ 32;
1197 tmxmd
= TM2MD_SRC_IOCLK_32
;
1198 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1199 if (tmp
> 0 && tmp
<= 255)
1208 /* refuse to change to a baud rate we can't support */
1209 _debug("CAN'T SUPPORT");
1214 new->c_cflag
&= ~CBAUD
;
1215 new->c_cflag
|= (old
->c_cflag
& CBAUD
);
1217 goto try_alternative
;
1221 /* as a last resort, if the quotient is zero, default to 9600
1223 new->c_cflag
&= ~CBAUD
;
1224 new->c_cflag
|= B9600
;
1226 goto try_alternative
;
1229 /* hmmm... can't seem to support 9600 either
1230 * - we could try iterating through the speeds we know about to
1233 new->c_cflag
&= ~CBAUD
;
1236 if (div_timer
== MNSCx_DIV_TIMER_16BIT
)
1237 tmxmd
= TM8MD_SRC_IOCLK_32
;
1238 else if (div_timer
== MNSCx_DIV_TIMER_8BIT
)
1239 tmxmd
= TM2MD_SRC_IOCLK_32
;
1242 port
->uart
.uartclk
= ioclk
/ 32;
1247 _debug("UARTCLK: %u / %hu", port
->uart
.uartclk
, tmxbr
);
1249 /* make the changes */
1250 spin_lock_irqsave(&port
->uart
.lock
, flags
);
1252 uart_update_timeout(&port
->uart
, new->c_cflag
, baud
);
1254 /* set the timer to produce the required baud rate */
1255 switch (div_timer
) {
1256 case MNSCx_DIV_TIMER_16BIT
:
1258 *port
->_tmxbr
= tmxbr
;
1259 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1260 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1263 case MNSCx_DIV_TIMER_8BIT
:
1265 *(volatile u8
*) port
->_tmxbr
= (u8
) tmxbr
;
1266 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1267 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1271 /* CTS flow control flag and modem status interrupts */
1272 scxctr
&= ~(SC2CTR_TWE
| SC2CTR_TWS
);
1274 if (port
->type
== PORT_MN10300_CTS
&& cflag
& CRTSCTS
) {
1275 /* want to interrupt when CTS goes low if CTS is now
1276 * high and vice versa
1278 port
->tx_cts
= *port
->_status
;
1280 if (port
->tx_cts
& SC2STR_CTS
)
1281 scxctr
|= SC2CTR_TWE
;
1283 scxctr
|= SC2CTR_TWE
| SC2CTR_TWS
;
1286 /* set up parity check flag */
1287 port
->uart
.read_status_mask
= (1 << TTY_NORMAL
) | (1 << TTY_OVERRUN
);
1288 if (new->c_iflag
& INPCK
)
1289 port
->uart
.read_status_mask
|=
1290 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1291 if (new->c_iflag
& (BRKINT
| PARMRK
))
1292 port
->uart
.read_status_mask
|= (1 << TTY_BREAK
);
1294 /* characters to ignore */
1295 port
->uart
.ignore_status_mask
= 0;
1296 if (new->c_iflag
& IGNPAR
)
1297 port
->uart
.ignore_status_mask
|=
1298 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1299 if (new->c_iflag
& IGNBRK
) {
1300 port
->uart
.ignore_status_mask
|= (1 << TTY_BREAK
);
1302 * If we're ignoring parity and break indicators,
1303 * ignore overruns to (for real raw support).
1305 if (new->c_iflag
& IGNPAR
)
1306 port
->uart
.ignore_status_mask
|= (1 << TTY_OVERRUN
);
1309 /* Ignore all characters if CREAD is not set */
1310 if ((new->c_cflag
& CREAD
) == 0)
1311 port
->uart
.ignore_status_mask
|= (1 << TTY_NORMAL
);
1313 scxctr
|= *port
->_control
& (SC01CTR_TXE
| SC01CTR_RXE
| SC01CTR_BKE
);
1314 *port
->_control
= scxctr
;
1316 spin_unlock_irqrestore(&port
->uart
.lock
, flags
);
1320 * set the terminal I/O parameters
1322 static void mn10300_serial_set_termios(struct uart_port
*_port
,
1323 struct ktermios
*new,
1324 struct ktermios
*old
)
1326 struct mn10300_serial_port
*port
=
1327 container_of(_port
, struct mn10300_serial_port
, uart
);
1329 _enter("%s,%p,%p", port
->name
, new, old
);
1331 mn10300_serial_change_speed(port
, new, old
);
1333 /* handle turning off CRTSCTS */
1334 if (!(new->c_cflag
& CRTSCTS
)) {
1335 u16 ctr
= *port
->_control
;
1337 *port
->_control
= ctr
;
1340 /* change Transfer bit-order (LSB/MSB) */
1341 if (new->c_cflag
& CODMSB
)
1342 *port
->_control
|= SC01CTR_OD_MSBFIRST
; /* MSB MODE */
1344 *port
->_control
&= ~SC01CTR_OD_MSBFIRST
; /* LSB MODE */
1348 * return description of port type
1350 static const char *mn10300_serial_type(struct uart_port
*_port
)
1352 struct mn10300_serial_port
*port
=
1353 container_of(_port
, struct mn10300_serial_port
, uart
);
1355 if (port
->uart
.type
== PORT_MN10300_CTS
)
1356 return "MN10300 SIF_CTS";
1358 return "MN10300 SIF";
1362 * release I/O and memory regions in use by port
1364 static void mn10300_serial_release_port(struct uart_port
*_port
)
1366 struct mn10300_serial_port
*port
=
1367 container_of(_port
, struct mn10300_serial_port
, uart
);
1369 _enter("%s", port
->name
);
1371 release_mem_region((unsigned long) port
->_iobase
, 16);
1375 * request I/O and memory regions for port
1377 static int mn10300_serial_request_port(struct uart_port
*_port
)
1379 struct mn10300_serial_port
*port
=
1380 container_of(_port
, struct mn10300_serial_port
, uart
);
1382 _enter("%s", port
->name
);
1384 request_mem_region((unsigned long) port
->_iobase
, 16, port
->name
);
1389 * configure the type and reserve the ports
1391 static void mn10300_serial_config_port(struct uart_port
*_port
, int type
)
1393 struct mn10300_serial_port
*port
=
1394 container_of(_port
, struct mn10300_serial_port
, uart
);
1396 _enter("%s", port
->name
);
1398 port
->uart
.type
= PORT_MN10300
;
1400 if (port
->options
& MNSCx_OPT_CTS
)
1401 port
->uart
.type
= PORT_MN10300_CTS
;
1403 mn10300_serial_request_port(_port
);
1407 * verify serial parameters are suitable for this port type
1409 static int mn10300_serial_verify_port(struct uart_port
*_port
,
1410 struct serial_struct
*ss
)
1412 struct mn10300_serial_port
*port
=
1413 container_of(_port
, struct mn10300_serial_port
, uart
);
1414 void *mapbase
= (void *) (unsigned long) port
->uart
.mapbase
;
1416 _enter("%s", port
->name
);
1418 /* these things may not be changed */
1419 if (ss
->irq
!= port
->uart
.irq
||
1420 ss
->port
!= port
->uart
.iobase
||
1421 ss
->io_type
!= port
->uart
.iotype
||
1422 ss
->iomem_base
!= mapbase
||
1423 ss
->iomem_reg_shift
!= port
->uart
.regshift
||
1424 ss
->hub6
!= port
->uart
.hub6
||
1425 ss
->xmit_fifo_size
!= port
->uart
.fifosize
)
1428 /* type may be changed on a port that supports CTS */
1429 if (ss
->type
!= port
->uart
.type
) {
1430 if (!(port
->options
& MNSCx_OPT_CTS
))
1433 if (ss
->type
!= PORT_MN10300
&&
1434 ss
->type
!= PORT_MN10300_CTS
)
1442 * initialise the MN10300 on-chip UARTs
1444 static int __init
mn10300_serial_init(void)
1446 struct mn10300_serial_port
*port
;
1449 printk(KERN_INFO
"%s version %s (%s)\n",
1450 serial_name
, serial_version
, serial_revdate
);
1452 #if defined(CONFIG_MN10300_TTYSM2) && defined(CONFIG_AM33_2)
1455 SC2TIM
= 8; /* make the baud base of timer 2 IOCLK/8 */
1460 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
),
1461 mn10300_serial_vdma_interrupt
);
1463 ret
= uart_register_driver(&mn10300_serial_driver
);
1465 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1466 port
= mn10300_serial_ports
[i
];
1467 if (!port
|| port
->gdbstub
)
1470 switch (port
->clock_src
) {
1471 case MNSCx_CLOCK_SRC_IOCLK
:
1472 port
->ioclk
= MN10300_IOCLK
;
1475 #ifdef MN10300_IOBCLK
1476 case MNSCx_CLOCK_SRC_IOBCLK
:
1477 port
->ioclk
= MN10300_IOBCLK
;
1484 ret
= uart_add_one_port(&mn10300_serial_driver
,
1488 _debug("ERROR %d", -ret
);
1494 uart_unregister_driver(&mn10300_serial_driver
);
1500 __initcall(mn10300_serial_init
);
1503 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
1506 * print a string to the serial port without disturbing the real user of the
1508 * - the console must be locked by the caller
1510 static void mn10300_serial_console_write(struct console
*co
,
1511 const char *s
, unsigned count
)
1513 struct mn10300_serial_port
*port
;
1515 u16 scxctr
, txicr
, tmp
;
1518 port
= mn10300_serial_ports
[co
->index
];
1520 /* firstly hijack the serial port from the "virtual DMA" controller */
1522 txicr
= *port
->tx_icr
;
1523 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
1524 tmp
= *port
->tx_icr
;
1527 /* the transmitter may be disabled */
1528 scxctr
= *port
->_control
;
1529 if (!(scxctr
& SC01CTR_TXE
)) {
1530 /* restart the UART clock */
1531 tmxmd
= *port
->_tmxmd
;
1533 switch (port
->div_timer
) {
1534 case MNSCx_DIV_TIMER_16BIT
:
1536 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1537 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1540 case MNSCx_DIV_TIMER_8BIT
:
1542 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1543 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1547 /* enable the transmitter */
1548 *port
->_control
= (scxctr
& ~SC01CTR_BKE
) | SC01CTR_TXE
;
1550 } else if (scxctr
& SC01CTR_BKE
) {
1551 /* stop transmitting BREAK */
1552 *port
->_control
= (scxctr
& ~SC01CTR_BKE
);
1555 /* send the chars into the serial port (with LF -> LFCR conversion) */
1556 for (i
= 0; i
< count
; i
++) {
1559 while (*port
->_status
& SC01STR_TBF
)
1561 *(u8
*) port
->_txb
= ch
;
1564 while (*port
->_status
& SC01STR_TBF
)
1566 *(u8
*) port
->_txb
= 0xd;
1570 /* can't let the transmitter be turned off if it's actually
1572 while (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
))
1575 /* disable the transmitter if we re-enabled it */
1576 if (!(scxctr
& SC01CTR_TXE
))
1577 *port
->_control
= scxctr
;
1580 *port
->tx_icr
= txicr
;
1581 tmp
= *port
->tx_icr
;
1586 * set up a serial port as a console
1587 * - construct a cflag setting for the first rs_open()
1588 * - initialize the serial port
1589 * - return non-zero if we didn't find a serial port.
1591 static int __init
mn10300_serial_console_setup(struct console
*co
,
1594 struct mn10300_serial_port
*port
;
1595 int i
, parity
= 'n', baud
= 9600, bits
= 8, flow
= 0;
1597 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1598 port
= mn10300_serial_ports
[i
];
1599 if (port
&& !port
->gdbstub
&& port
->uart
.line
== co
->index
)
1606 switch (port
->clock_src
) {
1607 case MNSCx_CLOCK_SRC_IOCLK
:
1608 port
->ioclk
= MN10300_IOCLK
;
1611 #ifdef MN10300_IOBCLK
1612 case MNSCx_CLOCK_SRC_IOBCLK
:
1613 port
->ioclk
= MN10300_IOBCLK
;
1621 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1623 return uart_set_options(&port
->uart
, co
, baud
, parity
, bits
, flow
);
1629 static int __init
mn10300_serial_console_init(void)
1631 register_console(&mn10300_serial_console
);
1635 console_initcall(mn10300_serial_console_init
);