1 /* serial port driver for the Atmel AT91 series builtin USARTs
3 * Copyright (C) 2000, 2001 Erik Andersen <andersen@lineo.com>
4 * Copyright (C) 2004 Hyok S. Choi <hyok.choi@samsung.com>
7 * drivers/char/68302serial.c
8 * and also based on trioserial.c from Aplio, though this driver
9 * has been extensively changed since then. No author was
10 * listed in trioserial.c.
12 * Phil Wilshire 12/31/2002 Fixed multiple ^@ chars on TCSETA
13 * Hyok S. Choi 03/22/2004 2.6 port
16 /* Enable this to force this driver to always operate at 57600 */
19 #include <linux/config.h>
20 #include <linux/version.h>
21 #include <linux/types.h>
22 #include <linux/serial.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/config.h>
31 #include <linux/major.h>
32 #include <linux/string.h>
33 #include <linux/fcntl.h>
35 #include <linux/kernel.h>
36 #include <linux/init.h>
37 #include <linux/console.h>
41 #include <asm/arch/irq.h>
42 #include <asm/system.h>
43 #include <asm/segment.h>
44 #include <asm/bitops.h>
45 #include <asm/delay.h>
46 #include <asm/uaccess.h>
48 #include "serial_atmel.h"
52 static volatile struct atmel_usart_regs
*usarts
[AT91_USART_CNT
] = {
53 (volatile struct atmel_usart_regs
*) AT91_USART0_BASE
,
54 (volatile struct atmel_usart_regs
*) AT91_USART1_BASE
57 #define SERIAL_XMIT_SIZE PAGE_SIZE
58 #define RX_SERIAL_SIZE 256
60 static struct atmel_serial atmel_info
[AT91_USART_CNT
];
61 static struct tty_struct
*serial_table
[AT91_USART_CNT
];
62 struct atmel_serial
*atmel_consinfo
= 0;
64 #define UART_CLOCK (ARM_CLK/16)
66 static struct work_struct serialpoll
;
69 extern wait_queue_head_t keypress_wait
;
72 struct tty_driver
*serial_driver
;
74 /* serial subtype definitions */
75 #define SERIAL_TYPE_NORMAL 1
77 /* number of characters left in xmit buffer before we ask for more */
78 #define WAKEUP_CHARS 256
80 /* Debugging... DEBUG_INTR is bad to use when one of the zs
81 * lines is your console ;(
83 #undef SERIAL_DEBUG_INTR
84 #undef SERIAL_DEBUG_OPEN
85 #undef SERIAL_DEBUG_FLOW
87 #define RS_ISR_PASS_LIMIT 256
89 #define _INLINE_ inline
92 #define MIN(a,b) ((a) < (b) ? (a) : (b))
98 * tmp_buf is used as a temporary buffer by serial_write. We need to
99 * lock it in case the memcpy_fromfs blocks while swapping in a page,
100 * and some other program tries to do a serial write at the same time.
101 * Since the lock will only come under contention when the system is
102 * swapping and available memory is low, it makes sense to share one
103 * buffer across all the serial ports, since it significantly saves
104 * memory if large numbers of serial ports are open.
106 static unsigned char tmp_buf
[SERIAL_XMIT_SIZE
]; /* This is cheating */
107 DECLARE_MUTEX(tmp_buf_sem
);
109 static inline int serial_paranoia_check(struct atmel_serial
*info
,
110 char *name
, const char *routine
)
112 #ifdef SERIAL_PARANOIA_CHECK
113 static const char *badmagic
=
114 "Warning: bad magic number for serial struct %s in %s\n";
115 static const char *badinfo
=
116 "Warning: null atmel_serial struct for %s in %s\n";
119 printk(badinfo
, name
, routine
);
122 if (info
->magic
!= SERIAL_MAGIC
) {
123 printk(badmagic
, name
, routine
);
130 static unsigned char * rx_buf_table
[AT91_USART_CNT
];
132 static unsigned char rx_buf1
[RX_SERIAL_SIZE
];
133 static unsigned char rx_buf2
[RX_SERIAL_SIZE
];
135 /* Console hooks... */
137 static void serpoll(void *data
);
139 static void change_speed(struct atmel_serial
*info
);
142 static void xmit_char(struct atmel_serial
*info
, char ch
);
143 static void xmit_string(struct atmel_serial
*info
, char *p
, int len
);
144 static void start_rx(struct atmel_serial
*info
);
145 static void wait_EOT(volatile struct atmel_usart_regs
*);
146 static void uart_init(struct atmel_serial
*info
);
147 static void uart_speed(struct atmel_serial
*info
, unsigned cflag
);
149 static void tx_enable(volatile struct atmel_usart_regs
*uart
);
150 static void rx_enable(volatile struct atmel_usart_regs
*uart
);
151 static void tx_disable(volatile struct atmel_usart_regs
*uart
);
152 static void rx_disable(volatile struct atmel_usart_regs
*uart
);
153 static void tx_stop(volatile struct atmel_usart_regs
*uart
);
154 static void tx_start(volatile struct atmel_usart_regs
*uart
, int ints
);
155 static void rx_stop(volatile struct atmel_usart_regs
*uart
);
156 static void rx_start(volatile struct atmel_usart_regs
*uart
, int ints
);
157 static void set_ints_mode(int yes
, struct atmel_serial
*info
);
158 static irqreturn_t
rs_interrupt(struct atmel_serial
*info
);
159 extern void show_net_buffers(void);
160 extern void hard_reset_now(void);
161 static void handle_termios_tcsets(struct termios
* ptermios
, struct atmel_serial
* ptty
);
165 static void coucou1(void)
170 static void coucou2(void)
174 static void _INLINE_
tx_enable(volatile struct atmel_usart_regs
*uart
)
176 uart
->ier
= US_TXEMPTY
;
178 static void _INLINE_
rx_enable(volatile struct atmel_usart_regs
*uart
)
180 uart
->ier
= US_ENDRX
| US_TIMEOUT
;
182 static void _INLINE_
tx_disable(volatile struct atmel_usart_regs
*uart
)
184 uart
->idr
= US_TXEMPTY
;
186 static void _INLINE_
rx_disable(volatile struct atmel_usart_regs
*uart
)
188 uart
->idr
= US_ENDRX
| US_TIMEOUT
;
190 static void _INLINE_
tx_stop(volatile struct atmel_usart_regs
*uart
)
196 static void _INLINE_
tx_start(volatile struct atmel_usart_regs
*uart
, int ints
)
203 static void _INLINE_
rx_stop(volatile struct atmel_usart_regs
*uart
)
207 // PSW fixes slew of ^@ chars on a TCSETA ioctl
211 static void _INLINE_
rx_start(volatile struct atmel_usart_regs
*uart
, int ints
)
213 uart
->cr
= US_RXEN
| US_STTO
;
219 static void _INLINE_
reset_status(volatile struct atmel_usart_regs
*uart
)
221 uart
->cr
= US_RSTSTA
;
223 static void set_ints_mode(int yes
, struct atmel_serial
*info
)
225 info
->use_ints
= yes
;
228 (yes
) ? unmask_irq(info
->irq
) : mask_irq(info
->irq
);
233 static void atmel_cts_off(struct atmel_serial
*info
)
235 volatile struct atmel_usart_regs
*uart
;
238 uart
->mc
&= ~(unsigned long) US_RTS
;
241 static void atmel_cts_on(struct atmel_serial
*info
)
243 volatile struct atmel_usart_regs
*uart
;
249 /* Sets or clears DTR/RTS on the requested line */
250 static inline void atmel_rtsdtr(struct atmel_serial
*ss
, int set
)
252 volatile struct atmel_usart_regs
*uart
;
256 uart
->mc
|= US_DTR
| US_RTS
;
258 uart
->mc
&= ~(unsigned long) (US_DTR
| US_RTS
);
265 * ------------------------------------------------------------
266 * rs_stop() and rs_start()
268 * This routines are called before setting or resetting tty->stopped.
269 * They enable or disable transmitter interrupts, as necessary.
270 * ------------------------------------------------------------
272 static void rs_stop(struct tty_struct
*tty
)
274 struct atmel_serial
*info
= (struct atmel_serial
*)tty
->driver_data
;
277 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
280 save_flags(flags
); cli();
281 tx_stop(info
->usart
);
282 rx_stop(info
->usart
);
283 restore_flags(flags
);
286 static void rs_put_char(struct atmel_serial
*info
, char ch
)
290 save_flags(flags
); cli();
292 wait_EOT(info
->usart
);
293 restore_flags(flags
);
296 static void rs_start(struct tty_struct
*tty
)
298 struct atmel_serial
*info
= (struct atmel_serial
*)tty
->driver_data
;
301 if (serial_paranoia_check(info
, tty
->name
, "rs_start"))
304 save_flags(flags
); cli();
305 tx_start(info
->usart
, info
->use_ints
);
306 rx_start(info
->usart
, info
->use_ints
);
309 restore_flags(flags
);
312 /* Drop into either the boot monitor or kadb upon receiving a break
313 * from keyboard/console input.
315 static void batten_down_hatches(void)
317 /* Drop into the debugger */
320 static _INLINE_
void status_handle(struct atmel_serial
*info
, unsigned long status
)
324 if ((info
->tty
->termios
->c_cflag
& CRTSCTS
) &&
325 ((info
->curregs
[3] & AUTO_ENAB
) == 0)) {
326 info
->curregs
[3] |= AUTO_ENAB
;
327 info
->pendregs
[3] |= AUTO_ENAB
;
328 write_zsreg(info
->atmel_channel
, 3, info
->curregs
[3]);
331 if ((info
->curregs
[3] & AUTO_ENAB
)) {
332 info
->curregs
[3] &= ~AUTO_ENAB
;
333 info
->pendregs
[3] &= ~AUTO_ENAB
;
334 write_zsreg(info
->atmel_channel
, 3, info
->curregs
[3]);
338 /* Whee, if this is console input and this is a
339 * 'break asserted' status change interrupt, call
342 if ((status
& US_RXBRK
) && info
->break_abort
)
343 batten_down_hatches();
345 /* XXX Whee, put in a buffer somewhere, the status information
346 * XXX whee whee whee... Where does the information go...
348 reset_status(info
->usart
);
352 static _INLINE_
void receive_chars(struct atmel_serial
*info
, unsigned long status
)
355 volatile struct atmel_usart_regs
*uart
= info
->usart
;
357 struct tty_struct
*tty
= info
->tty
;
359 if (!(info
->flags
& S_INITIALIZED
))
361 count
= RX_SERIAL_SIZE
- uart
->rcr
;
362 // hack to receive chars by polling only BD fields
370 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
371 schedule_work(&tty
->flip
.work
);
373 if ((count
+ tty
->flip
.count
) >= TTY_FLIPBUF_SIZE
) {
377 serialpoll
.data
= (void *) info
;
378 schedule_work(&serialpoll
);
380 memset(tty
->flip
.flag_buf_ptr
, 0, count
);
381 memcpy(tty
->flip
.char_buf_ptr
, info
->rx_buf
, count
);
382 tty
->flip
.char_buf_ptr
+= count
;
384 if (status
& US_PARE
)
385 *(tty
->flip
.flag_buf_ptr
- 1) = TTY_PARITY
;
386 else if (status
& US_OVRE
)
387 *(tty
->flip
.flag_buf_ptr
- 1) = TTY_OVERRUN
;
388 else if (status
& US_FRAME
)
389 *(tty
->flip
.flag_buf_ptr
- 1) = TTY_FRAME
;
391 tty
->flip
.count
+= count
;
393 schedule_work(&tty
->flip
.work
);
400 static _INLINE_
void transmit_chars(struct atmel_serial
*info
)
404 xmit_char(info
, info
->x_char
);
406 goto clear_and_return
;
409 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
) {
410 /* That's peculiar... */
411 tx_stop(info
->usart
);
412 goto clear_and_return
;
415 if (info
->xmit_tail
+ info
->xmit_cnt
< SERIAL_XMIT_SIZE
) {
416 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
419 (info
->xmit_tail
+ info
->xmit_cnt
) & (SERIAL_XMIT_SIZE
- 1);
423 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
424 SERIAL_XMIT_SIZE
- info
->xmit_tail
);
425 //xmit_string(info, info->xmit_buf, info->xmit_tail + info->xmit_cnt - SERIAL_XMIT_SIZE);
427 info
->xmit_cnt
- (SERIAL_XMIT_SIZE
- info
->xmit_tail
);
431 if (info
->xmit_cnt
< WAKEUP_CHARS
)
432 schedule_work(&info
->tqueue
);
434 if (info
->xmit_cnt
<= 0) {
435 //tx_stop(info->usart);
436 goto clear_and_return
;
440 /* Clear interrupt (should be auto) */
445 * This is the serial driver's generic interrupt routine
447 static irqreturn_t
rs_interrupta(int irq
, void *dev_id
, struct pt_regs
*regs
)
449 return rs_interrupt(&atmel_info
[0]);
451 static irqreturn_t
rs_interruptb(int irq
, void *dev_id
, struct pt_regs
*regs
)
453 return rs_interrupt(&atmel_info
[1]);
455 static irqreturn_t
rs_interrupt(struct atmel_serial
*info
)
457 unsigned long status
;
459 status
= info
->usart
->csr
;
460 if (status
& (US_ENDRX
| US_TIMEOUT
)) {
461 receive_chars(info
, status
);
463 if (status
& (US_TXEMPTY
)) {
464 transmit_chars(info
);
466 status_handle(info
, status
);
469 if (!info
->cts_state
) {
470 if (info
->tty
->flip
.count
< TTY_FLIPBUF_SIZE
- RX_SERIAL_SIZE
) {
475 if (!info
->use_ints
) {
476 serialpoll
.data
= (void *) info
;
477 schedule_work(&serialpoll
);
481 static void serpoll(void *data
)
483 struct atmel_serial
*info
= data
;
489 * -------------------------------------------------------------------
490 * Here ends the serial interrupt routines.
491 * -------------------------------------------------------------------
495 static void do_softint(void *private_
)
497 struct atmel_serial
*info
= (struct atmel_serial
*) private_
;
498 struct tty_struct
*tty
;
503 #if 0 // FIXME - CHECK
504 if (clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
505 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
506 tty
->ldisc
.write_wakeup
) (tty
->ldisc
.write_wakeup
) (tty
);
507 wake_up_interruptible(&tty
->write_wait
);
513 * This routine is called from the scheduler tqueue when the interrupt
514 * routine has signalled that a hangup has occurred. The path of
515 * hangup processing is:
517 * serial interrupt routine -> (scheduler tqueue) ->
518 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
521 static void do_serial_hangup(void *private_
)
523 struct atmel_serial
*info
= (struct atmel_serial
*) private_
;
524 struct tty_struct
*tty
;
535 * This subroutine is called when the RS_TIMER goes off. It is used
536 * by the serial driver to handle ports that do not have an interrupt
537 * (irq=0). This doesn't work at all for 16450's, as a sun has a Z8530.
540 static void rs_timer(void)
542 panic("rs_timer called\n");
547 static unsigned long calcCD(unsigned long br
)
549 return (UART_CLOCK
/ br
);
552 static void uart_init(struct atmel_serial
*info
)
554 volatile struct atmel_usart_regs
*uart
;
562 /* Reset the USART */
563 uart
->cr
= US_TXDIS
| US_RXDIS
| US_RSTTX
| US_RSTRX
;
564 /* clear Rx receive and Tx sent counters */
568 /* Disable interrups till we say we want them */
569 tx_disable(info
->usart
);
570 rx_disable(info
->usart
);
572 /* Set the serial port into a safe sane state */
573 uart
->mr
= US_USCLKS(0) | US_CLK0
| US_CHMODE(0) | US_NBSTOP(0) |
574 US_PAR(4) | US_CHRL(3);
577 uart
->brgr
= calcCD(9600);
579 uart
->brgr
= calcCD(57600);
582 uart
->rtor
= 20; // timeout = value * 4 *bit period
583 uart
->ttgr
= 0; // no guard time
593 /* It is the responsibilty of whoever calls this function to be sure
594 * that that have called
595 * tx_stop(uart); rx_stop(uart);
596 * before calling the function. Failure to do this will cause messy
597 * things to happen. You have been warned. */
598 static void uart_speed(struct atmel_serial
*info
, unsigned cflag
)
600 unsigned baud
= info
->baud
;
601 volatile struct atmel_usart_regs
*uart
= info
->usart
;
604 uart
->cr
= US_TXDIS
| US_RXDIS
;
606 // disable interrupts
611 uart
->brgr
= calcCD(baud
);
613 uart
->brgr
= calcCD(57600);
617 /* probably not needed */
618 uart
->US_RTOR
= 20; // timeout = value * 4 *bit period
619 uart
->US_TTGR
= 0; // no guard time
630 if (cflag
!= 0xffff) {
631 uart
->mr
= US_USCLKS(0) | US_CLK0
| US_CHMODE(0) | US_NBSTOP(0) |
634 if ((cflag
& CSIZE
) == CS8
)
635 uart
->mr
|= US_CHRL(3); // 8 bit char
637 uart
->mr
|= US_CHRL(2); // 7 bit char
640 uart
->mr
|= US_NBSTOP(2); // 2 stop bits
642 if (!(cflag
& PARENB
))
643 uart
->mr
|= US_PAR(4); // parity disabled
644 else if (cflag
& PARODD
)
645 uart
->mr
|= US_PAR(1); // odd parity
652 uart
->cr
= US_TXEN
| US_RXEN
;
658 tx_start(uart
, info
->use_ints
);
662 static void wait_EOT(volatile struct atmel_usart_regs
*uart
)
664 // make sure tx is enabled
667 // wait until all chars sent FIXME - is this sane ?
669 if (uart
->csr
& US_TXEMPTY
)
673 static int startup(struct atmel_serial
*info
)
677 if (info
->flags
& S_INITIALIZED
)
680 if (!info
->xmit_buf
) {
681 info
->xmit_buf
= (unsigned char *) __get_free_page(GFP_KERNEL
);
686 //info->rx_buf = (unsigned char *) ))__get_free_page(GFP_KERNEL);
687 //info->rx_buf = rx_buf1;
693 #ifdef SERIAL_DEBUG_OPEN
694 printk("starting up ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
697 * Clear the FIFO buffers and disable them
698 * (they will be reenabled in change_speed())
702 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
703 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
706 * and set the speed of the serial port
710 //set_ints_mode(0, info);
712 info
->flags
|= S_INITIALIZED
;
713 restore_flags(flags
);
718 * This routine will shutdown a serial port; interrupts are disabled, and
719 * DTR is dropped if the hangup on close termio flag is on.
721 static void shutdown(struct atmel_serial
*info
)
725 tx_disable(info
->usart
);
726 rx_disable(info
->usart
);
727 rx_stop(info
->usart
); /* All off! */
728 if (!(info
->flags
& S_INITIALIZED
))
731 #ifdef SERIAL_DEBUG_OPEN
732 printk("Shutting down serial port %d (irq %d)....\n", info
->line
,
737 cli(); /* Disable interrupts */
739 if (info
->xmit_buf
) {
740 free_page((unsigned long) info
->xmit_buf
);
745 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
747 info
->flags
&= ~S_INITIALIZED
;
748 restore_flags(flags
);
751 /* rate = 1036800 / ((65 - prescale) * (1<<divider)) */
753 static int baud_table
[] = {
754 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
755 9600, 19200, 38400, 57600, 115200, 0
759 * This routine is called to set the UART divisor registers to match
760 * the specified baud rate for a serial port.
762 static void change_speed(struct atmel_serial
*info
)
767 if (!info
->tty
|| !info
->tty
->termios
)
769 cflag
= info
->tty
->termios
->c_cflag
;
772 info
->usart
->cr
= US_TXDIS
| US_RXDIS
;
774 /* First disable the interrupts */
775 tx_stop(info
->usart
);
776 rx_stop(info
->usart
);
778 /* set the baudrate */
781 info
->baud
= baud_table
[i
];
782 uart_speed(info
, cflag
);
783 tx_start(info
->usart
, info
->use_ints
);
784 rx_start(info
->usart
, info
->use_ints
);
787 info
->usart
->cr
= US_TXEN
| US_RXEN
;
792 static void start_rx(struct atmel_serial
*info
)
794 volatile struct atmel_usart_regs
*uart
= info
->usart
;
798 if (info->rx_buf == rx_buf1) {
799 info->rx_buf = rx_buf2;
801 info->rx_buf = rx_buf1;
804 uart
->rpr
= (unsigned long) info
->rx_buf
;
805 uart
->rcr
= (unsigned long) RX_SERIAL_SIZE
;
806 rx_start(uart
, info
->use_ints
);
808 static void xmit_char(struct atmel_serial
*info
, char ch
)
811 xmit_string(info
, &prompt0
, 1);
813 static void xmit_string(struct atmel_serial
*info
, char *p
, int len
)
815 info
->usart
->tcr
= 0;
816 info
->usart
->tpr
= (unsigned long) p
;
817 info
->usart
->tcr
= (unsigned long) len
;
818 tx_start(info
->usart
, info
->use_ints
);
822 * atmel_console_print is registered for printk.
824 int atmel_console_initialized
;
826 static void init_console(struct atmel_serial
*info
)
828 memset(info
, 0, sizeof(struct atmel_serial
));
830 #ifdef CONFIG_SWAP_ATMEL_PORTS
831 info
->usart
= (volatile struct atmel_usart_regs
*) AT91_USART1_BASE
;
832 info
->irqmask
= AIC_URT1
;
833 info
->irq
= IRQ_USART1
;
835 info
->usart
= (volatile struct atmel_usart_regs
*) AT91_USART0_BASE
;
836 info
->irqmask
= 1<<IRQ_USART0
;
837 info
->irq
= IRQ_USART0
;
844 atmel_console_initialized
= 1;
848 void console_print_atmel(const char *p
)
851 struct atmel_serial
*info
;
853 #ifdef CONFIG_SWAP_ATMEL_PORTS
854 info
= &atmel_info
[1];
856 info
= &atmel_info
[0];
859 if (!atmel_console_initialized
) {
863 tx_stop(info
->usart
);
864 rx_stop(info
->usart
);
865 uart_speed(info
, 0xffff);
866 tx_start(info
->usart
, info
->use_ints
);
867 rx_start(info
->usart
, info
->use_ints
);
870 while ((c
= *(p
++)) != 0) {
872 rs_put_char(info
, '\r');
873 rs_put_char(info
, c
);
876 /* Comment this if you want to have a strict interrupt-driven output */
879 rs_fair_output(info
);
885 static void rs_set_ldisc(struct tty_struct
*tty
)
887 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
889 if (serial_paranoia_check(info
, tty
->name
, "rs_set_ldisc"))
892 info
->is_cons
= (tty
->termios
->c_line
== N_TTY
);
894 printk("ttyS%d console mode %s\n", info
->line
,
895 info
->is_cons
? "on" : "off");
898 static void rs_flush_chars(struct tty_struct
*tty
)
900 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
903 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_chars"))
905 if (!info
->use_ints
) {
907 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
908 !info
->xmit_buf
) return;
910 /* Enable transmitter */
913 tx_start(info
->usart
, info
->use_ints
);
916 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
917 !info
->xmit_buf
) return;
919 /* Enable transmitter */
922 tx_start(info
->usart
, info
->use_ints
);
926 wait_EOT(info
->usart
);
928 xmit_char(info
, info
->xmit_buf
[info
->xmit_tail
++]);
929 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
932 restore_flags(flags
);
935 extern void console_printn(const char *b
, int count
);
937 static int rs_write(struct tty_struct
*tty
, int from_user
,
938 const unsigned char *buf
, int count
)
941 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
944 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
947 if (!tty
|| !info
->xmit_buf
)
953 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
954 SERIAL_XMIT_SIZE
- info
->xmit_head
));
960 copy_from_user(tmp_buf
, buf
, c
);
961 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
964 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
966 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
- 1);
968 restore_flags(flags
);
974 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
975 /* Enable transmitter */
978 /*printk("Enabling transmitter\n"); */
980 if (!info
->use_ints
) {
981 while (info
->xmit_cnt
) {
982 wait_EOT(info
->usart
);
984 xmit_char(info
, info
->xmit_buf
[info
->xmit_tail
++]);
985 wait_EOT(info
->usart
);
986 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
990 if (info
->xmit_cnt
) {
992 wait_EOT(info
->usart
);
993 if (info
->xmit_tail
+ info
->xmit_cnt
< SERIAL_XMIT_SIZE
) {
994 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
998 info
->xmit_cnt
) & (SERIAL_XMIT_SIZE
- 1);
1002 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
1003 SERIAL_XMIT_SIZE
- info
->xmit_tail
);
1004 //xmit_string(info, info->xmit_buf, info->xmit_tail + info->xmit_cnt - SERIAL_XMIT_SIZE);
1006 info
->xmit_cnt
- (SERIAL_XMIT_SIZE
- info
->xmit_tail
);
1007 info
->xmit_tail
= 0;
1012 /*printk("Skipping transmit\n"); */
1016 printk("Enabling stuff anyhow\n");
1019 if (SCC_EOT(0, 0)) {
1020 printk("TX FIFO empty.\n");
1022 atmel_xmit_char(info
->usart
, info
->xmit_buf
[info
->xmit_tail
++]);
1023 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
1028 restore_flags(flags
);
1032 static int rs_write_room(struct tty_struct
*tty
)
1034 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1037 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
1039 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1045 static int rs_chars_in_buffer(struct tty_struct
*tty
)
1047 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1049 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
1051 return info
->xmit_cnt
;
1054 static void rs_flush_buffer(struct tty_struct
*tty
)
1056 unsigned long flags
;
1057 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1059 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
1063 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1064 restore_flags(flags
);
1065 wake_up_interruptible(&tty
->write_wait
);
1066 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1067 tty
->ldisc
.write_wakeup
) (tty
->ldisc
.write_wakeup
) (tty
);
1071 * ------------------------------------------------------------
1074 * This routine is called by the upper-layer tty layer to signal that
1075 * incoming characters should be throttled.
1076 * ------------------------------------------------------------
1078 static void rs_throttle(struct tty_struct
*tty
)
1080 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1082 #ifdef SERIAL_DEBUG_THROTTLE
1085 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1086 tty
->ldisc
.chars_in_buffer(tty
));
1089 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
1093 info
->x_char
= STOP_CHAR(tty
);
1095 /* Turn off RTS line (do this atomic) */
1098 static void rs_unthrottle(struct tty_struct
*tty
)
1100 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1102 #ifdef SERIAL_DEBUG_THROTTLE
1105 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1106 tty
->ldisc
.chars_in_buffer(tty
));
1109 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1116 info
->x_char
= START_CHAR(tty
);
1119 /* Assert RTS line (do this atomic) */
1123 * ------------------------------------------------------------
1124 * rs_ioctl() and friends
1125 * ------------------------------------------------------------
1128 static int get_serial_info(struct atmel_serial
*info
,
1129 struct serial_struct
*retinfo
)
1131 struct serial_struct tmp
;
1135 memset(&tmp
, 0, sizeof(tmp
));
1136 tmp
.type
= info
->type
;
1137 tmp
.line
= info
->line
;
1138 tmp
.port
= info
->port
;
1139 tmp
.irq
= info
->irq
;
1140 tmp
.flags
= info
->flags
;
1141 tmp
.baud_base
= info
->baud_base
;
1142 tmp
.close_delay
= info
->close_delay
;
1143 tmp
.closing_wait
= info
->closing_wait
;
1144 tmp
.custom_divisor
= info
->custom_divisor
;
1145 copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
));
1149 static int set_serial_info(struct atmel_serial
*info
,
1150 struct serial_struct
*new_info
)
1152 struct serial_struct new_serial
;
1153 struct atmel_serial old_info
;
1158 copy_from_user(&new_serial
, new_info
, sizeof(new_serial
));
1161 if (!capable(CAP_SYS_ADMIN
)) {
1162 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1163 (new_serial
.type
!= info
->type
) ||
1164 (new_serial
.close_delay
!= info
->close_delay
) ||
1165 ((new_serial
.flags
& ~S_USR_MASK
) !=
1166 (info
->flags
& ~S_USR_MASK
)))
1168 info
->flags
= ((info
->flags
& ~S_USR_MASK
) |
1169 (new_serial
.flags
& S_USR_MASK
));
1170 info
->custom_divisor
= new_serial
.custom_divisor
;
1171 goto check_and_exit
;
1174 if (info
->count
> 1)
1178 * OK, past this point, all the error checking has been done.
1179 * At this point, we start making changes.....
1182 info
->baud_base
= new_serial
.baud_base
;
1183 info
->flags
= ((info
->flags
& ~S_FLAGS
) |
1184 (new_serial
.flags
& S_FLAGS
));
1185 info
->type
= new_serial
.type
;
1186 info
->close_delay
= new_serial
.close_delay
;
1187 info
->closing_wait
= new_serial
.closing_wait
;
1190 //retval = startup(info);
1197 * get_lsr_info - get line status register info
1199 * Purpose: Let user call ioctl() to get info when the UART physically
1200 * is emptied. On bus types like RS485, the transmitter must
1201 * release the bus after transmitting. This must be done when
1202 * the transmit shift register is empty, not be done when the
1203 * transmit holding register is empty. This functionality
1204 * allows an RS485 driver to be written in user space.
1206 static int get_lsr_info(struct atmel_serial
*info
, unsigned int *value
)
1208 unsigned char status
;
1211 status
= info
->usart
->csr
;
1212 status
&= US_TXEMPTY
;
1214 put_user(status
, value
);
1219 * This routine sends a break character out the serial port.
1221 static void send_break(struct atmel_serial
*info
, int duration
)
1223 unsigned long flags
;
1224 if (!info
->port
) return;
1226 current
->state
= TASK_INTERRUPTIBLE
;
1227 save_flags(flags
); cli();
1228 info
->usart
->cr
= US_STTBRK
;
1229 if (!info
->use_ints
) {
1230 while (US_TXRDY
!= (info
->usart
->csr
& US_TXRDY
)) {
1231 ; // this takes max 2ms at 9600
1233 info
->usart
->cr
= US_STPBRK
;
1235 restore_flags(flags
);
1238 static int rs_ioctl(struct tty_struct
*tty
, struct file
*file
,
1239 unsigned int cmd
, unsigned long arg
)
1242 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1245 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1248 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1249 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1250 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1251 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1256 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1257 retval
= tty_check_change(tty
);
1260 tty_wait_until_sent(tty
, 0);
1262 send_break(info
, HZ
/ 4); /* 1/4 second */
1264 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1265 retval
= tty_check_change(tty
);
1268 tty_wait_until_sent(tty
, 0);
1269 send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1272 error
= verify_area(VERIFY_WRITE
, (void *) arg
, sizeof(long));
1275 put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
1278 arg
= get_user(arg
,(unsigned long *) arg
);
1279 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
1282 error
= verify_area(VERIFY_WRITE
, (void *) arg
, sizeof(struct serial_struct
));
1285 return get_serial_info(info
, (struct serial_struct
*) arg
);
1287 return set_serial_info(info
, (struct serial_struct
*) arg
);
1288 case TIOCSERGETLSR
: /* Get line status register */
1289 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1290 sizeof(unsigned int));
1294 return get_lsr_info(info
, (unsigned int *) arg
);
1296 case TIOCSERGSTRUCT
:
1297 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1298 sizeof(struct atmel_serial
));
1301 copy_to_user((struct atmel_serial
*) arg
, info
,
1302 sizeof(struct atmel_serial
));
1306 handle_termios_tcsets((struct termios
*)arg
, info
);
1307 // return set_serial_info(info, (struct serial_struct *) arg);
1310 return -ENOIOCTLCMD
;
1315 static void handle_termios_tcsets(struct termios
* ptermios
, struct atmel_serial
* pinfo
)
1320 if (pinfo
->tty
->termios
->c_cflag
!= ptermios
->c_cflag
)
1321 pinfo
->tty
->termios
->c_cflag
= ptermios
->c_cflag
;
1322 change_speed(pinfo
);
1325 static void rs_set_termios(struct tty_struct
*tty
,
1326 struct termios
*old_termios
)
1328 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1330 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1335 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1336 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1337 tty
->hw_stopped
= 0;
1344 * ------------------------------------------------------------
1347 * This routine is called when the serial port gets closed. First, we
1348 * wait for the last remaining data to be sent. Then, we unlink its
1349 * S structure from the interrupt chain if necessary, and we free
1350 * that IRQ if nothing is left in the chain.
1351 * ------------------------------------------------------------
1353 static void rs_close(struct tty_struct
*tty
, struct file
*filp
)
1355 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1356 unsigned long flags
;
1358 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1364 if (tty_hung_up_p(filp
)) {
1365 restore_flags(flags
);
1368 #ifdef SERIAL_DEBUG_OPEN
1369 printk("rs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1371 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1373 * Uh, oh. tty->count is 1, which means that the tty
1374 * structure will be freed. Info->count should always
1375 * be one in these conditions. If it's greater than
1376 * one, we've got real problems, since it means the
1377 * serial port won't be shutdown.
1379 printk("rs_close: bad serial port count; tty->count is 1, "
1380 "info->count is %d\n", info
->count
);
1383 if (--info
->count
< 0) {
1384 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1385 info
->line
, info
->count
);
1389 restore_flags(flags
);
1392 // closing port so disable interrupts
1393 set_ints_mode(0, info
);
1395 info
->flags
|= S_CLOSING
;
1397 * Now we wait for the transmit buffer to clear; and we notify
1398 * the line discipline to only process XON/XOFF characters.
1401 if (info
->closing_wait
!= S_CLOSING_WAIT_NONE
)
1402 tty_wait_until_sent(tty
, info
->closing_wait
);
1404 * At this point we stop accepting input. To do this, we
1405 * disable the receive line status interrupts, and tell the
1406 * interrupt driver to stop checking the data ready bit in the
1407 * line status register.
1411 if (tty
->driver
->flush_buffer
)
1412 tty
->driver
->flush_buffer(tty
);
1413 if (tty
->ldisc
.flush_buffer
)
1414 tty
->ldisc
.flush_buffer(tty
);
1418 #warning "This is not and has never been valid so fix it"
1420 if (tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) {
1421 if (tty
->ldisc
.close
)
1422 (tty
->ldisc
.close
) (tty
);
1423 tty
->ldisc
= ldiscs
[N_TTY
];
1424 tty
->termios
->c_line
= N_TTY
;
1425 if (tty
->ldisc
.open
)
1426 (tty
->ldisc
.open
) (tty
);
1429 if (info
->blocked_open
) {
1430 if (info
->close_delay
) {
1431 current
->state
= TASK_INTERRUPTIBLE
;
1432 schedule_timeout(info
->close_delay
);
1434 wake_up_interruptible(&info
->open_wait
);
1436 info
->flags
&= ~(S_NORMAL_ACTIVE
| S_CALLOUT_ACTIVE
| S_CLOSING
);
1437 wake_up_interruptible(&info
->close_wait
);
1438 restore_flags(flags
);
1442 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1444 static void rs_hangup(struct tty_struct
*tty
)
1446 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1448 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
1451 rs_flush_buffer(tty
);
1455 info
->flags
&= ~S_NORMAL_ACTIVE
;
1457 wake_up_interruptible(&info
->open_wait
);
1461 * ------------------------------------------------------------
1462 * rs_open() and friends
1463 * ------------------------------------------------------------
1465 static int block_til_ready(struct tty_struct
*tty
, struct file
*filp
,
1466 struct atmel_serial
*info
)
1468 DECLARE_WAITQUEUE(wait
, current
);
1473 * If the device is in the middle of being closed, then block
1474 * until it's done, and then try again.
1476 if (info
->flags
& S_CLOSING
) {
1477 interruptible_sleep_on(&info
->close_wait
);
1478 #ifdef SERIAL_DO_RESTART
1479 if (info
->flags
& S_HUP_NOTIFY
)
1482 return -ERESTARTSYS
;
1489 * If non-blocking mode is set, or the port is not enabled,
1490 * then make the check up front and then exit.
1492 if ((filp
->f_flags
& O_NONBLOCK
) ||
1493 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1494 info
->flags
|= S_NORMAL_ACTIVE
;
1498 if (tty
->termios
->c_cflag
& CLOCAL
)
1502 * Block waiting for the carrier detect and the line to become
1503 * free (i.e., not in use by the callout). While we are in
1504 * this loop, info->count is dropped by one, so that
1505 * rs_close() knows when to free things. We restore it upon
1506 * exit, either normal or abnormal.
1509 add_wait_queue(&info
->open_wait
, &wait
);
1510 #ifdef SERIAL_DEBUG_OPEN
1511 printk("block_til_ready before block: ttyS%d, count = %d\n",
1512 info
->line
, info
->count
);
1515 info
->blocked_open
++;
1520 atmel_rtsdtr(info
, 1);
1521 restore_flags(flags
);
1523 current
->state
= TASK_INTERRUPTIBLE
;
1524 if (tty_hung_up_p(filp
) ||
1525 !(info
->flags
& S_INITIALIZED
)) {
1526 #ifdef SERIAL_DO_RESTART
1527 if (info
->flags
& S_HUP_NOTIFY
)
1530 retval
= -ERESTARTSYS
;
1536 if (!(info
->flags
& S_CLOSING
) && do_clocal
)
1538 if (signal_pending(current
)) {
1539 retval
= -ERESTARTSYS
;
1542 #ifdef SERIAL_DEBUG_OPEN
1543 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1544 info
->line
, info
->count
);
1548 current
->state
= TASK_RUNNING
;
1549 remove_wait_queue(&info
->open_wait
, &wait
);
1550 if (!tty_hung_up_p(filp
))
1552 info
->blocked_open
--;
1553 #ifdef SERIAL_DEBUG_OPEN
1554 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1555 info
->line
, info
->count
);
1559 info
->flags
|= S_NORMAL_ACTIVE
;
1560 if (!info
->use_ints
) {
1561 serialpoll
.data
= (void *) info
;
1562 schedule_work(&serialpoll
);
1568 * This routine is called whenever a serial port is opened. It
1569 * enables interrupts for a serial port, linking in its S structure into
1570 * the IRQ chain. It also performs the serial-specific
1571 * initialization for the tty structure.
1573 int rs_open(struct tty_struct
*tty
, struct file
*filp
)
1575 struct atmel_serial
*info
;
1580 // check if line is sane
1581 if (line
< 0 || line
>= AT91_USART_CNT
)
1584 info
= &atmel_info
[line
];
1585 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
1589 tty
->driver_data
= info
;
1593 * Start up serial port
1595 set_ints_mode(1, info
);
1597 retval
= startup(info
);
1601 return block_til_ready(tty
, filp
, info
);
1605 static struct irqaction irq_usart0
=
1606 { rs_interrupta
, 0, 0, "usart0", NULL
, NULL
};
1607 static struct irqaction irq_usart1
=
1608 { rs_interruptb
, 0, 0, "usart1", NULL
, NULL
};
1610 static void interrupts_init(void)
1612 setup_irq(IRQ_USART0
, &irq_usart0
);
1613 setup_irq(IRQ_USART1
, &irq_usart1
);
1616 static void show_serial_version(void)
1618 printk("Atmel USART driver version 0.99\n");
1621 static struct tty_operations rs_ops
= {
1625 .flush_chars
= rs_flush_chars
,
1626 .write_room
= rs_write_room
,
1627 .chars_in_buffer
= rs_chars_in_buffer
,
1628 .flush_buffer
= rs_flush_buffer
,
1630 .throttle
= rs_throttle
,
1631 .unthrottle
= rs_unthrottle
,
1632 .set_termios
= rs_set_termios
,
1635 .hangup
= rs_hangup
,
1636 .set_ldisc
= rs_set_ldisc
,
1639 /* rs_init inits the driver */
1644 struct atmel_serial
*info
;
1646 /* initialise PIO for serial port */
1649 serial_driver
= alloc_tty_driver(2);
1653 // FIXME - do this right
1654 rx_buf_table
[0] = rx_buf1
;
1655 rx_buf_table
[1] = rx_buf2
;
1657 show_serial_version();
1659 /* Initialize the tty_driver structure */
1661 // set the tty_struct pointers to NULL to let the layer
1662 // above allocate the structs.
1663 for (i
=0; i
< AT91_USART_CNT
; i
++)
1664 serial_table
[i
] = NULL
;
1666 serial_driver
->name
= "ttyS";
1667 serial_driver
->major
= TTY_MAJOR
;
1668 serial_driver
->minor_start
= 64;
1669 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1670 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1671 serial_driver
->init_termios
= tty_std_termios
;
1672 serial_driver
->init_termios
.c_cflag
=
1673 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1674 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1675 tty_set_operations(serial_driver
, &rs_ops
);
1677 if (tty_register_driver(serial_driver
)) {
1678 put_tty_driver(serial_driver
);
1679 printk(KERN_ERR
"Couldn't register serial driver\n");
1683 save_flags(flags
); cli();
1684 for (i
= 0; i
< 2; i
++) {
1685 info
= &atmel_info
[i
];
1686 info
->magic
= SERIAL_MAGIC
;
1687 info
->usart
= usarts
[i
];
1689 info
->irqmask
= (i
) ? (1<<IRQ_USART1
) : (1<<IRQ_USART0
);
1690 info
->irq
= (i
) ? IRQ_USART1
: IRQ_USART0
;
1691 #ifdef CONFIG_SWAP_ATMEL_PORTS
1692 info
->port
= (i
) ? 2 : 1;
1694 #ifdef CONFIG_ATMEL_CONSOLE
1700 info
->port
= (i
) ? 1 : 2;
1702 #ifdef CONFIG_ATMEL_CONSOLE
1708 #ifdef CONFIG_CONSOLE_ON_SC28L91
1711 set_ints_mode(0, info
);
1712 info
->custom_divisor
= 16;
1713 info
->close_delay
= 50;
1714 info
->closing_wait
= 3000;
1715 info
->cts_state
= 1;
1719 info
->blocked_open
= 0;
1720 INIT_WORK(&info
->tqueue
, do_softint
, info
);
1721 INIT_WORK(&info
->tqueue_hangup
, do_serial_hangup
, info
);
1722 init_waitqueue_head(&info
->open_wait
);
1723 init_waitqueue_head(&info
->close_wait
);
1724 info
->rx_buf
= rx_buf_table
[i
];
1726 printk("%s%d at 0x%p (irq = %d)", serial_driver
->name
, info
->line
,
1727 info
->usart
, info
->irq
);
1728 printk(" is a builtin Atmel APB USART\n");
1732 info
->usart
->cr
= 0x1ac; // reset, disable
1733 info
->usart
->idr
= 0xffffffff; // disable all interrupts
1734 info
->usart
->tcr
= 0; // stop transmit
1735 info
->usart
->rcr
= 0; // stop receive
1739 restore_flags(flags
);
1740 // hack to do polling
1741 serialpoll
.func
= serpoll
;
1742 serialpoll
.data
= 0;
1747 module_init(rs_atmel_init
);
1751 * register_serial and unregister_serial allows for serial ports to be
1752 * configured at run-time, to support PCMCIA modems.
1754 /* SPARC: Unused at this time, just here to make things link. */
1755 static int register_serial(struct serial_struct
*req
)
1760 static void unregister_serial(int line
)
1765 static void dbg_putc(int ch
)
1768 #define US_TPR (0x38) /* Transmit Pointer Register */
1769 #define US_TCR (0x3C) /* Transmit Counter Register */
1773 outl_t((unsigned long) tmp
, (USART0_BASE
+ US_TPR
) );
1774 outl_t(1, (USART0_BASE
+ US_TCR
) );
1776 while (inl_t((USART0_BASE
+ US_TCR
) )) {
1780 static void dbg_print(const char *str
)
1784 for (p
= str
; *p
; p
++) {
1792 static void dbg_printk(const char *fmt
, ...)
1797 va_start(args
, fmt
);
1798 vsprintf(tmp
, fmt
, args
);
1803 static void rs_atmel_print(const char *str
)
1808 static void dump_a(unsigned long a
, unsigned int s
)
1812 for (q
= 0; q
< s
; q
++) {
1814 dbg_printk("%08X: ", q
+ a
);
1817 dbg_printk("%02X-", *(unsigned char *) (q
+ a
));
1819 dbg_printk("%02X ", *(unsigned char *) (q
+ a
));
1831 int atmel_console_setup(struct console
*cp
, char *arg
)
1839 static struct tty_driver
*atmel_console_device(struct console
*c
, int *index
)
1842 return serial_driver
;
1845 void atmel_console_write (struct console
*co
, const char *str
,
1848 struct atmel_serial
*info
;
1850 #ifdef CONFIG_SWAP_ATMEL_PORTS
1851 info
= &atmel_info
[1];
1853 info
= &atmel_info
[0];
1856 if (!atmel_console_initialized
) {
1860 tx_stop(info
->usart
);
1861 rx_stop(info
->usart
);
1862 uart_speed(info
, 0xffff);
1863 tx_start(info
->usart
, info
->use_ints
);
1864 rx_start(info
->usart
, info
->use_ints
);
1869 rs_put_char(info
,'\r');
1870 rs_put_char(info
, *str
++ );
1874 static struct console atmel_driver
= {
1876 write
: atmel_console_write
,
1877 device
: atmel_console_device
,
1878 setup
: atmel_console_setup
,
1879 flags
: CON_PRINTBUFFER
,
1884 static int __init
atmel_console_init(void)
1886 register_console(&atmel_driver
);
1890 console_initcall(atmel_console_init
);