2 * (C) Copyright 2009 Reinhard Arlt, reinhard.arlt@esd-electronics.com
4 * base on universe.h by
6 * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 #define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
36 #define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_TSI148
38 typedef struct _TSI148_DEV TSI148_DEV;
47 static TSI148_DEV *dev;
50 * Most of the TSI148 register are BIGENDIAN
51 * This is the reason for the __raw_writel(htonl(x), x) usage!
60 busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
62 puts("Tsi148: No Tundra Tsi148 found!\n");
66 /* Lets turn Latency off */
67 pci_write_config_dword(busdevfn, 0x0c, 0);
69 dev = malloc(sizeof(*dev));
71 puts("Tsi148: No memory!\n");
75 memset(dev, 0, sizeof(*dev));
76 dev->busdevfn = busdevfn;
78 pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
80 dev->uregs = (TSI148 *)val;
82 debug("Tsi148: Base : %p\n", dev->uregs);
85 debug("Tsi148: Read via mapping, PCI_ID = %08X\n",
86 readl(&dev->uregs->pci_id));
87 if (((PCI_DEVICE << 16) | PCI_VENDOR) != readl(&dev->uregs->pci_id)) {
88 printf("Tsi148: Cannot read PCI-ID via Mapping: %08x\n",
89 readl(&dev->uregs->pci_id));
94 debug("Tsi148: PCI_BS = %08X\n", readl(&dev->uregs->pci_mbarl));
96 dev->pci_bs = readl(&dev->uregs->pci_mbarl);
98 /* turn off windows */
99 for (j = 0; j < 8; j++) {
100 __raw_writel(htonl(0x00000000), &dev->uregs->outbound[j].otat);
101 __raw_writel(htonl(0x00000000), &dev->uregs->inbound[j].itat);
104 /* Tsi148 VME timeout etc */
105 __raw_writel(htonl(0x00000084), &dev->uregs->vctrl);
108 if ((__raw_readl(&dev->uregs->vstat) & 0x00000100) != 0)
109 printf("Tsi148: System Controller!\n");
111 printf("Tsi148: Not System Controller!\n");
115 * Lets turn off interrupts
117 /* Disable interrupts in Tsi148 first */
118 __raw_writel(htonl(0x00000000), &dev->uregs->inten);
119 /* Disable interrupt out */
120 __raw_writel(htonl(0x00000000), &dev->uregs->inteo);
122 /* Reset all IRQ's */
123 __raw_writel(htonl(0x03ff3f00), &dev->uregs->intc);
124 /* Map all ints to 0 */
125 __raw_writel(htonl(0x00000000), &dev->uregs->intm1);
126 __raw_writel(htonl(0x00000000), &dev->uregs->intm2);
129 val = __raw_readl(&dev->uregs->vstat);
130 val &= ~(0x00004000);
131 __raw_writel(val, &dev->uregs->vstat);
134 debug("Tsi148: register struct size %08x\n", sizeof(TSI148));
146 * Create pci slave window (access: pci -> vme)
148 int tsi148_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr,
149 int size, int vam, int vdw)
152 unsigned int ctl = 0;
159 for (i = 0; i < 8; i++) {
160 if (0x00000000 == readl(&dev->uregs->outbound[i].otat))
165 printf("Tsi148: No Image available\n");
170 debug("Tsi148: Using image %d\n", i);
172 printf("Tsi148: Pci addr %08x\n", pciAddr);
174 __raw_writel(htonl(pciAddr), &dev->uregs->outbound[i].otsal);
175 __raw_writel(0x00000000, &dev->uregs->outbound[i].otsau);
176 __raw_writel(htonl(pciAddr + size), &dev->uregs->outbound[i].oteal);
177 __raw_writel(0x00000000, &dev->uregs->outbound[i].oteau);
178 __raw_writel(htonl(vmeAddr - pciAddr), &dev->uregs->outbound[i].otofl);
179 __raw_writel(0x00000000, &dev->uregs->outbound[i].otofu);
181 switch (vam & VME_AM_Axx) {
193 switch (vam & VME_AM_Mxx) {
202 if (vam & VME_AM_SUP)
205 switch (vdw & VME_FLAG_Dxx) {
214 ctl |= 0x80040000; /* enable, no prefetch */
216 __raw_writel(htonl(ctl), &dev->uregs->outbound[i].otat);
218 debug("Tsi148: window-addr =%p\n",
219 &dev->uregs->outbound[i].otsau);
220 debug("Tsi148: pci slave window[%d] attr =%08x\n",
221 i, ntohl(__raw_readl(&dev->uregs->outbound[i].otat)));
222 debug("Tsi148: pci slave window[%d] start =%08x\n",
223 i, ntohl(__raw_readl(&dev->uregs->outbound[i].otsal)));
224 debug("Tsi148: pci slave window[%d] end =%08x\n",
225 i, ntohl(__raw_readl(&dev->uregs->outbound[i].oteal)));
226 debug("Tsi148: pci slave window[%d] offset=%08x\n",
227 i, ntohl(__raw_readl(&dev->uregs->outbound[i].otofl)));
235 unsigned int tsi148_eval_vam(int vam)
237 unsigned int ctl = 0;
239 switch (vam & VME_AM_Axx) {
250 switch (vam & VME_AM_Mxx) {
257 case (VME_AM_PROG | VME_AM_DATA):
262 if (vam & VME_AM_SUP)
264 if (vam & VME_AM_USR)
271 * Create vme slave window (access: vme -> pci)
273 int tsi148_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr,
277 unsigned int ctl = 0;
284 for (i = 0; i < 8; i++) {
285 if (0x00000000 == readl(&dev->uregs->inbound[i].itat))
290 printf("Tsi148: No Image available\n");
295 debug("Tsi148: Using image %d\n", i);
297 __raw_writel(htonl(vmeAddr), &dev->uregs->inbound[i].itsal);
298 __raw_writel(0x00000000, &dev->uregs->inbound[i].itsau);
299 __raw_writel(htonl(vmeAddr + size), &dev->uregs->inbound[i].iteal);
300 __raw_writel(0x00000000, &dev->uregs->inbound[i].iteau);
301 __raw_writel(htonl(pciAddr - vmeAddr), &dev->uregs->inbound[i].itofl);
302 if (vmeAddr > pciAddr)
303 __raw_writel(0xffffffff, &dev->uregs->inbound[i].itofu);
305 __raw_writel(0x00000000, &dev->uregs->inbound[i].itofu);
307 ctl = tsi148_eval_vam(vam);
308 ctl |= 0x80000000; /* enable */
309 __raw_writel(htonl(ctl), &dev->uregs->inbound[i].itat);
311 debug("Tsi148: window-addr =%p\n",
312 &dev->uregs->inbound[i].itsau);
313 debug("Tsi148: vme slave window[%d] attr =%08x\n",
314 i, ntohl(__raw_readl(&dev->uregs->inbound[i].itat)));
315 debug("Tsi148: vme slave window[%d] start =%08x\n",
316 i, ntohl(__raw_readl(&dev->uregs->inbound[i].itsal)));
317 debug("Tsi148: vme slave window[%d] end =%08x\n",
318 i, ntohl(__raw_readl(&dev->uregs->inbound[i].iteal)));
319 debug("Tsi148: vme slave window[%d] offset=%08x\n",
320 i, ntohl(__raw_readl(&dev->uregs->inbound[i].itofl)));
329 * Create vme slave window (access: vme -> gcsr)
331 int tsi148_vme_gcsr_window(unsigned int vmeAddr, int vam)
341 __raw_writel(htonl(vmeAddr), &dev->uregs->gbal);
342 __raw_writel(0x00000000, &dev->uregs->gbau);
344 ctl = tsi148_eval_vam(vam);
345 ctl |= 0x00000080; /* enable */
346 __raw_writel(htonl(ctl), &dev->uregs->gcsrat);
353 * Create vme slave window (access: vme -> crcsr)
355 int tsi148_vme_crcsr_window(unsigned int vmeAddr)
365 __raw_writel(htonl(vmeAddr), &dev->uregs->crol);
366 __raw_writel(0x00000000, &dev->uregs->crou);
368 ctl = 0x00000080; /* enable */
369 __raw_writel(htonl(ctl), &dev->uregs->crat);
376 * Create vme slave window (access: vme -> crg)
378 int tsi148_vme_crg_window(unsigned int vmeAddr, int vam)
388 __raw_writel(htonl(vmeAddr), &dev->uregs->cbal);
389 __raw_writel(0x00000000, &dev->uregs->cbau);
391 ctl = tsi148_eval_vam(vam);
392 ctl |= 0x00000080; /* enable */
393 __raw_writel(htonl(ctl), &dev->uregs->crgat);
400 * Tundra Tsi148 configuration
402 int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
404 ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, vdw = 0;
411 addr1 = simple_strtoul(argv[2], NULL, 16);
413 addr2 = simple_strtoul(argv[3], NULL, 16);
415 size = simple_strtoul(argv[4], NULL, 16);
417 vam = simple_strtoul(argv[5], NULL, 16);
419 vdw = simple_strtoul(argv[6], NULL, 16);
423 if (strcmp(argv[1], "crg") == 0) {
425 printf("Tsi148: Configuring VME CRG Window "
427 printf(" vme=%08lx vam=%02lx\n", addr1, vam);
428 tsi148_vme_crg_window(addr1, vam);
430 printf("Tsi148: Configuring VME CR/CSR Window "
432 printf(" pci=%08lx\n", addr1);
433 tsi148_vme_crcsr_window(addr1);
441 printf("Tsi148: Configuring VME GCSR Window (VME->GCSR):\n");
442 printf(" vme=%08lx vam=%02lx\n", addr1, vam);
443 tsi148_vme_gcsr_window(addr1, vam);
446 printf("Tsi148: Configuring VME Slave Window (VME->PCI):\n");
447 printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx\n",
448 addr1, addr2, size, vam);
449 tsi148_vme_slave_window(addr1, addr2, size, vam);
452 printf("Tsi148: Configuring PCI Slave Window (PCI->VME):\n");
453 printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx vdw=%02lx\n",
454 addr1, addr2, size, vam, vdw);
455 tsi148_pci_slave_window(addr1, addr2, size, vam, vdw);
458 printf("Tsi148: Command %s not supported!\n", argv[1]);
465 tsi148, 7, 1, do_tsi148,
466 "initialize and configure Turndra Tsi148\n",
468 " - initialize tsi148\n"
469 "tsi148 vme [vme_addr] [pci_addr] [size] [vam]\n"
470 " - create vme slave window (access: vme->pci)\n"
471 "tsi148 pci [pci_addr] [vme_addr] [size] [vam] [vdw]\n"
472 " - create pci slave window (access: pci->vme)\n"
473 "tsi148 crg [vme_addr] [vam]\n"
474 " - create vme slave window: (access vme->CRG\n"
475 "tsi148 crcsr [pci_addr]\n"
476 " - create vme slave window: (access vme->CR/CSR\n"
477 "tsi148 gcsr [vme_addr] [vam]\n"
478 " - create vme slave window: (access vme->GCSR\n"
479 " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
480 " 02 -> A24 Address Space\n"
481 " 03 -> A32 Address Space\n"
482 " 04 -> Usr AM Code\n"
483 " 08 -> Supervisor AM Code\n"
484 " 10 -> Data AM Code\n"
485 " 20 -> Program AM Code\n"
486 " [vdw] = VMEbus Maximum Datawidth: 02 -> D16 Data Width\n"
487 " 03 -> D32 Data Width\n"