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>
41 #include <asm/bitops.h>
42 #include <asm/serial-regs.h>
43 #include <unit/timex.h>
44 #include "mn10300-serial.h"
48 #define GxICR(X) CROSS_GxICR(X, 0)
49 #endif /* CONFIG_SMP */
51 #define kenter(FMT, ...) \
52 printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
53 #define _enter(FMT, ...) \
54 no_printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
55 #define kdebug(FMT, ...) \
56 printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
57 #define _debug(FMT, ...) \
58 no_printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
59 #define kproto(FMT, ...) \
60 printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
61 #define _proto(FMT, ...) \
62 no_printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
65 /* c_cflag bit meaning */
66 #define CODMSB 004000000000 /* change Transfer bit-order */
71 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
72 static void mn10300_serial_console_write(struct console
*co
,
73 const char *s
, unsigned count
);
74 static int __init
mn10300_serial_console_setup(struct console
*co
,
77 static struct uart_driver mn10300_serial_driver
;
78 static struct console mn10300_serial_console
= {
80 .write
= mn10300_serial_console_write
,
81 .device
= uart_console_device
,
82 .setup
= mn10300_serial_console_setup
,
83 .flags
= CON_PRINTBUFFER
,
85 .data
= &mn10300_serial_driver
,
89 static struct uart_driver mn10300_serial_driver
= {
91 .driver_name
= "mn10300-serial",
96 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
97 .cons
= &mn10300_serial_console
,
101 static unsigned int mn10300_serial_tx_empty(struct uart_port
*);
102 static void mn10300_serial_set_mctrl(struct uart_port
*, unsigned int mctrl
);
103 static unsigned int mn10300_serial_get_mctrl(struct uart_port
*);
104 static void mn10300_serial_stop_tx(struct uart_port
*);
105 static void mn10300_serial_start_tx(struct uart_port
*);
106 static void mn10300_serial_send_xchar(struct uart_port
*, char ch
);
107 static void mn10300_serial_stop_rx(struct uart_port
*);
108 static void mn10300_serial_enable_ms(struct uart_port
*);
109 static void mn10300_serial_break_ctl(struct uart_port
*, int ctl
);
110 static int mn10300_serial_startup(struct uart_port
*);
111 static void mn10300_serial_shutdown(struct uart_port
*);
112 static void mn10300_serial_set_termios(struct uart_port
*,
113 struct ktermios
*new,
114 struct ktermios
*old
);
115 static const char *mn10300_serial_type(struct uart_port
*);
116 static void mn10300_serial_release_port(struct uart_port
*);
117 static int mn10300_serial_request_port(struct uart_port
*);
118 static void mn10300_serial_config_port(struct uart_port
*, int);
119 static int mn10300_serial_verify_port(struct uart_port
*,
120 struct serial_struct
*);
121 #ifdef CONFIG_CONSOLE_POLL
122 static void mn10300_serial_poll_put_char(struct uart_port
*, unsigned char);
123 static int mn10300_serial_poll_get_char(struct uart_port
*);
126 static const struct uart_ops mn10300_serial_ops
= {
127 .tx_empty
= mn10300_serial_tx_empty
,
128 .set_mctrl
= mn10300_serial_set_mctrl
,
129 .get_mctrl
= mn10300_serial_get_mctrl
,
130 .stop_tx
= mn10300_serial_stop_tx
,
131 .start_tx
= mn10300_serial_start_tx
,
132 .send_xchar
= mn10300_serial_send_xchar
,
133 .stop_rx
= mn10300_serial_stop_rx
,
134 .enable_ms
= mn10300_serial_enable_ms
,
135 .break_ctl
= mn10300_serial_break_ctl
,
136 .startup
= mn10300_serial_startup
,
137 .shutdown
= mn10300_serial_shutdown
,
138 .set_termios
= mn10300_serial_set_termios
,
139 .type
= mn10300_serial_type
,
140 .release_port
= mn10300_serial_release_port
,
141 .request_port
= mn10300_serial_request_port
,
142 .config_port
= mn10300_serial_config_port
,
143 .verify_port
= mn10300_serial_verify_port
,
144 #ifdef CONFIG_CONSOLE_POLL
145 .poll_put_char
= mn10300_serial_poll_put_char
,
146 .poll_get_char
= mn10300_serial_poll_get_char
,
150 static irqreturn_t
mn10300_serial_interrupt(int irq
, void *dev_id
);
153 * the first on-chip serial port: ttySM0 (aka SIF0)
155 #ifdef CONFIG_MN10300_TTYSM0
156 struct mn10300_serial_port mn10300_serial_port_sif0
= {
157 .uart
.ops
= &mn10300_serial_ops
,
158 .uart
.membase
= (void __iomem
*) &SC0CTR
,
159 .uart
.mapbase
= (unsigned long) &SC0CTR
,
160 .uart
.iotype
= UPIO_MEM
,
162 .uart
.uartclk
= 0, /* MN10300_IOCLK, */
164 .uart
.flags
= UPF_BOOT_AUTOCONF
,
166 .uart
.type
= PORT_MN10300
,
168 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif0
.uart
.lock
),
172 ._status
= (volatile u8
*)&SC0STR
,
176 .rx_name
= "ttySM0:Rx",
177 .tx_name
= "ttySM0:Tx",
178 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
179 .tm_name
= "ttySM0:Timer8",
184 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
185 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
186 .tm_name
= "ttySM0:Timer0",
188 ._tmxbr
= (volatile u16
*)&TM0BR
,
191 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
192 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
193 .tm_name
= "ttySM0:Timer2",
195 ._tmxbr
= (volatile u16
*)&TM2BR
,
198 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
200 #error "Unknown config for ttySM0"
204 .rx_icr
= &GxICR(SC0RXIRQ
),
205 .tx_icr
= &GxICR(SC0TXIRQ
),
206 .clock_src
= MNSCx_CLOCK_SRC_IOCLK
,
208 #ifdef CONFIG_GDBSTUB_ON_TTYSM0
212 #endif /* CONFIG_MN10300_TTYSM0 */
215 * the second on-chip serial port: ttySM1 (aka SIF1)
217 #ifdef CONFIG_MN10300_TTYSM1
218 struct mn10300_serial_port mn10300_serial_port_sif1
= {
219 .uart
.ops
= &mn10300_serial_ops
,
220 .uart
.membase
= (void __iomem
*) &SC1CTR
,
221 .uart
.mapbase
= (unsigned long) &SC1CTR
,
222 .uart
.iotype
= UPIO_MEM
,
224 .uart
.uartclk
= 0, /* MN10300_IOCLK, */
226 .uart
.flags
= UPF_BOOT_AUTOCONF
,
228 .uart
.type
= PORT_MN10300
,
230 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif1
.uart
.lock
),
234 ._status
= (volatile u8
*)&SC1STR
,
238 .rx_name
= "ttySM1:Rx",
239 .tx_name
= "ttySM1:Tx",
240 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
241 .tm_name
= "ttySM1:Timer9",
246 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
247 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
248 .tm_name
= "ttySM1:Timer3",
250 ._tmxbr
= (volatile u16
*)&TM3BR
,
253 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
254 #elif defined(CONFIG_MN10300_TTYSM1_TIMER12)
255 .tm_name
= "ttySM1/Timer12",
260 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
262 #error "Unknown config for ttySM1"
266 .rx_icr
= &GxICR(SC1RXIRQ
),
267 .tx_icr
= &GxICR(SC1TXIRQ
),
268 .clock_src
= MNSCx_CLOCK_SRC_IOCLK
,
270 #ifdef CONFIG_GDBSTUB_ON_TTYSM1
274 #endif /* CONFIG_MN10300_TTYSM1 */
277 * the third on-chip serial port: ttySM2 (aka SIF2)
279 #ifdef CONFIG_MN10300_TTYSM2
280 struct mn10300_serial_port mn10300_serial_port_sif2
= {
281 .uart
.ops
= &mn10300_serial_ops
,
282 .uart
.membase
= (void __iomem
*) &SC2CTR
,
283 .uart
.mapbase
= (unsigned long) &SC2CTR
,
284 .uart
.iotype
= UPIO_MEM
,
286 .uart
.uartclk
= 0, /* MN10300_IOCLK, */
288 .uart
.flags
= UPF_BOOT_AUTOCONF
,
290 #ifdef CONFIG_MN10300_TTYSM2_CTS
291 .uart
.type
= PORT_MN10300_CTS
,
293 .uart
.type
= PORT_MN10300
,
296 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif2
.uart
.lock
),
300 ._status
= (volatile u8
*)&SC2STR
,
304 .rx_name
= "ttySM2:Rx",
305 .tx_name
= "ttySM2:Tx",
306 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
307 .tm_name
= "ttySM2/Timer10",
312 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
313 #elif defined(CONFIG_MN10300_TTYSM2_TIMER9)
314 .tm_name
= "ttySM2/Timer9",
319 .div_timer
= MNSCx_DIV_TIMER_16BIT
,
320 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
321 .tm_name
= "ttySM2/Timer1",
323 ._tmxbr
= (volatile u16
*)&TM1BR
,
326 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
327 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
328 .tm_name
= "ttySM2/Timer3",
330 ._tmxbr
= (volatile u16
*)&TM3BR
,
333 .div_timer
= MNSCx_DIV_TIMER_8BIT
,
335 #error "Unknown config for ttySM2"
339 .rx_icr
= &GxICR(SC2RXIRQ
),
340 .tx_icr
= &GxICR(SC2TXIRQ
),
341 .clock_src
= MNSCx_CLOCK_SRC_IOCLK
,
342 #ifdef CONFIG_MN10300_TTYSM2_CTS
343 .options
= MNSCx_OPT_CTS
,
347 #ifdef CONFIG_GDBSTUB_ON_TTYSM2
351 #endif /* CONFIG_MN10300_TTYSM2 */
355 * list of available serial ports
357 struct mn10300_serial_port
*mn10300_serial_ports
[NR_UARTS
+ 1] = {
358 #ifdef CONFIG_MN10300_TTYSM0
359 [0] = &mn10300_serial_port_sif0
,
361 #ifdef CONFIG_MN10300_TTYSM1
362 [1] = &mn10300_serial_port_sif1
,
364 #ifdef CONFIG_MN10300_TTYSM2
365 [2] = &mn10300_serial_port_sif2
,
372 * we abuse the serial ports' baud timers' interrupt lines to get the ability
373 * to deliver interrupts to userspace as we use the ports' interrupt lines to
374 * do virtual DMA on account of the ports having no hardware FIFOs
376 * we can generate an interrupt manually in the assembly stubs by writing to
377 * the enable and detect bits in the interrupt control register, so all we need
378 * to do here is disable the interrupt line
380 * note that we can't just leave the line enabled as the baud rate timer *also*
381 * generates interrupts
383 static void mn10300_serial_mask_ack(unsigned int irq
)
388 flags
= arch_local_cli_save();
389 GxICR(irq
) = GxICR_LEVEL_6
;
390 tmp
= GxICR(irq
); /* flush write buffer */
391 arch_local_irq_restore(flags
);
394 static void mn10300_serial_chip_mask_ack(struct irq_data
*d
)
396 mn10300_serial_mask_ack(d
->irq
);
399 static void mn10300_serial_nop(struct irq_data
*d
)
403 static struct irq_chip mn10300_serial_pic
= {
405 .irq_ack
= mn10300_serial_chip_mask_ack
,
406 .irq_mask
= mn10300_serial_chip_mask_ack
,
407 .irq_mask_ack
= mn10300_serial_chip_mask_ack
,
408 .irq_unmask
= mn10300_serial_nop
,
413 * serial virtual DMA interrupt jump table
415 struct mn10300_serial_int mn10300_serial_int_tbl
[NR_IRQS
];
417 static void mn10300_serial_dis_tx_intr(struct mn10300_serial_port
*port
)
422 flags
= arch_local_cli_save();
423 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
425 arch_local_irq_restore(flags
);
428 static void mn10300_serial_en_tx_intr(struct mn10300_serial_port
*port
)
433 flags
= arch_local_cli_save();
435 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
) | GxICR_ENABLE
;
437 arch_local_irq_restore(flags
);
440 static void mn10300_serial_dis_rx_intr(struct mn10300_serial_port
*port
)
445 flags
= arch_local_cli_save();
446 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
448 arch_local_irq_restore(flags
);
452 * multi-bit equivalent of test_and_clear_bit()
454 static int mask_test_and_clear(volatile u8
*ptr
, u8 mask
)
457 asm volatile(" bclr %1,(%2) \n"
459 : "=d"(epsw
) : "d"(mask
), "a"(ptr
)
461 return !(epsw
& EPSW_FLAG_Z
);
465 * receive chars from the ring buffer for this serial port
466 * - must do break detection here (not done in the UART)
468 static void mn10300_serial_receive_interrupt(struct mn10300_serial_port
*port
)
470 struct uart_icount
*icount
= &port
->uart
.icount
;
471 struct tty_struct
*tty
= port
->uart
.state
->port
.tty
;
474 u8 st
, ch
, push
, status
, overrun
;
476 _enter("%s", port
->name
);
480 count
= CIRC_CNT(port
->rx_inp
, port
->rx_outp
, MNSC_BUFFER_SIZE
);
481 count
= tty_buffer_request_room(tty
, count
);
483 if (!tty
->low_latency
)
484 tty_flip_buffer_push(tty
);
489 /* pull chars out of the hat */
491 if (ix
== port
->rx_inp
) {
492 if (push
&& !tty
->low_latency
)
493 tty_flip_buffer_push(tty
);
497 ch
= port
->rx_buffer
[ix
++];
498 st
= port
->rx_buffer
[ix
++];
500 port
->rx_outp
= ix
& (MNSC_BUFFER_SIZE
- 1);
501 port
->uart
.icount
.rx
++;
503 st
&= SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
;
507 /* the UART doesn't detect BREAK, so we have to do that ourselves
508 * - it starts as a framing error on a NUL character
509 * - then we count another two NUL characters before issuing TTY_BREAK
510 * - then we end on a normal char or one that has all the bottom bits
511 * zero and the top bits set
513 switch (port
->rx_brk
) {
515 /* not breaking at the moment */
519 if (st
& SC01STR_FEF
&& ch
== 0) {
526 if (st
& SC01STR_FEF
&& ch
== 0) {
528 _proto("Rx Break Detected");
530 if (uart_handle_break(&port
->uart
))
532 status
|= 1 << TTY_BREAK
;
538 if (st
& (SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
))
539 goto try_again
; /* still breaking */
541 port
->rx_brk
= 0; /* end of the break */
553 /* discard char at probable break end */
560 /* handle framing error */
561 if (st
& SC01STR_FEF
) {
563 /* framing error with NUL char is probably a BREAK */
568 _proto("Rx Framing Error");
570 status
|= 1 << TTY_FRAME
;
573 /* handle parity error */
574 if (st
& SC01STR_PEF
) {
575 _proto("Rx Parity Error");
580 /* handle normal char */
582 if (uart_handle_sysrq_char(&port
->uart
, ch
))
584 status
= (1 << TTY_NORMAL
);
587 /* handle overrun error */
588 if (st
& SC01STR_OEF
) {
592 _proto("Rx Overrun Error");
598 status
&= port
->uart
.read_status_mask
;
600 if (!overrun
&& !(status
& port
->uart
.ignore_status_mask
)) {
603 if (status
& (1 << TTY_BREAK
))
605 else if (status
& (1 << TTY_PARITY
))
607 else if (status
& (1 << TTY_FRAME
))
612 tty_insert_flip_char(tty
, ch
, flag
);
615 /* overrun is special, since it's reported immediately, and doesn't
616 * affect the current character
619 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
623 if (!tty
->low_latency
)
624 tty_flip_buffer_push(tty
);
638 * handle an interrupt from the serial transmission "virtual DMA" driver
639 * - note: the interrupt routine will disable its own interrupts when the Tx
642 static void mn10300_serial_transmit_interrupt(struct mn10300_serial_port
*port
)
644 _enter("%s", port
->name
);
646 if (!port
->uart
.state
|| !port
->uart
.state
->port
.tty
) {
647 mn10300_serial_dis_tx_intr(port
);
651 if (uart_tx_stopped(&port
->uart
) ||
652 uart_circ_empty(&port
->uart
.state
->xmit
))
653 mn10300_serial_dis_tx_intr(port
);
655 if (uart_circ_chars_pending(&port
->uart
.state
->xmit
) < WAKEUP_CHARS
)
656 uart_write_wakeup(&port
->uart
);
660 * deal with a change in the status of the CTS line
662 static void mn10300_serial_cts_changed(struct mn10300_serial_port
*port
, u8 st
)
667 port
->uart
.icount
.cts
++;
669 /* flip the CTS state selector flag to interrupt when it changes
671 ctr
= *port
->_control
;
673 *port
->_control
= ctr
;
675 uart_handle_cts_change(&port
->uart
, st
& SC2STR_CTS
);
676 wake_up_interruptible(&port
->uart
.state
->port
.delta_msr_wait
);
680 * handle a virtual interrupt generated by the lower level "virtual DMA"
681 * routines (irq is the baud timer interrupt)
683 static irqreturn_t
mn10300_serial_interrupt(int irq
, void *dev_id
)
685 struct mn10300_serial_port
*port
= dev_id
;
688 spin_lock(&port
->uart
.lock
);
690 if (port
->intr_flags
) {
691 _debug("INT %s: %x", port
->name
, port
->intr_flags
);
693 if (mask_test_and_clear(&port
->intr_flags
, MNSCx_RX_AVAIL
))
694 mn10300_serial_receive_interrupt(port
);
696 if (mask_test_and_clear(&port
->intr_flags
,
697 MNSCx_TX_SPACE
| MNSCx_TX_EMPTY
))
698 mn10300_serial_transmit_interrupt(port
);
701 /* the only modem control line amongst the whole lot is CTS on
703 if (port
->type
== PORT_MN10300_CTS
) {
705 if ((port
->tx_cts
^ st
) & SC2STR_CTS
)
706 mn10300_serial_cts_changed(port
, st
);
709 spin_unlock(&port
->uart
.lock
);
715 * return indication of whether the hardware transmit buffer is empty
717 static unsigned int mn10300_serial_tx_empty(struct uart_port
*_port
)
719 struct mn10300_serial_port
*port
=
720 container_of(_port
, struct mn10300_serial_port
, uart
);
722 _enter("%s", port
->name
);
724 return (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
)) ?
729 * set the modem control lines (we don't have any)
731 static void mn10300_serial_set_mctrl(struct uart_port
*_port
,
734 struct mn10300_serial_port
*port
__attribute__ ((unused
)) =
735 container_of(_port
, struct mn10300_serial_port
, uart
);
737 _enter("%s,%x", port
->name
, mctrl
);
741 * get the modem control line statuses
743 static unsigned int mn10300_serial_get_mctrl(struct uart_port
*_port
)
745 struct mn10300_serial_port
*port
=
746 container_of(_port
, struct mn10300_serial_port
, uart
);
748 _enter("%s", port
->name
);
750 if (port
->type
== PORT_MN10300_CTS
&& !(*port
->_status
& SC2STR_CTS
))
751 return TIOCM_CAR
| TIOCM_DSR
;
753 return TIOCM_CAR
| TIOCM_CTS
| TIOCM_DSR
;
757 * stop transmitting characters
759 static void mn10300_serial_stop_tx(struct uart_port
*_port
)
761 struct mn10300_serial_port
*port
=
762 container_of(_port
, struct mn10300_serial_port
, uart
);
764 _enter("%s", port
->name
);
766 /* disable the virtual DMA */
767 mn10300_serial_dis_tx_intr(port
);
771 * start transmitting characters
772 * - jump-start transmission if it has stalled
773 * - enable the serial Tx interrupt (used by the virtual DMA controller)
774 * - force an interrupt to happen if necessary
776 static void mn10300_serial_start_tx(struct uart_port
*_port
)
778 struct mn10300_serial_port
*port
=
779 container_of(_port
, struct mn10300_serial_port
, uart
);
785 CIRC_CNT(&port
->uart
.state
->xmit
.head
,
786 &port
->uart
.state
->xmit
.tail
,
789 /* kick the virtual DMA controller */
794 if (*port
->_status
& SC01STR_TBF
)
795 x
&= ~(GxICR_REQUEST
| GxICR_DETECT
);
797 x
|= GxICR_REQUEST
| GxICR_DETECT
;
799 _debug("CTR=%04hx ICR=%02hx STR=%04x TMD=%02hx TBR=%04hx ICR=%04hx",
800 *port
->_control
, *port
->_intr
, *port
->_status
,
802 (port
->div_timer
== MNSCx_DIV_TIMER_8BIT
) ?
803 *(volatile u8
*)port
->_tmxbr
: *port
->_tmxbr
,
812 * transmit a high-priority XON/XOFF character
814 static void mn10300_serial_send_xchar(struct uart_port
*_port
, char ch
)
816 struct mn10300_serial_port
*port
=
817 container_of(_port
, struct mn10300_serial_port
, uart
);
819 _enter("%s,%02x", port
->name
, ch
);
821 if (likely(port
->gdbstub
)) {
824 mn10300_serial_en_tx_intr(port
);
829 * stop receiving characters
830 * - called whilst the port is being closed
832 static void mn10300_serial_stop_rx(struct uart_port
*_port
)
834 struct mn10300_serial_port
*port
=
835 container_of(_port
, struct mn10300_serial_port
, uart
);
839 _enter("%s", port
->name
);
841 ctr
= *port
->_control
;
843 *port
->_control
= ctr
;
845 mn10300_serial_dis_rx_intr(port
);
849 * enable modem status interrupts
851 static void mn10300_serial_enable_ms(struct uart_port
*_port
)
853 struct mn10300_serial_port
*port
=
854 container_of(_port
, struct mn10300_serial_port
, uart
);
858 _enter("%s", port
->name
);
860 if (port
->type
== PORT_MN10300_CTS
) {
861 /* want to interrupt when CTS goes low if CTS is now high and
864 port
->tx_cts
= *port
->_status
;
866 cts
= (port
->tx_cts
& SC2STR_CTS
) ?
867 SC2CTR_TWE
: SC2CTR_TWE
| SC2CTR_TWS
;
869 ctr
= *port
->_control
;
872 *port
->_control
= ctr
;
874 mn10300_serial_en_tx_intr(port
);
879 * transmit or cease transmitting a break signal
881 static void mn10300_serial_break_ctl(struct uart_port
*_port
, int ctl
)
883 struct mn10300_serial_port
*port
=
884 container_of(_port
, struct mn10300_serial_port
, uart
);
886 _enter("%s,%d", port
->name
, ctl
);
889 /* tell the virtual DMA handler to assert BREAK */
891 mn10300_serial_en_tx_intr(port
);
894 *port
->_control
&= ~SC01CTR_BKE
;
895 mn10300_serial_en_tx_intr(port
);
900 * grab the interrupts and enable the port for reception
902 static int mn10300_serial_startup(struct uart_port
*_port
)
904 struct mn10300_serial_port
*port
=
905 container_of(_port
, struct mn10300_serial_port
, uart
);
906 struct mn10300_serial_int
*pint
;
908 _enter("%s{%d}", port
->name
, port
->gdbstub
);
910 if (unlikely(port
->gdbstub
))
913 /* allocate an Rx buffer for the virtual DMA handler */
914 port
->rx_buffer
= kmalloc(MNSC_BUFFER_SIZE
, GFP_KERNEL
);
915 if (!port
->rx_buffer
)
918 port
->rx_inp
= port
->rx_outp
= 0;
920 /* finally, enable the device */
921 *port
->_intr
= SC01ICR_TI
;
922 *port
->_control
|= SC01CTR_TXE
| SC01CTR_RXE
;
924 pint
= &mn10300_serial_int_tbl
[port
->rx_irq
];
926 pint
->vdma
= mn10300_serial_vdma_rx_handler
;
927 pint
= &mn10300_serial_int_tbl
[port
->tx_irq
];
929 pint
->vdma
= mn10300_serial_vdma_tx_handler
;
931 set_intr_level(port
->rx_irq
,
932 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
));
933 set_intr_level(port
->tx_irq
,
934 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
));
935 irq_set_chip(port
->tm_irq
, &mn10300_serial_pic
);
937 if (request_irq(port
->rx_irq
, mn10300_serial_interrupt
,
938 IRQF_DISABLED
, port
->rx_name
, port
) < 0)
941 if (request_irq(port
->tx_irq
, mn10300_serial_interrupt
,
942 IRQF_DISABLED
, port
->tx_name
, port
) < 0)
945 if (request_irq(port
->tm_irq
, mn10300_serial_interrupt
,
946 IRQF_DISABLED
, port
->tm_name
, port
) < 0)
948 mn10300_serial_mask_ack(port
->tm_irq
);
953 free_irq(port
->tx_irq
, port
);
955 free_irq(port
->rx_irq
, port
);
957 kfree(port
->rx_buffer
);
958 port
->rx_buffer
= NULL
;
963 * shutdown the port and release interrupts
965 static void mn10300_serial_shutdown(struct uart_port
*_port
)
968 struct mn10300_serial_port
*port
=
969 container_of(_port
, struct mn10300_serial_port
, uart
);
971 _enter("%s", port
->name
);
973 /* disable the serial port and its baud rate timer */
975 *port
->_control
&= ~(SC01CTR_TXE
| SC01CTR_RXE
| SC01CTR_BKE
);
978 if (port
->rx_buffer
) {
979 void *buf
= port
->rx_buffer
;
980 port
->rx_buffer
= NULL
;
984 /* disable all intrs */
985 free_irq(port
->tm_irq
, port
);
986 free_irq(port
->rx_irq
, port
);
987 free_irq(port
->tx_irq
, port
);
990 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
992 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
998 * this routine is called to set the UART divisor registers to match the
999 * specified baud rate for a serial port.
1001 static void mn10300_serial_change_speed(struct mn10300_serial_port
*port
,
1002 struct ktermios
*new,
1003 struct ktermios
*old
)
1005 unsigned long flags
;
1006 unsigned long ioclk
= port
->ioclk
;
1008 int baud
, bits
, xdiv
, tmp
;
1011 u8 div_timer
= port
->div_timer
;
1013 _enter("%s{%lu}", port
->name
, ioclk
);
1015 /* byte size and parity */
1016 cflag
= new->c_cflag
;
1017 switch (cflag
& CSIZE
) {
1018 case CS7
: scxctr
= SC01CTR_CLN_7BIT
; bits
= 9; break;
1019 case CS8
: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1020 default: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1023 if (cflag
& CSTOPB
) {
1024 scxctr
|= SC01CTR_STB_2BIT
;
1028 if (cflag
& PARENB
) {
1031 scxctr
|= SC01CTR_PB_ODD
;
1033 else if (cflag
& CMSPAR
)
1034 scxctr
|= SC01CTR_PB_FIXED0
;
1037 scxctr
|= SC01CTR_PB_EVEN
;
1040 /* Determine divisor based on baud rate */
1043 switch (port
->uart
.line
) {
1044 #ifdef CONFIG_MN10300_TTYSM0
1045 case 0: /* ttySM0 */
1046 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
1047 scxctr
|= SC0CTR_CK_TM8UFLOW_8
;
1048 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
1049 scxctr
|= SC0CTR_CK_TM0UFLOW_8
;
1050 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
1051 scxctr
|= SC0CTR_CK_TM2UFLOW_8
;
1053 #error "Unknown config for ttySM0"
1056 #endif /* CONFIG_MN10300_TTYSM0 */
1058 #ifdef CONFIG_MN10300_TTYSM1
1059 case 1: /* ttySM1 */
1060 #if defined(CONFIG_AM33_2) || defined(CONFIG_AM33_3)
1061 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
1062 scxctr
|= SC1CTR_CK_TM9UFLOW_8
;
1063 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
1064 scxctr
|= SC1CTR_CK_TM3UFLOW_8
;
1066 #error "Unknown config for ttySM1"
1068 #else /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1069 #if defined(CONFIG_MN10300_TTYSM1_TIMER12)
1070 scxctr
|= SC1CTR_CK_TM12UFLOW_8
;
1072 #error "Unknown config for ttySM1"
1074 #endif /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1076 #endif /* CONFIG_MN10300_TTYSM1 */
1078 #ifdef CONFIG_MN10300_TTYSM2
1079 case 2: /* ttySM2 */
1080 #if defined(CONFIG_AM33_2)
1081 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
1082 scxctr
|= SC2CTR_CK_TM10UFLOW
;
1084 #error "Unknown config for ttySM2"
1086 #else /* CONFIG_AM33_2 */
1087 #if defined(CONFIG_MN10300_TTYSM2_TIMER9)
1088 scxctr
|= SC2CTR_CK_TM9UFLOW_8
;
1089 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
1090 scxctr
|= SC2CTR_CK_TM1UFLOW_8
;
1091 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
1092 scxctr
|= SC2CTR_CK_TM3UFLOW_8
;
1094 #error "Unknown config for ttySM2"
1096 #endif /* CONFIG_AM33_2 */
1098 #endif /* CONFIG_MN10300_TTYSM2 */
1105 baud
= uart_get_baud_rate(&port
->uart
, new, old
, 0,
1108 _debug("ALT %d [baud %d]", battempt
, baud
);
1111 baud
= 9600; /* B0 transition handled in rs_set_termios */
1114 baud
= 269; /* 134 is really 134.5 */
1118 if (baud
== 38400 &&
1119 (port
->uart
.flags
& UPF_SPD_MASK
) == UPF_SPD_CUST
1121 _debug("CUSTOM %u", port
->uart
.custom_divisor
);
1123 if (div_timer
== MNSCx_DIV_TIMER_16BIT
) {
1124 if (port
->uart
.custom_divisor
<= 65535) {
1125 tmxmd
= TM8MD_SRC_IOCLK
;
1126 tmxbr
= port
->uart
.custom_divisor
;
1127 port
->uart
.uartclk
= ioclk
;
1130 if (port
->uart
.custom_divisor
/ 8 <= 65535) {
1131 tmxmd
= TM8MD_SRC_IOCLK_8
;
1132 tmxbr
= port
->uart
.custom_divisor
/ 8;
1133 port
->uart
.custom_divisor
= tmxbr
* 8;
1134 port
->uart
.uartclk
= ioclk
/ 8;
1137 if (port
->uart
.custom_divisor
/ 32 <= 65535) {
1138 tmxmd
= TM8MD_SRC_IOCLK_32
;
1139 tmxbr
= port
->uart
.custom_divisor
/ 32;
1140 port
->uart
.custom_divisor
= tmxbr
* 32;
1141 port
->uart
.uartclk
= ioclk
/ 32;
1145 } else if (div_timer
== MNSCx_DIV_TIMER_8BIT
) {
1146 if (port
->uart
.custom_divisor
<= 255) {
1147 tmxmd
= TM2MD_SRC_IOCLK
;
1148 tmxbr
= port
->uart
.custom_divisor
;
1149 port
->uart
.uartclk
= ioclk
;
1152 if (port
->uart
.custom_divisor
/ 8 <= 255) {
1153 tmxmd
= TM2MD_SRC_IOCLK_8
;
1154 tmxbr
= port
->uart
.custom_divisor
/ 8;
1155 port
->uart
.custom_divisor
= tmxbr
* 8;
1156 port
->uart
.uartclk
= ioclk
/ 8;
1159 if (port
->uart
.custom_divisor
/ 32 <= 255) {
1160 tmxmd
= TM2MD_SRC_IOCLK_32
;
1161 tmxbr
= port
->uart
.custom_divisor
/ 32;
1162 port
->uart
.custom_divisor
= tmxbr
* 32;
1163 port
->uart
.uartclk
= ioclk
/ 32;
1169 switch (div_timer
) {
1170 case MNSCx_DIV_TIMER_16BIT
:
1171 port
->uart
.uartclk
= ioclk
;
1172 tmxmd
= TM8MD_SRC_IOCLK
;
1173 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1174 if (tmp
> 0 && tmp
<= 65535)
1177 port
->uart
.uartclk
= ioclk
/ 8;
1178 tmxmd
= TM8MD_SRC_IOCLK_8
;
1179 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1180 if (tmp
> 0 && tmp
<= 65535)
1183 port
->uart
.uartclk
= ioclk
/ 32;
1184 tmxmd
= TM8MD_SRC_IOCLK_32
;
1185 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1186 if (tmp
> 0 && tmp
<= 65535)
1190 case MNSCx_DIV_TIMER_8BIT
:
1191 port
->uart
.uartclk
= ioclk
;
1192 tmxmd
= TM2MD_SRC_IOCLK
;
1193 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1194 if (tmp
> 0 && tmp
<= 255)
1197 port
->uart
.uartclk
= ioclk
/ 8;
1198 tmxmd
= TM2MD_SRC_IOCLK_8
;
1199 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1200 if (tmp
> 0 && tmp
<= 255)
1203 port
->uart
.uartclk
= ioclk
/ 32;
1204 tmxmd
= TM2MD_SRC_IOCLK_32
;
1205 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1206 if (tmp
> 0 && tmp
<= 255)
1215 /* refuse to change to a baud rate we can't support */
1216 _debug("CAN'T SUPPORT");
1221 new->c_cflag
&= ~CBAUD
;
1222 new->c_cflag
|= (old
->c_cflag
& CBAUD
);
1224 goto try_alternative
;
1228 /* as a last resort, if the quotient is zero, default to 9600
1230 new->c_cflag
&= ~CBAUD
;
1231 new->c_cflag
|= B9600
;
1233 goto try_alternative
;
1236 /* hmmm... can't seem to support 9600 either
1237 * - we could try iterating through the speeds we know about to
1240 new->c_cflag
&= ~CBAUD
;
1243 if (div_timer
== MNSCx_DIV_TIMER_16BIT
)
1244 tmxmd
= TM8MD_SRC_IOCLK_32
;
1245 else if (div_timer
== MNSCx_DIV_TIMER_8BIT
)
1246 tmxmd
= TM2MD_SRC_IOCLK_32
;
1249 port
->uart
.uartclk
= ioclk
/ 32;
1254 _debug("UARTCLK: %u / %hu", port
->uart
.uartclk
, tmxbr
);
1256 /* make the changes */
1257 spin_lock_irqsave(&port
->uart
.lock
, flags
);
1259 uart_update_timeout(&port
->uart
, new->c_cflag
, baud
);
1261 /* set the timer to produce the required baud rate */
1262 switch (div_timer
) {
1263 case MNSCx_DIV_TIMER_16BIT
:
1265 *port
->_tmxbr
= tmxbr
;
1266 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1267 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1270 case MNSCx_DIV_TIMER_8BIT
:
1272 *(volatile u8
*) port
->_tmxbr
= (u8
) tmxbr
;
1273 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1274 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1278 /* CTS flow control flag and modem status interrupts */
1279 scxctr
&= ~(SC2CTR_TWE
| SC2CTR_TWS
);
1281 if (port
->type
== PORT_MN10300_CTS
&& cflag
& CRTSCTS
) {
1282 /* want to interrupt when CTS goes low if CTS is now
1283 * high and vice versa
1285 port
->tx_cts
= *port
->_status
;
1287 if (port
->tx_cts
& SC2STR_CTS
)
1288 scxctr
|= SC2CTR_TWE
;
1290 scxctr
|= SC2CTR_TWE
| SC2CTR_TWS
;
1293 /* set up parity check flag */
1294 port
->uart
.read_status_mask
= (1 << TTY_NORMAL
) | (1 << TTY_OVERRUN
);
1295 if (new->c_iflag
& INPCK
)
1296 port
->uart
.read_status_mask
|=
1297 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1298 if (new->c_iflag
& (BRKINT
| PARMRK
))
1299 port
->uart
.read_status_mask
|= (1 << TTY_BREAK
);
1301 /* characters to ignore */
1302 port
->uart
.ignore_status_mask
= 0;
1303 if (new->c_iflag
& IGNPAR
)
1304 port
->uart
.ignore_status_mask
|=
1305 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1306 if (new->c_iflag
& IGNBRK
) {
1307 port
->uart
.ignore_status_mask
|= (1 << TTY_BREAK
);
1309 * If we're ignoring parity and break indicators,
1310 * ignore overruns to (for real raw support).
1312 if (new->c_iflag
& IGNPAR
)
1313 port
->uart
.ignore_status_mask
|= (1 << TTY_OVERRUN
);
1316 /* Ignore all characters if CREAD is not set */
1317 if ((new->c_cflag
& CREAD
) == 0)
1318 port
->uart
.ignore_status_mask
|= (1 << TTY_NORMAL
);
1320 scxctr
|= *port
->_control
& (SC01CTR_TXE
| SC01CTR_RXE
| SC01CTR_BKE
);
1321 *port
->_control
= scxctr
;
1323 spin_unlock_irqrestore(&port
->uart
.lock
, flags
);
1327 * set the terminal I/O parameters
1329 static void mn10300_serial_set_termios(struct uart_port
*_port
,
1330 struct ktermios
*new,
1331 struct ktermios
*old
)
1333 struct mn10300_serial_port
*port
=
1334 container_of(_port
, struct mn10300_serial_port
, uart
);
1336 _enter("%s,%p,%p", port
->name
, new, old
);
1338 mn10300_serial_change_speed(port
, new, old
);
1340 /* handle turning off CRTSCTS */
1341 if (!(new->c_cflag
& CRTSCTS
)) {
1342 u16 ctr
= *port
->_control
;
1344 *port
->_control
= ctr
;
1347 /* change Transfer bit-order (LSB/MSB) */
1348 if (new->c_cflag
& CODMSB
)
1349 *port
->_control
|= SC01CTR_OD_MSBFIRST
; /* MSB MODE */
1351 *port
->_control
&= ~SC01CTR_OD_MSBFIRST
; /* LSB MODE */
1355 * return description of port type
1357 static const char *mn10300_serial_type(struct uart_port
*_port
)
1359 struct mn10300_serial_port
*port
=
1360 container_of(_port
, struct mn10300_serial_port
, uart
);
1362 if (port
->uart
.type
== PORT_MN10300_CTS
)
1363 return "MN10300 SIF_CTS";
1365 return "MN10300 SIF";
1369 * release I/O and memory regions in use by port
1371 static void mn10300_serial_release_port(struct uart_port
*_port
)
1373 struct mn10300_serial_port
*port
=
1374 container_of(_port
, struct mn10300_serial_port
, uart
);
1376 _enter("%s", port
->name
);
1378 release_mem_region((unsigned long) port
->_iobase
, 16);
1382 * request I/O and memory regions for port
1384 static int mn10300_serial_request_port(struct uart_port
*_port
)
1386 struct mn10300_serial_port
*port
=
1387 container_of(_port
, struct mn10300_serial_port
, uart
);
1389 _enter("%s", port
->name
);
1391 request_mem_region((unsigned long) port
->_iobase
, 16, port
->name
);
1396 * configure the type and reserve the ports
1398 static void mn10300_serial_config_port(struct uart_port
*_port
, int type
)
1400 struct mn10300_serial_port
*port
=
1401 container_of(_port
, struct mn10300_serial_port
, uart
);
1403 _enter("%s", port
->name
);
1405 port
->uart
.type
= PORT_MN10300
;
1407 if (port
->options
& MNSCx_OPT_CTS
)
1408 port
->uart
.type
= PORT_MN10300_CTS
;
1410 mn10300_serial_request_port(_port
);
1414 * verify serial parameters are suitable for this port type
1416 static int mn10300_serial_verify_port(struct uart_port
*_port
,
1417 struct serial_struct
*ss
)
1419 struct mn10300_serial_port
*port
=
1420 container_of(_port
, struct mn10300_serial_port
, uart
);
1421 void *mapbase
= (void *) (unsigned long) port
->uart
.mapbase
;
1423 _enter("%s", port
->name
);
1425 /* these things may not be changed */
1426 if (ss
->irq
!= port
->uart
.irq
||
1427 ss
->port
!= port
->uart
.iobase
||
1428 ss
->io_type
!= port
->uart
.iotype
||
1429 ss
->iomem_base
!= mapbase
||
1430 ss
->iomem_reg_shift
!= port
->uart
.regshift
||
1431 ss
->hub6
!= port
->uart
.hub6
||
1432 ss
->xmit_fifo_size
!= port
->uart
.fifosize
)
1435 /* type may be changed on a port that supports CTS */
1436 if (ss
->type
!= port
->uart
.type
) {
1437 if (!(port
->options
& MNSCx_OPT_CTS
))
1440 if (ss
->type
!= PORT_MN10300
&&
1441 ss
->type
!= PORT_MN10300_CTS
)
1449 * initialise the MN10300 on-chip UARTs
1451 static int __init
mn10300_serial_init(void)
1453 struct mn10300_serial_port
*port
;
1456 printk(KERN_INFO
"%s version %s (%s)\n",
1457 serial_name
, serial_version
, serial_revdate
);
1459 #if defined(CONFIG_MN10300_TTYSM2) && defined(CONFIG_AM33_2)
1462 SC2TIM
= 8; /* make the baud base of timer 2 IOCLK/8 */
1467 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
),
1468 mn10300_serial_vdma_interrupt
);
1470 ret
= uart_register_driver(&mn10300_serial_driver
);
1472 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1473 port
= mn10300_serial_ports
[i
];
1474 if (!port
|| port
->gdbstub
)
1477 switch (port
->clock_src
) {
1478 case MNSCx_CLOCK_SRC_IOCLK
:
1479 port
->ioclk
= MN10300_IOCLK
;
1482 #ifdef MN10300_IOBCLK
1483 case MNSCx_CLOCK_SRC_IOBCLK
:
1484 port
->ioclk
= MN10300_IOBCLK
;
1491 ret
= uart_add_one_port(&mn10300_serial_driver
,
1495 _debug("ERROR %d", -ret
);
1501 uart_unregister_driver(&mn10300_serial_driver
);
1507 __initcall(mn10300_serial_init
);
1510 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
1513 * print a string to the serial port without disturbing the real user of the
1515 * - the console must be locked by the caller
1517 static void mn10300_serial_console_write(struct console
*co
,
1518 const char *s
, unsigned count
)
1520 struct mn10300_serial_port
*port
;
1522 u16 scxctr
, txicr
, tmp
;
1525 port
= mn10300_serial_ports
[co
->index
];
1527 /* firstly hijack the serial port from the "virtual DMA" controller */
1529 txicr
= *port
->tx_icr
;
1530 *port
->tx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
1531 tmp
= *port
->tx_icr
;
1534 /* the transmitter may be disabled */
1535 scxctr
= *port
->_control
;
1536 if (!(scxctr
& SC01CTR_TXE
)) {
1537 /* restart the UART clock */
1538 tmxmd
= *port
->_tmxmd
;
1540 switch (port
->div_timer
) {
1541 case MNSCx_DIV_TIMER_16BIT
:
1543 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1544 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1547 case MNSCx_DIV_TIMER_8BIT
:
1549 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1550 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1554 /* enable the transmitter */
1555 *port
->_control
= (scxctr
& ~SC01CTR_BKE
) | SC01CTR_TXE
;
1557 } else if (scxctr
& SC01CTR_BKE
) {
1558 /* stop transmitting BREAK */
1559 *port
->_control
= (scxctr
& ~SC01CTR_BKE
);
1562 /* send the chars into the serial port (with LF -> LFCR conversion) */
1563 for (i
= 0; i
< count
; i
++) {
1566 while (*port
->_status
& SC01STR_TBF
)
1568 *(u8
*) port
->_txb
= ch
;
1571 while (*port
->_status
& SC01STR_TBF
)
1573 *(u8
*) port
->_txb
= 0xd;
1577 /* can't let the transmitter be turned off if it's actually
1579 while (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
))
1582 /* disable the transmitter if we re-enabled it */
1583 if (!(scxctr
& SC01CTR_TXE
))
1584 *port
->_control
= scxctr
;
1587 *port
->tx_icr
= txicr
;
1588 tmp
= *port
->tx_icr
;
1593 * set up a serial port as a console
1594 * - construct a cflag setting for the first rs_open()
1595 * - initialize the serial port
1596 * - return non-zero if we didn't find a serial port.
1598 static int __init
mn10300_serial_console_setup(struct console
*co
,
1601 struct mn10300_serial_port
*port
;
1602 int i
, parity
= 'n', baud
= 9600, bits
= 8, flow
= 0;
1604 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1605 port
= mn10300_serial_ports
[i
];
1606 if (port
&& !port
->gdbstub
&& port
->uart
.line
== co
->index
)
1613 switch (port
->clock_src
) {
1614 case MNSCx_CLOCK_SRC_IOCLK
:
1615 port
->ioclk
= MN10300_IOCLK
;
1618 #ifdef MN10300_IOBCLK
1619 case MNSCx_CLOCK_SRC_IOBCLK
:
1620 port
->ioclk
= MN10300_IOBCLK
;
1628 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1630 return uart_set_options(&port
->uart
, co
, baud
, parity
, bits
, flow
);
1636 static int __init
mn10300_serial_console_init(void)
1638 register_console(&mn10300_serial_console
);
1642 console_initcall(mn10300_serial_console_init
);
1645 #ifdef CONFIG_CONSOLE_POLL
1647 * Polled character reception for the kernel debugger
1649 static int mn10300_serial_poll_get_char(struct uart_port
*_port
)
1651 struct mn10300_serial_port
*port
=
1652 container_of(_port
, struct mn10300_serial_port
, uart
);
1656 _enter("%s", port
->name
);
1659 /* pull chars out of the hat */
1661 if (ix
== port
->rx_inp
)
1662 return NO_POLL_CHAR
;
1664 ch
= port
->rx_buffer
[ix
++];
1665 st
= port
->rx_buffer
[ix
++];
1667 port
->rx_outp
= ix
& (MNSC_BUFFER_SIZE
- 1);
1669 } while (st
& (SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
));
1676 * Polled character transmission for the kernel debugger
1678 static void mn10300_serial_poll_put_char(struct uart_port
*_port
,
1681 struct mn10300_serial_port
*port
=
1682 container_of(_port
, struct mn10300_serial_port
, uart
);
1685 /* wait for the transmitter to finish anything it might be doing (and
1686 * this includes the virtual DMA handler, so it might take a while) */
1687 while (*port
->_status
& (SC01STR_TBF
| SC01STR_TXF
))
1690 /* disable the Tx ready interrupt */
1691 intr
= *port
->_intr
;
1692 *port
->_intr
= intr
& ~SC01ICR_TI
;
1696 *(u8
*) port
->_txb
= 0x0d;
1697 while (*port
->_status
& SC01STR_TBF
)
1701 *(u8
*) port
->_txb
= ch
;
1702 while (*port
->_status
& SC01STR_TBF
)
1705 /* restore the Tx interrupt flag */
1706 *port
->_intr
= intr
;
1710 #endif /* CONFIG_CONSOLE_POLL */