4 * Options hardcoded to 8N1
6 * Copyright (c) 2009, yajin <yajin@vm-kernel.org>
7 * Copyright (c) 2005 - 2008, Ingenic Semiconductor Inc.
8 * Ingenic Semiconductor, <jlwei@ingenic.cn>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #define UART_BASE UART0_BASE
34 #define UART_BASE CFG_UART_BASE
37 /******************************************************************************
39 * serial_init - initialize a channel
41 * This routine initializes the number of data bits, parity
42 * and set the selected baud rate. Interrupts are disabled.
43 * Set the modem control signals if the option is selected.
48 static void serial_setbrg(void)
50 volatile u8
*uart_lcr
= (volatile u8
*) (UART_BASE
+ OFF_LCR
);
51 volatile u8
*uart_dlhr
= (volatile u8
*) (UART_BASE
+ OFF_DLHR
);
52 volatile u8
*uart_dllr
= (volatile u8
*) (UART_BASE
+ OFF_DLLR
);
55 baud_div
= CFG_EXTAL
/ 16 / CONFIG_BAUDRATE
;
60 *uart_dlhr
= (baud_div
>> 8) & 0xff;
61 *uart_dllr
= baud_div
& 0xff;
63 tmp
&= ~UART_LCR_DLAB
;
69 volatile u8
*uart_fcr
= (volatile u8
*) (UART_BASE
+ OFF_FCR
);
70 volatile u8
*uart_lcr
= (volatile u8
*) (UART_BASE
+ OFF_LCR
);
71 volatile u8
*uart_ier
= (volatile u8
*) (UART_BASE
+ OFF_IER
);
72 volatile u8
*uart_sircr
= (volatile u8
*) (UART_BASE
+ OFF_SIRCR
);
74 /* Disable port interrupts while changing hardware */
77 /* Disable UART unit function */
78 *uart_fcr
= ~UART_FCR_UUE
;
80 /* Set both receiver and transmitter in UART mode (not SIR) */
81 *uart_sircr
= ~(SIRCR_RSIRE
| SIRCR_TSIRE
);
83 /* Set databits, stopbits and parity. (8-bit data, 1 stopbit, no parity) */
84 *uart_lcr
= UART_LCR_WLEN_8
| UART_LCR_STOP_1
;
89 /* Enable UART unit, enable and clear FIFO */
90 *uart_fcr
= UART_FCR_UUE
| UART_FCR_FE
| UART_FCR_TFLS
| UART_FCR_RFLS
;
95 void serial_putc(const char c
)
97 volatile u8
*uart_lsr
= (volatile u8
*) (UART_BASE
+ OFF_LSR
);
98 volatile u8
*uart_tdr
= (volatile u8
*) (UART_BASE
+ OFF_TDR
);
103 /* Wait for fifo to shift out some bytes */
104 while (!((*uart_lsr
& (UART_LSR_TDRQ
| UART_LSR_TEMT
)) == 0x60));
109 void serial_puts(const char *s
)