2 * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Driver support for the on-chip sb1250 dual-channel serial port,
21 * running in asynchronous mode. Also, support for doing a serial console
22 * on one of those ports
24 #include <linux/config.h>
25 #include <linux/types.h>
26 #include <linux/serial.h>
27 #include <linux/module.h>
28 #include <linux/console.h>
29 #include <linux/kdev_t.h>
30 #include <linux/major.h>
31 #include <linux/termios.h>
32 #include <linux/spinlock.h>
33 #include <linux/irq.h>
34 #include <linux/errno.h>
35 #include <linux/tty.h>
36 #include <linux/sched.h>
37 #include <linux/tty_flip.h>
38 #include <linux/timer.h>
39 #include <linux/init.h>
41 #include <asm/delay.h>
43 #include <asm/uaccess.h>
44 #include <asm/sibyte/swarm.h>
45 #include <asm/sibyte/sb1250_regs.h>
46 #include <asm/sibyte/sb1250_uart.h>
47 #include <asm/sibyte/sb1250_int.h>
48 #include <asm/sibyte/sb1250.h>
49 #include <asm/sibyte/64bit.h>
52 /* Toggle spewing of debugging output */
55 #define DEFAULT_CFLAGS (CS8 | B115200)
59 #define SB1250_DUART_MINOR_BASE 64
62 #define MIN(a,b) ((a) < (b) ? (a) : (b))
65 #ifdef CONFIG_SIBYTE_SB1250_DUART_NO_PORT_1
66 #define DUART_MAX_LINE 1
68 #define DUART_MAX_LINE 2
72 * Still not sure what the termios structures set up here are for,
73 * but we have to supply pointers to them to register the tty driver
75 static struct tty_driver sb1250_duart_driver
, sb1250_duart_callout_driver
;
76 static int duart_refcount
;
77 static struct tty_struct
*duart_table
[DUART_MAX_LINE
];
78 static struct termios
*duart_termios
[DUART_MAX_LINE
];
79 static struct termios
*duart_termios_locked
[DUART_MAX_LINE
];
82 * This lock protects both the open flags for all the uart states as
83 * well as the reference count for the module
85 static spinlock_t open_lock
= SPIN_LOCK_UNLOCKED
;
88 unsigned char outp_buf
[SERIAL_XMIT_SIZE
];
89 unsigned int outp_head
;
90 unsigned int outp_tail
;
91 unsigned int outp_count
;
95 unsigned int last_cflags
;
97 struct tty_struct
*tty
;
109 static uart_state_t uart_states
[DUART_MAX_LINE
];
112 * Inline functions local to this module
116 * In bug 1956, we get glitches that can mess up uart registers. This
117 * "write-mode-1 after any register access" is the accepted
121 static unsigned int last_mode1
[DUART_MAX_LINE
];
124 static inline u32
READ_SERCSR(u32
*addr
, int line
)
126 u32 val
= csr_in32(addr
);
128 csr_out32(last_mode1
[line
], uart_states
[line
].mode_1
);
133 static inline void WRITE_SERCSR(u32 val
, u32
*addr
, int line
)
135 csr_out32(val
, addr
);
137 csr_out32(last_mode1
[line
], uart_states
[line
].mode_1
);
141 static void init_duart_port(uart_state_t
*port
, int line
)
144 port
->status
= (u32
*)(IO_SPACE_BASE
| A_DUART_CHANREG(line
, R_DUART_STATUS
));
145 port
->imr
= (u32
*)(IO_SPACE_BASE
| A_DUART_IMRREG(line
));
146 port
->tx_hold
= (u32
*)(IO_SPACE_BASE
| A_DUART_CHANREG(line
, R_DUART_TX_HOLD
));
147 port
->rx_hold
= (u32
*)(IO_SPACE_BASE
| A_DUART_CHANREG(line
, R_DUART_RX_HOLD
));
148 port
->mode_1
= (u32
*)(IO_SPACE_BASE
| A_DUART_CHANREG(line
, R_DUART_MODE_REG_1
));
149 port
->mode_2
= (u32
*)(IO_SPACE_BASE
| A_DUART_CHANREG(line
, R_DUART_MODE_REG_2
));
150 port
->clk_sel
= (u32
*)(IO_SPACE_BASE
| A_DUART_CHANREG(line
, R_DUART_CLK_SEL
));
151 port
->cmd
= (u32
*)(IO_SPACE_BASE
| A_DUART_CHANREG(line
, R_DUART_CMD
));
154 * Mask out the passed interrupt lines at the duart level. This should be
155 * called while holding the associated outp_lock.
157 static inline void duart_mask_ints(unsigned int line
, unsigned int mask
)
159 uart_state_t
*port
= uart_states
+ line
;
160 u64 tmp
= READ_SERCSR(port
->imr
, line
);
161 WRITE_SERCSR(tmp
& ~mask
, port
->imr
, line
);
165 /* Unmask the passed interrupt lines at the duart level */
166 static inline void duart_unmask_ints(unsigned int line
, unsigned int mask
)
168 uart_state_t
*port
= uart_states
+ line
;
169 u64 tmp
= READ_SERCSR(port
->imr
, line
);
170 WRITE_SERCSR(tmp
| mask
, port
->imr
, line
);
173 static inline void transmit_char_pio(uart_state_t
*us
)
175 struct tty_struct
*tty
= us
->tty
;
178 if (spin_trylock(&us
->outp_lock
)) {
180 if (!(READ_SERCSR(us
->status
, us
->line
) & M_DUART_TX_RDY
))
182 if (us
->outp_count
<= 0 || tty
->stopped
|| tty
->hw_stopped
) {
185 WRITE_SERCSR(us
->outp_buf
[us
->outp_head
],
186 us
->tx_hold
, us
->line
);
187 us
->outp_head
= (us
->outp_head
+ 1) & (SERIAL_XMIT_SIZE
-1);
188 if (--us
->outp_count
<= 0)
193 spin_unlock(&us
->outp_lock
);
198 if (!us
->outp_count
|| tty
->stopped
||
199 tty
->hw_stopped
|| blocked
) {
200 us
->flags
&= ~TX_INTEN
;
201 duart_mask_ints(us
->line
, M_DUART_IMR_TX
);
205 (us
->outp_count
< (SERIAL_XMIT_SIZE
/2))) {
207 * We told the discipline at one point that we had no
208 * space, so it went to sleep. Wake it up when we hit
211 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
212 tty
->ldisc
.write_wakeup
)
213 tty
->ldisc
.write_wakeup(tty
);
214 wake_up_interruptible(&tty
->write_wait
);
219 * Generic interrupt handler for both channels. dev_id is a pointer
220 * to the proper uart_states structure, so from that we can derive
221 * which port interrupted
224 static void duart_int(int irq
, void *dev_id
, struct pt_regs
*regs
)
226 uart_state_t
*us
= (uart_state_t
*)dev_id
;
227 struct tty_struct
*tty
= us
->tty
;
228 unsigned int status
= READ_SERCSR(us
->status
, us
->line
);
231 printk("DUART INT\n");
234 if (status
& M_DUART_RX_RDY
) {
239 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
241 printk("Parity error!\n");
242 } else if (status
& 0x40) {
243 printk("Frame error!\n");
246 while (counter
> 0) {
247 if (!(READ_SERCSR(us
->status
, us
->line
) & M_DUART_RX_RDY
))
249 ch
= READ_SERCSR(us
->rx_hold
, us
->line
);
250 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
251 *tty
->flip
.char_buf_ptr
++ = ch
;
252 *tty
->flip
.flag_buf_ptr
++ = 0;
258 tty_flip_buffer_push(tty
);
261 if (status
& M_DUART_TX_RDY
) {
262 transmit_char_pio(us
);
267 * Actual driver functions
270 /* Return the number of characters we can accomodate in a write at this instant */
271 static int duart_write_room(struct tty_struct
*tty
)
273 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
276 retval
= SERIAL_XMIT_SIZE
- us
->outp_count
;
279 printk("duart_write_room called, returning %i\n", retval
);
285 /* memcpy the data from src to destination, but take extra care if the
286 data is coming from user space */
287 static inline int copy_buf(char *dest
, const char *src
, int size
, int from_user
)
290 (void) copy_from_user(dest
, src
, size
);
292 memcpy(dest
, src
, size
);
298 * Buffer up to count characters from buf to be written. If we don't have
299 * other characters buffered, enable the tx interrupt to start sending
301 static int duart_write(struct tty_struct
* tty
, int from_user
,
302 const unsigned char *buf
, int count
)
310 us
= tty
->driver_data
;
314 printk("duart_write called for %i chars by %i (%s)\n", count
, current
->pid
, current
->comm
);
317 spin_lock_irqsave(&us
->outp_lock
, flags
);
322 t
= SERIAL_XMIT_SIZE
- us
->outp_tail
;
325 t
= SERIAL_XMIT_SIZE
- 1 - us
->outp_count
;
331 if (copy_from_user(us
->outp_buf
+ us
->outp_tail
, buf
, c
)) {
332 spin_unlock_irqrestore(&us
->outp_lock
, flags
);
336 memcpy(us
->outp_buf
+ us
->outp_tail
, buf
, c
);
340 us
->outp_tail
= (us
->outp_tail
+ c
) & (SERIAL_XMIT_SIZE
- 1);
346 spin_unlock_irqrestore(&us
->outp_lock
, flags
);
348 if (us
->outp_count
&& !tty
->stopped
&&
349 !tty
->hw_stopped
&& !(us
->flags
& TX_INTEN
)) {
350 us
->flags
|= TX_INTEN
;
351 duart_unmask_ints(us
->line
, M_DUART_IMR_TX
);
358 /* Buffer one character to be written. If there's not room for it, just drop
359 it on the floor. This is used for echo, among other things */
360 static void duart_put_char(struct tty_struct
*tty
, u_char ch
)
362 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
366 printk("duart_put_char called. Char is %x (%c)\n", (int)ch
, ch
);
369 spin_lock_irqsave(&us
->outp_lock
, flags
);
371 if (us
->outp_count
>= SERIAL_XMIT_SIZE
- 1) {
372 spin_unlock_irqrestore(&us
->outp_lock
, flags
);
376 us
->outp_buf
[us
->outp_tail
] = ch
;
377 us
->outp_tail
= (us
->outp_tail
+ 1) &(SERIAL_XMIT_SIZE
-1);
380 spin_unlock_irqrestore(&us
->outp_lock
, flags
);
383 static void duart_flush_chars(struct tty_struct
* tty
)
389 port
= tty
->driver_data
;
393 if (port
->outp_count
<= 0 || tty
->stopped
|| tty
->hw_stopped
) {
397 port
->flags
|= TX_INTEN
;
398 duart_unmask_ints(port
->line
, M_DUART_IMR_TX
);
401 /* Return the number of characters in the output buffer that have yet to be
403 static int duart_chars_in_buffer(struct tty_struct
*tty
)
405 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
408 retval
= us
->outp_count
;
411 printk("duart_chars_in_buffer returning %i\n", retval
);
416 /* Kill everything we haven't yet shoved into the FIFO. Turn off the
417 transmit interrupt since we've nothing more to transmit */
418 static void duart_flush_buffer(struct tty_struct
*tty
)
420 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
424 printk("duart_flush_buffer called\n");
426 spin_lock_irqsave(&us
->outp_lock
, flags
);
427 us
->outp_head
= us
->outp_tail
= us
->outp_count
= 0;
428 spin_unlock_irqrestore(&us
->outp_lock
, flags
);
430 wake_up_interruptible(&us
->tty
->write_wait
);
431 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
432 tty
->ldisc
.write_wakeup
)
433 tty
->ldisc
.write_wakeup(tty
);
437 /* See sb1250 user manual for details on these registers */
438 static inline void duart_set_cflag(unsigned int line
, unsigned int cflag
)
440 unsigned int mode_reg1
= 0, mode_reg2
= 0;
441 unsigned int clk_divisor
;
442 uart_state_t
*port
= uart_states
+ line
;
444 switch (cflag
& CSIZE
) {
446 mode_reg1
|= V_DUART_BITS_PER_CHAR_7
;
449 /* We don't handle CS5 or CS6...is there a way we're supposed to flag this?
450 right now we just force them to CS8 */
454 if (cflag
& CSTOPB
) {
455 mode_reg2
|= M_DUART_STOP_BIT_LEN_2
; /* XXX was: 0x4; */
457 if (!(cflag
& PARENB
)) {
458 mode_reg1
|= V_DUART_PARITY_MODE_NONE
; /* XXX was: 0x8; */
460 if (cflag
& PARODD
) {
461 mode_reg1
|= M_DUART_PARITY_TYPE_ODD
;
464 /* Formula for this is (5000000/baud)-1, but we saturate
465 at 12 bits, which means we can't actually do anything less
467 switch (cflag
& CBAUD
) {
470 case B1200
: clk_divisor
= 4095; break;
471 case B1800
: clk_divisor
= 2776; break;
472 case B2400
: clk_divisor
= 2082; break;
473 case B4800
: clk_divisor
= 1040; break;
475 case B9600
: clk_divisor
= 519; break;
476 case B19200
: clk_divisor
= 259; break;
477 case B38400
: clk_divisor
= 129; break;
478 case B57600
: clk_divisor
= 85; break;
479 case B115200
: clk_divisor
= 42; break;
481 WRITE_SERCSR(mode_reg1
, port
->mode_1
, port
->line
);
482 WRITE_SERCSR(mode_reg2
, port
->mode_2
, port
->line
);
483 WRITE_SERCSR(clk_divisor
, port
->clk_sel
, port
->line
);
484 port
->last_cflags
= cflag
;
488 /* Handle notification of a termios change. */
489 static void duart_set_termios(struct tty_struct
*tty
, struct termios
*old
)
491 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
494 printk("duart_set_termios called by %i (%s)\n", current
->pid
, current
->comm
);
496 if (old
&& tty
->termios
->c_cflag
== old
->c_cflag
)
498 duart_set_cflag(us
->line
, tty
->termios
->c_cflag
);
501 static int duart_ioctl(struct tty_struct
*tty
, struct file
* file
,
502 unsigned int cmd
, unsigned long arg
)
504 /* if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
508 printk("Ignoring TIOCMGET\n");
511 printk("Ignoring TIOCMBIS\n");
514 printk("Ignoring TIOCMBIC\n");
517 printk("Ignoring TIOCMSET\n");
520 printk("Ignoring TIOCGSERIAL\n");
523 printk("Ignoring TIOCSSERIAL\n");
526 printk("Ignoring TIOCSERCONFIG\n");
528 case TIOCSERGETLSR
: /* Get line status register */
529 printk("Ignoring TIOCSERGETLSR\n");
532 printk("Ignoring TIOCSERGSTRUCT\n");
535 printk("Ignoring TIOCMIWAIT\n");
538 printk("Ignoring TIOCGICOUNT\n");
541 printk("Ignoring TIOCSERGWILD\n");
544 printk("Ignoring TIOCSERSWILD\n");
549 // printk("Ignoring IOCTL %x from pid %i (%s)\n", cmd, current->pid, current->comm);
552 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
553 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
) &&
554 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
555 if (tty
->flags
& (1 << TTY_IO_ERROR
))
567 case TIOCSERGETLSR
: /* Get line status register */
573 /* XXX Implement me! */
574 printk("IOCTL needs implementing: %x\n", cmd
);
577 printk("Unknown ioctl: %x\n", cmd
);
584 static void duart_start(struct tty_struct
*tty
)
586 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
589 printk("duart_start called\n");
592 if (us
->outp_count
&& !(us
->flags
& TX_INTEN
)) {
593 us
->flags
|= TX_INTEN
;
594 duart_unmask_ints(us
->line
, M_DUART_IMR_TX
);
599 static void duart_stop(struct tty_struct
*tty
)
601 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
604 printk("duart_stop called\n");
607 if (us
->outp_count
&& (us
->flags
& TX_INTEN
)) {
608 us
->flags
&= ~TX_INTEN
;
609 duart_mask_ints(us
->line
, M_DUART_IMR_TX
);
613 /* Not sure on the semantics of this; are we supposed to wait until the stuff
614 already in the hardware FIFO drains, or are we supposed to wait until
615 we've drained the output buffer, too? I'm assuming the former, 'cause thats
616 what the other drivers seem to assume
619 static void duart_wait_until_sent(struct tty_struct
*tty
, int timeout
)
621 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
622 unsigned long orig_jiffies
;
624 orig_jiffies
= jiffies
;
626 printk("duart_wait_until_sent(%d)+\n", timeout
);
628 while (!(READ_SERCSR(us
->status
, us
->line
) & M_DUART_TX_EMT
)) {
629 set_current_state(TASK_INTERRUPTIBLE
);
631 if (signal_pending(current
))
633 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
637 printk("duart_wait_until_sent()-\n");
642 * duart_hangup() --- called by tty_hangup() when a hangup is signaled.
644 static void duart_hangup(struct tty_struct
*tty
)
646 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
648 duart_flush_buffer(tty
);
654 * Open a tty line. Note that this can be called multiple times, so ->open can
655 * be >1. Only set up the tty struct if this is a "new" open, e.g. ->open was
658 static int duart_open(struct tty_struct
*tty
, struct file
*filp
)
661 unsigned int line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
666 if ((line
< 0) || (line
>= DUART_MAX_LINE
)) {
672 printk("duart_open called by %i (%s), tty is %p, rw is %p, ww is %p\n",
673 current
->pid
, current
->comm
, tty
, tty
->read_wait
,
677 us
= uart_states
+ line
;
678 tty
->driver_data
= us
;
680 spin_lock_irqsave(&open_lock
, flags
);
683 us
->tty
->termios
->c_cflag
= us
->last_cflags
;
686 us
->flags
&= ~TX_INTEN
;
687 duart_unmask_ints(line
, M_DUART_IMR_RX
);
688 spin_unlock_irqrestore(&open_lock
, flags
);
695 * Close a reference count out. If reference count hits zero, null the
696 * tty, kill the interrupts. The tty_io driver is responsible for making
697 * sure we've cleared out our internal buffers before calling close()
699 static void duart_close(struct tty_struct
*tty
, struct file
*filp
)
701 uart_state_t
*us
= (uart_state_t
*) tty
->driver_data
;
705 printk("duart_close called by %i (%s)\n", current
->pid
, current
->comm
);
708 if (!us
|| !us
->open
)
711 spin_lock_irqsave(&open_lock
, flags
);
712 if (tty_hung_up_p(filp
)) {
714 spin_unlock_irqrestore(&open_lock
, flags
);
718 if (--us
->open
< 0) {
720 printk(KERN_ERR
"duart: bad open count: %d\n", us
->open
);
723 spin_unlock_irqrestore(&open_lock
, flags
);
727 spin_unlock_irqrestore(&open_lock
, flags
);
731 /* Stop accepting input */
732 duart_mask_ints(us
->line
, M_DUART_IMR_RX
);
733 /* Wait for FIFO to drain */
734 while (!(READ_SERCSR(us
->status
, us
->line
) & M_DUART_TX_EMT
))
737 if (tty
->driver
.flush_buffer
)
738 tty
->driver
.flush_buffer(tty
);
739 if (tty
->ldisc
.flush_buffer
)
740 tty
->ldisc
.flush_buffer(tty
);
747 /* Set up the driver and register it, register the 2 1250 UART interrupts. This
748 is called from tty_init, or as a part of the module init */
749 static int __init
sb1250_duart_init(void)
753 sb1250_duart_driver
.magic
= TTY_DRIVER_MAGIC
;
754 sb1250_duart_driver
.driver_name
= "serial";
755 #ifdef CONFIG_DEVFS_FS
756 sb1250_duart_driver
.name
= "tts/%d";
758 sb1250_duart_driver
.name
= "ttyS";
760 sb1250_duart_driver
.major
= TTY_MAJOR
;
761 sb1250_duart_driver
.minor_start
= SB1250_DUART_MINOR_BASE
;
762 sb1250_duart_driver
.num
= DUART_MAX_LINE
;
763 sb1250_duart_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
764 sb1250_duart_driver
.subtype
= SERIAL_TYPE_NORMAL
;
765 sb1250_duart_driver
.init_termios
= tty_std_termios
;
766 sb1250_duart_driver
.flags
= TTY_DRIVER_REAL_RAW
;
767 sb1250_duart_driver
.refcount
= &duart_refcount
;
768 sb1250_duart_driver
.table
= duart_table
;
769 sb1250_duart_driver
.termios
= duart_termios
;
770 sb1250_duart_driver
.termios_locked
= duart_termios_locked
;
772 sb1250_duart_driver
.open
= duart_open
;
773 sb1250_duart_driver
.close
= duart_close
;
774 sb1250_duart_driver
.write
= duart_write
;
775 sb1250_duart_driver
.put_char
= duart_put_char
;
776 sb1250_duart_driver
.write_room
= duart_write_room
;
777 sb1250_duart_driver
.flush_chars
= duart_flush_chars
;
778 sb1250_duart_driver
.chars_in_buffer
= duart_chars_in_buffer
;
779 sb1250_duart_driver
.flush_buffer
= duart_flush_buffer
;
780 sb1250_duart_driver
.ioctl
= duart_ioctl
;
781 sb1250_duart_driver
.set_termios
= duart_set_termios
;
782 sb1250_duart_driver
.stop
= duart_stop
;
783 sb1250_duart_driver
.start
= duart_start
;
784 sb1250_duart_driver
.hangup
= duart_hangup
;
785 sb1250_duart_driver
.wait_until_sent
= duart_wait_until_sent
;
787 sb1250_duart_callout_driver
= sb1250_duart_driver
;
788 #ifdef CONFIG_DEVFS_FS
789 sb1250_duart_callout_driver
.name
= "cua/%d";
791 sb1250_duart_callout_driver
.name
= "cua";
793 sb1250_duart_callout_driver
.major
= TTYAUX_MAJOR
;
794 sb1250_duart_callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
796 for (i
=0; i
<DUART_MAX_LINE
; i
++) {
797 uart_state_t
*port
= uart_states
+ i
;
799 #ifndef CONFIG_SIBYTE_SB1250_DUART_CONSOLE
800 init_duart_port(port
, i
);
802 spin_lock_init(&port
->outp_lock
);
803 duart_mask_ints(i
, 0xf);
804 if (request_irq(K_INT_UART_0
+i
, duart_int
, 0, "uart", port
)) {
805 panic("Couldn't get uart0 interrupt line");
807 out64(M_DUART_RX_EN
|M_DUART_TX_EN
,
808 IO_SPACE_BASE
| A_DUART_CHANREG(i
, R_DUART_CMD
));
809 duart_set_cflag(i
, DEFAULT_CFLAGS
);
812 /* Interrupts are now active, our ISR can be called. */
814 if (tty_register_driver(&sb1250_duart_driver
)) {
815 printk(KERN_ERR
"Couldn't register sb1250 duart serial driver\n");
817 if (tty_register_driver(&sb1250_duart_callout_driver
)) {
818 printk(KERN_ERR
"Couldn't register sb1250 duart callout driver\n");
823 /* Unload the driver. Unregister stuff, get ready to go away */
824 static void __exit
sb1250_duart_fini(void)
831 ret
= tty_unregister_driver(&sb1250_duart_callout_driver
);
833 printk(KERN_ERR
"Unable to unregister sb1250 duart callout driver (%d)\n", ret
);
835 ret
= tty_unregister_driver(&sb1250_duart_driver
);
837 printk(KERN_ERR
"Unable to unregister sb1250 duart serial driver (%d)\n", ret
);
839 for (i
=0; i
<DUART_MAX_LINE
; i
++) {
840 free_irq(K_INT_UART_0
+i
, &uart_states
[i
]);
841 disable_irq(K_INT_UART_0
+i
);
843 restore_flags(flags
);
846 module_init(sb1250_duart_init
);
847 module_exit(sb1250_duart_fini
);
848 MODULE_DESCRIPTION("SB1250 Duart serial driver");
849 MODULE_AUTHOR("Justin Carlson <carlson@sibyte.com>");
851 #ifdef CONFIG_SIBYTE_SB1250_DUART_CONSOLE
854 * Serial console stuff. Very basic, polling driver for doing serial
855 * console output. The console_sem is held by the caller, so we
856 * shouldn't be interrupted for more console activity.
857 * XXXKW What about getting interrupted by uart driver activity?
860 void serial_outc(unsigned char c
, int line
)
862 uart_state_t
*port
= uart_states
+ line
;
863 while (!(READ_SERCSR(port
->status
, line
) & M_DUART_TX_RDY
)) ;
864 WRITE_SERCSR(c
, port
->tx_hold
, line
);
865 while (!(READ_SERCSR(port
->status
, port
->line
) & M_DUART_TX_EMT
)) ;
868 static void ser_console_write(struct console
*cons
, const char *s
,
871 int line
= cons
->index
;
872 uart_state_t
*port
= uart_states
+ line
;
875 imr
= READ_SERCSR(port
->imr
, line
);
876 WRITE_SERCSR(0, port
->imr
, line
);
879 serial_outc('\r', line
);
880 serial_outc(*s
++, line
);
882 WRITE_SERCSR(imr
, port
->imr
, line
);
885 static kdev_t
ser_console_device(struct console
*c
)
887 return MKDEV(TTY_MAJOR
, SB1250_DUART_MINOR_BASE
+ c
->index
);
890 static int ser_console_setup(struct console
*cons
, char *str
)
894 for (i
=0; i
<DUART_MAX_LINE
; i
++) {
895 uart_state_t
*port
= uart_states
+ i
;
897 init_duart_port(port
, i
);
899 last_mode1
[i
] = V_DUART_PARITY_MODE_NONE
|V_DUART_BITS_PER_CHAR_8
;
901 WRITE_SERCSR(V_DUART_PARITY_MODE_NONE
|V_DUART_BITS_PER_CHAR_8
,
903 WRITE_SERCSR(M_DUART_STOP_BIT_LEN_1
,
905 WRITE_SERCSR(V_DUART_BAUD_RATE(115200),
911 static struct console sb1250_ser_cons
= {
913 write
: ser_console_write
,
914 device
: ser_console_device
,
915 setup
: ser_console_setup
,
916 flags
: CON_PRINTBUFFER
,
920 void __init
sb1250_serial_console_init(void)
922 register_console(&sb1250_ser_cons
);
925 #endif /* CONFIG_SIBYTE_SB1250_DUART_CONSOLE */