2 * drivers/char/serial_tx3912.c
4 * Copyright (C) 1999 Harald Koerfgen
5 * Copyright (C) 2000 Jim Pick <jim@jimpick.com>
6 * Copyright (C) 2001 Steven J. Hill (sjhill@realitydiluted.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * Serial driver for TMPR3912/05 and PR31700 processors
14 #include <linux/init.h>
15 #include <linux/config.h>
16 #include <linux/tty.h>
17 #include <linux/major.h>
18 #include <linux/ptrace.h>
19 #include <linux/console.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <linux/delay.h>
27 #include <asm/uaccess.h>
28 #include <asm/delay.h>
29 #include <asm/wbflush.h>
30 #include <asm/tx3912.h>
31 #include "serial_tx3912.h"
34 * Forward declarations for serial routines
36 static void rs_disable_tx_interrupts (void * ptr);
37 static void rs_enable_tx_interrupts (void * ptr);
38 static void rs_disable_rx_interrupts (void * ptr);
39 static void rs_enable_rx_interrupts (void * ptr);
40 static int rs_get_CD (void * ptr);
41 static void rs_shutdown_port (void * ptr);
42 static int rs_set_real_termios (void *ptr);
43 static int rs_chars_in_buffer (void * ptr);
46 * Used by generic serial driver to access hardware
48 static struct real_driver rs_real_driver = {
49 .disable_tx_interrupts = rs_disable_tx_interrupts,
50 .enable_tx_interrupts = rs_enable_tx_interrupts,
51 .disable_rx_interrupts = rs_disable_rx_interrupts,
52 .enable_rx_interrupts = rs_enable_rx_interrupts,
54 .shutdown_port = rs_shutdown_port,
55 .set_real_termios = rs_set_real_termios,
56 .chars_in_buffer = rs_chars_in_buffer,
60 * Structures and such for TTY sessions and usage counts
62 static struct tty_driver *rs_driver;
63 struct rs_port *rs_ports;
64 int rs_initialized = 0;
67 * ----------------------------------------------------------------------
69 * Here starts the interrupt handling routines. All of the following
70 * subroutines are declared as inline and are folded into
71 * rs_interrupt(). They were separated out for readability's sake.
73 * Note: rs_interrupt() is a "fast" interrupt, which means that it
74 * runs with interrupts turned off. People who may want to modify
75 * rs_interrupt() should try to keep the interrupt handler as fast as
76 * possible. After you are done making modifications, it is not a bad
79 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
81 * and look at the resulting assemble code in serial.s.
83 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
84 * -----------------------------------------------------------------------
86 static inline void receive_char_pio(struct rs_port *port)
88 struct tty_struct *tty = port->gs.tty;
92 /* While there are characters, get them ... */
94 if (!(inl(port->base + TX3912_UART_CTRL1) & UART_RX_HOLD_FULL))
96 ch = inb(port->base + TX3912_UART_DATA);
97 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
98 *tty->flip.char_buf_ptr++ = ch;
99 *tty->flip.flag_buf_ptr++ = 0;
102 udelay(1); /* Allow things to happen - it take a while */
106 printk( "Ugh, looped in receive_char_pio!\n" );
108 tty_flip_buffer_push(tty);
111 /* Now handle error conditions */
112 if (*status & (INTTYPE(UART_RXOVERRUN_INT) |
113 INTTYPE(UART_FRAMEERR_INT) |
114 INTTYPE(UART_PARITYERR_INT) |
115 INTTYPE(UART_BREAK_INT))) {
118 * Now check to see if character should be
119 * ignored, and mask off conditions which
122 if (*status & port->ignore_status_mask) {
125 *status &= port->read_status_mask;
127 if (*status & INTTYPE(UART_BREAK_INT)) {
128 rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "handling break....");
129 *tty->flip.flag_buf_ptr = TTY_BREAK;
131 else if (*status & INTTYPE(UART_PARITYERR_INT)) {
132 *tty->flip.flag_buf_ptr = TTY_PARITY;
134 else if (*status & INTTYPE(UART_FRAMEERR_INT)) {
135 *tty->flip.flag_buf_ptr = TTY_FRAME;
137 if (*status & INTTYPE(UART_RXOVERRUN_INT)) {
139 * Overrun is special, since it's
140 * reported immediately, and doesn't
141 * affect the current character
143 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
145 tty->flip.flag_buf_ptr++;
146 tty->flip.char_buf_ptr++;
147 *tty->flip.flag_buf_ptr = TTY_OVERRUN;
152 tty->flip.flag_buf_ptr++;
153 tty->flip.char_buf_ptr++;
157 tty_flip_buffer_push(tty);
161 static inline void transmit_char_pio(struct rs_port *port)
163 /* While I'm able to transmit ... */
165 if (!(inl(port->base + TX3912_UART_CTRL1) & UART_TX_EMPTY))
167 else if (port->x_char) {
168 outb(port->x_char, port->base + TX3912_UART_DATA);
172 else if (port->gs.xmit_cnt <= 0 || port->gs.tty->stopped ||
173 port->gs.tty->hw_stopped) {
177 outb(port->gs.xmit_buf[port->gs.xmit_tail++],
178 port->base + TX3912_UART_DATA);
180 port->gs.xmit_tail &= SERIAL_XMIT_SIZE-1;
181 if (--port->gs.xmit_cnt <= 0) {
185 udelay(10); /* Allow things to happen - it take a while */
188 if (port->gs.xmit_cnt <= 0 || port->gs.tty->stopped ||
189 port->gs.tty->hw_stopped) {
190 rs_disable_tx_interrupts(port);
193 if (port->gs.xmit_cnt <= port->gs.wakeup_chars) {
194 if ((port->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
195 port->gs.tty->ldisc.write_wakeup)
196 (port->gs.tty->ldisc.write_wakeup)(port->gs.tty);
197 rs_dprintk (TX3912_UART_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
198 port->gs.wakeup_chars);
199 wake_up_interruptible(&port->gs.tty->write_wait);
205 static inline void check_modem_status(struct rs_port *port)
207 /* We don't have a carrier detect line - but just respond
208 like we had one anyways so that open() becomes unblocked */
209 wake_up_interruptible(&port->gs.open_wait);
215 * This is the serial driver's interrupt routine (inlined, because
216 * there are two different versions of this, one for each serial port,
217 * differing only by the bits used in interrupt status 2 register)
220 static inline void rs_rx_interrupt(int irq, void *dev_id,
221 struct pt_regs * regs, int intshift)
223 struct rs_port * port;
224 unsigned long int2status;
230 port = (struct rs_port *)dev_id;
231 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "rs_interrupt (port %p, shift %d)...", port, intshift);
233 /* Get the interrrupts we have enabled */
234 int2status = IntStatus2 & IntEnable2;
236 /* Get interrupts in easy to use form */
237 ints = int2status >> intshift;
239 /* Clear any interrupts we might be about to handle */
240 IntClear2 = int2status & (
241 (INTTYPE(UART_RXOVERRUN_INT) |
242 INTTYPE(UART_FRAMEERR_INT) |
243 INTTYPE(UART_BREAK_INT) |
244 INTTYPE(UART_PARITYERR_INT) |
245 INTTYPE(UART_RX_INT)) << intshift);
247 if (!port || !port->gs.tty) {
248 restore_flags(flags);
252 /* RX Receiver Holding Register Overrun */
253 if (ints & INTTYPE(UART_RXOVERRUN_INT)) {
254 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "overrun");
255 port->icount.overrun++;
259 if (ints & INTTYPE(UART_FRAMEERR_INT)) {
260 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "frame error");
261 port->icount.frame++;
264 /* Break signal received */
265 if (ints & INTTYPE(UART_BREAK_INT)) {
266 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "break");
270 /* RX Parity Error */
271 if (ints & INTTYPE(UART_PARITYERR_INT)) {
272 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "parity error");
273 port->icount.parity++;
276 /* Receive byte (non-DMA) */
277 if (ints & INTTYPE(UART_RX_INT)) {
278 receive_char_pio(port);
281 restore_flags(flags);
283 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "end.\n");
286 static inline void rs_tx_interrupt(int irq, void *dev_id,
287 struct pt_regs * regs, int intshift)
289 struct rs_port * port;
290 unsigned long int2status;
296 port = (struct rs_port *)dev_id;
297 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "rs_interrupt (port %p, shift %d)...", port, intshift);
299 /* Get the interrrupts we have enabled */
300 int2status = IntStatus2 & IntEnable2;
302 if (!port || !port->gs.tty) {
303 restore_flags(flags);
307 /* Get interrupts in easy to use form */
308 ints = int2status >> intshift;
310 /* Clear any interrupts we might be about to handle */
311 IntClear2 = int2status & (
312 (INTTYPE(UART_TX_INT) |
313 INTTYPE(UART_EMPTY_INT) |
314 INTTYPE(UART_TXOVERRUN_INT)) << intshift);
316 /* TX holding register empty, so transmit byte (non-DMA) */
317 if (ints & (INTTYPE(UART_TX_INT) | INTTYPE(UART_EMPTY_INT))) {
318 transmit_char_pio(port);
321 /* TX Transmit Holding Register Overrun (shouldn't happen) */
322 if (ints & INTTYPE(UART_TXOVERRUN_INT)) {
323 printk ( "rs: TX overrun\n");
327 check_modem_status();
330 restore_flags(flags);
332 rs_dprintk (TX3912_UART_DEBUG_INTERRUPTS, "end.\n");
335 static void rs_rx_interrupt_uarta(int irq, void *dev_id,
336 struct pt_regs * regs)
338 rs_rx_interrupt(irq, dev_id, regs, UARTA_SHIFT);
341 static void rs_tx_interrupt_uarta(int irq, void *dev_id,
342 struct pt_regs * regs)
344 rs_tx_interrupt(irq, dev_id, regs, UARTA_SHIFT);
348 ***********************************************************************
349 * Here are the routines that actually *
350 * interface with the generic_serial driver *
351 ***********************************************************************
353 static void rs_disable_tx_interrupts (void * ptr)
355 struct rs_port *port = ptr;
359 port->gs.flags &= ~GS_TX_INTEN;
361 IntEnable2 &= ~((INTTYPE(UART_TX_INT) |
362 INTTYPE(UART_EMPTY_INT) |
363 INTTYPE(UART_TXOVERRUN_INT)) << port->intshift);
365 IntClear2 = (INTTYPE(UART_TX_INT) |
366 INTTYPE(UART_EMPTY_INT) |
367 INTTYPE(UART_TXOVERRUN_INT)) << port->intshift;
369 restore_flags(flags);
372 static void rs_enable_tx_interrupts (void * ptr)
374 struct rs_port *port = ptr;
379 IntClear2 = (INTTYPE(UART_TX_INT) |
380 INTTYPE(UART_EMPTY_INT) |
381 INTTYPE(UART_TXOVERRUN_INT)) << port->intshift;
383 IntEnable2 |= (INTTYPE(UART_TX_INT) |
384 INTTYPE(UART_EMPTY_INT) |
385 INTTYPE(UART_TXOVERRUN_INT)) << port->intshift;
387 /* Send a char to start TX interrupts happening */
388 transmit_char_pio(port);
390 restore_flags(flags);
393 static void rs_disable_rx_interrupts (void * ptr)
395 struct rs_port *port = ptr;
400 IntEnable2 &= ~((INTTYPE(UART_RX_INT) |
401 INTTYPE(UART_RXOVERRUN_INT) |
402 INTTYPE(UART_FRAMEERR_INT) |
403 INTTYPE(UART_BREAK_INT) |
404 INTTYPE(UART_PARITYERR_INT)) << port->intshift);
406 IntClear2 = (INTTYPE(UART_RX_INT) |
407 INTTYPE(UART_RXOVERRUN_INT) |
408 INTTYPE(UART_FRAMEERR_INT) |
409 INTTYPE(UART_BREAK_INT) |
410 INTTYPE(UART_PARITYERR_INT)) << port->intshift;
412 restore_flags(flags);
415 static void rs_enable_rx_interrupts (void * ptr)
417 struct rs_port *port = ptr;
422 IntEnable2 |= (INTTYPE(UART_RX_INT) |
423 INTTYPE(UART_RXOVERRUN_INT) |
424 INTTYPE(UART_FRAMEERR_INT) |
425 INTTYPE(UART_BREAK_INT) |
426 INTTYPE(UART_PARITYERR_INT)) << port->intshift;
428 /* Empty the input buffer - apparently this is *vital* */
429 while (inl(port->base + TX3912_UART_CTRL1) & UART_RX_HOLD_FULL) {
430 inb(port->base + TX3912_UART_DATA);
433 IntClear2 = (INTTYPE(UART_RX_INT) |
434 INTTYPE(UART_RXOVERRUN_INT) |
435 INTTYPE(UART_FRAMEERR_INT) |
436 INTTYPE(UART_BREAK_INT) |
437 INTTYPE(UART_PARITYERR_INT)) << port->intshift;
439 restore_flags(flags);
443 static int rs_get_CD (void * ptr)
445 /* No Carried Detect in Hardware - just return true */
450 static void rs_shutdown_port (void * ptr)
452 struct rs_port *port = ptr;
456 port->gs.flags &= ~GS_ACTIVE;
461 static int rs_set_real_termios (void *ptr)
463 struct rs_port *port = ptr;
466 switch (port->gs.baud) {
467 /* Save some typing work... */
468 #define e(x) case x:t= TX3912_UART_CTRL2_B ## x ; break
469 e(300);e(600);e(1200);e(2400);e(4800);e(9600);
470 e(19200);e(38400);e(57600);e(76800);e(115200);e(230400);
474 /* Can I return "invalid"? */
475 t = TX3912_UART_CTRL2_B9600;
476 printk (KERN_INFO "rs: unsupported baud rate: %d.\n", port->gs.baud);
481 /* Jim: Set Hardware Baud rate - there is some good
482 code in drivers/char/serial.c */
484 /* Program hardware for parity, data bits, stop bits (note: these are hardcoded to 8N1 */
485 UartA_Ctrl1 &= 0xf000000f;
486 UartA_Ctrl1 &= ~(UART_DIS_TXD | SER_SEVEN_BIT | SER_EVEN_PARITY | SER_TWO_STOP);
488 #define CFLAG port->gs.tty->termios->c_cflag
489 if (C_PARENB(port->gs.tty)) {
490 if (!C_PARODD(port->gs.tty))
491 UartA_Ctrl1 |= SER_EVEN_PARITY;
493 UartA_Ctrl1 |= SER_ODD_PARITY;
495 if ((CFLAG & CSIZE)==CS6)
496 printk(KERN_ERR "6 bits not supported\n");
497 if ((CFLAG & CSIZE)==CS5)
498 printk(KERN_ERR "5 bits not supported\n");
499 if ((CFLAG & CSIZE)==CS7)
500 UartA_Ctrl1 |= SER_SEVEN_BIT;
501 if (C_CSTOPB(port->gs.tty))
502 UartA_Ctrl1 |= SER_TWO_STOP;
504 outl(t, port->base + TX3912_UART_CTRL2);
505 outl(0, port->base + TX3912_UART_DMA_CTRL1);
506 outl(0, port->base + TX3912_UART_DMA_CTRL2);
507 UartA_Ctrl1 |= TX3912_UART_CTRL1_UARTON;
509 /* wait until UARTA is stable */
510 while (~UartA_Ctrl1 & TX3912_UART_CTRL1_UARTON);
517 static int rs_chars_in_buffer (void * ptr)
519 struct rs_port *port = ptr;
522 scratch = inl(port->base + TX3912_UART_CTRL1);
524 return ((scratch & UART_TX_EMPTY) ? 0 : 1);
527 /* ********************************************************************** *
528 * Here are the routines that actually *
529 * interface with the rest of the system *
530 * ********************************************************************** */
531 static int rs_open (struct tty_struct * tty, struct file * filp)
533 struct rs_port *port;
538 if (!rs_initialized) {
543 rs_dprintk (TX3912_UART_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p)\n",
544 (int) current->pid, line, tty, current->tty);
546 if ((line < 0) || (line >= TX3912_UART_NPORTS))
549 /* Pre-initialized already */
550 port = & rs_ports[line];
552 rs_dprintk (TX3912_UART_DEBUG_OPEN, "port = %p\n", port);
554 tty->driver_data = port;
558 rs_dprintk (TX3912_UART_DEBUG_OPEN, "starting port\n");
561 * Start up serial port
563 retval = gs_init_port(&port->gs);
564 rs_dprintk (TX3912_UART_DEBUG_OPEN, "done gs_init\n");
570 port->gs.flags |= GS_ACTIVE;
572 rs_dprintk (TX3912_UART_DEBUG_OPEN, "before inc_use_count (count=%d.\n",
574 rs_dprintk (TX3912_UART_DEBUG_OPEN, "after inc_use_count\n");
576 /* Jim: Initialize port hardware here */
578 /* Enable high-priority interrupts for UARTA */
579 IntEnable6 |= INT6_UARTARXINT;
580 rs_enable_rx_interrupts(&rs_ports[0]);
582 retval = gs_block_til_ready(&port->gs, filp);
583 rs_dprintk (TX3912_UART_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
584 retval, port->gs.count);
590 /* tty->low_latency = 1; */
602 static int rs_ioctl (struct tty_struct * tty, struct file * filp,
603 unsigned int cmd, unsigned long arg)
606 struct rs_port *port = tty->driver_data;
612 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
613 (unsigned int *) arg);
616 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
617 tty->termios->c_cflag =
618 (tty->termios->c_cflag & ~CLOCAL) |
623 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
624 sizeof(struct serial_struct))) == 0)
625 rc = gs_getserial(&port->gs, (struct serial_struct *) arg);
628 if ((rc = verify_area(VERIFY_READ, (void *) arg,
629 sizeof(struct serial_struct))) == 0)
630 rc = gs_setserial(&port->gs, (struct serial_struct *) arg);
643 * This function is used to send a high-priority XON/XOFF character to
646 static void rs_send_xchar(struct tty_struct * tty, char ch)
648 struct rs_port *port = (struct rs_port *)tty->driver_data;
653 /* Make sure transmit interrupts are on */
654 rs_enable_tx_interrupts(tty);
662 * ------------------------------------------------------------
665 * This routine is called by the upper-layer tty layer to signal that
666 * incoming characters should be throttled.
667 * ------------------------------------------------------------
669 static void rs_throttle(struct tty_struct * tty)
671 #ifdef TX3912_UART_DEBUG_THROTTLE
674 printk("throttle %s: %d....\n", tty_name(tty, buf),
675 tty->ldisc.chars_in_buffer(tty));
681 rs_send_xchar(tty, STOP_CHAR(tty));
686 static void rs_unthrottle(struct tty_struct * tty)
688 struct rs_port *port = (struct rs_port *)tty->driver_data;
689 #ifdef TX3912_UART_DEBUG_THROTTLE
692 printk("unthrottle %s: %d....\n", tty_name(tty, buf),
693 tty->ldisc.chars_in_buffer(tty));
702 rs_send_xchar(tty, START_CHAR(tty));
712 /* ********************************************************************** *
713 * Here are the initialization routines. *
714 * ********************************************************************** */
716 void * ckmalloc (int size)
720 p = kmalloc(size, GFP_KERNEL);
728 static int rs_init_portstructs(void)
730 struct rs_port *port;
736 rs_ports = ckmalloc(TX3912_UART_NPORTS * sizeof (struct rs_port));
741 for (i=0; i < TX3912_UART_NPORTS;i++) {
742 rs_dprintk (TX3912_UART_DEBUG_INIT, "initing port %d\n", i);
743 port->gs.magic = SERIAL_MAGIC;
744 port->gs.close_delay = HZ/2;
745 port->gs.closing_wait = 30 * HZ;
746 port->gs.rd = &rs_real_driver;
747 #ifdef NEW_WRITE_LOCKING
748 port->gs.port_write_sem = MUTEX;
750 #ifdef DECLARE_WAITQUEUE
751 init_waitqueue_head(&port->gs.open_wait);
752 init_waitqueue_head(&port->gs.close_wait);
754 port->base = (i == 0) ? TX3912_UARTA_BASE : TX3912_UARTB_BASE;
755 port->intshift = (i == 0) ? UARTA_SHIFT : UARTB_SHIFT;
756 rs_dprintk (TX3912_UART_DEBUG_INIT, "base 0x%08lx intshift %d\n",
757 port->base, port->intshift);
765 static struct tty_operations rs_ops = {
769 .put_char = gs_put_char,
770 .flush_chars = gs_flush_chars,
771 .write_room = gs_write_room,
772 .chars_in_buffer = gs_chars_in_buffer,
773 .flush_buffer = gs_flush_buffer,
775 .throttle = rs_throttle,
776 .unthrottle = rs_unthrottle,
777 .set_termios = gs_set_termios,
783 static int rs_init_drivers(void)
789 rs_driver = alloc_tty_driver(TX3912_UART_NPORTS);
792 rs_driver->owner = THIS_MODULE;
793 rs_driver->driver_name = "serial";
794 rs_driver->name = "ttyS";
795 rs_driver->major = TTY_MAJOR;
796 rs_driver->minor_start = 64;
797 rs_driver->type = TTY_DRIVER_TYPE_SERIAL;
798 rs_driver->subtype = SERIAL_TYPE_NORMAL;
799 rs_driver->init_termios = tty_std_termios;
800 rs_driver->init_termios.c_cflag =
801 B115200 | CS8 | CREAD | HUPCL | CLOCAL;
802 tty_set_operations(rs_driver, &rs_ops);
803 if ((error = tty_register_driver(rs_driver))) {
804 printk(KERN_ERR "Couldn't register serial driver, error = %d\n",
806 put_tty_driver(rs_driver);
813 static void __init tx3912_rs_init(void)
819 rs_dprintk (TX3912_UART_DEBUG_INIT, "Initing serial module... (rs_debug=%d)\n", rs_debug);
821 rc = rs_init_portstructs ();
823 if (request_irq(2, rs_tx_interrupt_uarta, SA_SHIRQ | SA_INTERRUPT,
824 "serial", &rs_ports[0])) {
825 printk(KERN_ERR "rs: Cannot allocate irq for UARTA.\n");
828 if (request_irq(3, rs_rx_interrupt_uarta, SA_SHIRQ | SA_INTERRUPT,
829 "serial", &rs_ports[0])) {
830 printk(KERN_ERR "rs: Cannot allocate irq for UARTA.\n");
834 IntEnable6 |= INT6_UARTARXINT;
835 rs_enable_rx_interrupts(&rs_ports[0]);
837 #ifndef CONFIG_SERIAL_TX3912_CONSOLE
839 unsigned int scratch = 0;
841 /* Setup master clock for UART */
842 scratch = inl(TX3912_CLK_CTRL_BASE);
843 scratch &= ~TX3912_CLK_CTRL_SIBMCLKDIV_MASK;
844 scratch |= ((0x2 << TX3912_CLK_CTRL_SIBMCLKDIV_SHIFT) &
845 TX3912_CLK_CTRL_SIBMCLKDIV_MASK)
846 | TX3912_CLK_CTRL_SIBMCLKDIR
847 | TX3912_CLK_CTRL_ENSIBMCLK
848 | TX3912_CLK_CTRL_CSERSEL;
849 outl(scratch, TX3912_CLK_CTRL_BASE);
851 /* Configure UARTA clock */
852 scratch = inl(TX3912_CLK_CTRL_BASE);
853 scratch |= ((0x3 << TX3912_CLK_CTRL_CSERDIV_SHIFT) &
854 TX3912_CLK_CTRL_CSERDIV_MASK)
855 | TX3912_CLK_CTRL_ENCSERCLK
856 | TX3912_CLK_CTRL_ENUARTACLK;
857 outl(scratch, TX3912_CLK_CTRL_BASE);
859 /* Setup UARTA for 115200,8N1 */
860 outl(0, TX3912_UARTA_BASE + TX3912_UART_CTRL1);
861 outl(TX3912_UART_CTRL2_B115200, TX3912_UARTA_BASE + TX3912_UART_CTRL2);
862 outl(0, TX3912_UARTA_BASE + TX3912_UART_DMA_CTRL1);
863 outl(0, TX3912_UARTA_BASE + TX3912_UART_DMA_CTRL2);
866 outl(TX3912_UART_CTRL1_ENUART, TX3912_UARTA_BASE + TX3912_UART_CTRL1);
867 while (~inl(TX3912_UARTA_BASE + TX3912_UART_CTRL1) &
868 TX3912_UART_CTRL1_UARTON);
872 /* Note: I didn't do anything to enable the second UART */
878 module_init(tx3912_rs_init);
881 * Begin serial console routines
883 #ifdef CONFIG_SERIAL_TX3912_CONSOLE
885 void serial_outc(unsigned char c)
889 #define BUSY_WAIT 10000
892 * Turn UARTA interrupts off
896 ~(INT2_UARTATXINT | INT2_UARTATXOVERRUN | INT2_UARTAEMPTY);
899 * The UART_TX_EMPTY bit in UartA_Ctrl1 seems
900 * not to be very reliable :-(
902 * Wait for the Tx register to become empty
904 for (i = 0; !(IntStatus2 & INT2_UARTATXINT) && (i < BUSY_WAIT); i++);
906 IntClear2 = INT2_UARTATXINT | INT2_UARTATXOVERRUN | INT2_UARTAEMPTY;
908 for (i = 0; !(IntStatus2 & INT2_UARTATXINT) && (i < BUSY_WAIT); i++);
909 IntClear2 = INT2_UARTATXINT | INT2_UARTATXOVERRUN | INT2_UARTAEMPTY;
914 static void serial_console_write(struct console *co, const char *s,
919 for (i = 0; i < count; i++) {
926 static struct tty_driver *serial_console_device(struct console *c, int *index)
932 static __init int serial_console_setup(struct console *co, char *options)
934 unsigned int scratch = 0;
936 /* Setup master clock for UART */
937 scratch = inl(TX3912_CLK_CTRL_BASE);
938 scratch &= ~TX3912_CLK_CTRL_SIBMCLKDIV_MASK;
939 scratch |= ((0x2 << TX3912_CLK_CTRL_SIBMCLKDIV_SHIFT) &
940 TX3912_CLK_CTRL_SIBMCLKDIV_MASK)
941 | TX3912_CLK_CTRL_SIBMCLKDIR
942 | TX3912_CLK_CTRL_ENSIBMCLK
943 | TX3912_CLK_CTRL_CSERSEL;
944 outl(scratch, TX3912_CLK_CTRL_BASE);
946 /* Configure UARTA clock */
947 scratch = inl(TX3912_CLK_CTRL_BASE);
948 scratch |= ((0x3 << TX3912_CLK_CTRL_CSERDIV_SHIFT) &
949 TX3912_CLK_CTRL_CSERDIV_MASK)
950 | TX3912_CLK_CTRL_ENCSERCLK
951 | TX3912_CLK_CTRL_ENUARTACLK;
952 outl(scratch, TX3912_CLK_CTRL_BASE);
954 /* Setup UARTA for 115200,8N1 */
955 outl(0, TX3912_UARTA_BASE + TX3912_UART_CTRL1);
956 outl(TX3912_UART_CTRL2_B115200, TX3912_UARTA_BASE + TX3912_UART_CTRL2);
957 outl(0, TX3912_UARTA_BASE + TX3912_UART_DMA_CTRL1);
958 outl(0, TX3912_UARTA_BASE + TX3912_UART_DMA_CTRL2);
961 outl(TX3912_UART_CTRL1_ENUART, TX3912_UARTA_BASE + TX3912_UART_CTRL1);
962 while (~inl(TX3912_UARTA_BASE + TX3912_UART_CTRL1) &
963 TX3912_UART_CTRL1_UARTON);
968 static struct console sercons = {
970 .write = serial_console_write,
971 .device = serial_console_device,
972 .setup = serial_console_setup,
973 .flags = CON_PRINTBUFFER,
977 static int __init tx3912_console_init(void)
979 register_console(&sercons);
982 console_initcall(tx3912_console_init);