2 * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #if (CONFIG_COMMANDS & CFG_CMD_UNIVERSE)
33 #define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
34 #define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
37 typedef struct _UNI_DEV UNI_DEV
;
49 int universe_init(void)
51 int j
, result
, lastError
= 0;
55 busdevfn
= pci_find_device(PCI_VENDOR
, PCI_DEVICE
, 0);
57 puts("No Tundra Universe found!\n");
61 /* Lets turn Latency off */
62 pci_write_config_dword(busdevfn
, 0x0c, 0);
64 dev
= malloc(sizeof(*dev
));
66 puts("UNIVERSE: No memory!\n");
71 memset(dev
, 0, sizeof(*dev
));
72 dev
->busdevfn
= busdevfn
;
74 pci_read_config_dword(busdevfn
, PCI_BASE_ADDRESS_1
, &val
);
76 pci_read_config_dword(busdevfn
, PCI_BASE_ADDRESS_0
, &val
);
79 dev
->uregs
= (UNIVERSE
*)val
;
81 debug ("UNIVERSE-Base : %p\n", dev
->uregs
);
84 debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev
->uregs
->pci_id
));
85 if (((PCI_DEVICE
<<16) | PCI_VENDOR
) != readl(&dev
->uregs
->pci_id
)) {
86 printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
87 readl(&dev
->uregs
->pci_id
));
92 debug ("PCI_BS = %08X\n", readl(&dev
->uregs
->pci_bs
));
94 dev
->pci_bs
= readl(&dev
->uregs
->pci_bs
);
96 /* turn off windows */
97 for (j
=0; j
<4; j
++) {
98 writel(0x00800000, &dev
->uregs
->lsi
[j
].ctl
);
99 writel(0x00800000, &dev
->uregs
->vsi
[j
].ctl
);
103 * Write to Misc Register
104 * Set VME Bus Time-out
108 writel(0x15040000 | (readl(&dev
->uregs
->misc_ctl
) & 0x00020000), &dev
->uregs
->misc_ctl
);
110 if (readl(&dev
->uregs
->misc_ctl
) & 0x00020000) {
111 debug ("System Controller!\n"); /* test-only */
113 debug ("Not System Controller!\n"); /* test-only */
117 * Lets turn off interrupts
119 writel(0x00000000,&dev
->uregs
->lint_en
); /* Disable interrupts in the Universe first */
120 writel(0x0000FFFF,&dev
->uregs
->lint_stat
); /* Clear Any Pending Interrupts */
122 writel(0x0000, &dev
->uregs
->lint_map0
); /* Map all ints to 0 */
123 writel(0x0000, &dev
->uregs
->lint_map1
); /* Map all ints to 0 */
138 * Create pci slave window (access: pci -> vme)
140 int universe_pci_slave_window(unsigned int pciAddr
, unsigned int vmeAddr
, int size
, int vam
, int pms
, int vdw
)
143 unsigned int ctl
= 0;
150 for (i
= 0; i
< 4; i
++) {
151 if (0x00800000 == readl(&dev
->uregs
->lsi
[i
].ctl
))
156 printf ("universe: No Image available\n");
161 debug ("universe: Using image %d\n", i
);
163 writel(pciAddr
, &dev
->uregs
->lsi
[i
].bs
);
164 writel((pciAddr
+ size
), &dev
->uregs
->lsi
[i
].bd
);
165 writel((vmeAddr
- pciAddr
), &dev
->uregs
->lsi
[i
].to
);
167 switch (vam
& VME_AM_Axx
) {
179 switch (vam
& VME_AM_Mxx
) {
188 if (vam
& VME_AM_SUP
) {
193 switch (vdw
& VME_FLAG_Dxx
) {
205 switch (pms
& PCI_MS_Mxx
) {
217 ctl
|= 0x80000000; /* enable */
219 writel(ctl
, &dev
->uregs
->lsi
[i
].ctl
);
221 debug ("universe: window-addr=%p\n", &dev
->uregs
->lsi
[i
].ctl
);
222 debug ("universe: pci slave window[%d] ctl=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].ctl
));
223 debug ("universe: pci slave window[%d] bs=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].bs
));
224 debug ("universe: pci slave window[%d] bd=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].bd
));
225 debug ("universe: pci slave window[%d] to=%08x\n", i
, readl(&dev
->uregs
->lsi
[i
].to
));
235 * Create vme slave window (access: vme -> pci)
237 int universe_vme_slave_window(unsigned int vmeAddr
, unsigned int pciAddr
, int size
, int vam
, int pms
)
240 unsigned int ctl
= 0;
247 for (i
= 0; i
< 4; i
++) {
248 if (0x00800000 == readl(&dev
->uregs
->vsi
[i
].ctl
))
253 printf ("universe: No Image available\n");
258 debug ("universe: Using image %d\n", i
);
260 writel(vmeAddr
, &dev
->uregs
->vsi
[i
].bs
);
261 writel((vmeAddr
+ size
), &dev
->uregs
->vsi
[i
].bd
);
262 writel((pciAddr
- vmeAddr
), &dev
->uregs
->vsi
[i
].to
);
264 switch (vam
& VME_AM_Axx
) {
276 switch (vam
& VME_AM_Mxx
) {
285 if (vam
& VME_AM_SUP
) {
290 switch (pms
& PCI_MS_Mxx
) {
302 ctl
|= 0x80f00000; /* enable */
304 writel(ctl
, &dev
->uregs
->vsi
[i
].ctl
);
306 debug ("universe: window-addr=%p\n", &dev
->uregs
->vsi
[i
].ctl
);
307 debug ("universe: vme slave window[%d] ctl=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].ctl
));
308 debug ("universe: vme slave window[%d] bs=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].bs
));
309 debug ("universe: vme slave window[%d] bd=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].bd
));
310 debug ("universe: vme slave window[%d] to=%08x\n", i
, readl(&dev
->uregs
->vsi
[i
].to
));
320 * Tundra Universe configuration
322 int do_universe(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
324 ulong addr1
= 0, addr2
= 0, size
= 0, vam
= 0, pms
= 0, vdw
= 0;
331 addr1
= simple_strtoul(argv
[2], NULL
, 16);
333 addr2
= simple_strtoul(argv
[3], NULL
, 16);
335 size
= simple_strtoul(argv
[4], NULL
, 16);
337 vam
= simple_strtoul(argv
[5], NULL
, 16);
339 pms
= simple_strtoul(argv
[6], NULL
, 16);
341 vdw
= simple_strtoul(argv
[7], NULL
, 16);
348 printf("Configuring Universe VME Slave Window (VME->PCI):\n");
349 printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
350 addr1
, addr2
, size
, vam
, pms
);
351 universe_vme_slave_window(addr1
, addr2
, size
, vam
, pms
);
354 printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
355 printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
356 addr1
, addr2
, size
, vam
, pms
, vdw
);
357 universe_pci_slave_window(addr1
, addr2
, size
, vam
, pms
, vdw
);
360 printf("Universe command %s not supported!\n", argv
[1]);
368 universe
, 8, 1, do_universe
,
369 "universe- initialize and configure Turndra Universe\n",
371 " - initialize universe\n"
372 "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
373 " - create vme slave window (access: vme->pci)\n"
374 "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
375 " - create pci slave window (access: pci->vme)\n"
376 " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
377 " 02 -> A24 Address Space\n"
378 " 03 -> A32 Address Space\n"
379 " 04 -> Supervisor AM Code\n"
380 " 10 -> Data AM Code\n"
381 " 20 -> Program AM Code\n"
382 " [pms] = PCI Memory Space: 01 -> Memory Space\n"
384 " 03 -> Configuration Space\n"
385 " [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
386 " 02 -> D16 Data Width\n"
387 " 03 -> D32 Data Width\n"
390 #endif /* (CONFIG_COMMANDS & CFG_CMD_UNIVERSE) */