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
,
411 static void mn10300_serial_low_mask(struct irq_data
*d
)
416 flags
= arch_local_cli_save();
417 GxICR(d
->irq
) = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
418 tmp
= GxICR(d
->irq
); /* flush write buffer */
419 arch_local_irq_restore(flags
);
422 static void mn10300_serial_low_unmask(struct irq_data
*d
)
427 flags
= arch_local_cli_save();
429 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
) | GxICR_ENABLE
;
430 tmp
= GxICR(d
->irq
); /* flush write buffer */
431 arch_local_irq_restore(flags
);
434 static struct irq_chip mn10300_serial_low_pic
= {
435 .name
= "mnserial-low",
436 .irq_mask
= mn10300_serial_low_mask
,
437 .irq_unmask
= mn10300_serial_low_unmask
,
441 * serial virtual DMA interrupt jump table
443 struct mn10300_serial_int mn10300_serial_int_tbl
[NR_IRQS
];
445 static void mn10300_serial_dis_tx_intr(struct mn10300_serial_port
*port
)
450 /* nothing to do if irq isn't set up */
451 if (!mn10300_serial_int_tbl
[port
->tx_irq
].port
)
454 port
->tx_flags
|= MNSCx_TX_STOP
;
458 * Here we wait for the irq to be disabled. Either it already is
459 * disabled or we wait some number of retries for the VDMA handler
460 * to disable it. The retries give the VDMA handler enough time to
461 * run to completion if it was already in progress. If the VDMA IRQ
462 * is enabled but the handler is not yet running when arrive here,
463 * the STOP flag will prevent the handler from conflicting with the
464 * driver code following this loop.
466 while ((*port
->tx_icr
& GxICR_ENABLE
) && retries
-- > 0)
470 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
475 static void mn10300_serial_en_tx_intr(struct mn10300_serial_port
*port
)
479 /* nothing to do if irq isn't set up */
480 if (!mn10300_serial_int_tbl
[port
->tx_irq
].port
)
483 /* stop vdma irq if not already stopped */
484 if (!(port
->tx_flags
& MNSCx_TX_STOP
))
485 mn10300_serial_dis_tx_intr(port
);
487 port
->tx_flags
&= ~MNSCx_TX_STOP
;
491 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
) |
492 GxICR_ENABLE
| GxICR_REQUEST
| GxICR_DETECT
;
496 static void mn10300_serial_dis_rx_intr(struct mn10300_serial_port
*port
)
501 flags
= arch_local_cli_save();
502 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
504 arch_local_irq_restore(flags
);
508 * multi-bit equivalent of test_and_clear_bit()
510 static int mask_test_and_clear(volatile u8
*ptr
, u8 mask
)
513 asm volatile(" bclr %1,(%2) \n"
515 : "=d"(epsw
) : "d"(mask
), "a"(ptr
)
517 return !(epsw
& EPSW_FLAG_Z
);
521 * receive chars from the ring buffer for this serial port
522 * - must do break detection here (not done in the UART)
524 static void mn10300_serial_receive_interrupt(struct mn10300_serial_port
*port
)
526 struct uart_icount
*icount
= &port
->uart
.icount
;
527 struct tty_port
*tport
= &port
->uart
.state
->port
;
530 u8 st
, ch
, push
, status
, overrun
;
532 _enter("%s", port
->name
);
536 count
= CIRC_CNT(port
->rx_inp
, port
->rx_outp
, MNSC_BUFFER_SIZE
);
537 count
= tty_buffer_request_room(tport
, count
);
539 if (!tport
->low_latency
)
540 tty_flip_buffer_push(tport
);
545 /* pull chars out of the hat */
546 ix
= READ_ONCE(port
->rx_outp
);
547 if (CIRC_CNT(port
->rx_inp
, ix
, MNSC_BUFFER_SIZE
) == 0) {
548 if (push
&& !tport
->low_latency
)
549 tty_flip_buffer_push(tport
);
553 /* READ_ONCE() enforces dependency, but dangerous through integer!!! */
554 ch
= port
->rx_buffer
[ix
++];
555 st
= port
->rx_buffer
[ix
++];
557 port
->rx_outp
= ix
& (MNSC_BUFFER_SIZE
- 1);
558 port
->uart
.icount
.rx
++;
560 st
&= SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
;
564 /* the UART doesn't detect BREAK, so we have to do that ourselves
565 * - it starts as a framing error on a NUL character
566 * - then we count another two NUL characters before issuing TTY_BREAK
567 * - then we end on a normal char or one that has all the bottom bits
568 * zero and the top bits set
570 switch (port
->rx_brk
) {
572 /* not breaking at the moment */
576 if (st
& SC01STR_FEF
&& ch
== 0) {
583 if (st
& SC01STR_FEF
&& ch
== 0) {
585 _proto("Rx Break Detected");
587 if (uart_handle_break(&port
->uart
))
589 status
|= 1 << TTY_BREAK
;
595 if (st
& (SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
))
596 goto try_again
; /* still breaking */
598 port
->rx_brk
= 0; /* end of the break */
610 /* discard char at probable break end */
617 /* handle framing error */
618 if (st
& SC01STR_FEF
) {
620 /* framing error with NUL char is probably a BREAK */
625 _proto("Rx Framing Error");
627 status
|= 1 << TTY_FRAME
;
630 /* handle parity error */
631 if (st
& SC01STR_PEF
) {
632 _proto("Rx Parity Error");
637 /* handle normal char */
639 if (uart_handle_sysrq_char(&port
->uart
, ch
))
641 status
= (1 << TTY_NORMAL
);
644 /* handle overrun error */
645 if (st
& SC01STR_OEF
) {
649 _proto("Rx Overrun Error");
655 status
&= port
->uart
.read_status_mask
;
657 if (!overrun
&& !(status
& port
->uart
.ignore_status_mask
)) {
660 if (status
& (1 << TTY_BREAK
))
662 else if (status
& (1 << TTY_PARITY
))
664 else if (status
& (1 << TTY_FRAME
))
669 tty_insert_flip_char(tport
, ch
, flag
);
672 /* overrun is special, since it's reported immediately, and doesn't
673 * affect the current character
676 tty_insert_flip_char(tport
, 0, TTY_OVERRUN
);
680 if (!tport
->low_latency
)
681 tty_flip_buffer_push(tport
);
695 * handle an interrupt from the serial transmission "virtual DMA" driver
696 * - note: the interrupt routine will disable its own interrupts when the Tx
699 static void mn10300_serial_transmit_interrupt(struct mn10300_serial_port
*port
)
701 _enter("%s", port
->name
);
703 if (!port
->uart
.state
|| !port
->uart
.state
->port
.tty
) {
704 mn10300_serial_dis_tx_intr(port
);
708 if (uart_tx_stopped(&port
->uart
) ||
709 uart_circ_empty(&port
->uart
.state
->xmit
))
710 mn10300_serial_dis_tx_intr(port
);
712 if (uart_circ_chars_pending(&port
->uart
.state
->xmit
) < WAKEUP_CHARS
)
713 uart_write_wakeup(&port
->uart
);
717 * deal with a change in the status of the CTS line
719 static void mn10300_serial_cts_changed(struct mn10300_serial_port
*port
, u8 st
)
724 port
->uart
.icount
.cts
++;
726 /* flip the CTS state selector flag to interrupt when it changes
728 ctr
= *port
->_control
;
730 *port
->_control
= ctr
;
732 uart_handle_cts_change(&port
->uart
, st
& SC2STR_CTS
);
733 wake_up_interruptible(&port
->uart
.state
->port
.delta_msr_wait
);
737 * handle a virtual interrupt generated by the lower level "virtual DMA"
738 * routines (irq is the baud timer interrupt)
740 static irqreturn_t
mn10300_serial_interrupt(int irq
, void *dev_id
)
742 struct mn10300_serial_port
*port
= dev_id
;
745 spin_lock(&port
->uart
.lock
);
747 if (port
->intr_flags
) {
748 _debug("INT %s: %x", port
->name
, port
->intr_flags
);
750 if (mask_test_and_clear(&port
->intr_flags
, MNSCx_RX_AVAIL
))
751 mn10300_serial_receive_interrupt(port
);
753 if (mask_test_and_clear(&port
->intr_flags
,
754 MNSCx_TX_SPACE
| MNSCx_TX_EMPTY
))
755 mn10300_serial_transmit_interrupt(port
);
758 /* the only modem control line amongst the whole lot is CTS on
760 if (port
->type
== PORT_MN10300_CTS
) {
762 if ((port
->tx_cts
^ st
) & SC2STR_CTS
)
763 mn10300_serial_cts_changed(port
, st
);
766 spin_unlock(&port
->uart
.lock
);
772 * return indication of whether the hardware transmit buffer is empty
774 static unsigned int mn10300_serial_tx_empty(struct uart_port
*_port
)
776 struct mn10300_serial_port
*port
=
777 container_of(_port
, struct mn10300_serial_port
, uart
);
779 _enter("%s", port
->name
);
781 return (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
)) ?
786 * set the modem control lines (we don't have any)
788 static void mn10300_serial_set_mctrl(struct uart_port
*_port
,
791 struct mn10300_serial_port
*port
__attribute__ ((unused
)) =
792 container_of(_port
, struct mn10300_serial_port
, uart
);
794 _enter("%s,%x", port
->name
, mctrl
);
798 * get the modem control line statuses
800 static unsigned int mn10300_serial_get_mctrl(struct uart_port
*_port
)
802 struct mn10300_serial_port
*port
=
803 container_of(_port
, struct mn10300_serial_port
, uart
);
805 _enter("%s", port
->name
);
807 if (port
->type
== PORT_MN10300_CTS
&& !(*port
->_status
& SC2STR_CTS
))
808 return TIOCM_CAR
| TIOCM_DSR
;
810 return TIOCM_CAR
| TIOCM_CTS
| TIOCM_DSR
;
814 * stop transmitting characters
816 static void mn10300_serial_stop_tx(struct uart_port
*_port
)
818 struct mn10300_serial_port
*port
=
819 container_of(_port
, struct mn10300_serial_port
, uart
);
821 _enter("%s", port
->name
);
823 /* disable the virtual DMA */
824 mn10300_serial_dis_tx_intr(port
);
828 * start transmitting characters
829 * - jump-start transmission if it has stalled
830 * - enable the serial Tx interrupt (used by the virtual DMA controller)
831 * - force an interrupt to happen if necessary
833 static void mn10300_serial_start_tx(struct uart_port
*_port
)
835 struct mn10300_serial_port
*port
=
836 container_of(_port
, struct mn10300_serial_port
, uart
);
840 CIRC_CNT(&port
->uart
.state
->xmit
.head
,
841 &port
->uart
.state
->xmit
.tail
,
844 /* kick the virtual DMA controller */
845 mn10300_serial_en_tx_intr(port
);
847 _debug("CTR=%04hx ICR=%02hx STR=%04x TMD=%02hx TBR=%04hx ICR=%04hx",
848 *port
->_control
, *port
->_intr
, *port
->_status
,
850 (port
->div_timer
== MNSCx_DIV_TIMER_8BIT
) ?
851 *(volatile u8
*)port
->_tmxbr
: *port
->_tmxbr
,
856 * transmit a high-priority XON/XOFF character
858 static void mn10300_serial_send_xchar(struct uart_port
*_port
, char ch
)
860 struct mn10300_serial_port
*port
=
861 container_of(_port
, struct mn10300_serial_port
, uart
);
864 _enter("%s,%02x", port
->name
, ch
);
866 if (likely(port
->gdbstub
)) {
869 spin_lock_irqsave(&port
->uart
.lock
, flags
);
870 mn10300_serial_en_tx_intr(port
);
871 spin_unlock_irqrestore(&port
->uart
.lock
, flags
);
877 * stop receiving characters
878 * - called whilst the port is being closed
880 static void mn10300_serial_stop_rx(struct uart_port
*_port
)
882 struct mn10300_serial_port
*port
=
883 container_of(_port
, struct mn10300_serial_port
, uart
);
887 _enter("%s", port
->name
);
889 ctr
= *port
->_control
;
891 *port
->_control
= ctr
;
893 mn10300_serial_dis_rx_intr(port
);
897 * enable modem status interrupts
899 static void mn10300_serial_enable_ms(struct uart_port
*_port
)
901 struct mn10300_serial_port
*port
=
902 container_of(_port
, struct mn10300_serial_port
, uart
);
906 _enter("%s", port
->name
);
908 if (port
->type
== PORT_MN10300_CTS
) {
909 /* want to interrupt when CTS goes low if CTS is now high and
912 port
->tx_cts
= *port
->_status
;
914 cts
= (port
->tx_cts
& SC2STR_CTS
) ?
915 SC2CTR_TWE
: SC2CTR_TWE
| SC2CTR_TWS
;
917 ctr
= *port
->_control
;
920 *port
->_control
= ctr
;
922 mn10300_serial_en_tx_intr(port
);
927 * transmit or cease transmitting a break signal
929 static void mn10300_serial_break_ctl(struct uart_port
*_port
, int ctl
)
931 struct mn10300_serial_port
*port
=
932 container_of(_port
, struct mn10300_serial_port
, uart
);
935 _enter("%s,%d", port
->name
, ctl
);
937 spin_lock_irqsave(&port
->uart
.lock
, flags
);
939 /* tell the virtual DMA handler to assert BREAK */
940 port
->tx_flags
|= MNSCx_TX_BREAK
;
941 mn10300_serial_en_tx_intr(port
);
943 port
->tx_flags
&= ~MNSCx_TX_BREAK
;
944 *port
->_control
&= ~SC01CTR_BKE
;
945 mn10300_serial_en_tx_intr(port
);
947 spin_unlock_irqrestore(&port
->uart
.lock
, flags
);
951 * grab the interrupts and enable the port for reception
953 static int mn10300_serial_startup(struct uart_port
*_port
)
955 struct mn10300_serial_port
*port
=
956 container_of(_port
, struct mn10300_serial_port
, uart
);
957 struct mn10300_serial_int
*pint
;
959 _enter("%s{%d}", port
->name
, port
->gdbstub
);
961 if (unlikely(port
->gdbstub
))
964 /* allocate an Rx buffer for the virtual DMA handler */
965 port
->rx_buffer
= kmalloc(MNSC_BUFFER_SIZE
, GFP_KERNEL
);
966 if (!port
->rx_buffer
)
969 port
->rx_inp
= port
->rx_outp
= 0;
972 /* finally, enable the device */
973 *port
->_intr
= SC01ICR_TI
;
974 *port
->_control
|= SC01CTR_TXE
| SC01CTR_RXE
;
976 pint
= &mn10300_serial_int_tbl
[port
->rx_irq
];
978 pint
->vdma
= mn10300_serial_vdma_rx_handler
;
979 pint
= &mn10300_serial_int_tbl
[port
->tx_irq
];
981 pint
->vdma
= mn10300_serial_vdma_tx_handler
;
983 irq_set_chip(port
->rx_irq
, &mn10300_serial_low_pic
);
984 irq_set_chip(port
->tx_irq
, &mn10300_serial_low_pic
);
985 irq_set_chip(port
->tm_irq
, &mn10300_serial_pic
);
987 if (request_irq(port
->rx_irq
, mn10300_serial_interrupt
,
989 port
->rx_name
, port
) < 0)
992 if (request_irq(port
->tx_irq
, mn10300_serial_interrupt
,
994 port
->tx_name
, port
) < 0)
997 if (request_irq(port
->tm_irq
, mn10300_serial_interrupt
,
999 port
->tm_name
, port
) < 0)
1001 mn10300_serial_mask_ack(port
->tm_irq
);
1006 free_irq(port
->tx_irq
, port
);
1008 free_irq(port
->rx_irq
, port
);
1010 kfree(port
->rx_buffer
);
1011 port
->rx_buffer
= NULL
;
1016 * shutdown the port and release interrupts
1018 static void mn10300_serial_shutdown(struct uart_port
*_port
)
1020 unsigned long flags
;
1022 struct mn10300_serial_port
*port
=
1023 container_of(_port
, struct mn10300_serial_port
, uart
);
1025 _enter("%s", port
->name
);
1027 spin_lock_irqsave(&_port
->lock
, flags
);
1028 mn10300_serial_dis_tx_intr(port
);
1030 *port
->rx_icr
= NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
);
1033 spin_unlock_irqrestore(&_port
->lock
, flags
);
1035 /* disable the serial port and its baud rate timer */
1036 *port
->_control
&= ~(SC01CTR_TXE
| SC01CTR_RXE
| SC01CTR_BKE
);
1039 if (port
->rx_buffer
) {
1040 void *buf
= port
->rx_buffer
;
1041 port
->rx_buffer
= NULL
;
1045 /* disable all intrs */
1046 free_irq(port
->tm_irq
, port
);
1047 free_irq(port
->rx_irq
, port
);
1048 free_irq(port
->tx_irq
, port
);
1050 mn10300_serial_int_tbl
[port
->tx_irq
].port
= NULL
;
1051 mn10300_serial_int_tbl
[port
->rx_irq
].port
= NULL
;
1055 * this routine is called to set the UART divisor registers to match the
1056 * specified baud rate for a serial port.
1058 static void mn10300_serial_change_speed(struct mn10300_serial_port
*port
,
1059 struct ktermios
*new,
1060 struct ktermios
*old
)
1062 unsigned long flags
;
1063 unsigned long ioclk
= port
->ioclk
;
1065 int baud
, bits
, xdiv
, tmp
;
1068 u8 div_timer
= port
->div_timer
;
1070 _enter("%s{%lu}", port
->name
, ioclk
);
1072 /* byte size and parity */
1073 cflag
= new->c_cflag
;
1074 switch (cflag
& CSIZE
) {
1075 case CS7
: scxctr
= SC01CTR_CLN_7BIT
; bits
= 9; break;
1076 case CS8
: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1077 default: scxctr
= SC01CTR_CLN_8BIT
; bits
= 10; break;
1080 if (cflag
& CSTOPB
) {
1081 scxctr
|= SC01CTR_STB_2BIT
;
1085 if (cflag
& PARENB
) {
1088 scxctr
|= SC01CTR_PB_ODD
;
1090 else if (cflag
& CMSPAR
)
1091 scxctr
|= SC01CTR_PB_FIXED0
;
1094 scxctr
|= SC01CTR_PB_EVEN
;
1097 /* Determine divisor based on baud rate */
1100 switch (port
->uart
.line
) {
1101 #ifdef CONFIG_MN10300_TTYSM0
1102 case 0: /* ttySM0 */
1103 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
1104 scxctr
|= SC0CTR_CK_TM8UFLOW_8
;
1105 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
1106 scxctr
|= SC0CTR_CK_TM0UFLOW_8
;
1107 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
1108 scxctr
|= SC0CTR_CK_TM2UFLOW_8
;
1110 #error "Unknown config for ttySM0"
1113 #endif /* CONFIG_MN10300_TTYSM0 */
1115 #ifdef CONFIG_MN10300_TTYSM1
1116 case 1: /* ttySM1 */
1117 #if defined(CONFIG_AM33_2) || defined(CONFIG_AM33_3)
1118 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
1119 scxctr
|= SC1CTR_CK_TM9UFLOW_8
;
1120 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
1121 scxctr
|= SC1CTR_CK_TM3UFLOW_8
;
1123 #error "Unknown config for ttySM1"
1125 #else /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1126 #if defined(CONFIG_MN10300_TTYSM1_TIMER12)
1127 scxctr
|= SC1CTR_CK_TM12UFLOW_8
;
1129 #error "Unknown config for ttySM1"
1131 #endif /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1133 #endif /* CONFIG_MN10300_TTYSM1 */
1135 #ifdef CONFIG_MN10300_TTYSM2
1136 case 2: /* ttySM2 */
1137 #if defined(CONFIG_AM33_2)
1138 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
1139 scxctr
|= SC2CTR_CK_TM10UFLOW
;
1141 #error "Unknown config for ttySM2"
1143 #else /* CONFIG_AM33_2 */
1144 #if defined(CONFIG_MN10300_TTYSM2_TIMER9)
1145 scxctr
|= SC2CTR_CK_TM9UFLOW_8
;
1146 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
1147 scxctr
|= SC2CTR_CK_TM1UFLOW_8
;
1148 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
1149 scxctr
|= SC2CTR_CK_TM3UFLOW_8
;
1151 #error "Unknown config for ttySM2"
1153 #endif /* CONFIG_AM33_2 */
1155 #endif /* CONFIG_MN10300_TTYSM2 */
1162 baud
= uart_get_baud_rate(&port
->uart
, new, old
, 0,
1165 _debug("ALT %d [baud %d]", battempt
, baud
);
1168 baud
= 9600; /* B0 transition handled in rs_set_termios */
1171 baud
= 269; /* 134 is really 134.5 */
1175 if (baud
== 38400 &&
1176 (port
->uart
.flags
& UPF_SPD_MASK
) == UPF_SPD_CUST
1178 _debug("CUSTOM %u", port
->uart
.custom_divisor
);
1180 if (div_timer
== MNSCx_DIV_TIMER_16BIT
) {
1181 if (port
->uart
.custom_divisor
<= 65535) {
1182 tmxmd
= TM8MD_SRC_IOCLK
;
1183 tmxbr
= port
->uart
.custom_divisor
;
1184 port
->uart
.uartclk
= ioclk
;
1187 if (port
->uart
.custom_divisor
/ 8 <= 65535) {
1188 tmxmd
= TM8MD_SRC_IOCLK_8
;
1189 tmxbr
= port
->uart
.custom_divisor
/ 8;
1190 port
->uart
.custom_divisor
= tmxbr
* 8;
1191 port
->uart
.uartclk
= ioclk
/ 8;
1194 if (port
->uart
.custom_divisor
/ 32 <= 65535) {
1195 tmxmd
= TM8MD_SRC_IOCLK_32
;
1196 tmxbr
= port
->uart
.custom_divisor
/ 32;
1197 port
->uart
.custom_divisor
= tmxbr
* 32;
1198 port
->uart
.uartclk
= ioclk
/ 32;
1202 } else if (div_timer
== MNSCx_DIV_TIMER_8BIT
) {
1203 if (port
->uart
.custom_divisor
<= 255) {
1204 tmxmd
= TM2MD_SRC_IOCLK
;
1205 tmxbr
= port
->uart
.custom_divisor
;
1206 port
->uart
.uartclk
= ioclk
;
1209 if (port
->uart
.custom_divisor
/ 8 <= 255) {
1210 tmxmd
= TM2MD_SRC_IOCLK_8
;
1211 tmxbr
= port
->uart
.custom_divisor
/ 8;
1212 port
->uart
.custom_divisor
= tmxbr
* 8;
1213 port
->uart
.uartclk
= ioclk
/ 8;
1216 if (port
->uart
.custom_divisor
/ 32 <= 255) {
1217 tmxmd
= TM2MD_SRC_IOCLK_32
;
1218 tmxbr
= port
->uart
.custom_divisor
/ 32;
1219 port
->uart
.custom_divisor
= tmxbr
* 32;
1220 port
->uart
.uartclk
= ioclk
/ 32;
1226 switch (div_timer
) {
1227 case MNSCx_DIV_TIMER_16BIT
:
1228 port
->uart
.uartclk
= ioclk
;
1229 tmxmd
= TM8MD_SRC_IOCLK
;
1230 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1231 if (tmp
> 0 && tmp
<= 65535)
1234 port
->uart
.uartclk
= ioclk
/ 8;
1235 tmxmd
= TM8MD_SRC_IOCLK_8
;
1236 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1237 if (tmp
> 0 && tmp
<= 65535)
1240 port
->uart
.uartclk
= ioclk
/ 32;
1241 tmxmd
= TM8MD_SRC_IOCLK_32
;
1242 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1243 if (tmp
> 0 && tmp
<= 65535)
1247 case MNSCx_DIV_TIMER_8BIT
:
1248 port
->uart
.uartclk
= ioclk
;
1249 tmxmd
= TM2MD_SRC_IOCLK
;
1250 tmxbr
= tmp
= (ioclk
/ (baud
* xdiv
) + 4) / 8 - 1;
1251 if (tmp
> 0 && tmp
<= 255)
1254 port
->uart
.uartclk
= ioclk
/ 8;
1255 tmxmd
= TM2MD_SRC_IOCLK_8
;
1256 tmxbr
= tmp
= (ioclk
/ (baud
* 8 * xdiv
) + 4) / 8 - 1;
1257 if (tmp
> 0 && tmp
<= 255)
1260 port
->uart
.uartclk
= ioclk
/ 32;
1261 tmxmd
= TM2MD_SRC_IOCLK_32
;
1262 tmxbr
= tmp
= (ioclk
/ (baud
* 32 * xdiv
) + 4) / 8 - 1;
1263 if (tmp
> 0 && tmp
<= 255)
1272 /* refuse to change to a baud rate we can't support */
1273 _debug("CAN'T SUPPORT");
1278 new->c_cflag
&= ~CBAUD
;
1279 new->c_cflag
|= (old
->c_cflag
& CBAUD
);
1281 goto try_alternative
;
1285 /* as a last resort, if the quotient is zero, default to 9600
1287 new->c_cflag
&= ~CBAUD
;
1288 new->c_cflag
|= B9600
;
1290 goto try_alternative
;
1293 /* hmmm... can't seem to support 9600 either
1294 * - we could try iterating through the speeds we know about to
1297 new->c_cflag
&= ~CBAUD
;
1300 if (div_timer
== MNSCx_DIV_TIMER_16BIT
)
1301 tmxmd
= TM8MD_SRC_IOCLK_32
;
1302 else if (div_timer
== MNSCx_DIV_TIMER_8BIT
)
1303 tmxmd
= TM2MD_SRC_IOCLK_32
;
1306 port
->uart
.uartclk
= ioclk
/ 32;
1311 _debug("UARTCLK: %u / %hu", port
->uart
.uartclk
, tmxbr
);
1313 /* make the changes */
1314 spin_lock_irqsave(&port
->uart
.lock
, flags
);
1316 uart_update_timeout(&port
->uart
, new->c_cflag
, baud
);
1318 /* set the timer to produce the required baud rate */
1319 switch (div_timer
) {
1320 case MNSCx_DIV_TIMER_16BIT
:
1322 *port
->_tmxbr
= tmxbr
;
1323 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1324 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1327 case MNSCx_DIV_TIMER_8BIT
:
1329 *(volatile u8
*) port
->_tmxbr
= (u8
) tmxbr
;
1330 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1331 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1335 /* CTS flow control flag and modem status interrupts */
1336 scxctr
&= ~(SC2CTR_TWE
| SC2CTR_TWS
);
1338 if (port
->type
== PORT_MN10300_CTS
&& cflag
& CRTSCTS
) {
1339 /* want to interrupt when CTS goes low if CTS is now
1340 * high and vice versa
1342 port
->tx_cts
= *port
->_status
;
1344 if (port
->tx_cts
& SC2STR_CTS
)
1345 scxctr
|= SC2CTR_TWE
;
1347 scxctr
|= SC2CTR_TWE
| SC2CTR_TWS
;
1350 /* set up parity check flag */
1351 port
->uart
.read_status_mask
= (1 << TTY_NORMAL
) | (1 << TTY_OVERRUN
);
1352 if (new->c_iflag
& INPCK
)
1353 port
->uart
.read_status_mask
|=
1354 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1355 if (new->c_iflag
& (BRKINT
| PARMRK
))
1356 port
->uart
.read_status_mask
|= (1 << TTY_BREAK
);
1358 /* characters to ignore */
1359 port
->uart
.ignore_status_mask
= 0;
1360 if (new->c_iflag
& IGNPAR
)
1361 port
->uart
.ignore_status_mask
|=
1362 (1 << TTY_PARITY
) | (1 << TTY_FRAME
);
1363 if (new->c_iflag
& IGNBRK
) {
1364 port
->uart
.ignore_status_mask
|= (1 << TTY_BREAK
);
1366 * If we're ignoring parity and break indicators,
1367 * ignore overruns to (for real raw support).
1369 if (new->c_iflag
& IGNPAR
)
1370 port
->uart
.ignore_status_mask
|= (1 << TTY_OVERRUN
);
1373 /* Ignore all characters if CREAD is not set */
1374 if ((new->c_cflag
& CREAD
) == 0)
1375 port
->uart
.ignore_status_mask
|= (1 << TTY_NORMAL
);
1377 scxctr
|= SC01CTR_TXE
| SC01CTR_RXE
;
1378 scxctr
|= *port
->_control
& SC01CTR_BKE
;
1379 *port
->_control
= scxctr
;
1381 spin_unlock_irqrestore(&port
->uart
.lock
, flags
);
1385 * set the terminal I/O parameters
1387 static void mn10300_serial_set_termios(struct uart_port
*_port
,
1388 struct ktermios
*new,
1389 struct ktermios
*old
)
1391 struct mn10300_serial_port
*port
=
1392 container_of(_port
, struct mn10300_serial_port
, uart
);
1394 _enter("%s,%p,%p", port
->name
, new, old
);
1396 mn10300_serial_change_speed(port
, new, old
);
1398 /* handle turning off CRTSCTS */
1399 if (!(new->c_cflag
& CRTSCTS
)) {
1400 u16 ctr
= *port
->_control
;
1402 *port
->_control
= ctr
;
1405 /* change Transfer bit-order (LSB/MSB) */
1406 if (new->c_cflag
& CODMSB
)
1407 *port
->_control
|= SC01CTR_OD_MSBFIRST
; /* MSB MODE */
1409 *port
->_control
&= ~SC01CTR_OD_MSBFIRST
; /* LSB MODE */
1413 * return description of port type
1415 static const char *mn10300_serial_type(struct uart_port
*_port
)
1417 struct mn10300_serial_port
*port
=
1418 container_of(_port
, struct mn10300_serial_port
, uart
);
1420 if (port
->uart
.type
== PORT_MN10300_CTS
)
1421 return "MN10300 SIF_CTS";
1423 return "MN10300 SIF";
1427 * release I/O and memory regions in use by port
1429 static void mn10300_serial_release_port(struct uart_port
*_port
)
1431 struct mn10300_serial_port
*port
=
1432 container_of(_port
, struct mn10300_serial_port
, uart
);
1434 _enter("%s", port
->name
);
1436 release_mem_region((unsigned long) port
->_iobase
, 16);
1440 * request I/O and memory regions for port
1442 static int mn10300_serial_request_port(struct uart_port
*_port
)
1444 struct mn10300_serial_port
*port
=
1445 container_of(_port
, struct mn10300_serial_port
, uart
);
1447 _enter("%s", port
->name
);
1449 request_mem_region((unsigned long) port
->_iobase
, 16, port
->name
);
1454 * configure the type and reserve the ports
1456 static void mn10300_serial_config_port(struct uart_port
*_port
, int type
)
1458 struct mn10300_serial_port
*port
=
1459 container_of(_port
, struct mn10300_serial_port
, uart
);
1461 _enter("%s", port
->name
);
1463 port
->uart
.type
= PORT_MN10300
;
1465 if (port
->options
& MNSCx_OPT_CTS
)
1466 port
->uart
.type
= PORT_MN10300_CTS
;
1468 mn10300_serial_request_port(_port
);
1472 * verify serial parameters are suitable for this port type
1474 static int mn10300_serial_verify_port(struct uart_port
*_port
,
1475 struct serial_struct
*ss
)
1477 struct mn10300_serial_port
*port
=
1478 container_of(_port
, struct mn10300_serial_port
, uart
);
1479 void *mapbase
= (void *) (unsigned long) port
->uart
.mapbase
;
1481 _enter("%s", port
->name
);
1483 /* these things may not be changed */
1484 if (ss
->irq
!= port
->uart
.irq
||
1485 ss
->port
!= port
->uart
.iobase
||
1486 ss
->io_type
!= port
->uart
.iotype
||
1487 ss
->iomem_base
!= mapbase
||
1488 ss
->iomem_reg_shift
!= port
->uart
.regshift
||
1489 ss
->hub6
!= port
->uart
.hub6
||
1490 ss
->xmit_fifo_size
!= port
->uart
.fifosize
)
1493 /* type may be changed on a port that supports CTS */
1494 if (ss
->type
!= port
->uart
.type
) {
1495 if (!(port
->options
& MNSCx_OPT_CTS
))
1498 if (ss
->type
!= PORT_MN10300
&&
1499 ss
->type
!= PORT_MN10300_CTS
)
1507 * initialise the MN10300 on-chip UARTs
1509 static int __init
mn10300_serial_init(void)
1511 struct mn10300_serial_port
*port
;
1514 printk(KERN_INFO
"%s version %s (%s)\n",
1515 serial_name
, serial_version
, serial_revdate
);
1517 #if defined(CONFIG_MN10300_TTYSM2) && defined(CONFIG_AM33_2)
1520 SC2TIM
= 8; /* make the baud base of timer 2 IOCLK/8 */
1525 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL
),
1526 mn10300_serial_vdma_interrupt
);
1528 ret
= uart_register_driver(&mn10300_serial_driver
);
1530 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1531 port
= mn10300_serial_ports
[i
];
1532 if (!port
|| port
->gdbstub
)
1535 switch (port
->clock_src
) {
1536 case MNSCx_CLOCK_SRC_IOCLK
:
1537 port
->ioclk
= MN10300_IOCLK
;
1540 #ifdef MN10300_IOBCLK
1541 case MNSCx_CLOCK_SRC_IOBCLK
:
1542 port
->ioclk
= MN10300_IOBCLK
;
1549 ret
= uart_add_one_port(&mn10300_serial_driver
,
1553 _debug("ERROR %d", -ret
);
1559 uart_unregister_driver(&mn10300_serial_driver
);
1565 __initcall(mn10300_serial_init
);
1568 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
1571 * print a string to the serial port without disturbing the real user of the
1573 * - the console must be locked by the caller
1575 static void mn10300_serial_console_write(struct console
*co
,
1576 const char *s
, unsigned count
)
1578 struct mn10300_serial_port
*port
;
1582 unsigned long flags
;
1585 port
= mn10300_serial_ports
[co
->index
];
1587 local_irq_save(flags
);
1588 if (port
->uart
.sysrq
) {
1589 /* mn10300_serial_interrupt() already took the lock */
1591 } else if (oops_in_progress
) {
1592 locked
= spin_trylock(&port
->uart
.lock
);
1594 spin_lock(&port
->uart
.lock
);
1596 /* firstly hijack the serial port from the "virtual DMA" controller */
1597 mn10300_serial_dis_tx_intr(port
);
1599 /* the transmitter may be disabled */
1600 scxctr
= *port
->_control
;
1601 if (!(scxctr
& SC01CTR_TXE
)) {
1602 /* restart the UART clock */
1603 tmxmd
= *port
->_tmxmd
;
1605 switch (port
->div_timer
) {
1606 case MNSCx_DIV_TIMER_16BIT
:
1608 *port
->_tmxmd
= TM8MD_INIT_COUNTER
;
1609 *port
->_tmxmd
= tmxmd
| TM8MD_COUNT_ENABLE
;
1612 case MNSCx_DIV_TIMER_8BIT
:
1614 *port
->_tmxmd
= TM2MD_INIT_COUNTER
;
1615 *port
->_tmxmd
= tmxmd
| TM2MD_COUNT_ENABLE
;
1619 /* enable the transmitter */
1620 *port
->_control
= (scxctr
& ~SC01CTR_BKE
) | SC01CTR_TXE
;
1622 } else if (scxctr
& SC01CTR_BKE
) {
1623 /* stop transmitting BREAK */
1624 *port
->_control
= (scxctr
& ~SC01CTR_BKE
);
1627 /* send the chars into the serial port (with LF -> LFCR conversion) */
1628 for (i
= 0; i
< count
; i
++) {
1631 while (*port
->_status
& SC01STR_TBF
)
1636 while (*port
->_status
& SC01STR_TBF
)
1642 /* can't let the transmitter be turned off if it's actually
1644 while (*port
->_status
& (SC01STR_TXF
| SC01STR_TBF
))
1647 /* disable the transmitter if we re-enabled it */
1648 if (!(scxctr
& SC01CTR_TXE
))
1649 *port
->_control
= scxctr
;
1651 mn10300_serial_en_tx_intr(port
);
1654 spin_unlock(&port
->uart
.lock
);
1655 local_irq_restore(flags
);
1659 * set up a serial port as a console
1660 * - construct a cflag setting for the first rs_open()
1661 * - initialize the serial port
1662 * - return non-zero if we didn't find a serial port.
1664 static int __init
mn10300_serial_console_setup(struct console
*co
,
1667 struct mn10300_serial_port
*port
;
1668 int i
, parity
= 'n', baud
= 9600, bits
= 8, flow
= 0;
1670 for (i
= 0 ; i
< NR_PORTS
; i
++) {
1671 port
= mn10300_serial_ports
[i
];
1672 if (port
&& !port
->gdbstub
&& port
->uart
.line
== co
->index
)
1679 switch (port
->clock_src
) {
1680 case MNSCx_CLOCK_SRC_IOCLK
:
1681 port
->ioclk
= MN10300_IOCLK
;
1684 #ifdef MN10300_IOBCLK
1685 case MNSCx_CLOCK_SRC_IOBCLK
:
1686 port
->ioclk
= MN10300_IOBCLK
;
1694 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1696 return uart_set_options(&port
->uart
, co
, baud
, parity
, bits
, flow
);
1702 static int __init
mn10300_serial_console_init(void)
1704 register_console(&mn10300_serial_console
);
1708 console_initcall(mn10300_serial_console_init
);
1711 #ifdef CONFIG_CONSOLE_POLL
1713 * Polled character reception for the kernel debugger
1715 static int mn10300_serial_poll_get_char(struct uart_port
*_port
)
1717 struct mn10300_serial_port
*port
=
1718 container_of(_port
, struct mn10300_serial_port
, uart
);
1722 _enter("%s", port
->name
);
1724 if (mn10300_serial_int_tbl
[port
->rx_irq
].port
!= NULL
) {
1726 /* pull chars out of the hat */
1727 ix
= READ_ONCE(port
->rx_outp
);
1728 if (CIRC_CNT(port
->rx_inp
, ix
, MNSC_BUFFER_SIZE
) == 0)
1729 return NO_POLL_CHAR
;
1732 * READ_ONCE() enforces dependency, but dangerous
1733 * through integer!!!
1735 ch
= port
->rx_buffer
[ix
++];
1736 st
= port
->rx_buffer
[ix
++];
1738 port
->rx_outp
= ix
& (MNSC_BUFFER_SIZE
- 1);
1740 } while (st
& (SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
));
1743 st
= *port
->_status
;
1744 if (st
& (SC01STR_FEF
| SC01STR_PEF
| SC01STR_OEF
))
1746 } while (!(st
& SC01STR_RBF
));
1756 * Polled character transmission for the kernel debugger
1758 static void mn10300_serial_poll_put_char(struct uart_port
*_port
,
1761 struct mn10300_serial_port
*port
=
1762 container_of(_port
, struct mn10300_serial_port
, uart
);
1765 /* wait for the transmitter to finish anything it might be doing (and
1766 * this includes the virtual DMA handler, so it might take a while) */
1767 while (*port
->_status
& (SC01STR_TBF
| SC01STR_TXF
))
1770 /* disable the Tx ready interrupt */
1771 intr
= *port
->_intr
;
1772 *port
->_intr
= intr
& ~SC01ICR_TI
;
1777 while (*port
->_status
& SC01STR_TBF
)
1782 while (*port
->_status
& SC01STR_TBF
)
1785 /* restore the Tx interrupt flag */
1786 *port
->_intr
= intr
;
1790 #endif /* CONFIG_CONSOLE_POLL */