2 * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
4 * SPDX-License-Identifier: GPL-2.0+
15 #define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
16 #define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
19 typedef struct _UNI_DEV UNI_DEV;
31 int universe_init(void)
37 busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
39 puts("No Tundra Universe found!\n");
43 /* Lets turn Latency off */
44 pci_write_config_dword(busdevfn, 0x0c, 0);
46 dev = malloc(sizeof(*dev));
48 puts("UNIVERSE: No memory!\n");
53 memset(dev, 0, sizeof(*dev));
54 dev->busdevfn = busdevfn;
56 pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val);
58 pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
61 dev->uregs = (UNIVERSE *)val;
63 debug ("UNIVERSE-Base : %p\n", dev->uregs);
66 debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id));
67 if (((PCI_DEVICE <<16) | PCI_VENDOR) != readl(&dev->uregs->pci_id)) {
68 printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
69 readl(&dev->uregs->pci_id));
74 debug ("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs));
76 dev->pci_bs = readl(&dev->uregs->pci_bs);
78 /* turn off windows */
79 for (j=0; j <4; j ++) {
80 writel(0x00800000, &dev->uregs->lsi[j].ctl);
81 writel(0x00800000, &dev->uregs->vsi[j].ctl);
85 * Write to Misc Register
86 * Set VME Bus Time-out
90 writel(0x15040000 | (readl(&dev->uregs->misc_ctl) & 0x00020000), &dev->uregs->misc_ctl);
92 if (readl(&dev->uregs->misc_ctl) & 0x00020000) {
93 debug ("System Controller!\n"); /* test-only */
95 debug ("Not System Controller!\n"); /* test-only */
99 * Lets turn off interrupts
101 writel(0x00000000,&dev->uregs->lint_en); /* Disable interrupts in the Universe first */
102 writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */
104 writel(0x0000, &dev->uregs->lint_map0); /* Map all ints to 0 */
105 writel(0x0000, &dev->uregs->lint_map1); /* Map all ints to 0 */
118 * Create pci slave window (access: pci -> vme)
120 int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw)
123 unsigned int ctl = 0;
130 for (i = 0; i < 4; i++) {
131 if (0x00800000 == readl(&dev->uregs->lsi[i].ctl))
136 printf ("universe: No Image available\n");
141 debug ("universe: Using image %d\n", i);
143 writel(pciAddr , &dev->uregs->lsi[i].bs);
144 writel((pciAddr + size), &dev->uregs->lsi[i].bd);
145 writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to);
147 switch (vam & VME_AM_Axx) {
159 switch (vam & VME_AM_Mxx) {
168 if (vam & VME_AM_SUP) {
173 switch (vdw & VME_FLAG_Dxx) {
185 switch (pms & PCI_MS_Mxx) {
197 ctl |= 0x80000000; /* enable */
199 writel(ctl, &dev->uregs->lsi[i].ctl);
201 debug ("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl);
202 debug ("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl));
203 debug ("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs));
204 debug ("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd));
205 debug ("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to));
215 * Create vme slave window (access: vme -> pci)
217 int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms)
220 unsigned int ctl = 0;
227 for (i = 0; i < 4; i++) {
228 if (0x00800000 == readl(&dev->uregs->vsi[i].ctl))
233 printf ("universe: No Image available\n");
238 debug ("universe: Using image %d\n", i);
240 writel(vmeAddr , &dev->uregs->vsi[i].bs);
241 writel((vmeAddr + size), &dev->uregs->vsi[i].bd);
242 writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to);
244 switch (vam & VME_AM_Axx) {
256 switch (vam & VME_AM_Mxx) {
265 if (vam & VME_AM_SUP) {
270 switch (pms & PCI_MS_Mxx) {
282 ctl |= 0x80f00000; /* enable */
284 writel(ctl, &dev->uregs->vsi[i].ctl);
286 debug ("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl);
287 debug ("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl));
288 debug ("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs));
289 debug ("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd));
290 debug ("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to));
300 * Tundra Universe configuration
302 int do_universe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
304 ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0;
311 addr1 = simple_strtoul(argv[2], NULL, 16);
313 addr2 = simple_strtoul(argv[3], NULL, 16);
315 size = simple_strtoul(argv[4], NULL, 16);
317 vam = simple_strtoul(argv[5], NULL, 16);
319 pms = simple_strtoul(argv[6], NULL, 16);
321 vdw = simple_strtoul(argv[7], NULL, 16);
328 printf("Configuring Universe VME Slave Window (VME->PCI):\n");
329 printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
330 addr1, addr2, size, vam, pms);
331 universe_vme_slave_window(addr1, addr2, size, vam, pms);
334 printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
335 printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
336 addr1, addr2, size, vam, pms, vdw);
337 universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw);
340 printf("Universe command %s not supported!\n", argv[1]);
348 universe, 8, 1, do_universe,
349 "initialize and configure Turndra Universe",
351 " - initialize universe\n"
352 "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
353 " - create vme slave window (access: vme->pci)\n"
354 "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
355 " - create pci slave window (access: pci->vme)\n"
356 " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
357 " 02 -> A24 Address Space\n"
358 " 03 -> A32 Address Space\n"
359 " 04 -> Supervisor AM Code\n"
360 " 10 -> Data AM Code\n"
361 " 20 -> Program AM Code\n"
362 " [pms] = PCI Memory Space: 01 -> Memory Space\n"
364 " 03 -> Configuration Space\n"
365 " [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
366 " 02 -> D16 Data Width\n"
367 " 03 -> D32 Data Width"