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
17 typedef struct _UNI_DEV UNI_DEV
;
28 int universe_init(void)
34 busdevfn
= pci_find_device(PCI_VENDOR
, PCI_DEVICE
, 0);
36 puts("No Tundra Universe found!\n");
40 /* Lets turn Latency off */
41 pci_write_config_dword(busdevfn
, 0x0c, 0);
43 dev
= malloc(sizeof(*dev
));
45 puts("UNIVERSE: No memory!\n");
50 memset(dev
, 0, sizeof(*dev
));
51 dev
->busdevfn
= busdevfn
;
53 pci_read_config_dword(busdevfn
, PCI_BASE_ADDRESS_1
, &val
);
55 pci_read_config_dword(busdevfn
, PCI_BASE_ADDRESS_0
, &val
);
58 dev
->uregs
= (UNIVERSE
*)val
;
60 debug ("UNIVERSE-Base : %p\n", dev
->uregs
);
63 debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev
->uregs
->pci_id
));
64 if (((PCI_DEVICE
<<16) | PCI_VENDOR
) != readl(&dev
->uregs
->pci_id
)) {
65 printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
66 readl(&dev
->uregs
->pci_id
));
71 debug ("PCI_BS = %08X\n", readl(&dev
->uregs
->pci_bs
));
73 dev
->pci_bs
= readl(&dev
->uregs
->pci_bs
);
75 /* turn off windows */
76 for (j
=0; j
<4; j
++) {
77 writel(0x00800000, &dev
->uregs
->lsi
[j
].ctl
);
78 writel(0x00800000, &dev
->uregs
->vsi
[j
].ctl
);
82 * Write to Misc Register
83 * Set VME Bus Time-out
87 writel(0x15040000 | (readl(&dev
->uregs
->misc_ctl
) & 0x00020000), &dev
->uregs
->misc_ctl
);
89 if (readl(&dev
->uregs
->misc_ctl
) & 0x00020000) {
90 debug ("System Controller!\n"); /* test-only */
92 debug ("Not System Controller!\n"); /* test-only */
96 * Lets turn off interrupts
98 writel(0x00000000,&dev
->uregs
->lint_en
); /* Disable interrupts in the Universe first */
99 writel(0x0000FFFF,&dev
->uregs
->lint_stat
); /* Clear Any Pending Interrupts */
101 writel(0x0000, &dev
->uregs
->lint_map0
); /* Map all ints to 0 */
102 writel(0x0000, &dev
->uregs
->lint_map1
); /* Map all ints to 0 */
114 * Create pci slave window (access: pci -> vme)
116 int universe_pci_slave_window(unsigned int pciAddr
, unsigned int vmeAddr
, int size
, int vam
, int pms
, int vdw
)
119 unsigned int ctl
= 0;
126 for (i
= 0; i
< 4; i
++) {
127 if (0x00800000 == readl(&dev
->uregs
->lsi
[i
].ctl
))
132 printf ("universe: No Image available\n");
137 debug ("universe: Using image %d\n", i
);
139 writel(pciAddr
, &dev
->uregs
->lsi
[i
].bs
);
140 writel((pciAddr
+ size
), &dev
->uregs
->lsi
[i
].bd
);
141 writel((vmeAddr
- pciAddr
), &dev
->uregs
->lsi
[i
].to
);
143 switch (vam
& VME_AM_Axx
) {
155 switch (vam
& VME_AM_Mxx
) {
164 if (vam
& VME_AM_SUP
) {
169 switch (vdw
& VME_FLAG_Dxx
) {
181 switch (pms
& PCI_MS_Mxx
) {
193 ctl
|= 0x80000000; /* enable */
195 writel(ctl
, &dev
->uregs
->lsi
[i
].ctl
);
197 debug ("universe: window-addr=%p\n", &dev
->uregs
->lsi
[i
].ctl
);
198 debug ("universe: pci slave window[%d] ctl=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].ctl
));
199 debug ("universe: pci slave window[%d] bs=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].bs
));
200 debug ("universe: pci slave window[%d] bd=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].bd
));
201 debug ("universe: pci slave window[%d] to=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].to
));
210 * Create vme slave window (access: vme -> pci)
212 int universe_vme_slave_window(unsigned int vmeAddr
, unsigned int pciAddr
, int size
, int vam
, int pms
)
215 unsigned int ctl
= 0;
222 for (i
= 0; i
< 4; i
++) {
223 if (0x00800000 == readl(&dev
->uregs
->vsi
[i
].ctl
))
228 printf ("universe: No Image available\n");
233 debug ("universe: Using image %d\n", i
);
235 writel(vmeAddr
, &dev
->uregs
->vsi
[i
].bs
);
236 writel((vmeAddr
+ size
), &dev
->uregs
->vsi
[i
].bd
);
237 writel((pciAddr
- vmeAddr
), &dev
->uregs
->vsi
[i
].to
);
239 switch (vam
& VME_AM_Axx
) {
251 switch (vam
& VME_AM_Mxx
) {
260 if (vam
& VME_AM_SUP
) {
265 switch (pms
& PCI_MS_Mxx
) {
277 ctl
|= 0x80f00000; /* enable */
279 writel(ctl
, &dev
->uregs
->vsi
[i
].ctl
);
281 debug ("universe: window-addr=%p\n", &dev
->uregs
->vsi
[i
].ctl
);
282 debug ("universe: vme slave window[%d] ctl=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].ctl
));
283 debug ("universe: vme slave window[%d] bs=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].bs
));
284 debug ("universe: vme slave window[%d] bd=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].bd
));
285 debug ("universe: vme slave window[%d] to=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].to
));
294 * Tundra Universe configuration
296 int do_universe(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
298 ulong addr1
= 0, addr2
= 0, size
= 0, vam
= 0, pms
= 0, vdw
= 0;
305 addr1
= hextoul(argv
[2], NULL
);
307 addr2
= hextoul(argv
[3], NULL
);
309 size
= hextoul(argv
[4], NULL
);
311 vam
= hextoul(argv
[5], NULL
);
313 pms
= hextoul(argv
[6], NULL
);
315 vdw
= hextoul(argv
[7], NULL
);
322 printf("Configuring Universe VME Slave Window (VME->PCI):\n");
323 printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
324 addr1
, addr2
, size
, vam
, pms
);
325 universe_vme_slave_window(addr1
, addr2
, size
, vam
, pms
);
328 printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
329 printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
330 addr1
, addr2
, size
, vam
, pms
, vdw
);
331 universe_pci_slave_window(addr1
, addr2
, size
, vam
, pms
, vdw
);
334 printf("Universe command %s not supported!\n", argv
[1]);
341 universe
, 8, 1, do_universe
,
342 "initialize and configure Turndra Universe",
344 " - initialize universe\n"
345 "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
346 " - create vme slave window (access: vme->pci)\n"
347 "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
348 " - create pci slave window (access: pci->vme)\n"
349 " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
350 " 02 -> A24 Address Space\n"
351 " 03 -> A32 Address Space\n"
352 " 04 -> Supervisor AM Code\n"
353 " 10 -> Data AM Code\n"
354 " 20 -> Program AM Code\n"
355 " [pms] = PCI Memory Space: 01 -> Memory Space\n"
357 " 03 -> Configuration Space\n"
358 " [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
359 " 02 -> D16 Data Width\n"
360 " 03 -> D32 Data Width"