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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include <draw.h>
#include <memdraw.h>
#include "screen.h"
#include "../port/netif.h"
#include "etherif.h"
#include "../port/flashif.h"
#include "archipe.h"
/*
* board-specific support for the Bright Star Engineering ipEngine-1
*/
enum {
/* sccr */
COM3= IBIT(1)|IBIT(2), /* clock output disabled */
TBS = IBIT(6), /* =0, time base is OSCCLK/{4,16}; =1, time base is GCLK2/16 */
RTSEL = IBIT(8), /* =0, select main oscillator (OSCM); =1, select external crystal (EXTCLK) */
RTDIV = IBIT(7), /* =0, divide by 4; =1, divide by 512 */
CRQEN = IBIT(9), /* =1, switch to high frequency when CPM active */
PRQEN = IBIT(10), /* =1, switch to high frequency when interrupt pending */
/* plprcr */
CSRC = IBIT(21), /* =0, clock is DFNH; =1, clock is DFNL */
Showports = 0, /* used to find lightly-documented bits set by bootstrap (eg, PDN) */
};
static ulong ports[4*4];
/*
* called early in main.c, after machinit:
* using board and architecture specific registers, initialise
* 8xx registers that need it and complete initialisation of the Mach structure.
*/
void
archinit(void)
{
IMM *io;
int mf;
io = m->iomem; /* run by reset code: no need to lock */
m->clockgen = 4000000; /* crystal frequency */
m->oscclk = m->clockgen/MHz;
io->plprcrk = KEEP_ALIVE_KEY;
io->plprcr &= ~CSRC; /* general system clock is DFNH */
mf = (io->plprcr >> 20)+1; /* use timing set by bootstrap */
io->plprcrk = ~KEEP_ALIVE_KEY;
io->sccrk = KEEP_ALIVE_KEY;
io->sccr |= CRQEN | PRQEN | RTDIV | COM3; /* devfpga.c resets COM3 if needed */
io->sccrk = ~KEEP_ALIVE_KEY;
m->cpuhz = m->clockgen*mf;
m->speed = m->cpuhz/MHz;
if((io->memc[CLOCKCS].base & 1) == 0){ /* prom hasn't mapped it */
io->memc[CLOCKCS].option = 0xFFFF0F24;
io->memc[CLOCKCS].base = 0xFF020001;
}
if(Showports){
ports[0] = io->padat;
ports[1] = io->padir;
ports[2] = io->papar;
ports[3] = io->paodr;
ports[4] = io->pbdat;
ports[5] = io->pbdir;
ports[6] = io->pbpar;
ports[7] = io->pbodr;
ports[8] = io->pcdat;
ports[9] = io->pcdir;
ports[10] = io->pcpar;
ports[11] = io->pcso;
ports[12] = io->pddat;
ports[13] = io->pddir;
ports[14] = io->pdpar;
ports[15] = 0;
}
}
static ulong
banksize(int x, ulong *pa)
{
IMM *io;
io = m->iomem;
if((io->memc[x].base & 1) == 0)
return 0; /* bank not valid */
*pa = io->memc[x].base & ~0x7FFF;
return -(io->memc[x].option&~0x7FFF);
}
/*
* initialise the kernel's memory configuration:
* there are two banks (base0, npage0) and (base1, npage1).
* initialise any other values in conf that are board-specific.
*/
void
archconfinit(void)
{
ulong pa, nbytes, ktop;
conf.nscc = 2;
conf.sccuarts = 0; /* no SCC uarts */
conf.smcuarts = (1<<0)|(1<<1); /* SMC1 (console) and SMC2 */
nbytes = banksize(DRAMCS, &pa);
if(nbytes == 0){ /* force default */
nbytes = 16*1024*1024;
pa = 0;
}
conf.npage0 = nbytes/BY2PG;
conf.base0 = pa;
conf.npage1 = 0;
/* the following assumes the kernel text and/or data is in bank 0 */
ktop = PGROUND((ulong)end);
ktop = PADDR(ktop) - conf.base0;
conf.npage0 -= ktop/BY2PG;
conf.base0 += ktop;
}
void
cpuidprint(void)
{
ulong v;
print("PVR: ");
switch(m->cputype){
case 0x01: print("MPC601"); break;
case 0x03: print("MPC603"); break;
case 0x04: print("MPC604"); break;
case 0x06: print("MPC603e"); break;
case 0x07: print("MPC603e-v7"); break;
case 0x50: print("MPC8xx"); break;
default: print("PowerPC version #%x", m->cputype); break;
}
print(", revision #%lux\n", getpvr()&0xffff);
print("IMMR: ");
v = getimmr() & 0xFFFF;
switch(v>>8){
case 0x00: print("MPC860/821"); break;
case 0x20: print("MPC823"); break;
case 0x21: print("MPC823A"); break;
default: print("Type #%lux", v>>8); break;
}
print(", mask #%lux\n", v&0xFF);
print("%lud MHz system\n", m->cpuhz/MHz);
print("\n");
if(Showports){
print("plprcr=%8.8lux sccr=%8.8lux\n", m->iomem->plprcr, m->iomem->sccr);
print("pipr=%8.8lux\n", m->iomem->pipr);
print("ports:\n");
for(v=0;v<nelem(ports);v++)
print("%2ld %8.8lux\n", v, ports[v]);
/* dump the memory configuration while we're at it */
for(v=0; v<nelem(m->iomem->memc); v++)
if(m->iomem->memc[v].base & 1)
print("%ld %8.8lux %8.8lux\n", v, m->iomem->memc[v].base, m->iomem->memc[v].option);
}
}
/*
* fetch parameters from flash, as stored by BSE bootstrap,
* compensating for a bug in its fset that produces silly entries.
*/
static int
envnameok(char *s)
{
if(*s == '*')
s++;
if(*s >= '0' && *s <= '9' || *s == 0)
return 0;
for(; *s; s++)
if(*s >= '0' && *s <= '9' ||
*s >= 'a' && *s <= 'z' ||
*s >= 'A' && *s <= 'Z' ||
*s == '.' || *s == '_' || *s == '#'){
/* ok */
}else
return 0;
return 1;
}
int
archconfval(char **names, char **vals, int limit)
{
uchar *b, *e;
char *s;
int n, v, l, o;
static char bootargs[512];
/* we assume we can access this space before mmuinit() */
b = KADDR(PHYSFLASH+0x4000);
if(*b & 1){
b += 0x2000; /* try alternative location */
if(*b & 1)
return 0;
}
v = (b[2]<<8)|b[3];
b += 4;
if(v >= 0x2000-4)
return 0;
n = 0;
o = 0;
e = b+v;
for(; b < e; b += v){
v = *b;
if(v == 0xFF || n >= limit)
break;
s = (char*)b+1;
if(v >= 0x80){
v = ((v&0x7F)<<8) | b[1];
s++;
}
if(envnameok(s)){
names[n] = s;
s += strlen(s)+1;
l = strlen(s)+1;
if(o+l > sizeof(bootargs))
break;
vals[n] = bootargs+o;
memmove(vals[n], s, l);
o += l;
n++;
}
}
return n;
}
void
toggleled(int b)
{
int s;
s = splhi();
m->iomem->pdpar &= ~(0x20<<b);
m->iomem->pddir |= 0x20<<b;
m->iomem->pddat ^= 0x020<<b;
splx(s);
}
/*
* provide value for #r/switch (devrtc.c)
*/
int
archoptionsw(void)
{
return 0;
}
/*
* invoked by clock.c:/^clockintr
*/
static void
twinkle(void)
{
if(m->ticks%MS2TK(1000) == 0 && m->iomem)
toggleled(0);
}
void (*archclocktick)(void) = twinkle;
/*
* invoked by ../port/taslock.c:/^ilock:
* reset watchdog timer here, if there is one and it is enabled
*/
void
clockcheck(void)
{
}
/*
* for ../port/devflash.c:/^flashreset
* retrieve flash type, virtual base and length and return 0;
* return -1 on error (no flash)
*/
int
archflashreset(int bank, Flash *f)
{
if(bank != 0)
return -1;
f->type = "Intel28F320B3B";
f->addr = KADDR(PHYSFLASH);
f->size = 4*1024*1024;
f->width = 2;
return 0;
}
void
archflashwp(Flash*, int)
{
}
/*
* set ether parameters: the contents should be derived from EEPROM or NVRAM
*/
int
archether(int ctlno, Ether *ether)
{
if(isaconfig("ether", ctlno, ether) == 0 && ctlno > 0)
return -1;
if(ctlno == 0){
ether->type = "SCC";
ether->port = 2;
}
memmove(ether->ea, KADDR(PHYSFLASH+0x3FFA), Eaddrlen);
return 1;
}
/*
* enable the clocks for the given SCC ether and reveal them to the caller.
* do anything else required to prepare the transceiver (eg, set full-duplex, reset loopback).
*/
int
archetherenable(int cpmid, int *rcs, int *tcs, int mbps, int fd)
{
IMM *io;
if(cpmid != CPscc2)
return -1;
USED(mbps);
io = ioplock();
io->pcpar &= ~EnetLoopback;
io->pcso &= ~EnetLoopback;
io->pcdir |= EnetLoopback;
io->pcdat &= ~EnetLoopback;
if(0){ /* TO CHECK: causes ether errors if used */
io->pbpar &= ~EnetFullDuplex;
io->pbdir |= EnetFullDuplex;
if(fd)
io->pbdat |= EnetFullDuplex;
else
io->pbdat &= ~EnetFullDuplex;
}
io->pbpar &= ~EnableEnet;
io->pbdir |= EnableEnet;
io->pbdat |= EnableEnet;
io->papar |= SIBIT(7)|SIBIT(6); /* enable CLK1 and CLK2 */
io->padir &= ~(SIBIT(7)|SIBIT(6));
iopunlock();
*rcs = CLK2;
*tcs = CLK1;
return 0;
}
/*
* do anything extra required to enable the UART on the given CPM port
*/
static ulong uartsactive;
void
archenableuart(int id, int irda)
{
IMM *io;
USED(id); /* both uarts seem to be controlled by the same bit */
USED(irda); /* no IrDA on ipEngine */
io = ioplock();
if(uartsactive == 0){
io->pbpar &= ~EnableRS232;
io->pbdir |= EnableRS232;
io->pbdat |= EnableRS232;
}
uartsactive |= 1<<id;
iopunlock();
}
/*
* do anything extra required to disable the UART on the given CPM port
*/
void
archdisableuart(int id)
{
IMM *io;
io = ioplock();
uartsactive &= ~(1<<id);
if(uartsactive == 0)
io->pbdat &= ~EnableRS232;
iopunlock();
}
/*
* enable the external USB transceiver
* speed is 12MHz if highspeed is non-zero; 1.5MHz if zero
* master is non-zero if the node is acting as USB Host and should provide power
*/
void
archenableusb(int highspeed, int master)
{
IMM *io;
USED(master);
io = ioplock();
io->pcpar &= ~USBFullSpeed;
io->pcso &= ~USBFullSpeed;
if(highspeed)
io->pcdat |= USBFullSpeed;
else
io->pcdat &= ~USBFullSpeed;
io->pcdir |= USBFullSpeed;
iopunlock();
}
/*
* shut down the USB transceiver
*/
void
archdisableusb(void)
{
/* nothing to be done on ipEngine, apparently */
}
/*
* set the external infrared transceiver to the given speed
*/
void
archsetirxcvr(int highspeed)
{
USED(highspeed);
}
/*
* force hardware reset/reboot
*/
void
archreboot(void)
{
IMM *io;
io = m->iomem;
io->plprcrk = KEEP_ALIVE_KEY;
io->plprcr |= 1<<7; /* checkstop reset enable */
io->plprcrk = ~KEEP_ALIVE_KEY;
eieio();
io->sdcr = 1;
eieio();
io->lccr = 0; /* switch LCD off */
eieio();
firmware(0);
}
/*
* enable/disable the LCD panel's backlight
*/
void
archbacklight(int on)
{
USED(on);
}
/*
* set parameters to describe the screen
*/
int
archlcdmode(Mode *m)
{
/* sample parameters in case a panel is attached to the external pins */
m->x = 640;
m->y = 480;
m->d = 3;
m->lcd.freq = 25000000;
m->lcd.ac = 0;
m->lcd.vpw = 1;
m->lcd.wbf = 33;
m->lcd.wbl = 228;
m->lcd.flags = IsColour | IsTFT | OELow | VsyncLow | ClockLow;
return -1; /* there isn't a screen */
}
/*
* there isn't a keyboard port
*/
void
archkbdinit(void)
{
}
|