4 * Qi Hardware, Xiangfu Liu <xiangfu@sharism.cc>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <asm/jz4740.h>
28 * serial_init - initialize a channel
30 * This routine initializes the number of data bits, parity
31 * and set the selected baud rate. Interrupts are disabled.
32 * Set the modem control signals if the option is selected.
36 struct jz4740_uart *uart = (struct jz4740_uart *)CONFIG_SYS_UART_BASE;
40 /* Disable port interrupts while changing hardware */
41 writeb(0, &uart->dlhr_ier);
43 /* Disable UART unit function */
44 writeb(~UART_FCR_UUE, &uart->iir_fcr);
46 /* Set both receiver and transmitter in UART mode (not SIR) */
47 writeb(~(SIRCR_RSIRE | SIRCR_TSIRE), &uart->isr);
50 * Set databits, stopbits and parity.
51 * (8-bit data, 1 stopbit, no parity)
53 writeb(UART_LCR_WLEN_8 | UART_LCR_STOP_1, &uart->lcr);
58 /* Enable UART unit, enable and clear FIFO */
59 writeb(UART_FCR_UUE | UART_FCR_FE | UART_FCR_TFLS | UART_FCR_RFLS,
65 void serial_setbrg(void)
69 baud_div = CONFIG_SYS_EXTAL / 16 / CONFIG_BAUDRATE;
71 tmp = readb(&uart->lcr);
73 writeb(tmp, &uart->lcr);
75 writeb((baud_div >> 8) & 0xff, &uart->dlhr_ier);
76 writeb(baud_div & 0xff, &uart->rbr_thr_dllr);
78 tmp &= ~UART_LCR_DLAB;
79 writeb(tmp, &uart->lcr);
84 if (readb(&uart->lsr) & UART_LSR_DR)
90 void serial_putc(const char c)
95 /* Wait for fifo to shift out some bytes */
96 while (!((readb(&uart->lsr) & (UART_LSR_TDRQ | UART_LSR_TEMT)) == 0x60))
99 writeb((u8)c, &uart->rbr_thr_dllr);
102 int serial_getc(void)
104 while (!serial_tstc())
107 return readb(&uart->rbr_thr_dllr);
110 void serial_puts(const char *s)