1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
14 #define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
15 #define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
18 typedef struct _UNI_DEV UNI_DEV;
30 int universe_init(void)
36 busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
38 puts("No Tundra Universe found!\n");
42 /* Lets turn Latency off */
43 pci_write_config_dword(busdevfn, 0x0c, 0);
45 dev = malloc(sizeof(*dev));
47 puts("UNIVERSE: No memory!\n");
52 memset(dev, 0, sizeof(*dev));
53 dev->busdevfn = busdevfn;
55 pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val);
57 pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
60 dev->uregs = (UNIVERSE *)val;
62 debug ("UNIVERSE-Base : %p\n", dev->uregs);
65 debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id));
66 if (((PCI_DEVICE <<16) | PCI_VENDOR) != readl(&dev->uregs->pci_id)) {
67 printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
68 readl(&dev->uregs->pci_id));
73 debug ("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs));
75 dev->pci_bs = readl(&dev->uregs->pci_bs);
77 /* turn off windows */
78 for (j=0; j <4; j ++) {
79 writel(0x00800000, &dev->uregs->lsi[j].ctl);
80 writel(0x00800000, &dev->uregs->vsi[j].ctl);
84 * Write to Misc Register
85 * Set VME Bus Time-out
89 writel(0x15040000 | (readl(&dev->uregs->misc_ctl) & 0x00020000), &dev->uregs->misc_ctl);
91 if (readl(&dev->uregs->misc_ctl) & 0x00020000) {
92 debug ("System Controller!\n"); /* test-only */
94 debug ("Not System Controller!\n"); /* test-only */
98 * Lets turn off interrupts
100 writel(0x00000000,&dev->uregs->lint_en); /* Disable interrupts in the Universe first */
101 writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */
103 writel(0x0000, &dev->uregs->lint_map0); /* Map all ints to 0 */
104 writel(0x0000, &dev->uregs->lint_map1); /* Map all ints to 0 */
117 * Create pci slave window (access: pci -> vme)
119 int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw)
122 unsigned int ctl = 0;
129 for (i = 0; i < 4; i++) {
130 if (0x00800000 == readl(&dev->uregs->lsi[i].ctl))
135 printf ("universe: No Image available\n");
140 debug ("universe: Using image %d\n", i);
142 writel(pciAddr , &dev->uregs->lsi[i].bs);
143 writel((pciAddr + size), &dev->uregs->lsi[i].bd);
144 writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to);
146 switch (vam & VME_AM_Axx) {
158 switch (vam & VME_AM_Mxx) {
167 if (vam & VME_AM_SUP) {
172 switch (vdw & VME_FLAG_Dxx) {
184 switch (pms & PCI_MS_Mxx) {
196 ctl |= 0x80000000; /* enable */
198 writel(ctl, &dev->uregs->lsi[i].ctl);
200 debug ("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl);
201 debug ("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl));
202 debug ("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs));
203 debug ("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd));
204 debug ("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to));
214 * Create vme slave window (access: vme -> pci)
216 int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms)
219 unsigned int ctl = 0;
226 for (i = 0; i < 4; i++) {
227 if (0x00800000 == readl(&dev->uregs->vsi[i].ctl))
232 printf ("universe: No Image available\n");
237 debug ("universe: Using image %d\n", i);
239 writel(vmeAddr , &dev->uregs->vsi[i].bs);
240 writel((vmeAddr + size), &dev->uregs->vsi[i].bd);
241 writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to);
243 switch (vam & VME_AM_Axx) {
255 switch (vam & VME_AM_Mxx) {
264 if (vam & VME_AM_SUP) {
269 switch (pms & PCI_MS_Mxx) {
281 ctl |= 0x80f00000; /* enable */
283 writel(ctl, &dev->uregs->vsi[i].ctl);
285 debug ("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl);
286 debug ("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl));
287 debug ("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs));
288 debug ("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd));
289 debug ("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to));
299 * Tundra Universe configuration
301 int do_universe(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
303 ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0;
310 addr1 = simple_strtoul(argv[2], NULL, 16);
312 addr2 = simple_strtoul(argv[3], NULL, 16);
314 size = simple_strtoul(argv[4], NULL, 16);
316 vam = simple_strtoul(argv[5], NULL, 16);
318 pms = simple_strtoul(argv[6], NULL, 16);
320 vdw = simple_strtoul(argv[7], NULL, 16);
327 printf("Configuring Universe VME Slave Window (VME->PCI):\n");
328 printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
329 addr1, addr2, size, vam, pms);
330 universe_vme_slave_window(addr1, addr2, size, vam, pms);
333 printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
334 printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
335 addr1, addr2, size, vam, pms, vdw);
336 universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw);
339 printf("Universe command %s not supported!\n", argv[1]);
347 universe, 8, 1, do_universe,
348 "initialize and configure Turndra Universe",
350 " - initialize universe\n"
351 "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
352 " - create vme slave window (access: vme->pci)\n"
353 "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
354 " - create pci slave window (access: pci->vme)\n"
355 " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
356 " 02 -> A24 Address Space\n"
357 " 03 -> A32 Address Space\n"
358 " 04 -> Supervisor AM Code\n"
359 " 10 -> Data AM Code\n"
360 " 20 -> Program AM Code\n"
361 " [pms] = PCI Memory Space: 01 -> Memory Space\n"
363 " 03 -> Configuration Space\n"
364 " [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
365 " 02 -> D16 Data Width\n"
366 " 03 -> D32 Data Width"