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
|
/*
* (C) Copyright 2009 Reinhard Arlt, reinhard.arlt@esd-electronics.com
*
* base on universe.h by
*
* (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <common.h>
#include <command.h>
#include <malloc.h>
#include <asm/io.h>
#include <pci.h>
#include <tsi148.h>
#define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
#define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_TSI148
typedef struct _TSI148_DEV TSI148_DEV;
struct _TSI148_DEV {
int bus;
pci_dev_t busdevfn;
TSI148 *uregs;
unsigned int pci_bs;
};
static TSI148_DEV *dev;
/*
* Most of the TSI148 register are BIGENDIAN
* This is the reason for the __raw_writel(htonl(x), x) usage!
*/
int tsi148_init(void)
{
int j, result;
pci_dev_t busdevfn;
unsigned int val;
busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
if (busdevfn == -1) {
puts("Tsi148: No Tundra Tsi148 found!\n");
return -1;
}
/* Lets turn Latency off */
pci_write_config_dword(busdevfn, 0x0c, 0);
dev = malloc(sizeof(*dev));
if (NULL == dev) {
puts("Tsi148: No memory!\n");
return -1;
}
memset(dev, 0, sizeof(*dev));
dev->busdevfn = busdevfn;
pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
val &= ~0xf;
dev->uregs = (TSI148 *)val;
debug("Tsi148: Base : %p\n", dev->uregs);
/* check mapping */
debug("Tsi148: Read via mapping, PCI_ID = %08X\n",
readl(&dev->uregs->pci_id));
if (((PCI_DEVICE << 16) | PCI_VENDOR) != readl(&dev->uregs->pci_id)) {
printf("Tsi148: Cannot read PCI-ID via Mapping: %08x\n",
readl(&dev->uregs->pci_id));
result = -1;
goto break_30;
}
debug("Tsi148: PCI_BS = %08X\n", readl(&dev->uregs->pci_mbarl));
dev->pci_bs = readl(&dev->uregs->pci_mbarl);
/* turn off windows */
for (j = 0; j < 8; j++) {
__raw_writel(htonl(0x00000000), &dev->uregs->outbound[j].otat);
__raw_writel(htonl(0x00000000), &dev->uregs->inbound[j].itat);
}
/* Tsi148 VME timeout etc */
__raw_writel(htonl(0x00000084), &dev->uregs->vctrl);
#ifdef DEBUG
if ((__raw_readl(&dev->uregs->vstat) & 0x00000100) != 0)
printf("Tsi148: System Controller!\n");
else
printf("Tsi148: Not System Controller!\n");
#endif
/*
* Lets turn off interrupts
*/
/* Disable interrupts in Tsi148 first */
__raw_writel(htonl(0x00000000), &dev->uregs->inten);
/* Disable interrupt out */
__raw_writel(htonl(0x00000000), &dev->uregs->inteo);
eieio();
/* Reset all IRQ's */
__raw_writel(htonl(0x03ff3f00), &dev->uregs->intc);
/* Map all ints to 0 */
__raw_writel(htonl(0x00000000), &dev->uregs->intm1);
__raw_writel(htonl(0x00000000), &dev->uregs->intm2);
eieio();
val = __raw_readl(&dev->uregs->vstat);
val &= ~(0x00004000);
__raw_writel(val, &dev->uregs->vstat);
eieio();
debug("Tsi148: register struct size %08x\n", sizeof(TSI148));
return 0;
break_30:
free(dev);
dev = NULL;
return result;
}
/*
* Create pci slave window (access: pci -> vme)
*/
int tsi148_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr,
int size, int vam, int vdw)
{
int result, i;
unsigned int ctl = 0;
if (NULL == dev) {
result = -1;
goto exit_10;
}
for (i = 0; i < 8; i++) {
if (0x00000000 == readl(&dev->uregs->outbound[i].otat))
break;
}
if (i > 7) {
printf("Tsi148: No Image available\n");
result = -1;
goto exit_10;
}
debug("Tsi148: Using image %d\n", i);
printf("Tsi148: Pci addr %08x\n", pciAddr);
__raw_writel(htonl(pciAddr), &dev->uregs->outbound[i].otsal);
__raw_writel(0x00000000, &dev->uregs->outbound[i].otsau);
__raw_writel(htonl(pciAddr + size), &dev->uregs->outbound[i].oteal);
__raw_writel(0x00000000, &dev->uregs->outbound[i].oteau);
__raw_writel(htonl(vmeAddr - pciAddr), &dev->uregs->outbound[i].otofl);
__raw_writel(0x00000000, &dev->uregs->outbound[i].otofu);
switch (vam & VME_AM_Axx) {
case VME_AM_A16:
ctl = 0x00000000;
break;
case VME_AM_A24:
ctl = 0x00000001;
break;
case VME_AM_A32:
ctl = 0x00000002;
break;
}
switch (vam & VME_AM_Mxx) {
case VME_AM_DATA:
ctl |= 0x00000000;
break;
case VME_AM_PROG:
ctl |= 0x00000010;
break;
}
if (vam & VME_AM_SUP)
ctl |= 0x00000020;
switch (vdw & VME_FLAG_Dxx) {
case VME_FLAG_D16:
ctl |= 0x00000000;
break;
case VME_FLAG_D32:
ctl |= 0x00000040;
break;
}
ctl |= 0x80040000; /* enable, no prefetch */
__raw_writel(htonl(ctl), &dev->uregs->outbound[i].otat);
debug("Tsi148: window-addr =%p\n",
&dev->uregs->outbound[i].otsau);
debug("Tsi148: pci slave window[%d] attr =%08x\n",
i, ntohl(__raw_readl(&dev->uregs->outbound[i].otat)));
debug("Tsi148: pci slave window[%d] start =%08x\n",
i, ntohl(__raw_readl(&dev->uregs->outbound[i].otsal)));
debug("Tsi148: pci slave window[%d] end =%08x\n",
i, ntohl(__raw_readl(&dev->uregs->outbound[i].oteal)));
debug("Tsi148: pci slave window[%d] offset=%08x\n",
i, ntohl(__raw_readl(&dev->uregs->outbound[i].otofl)));
return 0;
exit_10:
return -result;
}
unsigned int tsi148_eval_vam(int vam)
{
unsigned int ctl = 0;
switch (vam & VME_AM_Axx) {
case VME_AM_A16:
ctl = 0x00000000;
break;
case VME_AM_A24:
ctl = 0x00000010;
break;
case VME_AM_A32:
ctl = 0x00000020;
break;
}
switch (vam & VME_AM_Mxx) {
case VME_AM_DATA:
ctl |= 0x00000001;
break;
case VME_AM_PROG:
ctl |= 0x00000002;
break;
case (VME_AM_PROG | VME_AM_DATA):
ctl |= 0x00000003;
break;
}
if (vam & VME_AM_SUP)
ctl |= 0x00000008;
if (vam & VME_AM_USR)
ctl |= 0x00000004;
return ctl;
}
/*
* Create vme slave window (access: vme -> pci)
*/
int tsi148_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr,
int size, int vam)
{
int result, i;
unsigned int ctl = 0;
if (NULL == dev) {
result = -1;
goto exit_10;
}
for (i = 0; i < 8; i++) {
if (0x00000000 == readl(&dev->uregs->inbound[i].itat))
break;
}
if (i > 7) {
printf("Tsi148: No Image available\n");
result = -1;
goto exit_10;
}
debug("Tsi148: Using image %d\n", i);
__raw_writel(htonl(vmeAddr), &dev->uregs->inbound[i].itsal);
__raw_writel(0x00000000, &dev->uregs->inbound[i].itsau);
__raw_writel(htonl(vmeAddr + size), &dev->uregs->inbound[i].iteal);
__raw_writel(0x00000000, &dev->uregs->inbound[i].iteau);
__raw_writel(htonl(pciAddr - vmeAddr), &dev->uregs->inbound[i].itofl);
if (vmeAddr > pciAddr)
__raw_writel(0xffffffff, &dev->uregs->inbound[i].itofu);
else
__raw_writel(0x00000000, &dev->uregs->inbound[i].itofu);
ctl = tsi148_eval_vam(vam);
ctl |= 0x80000000; /* enable */
__raw_writel(htonl(ctl), &dev->uregs->inbound[i].itat);
debug("Tsi148: window-addr =%p\n",
&dev->uregs->inbound[i].itsau);
debug("Tsi148: vme slave window[%d] attr =%08x\n",
i, ntohl(__raw_readl(&dev->uregs->inbound[i].itat)));
debug("Tsi148: vme slave window[%d] start =%08x\n",
i, ntohl(__raw_readl(&dev->uregs->inbound[i].itsal)));
debug("Tsi148: vme slave window[%d] end =%08x\n",
i, ntohl(__raw_readl(&dev->uregs->inbound[i].iteal)));
debug("Tsi148: vme slave window[%d] offset=%08x\n",
i, ntohl(__raw_readl(&dev->uregs->inbound[i].itofl)));
return 0;
exit_10:
return -result;
}
/*
* Create vme slave window (access: vme -> gcsr)
*/
int tsi148_vme_gcsr_window(unsigned int vmeAddr, int vam)
{
int result;
unsigned int ctl;
result = 0;
if (NULL == dev) {
result = 1;
} else {
__raw_writel(htonl(vmeAddr), &dev->uregs->gbal);
__raw_writel(0x00000000, &dev->uregs->gbau);
ctl = tsi148_eval_vam(vam);
ctl |= 0x00000080; /* enable */
__raw_writel(htonl(ctl), &dev->uregs->gcsrat);
}
return result;
}
/*
* Create vme slave window (access: vme -> crcsr)
*/
int tsi148_vme_crcsr_window(unsigned int vmeAddr)
{
int result;
unsigned int ctl;
result = 0;
if (NULL == dev) {
result = 1;
} else {
__raw_writel(htonl(vmeAddr), &dev->uregs->crol);
__raw_writel(0x00000000, &dev->uregs->crou);
ctl = 0x00000080; /* enable */
__raw_writel(htonl(ctl), &dev->uregs->crat);
}
return result;
}
/*
* Create vme slave window (access: vme -> crg)
*/
int tsi148_vme_crg_window(unsigned int vmeAddr, int vam)
{
int result;
unsigned int ctl;
result = 0;
if (NULL == dev) {
result = 1;
} else {
__raw_writel(htonl(vmeAddr), &dev->uregs->cbal);
__raw_writel(0x00000000, &dev->uregs->cbau);
ctl = tsi148_eval_vam(vam);
ctl |= 0x00000080; /* enable */
__raw_writel(htonl(ctl), &dev->uregs->crgat);
}
return result;
}
/*
* Tundra Tsi148 configuration
*/
int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, vdw = 0;
char cmd = 'x';
/* get parameter */
if (argc > 1)
cmd = argv[1][0];
if (argc > 2)
addr1 = simple_strtoul(argv[2], NULL, 16);
if (argc > 3)
addr2 = simple_strtoul(argv[3], NULL, 16);
if (argc > 4)
size = simple_strtoul(argv[4], NULL, 16);
if (argc > 5)
vam = simple_strtoul(argv[5], NULL, 16);
if (argc > 6)
vdw = simple_strtoul(argv[6], NULL, 16);
switch (cmd) {
case 'c':
if (strcmp(argv[1], "crg") == 0) {
vam = addr2;
printf("Tsi148: Configuring VME CRG Window "
"(VME->CRG):\n");
printf(" vme=%08lx vam=%02lx\n", addr1, vam);
tsi148_vme_crg_window(addr1, vam);
} else {
printf("Tsi148: Configuring VME CR/CSR Window "
"(VME->CR/CSR):\n");
printf(" pci=%08lx\n", addr1);
tsi148_vme_crcsr_window(addr1);
}
break;
case 'i': /* init */
tsi148_init();
break;
case 'g':
vam = addr2;
printf("Tsi148: Configuring VME GCSR Window (VME->GCSR):\n");
printf(" vme=%08lx vam=%02lx\n", addr1, vam);
tsi148_vme_gcsr_window(addr1, vam);
break;
case 'v': /* vme */
printf("Tsi148: Configuring VME Slave Window (VME->PCI):\n");
printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx\n",
addr1, addr2, size, vam);
tsi148_vme_slave_window(addr1, addr2, size, vam);
break;
case 'p': /* pci */
printf("Tsi148: Configuring PCI Slave Window (PCI->VME):\n");
printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx vdw=%02lx\n",
addr1, addr2, size, vam, vdw);
tsi148_pci_slave_window(addr1, addr2, size, vam, vdw);
break;
default:
printf("Tsi148: Command %s not supported!\n", argv[1]);
}
return 0;
}
U_BOOT_CMD(
tsi148, 7, 1, do_tsi148,
"initialize and configure Turndra Tsi148\n",
"init\n"
" - initialize tsi148\n"
"tsi148 vme [vme_addr] [pci_addr] [size] [vam]\n"
" - create vme slave window (access: vme->pci)\n"
"tsi148 pci [pci_addr] [vme_addr] [size] [vam] [vdw]\n"
" - create pci slave window (access: pci->vme)\n"
"tsi148 crg [vme_addr] [vam]\n"
" - create vme slave window: (access vme->CRG\n"
"tsi148 crcsr [pci_addr]\n"
" - create vme slave window: (access vme->CR/CSR\n"
"tsi148 gcsr [vme_addr] [vam]\n"
" - create vme slave window: (access vme->GCSR\n"
" [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
" 02 -> A24 Address Space\n"
" 03 -> A32 Address Space\n"
" 04 -> Usr AM Code\n"
" 08 -> Supervisor AM Code\n"
" 10 -> Data AM Code\n"
" 20 -> Program AM Code\n"
" [vdw] = VMEbus Maximum Datawidth: 02 -> D16 Data Width\n"
" 03 -> D32 Data Width\n"
);
|