1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <common.h>
32
33#if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
34
35#include <clps7111.h>
36
37DECLARE_GLOBAL_DATA_PTR;
38
39void serial_setbrg (void)
40{
41 unsigned int reg = 0;
42
43 switch (gd->baudrate) {
44 case 1200: reg = 191; break;
45 case 9600: reg = 23; break;
46 case 19200: reg = 11; break;
47 case 38400: reg = 5; break;
48 case 57600: reg = 3; break;
49 case 115200: reg = 1; break;
50 default: hang (); break;
51 }
52
53
54 IO_SYSCON1 = SYSCON1_UART1EN;
55 IO_SYSCON2 = SYSCON2_UART2EN;
56
57 reg |= UBRLCR_WRDLEN8;
58
59 IO_UBRLCR1 = reg;
60 IO_UBRLCR2 = reg;
61}
62
63
64
65
66
67
68
69int serial_init (void)
70{
71 serial_setbrg ();
72
73 return (0);
74}
75
76
77
78
79
80void serial_putc (const char c)
81{
82 int tmo;
83
84
85 if (c == '\n')
86 serial_putc ('\r');
87
88 tmo = get_timer (0) + 1 * CONFIG_SYS_HZ;
89 while (IO_SYSFLG1 & SYSFLG1_UTXFF)
90 if (get_timer (0) > tmo)
91 break;
92
93 IO_UARTDR1 = c;
94}
95
96
97
98
99
100
101int serial_tstc (void)
102{
103 return !(IO_SYSFLG1 & SYSFLG1_URXFE);
104}
105
106
107
108
109
110
111int serial_getc (void)
112{
113 while (IO_SYSFLG1 & SYSFLG1_URXFE);
114
115 return IO_UARTDR1 & 0xff;
116}
117
118void
119serial_puts (const char *s)
120{
121 while (*s) {
122 serial_putc (*s++);
123 }
124}
125
126#elif defined(CONFIG_LPC2292)
127
128DECLARE_GLOBAL_DATA_PTR;
129
130#include <asm/arch/hardware.h>
131
132void serial_setbrg (void)
133{
134 unsigned short divisor = 0;
135
136 switch (gd->baudrate) {
137 case 1200: divisor = 3072; break;
138 case 9600: divisor = 384; break;
139 case 19200: divisor = 192; break;
140 case 38400: divisor = 96; break;
141 case 57600: divisor = 64; break;
142 case 115200: divisor = 32; break;
143 default: hang (); break;
144 }
145
146
147 PUT8(U0LCR, 0);
148 PUT8(U0IER, 0);
149 PUT8(U0LCR, 0x80);
150 PUT8(U0DLL, (unsigned char)(divisor & 0x00FF));
151 PUT8(U0DLM, (unsigned char)(divisor >> 8));
152 PUT8(U0LCR, 0x03);
153 PUT8(U0FCR, 1);
154}
155
156int serial_init (void)
157{
158 unsigned long pinsel0;
159
160 serial_setbrg ();
161
162 pinsel0 = GET32(PINSEL0);
163 pinsel0 &= ~(0x00000003);
164 pinsel0 |= 5;
165 PUT32(PINSEL0, pinsel0);
166
167 return (0);
168}
169
170void serial_putc (const char c)
171{
172 if (c == '\n')
173 {
174 while((GET8(U0LSR) & (1<<5)) == 0);
175 PUT8(U0THR, '\r');
176 }
177
178 while((GET8(U0LSR) & (1<<5)) == 0);
179 PUT8(U0THR, c);
180}
181
182int serial_getc (void)
183{
184 while((GET8(U0LSR) & 1) == 0);
185 return GET8(U0RBR);
186}
187
188void
189serial_puts (const char *s)
190{
191 while (*s) {
192 serial_putc (*s++);
193 }
194}
195
196
197int serial_tstc (void)
198{
199 return (GET8(U0LSR) & 1);
200}
201
202#endif
203