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_nop(unsigned int irq
)
391 static struct irq_chip mn10300_serial_pic
= {
393 .ack
= mn10300_serial_mask_ack
,
394 .mask
= mn10300_serial_mask_ack
,
395 .mask_ack
= mn10300_serial_mask_ack
,
396 .unmask
= mn10300_serial_nop
,
397 .end
= mn10300_serial_nop
,
402 * serial virtual DMA interrupt jump table
404 struct mn10300_serial_int mn10300_serial_int_tbl
[NR_IRQS
];
406 static void mn10300_serial_dis_tx_intr(struct mn10300_serial_port
*port
)
411 flags
= arch_local_cli_save();
412 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
414 arch_local_irq_restore(flags
);
417 static void mn10300_serial_en_tx_intr(struct mn10300_serial_port
*port
)
422 flags
= arch_local_cli_save();
424 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
) | GxICR_ENABLE
;
426 arch_local_irq_restore(flags
);
429 static void mn10300_serial_dis_rx_intr(struct mn10300_serial_port
*port
)
434 flags
= arch_local_cli_save();
435 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
437 arch_local_irq_restore(flags
);
441 * multi-bit equivalent of test_and_clear_bit()
443 static int mask_test_and_clear(volatile u8
*ptr
, u8 mask
)
446 asm volatile(" bclr %1,(%2) \n"
448 : "=d"(epsw
) : "d"(mask
), "a"(ptr
)
450 return !(epsw
& EPSW_FLAG_Z
);
454 * receive chars from the ring buffer for this serial port
455 * - must do break detection here (not done in the UART)
457 static void mn10300_serial_receive_interrupt(struct mn10300_serial_port
*port
)
459 struct uart_icount
*icount
= &port
->uart
.icount
;
460 struct tty_struct
*tty
= port
->uart
.state
->port
.tty
;
463 u8 st
, ch
, push
, status
, overrun
;
465 _enter("%s", port
->name
);
469 count
= CIRC_CNT(port
->rx_inp
, port
->rx_outp
, MNSC_BUFFER_SIZE
);
470 count
= tty_buffer_request_room(tty
, count
);
472 if (!tty
->low_latency
)
473 tty_flip_buffer_push(tty
);
478 /* pull chars out of the hat */
480 if (ix
== port
->rx_inp
) {
481 if (push
&& !tty
->low_latency
)
482 tty_flip_buffer_push(tty
);
486 ch
= port
->rx_buffer
[ix
++];
487 st
= port
->rx_buffer
[ix
++];
489 port
->rx_outp
= ix
& (MNSC_BUFFER_SIZE
- 1);
490 port
->uart
.icount
.rx
++;
492 st
&= SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
;
496 /* the UART doesn't detect BREAK, so we have to do that ourselves
497 * - it starts as a framing error on a NUL character
498 * - then we count another two NUL characters before issuing TTY_BREAK
499 * - then we end on a normal char or one that has all the bottom bits
500 * zero and the top bits set
502 switch (port
->rx_brk
) {
504 /* not breaking at the moment */
508 if (st
& SC01STR_FEF
&& ch
== 0) {
515 if (st
& SC01STR_FEF
&& ch
== 0) {
517 _proto("Rx Break Detected");
519 if (uart_handle_break(&port
->uart
))
521 status
|= 1 << TTY_BREAK
;
527 if (st
& (SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
))
528 goto try_again
; /* still breaking */
530 port
->rx_brk
= 0; /* end of the break */
542 /* discard char at probable break end */
549 /* handle framing error */
550 if (st
& SC01STR_FEF
) {
552 /* framing error with NUL char is probably a BREAK */
557 _proto("Rx Framing Error");
559 status
|= 1 << TTY_FRAME
;
562 /* handle parity error */
563 if (st
& SC01STR_PEF
) {
564 _proto("Rx Parity Error");
569 /* handle normal char */
571 if (uart_handle_sysrq_char(&port
->uart
, ch
))
573 status
= (1 << TTY_NORMAL
);
576 /* handle overrun error */
577 if (st
& SC01STR_OEF
) {
581 _proto("Rx Overrun Error");
587 status
&= port
->uart
.read_status_mask
;
589 if (!overrun
&& !(status
& port
->uart
.ignore_status_mask
)) {
592 if (status
& (1 << TTY_BREAK
))
594 else if (status
& (1 << TTY_PARITY
))
596 else if (status
& (1 << TTY_FRAME
))
601 tty_insert_flip_char(tty
, ch
, flag
);
604 /* overrun is special, since it's reported immediately, and doesn't
605 * affect the current character
608 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
612 if (!tty
->low_latency
)
613 tty_flip_buffer_push(tty
);
627 * handle an interrupt from the serial transmission "virtual DMA" driver
628 * - note: the interrupt routine will disable its own interrupts when the Tx
631 static void mn10300_serial_transmit_interrupt(struct mn10300_serial_port
*port
)
633 _enter("%s", port
->name
);
635 if (!port
->uart
.state
|| !port
->uart
.state
->port
.tty
) {
636 mn10300_serial_dis_tx_intr(port
);
640 if (uart_tx_stopped(&port
->uart
) ||
641 uart_circ_empty(&port
->uart
.state
->xmit
))
642 mn10300_serial_dis_tx_intr(port
);
644 if (uart_circ_chars_pending(&port
->uart
.state
->xmit
) < WAKEUP_CHARS
)
645 uart_write_wakeup(&port
->uart
);
649 * deal with a change in the status of the CTS line
651 static void mn10300_serial_cts_changed(struct mn10300_serial_port
*port
, u8 st
)
656 port
->uart
.icount
.cts
++;
658 /* flip the CTS state selector flag to interrupt when it changes
660 ctr
= *port
->_control
;
662 *port
->_control
= ctr
;
664 uart_handle_cts_change(&port
->uart
, st
& SC2STR_CTS
);
665 wake_up_interruptible(&port
->uart
.state
->port
.delta_msr_wait
);
669 * handle a virtual interrupt generated by the lower level "virtual DMA"
670 * routines (irq is the baud timer interrupt)
672 static irqreturn_t
mn10300_serial_interrupt(int irq
, void *dev_id
)
674 struct mn10300_serial_port
*port
= dev_id
;
677 spin_lock(&port
->uart
.lock
);
679 if (port
->intr_flags
) {
680 _debug("INT %s: %x", port
->name
, port
->intr_flags
);
682 if (mask_test_and_clear(&port
->intr_flags
, MNSCx_RX_AVAIL
))
683 mn10300_serial_receive_interrupt(port
);
685 if (mask_test_and_clear(&port
->intr_flags
,
686 MNSCx_TX_SPACE
| MNSCx_TX_EMPTY
))
687 mn10300_serial_transmit_interrupt(port
);
690 /* the only modem control line amongst the whole lot is CTS on
692 if (port
->type
== PORT_MN10300_CTS
) {
694 if ((port
->tx_cts
^ st
) & SC2STR_CTS
)
695 mn10300_serial_cts_changed(port
, st
);
698 spin_unlock(&port
->uart
.lock
);
704 * return indication of whether the hardware transmit buffer is empty
706 static unsigned int mn10300_serial_tx_empty(struct uart_port
*_port
)
708 struct mn10300_serial_port
*port
=
709 container_of(_port
, struct mn10300_serial_port
, uart
);
711 _enter("%s", port
->name
);
713 return (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
)) ?
718 * set the modem control lines (we don't have any)
720 static void mn10300_serial_set_mctrl(struct uart_port
*_port
,
723 struct mn10300_serial_port
*port
__attribute__ ((unused
)) =
724 container_of(_port
, struct mn10300_serial_port
, uart
);
726 _enter("%s,%x", port
->name
, mctrl
);
730 * get the modem control line statuses
732 static unsigned int mn10300_serial_get_mctrl(struct uart_port
*_port
)
734 struct mn10300_serial_port
*port
=
735 container_of(_port
, struct mn10300_serial_port
, uart
);
737 _enter("%s", port
->name
);
739 if (port
->type
== PORT_MN10300_CTS
&& !(*port
->_status
& SC2STR_CTS
))
740 return TIOCM_CAR
| TIOCM_DSR
;
742 return TIOCM_CAR
| TIOCM_CTS
| TIOCM_DSR
;
746 * stop transmitting characters
748 static void mn10300_serial_stop_tx(struct uart_port
*_port
)
750 struct mn10300_serial_port
*port
=
751 container_of(_port
, struct mn10300_serial_port
, uart
);
753 _enter("%s", port
->name
);
755 /* disable the virtual DMA */
756 mn10300_serial_dis_tx_intr(port
);
760 * start transmitting characters
761 * - jump-start transmission if it has stalled
762 * - enable the serial Tx interrupt (used by the virtual DMA controller)
763 * - force an interrupt to happen if necessary
765 static void mn10300_serial_start_tx(struct uart_port
*_port
)
767 struct mn10300_serial_port
*port
=
768 container_of(_port
, struct mn10300_serial_port
, uart
);
774 CIRC_CNT(&port
->uart
.state
->xmit
.head
,
775 &port
->uart
.state
->xmit
.tail
,
778 /* kick the virtual DMA controller */
783 if (*port
->_status
& SC01STR_TBF
)
784 x
&= ~(GxICR_REQUEST
| GxICR_DETECT
);
786 x
|= GxICR_REQUEST
| GxICR_DETECT
;
788 _debug("CTR=%04hx ICR=%02hx STR=%04x TMD=%02hx TBR=%04hx ICR=%04hx",
789 *port
->_control
, *port
->_intr
, *port
->_status
,
791 (port
->div_timer
== MNSCx_DIV_TIMER_8BIT
) ?
792 *(volatile u8
*)port
->_tmxbr
: *port
->_tmxbr
,
801 * transmit a high-priority XON/XOFF character
803 static void mn10300_serial_send_xchar(struct uart_port
*_port
, char ch
)
805 struct mn10300_serial_port
*port
=
806 container_of(_port
, struct mn10300_serial_port
, uart
);
808 _enter("%s,%02x", port
->name
, ch
);
810 if (likely(port
->gdbstub
)) {
813 mn10300_serial_en_tx_intr(port
);
818 * stop receiving characters
819 * - called whilst the port is being closed
821 static void mn10300_serial_stop_rx(struct uart_port
*_port
)
823 struct mn10300_serial_port
*port
=
824 container_of(_port
, struct mn10300_serial_port
, uart
);
828 _enter("%s", port
->name
);
830 ctr
= *port
->_control
;
832 *port
->_control
= ctr
;
834 mn10300_serial_dis_rx_intr(port
);
838 * enable modem status interrupts
840 static void mn10300_serial_enable_ms(struct uart_port
*_port
)
842 struct mn10300_serial_port
*port
=
843 container_of(_port
, struct mn10300_serial_port
, uart
);
847 _enter("%s", port
->name
);
849 if (port
->type
== PORT_MN10300_CTS
) {
850 /* want to interrupt when CTS goes low if CTS is now high and
853 port
->tx_cts
= *port
->_status
;
855 cts
= (port
->tx_cts
& SC2STR_CTS
) ?
856 SC2CTR_TWE
: SC2CTR_TWE
| SC2CTR_TWS
;
858 ctr
= *port
->_control
;
861 *port
->_control
= ctr
;
863 mn10300_serial_en_tx_intr(port
);
868 * transmit or cease transmitting a break signal
870 static void mn10300_serial_break_ctl(struct uart_port
*_port
, int ctl
)
872 struct mn10300_serial_port
*port
=
873 container_of(_port
, struct mn10300_serial_port
, uart
);
875 _enter("%s,%d", port
->name
, ctl
);
878 /* tell the virtual DMA handler to assert BREAK */
880 mn10300_serial_en_tx_intr(port
);
883 *port
->_control
&= ~SC01CTR_BKE
;
884 mn10300_serial_en_tx_intr(port
);
889 * grab the interrupts and enable the port for reception
891 static int mn10300_serial_startup(struct uart_port
*_port
)
893 struct mn10300_serial_port
*port
=
894 container_of(_port
, struct mn10300_serial_port
, uart
);
895 struct mn10300_serial_int
*pint
;
897 _enter("%s{%d}", port
->name
, port
->gdbstub
);
899 if (unlikely(port
->gdbstub
))
902 /* allocate an Rx buffer for the virtual DMA handler */
903 port
->rx_buffer
= kmalloc(MNSC_BUFFER_SIZE
, GFP_KERNEL
);
904 if (!port
->rx_buffer
)
907 port
->rx_inp
= port
->rx_outp
= 0;
909 /* finally, enable the device */
910 *port
->_intr
= SC01ICR_TI
;
911 *port
->_control
|= SC01CTR_TXE
| SC01CTR_RXE
;
913 pint
= &mn10300_serial_int_tbl
[port
->rx_irq
];
915 pint
->vdma
= mn10300_serial_vdma_rx_handler
;
916 pint
= &mn10300_serial_int_tbl
[port
->tx_irq
];
918 pint
->vdma
= mn10300_serial_vdma_tx_handler
;
920 set_intr_level(port
->rx_irq
,
921 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
));
922 set_intr_level(port
->tx_irq
,
923 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
));
924 set_irq_chip(port
->tm_irq
, &mn10300_serial_pic
);
926 if (request_irq(port
->rx_irq
, mn10300_serial_interrupt
,
927 IRQF_DISABLED
, port
->rx_name
, port
) < 0)
930 if (request_irq(port
->tx_irq
, mn10300_serial_interrupt
,
931 IRQF_DISABLED
, port
->tx_name
, port
) < 0)
934 if (request_irq(port
->tm_irq
, mn10300_serial_interrupt
,
935 IRQF_DISABLED
, port
->tm_name
, port
) < 0)
937 mn10300_serial_mask_ack(port
->tm_irq
);
942 free_irq(port
->tx_irq
, port
);
944 free_irq(port
->rx_irq
, port
);
946 kfree(port
->rx_buffer
);
947 port
->rx_buffer
= NULL
;
952 * shutdown the port and release interrupts
954 static void mn10300_serial_shutdown(struct uart_port
*_port
)
957 struct mn10300_serial_port
*port
=
958 container_of(_port
, struct mn10300_serial_port
, uart
);
960 _enter("%s", port
->name
);
962 /* disable the serial port and its baud rate timer */
964 *port
->_control
&= ~(SC01CTR_TXE
| SC01CTR_RXE
| SC01CTR_BKE
);
967 if (port
->rx_buffer
) {
968 void *buf
= port
->rx_buffer
;
969 port
->rx_buffer
= NULL
;
973 /* disable all intrs */
974 free_irq(port
->tm_irq
, port
);
975 free_irq(port
->rx_irq
, port
);
976 free_irq(port
->tx_irq
, port
);
979 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
981 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
987 * this routine is called to set the UART divisor registers to match the
988 * specified baud rate for a serial port.
990 static void mn10300_serial_change_speed(struct mn10300_serial_port
*port
,
991 struct ktermios
*new,
992 struct ktermios
*old
)
995 unsigned long ioclk
= port
->ioclk
;
997 int baud
, bits
, xdiv
, tmp
;
1000 u8 div_timer
= port
->div_timer
;
1002 _enter("%s{%lu}", port
->name
, ioclk
);
1004 /* byte size and parity */
1005 cflag
= new->c_cflag
;
1006 switch (cflag
& CSIZE
) {
1007 case CS7
: scxctr
= SC01CTR_CLN_7BIT
; bits
= 9; break;
1008 case CS8
: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1009 default: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1012 if (cflag
& CSTOPB
) {
1013 scxctr
|= SC01CTR_STB_2BIT
;
1017 if (cflag
& PARENB
) {
1020 scxctr
|= SC01CTR_PB_ODD
;
1022 else if (cflag
& CMSPAR
)
1023 scxctr
|= SC01CTR_PB_FIXED0
;
1026 scxctr
|= SC01CTR_PB_EVEN
;
1029 /* Determine divisor based on baud rate */
1032 switch (port
->uart
.line
) {
1033 #ifdef CONFIG_MN10300_TTYSM0
1034 case 0: /* ttySM0 */
1035 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
1036 scxctr
|= SC0CTR_CK_TM8UFLOW_8
;
1037 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
1038 scxctr
|= SC0CTR_CK_TM0UFLOW_8
;
1039 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
1040 scxctr
|= SC0CTR_CK_TM2UFLOW_8
;
1042 #error "Unknown config for ttySM0"
1045 #endif /* CONFIG_MN10300_TTYSM0 */
1047 #ifdef CONFIG_MN10300_TTYSM1
1048 case 1: /* ttySM1 */
1049 #if defined(CONFIG_AM33_2) || defined(CONFIG_AM33_3)
1050 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
1051 scxctr
|= SC1CTR_CK_TM9UFLOW_8
;
1052 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
1053 scxctr
|= SC1CTR_CK_TM3UFLOW_8
;
1055 #error "Unknown config for ttySM1"
1057 #else /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1058 #if defined(CONFIG_MN10300_TTYSM1_TIMER12)
1059 scxctr
|= SC1CTR_CK_TM12UFLOW_8
;
1061 #error "Unknown config for ttySM1"
1063 #endif /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1065 #endif /* CONFIG_MN10300_TTYSM1 */
1067 #ifdef CONFIG_MN10300_TTYSM2
1068 case 2: /* ttySM2 */
1069 #if defined(CONFIG_AM33_2)
1070 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
1071 scxctr
|= SC2CTR_CK_TM10UFLOW
;
1073 #error "Unknown config for ttySM2"
1075 #else /* CONFIG_AM33_2 */
1076 #if defined(CONFIG_MN10300_TTYSM2_TIMER9)
1077 scxctr
|= SC2CTR_CK_TM9UFLOW_8
;
1078 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
1079 scxctr
|= SC2CTR_CK_TM1UFLOW_8
;
1080 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
1081 scxctr
|= SC2CTR_CK_TM3UFLOW_8
;
1083 #error "Unknown config for ttySM2"
1085 #endif /* CONFIG_AM33_2 */
1087 #endif /* CONFIG_MN10300_TTYSM2 */
1094 baud
= uart_get_baud_rate(&port
->uart
, new, old
, 0,
1097 _debug("ALT %d [baud %d]", battempt
, baud
);
1100 baud
= 9600; /* B0 transition handled in rs_set_termios */
1103 baud
= 269; /* 134 is really 134.5 */
1107 if (baud
== 38400 &&
1108 (port
->uart
.flags
& UPF_SPD_MASK
) == UPF_SPD_CUST
1110 _debug("CUSTOM %u", port
->uart
.custom_divisor
);
1112 if (div_timer
== MNSCx_DIV_TIMER_16BIT
) {
1113 if (port
->uart
.custom_divisor
<= 65535) {
1114 tmxmd
= TM8MD_SRC_IOCLK
;
1115 tmxbr
= port
->uart
.custom_divisor
;
1116 port
->uart
.uartclk
= ioclk
;
1119 if (port
->uart
.custom_divisor
/ 8 <= 65535) {
1120 tmxmd
= TM8MD_SRC_IOCLK_8
;
1121 tmxbr
= port
->uart
.custom_divisor
/ 8;
1122 port
->uart
.custom_divisor
= tmxbr
* 8;
1123 port
->uart
.uartclk
= ioclk
/ 8;
1126 if (port
->uart
.custom_divisor
/ 32 <= 65535) {
1127 tmxmd
= TM8MD_SRC_IOCLK_32
;
1128 tmxbr
= port
->uart
.custom_divisor
/ 32;
1129 port
->uart
.custom_divisor
= tmxbr
* 32;
1130 port
->uart
.uartclk
= ioclk
/ 32;
1134 } else if (div_timer
== MNSCx_DIV_TIMER_8BIT
) {
1135 if (port
->uart
.custom_divisor
<= 255) {
1136 tmxmd
= TM2MD_SRC_IOCLK
;
1137 tmxbr
= port
->uart
.custom_divisor
;
1138 port
->uart
.uartclk
= ioclk
;
1141 if (port
->uart
.custom_divisor
/ 8 <= 255) {
1142 tmxmd
= TM2MD_SRC_IOCLK_8
;
1143 tmxbr
= port
->uart
.custom_divisor
/ 8;
1144 port
->uart
.custom_divisor
= tmxbr
* 8;
1145 port
->uart
.uartclk
= ioclk
/ 8;
1148 if (port
->uart
.custom_divisor
/ 32 <= 255) {
1149 tmxmd
= TM2MD_SRC_IOCLK_32
;
1150 tmxbr
= port
->uart
.custom_divisor
/ 32;
1151 port
->uart
.custom_divisor
= tmxbr
* 32;
1152 port
->uart
.uartclk
= ioclk
/ 32;
1158 switch (div_timer
) {
1159 case MNSCx_DIV_TIMER_16BIT
:
1160 port
->uart
.uartclk
= ioclk
;
1161 tmxmd
= TM8MD_SRC_IOCLK
;
1162 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1163 if (tmp
> 0 && tmp
<= 65535)
1166 port
->uart
.uartclk
= ioclk
/ 8;
1167 tmxmd
= TM8MD_SRC_IOCLK_8
;
1168 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1169 if (tmp
> 0 && tmp
<= 65535)
1172 port
->uart
.uartclk
= ioclk
/ 32;
1173 tmxmd
= TM8MD_SRC_IOCLK_32
;
1174 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1175 if (tmp
> 0 && tmp
<= 65535)
1179 case MNSCx_DIV_TIMER_8BIT
:
1180 port
->uart
.uartclk
= ioclk
;
1181 tmxmd
= TM2MD_SRC_IOCLK
;
1182 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1183 if (tmp
> 0 && tmp
<= 255)
1186 port
->uart
.uartclk
= ioclk
/ 8;
1187 tmxmd
= TM2MD_SRC_IOCLK_8
;
1188 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1189 if (tmp
> 0 && tmp
<= 255)
1192 port
->uart
.uartclk
= ioclk
/ 32;
1193 tmxmd
= TM2MD_SRC_IOCLK_32
;
1194 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1195 if (tmp
> 0 && tmp
<= 255)
1204 /* refuse to change to a baud rate we can't support */
1205 _debug("CAN'T SUPPORT");
1210 new->c_cflag
&= ~CBAUD
;
1211 new->c_cflag
|= (old
->c_cflag
& CBAUD
);
1213 goto try_alternative
;
1217 /* as a last resort, if the quotient is zero, default to 9600
1219 new->c_cflag
&= ~CBAUD
;
1220 new->c_cflag
|= B9600
;
1222 goto try_alternative
;
1225 /* hmmm... can't seem to support 9600 either
1226 * - we could try iterating through the speeds we know about to
1229 new->c_cflag
&= ~CBAUD
;
1232 if (div_timer
== MNSCx_DIV_TIMER_16BIT
)
1233 tmxmd
= TM8MD_SRC_IOCLK_32
;
1234 else if (div_timer
== MNSCx_DIV_TIMER_8BIT
)
1235 tmxmd
= TM2MD_SRC_IOCLK_32
;
1238 port
->uart
.uartclk
= ioclk
/ 32;
1243 _debug("UARTCLK: %u / %hu", port
->uart
.uartclk
, tmxbr
);
1245 /* make the changes */
1246 spin_lock_irqsave(&port
->uart
.lock
, flags
);
1248 uart_update_timeout(&port
->uart
, new->c_cflag
, baud
);
1250 /* set the timer to produce the required baud rate */
1251 switch (div_timer
) {
1252 case MNSCx_DIV_TIMER_16BIT
:
1254 *port
->_tmxbr
= tmxbr
;
1255 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1256 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1259 case MNSCx_DIV_TIMER_8BIT
:
1261 *(volatile u8
*) port
->_tmxbr
= (u8
) tmxbr
;
1262 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1263 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1267 /* CTS flow control flag and modem status interrupts */
1268 scxctr
&= ~(SC2CTR_TWE
| SC2CTR_TWS
);
1270 if (port
->type
== PORT_MN10300_CTS
&& cflag
& CRTSCTS
) {
1271 /* want to interrupt when CTS goes low if CTS is now
1272 * high and vice versa
1274 port
->tx_cts
= *port
->_status
;
1276 if (port
->tx_cts
& SC2STR_CTS
)
1277 scxctr
|= SC2CTR_TWE
;
1279 scxctr
|= SC2CTR_TWE
| SC2CTR_TWS
;
1282 /* set up parity check flag */
1283 port
->uart
.read_status_mask
= (1 << TTY_NORMAL
) | (1 << TTY_OVERRUN
);
1284 if (new->c_iflag
& INPCK
)
1285 port
->uart
.read_status_mask
|=
1286 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1287 if (new->c_iflag
& (BRKINT
| PARMRK
))
1288 port
->uart
.read_status_mask
|= (1 << TTY_BREAK
);
1290 /* characters to ignore */
1291 port
->uart
.ignore_status_mask
= 0;
1292 if (new->c_iflag
& IGNPAR
)
1293 port
->uart
.ignore_status_mask
|=
1294 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1295 if (new->c_iflag
& IGNBRK
) {
1296 port
->uart
.ignore_status_mask
|= (1 << TTY_BREAK
);
1298 * If we're ignoring parity and break indicators,
1299 * ignore overruns to (for real raw support).
1301 if (new->c_iflag
& IGNPAR
)
1302 port
->uart
.ignore_status_mask
|= (1 << TTY_OVERRUN
);
1305 /* Ignore all characters if CREAD is not set */
1306 if ((new->c_cflag
& CREAD
) == 0)
1307 port
->uart
.ignore_status_mask
|= (1 << TTY_NORMAL
);
1309 scxctr
|= *port
->_control
& (SC01CTR_TXE
| SC01CTR_RXE
| SC01CTR_BKE
);
1310 *port
->_control
= scxctr
;
1312 spin_unlock_irqrestore(&port
->uart
.lock
, flags
);
1316 * set the terminal I/O parameters
1318 static void mn10300_serial_set_termios(struct uart_port
*_port
,
1319 struct ktermios
*new,
1320 struct ktermios
*old
)
1322 struct mn10300_serial_port
*port
=
1323 container_of(_port
, struct mn10300_serial_port
, uart
);
1325 _enter("%s,%p,%p", port
->name
, new, old
);
1327 mn10300_serial_change_speed(port
, new, old
);
1329 /* handle turning off CRTSCTS */
1330 if (!(new->c_cflag
& CRTSCTS
)) {
1331 u16 ctr
= *port
->_control
;
1333 *port
->_control
= ctr
;
1336 /* change Transfer bit-order (LSB/MSB) */
1337 if (new->c_cflag
& CODMSB
)
1338 *port
->_control
|= SC01CTR_OD_MSBFIRST
; /* MSB MODE */
1340 *port
->_control
&= ~SC01CTR_OD_MSBFIRST
; /* LSB MODE */
1344 * return description of port type
1346 static const char *mn10300_serial_type(struct uart_port
*_port
)
1348 struct mn10300_serial_port
*port
=
1349 container_of(_port
, struct mn10300_serial_port
, uart
);
1351 if (port
->uart
.type
== PORT_MN10300_CTS
)
1352 return "MN10300 SIF_CTS";
1354 return "MN10300 SIF";
1358 * release I/O and memory regions in use by port
1360 static void mn10300_serial_release_port(struct uart_port
*_port
)
1362 struct mn10300_serial_port
*port
=
1363 container_of(_port
, struct mn10300_serial_port
, uart
);
1365 _enter("%s", port
->name
);
1367 release_mem_region((unsigned long) port
->_iobase
, 16);
1371 * request I/O and memory regions for port
1373 static int mn10300_serial_request_port(struct uart_port
*_port
)
1375 struct mn10300_serial_port
*port
=
1376 container_of(_port
, struct mn10300_serial_port
, uart
);
1378 _enter("%s", port
->name
);
1380 request_mem_region((unsigned long) port
->_iobase
, 16, port
->name
);
1385 * configure the type and reserve the ports
1387 static void mn10300_serial_config_port(struct uart_port
*_port
, int type
)
1389 struct mn10300_serial_port
*port
=
1390 container_of(_port
, struct mn10300_serial_port
, uart
);
1392 _enter("%s", port
->name
);
1394 port
->uart
.type
= PORT_MN10300
;
1396 if (port
->options
& MNSCx_OPT_CTS
)
1397 port
->uart
.type
= PORT_MN10300_CTS
;
1399 mn10300_serial_request_port(_port
);
1403 * verify serial parameters are suitable for this port type
1405 static int mn10300_serial_verify_port(struct uart_port
*_port
,
1406 struct serial_struct
*ss
)
1408 struct mn10300_serial_port
*port
=
1409 container_of(_port
, struct mn10300_serial_port
, uart
);
1410 void *mapbase
= (void *) (unsigned long) port
->uart
.mapbase
;
1412 _enter("%s", port
->name
);
1414 /* these things may not be changed */
1415 if (ss
->irq
!= port
->uart
.irq
||
1416 ss
->port
!= port
->uart
.iobase
||
1417 ss
->io_type
!= port
->uart
.iotype
||
1418 ss
->iomem_base
!= mapbase
||
1419 ss
->iomem_reg_shift
!= port
->uart
.regshift
||
1420 ss
->hub6
!= port
->uart
.hub6
||
1421 ss
->xmit_fifo_size
!= port
->uart
.fifosize
)
1424 /* type may be changed on a port that supports CTS */
1425 if (ss
->type
!= port
->uart
.type
) {
1426 if (!(port
->options
& MNSCx_OPT_CTS
))
1429 if (ss
->type
!= PORT_MN10300
&&
1430 ss
->type
!= PORT_MN10300_CTS
)
1438 * initialise the MN10300 on-chip UARTs
1440 static int __init
mn10300_serial_init(void)
1442 struct mn10300_serial_port
*port
;
1445 printk(KERN_INFO
"%s version %s (%s)\n",
1446 serial_name
, serial_version
, serial_revdate
);
1448 #if defined(CONFIG_MN10300_TTYSM2) && defined(CONFIG_AM33_2)
1451 SC2TIM
= 8; /* make the baud base of timer 2 IOCLK/8 */
1456 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
),
1457 mn10300_serial_vdma_interrupt
);
1459 ret
= uart_register_driver(&mn10300_serial_driver
);
1461 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1462 port
= mn10300_serial_ports
[i
];
1463 if (!port
|| port
->gdbstub
)
1466 switch (port
->clock_src
) {
1467 case MNSCx_CLOCK_SRC_IOCLK
:
1468 port
->ioclk
= MN10300_IOCLK
;
1471 #ifdef MN10300_IOBCLK
1472 case MNSCx_CLOCK_SRC_IOBCLK
:
1473 port
->ioclk
= MN10300_IOBCLK
;
1480 ret
= uart_add_one_port(&mn10300_serial_driver
,
1484 _debug("ERROR %d", -ret
);
1490 uart_unregister_driver(&mn10300_serial_driver
);
1496 __initcall(mn10300_serial_init
);
1499 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
1502 * print a string to the serial port without disturbing the real user of the
1504 * - the console must be locked by the caller
1506 static void mn10300_serial_console_write(struct console
*co
,
1507 const char *s
, unsigned count
)
1509 struct mn10300_serial_port
*port
;
1511 u16 scxctr
, txicr
, tmp
;
1514 port
= mn10300_serial_ports
[co
->index
];
1516 /* firstly hijack the serial port from the "virtual DMA" controller */
1518 txicr
= *port
->tx_icr
;
1519 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
1520 tmp
= *port
->tx_icr
;
1523 /* the transmitter may be disabled */
1524 scxctr
= *port
->_control
;
1525 if (!(scxctr
& SC01CTR_TXE
)) {
1526 /* restart the UART clock */
1527 tmxmd
= *port
->_tmxmd
;
1529 switch (port
->div_timer
) {
1530 case MNSCx_DIV_TIMER_16BIT
:
1532 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1533 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1536 case MNSCx_DIV_TIMER_8BIT
:
1538 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1539 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1543 /* enable the transmitter */
1544 *port
->_control
= (scxctr
& ~SC01CTR_BKE
) | SC01CTR_TXE
;
1546 } else if (scxctr
& SC01CTR_BKE
) {
1547 /* stop transmitting BREAK */
1548 *port
->_control
= (scxctr
& ~SC01CTR_BKE
);
1551 /* send the chars into the serial port (with LF -> LFCR conversion) */
1552 for (i
= 0; i
< count
; i
++) {
1555 while (*port
->_status
& SC01STR_TBF
)
1557 *(u8
*) port
->_txb
= ch
;
1560 while (*port
->_status
& SC01STR_TBF
)
1562 *(u8
*) port
->_txb
= 0xd;
1566 /* can't let the transmitter be turned off if it's actually
1568 while (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
))
1571 /* disable the transmitter if we re-enabled it */
1572 if (!(scxctr
& SC01CTR_TXE
))
1573 *port
->_control
= scxctr
;
1576 *port
->tx_icr
= txicr
;
1577 tmp
= *port
->tx_icr
;
1582 * set up a serial port as a console
1583 * - construct a cflag setting for the first rs_open()
1584 * - initialize the serial port
1585 * - return non-zero if we didn't find a serial port.
1587 static int __init
mn10300_serial_console_setup(struct console
*co
,
1590 struct mn10300_serial_port
*port
;
1591 int i
, parity
= 'n', baud
= 9600, bits
= 8, flow
= 0;
1593 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1594 port
= mn10300_serial_ports
[i
];
1595 if (port
&& !port
->gdbstub
&& port
->uart
.line
== co
->index
)
1602 switch (port
->clock_src
) {
1603 case MNSCx_CLOCK_SRC_IOCLK
:
1604 port
->ioclk
= MN10300_IOCLK
;
1607 #ifdef MN10300_IOBCLK
1608 case MNSCx_CLOCK_SRC_IOBCLK
:
1609 port
->ioclk
= MN10300_IOBCLK
;
1617 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1619 return uart_set_options(&port
->uart
, co
, baud
, parity
, bits
, flow
);
1625 static int __init
mn10300_serial_console_init(void)
1627 register_console(&mn10300_serial_console
);
1631 console_initcall(mn10300_serial_console_init
);