1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
22e192b24SSimon Glass /*
32e192b24SSimon Glass * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
42e192b24SSimon Glass */
52e192b24SSimon Glass
62e192b24SSimon Glass #include <common.h>
72e192b24SSimon Glass #include <command.h>
82e192b24SSimon Glass #include <malloc.h>
92e192b24SSimon Glass #include <asm/io.h>
102e192b24SSimon Glass #include <pci.h>
112e192b24SSimon Glass
122e192b24SSimon Glass #include <universe.h>
132e192b24SSimon Glass
142e192b24SSimon Glass #define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
152e192b24SSimon Glass #define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
162e192b24SSimon Glass
172e192b24SSimon Glass
182e192b24SSimon Glass typedef struct _UNI_DEV UNI_DEV;
192e192b24SSimon Glass
202e192b24SSimon Glass struct _UNI_DEV {
212e192b24SSimon Glass int bus;
222e192b24SSimon Glass pci_dev_t busdevfn;
232e192b24SSimon Glass UNIVERSE *uregs;
242e192b24SSimon Glass unsigned int pci_bs;
252e192b24SSimon Glass };
262e192b24SSimon Glass
272e192b24SSimon Glass static UNI_DEV *dev;
282e192b24SSimon Glass
292e192b24SSimon Glass
universe_init(void)302e192b24SSimon Glass int universe_init(void)
312e192b24SSimon Glass {
322e192b24SSimon Glass int j, result;
332e192b24SSimon Glass pci_dev_t busdevfn;
342e192b24SSimon Glass unsigned int val;
352e192b24SSimon Glass
362e192b24SSimon Glass busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
372e192b24SSimon Glass if (busdevfn == -1) {
382e192b24SSimon Glass puts("No Tundra Universe found!\n");
392e192b24SSimon Glass return -1;
402e192b24SSimon Glass }
412e192b24SSimon Glass
422e192b24SSimon Glass /* Lets turn Latency off */
432e192b24SSimon Glass pci_write_config_dword(busdevfn, 0x0c, 0);
442e192b24SSimon Glass
452e192b24SSimon Glass dev = malloc(sizeof(*dev));
462e192b24SSimon Glass if (NULL == dev) {
472e192b24SSimon Glass puts("UNIVERSE: No memory!\n");
482e192b24SSimon Glass result = -1;
492e192b24SSimon Glass goto break_20;
502e192b24SSimon Glass }
512e192b24SSimon Glass
522e192b24SSimon Glass memset(dev, 0, sizeof(*dev));
532e192b24SSimon Glass dev->busdevfn = busdevfn;
542e192b24SSimon Glass
552e192b24SSimon Glass pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val);
562e192b24SSimon Glass if (val & 1) {
572e192b24SSimon Glass pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
582e192b24SSimon Glass }
592e192b24SSimon Glass val &= ~0xf;
602e192b24SSimon Glass dev->uregs = (UNIVERSE *)val;
612e192b24SSimon Glass
622e192b24SSimon Glass debug ("UNIVERSE-Base : %p\n", dev->uregs);
632e192b24SSimon Glass
642e192b24SSimon Glass /* check mapping */
652e192b24SSimon Glass debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id));
662e192b24SSimon Glass if (((PCI_DEVICE <<16) | PCI_VENDOR) != readl(&dev->uregs->pci_id)) {
672e192b24SSimon Glass printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
682e192b24SSimon Glass readl(&dev->uregs->pci_id));
692e192b24SSimon Glass result = -1;
702e192b24SSimon Glass goto break_30;
712e192b24SSimon Glass }
722e192b24SSimon Glass
732e192b24SSimon Glass debug ("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs));
742e192b24SSimon Glass
752e192b24SSimon Glass dev->pci_bs = readl(&dev->uregs->pci_bs);
762e192b24SSimon Glass
772e192b24SSimon Glass /* turn off windows */
782e192b24SSimon Glass for (j=0; j <4; j ++) {
792e192b24SSimon Glass writel(0x00800000, &dev->uregs->lsi[j].ctl);
802e192b24SSimon Glass writel(0x00800000, &dev->uregs->vsi[j].ctl);
812e192b24SSimon Glass }
822e192b24SSimon Glass
832e192b24SSimon Glass /*
842e192b24SSimon Glass * Write to Misc Register
852e192b24SSimon Glass * Set VME Bus Time-out
862e192b24SSimon Glass * Arbitration Mode
872e192b24SSimon Glass * DTACK Enable
882e192b24SSimon Glass */
892e192b24SSimon Glass writel(0x15040000 | (readl(&dev->uregs->misc_ctl) & 0x00020000), &dev->uregs->misc_ctl);
902e192b24SSimon Glass
912e192b24SSimon Glass if (readl(&dev->uregs->misc_ctl) & 0x00020000) {
922e192b24SSimon Glass debug ("System Controller!\n"); /* test-only */
932e192b24SSimon Glass } else {
942e192b24SSimon Glass debug ("Not System Controller!\n"); /* test-only */
952e192b24SSimon Glass }
962e192b24SSimon Glass
972e192b24SSimon Glass /*
982e192b24SSimon Glass * Lets turn off interrupts
992e192b24SSimon Glass */
1002e192b24SSimon Glass writel(0x00000000,&dev->uregs->lint_en); /* Disable interrupts in the Universe first */
1012e192b24SSimon Glass writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */
1022e192b24SSimon Glass eieio();
1032e192b24SSimon Glass writel(0x0000, &dev->uregs->lint_map0); /* Map all ints to 0 */
1042e192b24SSimon Glass writel(0x0000, &dev->uregs->lint_map1); /* Map all ints to 0 */
1052e192b24SSimon Glass eieio();
1062e192b24SSimon Glass
1072e192b24SSimon Glass return 0;
1082e192b24SSimon Glass
1092e192b24SSimon Glass break_30:
1102e192b24SSimon Glass free(dev);
1112e192b24SSimon Glass break_20:
1122e192b24SSimon Glass return result;
1132e192b24SSimon Glass }
1142e192b24SSimon Glass
1152e192b24SSimon Glass
1162e192b24SSimon Glass /*
1172e192b24SSimon Glass * Create pci slave window (access: pci -> vme)
1182e192b24SSimon Glass */
universe_pci_slave_window(unsigned int pciAddr,unsigned int vmeAddr,int size,int vam,int pms,int vdw)1192e192b24SSimon Glass int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw)
1202e192b24SSimon Glass {
1212e192b24SSimon Glass int result, i;
1222e192b24SSimon Glass unsigned int ctl = 0;
1232e192b24SSimon Glass
1242e192b24SSimon Glass if (NULL == dev) {
1252e192b24SSimon Glass result = -1;
1262e192b24SSimon Glass goto exit_10;
1272e192b24SSimon Glass }
1282e192b24SSimon Glass
1292e192b24SSimon Glass for (i = 0; i < 4; i++) {
1302e192b24SSimon Glass if (0x00800000 == readl(&dev->uregs->lsi[i].ctl))
1312e192b24SSimon Glass break;
1322e192b24SSimon Glass }
1332e192b24SSimon Glass
1342e192b24SSimon Glass if (i == 4) {
1352e192b24SSimon Glass printf ("universe: No Image available\n");
1362e192b24SSimon Glass result = -1;
1372e192b24SSimon Glass goto exit_10;
1382e192b24SSimon Glass }
1392e192b24SSimon Glass
1402e192b24SSimon Glass debug ("universe: Using image %d\n", i);
1412e192b24SSimon Glass
1422e192b24SSimon Glass writel(pciAddr , &dev->uregs->lsi[i].bs);
1432e192b24SSimon Glass writel((pciAddr + size), &dev->uregs->lsi[i].bd);
1442e192b24SSimon Glass writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to);
1452e192b24SSimon Glass
1462e192b24SSimon Glass switch (vam & VME_AM_Axx) {
1472e192b24SSimon Glass case VME_AM_A16:
1482e192b24SSimon Glass ctl = 0x00000000;
1492e192b24SSimon Glass break;
1502e192b24SSimon Glass case VME_AM_A24:
1512e192b24SSimon Glass ctl = 0x00010000;
1522e192b24SSimon Glass break;
1532e192b24SSimon Glass case VME_AM_A32:
1542e192b24SSimon Glass ctl = 0x00020000;
1552e192b24SSimon Glass break;
1562e192b24SSimon Glass }
1572e192b24SSimon Glass
1582e192b24SSimon Glass switch (vam & VME_AM_Mxx) {
1592e192b24SSimon Glass case VME_AM_DATA:
1602e192b24SSimon Glass ctl |= 0x00000000;
1612e192b24SSimon Glass break;
1622e192b24SSimon Glass case VME_AM_PROG:
1632e192b24SSimon Glass ctl |= 0x00008000;
1642e192b24SSimon Glass break;
1652e192b24SSimon Glass }
1662e192b24SSimon Glass
1672e192b24SSimon Glass if (vam & VME_AM_SUP) {
1682e192b24SSimon Glass ctl |= 0x00001000;
1692e192b24SSimon Glass
1702e192b24SSimon Glass }
1712e192b24SSimon Glass
1722e192b24SSimon Glass switch (vdw & VME_FLAG_Dxx) {
1732e192b24SSimon Glass case VME_FLAG_D8:
1742e192b24SSimon Glass ctl |= 0x00000000;
1752e192b24SSimon Glass break;
1762e192b24SSimon Glass case VME_FLAG_D16:
1772e192b24SSimon Glass ctl |= 0x00400000;
1782e192b24SSimon Glass break;
1792e192b24SSimon Glass case VME_FLAG_D32:
1802e192b24SSimon Glass ctl |= 0x00800000;
1812e192b24SSimon Glass break;
1822e192b24SSimon Glass }
1832e192b24SSimon Glass
1842e192b24SSimon Glass switch (pms & PCI_MS_Mxx) {
1852e192b24SSimon Glass case PCI_MS_MEM:
1862e192b24SSimon Glass ctl |= 0x00000000;
1872e192b24SSimon Glass break;
1882e192b24SSimon Glass case PCI_MS_IO:
1892e192b24SSimon Glass ctl |= 0x00000001;
1902e192b24SSimon Glass break;
1912e192b24SSimon Glass case PCI_MS_CONFIG:
1922e192b24SSimon Glass ctl |= 0x00000002;
1932e192b24SSimon Glass break;
1942e192b24SSimon Glass }
1952e192b24SSimon Glass
1962e192b24SSimon Glass ctl |= 0x80000000; /* enable */
1972e192b24SSimon Glass
1982e192b24SSimon Glass writel(ctl, &dev->uregs->lsi[i].ctl);
1992e192b24SSimon Glass
2002e192b24SSimon Glass debug ("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl);
2012e192b24SSimon Glass debug ("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl));
2022e192b24SSimon Glass debug ("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs));
2032e192b24SSimon Glass debug ("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd));
2042e192b24SSimon Glass debug ("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to));
2052e192b24SSimon Glass
2062e192b24SSimon Glass return 0;
2072e192b24SSimon Glass
2082e192b24SSimon Glass exit_10:
2092e192b24SSimon Glass return -result;
2102e192b24SSimon Glass }
2112e192b24SSimon Glass
2122e192b24SSimon Glass
2132e192b24SSimon Glass /*
2142e192b24SSimon Glass * Create vme slave window (access: vme -> pci)
2152e192b24SSimon Glass */
universe_vme_slave_window(unsigned int vmeAddr,unsigned int pciAddr,int size,int vam,int pms)2162e192b24SSimon Glass int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms)
2172e192b24SSimon Glass {
2182e192b24SSimon Glass int result, i;
2192e192b24SSimon Glass unsigned int ctl = 0;
2202e192b24SSimon Glass
2212e192b24SSimon Glass if (NULL == dev) {
2222e192b24SSimon Glass result = -1;
2232e192b24SSimon Glass goto exit_10;
2242e192b24SSimon Glass }
2252e192b24SSimon Glass
2262e192b24SSimon Glass for (i = 0; i < 4; i++) {
2272e192b24SSimon Glass if (0x00800000 == readl(&dev->uregs->vsi[i].ctl))
2282e192b24SSimon Glass break;
2292e192b24SSimon Glass }
2302e192b24SSimon Glass
2312e192b24SSimon Glass if (i == 4) {
2322e192b24SSimon Glass printf ("universe: No Image available\n");
2332e192b24SSimon Glass result = -1;
2342e192b24SSimon Glass goto exit_10;
2352e192b24SSimon Glass }
2362e192b24SSimon Glass
2372e192b24SSimon Glass debug ("universe: Using image %d\n", i);
2382e192b24SSimon Glass
2392e192b24SSimon Glass writel(vmeAddr , &dev->uregs->vsi[i].bs);
2402e192b24SSimon Glass writel((vmeAddr + size), &dev->uregs->vsi[i].bd);
2412e192b24SSimon Glass writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to);
2422e192b24SSimon Glass
2432e192b24SSimon Glass switch (vam & VME_AM_Axx) {
2442e192b24SSimon Glass case VME_AM_A16:
2452e192b24SSimon Glass ctl = 0x00000000;
2462e192b24SSimon Glass break;
2472e192b24SSimon Glass case VME_AM_A24:
2482e192b24SSimon Glass ctl = 0x00010000;
2492e192b24SSimon Glass break;
2502e192b24SSimon Glass case VME_AM_A32:
2512e192b24SSimon Glass ctl = 0x00020000;
2522e192b24SSimon Glass break;
2532e192b24SSimon Glass }
2542e192b24SSimon Glass
2552e192b24SSimon Glass switch (vam & VME_AM_Mxx) {
2562e192b24SSimon Glass case VME_AM_DATA:
2572e192b24SSimon Glass ctl |= 0x00000000;
2582e192b24SSimon Glass break;
2592e192b24SSimon Glass case VME_AM_PROG:
2602e192b24SSimon Glass ctl |= 0x00800000;
2612e192b24SSimon Glass break;
2622e192b24SSimon Glass }
2632e192b24SSimon Glass
2642e192b24SSimon Glass if (vam & VME_AM_SUP) {
2652e192b24SSimon Glass ctl |= 0x00100000;
2662e192b24SSimon Glass
2672e192b24SSimon Glass }
2682e192b24SSimon Glass
2692e192b24SSimon Glass switch (pms & PCI_MS_Mxx) {
2702e192b24SSimon Glass case PCI_MS_MEM:
2712e192b24SSimon Glass ctl |= 0x00000000;
2722e192b24SSimon Glass break;
2732e192b24SSimon Glass case PCI_MS_IO:
2742e192b24SSimon Glass ctl |= 0x00000001;
2752e192b24SSimon Glass break;
2762e192b24SSimon Glass case PCI_MS_CONFIG:
2772e192b24SSimon Glass ctl |= 0x00000002;
2782e192b24SSimon Glass break;
2792e192b24SSimon Glass }
2802e192b24SSimon Glass
2812e192b24SSimon Glass ctl |= 0x80f00000; /* enable */
2822e192b24SSimon Glass
2832e192b24SSimon Glass writel(ctl, &dev->uregs->vsi[i].ctl);
2842e192b24SSimon Glass
2852e192b24SSimon Glass debug ("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl);
2862e192b24SSimon Glass debug ("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl));
2872e192b24SSimon Glass debug ("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs));
2882e192b24SSimon Glass debug ("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd));
2892e192b24SSimon Glass debug ("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to));
2902e192b24SSimon Glass
2912e192b24SSimon Glass return 0;
2922e192b24SSimon Glass
2932e192b24SSimon Glass exit_10:
2942e192b24SSimon Glass return -result;
2952e192b24SSimon Glass }
2962e192b24SSimon Glass
2972e192b24SSimon Glass
2982e192b24SSimon Glass /*
2992e192b24SSimon Glass * Tundra Universe configuration
3002e192b24SSimon Glass */
do_universe(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])3012e192b24SSimon Glass int do_universe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3022e192b24SSimon Glass {
3032e192b24SSimon Glass ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0;
3042e192b24SSimon Glass char cmd = 'x';
3052e192b24SSimon Glass
3062e192b24SSimon Glass /* get parameter */
3072e192b24SSimon Glass if (argc > 1)
3082e192b24SSimon Glass cmd = argv[1][0];
3092e192b24SSimon Glass if (argc > 2)
3102e192b24SSimon Glass addr1 = simple_strtoul(argv[2], NULL, 16);
3112e192b24SSimon Glass if (argc > 3)
3122e192b24SSimon Glass addr2 = simple_strtoul(argv[3], NULL, 16);
3132e192b24SSimon Glass if (argc > 4)
3142e192b24SSimon Glass size = simple_strtoul(argv[4], NULL, 16);
3152e192b24SSimon Glass if (argc > 5)
3162e192b24SSimon Glass vam = simple_strtoul(argv[5], NULL, 16);
3172e192b24SSimon Glass if (argc > 6)
3182e192b24SSimon Glass pms = simple_strtoul(argv[6], NULL, 16);
3192e192b24SSimon Glass if (argc > 7)
3202e192b24SSimon Glass vdw = simple_strtoul(argv[7], NULL, 16);
3212e192b24SSimon Glass
3222e192b24SSimon Glass switch (cmd) {
3232e192b24SSimon Glass case 'i': /* init */
3242e192b24SSimon Glass universe_init();
3252e192b24SSimon Glass break;
3262e192b24SSimon Glass case 'v': /* vme */
3272e192b24SSimon Glass printf("Configuring Universe VME Slave Window (VME->PCI):\n");
3282e192b24SSimon Glass printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
3292e192b24SSimon Glass addr1, addr2, size, vam, pms);
3302e192b24SSimon Glass universe_vme_slave_window(addr1, addr2, size, vam, pms);
3312e192b24SSimon Glass break;
3322e192b24SSimon Glass case 'p': /* pci */
3332e192b24SSimon Glass printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
3342e192b24SSimon Glass printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
3352e192b24SSimon Glass addr1, addr2, size, vam, pms, vdw);
3362e192b24SSimon Glass universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw);
3372e192b24SSimon Glass break;
3382e192b24SSimon Glass default:
3392e192b24SSimon Glass printf("Universe command %s not supported!\n", argv[1]);
3402e192b24SSimon Glass }
3412e192b24SSimon Glass
3422e192b24SSimon Glass return 0;
3432e192b24SSimon Glass }
3442e192b24SSimon Glass
3452e192b24SSimon Glass
3462e192b24SSimon Glass U_BOOT_CMD(
3472e192b24SSimon Glass universe, 8, 1, do_universe,
3482e192b24SSimon Glass "initialize and configure Turndra Universe",
3492e192b24SSimon Glass "init\n"
3502e192b24SSimon Glass " - initialize universe\n"
3512e192b24SSimon Glass "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
3522e192b24SSimon Glass " - create vme slave window (access: vme->pci)\n"
3532e192b24SSimon Glass "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
3542e192b24SSimon Glass " - create pci slave window (access: pci->vme)\n"
3552e192b24SSimon Glass " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
3562e192b24SSimon Glass " 02 -> A24 Address Space\n"
3572e192b24SSimon Glass " 03 -> A32 Address Space\n"
3582e192b24SSimon Glass " 04 -> Supervisor AM Code\n"
3592e192b24SSimon Glass " 10 -> Data AM Code\n"
3602e192b24SSimon Glass " 20 -> Program AM Code\n"
3612e192b24SSimon Glass " [pms] = PCI Memory Space: 01 -> Memory Space\n"
3622e192b24SSimon Glass " 02 -> I/O Space\n"
3632e192b24SSimon Glass " 03 -> Configuration Space\n"
3642e192b24SSimon Glass " [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
3652e192b24SSimon Glass " 02 -> D16 Data Width\n"
3662e192b24SSimon Glass " 03 -> D32 Data Width"
3672e192b24SSimon Glass );
368