]>
Commit | Line | Data |
---|---|---|
3d3befa7 WD |
1 | /* |
2 | * (C) Copyright 2000 | |
3 | * Rob Taylor, Flying Pig Systems. robt@flyingpig.com. | |
4 | * | |
5 | * (C) Copyright 2004 | |
6 | * ARM Ltd. | |
7 | * Philippe Robin, <philippe.robin@arm.com> | |
8 | * | |
9 | * See file CREDITS for list of people who contributed to this | |
10 | * project. | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU General Public License as | |
14 | * published by the Free Software Foundation; either version 2 of | |
15 | * the License, or (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; if not, write to the Free Software | |
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
25 | * MA 02111-1307 USA | |
26 | */ | |
27 | ||
28 | /* Simple U-Boot driver for the PrimeCell PL011 UARTs on the IntegratorCP */ | |
29 | /* Should be fairly simple to make it work with the PL010 as well */ | |
30 | ||
31 | #include <common.h> | |
32 | ||
33 | #ifdef CFG_PL010_SERIAL | |
34 | ||
35 | #include "serial_pl011.h" | |
36 | ||
37 | #define IO_WRITE(addr, val) (*(volatile unsigned int *)(addr) = (val)) | |
38 | #define IO_READ(addr) (*(volatile unsigned int *)(addr)) | |
39 | ||
40 | /* Integrator AP has two UARTs, we use the first one, at 38400-8-N-1 */ | |
41 | #define NUM_PORTS 2 | |
42 | #define CONSOLE_PORT CONFIG_CONS_INDEX | |
43 | #define baudRate CONFIG_BAUDRATE | |
44 | static volatile unsigned char * const port[NUM_PORTS] = {(void*)(CFG_SERIAL0), | |
45 | (void*)(CFG_SERIAL1)}; | |
46 | ||
47 | ||
48 | static void pl010_putc(int portnum, char c); | |
49 | static int pl010_getc(int portnum); | |
50 | static int pl010_tstc(int portnum); | |
51 | ||
52 | ||
53 | int serial_init (void) | |
54 | { | |
55 | unsigned int temp; | |
56 | unsigned int divisor; | |
57 | ||
58 | /* | |
59 | ** First, disable everything. | |
60 | */ | |
61 | IO_WRITE(port[CONSOLE_PORT] + UART_PL010_CR, 0x0); | |
62 | ||
63 | /* | |
64 | ** Set baud rate | |
65 | ** | |
66 | */ | |
67 | switch (baudRate) { | |
68 | case 9600: | |
69 | divisor = UART_PL010_BAUD_9600; | |
70 | break; | |
71 | ||
72 | case 19200: | |
73 | divisor = UART_PL010_BAUD_9600; | |
74 | break; | |
75 | ||
76 | case 38400: | |
77 | divisor = UART_PL010_BAUD_38400; | |
78 | break; | |
79 | ||
80 | case 57600: | |
81 | divisor = UART_PL010_BAUD_57600; | |
82 | break; | |
83 | ||
84 | case 115200: | |
85 | divisor = UART_PL010_BAUD_115200; | |
86 | break; | |
87 | ||
88 | default: | |
89 | divisor = UART_PL010_BAUD_38400; | |
90 | } | |
91 | ||
92 | IO_WRITE(port[CONSOLE_PORT] + UART_PL010_LCRM, ((divisor & 0xf00) >> 8)); | |
93 | IO_WRITE(port[CONSOLE_PORT] + UART_PL010_LCRL, (divisor & 0xff)); | |
94 | ||
95 | /* | |
96 | ** Set the UART to be 8 bits, 1 stop bit, no parity, fifo enabled. | |
97 | */ | |
98 | IO_WRITE(port[CONSOLE_PORT] + UART_PL010_LCRH, | |
99 | (UART_PL010_LCRH_WLEN_8 | UART_PL010_LCRH_FEN)); | |
100 | ||
101 | /* | |
102 | ** Finally, enable the UART | |
103 | */ | |
104 | IO_WRITE(port[CONSOLE_PORT] + UART_PL010_CR, (UART_PL010_CR_UARTEN)); | |
105 | ||
106 | return (0); | |
107 | } | |
108 | ||
109 | void | |
110 | serial_putc(const char c) | |
111 | { | |
112 | if (c == '\n') | |
113 | pl010_putc(CONSOLE_PORT, '\r'); | |
114 | ||
115 | pl010_putc(CONSOLE_PORT, c); | |
116 | } | |
117 | ||
118 | void | |
119 | serial_puts (const char *s) | |
120 | { | |
121 | while (*s) { | |
122 | serial_putc (*s++); | |
123 | } | |
124 | } | |
125 | ||
126 | int | |
127 | serial_getc(void) | |
128 | { | |
129 | return pl010_getc(CONSOLE_PORT); | |
130 | } | |
131 | ||
132 | int | |
133 | serial_tstc(void) | |
134 | { | |
135 | return pl010_tstc(CONSOLE_PORT); | |
136 | } | |
137 | ||
138 | void | |
139 | serial_setbrg (void) | |
140 | { | |
141 | } | |
142 | ||
143 | static void pl010_putc(int portnum, char c) | |
144 | { | |
145 | /* Wait until there is space in the FIFO */ | |
146 | while (IO_READ(port[portnum] + UART_PL01x_FR) & UART_PL01x_FR_TXFF); | |
147 | ||
148 | /* Send the character */ | |
149 | IO_WRITE(port[portnum] + UART_PL01x_DR, c); | |
150 | } | |
151 | ||
152 | static int pl010_getc(int portnum) | |
153 | { | |
154 | unsigned int data; | |
155 | ||
156 | /* Wait until there is data in the FIFO */ | |
157 | while (IO_READ(port[portnum] + UART_PL01x_FR) & UART_PL01x_FR_RXFE); | |
158 | ||
159 | data = IO_READ(port[portnum] + UART_PL01x_DR); | |
160 | ||
161 | /* Check for an error flag */ | |
162 | if (data & 0xFFFFFF00) | |
163 | { | |
164 | /* Clear the error */ | |
165 | IO_WRITE(port[portnum] + UART_PL01x_ECR, 0xFFFFFFFF); | |
166 | return -1; | |
167 | } | |
168 | ||
169 | return (int)data; | |
170 | } | |
171 | ||
172 | static int pl010_tstc(int portnum) | |
173 | { | |
174 | return !(IO_READ(port[portnum] + UART_PL01x_FR) & UART_PL01x_FR_RXFE); | |
175 | } | |
176 | ||
177 | #endif |