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/version.h>
20 #include <linux/types.h>
21 #include <linux/serial.h>
22 #include <linux/errno.h>
23 #include <linux/signal.h>
24 #include <linux/sched.h>
25 #include <linux/timer.h>
26 #include <linux/interrupt.h>
27 #include <linux/tty.h>
28 #include <linux/tty_flip.h>
29 #include <linux/major.h>
30 #include <linux/string.h>
31 #include <linux/fcntl.h>
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/console.h>
39 #include <asm/arch/irq.h>
40 #include <asm/system.h>
41 #include <asm/segment.h>
42 #include <asm/bitops.h>
43 #include <asm/delay.h>
44 #include <asm/uaccess.h>
46 #include "serial_atmel.h"
50 static volatile struct atmel_usart_regs
*usarts
[AT91_USART_CNT
] = {
51 (volatile struct atmel_usart_regs
*) AT91_USART0_BASE
,
52 (volatile struct atmel_usart_regs
*) AT91_USART1_BASE
55 #define SERIAL_XMIT_SIZE PAGE_SIZE
56 #define RX_SERIAL_SIZE 256
58 static struct atmel_serial atmel_info
[AT91_USART_CNT
];
59 static struct tty_struct
*serial_table
[AT91_USART_CNT
];
60 struct atmel_serial
*atmel_consinfo
= 0;
62 #define UART_CLOCK (ARM_CLK/16)
64 static struct work_struct serialpoll
;
67 extern wait_queue_head_t keypress_wait
;
70 struct tty_driver
*serial_driver
;
72 /* serial subtype definitions */
73 #define SERIAL_TYPE_NORMAL 1
75 /* number of characters left in xmit buffer before we ask for more */
76 #define WAKEUP_CHARS 256
78 /* Debugging... DEBUG_INTR is bad to use when one of the zs
79 * lines is your console ;(
81 #undef SERIAL_DEBUG_INTR
82 #undef SERIAL_DEBUG_OPEN
83 #undef SERIAL_DEBUG_FLOW
85 #define RS_ISR_PASS_LIMIT 256
87 #define _INLINE_ inline
89 static inline int serial_paranoia_check(struct atmel_serial
*info
,
90 char *name
, const char *routine
)
92 #ifdef SERIAL_PARANOIA_CHECK
93 static const char *badmagic
=
94 "Warning: bad magic number for serial struct %s in %s\n";
95 static const char *badinfo
=
96 "Warning: null atmel_serial struct for %s in %s\n";
99 printk(badinfo
, name
, routine
);
102 if (info
->magic
!= SERIAL_MAGIC
) {
103 printk(badmagic
, name
, routine
);
110 static unsigned char * rx_buf_table
[AT91_USART_CNT
];
112 static unsigned char rx_buf1
[RX_SERIAL_SIZE
];
113 static unsigned char rx_buf2
[RX_SERIAL_SIZE
];
115 /* Console hooks... */
117 static void serpoll(void *data
);
119 static void change_speed(struct atmel_serial
*info
);
122 static void xmit_char(struct atmel_serial
*info
, char ch
);
123 static void xmit_string(struct atmel_serial
*info
, char *p
, int len
);
124 static void start_rx(struct atmel_serial
*info
);
125 static void wait_EOT(volatile struct atmel_usart_regs
*);
126 static void uart_init(struct atmel_serial
*info
);
127 static void uart_speed(struct atmel_serial
*info
, unsigned cflag
);
129 static void tx_enable(volatile struct atmel_usart_regs
*uart
);
130 static void rx_enable(volatile struct atmel_usart_regs
*uart
);
131 static void tx_disable(volatile struct atmel_usart_regs
*uart
);
132 static void rx_disable(volatile struct atmel_usart_regs
*uart
);
133 static void tx_stop(volatile struct atmel_usart_regs
*uart
);
134 static void tx_start(volatile struct atmel_usart_regs
*uart
);
135 static void rx_stop(volatile struct atmel_usart_regs
*uart
);
136 static void rx_start(volatile struct atmel_usart_regs
*uart
, int ints
);
137 static void set_ints_mode(int yes
, struct atmel_serial
*info
);
138 static irqreturn_t
rs_interrupt(struct atmel_serial
*info
);
139 extern void show_net_buffers(void);
140 extern void hard_reset_now(void);
141 static void handle_termios_tcsets(struct termios
* ptermios
, struct atmel_serial
* ptty
);
145 static void coucou1(void)
150 static void coucou2(void)
154 static void _INLINE_
tx_enable(volatile struct atmel_usart_regs
*uart
)
156 uart
->ier
= US_TXEMPTY
;
158 static void _INLINE_
rx_enable(volatile struct atmel_usart_regs
*uart
)
160 uart
->ier
= US_ENDRX
| US_TIMEOUT
;
162 static void _INLINE_
tx_disable(volatile struct atmel_usart_regs
*uart
)
164 uart
->idr
= US_TXEMPTY
;
166 static void _INLINE_
rx_disable(volatile struct atmel_usart_regs
*uart
)
168 uart
->idr
= US_ENDRX
| US_TIMEOUT
;
170 static void _INLINE_
tx_stop(volatile struct atmel_usart_regs
*uart
)
176 static void _INLINE_
tx_start(volatile struct atmel_usart_regs
*uart
)
181 static void _INLINE_
rx_stop(volatile struct atmel_usart_regs
*uart
)
185 // PSW fixes slew of ^@ chars on a TCSETA ioctl
189 static void _INLINE_
rx_start(volatile struct atmel_usart_regs
*uart
, int ints
)
191 uart
->cr
= US_RXEN
| US_STTO
;
197 static void _INLINE_
reset_status(volatile struct atmel_usart_regs
*uart
)
199 uart
->cr
= US_RSTSTA
;
201 static void set_ints_mode(int yes
, struct atmel_serial
*info
)
203 info
->use_ints
= yes
;
206 (yes
) ? unmask_irq(info
->irq
) : mask_irq(info
->irq
);
211 static void atmel_cts_off(struct atmel_serial
*info
)
213 volatile struct atmel_usart_regs
*uart
;
216 uart
->mc
&= ~(unsigned long) US_RTS
;
219 static void atmel_cts_on(struct atmel_serial
*info
)
221 volatile struct atmel_usart_regs
*uart
;
227 /* Sets or clears DTR/RTS on the requested line */
228 static inline void atmel_rtsdtr(struct atmel_serial
*ss
, int set
)
230 volatile struct atmel_usart_regs
*uart
;
234 uart
->mc
|= US_DTR
| US_RTS
;
236 uart
->mc
&= ~(unsigned long) (US_DTR
| US_RTS
);
243 * ------------------------------------------------------------
244 * rs_stop() and rs_start()
246 * This routines are called before setting or resetting tty->stopped.
247 * They enable or disable transmitter interrupts, as necessary.
248 * ------------------------------------------------------------
250 static void rs_stop(struct tty_struct
*tty
)
252 struct atmel_serial
*info
= (struct atmel_serial
*)tty
->driver_data
;
255 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
258 local_irq_save(flags
);
259 tx_stop(info
->usart
);
260 rx_stop(info
->usart
);
261 local_irq_restore(flags
);
264 static void rs_put_char(struct atmel_serial
*info
, char ch
)
268 local_irq_save(flags
);
270 wait_EOT(info
->usart
);
271 local_irq_restore(flags
);
274 static void rs_start(struct tty_struct
*tty
)
276 struct atmel_serial
*info
= (struct atmel_serial
*)tty
->driver_data
;
279 if (serial_paranoia_check(info
, tty
->name
, "rs_start"))
282 local_irq_save(flags
);
283 tx_start(info
->usart
);
284 rx_start(info
->usart
, info
->use_ints
);
287 local_irq_restore(flags
);
290 /* Drop into either the boot monitor or kadb upon receiving a break
291 * from keyboard/console input.
293 static void batten_down_hatches(void)
295 /* Drop into the debugger */
298 static _INLINE_
void status_handle(struct atmel_serial
*info
, unsigned long status
)
302 if ((info
->tty
->termios
->c_cflag
& CRTSCTS
) &&
303 ((info
->curregs
[3] & AUTO_ENAB
) == 0)) {
304 info
->curregs
[3] |= AUTO_ENAB
;
305 info
->pendregs
[3] |= AUTO_ENAB
;
306 write_zsreg(info
->atmel_channel
, 3, info
->curregs
[3]);
309 if ((info
->curregs
[3] & AUTO_ENAB
)) {
310 info
->curregs
[3] &= ~AUTO_ENAB
;
311 info
->pendregs
[3] &= ~AUTO_ENAB
;
312 write_zsreg(info
->atmel_channel
, 3, info
->curregs
[3]);
316 /* Whee, if this is console input and this is a
317 * 'break asserted' status change interrupt, call
320 if ((status
& US_RXBRK
) && info
->break_abort
)
321 batten_down_hatches();
323 /* XXX Whee, put in a buffer somewhere, the status information
324 * XXX whee whee whee... Where does the information go...
326 reset_status(info
->usart
);
330 static _INLINE_
void receive_chars(struct atmel_serial
*info
, unsigned long status
)
333 volatile struct atmel_usart_regs
*uart
= info
->usart
;
335 struct tty_struct
*tty
= info
->tty
;
337 if (!(info
->flags
& S_INITIALIZED
))
339 count
= RX_SERIAL_SIZE
- uart
->rcr
;
340 // hack to receive chars by polling only BD fields
349 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
350 schedule_work(&tty
->flip
.work
);
352 if ((count
+ tty
->flip
.count
) >= TTY_FLIPBUF_SIZE
) {
356 serialpoll
.data
= (void *) info
;
357 schedule_work(&serialpoll
);
359 memset(tty
->flip
.flag_buf_ptr
, 0, count
);
360 memcpy(tty
->flip
.char_buf_ptr
, info
->rx_buf
, count
);
361 tty
->flip
.char_buf_ptr
+= count
;
363 if (status
& US_PARE
)
364 *(tty
->flip
.flag_buf_ptr
- 1) = TTY_PARITY
;
365 else if (status
& US_OVRE
)
366 *(tty
->flip
.flag_buf_ptr
- 1) = TTY_OVERRUN
;
367 else if (status
& US_FRAME
)
368 *(tty
->flip
.flag_buf_ptr
- 1) = TTY_FRAME
;
370 tty
->flip
.count
+= count
;
374 for (; (count
> 0); count
--) {
378 if (status
& US_PARE
)
380 else if (status
& US_OVRE
)
382 else if (status
& US_FRAME
)
386 tty_insert_flip_char(tty
, ch
, flag
);
390 tty_schedule_flip(tty
);
397 static _INLINE_
void transmit_chars(struct atmel_serial
*info
)
401 xmit_char(info
, info
->x_char
);
403 goto clear_and_return
;
406 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
) {
407 /* That's peculiar... */
408 tx_stop(info
->usart
);
409 goto clear_and_return
;
412 if (info
->xmit_tail
+ info
->xmit_cnt
< SERIAL_XMIT_SIZE
) {
413 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
416 (info
->xmit_tail
+ info
->xmit_cnt
) & (SERIAL_XMIT_SIZE
- 1);
420 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
421 SERIAL_XMIT_SIZE
- info
->xmit_tail
);
422 //xmit_string(info, info->xmit_buf, info->xmit_tail + info->xmit_cnt - SERIAL_XMIT_SIZE);
424 info
->xmit_cnt
- (SERIAL_XMIT_SIZE
- info
->xmit_tail
);
428 if (info
->xmit_cnt
< WAKEUP_CHARS
)
429 schedule_work(&info
->tqueue
);
431 if (info
->xmit_cnt
<= 0) {
432 //tx_stop(info->usart);
433 goto clear_and_return
;
437 /* Clear interrupt (should be auto) */
442 * This is the serial driver's generic interrupt routine
444 static irqreturn_t
rs_interrupta(int irq
, void *dev_id
, struct pt_regs
*regs
)
446 return rs_interrupt(&atmel_info
[0]);
448 static irqreturn_t
rs_interruptb(int irq
, void *dev_id
, struct pt_regs
*regs
)
450 return rs_interrupt(&atmel_info
[1]);
452 static irqreturn_t
rs_interrupt(struct atmel_serial
*info
)
454 unsigned long status
;
456 status
= info
->usart
->csr
;
457 if (status
& (US_ENDRX
| US_TIMEOUT
)) {
458 receive_chars(info
, status
);
460 if (status
& (US_TXEMPTY
)) {
461 transmit_chars(info
);
463 status_handle(info
, status
);
466 if (!info
->cts_state
) {
467 if (info
->tty
->flip
.count
< TTY_FLIPBUF_SIZE
- RX_SERIAL_SIZE
) {
472 if (!info
->use_ints
) {
473 serialpoll
.data
= (void *) info
;
474 schedule_work(&serialpoll
);
478 static void serpoll(void *data
)
480 struct atmel_serial
*info
= data
;
486 * -------------------------------------------------------------------
487 * Here ends the serial interrupt routines.
488 * -------------------------------------------------------------------
492 static void do_softint(void *private_
)
494 struct atmel_serial
*info
= (struct atmel_serial
*) private_
;
495 struct tty_struct
*tty
;
500 #if 0 // FIXME - CHECK
501 if (clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
502 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
503 tty
->ldisc
.write_wakeup
) (tty
->ldisc
.write_wakeup
) (tty
);
504 wake_up_interruptible(&tty
->write_wait
);
510 * This routine is called from the scheduler tqueue when the interrupt
511 * routine has signalled that a hangup has occurred. The path of
512 * hangup processing is:
514 * serial interrupt routine -> (scheduler tqueue) ->
515 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
518 static void do_serial_hangup(void *private_
)
520 struct atmel_serial
*info
= (struct atmel_serial
*) private_
;
521 struct tty_struct
*tty
;
532 * This subroutine is called when the RS_TIMER goes off. It is used
533 * by the serial driver to handle ports that do not have an interrupt
534 * (irq=0). This doesn't work at all for 16450's, as a sun has a Z8530.
537 static void rs_timer(void)
539 panic("rs_timer called\n");
544 static unsigned long calcCD(unsigned long br
)
546 return (UART_CLOCK
/ br
);
549 static void uart_init(struct atmel_serial
*info
)
551 volatile struct atmel_usart_regs
*uart
;
559 /* Reset the USART */
560 uart
->cr
= US_TXDIS
| US_RXDIS
| US_RSTTX
| US_RSTRX
;
561 /* clear Rx receive and Tx sent counters */
565 /* Disable interrups till we say we want them */
566 tx_disable(info
->usart
);
567 rx_disable(info
->usart
);
569 /* Set the serial port into a safe sane state */
570 uart
->mr
= US_USCLKS(0) | US_CLK0
| US_CHMODE(0) | US_NBSTOP(0) |
571 US_PAR(4) | US_CHRL(3);
574 uart
->brgr
= calcCD(9600);
576 uart
->brgr
= calcCD(57600);
579 uart
->rtor
= 20; // timeout = value * 4 *bit period
580 uart
->ttgr
= 0; // no guard time
590 /* It is the responsibilty of whoever calls this function to be sure
591 * that that have called
592 * tx_stop(uart); rx_stop(uart);
593 * before calling the function. Failure to do this will cause messy
594 * things to happen. You have been warned. */
595 static void uart_speed(struct atmel_serial
*info
, unsigned cflag
)
597 unsigned baud
= info
->baud
;
598 volatile struct atmel_usart_regs
*uart
= info
->usart
;
601 uart
->cr
= US_TXDIS
| US_RXDIS
;
603 // disable interrupts
608 uart
->brgr
= calcCD(baud
);
610 uart
->brgr
= calcCD(57600);
614 /* probably not needed */
615 uart
->US_RTOR
= 20; // timeout = value * 4 *bit period
616 uart
->US_TTGR
= 0; // no guard time
627 if (cflag
!= 0xffff) {
628 uart
->mr
= US_USCLKS(0) | US_CLK0
| US_CHMODE(0) | US_NBSTOP(0) |
631 if ((cflag
& CSIZE
) == CS8
)
632 uart
->mr
|= US_CHRL(3); // 8 bit char
634 uart
->mr
|= US_CHRL(2); // 7 bit char
637 uart
->mr
|= US_NBSTOP(2); // 2 stop bits
639 if (!(cflag
& PARENB
))
640 uart
->mr
|= US_PAR(4); // parity disabled
641 else if (cflag
& PARODD
)
642 uart
->mr
|= US_PAR(1); // odd parity
649 uart
->cr
= US_TXEN
| US_RXEN
;
659 static void wait_EOT(volatile struct atmel_usart_regs
*uart
)
661 // make sure tx is enabled
664 // wait until all chars sent FIXME - is this sane ?
666 if (uart
->csr
& US_TXEMPTY
)
670 static int startup(struct atmel_serial
*info
)
674 if (info
->flags
& S_INITIALIZED
)
677 if (!info
->xmit_buf
) {
678 info
->xmit_buf
= (unsigned char *) __get_free_page(GFP_KERNEL
);
683 //info->rx_buf = (unsigned char *) ))__get_free_page(GFP_KERNEL);
684 //info->rx_buf = rx_buf1;
688 local_irq_save(flags
);
689 #ifdef SERIAL_DEBUG_OPEN
690 printk("starting up ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
693 * Clear the FIFO buffers and disable them
694 * (they will be reenabled in change_speed())
698 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
699 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
702 * and set the speed of the serial port
706 //set_ints_mode(0, info);
708 info
->flags
|= S_INITIALIZED
;
709 local_irq_restore(flags
);
714 * This routine will shutdown a serial port; interrupts are disabled, and
715 * DTR is dropped if the hangup on close termio flag is on.
717 static void shutdown(struct atmel_serial
*info
)
721 tx_disable(info
->usart
);
722 rx_disable(info
->usart
);
723 rx_stop(info
->usart
); /* All off! */
724 if (!(info
->flags
& S_INITIALIZED
))
727 #ifdef SERIAL_DEBUG_OPEN
728 printk("Shutting down serial port %d (irq %d)....\n", info
->line
,
732 local_irq_save(flags
);
734 if (info
->xmit_buf
) {
735 free_page((unsigned long) info
->xmit_buf
);
740 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
742 info
->flags
&= ~S_INITIALIZED
;
743 local_irq_restore(flags
);
746 /* rate = 1036800 / ((65 - prescale) * (1<<divider)) */
748 static int baud_table
[] = {
749 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
750 9600, 19200, 38400, 57600, 115200, 0
754 * This routine is called to set the UART divisor registers to match
755 * the specified baud rate for a serial port.
757 static void change_speed(struct atmel_serial
*info
)
762 if (!info
->tty
|| !info
->tty
->termios
)
764 cflag
= info
->tty
->termios
->c_cflag
;
767 info
->usart
->cr
= US_TXDIS
| US_RXDIS
;
769 /* First disable the interrupts */
770 tx_stop(info
->usart
);
771 rx_stop(info
->usart
);
773 /* set the baudrate */
776 info
->baud
= baud_table
[i
];
777 uart_speed(info
, cflag
);
778 tx_start(info
->usart
);
779 rx_start(info
->usart
, info
->use_ints
);
782 info
->usart
->cr
= US_TXEN
| US_RXEN
;
787 static void start_rx(struct atmel_serial
*info
)
789 volatile struct atmel_usart_regs
*uart
= info
->usart
;
793 if (info->rx_buf == rx_buf1) {
794 info->rx_buf = rx_buf2;
796 info->rx_buf = rx_buf1;
799 uart
->rpr
= (unsigned long) info
->rx_buf
;
800 uart
->rcr
= (unsigned long) RX_SERIAL_SIZE
;
801 rx_start(uart
, info
->use_ints
);
803 static void xmit_char(struct atmel_serial
*info
, char ch
)
806 xmit_string(info
, &prompt0
, 1);
808 static void xmit_string(struct atmel_serial
*info
, char *p
, int len
)
810 info
->usart
->tcr
= 0;
811 info
->usart
->tpr
= (unsigned long) p
;
812 info
->usart
->tcr
= (unsigned long) len
;
813 tx_start(info
->usart
);
817 * atmel_console_print is registered for printk.
819 int atmel_console_initialized
;
821 static void init_console(struct atmel_serial
*info
)
823 memset(info
, 0, sizeof(struct atmel_serial
));
825 #ifdef CONFIG_SWAP_ATMEL_PORTS
826 info
->usart
= (volatile struct atmel_usart_regs
*) AT91_USART1_BASE
;
827 info
->irqmask
= AIC_URT1
;
828 info
->irq
= IRQ_USART1
;
830 info
->usart
= (volatile struct atmel_usart_regs
*) AT91_USART0_BASE
;
831 info
->irqmask
= 1<<IRQ_USART0
;
832 info
->irq
= IRQ_USART0
;
839 atmel_console_initialized
= 1;
843 void console_print_atmel(const char *p
)
846 struct atmel_serial
*info
;
848 #ifdef CONFIG_SWAP_ATMEL_PORTS
849 info
= &atmel_info
[1];
851 info
= &atmel_info
[0];
854 if (!atmel_console_initialized
) {
858 tx_stop(info
->usart
);
859 rx_stop(info
->usart
);
860 uart_speed(info
, 0xffff);
861 tx_start(info
->usart
);
862 rx_start(info
->usart
, info
->use_ints
);
865 while ((c
= *(p
++)) != 0) {
867 rs_put_char(info
, '\r');
868 rs_put_char(info
, c
);
871 /* Comment this if you want to have a strict interrupt-driven output */
874 rs_fair_output(info
);
880 static void rs_set_ldisc(struct tty_struct
*tty
)
882 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
884 if (serial_paranoia_check(info
, tty
->name
, "rs_set_ldisc"))
887 info
->is_cons
= (tty
->termios
->c_line
== N_TTY
);
889 printk("ttyS%d console mode %s\n", info
->line
,
890 info
->is_cons
? "on" : "off");
893 static void rs_flush_chars(struct tty_struct
*tty
)
895 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
898 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_chars"))
900 if (!info
->use_ints
) {
902 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
903 !info
->xmit_buf
) return;
905 /* Enable transmitter */
906 local_irq_save(flags
);
907 tx_start(info
->usart
);
910 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
911 !info
->xmit_buf
) return;
913 /* Enable transmitter */
914 local_irq_save(flags
);
915 tx_start(info
->usart
);
919 wait_EOT(info
->usart
);
921 xmit_char(info
, info
->xmit_buf
[info
->xmit_tail
++]);
922 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
925 local_irq_restore(flags
);
928 extern void console_printn(const char *b
, int count
);
930 static int rs_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
933 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
936 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
939 if (!tty
|| !info
->xmit_buf
)
942 local_save_flags(flags
);
945 c
= min(count
, (int) min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
946 SERIAL_XMIT_SIZE
- info
->xmit_head
));
947 local_irq_restore(flags
);
952 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
955 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
957 local_irq_restore(flags
);
964 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
965 /* Enable transmitter */
968 /*printk("Enabling transmitter\n"); */
970 if (!info
->use_ints
) {
971 while (info
->xmit_cnt
) {
972 wait_EOT(info
->usart
);
974 xmit_char(info
, info
->xmit_buf
[info
->xmit_tail
++]);
975 wait_EOT(info
->usart
);
976 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
980 if (info
->xmit_cnt
) {
982 wait_EOT(info
->usart
);
983 if (info
->xmit_tail
+ info
->xmit_cnt
< SERIAL_XMIT_SIZE
) {
984 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
988 info
->xmit_cnt
) & (SERIAL_XMIT_SIZE
- 1);
992 xmit_string(info
, info
->xmit_buf
+ info
->xmit_tail
,
993 SERIAL_XMIT_SIZE
- info
->xmit_tail
);
994 //xmit_string(info, info->xmit_buf, info->xmit_tail + info->xmit_cnt - SERIAL_XMIT_SIZE);
996 info
->xmit_cnt
- (SERIAL_XMIT_SIZE
- info
->xmit_tail
);
1002 /*printk("Skipping transmit\n"); */
1006 printk("Enabling stuff anyhow\n");
1009 if (SCC_EOT(0, 0)) {
1010 printk("TX FIFO empty.\n");
1012 atmel_xmit_char(info
->usart
, info
->xmit_buf
[info
->xmit_tail
++]);
1013 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
1018 local_irq_restore(flags
);
1022 static int rs_write_room(struct tty_struct
*tty
)
1024 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1027 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
1029 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1035 static int rs_chars_in_buffer(struct tty_struct
*tty
)
1037 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1039 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
1041 return info
->xmit_cnt
;
1044 static void rs_flush_buffer(struct tty_struct
*tty
)
1046 unsigned long flags
;
1047 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1049 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
1051 local_irq_save(flags
);
1052 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1053 local_irq_restore(flags
);
1054 wake_up_interruptible(&tty
->write_wait
);
1055 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1056 tty
->ldisc
.write_wakeup
) (tty
->ldisc
.write_wakeup
) (tty
);
1060 * ------------------------------------------------------------
1063 * This routine is called by the upper-layer tty layer to signal that
1064 * incoming characters should be throttled.
1065 * ------------------------------------------------------------
1067 static void rs_throttle(struct tty_struct
*tty
)
1069 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1071 #ifdef SERIAL_DEBUG_THROTTLE
1074 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1075 tty
->ldisc
.chars_in_buffer(tty
));
1078 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
1082 info
->x_char
= STOP_CHAR(tty
);
1084 /* Turn off RTS line (do this atomic) */
1087 static void rs_unthrottle(struct tty_struct
*tty
)
1089 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1091 #ifdef SERIAL_DEBUG_THROTTLE
1094 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1095 tty
->ldisc
.chars_in_buffer(tty
));
1098 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1105 info
->x_char
= START_CHAR(tty
);
1108 /* Assert RTS line (do this atomic) */
1112 * ------------------------------------------------------------
1113 * rs_ioctl() and friends
1114 * ------------------------------------------------------------
1117 static int get_serial_info(struct atmel_serial
*info
,
1118 struct serial_struct
*retinfo
)
1120 struct serial_struct tmp
;
1124 memset(&tmp
, 0, sizeof(tmp
));
1125 tmp
.type
= info
->type
;
1126 tmp
.line
= info
->line
;
1127 tmp
.port
= info
->port
;
1128 tmp
.irq
= info
->irq
;
1129 tmp
.flags
= info
->flags
;
1130 tmp
.baud_base
= info
->baud_base
;
1131 tmp
.close_delay
= info
->close_delay
;
1132 tmp
.closing_wait
= info
->closing_wait
;
1133 tmp
.custom_divisor
= info
->custom_divisor
;
1134 copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
));
1138 static int set_serial_info(struct atmel_serial
*info
,
1139 struct serial_struct
*new_info
)
1141 struct serial_struct new_serial
;
1142 struct atmel_serial old_info
;
1147 copy_from_user(&new_serial
, new_info
, sizeof(new_serial
));
1150 if (!capable(CAP_SYS_ADMIN
)) {
1151 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1152 (new_serial
.type
!= info
->type
) ||
1153 (new_serial
.close_delay
!= info
->close_delay
) ||
1154 ((new_serial
.flags
& ~S_USR_MASK
) !=
1155 (info
->flags
& ~S_USR_MASK
)))
1157 info
->flags
= ((info
->flags
& ~S_USR_MASK
) |
1158 (new_serial
.flags
& S_USR_MASK
));
1159 info
->custom_divisor
= new_serial
.custom_divisor
;
1160 goto check_and_exit
;
1163 if (info
->count
> 1)
1167 * OK, past this point, all the error checking has been done.
1168 * At this point, we start making changes.....
1171 info
->baud_base
= new_serial
.baud_base
;
1172 info
->flags
= ((info
->flags
& ~S_FLAGS
) |
1173 (new_serial
.flags
& S_FLAGS
));
1174 info
->type
= new_serial
.type
;
1175 info
->close_delay
= new_serial
.close_delay
;
1176 info
->closing_wait
= new_serial
.closing_wait
;
1179 //retval = startup(info);
1186 * get_lsr_info - get line status register info
1188 * Purpose: Let user call ioctl() to get info when the UART physically
1189 * is emptied. On bus types like RS485, the transmitter must
1190 * release the bus after transmitting. This must be done when
1191 * the transmit shift register is empty, not be done when the
1192 * transmit holding register is empty. This functionality
1193 * allows an RS485 driver to be written in user space.
1195 static int get_lsr_info(struct atmel_serial
*info
, unsigned int *value
)
1197 unsigned char status
;
1198 unsigned long flags
;
1200 local_irq_save(flags
);
1201 status
= info
->usart
->csr
;
1202 status
&= US_TXEMPTY
;
1203 local_irq_restore(flags
);
1204 put_user(status
, value
);
1209 * This routine sends a break character out the serial port.
1211 static void send_break(struct atmel_serial
*info
, int duration
)
1213 unsigned long flags
;
1214 if (!info
->port
) return;
1216 current
->state
= TASK_INTERRUPTIBLE
;
1217 local_irq_save(flags
);
1218 info
->usart
->cr
= US_STTBRK
;
1219 if (!info
->use_ints
) {
1220 while (US_TXRDY
!= (info
->usart
->csr
& US_TXRDY
)) {
1221 ; // this takes max 2ms at 9600
1223 info
->usart
->cr
= US_STPBRK
;
1225 local_irq_restore(flags
);
1228 static int rs_ioctl(struct tty_struct
*tty
, struct file
*file
,
1229 unsigned int cmd
, unsigned long arg
)
1232 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1235 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1238 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1239 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1240 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1241 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1246 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1247 retval
= tty_check_change(tty
);
1250 tty_wait_until_sent(tty
, 0);
1252 send_break(info
, HZ
/ 4); /* 1/4 second */
1254 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1255 retval
= tty_check_change(tty
);
1258 tty_wait_until_sent(tty
, 0);
1259 send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1262 error
= access_ok(VERIFY_WRITE
, (void *) arg
, sizeof(long));
1265 put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
1268 arg
= get_user(arg
,(unsigned long *) arg
);
1269 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
1272 error
= access_ok(VERIFY_WRITE
, (void *) arg
, sizeof(struct serial_struct
));
1275 return get_serial_info(info
, (struct serial_struct
*) arg
);
1277 return set_serial_info(info
, (struct serial_struct
*) arg
);
1278 case TIOCSERGETLSR
: /* Get line status register */
1279 error
= access_ok(VERIFY_WRITE
, (void *) arg
,
1280 sizeof(unsigned int));
1284 return get_lsr_info(info
, (unsigned int *) arg
);
1286 case TIOCSERGSTRUCT
:
1287 error
= access_ok(VERIFY_WRITE
, (void *) arg
,
1288 sizeof(struct atmel_serial
));
1291 copy_to_user((struct atmel_serial
*) arg
, info
,
1292 sizeof(struct atmel_serial
));
1296 handle_termios_tcsets((struct termios
*)arg
, info
);
1297 // return set_serial_info(info, (struct serial_struct *) arg);
1300 return -ENOIOCTLCMD
;
1305 static void handle_termios_tcsets(struct termios
* ptermios
, struct atmel_serial
* pinfo
)
1310 if (pinfo
->tty
->termios
->c_cflag
!= ptermios
->c_cflag
)
1311 pinfo
->tty
->termios
->c_cflag
= ptermios
->c_cflag
;
1312 change_speed(pinfo
);
1315 static void rs_set_termios(struct tty_struct
*tty
,
1316 struct termios
*old_termios
)
1318 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1320 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1325 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1326 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1327 tty
->hw_stopped
= 0;
1334 * ------------------------------------------------------------
1337 * This routine is called when the serial port gets closed. First, we
1338 * wait for the last remaining data to be sent. Then, we unlink its
1339 * S structure from the interrupt chain if necessary, and we free
1340 * that IRQ if nothing is left in the chain.
1341 * ------------------------------------------------------------
1343 static void rs_close(struct tty_struct
*tty
, struct file
*filp
)
1345 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1346 unsigned long flags
;
1348 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1351 local_irq_save(flags
);
1353 if (tty_hung_up_p(filp
)) {
1354 local_irq_restore(flags
);
1357 #ifdef SERIAL_DEBUG_OPEN
1358 printk("rs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1360 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1362 * Uh, oh. tty->count is 1, which means that the tty
1363 * structure will be freed. Info->count should always
1364 * be one in these conditions. If it's greater than
1365 * one, we've got real problems, since it means the
1366 * serial port won't be shutdown.
1368 printk("rs_close: bad serial port count; tty->count is 1, "
1369 "info->count is %d\n", info
->count
);
1372 if (--info
->count
< 0) {
1373 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1374 info
->line
, info
->count
);
1378 local_irq_restore(flags
);
1381 // closing port so disable interrupts
1382 set_ints_mode(0, info
);
1384 info
->flags
|= S_CLOSING
;
1386 * Now we wait for the transmit buffer to clear; and we notify
1387 * the line discipline to only process XON/XOFF characters.
1390 if (info
->closing_wait
!= S_CLOSING_WAIT_NONE
)
1391 tty_wait_until_sent(tty
, info
->closing_wait
);
1393 * At this point we stop accepting input. To do this, we
1394 * disable the receive line status interrupts, and tell the
1395 * interrupt driver to stop checking the data ready bit in the
1396 * line status register.
1400 if (tty
->driver
->flush_buffer
)
1401 tty
->driver
->flush_buffer(tty
);
1402 if (tty
->ldisc
.flush_buffer
)
1403 tty
->ldisc
.flush_buffer(tty
);
1408 if (tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) {
1409 if (tty
->ldisc
.close
)
1410 (tty
->ldisc
.close
) (tty
);
1411 tty
->ldisc
= ldiscs
[N_TTY
];
1412 tty
->termios
->c_line
= N_TTY
;
1413 if (tty
->ldisc
.open
)
1414 (tty
->ldisc
.open
) (tty
);
1417 if (info
->blocked_open
) {
1418 if (info
->close_delay
) {
1419 current
->state
= TASK_INTERRUPTIBLE
;
1420 schedule_timeout(info
->close_delay
);
1422 wake_up_interruptible(&info
->open_wait
);
1424 info
->flags
&= ~(S_NORMAL_ACTIVE
| S_CALLOUT_ACTIVE
| S_CLOSING
);
1425 wake_up_interruptible(&info
->close_wait
);
1426 local_irq_restore(flags
);
1430 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1432 static void rs_hangup(struct tty_struct
*tty
)
1434 struct atmel_serial
*info
= (struct atmel_serial
*) tty
->driver_data
;
1436 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
1439 rs_flush_buffer(tty
);
1443 info
->flags
&= ~S_NORMAL_ACTIVE
;
1445 wake_up_interruptible(&info
->open_wait
);
1449 * ------------------------------------------------------------
1450 * rs_open() and friends
1451 * ------------------------------------------------------------
1453 static int block_til_ready(struct tty_struct
*tty
, struct file
*filp
,
1454 struct atmel_serial
*info
)
1456 DECLARE_WAITQUEUE(wait
, current
);
1461 * If the device is in the middle of being closed, then block
1462 * until it's done, and then try again.
1464 if (info
->flags
& S_CLOSING
) {
1465 interruptible_sleep_on(&info
->close_wait
);
1466 #ifdef SERIAL_DO_RESTART
1467 if (info
->flags
& S_HUP_NOTIFY
)
1470 return -ERESTARTSYS
;
1477 * If non-blocking mode is set, or the port is not enabled,
1478 * then make the check up front and then exit.
1480 if ((filp
->f_flags
& O_NONBLOCK
) ||
1481 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1482 info
->flags
|= S_NORMAL_ACTIVE
;
1486 if (tty
->termios
->c_cflag
& CLOCAL
)
1490 * Block waiting for the carrier detect and the line to become
1491 * free (i.e., not in use by the callout). While we are in
1492 * this loop, info->count is dropped by one, so that
1493 * rs_close() knows when to free things. We restore it upon
1494 * exit, either normal or abnormal.
1497 add_wait_queue(&info
->open_wait
, &wait
);
1498 #ifdef SERIAL_DEBUG_OPEN
1499 printk("block_til_ready before block: ttyS%d, count = %d\n",
1500 info
->line
, info
->count
);
1503 info
->blocked_open
++;
1506 local_irq_save(flags
);
1507 atmel_rtsdtr(info
, 1);
1508 local_irq_restore(flags
);
1510 current
->state
= TASK_INTERRUPTIBLE
;
1511 if (tty_hung_up_p(filp
) ||
1512 !(info
->flags
& S_INITIALIZED
)) {
1513 #ifdef SERIAL_DO_RESTART
1514 if (info
->flags
& S_HUP_NOTIFY
)
1517 retval
= -ERESTARTSYS
;
1523 if (!(info
->flags
& S_CLOSING
) && do_clocal
)
1525 if (signal_pending(current
)) {
1526 retval
= -ERESTARTSYS
;
1529 #ifdef SERIAL_DEBUG_OPEN
1530 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1531 info
->line
, info
->count
);
1535 current
->state
= TASK_RUNNING
;
1536 remove_wait_queue(&info
->open_wait
, &wait
);
1537 if (!tty_hung_up_p(filp
))
1539 info
->blocked_open
--;
1540 #ifdef SERIAL_DEBUG_OPEN
1541 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1542 info
->line
, info
->count
);
1546 info
->flags
|= S_NORMAL_ACTIVE
;
1547 if (!info
->use_ints
) {
1548 serialpoll
.data
= (void *) info
;
1549 schedule_work(&serialpoll
);
1555 * This routine is called whenever a serial port is opened. It
1556 * enables interrupts for a serial port, linking in its S structure into
1557 * the IRQ chain. It also performs the serial-specific
1558 * initialization for the tty structure.
1560 int rs_open(struct tty_struct
*tty
, struct file
*filp
)
1562 struct atmel_serial
*info
;
1567 // check if line is sane
1568 if (line
< 0 || line
>= AT91_USART_CNT
)
1571 info
= &atmel_info
[line
];
1572 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
1576 tty
->driver_data
= info
;
1580 * Start up serial port
1582 set_ints_mode(1, info
);
1584 retval
= startup(info
);
1588 return block_til_ready(tty
, filp
, info
);
1592 static struct irqaction irq_usart0
= {
1593 .handler
= rs_interrupta
,
1596 static struct irqaction irq_usart1
= {
1597 .handler
= rs_interruptb
,
1601 static void interrupts_init(void)
1603 setup_irq(IRQ_USART0
, &irq_usart0
);
1604 setup_irq(IRQ_USART1
, &irq_usart1
);
1607 static void show_serial_version(void)
1609 printk("Atmel USART driver version 0.99\n");
1612 static struct tty_operations rs_ops
= {
1616 .flush_chars
= rs_flush_chars
,
1617 .write_room
= rs_write_room
,
1618 .chars_in_buffer
= rs_chars_in_buffer
,
1619 .flush_buffer
= rs_flush_buffer
,
1621 .throttle
= rs_throttle
,
1622 .unthrottle
= rs_unthrottle
,
1623 .set_termios
= rs_set_termios
,
1626 .hangup
= rs_hangup
,
1627 .set_ldisc
= rs_set_ldisc
,
1630 /* rs_init inits the driver */
1634 struct atmel_serial
*info
;
1635 unsigned long flags
;
1638 /* initialise PIO for serial port */
1641 serial_driver
= alloc_tty_driver(2);
1645 // FIXME - do this right
1646 rx_buf_table
[0] = rx_buf1
;
1647 rx_buf_table
[1] = rx_buf2
;
1649 show_serial_version();
1651 /* Initialize the tty_driver structure */
1653 // set the tty_struct pointers to NULL to let the layer
1654 // above allocate the structs.
1655 for (i
=0; i
< AT91_USART_CNT
; i
++)
1656 serial_table
[i
] = NULL
;
1658 serial_driver
->name
= "ttyS";
1659 serial_driver
->major
= TTY_MAJOR
;
1660 serial_driver
->minor_start
= 64;
1661 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1662 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1663 serial_driver
->init_termios
= tty_std_termios
;
1664 serial_driver
->init_termios
.c_cflag
=
1665 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1666 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1667 tty_set_operations(serial_driver
, &rs_ops
);
1669 if (tty_register_driver(serial_driver
)) {
1670 put_tty_driver(serial_driver
);
1671 printk(KERN_ERR
"Couldn't register serial driver\n");
1675 local_irq_save(flags
);
1676 for (i
= 0; i
< 2; i
++) {
1677 info
= &atmel_info
[i
];
1678 info
->magic
= SERIAL_MAGIC
;
1679 info
->usart
= usarts
[i
];
1681 info
->irqmask
= (i
) ? (1<<IRQ_USART1
) : (1<<IRQ_USART0
);
1682 info
->irq
= (i
) ? IRQ_USART1
: IRQ_USART0
;
1683 #ifdef CONFIG_SWAP_ATMEL_PORTS
1684 info
->port
= (i
) ? 2 : 1;
1686 #ifdef CONFIG_ATMEL_CONSOLE
1692 info
->port
= (i
) ? 1 : 2;
1694 #ifdef CONFIG_ATMEL_CONSOLE
1700 #ifdef CONFIG_CONSOLE_ON_SC28L91
1703 set_ints_mode(0, info
);
1704 info
->custom_divisor
= 16;
1705 info
->close_delay
= 50;
1706 info
->closing_wait
= 3000;
1707 info
->cts_state
= 1;
1711 info
->blocked_open
= 0;
1712 INIT_WORK(&info
->tqueue
, do_softint
, info
);
1713 INIT_WORK(&info
->tqueue_hangup
, do_serial_hangup
, info
);
1714 init_waitqueue_head(&info
->open_wait
);
1715 init_waitqueue_head(&info
->close_wait
);
1716 info
->rx_buf
= rx_buf_table
[i
];
1718 printk("%s%d at 0x%p (irq = %d)", serial_driver
->name
, info
->line
,
1719 info
->usart
, info
->irq
);
1720 printk(" is a builtin Atmel APB USART\n");
1724 info
->usart
->cr
= 0x1ac; // reset, disable
1725 info
->usart
->idr
= 0xffffffff; // disable all interrupts
1726 info
->usart
->tcr
= 0; // stop transmit
1727 info
->usart
->rcr
= 0; // stop receive
1731 local_irq_restore(flags
);
1732 // hack to do polling
1733 serialpoll
.func
= serpoll
;
1734 serialpoll
.data
= 0;
1739 module_init(rs_atmel_init
);
1743 * register_serial and unregister_serial allows for serial ports to be
1744 * configured at run-time, to support PCMCIA modems.
1746 /* SPARC: Unused at this time, just here to make things link. */
1747 static int register_serial(struct serial_struct
*req
)
1752 static void unregister_serial(int line
)
1757 static void dbg_putc(int ch
)
1760 #define US_TPR (0x38) /* Transmit Pointer Register */
1761 #define US_TCR (0x3C) /* Transmit Counter Register */
1765 outl_t((unsigned long) tmp
, (USART0_BASE
+ US_TPR
) );
1766 outl_t(1, (USART0_BASE
+ US_TCR
) );
1768 while (inl_t((USART0_BASE
+ US_TCR
) )) {
1772 static void dbg_print(const char *str
)
1776 for (p
= str
; *p
; p
++) {
1784 static void dbg_printk(const char *fmt
, ...)
1789 va_start(args
, fmt
);
1790 vsprintf(tmp
, fmt
, args
);
1795 static void rs_atmel_print(const char *str
)
1800 static void dump_a(unsigned long a
, unsigned int s
)
1804 for (q
= 0; q
< s
; q
++) {
1806 dbg_printk("%08X: ", q
+ a
);
1809 dbg_printk("%02X-", *(unsigned char *) (q
+ a
));
1811 dbg_printk("%02X ", *(unsigned char *) (q
+ a
));
1823 int atmel_console_setup(struct console
*cp
, char *arg
)
1831 static struct tty_driver
*atmel_console_device(struct console
*c
, int *index
)
1834 return serial_driver
;
1837 void atmel_console_write (struct console
*co
, const char *str
,
1840 struct atmel_serial
*info
;
1842 #ifdef CONFIG_SWAP_ATMEL_PORTS
1843 info
= &atmel_info
[1];
1845 info
= &atmel_info
[0];
1848 if (!atmel_console_initialized
) {
1852 tx_stop(info
->usart
);
1853 rx_stop(info
->usart
);
1854 uart_speed(info
, 0xffff);
1855 tx_start(info
->usart
);
1856 rx_start(info
->usart
, info
->use_ints
);
1861 rs_put_char(info
,'\r');
1862 rs_put_char(info
, *str
++ );
1866 static struct console atmel_driver
= {
1868 write
: atmel_console_write
,
1869 device
: atmel_console_device
,
1870 setup
: atmel_console_setup
,
1871 flags
: CON_PRINTBUFFER
,
1876 static int __init
atmel_console_init(void)
1878 register_console(&atmel_driver
);
1882 console_initcall(atmel_console_init
);