1
2
3
4
5
6
7
8#include <common.h>
9#include <mpc8xx.h>
10#include <asm/8xx_immap.h>
11#include "ioport.h"
12
13#if 0
14#define IOPORT_DEBUG
15#endif
16
17#ifdef IOPORT_DEBUG
18#define PRINTF(fmt,args...) printf (fmt ,##args)
19#else
20#define PRINTF(fmt,args...)
21#endif
22
23
24
25
26const mpc8xx_iop_conf_t iop_conf_tab[NUM_PORTS][PORT_BITS] = {
27
28
29
30
31
32
33 {
34 { 0, 0, 0, 0, 0, 0, 0 },
35 { 0, 0, 0, 0, 0, 0, 0 },
36 { 0, 0, 0, 0, 0, 0, 0 },
37 { 0, 0, 0, 0, 0, 0, 0 },
38 { 0, 0, 0, 0, 0, 0, 0 },
39 { 0, 0, 0, 0, 0, 0, 0 },
40 { 0, 0, 0, 0, 0, 0, 0 },
41 { 0, 0, 0, 0, 0, 0, 0 },
42 { 1, 0, 0, 1, 0, 0, 0 },
43 { 1, 0, 0, 1, 0, 0, 0 },
44 { 1, 0, 0, 1, 0, 1, 0 },
45 { 0, 0, 0, 0, 0, 0, 0 },
46 { 1, 0, 0, 1, 0, 0, 0 },
47 { 1, 0, 0, 1, 0, 0, 0 },
48 { 0, 0, 0, 0, 0, 0, 0 },
49 { 0, 0, 0, 0, 0, 0, 0 },
50#if !defined(CONFIG_SC)
51 { 1, 0, 0, 0, 0, 0, 0 },
52#else
53 { 0, 0, 0, 0, 0, 0, 0 },
54#endif
55 { 0, 0, 0, 0, 0, 0, 0 }
56 },
57
58
59
60
61
62
63
64
65
66
67
68
69
70 {
71#if !defined(CONFIG_SC)
72 { 0, 0, 0, 0, 0, 0, 0 },
73#else
74 { 1, 0, 0, 1, 0, 0, 0 },
75#endif
76 { 0, 0, 0, 0, 0, 0, 0 },
77 { 0, 0, 0, 0, 0, 0, 0 },
78 { 0, 0, 0, 0, 0, 0, 0 },
79 { 0, 0, 0, 0, 0, 0, 0 },
80 { 0, 0, 0, 0, 0, 0, 0 },
81 { 0, 0, 0, 0, 0, 0, 0 },
82 { 0, 0, 0, 0, 0, 0, 0 },
83#if !defined(CONFIG_SC)
84 { 1, 0, 0, 0, 0, 0, 0 },
85#else
86 { 0, 0, 0, 0, 0, 0, 0 },
87#endif
88 { 1, 0, 0, 0, 0, 0, 0 },
89 { 0, 0, 0, 0, 0, 0, 0 },
90 { 0, 0, 0, 0, 0, 0, 0 },
91#if !defined(CONFIG_SC)
92 { 1, 0, 0, 1, 1, 1, 0 },
93#else
94 { 0, 0, 0, 1, 1, 1, 0 },
95#endif
96 { 0, 0, 0, 0, 0, 0, 0 },
97 { 1, 0, 0, 1, 0, 1, 0 },
98 { 1, 0, 0, 0, 0, 0, 0 },
99 { 1, 0, 0, 1, 0, 0, 0 },
100#if !defined(CONFIG_SC)
101 { 1, 0, 0, 0, 0, 0, 0 }
102#else
103 { 0, 0, 0, 0, 0, 0, 0 }
104#endif
105 },
106
107
108
109
110
111
112
113
114
115
116
117
118
119 {
120 { 0, 0, 0, 0, 0, 0, 0 },
121 { 0, 0, 0, 0, 0, 0, 0 },
122 { 1, 0, 0, 0, 0, 0, 0 },
123 { 0, 0, 0, 0, 0, 0, 0 },
124 { 0, 0, 0, 0, 0, 0, 0 },
125#if !defined(CONFIG_SC)
126 { 1, 0, 0, 0, 0, 0, 0 },
127#else
128 { 0, 0, 0, 0, 0, 0, 0 },
129#endif
130 { 1, 0, 0, 1, 0, 1, 0 },
131#if !defined(CONFIG_SC)
132 { 1, 0, 0, 1, 0, 1, 0 },
133#else
134 { 0, 0, 0, 1, 0, 1, 0 },
135#endif
136 { 0, 0, 0, 0, 0, 0, 0 },
137#if !defined(CONFIG_SC)
138 { 1, 0, 0, 1, 0, 1, 0 },
139#else
140 { 0, 0, 0, 1, 0, 1, 0 },
141#endif
142 { 0, 0, 0, 0, 0, 0, 0 },
143 { 1, 0, 0, 1, 0, 1, 0 },
144#if !defined(CONFIG_SC)
145 { 1, 0, 0, 1, 0, 1, 0 },
146 { 1, 0, 0, 1, 0, 1, 0 },
147#else
148 { 0, 0, 0, 1, 0, 1, 0 },
149 { 0, 0, 0, 1, 0, 1, 0 },
150#endif
151 { 0, 0, 0, 0, 0, 0, 0 },
152 { 0, 0, 0, 0, 0, 0, 0 },
153 { 0, 0, 0, 0, 0, 0, 0 },
154 { 0, 0, 0, 0, 0, 0, 0 }
155 },
156
157
158
159
160 {
161 { 0, 0, 0, 0, 0, 0, 0 },
162 { 0, 0, 0, 0, 0, 0, 0 },
163 { 0, 0, 0, 0, 0, 0, 0 },
164 { 0, 0, 0, 0, 0, 0, 0 },
165 { 0, 0, 0, 0, 0, 0, 0 },
166 { 0, 0, 0, 0, 0, 0, 0 },
167 { 0, 0, 0, 0, 0, 0, 0 },
168 { 0, 0, 0, 0, 0, 0, 0 },
169 { 0, 0, 0, 0, 0, 0, 0 },
170 { 0, 0, 0, 0, 0, 0, 0 },
171 { 0, 0, 0, 0, 0, 0, 0 },
172 { 0, 0, 0, 0, 0, 0, 0 },
173 { 0, 0, 0, 0, 0, 0, 0 },
174 { 0, 0, 0, 0, 0, 0, 0 },
175 { 0, 0, 0, 0, 0, 0, 0 },
176 { 0, 0, 0, 0, 0, 0, 0 },
177 { 0, 0, 0, 0, 0, 0, 0 },
178 { 0, 0, 0, 0, 0, 0, 0 }
179 }
180};
181
182
183
184
185
186void config_mpc8xx_ioports (volatile immap_t * immr)
187{
188 int portnum;
189
190 for (portnum = 0; portnum < NUM_PORTS; portnum++) {
191 uint pmsk = 0, ppar = 0, psor = 0, pdir = 0;
192 uint podr = 0, pdat = 0, pint = 0;
193 uint msk = 1;
194 mpc8xx_iop_conf_t *iopc =
195 (mpc8xx_iop_conf_t *) & iop_conf_tab[portnum][0];
196 mpc8xx_iop_conf_t *eiopc = iopc + PORT_BITS;
197
198
199
200
201
202 if (portnum != 1) {
203 iopc = (mpc8xx_iop_conf_t *) &
204 iop_conf_tab[portnum][2];
205 }
206
207
208
209
210 while (iopc < eiopc) {
211 if (iopc->conf) {
212 pmsk |= msk;
213 if (iopc->ppar)
214 ppar |= msk;
215 if (iopc->psor)
216 psor |= msk;
217 if (iopc->pdir)
218 pdir |= msk;
219 if (iopc->podr)
220 podr |= msk;
221 if (iopc->pdat)
222 pdat |= msk;
223 if (iopc->pint)
224 pint |= msk;
225 }
226 msk <<= 1;
227 iopc++;
228 }
229
230 PRINTF ("%s:%d:\n portnum=%d ", __FUNCTION__, __LINE__,
231 portnum);
232#ifdef IOPORT_DEBUG
233 switch (portnum) {
234 case 0:
235 printf ("(A)\n");
236 break;
237 case 1:
238 printf ("(B)\n");
239 break;
240 case 2:
241 printf ("(C)\n");
242 break;
243 case 3:
244 printf ("(D)\n");
245 break;
246 default:
247 printf ("(?)\n");
248 break;
249 }
250#endif
251 PRINTF (" ppar=0x%.8x pdir=0x%.8x podr=0x%.8x\n"
252 " pdat=0x%.8x psor=0x%.8x pint=0x%.8x pmsk=0x%.8x\n",
253 ppar, pdir, podr, pdat, psor, pint, pmsk);
254
255
256
257
258
259 if (pmsk != 0) {
260 uint tpmsk = ~pmsk;
261
262 if (0 == portnum) {
263 immr->im_ioport.iop_papar &= tpmsk;
264 immr->im_ioport.iop_padat =
265 (immr->im_ioport.
266 iop_padat & tpmsk) | pdat;
267 immr->im_ioport.iop_padir =
268 (immr->im_ioport.
269 iop_padir & tpmsk) | pdir;
270 immr->im_ioport.iop_paodr =
271 (immr->im_ioport.
272 iop_paodr & tpmsk) | podr;
273 immr->im_ioport.iop_papar |= ppar;
274 } else if (1 == portnum) {
275 immr->im_cpm.cp_pbpar &= tpmsk;
276 immr->im_cpm.cp_pbdat =
277 (immr->im_cpm.
278 cp_pbdat & tpmsk) | pdat;
279 immr->im_cpm.cp_pbdir =
280 (immr->im_cpm.
281 cp_pbdir & tpmsk) | pdir;
282 immr->im_cpm.cp_pbodr =
283 (immr->im_cpm.
284 cp_pbodr & tpmsk) | podr;
285 immr->im_cpm.cp_pbpar |= ppar;
286 } else if (2 == portnum) {
287 immr->im_ioport.iop_pcpar &= tpmsk;
288 immr->im_ioport.iop_pcdat =
289 (immr->im_ioport.
290 iop_pcdat & tpmsk) | pdat;
291 immr->im_ioport.iop_pcdir =
292 (immr->im_ioport.
293 iop_pcdir & tpmsk) | pdir;
294 immr->im_ioport.iop_pcint =
295 (immr->im_ioport.
296 iop_pcint & tpmsk) | pint;
297 immr->im_ioport.iop_pcso =
298 (immr->im_ioport.
299 iop_pcso & tpmsk) | psor;
300 immr->im_ioport.iop_pcpar |= ppar;
301 } else if (3 == portnum) {
302 immr->im_ioport.iop_pdpar &= tpmsk;
303 immr->im_ioport.iop_pddat =
304 (immr->im_ioport.
305 iop_pddat & tpmsk) | pdat;
306 immr->im_ioport.iop_pddir =
307 (immr->im_ioport.
308 iop_pddir & tpmsk) | pdir;
309 immr->im_ioport.iop_pdpar |= ppar;
310 }
311 }
312 }
313
314 PRINTF ("%s:%d: Port A:\n papar=0x%.4x padir=0x%.4x"
315 " paodr=0x%.4x\n padat=0x%.4x\n", __FUNCTION__, __LINE__,
316 immr->im_ioport.iop_papar, immr->im_ioport.iop_padir,
317 immr->im_ioport.iop_paodr, immr->im_ioport.iop_padat);
318 PRINTF ("%s:%d: Port B:\n pbpar=0x%.8x pbdir=0x%.8x"
319 " pbodr=0x%.8x\n pbdat=0x%.8x\n", __FUNCTION__, __LINE__,
320 immr->im_cpm.cp_pbpar, immr->im_cpm.cp_pbdir,
321 immr->im_cpm.cp_pbodr, immr->im_cpm.cp_pbdat);
322 PRINTF ("%s:%d: Port C:\n pcpar=0x%.4x pcdir=0x%.4x"
323 " pcdat=0x%.4x\n pcso=0x%.4x pcint=0x%.4x\n ",
324 __FUNCTION__, __LINE__, immr->im_ioport.iop_pcpar,
325 immr->im_ioport.iop_pcdir, immr->im_ioport.iop_pcdat,
326 immr->im_ioport.iop_pcso, immr->im_ioport.iop_pcint);
327 PRINTF ("%s:%d: Port D:\n pdpar=0x%.4x pddir=0x%.4x"
328 " pddat=0x%.4x\n", __FUNCTION__, __LINE__,
329 immr->im_ioport.iop_pdpar, immr->im_ioport.iop_pddir,
330 immr->im_ioport.iop_pddat);
331}
332