1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <commproc.h>
26#include <asm/processor.h>
27#include <asm/io.h>
28#include <watchdog.h>
29
30#ifdef CONFIG_SERIAL_MULTI
31#include <serial.h>
32#endif
33
34DECLARE_GLOBAL_DATA_PTR;
35
36#ifdef CONFIG_IOP480
37
38#define SPU_BASE 0x40000000
39
40#define spu_LineStat_rc 0x00
41#define spu_LineStat_w 0x04
42#define spu_Handshk_rc 0x08
43#define spu_Handshk_w 0x0c
44#define spu_BRateDivh 0x10
45#define spu_BRateDivl 0x14
46#define spu_CtlReg 0x18
47#define spu_RxCmd 0x1c
48#define spu_TxCmd 0x20
49#define spu_RxBuff 0x24
50#define spu_TxBuff 0x24
51
52
53
54
55#define asyncLSRport1 0x40000000
56#define asyncLSRport1set 0x40000004
57#define asyncLSRDataReady 0x80
58#define asyncLSRFramingError 0x40
59#define asyncLSROverrunError 0x20
60#define asyncLSRParityError 0x10
61#define asyncLSRBreakInterrupt 0x08
62#define asyncLSRTxHoldEmpty 0x04
63#define asyncLSRTxShiftEmpty 0x02
64
65
66
67
68#define asyncHSRport1 0x40000008
69#define asyncHSRport1set 0x4000000c
70#define asyncHSRDsr 0x80
71#define asyncLSRCts 0x40
72
73
74
75
76#define asyncCRport1 0x40000018
77#define asyncCRNormal 0x00
78#define asyncCRLoopback 0x40
79#define asyncCRAutoEcho 0x80
80#define asyncCRDtr 0x20
81#define asyncCRRts 0x10
82#define asyncCRWordLength7 0x00
83#define asyncCRWordLength8 0x08
84#define asyncCRParityDisable 0x00
85#define asyncCRParityEnable 0x04
86#define asyncCREvenParity 0x00
87#define asyncCROddParity 0x02
88#define asyncCRStopBitsOne 0x00
89#define asyncCRStopBitsTwo 0x01
90#define asyncCRDisableDtrRts 0x00
91
92
93
94
95#define asyncRCRport1 0x4000001c
96#define asyncRCRDisable 0x00
97#define asyncRCREnable 0x80
98#define asyncRCRIntDisable 0x00
99#define asyncRCRIntEnabled 0x20
100#define asyncRCRDMACh2 0x40
101#define asyncRCRDMACh3 0x60
102#define asyncRCRErrorInt 0x10
103#define asyncRCRPauseEnable 0x08
104
105
106
107
108#define asyncTCRport1 0x40000020
109#define asyncTCRDisable 0x00
110#define asyncTCREnable 0x80
111#define asyncTCRIntDisable 0x00
112#define asyncTCRIntEnabled 0x20
113#define asyncTCRDMACh2 0x40
114#define asyncTCRDMACh3 0x60
115#define asyncTCRTxEmpty 0x10
116#define asyncTCRErrorInt 0x08
117#define asyncTCRStopPause 0x04
118#define asyncTCRBreakGen 0x02
119
120
121
122
123#define asyncTxBufferport1 0x40000024
124#define asyncRxBufferport1 0x40000024
125#define asyncDLABLsbport1 0x40000014
126#define asyncDLABMsbport1 0x40000010
127#define asyncXOFFchar 0x13
128#define asyncXONchar 0x11
129
130
131
132
133
134
135int serial_init (void)
136{
137 volatile char val;
138 unsigned short br_reg;
139
140 br_reg = ((((CONFIG_CPUCLOCK * 1000000) / 16) / gd->baudrate) - 1);
141
142
143
144
145 out_8((u8 *)SPU_BASE + spu_LineStat_rc, 0x78);
146 out_8((u8 *)SPU_BASE + spu_BRateDivl, (br_reg & 0x00ff));
147 out_8((u8 *)SPU_BASE + spu_BRateDivh, ((br_reg & 0xff00) >> 8));
148 out_8((u8 *)SPU_BASE + spu_CtlReg, 0x08);
149 out_8((u8 *)SPU_BASE + spu_RxCmd, 0xb0);
150 out_8((u8 *)SPU_BASE + spu_TxCmd, 0x9c);
151 out_8((u8 *)SPU_BASE + spu_Handshk_rc, 0xff);
152 val = in_8((u8 *)SPU_BASE + spu_RxBuff);
153
154 return (0);
155}
156
157void serial_setbrg (void)
158{
159 unsigned short br_reg;
160
161 br_reg = ((((CONFIG_CPUCLOCK * 1000000) / 16) / gd->baudrate) - 1);
162
163 out_8((u8 *)SPU_BASE + spu_BRateDivl,
164 (br_reg & 0x00ff));
165 out_8((u8 *)SPU_BASE + spu_BRateDivh,
166 ((br_reg & 0xff00) >> 8));
167}
168
169void serial_putc (const char c)
170{
171 if (c == '\n')
172 serial_putc ('\r');
173
174
175 if (in_8((u8 *)SPU_BASE + spu_Handshk_rc) != 00)
176 out_8((u8 *)SPU_BASE + spu_Handshk_rc, 0xff);
177
178 out_8((u8 *)SPU_BASE + spu_TxBuff, c);
179
180 while ((in_8((u8 *)SPU_BASE + spu_LineStat_rc) & 04) != 04) {
181 if (in_8((u8 *)SPU_BASE + spu_Handshk_rc) != 00)
182 out_8((u8 *)SPU_BASE + spu_Handshk_rc, 0xff);
183 }
184}
185
186void serial_puts (const char *s)
187{
188 while (*s) {
189 serial_putc (*s++);
190 }
191}
192
193int serial_getc ()
194{
195 unsigned char status = 0;
196
197 while (1) {
198 status = in_8((u8 *)asyncLSRport1);
199 if ((status & asyncLSRDataReady) != 0x0) {
200 break;
201 }
202 if ((status & ( asyncLSRFramingError |
203 asyncLSROverrunError |
204 asyncLSRParityError |
205 asyncLSRBreakInterrupt )) != 0) {
206 (void) out_8((u8 *)asyncLSRport1,
207 asyncLSRFramingError |
208 asyncLSROverrunError |
209 asyncLSRParityError |
210 asyncLSRBreakInterrupt );
211 }
212 }
213 return (0x000000ff & (int) in_8((u8 *)asyncRxBufferport1));
214}
215
216int serial_tstc ()
217{
218 unsigned char status;
219
220 status = in_8((u8 *)asyncLSRport1);
221 if ((status & asyncLSRDataReady) != 0x0) {
222 return (1);
223 }
224 if ((status & ( asyncLSRFramingError |
225 asyncLSROverrunError |
226 asyncLSRParityError |
227 asyncLSRBreakInterrupt )) != 0) {
228 (void) out_8((u8 *)asyncLSRport1,
229 asyncLSRFramingError |
230 asyncLSROverrunError |
231 asyncLSRParityError |
232 asyncLSRBreakInterrupt);
233 }
234 return 0;
235}
236
237#endif
238