2 * linux/drivers/char/au1x00_uart.c
4 * Driver for the 16550-like Au1x00 serial ports
5 * Basically a copy of 8250.c minus everything I could gut out
8 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
10 * Copyright (C) 2001 Russell King.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * $Id: 8250.c,v 1.90 2002/07/28 10:03:27 rmk Exp $
19 * A note about mapbase / membase
21 * mapbase is the physical address of the IO port. Currently, we don't
22 * support this very well, and it may well be dropped from this driver
23 * in future. As such, mapbase should be NULL.
25 * membase is an 'ioremapped' cookie. This is compatible with the old
26 * serial.c driver, and is currently the preferred form.
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/tty.h>
31 #include <linux/ioport.h>
32 #include <linux/init.h>
33 #include <linux/console.h>
34 #include <linux/sysrq.h>
35 #include <linux/serial.h>
36 #include <linux/serialP.h>
37 #include <linux/delay.h>
42 #if defined(CONFIG_SERIAL_AU1X00_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
46 #include <linux/serial_core.h>
53 * share_irqs - whether we pass SA_SHIRQ to request_irq(). This option
54 * is unsafe when used on edge-triggered interrupts.
56 unsigned int share_irqs
= SERIAL8250_SHARE_IRQS
;
62 #define DEBUG_AUTOCONF(fmt...) printk(fmt)
64 #define DEBUG_AUTOCONF(fmt...) do { } while (0)
68 #define DEBUG_INTR(fmt...) printk(fmt)
70 #define DEBUG_INTR(fmt...) do { } while (0)
73 #define PASS_LIMIT 256
76 * We default to IRQ0 for the "no irq" hack. Some
77 * machine types want others as well - they're free
78 * to redefine this in their header file.
80 #define is_real_interrupt(irq) ((irq) != 0)
83 * This converts from our new CONFIG_ symbols to the symbols
84 * that asm/serial.h expects. You _NEED_ to comment out the
85 * linux/config.h include contained inside asm/serial.h for
88 #undef CONFIG_SERIAL_MANY_PORTS
89 #undef CONFIG_SERIAL_DETECT_IRQ
90 #undef CONFIG_SERIAL_MULTIPORT
93 #ifdef CONFIG_SERIAL_8250_DETECT_IRQ
94 #define CONFIG_SERIAL_DETECT_IRQ 1
96 #ifdef CONFIG_SERIAL_8250_MULTIPORT
97 #define CONFIG_SERIAL_MULTIPORT 1
100 #include <asm/serial.h>
102 static struct old_serial_port old_serial_port
[] = {
103 SERIAL_PORT_DFNS
/* defined in asm/serial.h */
106 #define UART_NR ARRAY_SIZE(old_serial_port)
108 struct uart_8250_port
{
109 struct uart_port port
;
110 struct timer_list timer
; /* "no irq" timer */
111 struct list_head list
; /* ports on this IRQ */
116 unsigned char mcr_mask
; /* mask of user bits */
117 unsigned char mcr_force
; /* mask of forced bits */
118 unsigned int lsr_break_flag
;
121 * We provide a per-port pm hook.
123 void (*pm
)(struct uart_port
*port
,
124 unsigned int state
, unsigned int old
);
129 struct list_head
*head
;
132 static struct irq_info irq_lists
[NR_IRQS
];
135 * Here we define the default xmit fifo size used for each type of UART.
137 static const struct serial_uart_config uart_config
[1] = {
138 { "AU1X00_UART", 16, UART_CLEAR_FIFO
| UART_USE_FIFO
},
142 static _INLINE_
unsigned int serial_in(struct uart_8250_port
*up
, int offset
)
144 return au_readl((unsigned long)up
->port
.membase
+ offset
);
148 serial_out(struct uart_8250_port
*up
, int offset
, int value
)
150 au_writel(value
, (unsigned long)up
->port
.membase
+ offset
);
154 * We used to support using pause I/O for certain machines. We
155 * haven't supported this for a while, but just in case it's badly
156 * needed for certain old 386 machines, I've left these #define's
159 #define serial_inp(up, offset) serial_in(up, offset)
160 #define serial_outp(up, offset, value) serial_out(up, offset, value)
164 * This routine is called by rs_init() to initialize a specific serial
165 * port. It determines what type of UART chip this serial port is
166 * using: 8250, 16450, 16550, 16550A. The important question is
167 * whether or not this UART is a 16550A or not, since this will
168 * determine whether or not we can use its FIFO features or not.
170 static void autoconfig(struct uart_8250_port
*up
, unsigned int probeflags
)
172 unsigned char save_lcr
, save_mcr
;
175 if (!up
->port
.iobase
&& !up
->port
.membase
)
178 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%08lx): ",
179 up
->port
.line
, up
->port
.iobase
, up
->port
.membase
);
182 * We really do need global IRQs disabled here - we're going to
183 * be frobbing the chips IRQ enable register to see if it exists.
185 spin_lock_irqsave(&up
->port
.lock
, flags
);
186 // save_flags(flags); cli();
188 save_mcr
= serial_in(up
, UART_MCR
);
189 save_lcr
= serial_in(up
, UART_LCR
);
191 up
->port
.type
= AU1X00_UART
;
192 serial_outp(up
, UART_LCR
, save_lcr
);
194 up
->port
.fifosize
= uart_config
[up
->port
.type
].dfl_xmit_fifo_size
;
196 if (up
->port
.type
== PORT_UNKNOWN
)
202 serial_outp(up
, UART_MCR
, save_mcr
);
203 serial_outp(up
, UART_FCR
, (UART_FCR_ENABLE_FIFO
|
204 UART_FCR_CLEAR_RCVR
|
205 UART_FCR_CLEAR_XMIT
));
206 serial_outp(up
, UART_FCR
, 0);
207 (void)serial_in(up
, UART_RX
);
208 serial_outp(up
, UART_IER
, 0);
211 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
212 // restore_flags(flags);
213 DEBUG_AUTOCONF("type=%s\n", uart_config
[up
->port
.type
].name
);
216 static void serial_au1x00_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
218 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
220 if (up
->ier
& UART_IER_THRI
) {
221 up
->ier
&= ~UART_IER_THRI
;
222 serial_out(up
, UART_IER
, up
->ier
);
226 static void serial_au1x00_start_tx(struct uart_port
*port
, unsigned int tty_start
)
228 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
230 if (!(up
->ier
& UART_IER_THRI
)) {
231 up
->ier
|= UART_IER_THRI
;
232 serial_out(up
, UART_IER
, up
->ier
);
236 static void serial_au1x00_stop_rx(struct uart_port
*port
)
238 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
240 up
->ier
&= ~UART_IER_RLSI
;
241 up
->port
.read_status_mask
&= ~UART_LSR_DR
;
242 serial_out(up
, UART_IER
, up
->ier
);
245 static void serial_au1x00_enable_ms(struct uart_port
*port
)
247 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
249 up
->ier
|= UART_IER_MSI
;
250 serial_out(up
, UART_IER
, up
->ier
);
254 receive_chars(struct uart_8250_port
*up
, int *status
, struct pt_regs
*regs
)
256 struct tty_struct
*tty
= up
->port
.info
->tty
;
261 if (unlikely(tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)) {
262 tty
->flip
.work
.func((void *)tty
);
263 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
264 return; // if TTY_DONT_FLIP is set
266 ch
= serial_inp(up
, UART_RX
);
267 *tty
->flip
.char_buf_ptr
= ch
;
268 *tty
->flip
.flag_buf_ptr
= TTY_NORMAL
;
269 up
->port
.icount
.rx
++;
271 if (unlikely(*status
& (UART_LSR_BI
| UART_LSR_PE
|
272 UART_LSR_FE
| UART_LSR_OE
))) {
274 * For statistics only
276 if (*status
& UART_LSR_BI
) {
277 *status
&= ~(UART_LSR_FE
| UART_LSR_PE
);
278 up
->port
.icount
.brk
++;
280 * We do the SysRQ and SAK checking
281 * here because otherwise the break
282 * may get masked by ignore_status_mask
283 * or read_status_mask.
285 if (uart_handle_break(&up
->port
))
287 } else if (*status
& UART_LSR_PE
)
288 up
->port
.icount
.parity
++;
289 else if (*status
& UART_LSR_FE
)
290 up
->port
.icount
.frame
++;
291 if (*status
& UART_LSR_OE
)
292 up
->port
.icount
.overrun
++;
295 * Mask off conditions which should be ingored.
297 *status
&= up
->port
.read_status_mask
;
299 #ifdef CONFIG_SERIAL_AU1X00_CONSOLE
300 if (up
->port
.line
== up
->port
.cons
->index
) {
301 /* Recover the break flag from console xmit */
302 *status
|= up
->lsr_break_flag
;
303 up
->lsr_break_flag
= 0;
306 if (*status
& UART_LSR_BI
) {
307 DEBUG_INTR("handling break....");
308 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
309 } else if (*status
& UART_LSR_PE
)
310 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
311 else if (*status
& UART_LSR_FE
)
312 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
314 if (uart_handle_sysrq_char(&up
->port
, ch
, regs
))
316 if ((*status
& up
->port
.ignore_status_mask
) == 0) {
317 tty
->flip
.flag_buf_ptr
++;
318 tty
->flip
.char_buf_ptr
++;
321 if ((*status
& UART_LSR_OE
) &&
322 tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
324 * Overrun is special, since it's reported
325 * immediately, and doesn't affect the current
328 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
329 tty
->flip
.flag_buf_ptr
++;
330 tty
->flip
.char_buf_ptr
++;
334 *status
= serial_inp(up
, UART_LSR
);
335 } while ((*status
& UART_LSR_DR
) && (max_count
-- > 0));
336 tty_flip_buffer_push(tty
);
339 static _INLINE_
void transmit_chars(struct uart_8250_port
*up
)
341 struct circ_buf
*xmit
= &up
->port
.info
->xmit
;
344 if (up
->port
.x_char
) {
345 serial_outp(up
, UART_TX
, up
->port
.x_char
);
346 up
->port
.icount
.tx
++;
350 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
351 serial_au1x00_stop_tx(&up
->port
, 0);
355 count
= up
->port
.fifosize
;
357 serial_out(up
, UART_TX
, xmit
->buf
[xmit
->tail
]);
358 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
359 up
->port
.icount
.tx
++;
360 if (uart_circ_empty(xmit
))
362 } while (--count
> 0);
364 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
365 uart_write_wakeup(&up
->port
);
367 DEBUG_INTR("THRE...");
369 if (uart_circ_empty(xmit
))
370 serial_au1x00_stop_tx(&up
->port
, 0);
373 static _INLINE_
void check_modem_status(struct uart_8250_port
*up
)
377 status
= serial_in(up
, UART_MSR
);
379 if ((status
& UART_MSR_ANY_DELTA
) == 0)
382 if (status
& UART_MSR_TERI
)
383 up
->port
.icount
.rng
++;
384 if (status
& UART_MSR_DDSR
)
385 up
->port
.icount
.dsr
++;
386 if (status
& UART_MSR_DDCD
)
387 uart_handle_dcd_change(&up
->port
, status
& UART_MSR_DCD
);
388 if (status
& UART_MSR_DCTS
)
389 uart_handle_cts_change(&up
->port
, status
& UART_MSR_CTS
);
391 wake_up_interruptible(&up
->port
.info
->delta_msr_wait
);
395 * This handles the interrupt from one port.
398 serial_au1x00_handle_port(struct uart_8250_port
*up
, struct pt_regs
*regs
)
400 unsigned int status
= serial_inp(up
, UART_LSR
);
402 DEBUG_INTR("status = %x...", status
);
404 if (status
& UART_LSR_DR
)
405 receive_chars(up
, &status
, regs
);
406 check_modem_status(up
);
407 if (status
& UART_LSR_THRE
)
412 * This is the serial driver's interrupt routine.
414 * Arjan thinks the old way was overly complex, so it got simplified.
415 * Alan disagrees, saying that need the complexity to handle the weird
416 * nature of ISA shared interrupts. (This is a special exception.)
418 * In order to handle ISA shared interrupts properly, we need to check
419 * that all ports have been serviced, and therefore the ISA interrupt
420 * line has been de-asserted.
422 * This means we need to loop through all ports. checking that they
423 * don't have an interrupt pending.
425 static void serial_au1x00_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
427 struct irq_info
*i
= dev_id
;
428 struct list_head
*l
, *end
= NULL
;
429 int pass_counter
= 0;
431 DEBUG_INTR("serial_au1x00_interrupt(%d)...", irq
);
437 struct uart_8250_port
*up
;
440 up
= list_entry(l
, struct uart_8250_port
, list
);
442 iir
= serial_in(up
, UART_IIR
);
443 if (!(iir
& UART_IIR_NO_INT
)) {
444 spin_lock(&up
->port
.lock
);
445 serial_au1x00_handle_port(up
, regs
);
446 spin_unlock(&up
->port
.lock
);
449 } else if (end
== NULL
)
454 if (l
== i
->head
&& pass_counter
++ > PASS_LIMIT
) {
455 /* If we hit this, we're dead. */
456 printk(KERN_ERR
"serial_au1x00: too much work for "
462 spin_unlock(&i
->lock
);
464 DEBUG_INTR("end.\n");
468 * To support ISA shared interrupts, we need to have one interrupt
469 * handler that ensures that the IRQ line has been deasserted
470 * before returning. Failing to do this will result in the IRQ
471 * line being stuck active, and, since ISA irqs are edge triggered,
472 * no more IRQs will be seen.
474 static void serial_do_unlink(struct irq_info
*i
, struct uart_8250_port
*up
)
476 spin_lock_irq(&i
->lock
);
478 if (!list_empty(i
->head
)) {
479 if (i
->head
== &up
->list
)
480 i
->head
= i
->head
->next
;
483 BUG_ON(i
->head
!= &up
->list
);
487 spin_unlock_irq(&i
->lock
);
490 static int serial_link_irq_chain(struct uart_8250_port
*up
)
492 struct irq_info
*i
= irq_lists
+ up
->port
.irq
;
493 int ret
, irq_flags
= up
->port
.flags
& UPF_SHARE_IRQ
? SA_SHIRQ
: 0;
495 spin_lock_irq(&i
->lock
);
498 list_add(&up
->list
, i
->head
);
499 spin_unlock_irq(&i
->lock
);
503 INIT_LIST_HEAD(&up
->list
);
505 spin_unlock_irq(&i
->lock
);
507 ret
= request_irq(up
->port
.irq
, serial_au1x00_interrupt
,
508 irq_flags
, "serial", i
);
510 serial_do_unlink(i
, up
);
516 static void serial_unlink_irq_chain(struct uart_8250_port
*up
)
518 struct irq_info
*i
= irq_lists
+ up
->port
.irq
;
520 BUG_ON(i
->head
== NULL
);
522 if (list_empty(i
->head
))
523 free_irq(up
->port
.irq
, i
);
525 serial_do_unlink(i
, up
);
529 * This function is used to handle ports that do not have an
530 * interrupt. This doesn't work very well for 16450's, but gives
531 * barely passable results for a 16550A. (Although at the expense
532 * of much CPU overhead).
534 static void serial_au1x00_timeout(unsigned long data
)
536 struct uart_8250_port
*up
= (struct uart_8250_port
*)data
;
537 unsigned int timeout
;
540 iir
= serial_in(up
, UART_IIR
);
541 if (!(iir
& UART_IIR_NO_INT
)) {
542 spin_lock(&up
->port
.lock
);
543 serial_au1x00_handle_port(up
, NULL
);
544 spin_unlock(&up
->port
.lock
);
547 timeout
= up
->port
.timeout
;
548 timeout
= timeout
> 6 ? (timeout
/ 2 - 2) : 1;
549 mod_timer(&up
->timer
, jiffies
+ timeout
);
552 static unsigned int serial_au1x00_tx_empty(struct uart_port
*port
)
554 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
558 spin_lock_irqsave(&up
->port
.lock
, flags
);
559 ret
= serial_in(up
, UART_LSR
) & UART_LSR_TEMT
? TIOCSER_TEMT
: 0;
560 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
565 static unsigned int serial_au1x00_get_mctrl(struct uart_port
*port
)
567 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
569 unsigned char status
;
572 spin_lock_irqsave(&up
->port
.lock
, flags
);
573 status
= serial_in(up
, UART_MSR
);
574 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
577 if (status
& UART_MSR_DCD
)
579 if (status
& UART_MSR_RI
)
581 if (status
& UART_MSR_DSR
)
583 if (status
& UART_MSR_CTS
)
588 static void serial_au1x00_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
590 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
591 unsigned char mcr
= 0;
593 if (mctrl
& TIOCM_RTS
)
595 if (mctrl
& TIOCM_DTR
)
597 if (mctrl
& TIOCM_OUT1
)
598 mcr
|= UART_MCR_OUT1
;
599 if (mctrl
& TIOCM_OUT2
)
600 mcr
|= UART_MCR_OUT2
;
601 if (mctrl
& TIOCM_LOOP
)
602 mcr
|= UART_MCR_LOOP
;
604 mcr
= (mcr
& up
->mcr_mask
) | up
->mcr_force
;
606 serial_out(up
, UART_MCR
, mcr
);
609 static void serial_au1x00_break_ctl(struct uart_port
*port
, int break_state
)
611 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
614 spin_lock_irqsave(&up
->port
.lock
, flags
);
615 if (break_state
== -1)
616 up
->lcr
|= UART_LCR_SBC
;
618 up
->lcr
&= ~UART_LCR_SBC
;
619 serial_out(up
, UART_LCR
, up
->lcr
);
620 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
623 static int serial_au1x00_startup(struct uart_port
*port
)
625 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
631 * Clear the FIFO buffers and disable them.
632 * (they will be reeanbled in change_speed())
634 if (uart_config
[up
->port
.type
].flags
& UART_CLEAR_FIFO
) {
635 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
636 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
|
637 UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
);
638 serial_outp(up
, UART_FCR
, 0);
642 * Clear the interrupt registers.
644 (void) serial_inp(up
, UART_LSR
);
645 (void) serial_inp(up
, UART_RX
);
646 (void) serial_inp(up
, UART_IIR
);
647 (void) serial_inp(up
, UART_MSR
);
650 * At this point, there's no way the LSR could still be 0xff;
651 * if it is, then bail out, because there's likely no UART
654 if (!(up
->port
.flags
& UPF_BUGGY_UART
) &&
655 (serial_inp(up
, UART_LSR
) == 0xff)) {
656 printk("ttyS%d: LSR safety check engaged!\n", up
->port
.line
);
661 * If the "interrupt" for this port doesn't correspond with any
662 * hardware interrupt, we use a timer-based system. The original
663 * driver used to do this with IRQ0.
665 if (!is_real_interrupt(up
->port
.irq
)) {
666 unsigned int timeout
= up
->port
.timeout
;
668 timeout
= timeout
> 6 ? (timeout
/ 2 - 2) : 1;
670 up
->timer
.data
= (unsigned long)up
;
671 mod_timer(&up
->timer
, jiffies
+ timeout
);
673 retval
= serial_link_irq_chain(up
);
679 * Now, initialize the UART
681 serial_outp(up
, UART_LCR
, UART_LCR_WLEN8
);
683 spin_lock_irqsave(&up
->port
.lock
, flags
);
684 if (up
->port
.flags
& UPF_FOURPORT
) {
685 if (!is_real_interrupt(up
->port
.irq
))
686 up
->port
.mctrl
|= TIOCM_OUT1
;
689 * Most PC uarts need OUT2 raised to enable interrupts.
691 if (is_real_interrupt(up
->port
.irq
))
692 up
->port
.mctrl
|= TIOCM_OUT2
;
694 serial_au1x00_set_mctrl(&up
->port
, up
->port
.mctrl
);
695 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
698 * Finally, enable interrupts. Note: Modem status interrupts
699 * are set via change_speed(), which will be occuring imminently
700 * anyway, so we don't enable them here.
702 up
->ier
= UART_IER_RLSI
| UART_IER_RDI
;
703 serial_outp(up
, UART_IER
, up
->ier
);
705 if (up
->port
.flags
& UPF_FOURPORT
) {
708 * Enable interrupts on the AST Fourport board
710 icp
= (up
->port
.iobase
& 0xfe0) | 0x01f;
716 * And clear the interrupt registers again for luck.
718 (void) serial_inp(up
, UART_LSR
);
719 (void) serial_inp(up
, UART_RX
);
720 (void) serial_inp(up
, UART_IIR
);
721 (void) serial_inp(up
, UART_MSR
);
726 static void serial_au1x00_shutdown(struct uart_port
*port
)
728 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
732 * Disable interrupts from this port
735 serial_outp(up
, UART_IER
, 0);
737 spin_lock_irqsave(&up
->port
.lock
, flags
);
738 if (up
->port
.flags
& UPF_FOURPORT
) {
739 /* reset interrupts on the AST Fourport board */
740 inb((up
->port
.iobase
& 0xfe0) | 0x1f);
741 up
->port
.mctrl
|= TIOCM_OUT1
;
743 up
->port
.mctrl
&= ~TIOCM_OUT2
;
745 serial_au1x00_set_mctrl(&up
->port
, up
->port
.mctrl
);
746 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
749 * Disable break condition and FIFOs
751 serial_out(up
, UART_LCR
, serial_inp(up
, UART_LCR
) & ~UART_LCR_SBC
);
752 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
|
753 UART_FCR_CLEAR_RCVR
|
754 UART_FCR_CLEAR_XMIT
);
755 serial_outp(up
, UART_FCR
, 0);
758 * Read data port to reset things, and then unlink from
761 (void) serial_in(up
, UART_RX
);
763 if (!is_real_interrupt(up
->port
.irq
))
764 del_timer_sync(&up
->timer
);
766 serial_unlink_irq_chain(up
);
770 serial_au1x00_change_speed(struct uart_port
*port
, unsigned int cflag
,
771 unsigned int iflag
, unsigned int quot
)
773 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
777 switch (cflag
& CSIZE
) {
796 cval
|= UART_LCR_PARITY
;
797 if (!(cflag
& PARODD
))
798 cval
|= UART_LCR_EPAR
;
801 if (uart_config
[up
->port
.type
].flags
& UART_USE_FIFO
) {
802 if ((up
->port
.uartclk
/ quot
) < (2400 * 16))
803 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
805 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_8
;
809 up
->port
.read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
811 up
->port
.read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
812 if (iflag
& (BRKINT
| PARMRK
))
813 up
->port
.read_status_mask
|= UART_LSR_BI
;
816 * Characteres to ignore
818 up
->port
.ignore_status_mask
= 0;
820 up
->port
.ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
821 if (iflag
& IGNBRK
) {
822 up
->port
.ignore_status_mask
|= UART_LSR_BI
;
824 * If we're ignoring parity and break indicators,
825 * ignore overruns too (for real raw support).
828 up
->port
.ignore_status_mask
|= UART_LSR_OE
;
832 * ignore all characters if CREAD is not set
834 if ((cflag
& CREAD
) == 0)
835 up
->port
.ignore_status_mask
|= UART_LSR_DR
;
838 * Ok, we're now changing the port state. Do it with
839 * interrupts disabled.
841 spin_lock_irqsave(&up
->port
.lock
, flags
);
844 * CTS flow control flag and modem status interrupts
846 up
->ier
&= ~UART_IER_MSI
;
847 if (UART_ENABLE_MS(&up
->port
, cflag
))
848 up
->ier
|= UART_IER_MSI
;
850 serial_out(up
, UART_IER
, up
->ier
);
853 serial_outp(up
, 0x28, quot
& 0xffff);
855 up
->lcr
= cval
; /* Save LCR */
856 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
860 serial_au1x00_pm(struct uart_port
*port
, unsigned int state
,
861 unsigned int oldstate
)
864 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
867 if (uart_config
[up
->port
.type
].flags
& UART_STARTECH
) {
868 /* Arrange to enter sleep mode */
869 serial_outp(up
, UART_LCR
, 0xBF);
870 serial_outp(up
, UART_EFR
, UART_EFR_ECB
);
871 serial_outp(up
, UART_LCR
, 0);
872 serial_outp(up
, UART_IER
, UART_IERX_SLEEP
);
873 serial_outp(up
, UART_LCR
, 0xBF);
874 serial_outp(up
, UART_EFR
, 0);
875 serial_outp(up
, UART_LCR
, 0);
877 if (up
->port
.type
== PORT_16750
) {
878 /* Arrange to enter sleep mode */
879 serial_outp(up
, UART_IER
, UART_IERX_SLEEP
);
883 up
->pm(port
, state
, oldstate
);
886 if (uart_config
[up
->port
.type
].flags
& UART_STARTECH
) {
888 serial_outp(up
, UART_LCR
, 0xBF);
889 serial_outp(up
, UART_EFR
, UART_EFR_ECB
);
891 * Turn off LCR == 0xBF so we actually set the IER
892 * register on the XR16C850
894 serial_outp(up
, UART_LCR
, 0);
895 serial_outp(up
, UART_IER
, 0);
897 * Now reset LCR so we can turn off the ECB bit
899 serial_outp(up
, UART_LCR
, 0xBF);
900 serial_outp(up
, UART_EFR
, 0);
902 * For a XR16C850, we need to set the trigger levels
904 if (up
->port
.type
== PORT_16850
) {
907 fctr
= serial_inp(up
, UART_FCTR
) &
908 ~(UART_FCTR_RX
| UART_FCTR_TX
);
909 serial_outp(up
, UART_FCTR
, fctr
|
912 serial_outp(up
, UART_TRG
, UART_TRG_96
);
913 serial_outp(up
, UART_FCTR
, fctr
|
916 serial_outp(up
, UART_TRG
, UART_TRG_96
);
918 serial_outp(up
, UART_LCR
, 0);
921 if (up
->port
.type
== PORT_16750
) {
923 serial_outp(up
, UART_IER
, 0);
927 up
->pm(port
, state
, oldstate
);
933 * Resource handling. This is complicated by the fact that resources
934 * depend on the port type. Maybe we should be claiming the standard
935 * 8250 ports, and then trying to get other resources as necessary?
938 serial_au1x00_request_std_resource(struct uart_8250_port
*up
, struct resource
**res
)
940 unsigned int size
= 8 << up
->port
.regshift
;
943 printk("request_std_resource\n");
945 switch (up
->port
.iotype
) {
947 if (up
->port
.mapbase
) {
948 *res
= request_mem_region(up
->port
.mapbase
, size
, "serial");
956 *res
= request_region(up
->port
.iobase
, size
, "serial");
966 static void serial_au1x00_release_port(struct uart_port
*port
)
968 printk("release_port\n");
971 static int serial_au1x00_request_port(struct uart_port
*port
)
973 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
974 struct resource
*res
= NULL
, *res_rsa
= NULL
;
977 printk("request_port\n");
978 if (up
->port
.flags
& UPF_RESOURCES
) {
979 ret
= serial_au1x00_request_std_resource(up
, &res
);
983 * If we have a mapbase, then request that as well.
985 if (ret
== 0 && up
->port
.flags
& UPF_IOREMAP
) {
986 int size
= res
->end
- res
->start
+ 1;
988 up
->port
.membase
= ioremap(up
->port
.mapbase
, size
);
989 if (!up
->port
.membase
)
995 release_resource(res_rsa
);
997 release_resource(res
);
1002 static void serial_au1x00_config_port(struct uart_port
*port
, int flags
)
1004 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1005 struct resource
*res_std
= NULL
, *res_rsa
= NULL
;
1006 int probeflags
= PROBE_ANY
;
1008 probeflags
&= ~PROBE_RSA
;
1010 if (flags
& UART_CONFIG_TYPE
)
1011 autoconfig(up
, probeflags
);
1014 * If the port wasn't an RSA port, release the resource.
1016 if (up
->port
.type
!= PORT_RSA
&& res_rsa
)
1017 release_resource(res_rsa
);
1019 if (up
->port
.type
== PORT_UNKNOWN
&& res_std
)
1020 release_resource(res_std
);
1024 serial_au1x00_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
1026 if (ser
->irq
>= NR_IRQS
|| ser
->irq
< 0 ||
1027 ser
->baud_base
< 9600 || ser
->type
< PORT_UNKNOWN
||
1028 ser
->type
> PORT_MAX_8250
|| ser
->type
== PORT_CIRRUS
||
1029 ser
->type
== PORT_STARTECH
)
1035 serial_au1x00_type(struct uart_port
*port
)
1037 int type
= port
->type
;
1039 if (type
>= ARRAY_SIZE(uart_config
))
1041 return uart_config
[type
].name
;
1044 static struct uart_ops serial_au1x00_pops
= {
1045 .tx_empty
= serial_au1x00_tx_empty
,
1046 .set_mctrl
= serial_au1x00_set_mctrl
,
1047 .get_mctrl
= serial_au1x00_get_mctrl
,
1048 .stop_tx
= serial_au1x00_stop_tx
,
1049 .start_tx
= serial_au1x00_start_tx
,
1050 .stop_rx
= serial_au1x00_stop_rx
,
1051 .enable_ms
= serial_au1x00_enable_ms
,
1052 .break_ctl
= serial_au1x00_break_ctl
,
1053 .startup
= serial_au1x00_startup
,
1054 .shutdown
= serial_au1x00_shutdown
,
1055 .change_speed
= serial_au1x00_change_speed
,
1056 .pm
= serial_au1x00_pm
,
1057 .type
= serial_au1x00_type
,
1058 .release_port
= serial_au1x00_release_port
,
1059 .request_port
= serial_au1x00_request_port
,
1060 .config_port
= serial_au1x00_config_port
,
1061 .verify_port
= serial_au1x00_verify_port
,
1064 static struct uart_8250_port serial_au1x00_ports
[UART_NR
];
1066 static void __init
serial_au1x00_isa_init_ports(void)
1068 struct uart_8250_port
*up
;
1069 static int first
= 1;
1076 for (i
= 0, up
= serial_au1x00_ports
; i
< ARRAY_SIZE(old_serial_port
);
1078 up
->port
.iobase
= old_serial_port
[i
].port
;
1079 up
->port
.irq
= irq_cannonicalize(old_serial_port
[i
].irq
);
1080 up
->port
.uartclk
= old_serial_port
[i
].baud_base
* 16;
1081 up
->port
.flags
= old_serial_port
[i
].flags
|
1083 up
->port
.hub6
= old_serial_port
[i
].hub6
;
1084 up
->port
.membase
= old_serial_port
[i
].iomem_base
;
1085 up
->port
.iotype
= old_serial_port
[i
].io_type
;
1086 up
->port
.regshift
= old_serial_port
[i
].iomem_reg_shift
;
1087 up
->port
.ops
= &serial_au1x00_pops
;
1091 static void __init
serial_au1x00_register_ports(struct uart_driver
*drv
)
1095 serial_au1x00_isa_init_ports();
1097 for (i
= 0; i
< UART_NR
; i
++) {
1098 struct uart_8250_port
*up
= &serial_au1x00_ports
[i
];
1101 up
->port
.ops
= &serial_au1x00_pops
;
1102 init_timer(&up
->timer
);
1103 up
->timer
.function
= serial_au1x00_timeout
;
1106 * ALPHA_KLUDGE_MCR needs to be killed.
1108 up
->mcr_mask
= ~ALPHA_KLUDGE_MCR
;
1109 up
->mcr_force
= ALPHA_KLUDGE_MCR
;
1111 uart_add_one_port(drv
, &up
->port
);
1115 #ifdef CONFIG_SERIAL_AU1X00_CONSOLE
1117 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
1120 * Wait for transmitter & holding register to empty
1122 static inline void wait_for_xmitr(struct uart_8250_port
*up
)
1124 unsigned int status
, tmout
= 10000;
1126 /* Wait up to 10ms for the character(s) to be sent. */
1128 status
= serial_in(up
, UART_LSR
);
1130 if (status
& UART_LSR_BI
)
1131 up
->lsr_break_flag
= UART_LSR_BI
;
1136 } while ((status
& BOTH_EMPTY
) != BOTH_EMPTY
);
1138 /* Wait up to 1s for flow control if necessary */
1139 if (up
->port
.flags
& UPF_CONS_FLOW
) {
1142 ((serial_in(up
, UART_MSR
) & UART_MSR_CTS
) == 0))
1148 * Print a string to the serial port trying not to disturb
1149 * any possible real use of the port...
1151 * The console_lock must be held when we get here.
1154 serial_au1x00_console_write(struct console
*co
, const char *s
, unsigned int count
)
1156 struct uart_8250_port
*up
= &serial_au1x00_ports
[co
->index
];
1161 * First save the UER then disable the interrupts
1163 ier
= serial_in(up
, UART_IER
);
1164 serial_out(up
, UART_IER
, 0);
1167 * Now, do each character
1169 for (i
= 0; i
< count
; i
++, s
++) {
1173 * Send the character out.
1174 * If a LF, also do CR...
1176 serial_out(up
, UART_TX
, *s
);
1179 serial_out(up
, UART_TX
, 13);
1184 * Finally, wait for transmitter to become empty
1185 * and restore the IER
1188 serial_out(up
, UART_IER
, ier
);
1191 static kdev_t
serial_au1x00_console_device(struct console
*co
)
1193 return mk_kdev(TTY_MAJOR
, 64 + co
->index
);
1196 static int __init
serial_au1x00_console_setup(struct console
*co
, char *options
)
1198 struct uart_port
*port
;
1205 * Check whether an invalid uart number has been specified, and
1206 * if so, search for the first available port that does have
1209 //if (co->index >= UART_NR)
1212 port
= &serial_au1x00_ports
[co
->index
].port
;
1217 spin_lock_init(&port
->lock
);
1220 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1222 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
1225 static struct console serial_au1x00_console
= {
1227 .write
= serial_au1x00_console_write
,
1228 .device
= serial_au1x00_console_device
,
1229 .setup
= serial_au1x00_console_setup
,
1230 .flags
= CON_PRINTBUFFER
,
1234 void __init
serial_au1x00_console_init(void)
1236 serial_au1x00_isa_init_ports();
1237 register_console(&serial_au1x00_console
);
1240 #define SERIAL8250_CONSOLE &serial_au1x00_console
1242 #define SERIAL8250_CONSOLE NULL
1245 static struct uart_driver serial_au1x00_reg
= {
1246 .owner
= THIS_MODULE
,
1247 .driver_name
= "serial",
1248 #ifdef CONFIG_DEVFS_FS
1249 .dev_name
= "tts/%d",
1251 .dev_name
= "ttyS%d",
1256 .cons
= SERIAL8250_CONSOLE
,
1260 * register_serial and unregister_serial allows for 16x50 serial ports to be
1261 * configured at run-time, to support PCMCIA modems.
1264 static int __register_serial(struct serial_struct
*req
, int line
)
1266 struct uart_port port
;
1268 port
.iobase
= req
->port
;
1269 port
.membase
= req
->iomem_base
;
1270 port
.irq
= req
->irq
;
1271 port
.uartclk
= req
->baud_base
* 16;
1272 port
.fifosize
= req
->xmit_fifo_size
;
1273 port
.regshift
= req
->iomem_reg_shift
;
1274 port
.iotype
= req
->io_type
;
1275 port
.flags
= req
->flags
| UPF_BOOT_AUTOCONF
;
1279 * If a clock rate wasn't specified by the low level
1280 * driver, then default to the standard clock rate.
1282 if (port
.uartclk
== 0)
1283 port
.uartclk
= get_au1x00_uart_baud_base();
1284 //port.uartclk = BASE_BAUD * 16;
1286 return uart_register_port(&serial_au1x00_reg
, &port
);
1290 * register_serial - configure a 16x50 serial port at runtime
1291 * @req: request structure
1293 * Configure the serial port specified by the request. If the
1294 * port exists and is in use an error is returned. If the port
1295 * is not currently in the table it is added.
1297 * The port is then probed and if neccessary the IRQ is autodetected
1298 * If this fails an error is returned.
1300 * On success the port is ready to use and the line number is returned.
1302 int register_serial(struct serial_struct
*req
)
1304 return __register_serial(req
, -1);
1307 int __init
early_serial_setup(struct serial_struct
*req
)
1309 __register_serial(req
, req
->line
);
1314 * unregister_serial - remove a 16x50 serial port at runtime
1315 * @line: serial line number
1317 * Remove one serial port. This may be called from interrupt
1320 void unregister_serial(int line
)
1322 uart_unregister_port(&serial_au1x00_reg
, line
);
1325 static int __init
serial_au1x00_init(void)
1329 printk(KERN_INFO
"Serial: 8250/16550 driver $Revision: 1.90 $ "
1330 "IRQ sharing %sabled\n", share_irqs
? "en" : "dis");
1332 for (i
= 0; i
< NR_IRQS
; i
++)
1333 spin_lock_init(&irq_lists
[i
].lock
);
1335 ret
= uart_register_driver(&serial_au1x00_reg
);
1339 serial_au1x00_register_ports(&serial_au1x00_reg
);
1343 static void __exit
serial_au1x00_exit(void)
1347 for (i
= 0; i
< UART_NR
; i
++)
1348 uart_remove_one_port(&serial_au1x00_reg
, &serial_au1x00_ports
[i
].port
);
1350 uart_unregister_driver(&serial_au1x00_reg
);
1353 module_init(serial_au1x00_init
);
1354 module_exit(serial_au1x00_exit
);
1356 EXPORT_SYMBOL(register_serial
);
1357 EXPORT_SYMBOL(unregister_serial
);
1359 MODULE_LICENSE("GPL");
1360 MODULE_DESCRIPTION("Au1x00 serial driver $Revision: 1.00 $");
1362 MODULE_PARM(share_irqs
, "i");