]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_universe.c
Tundra universe support added
[karo-tx-uboot.git] / common / cmd_universe.c
1 /*
2  * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
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.
11  *
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.
16  *
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,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <command.h>
25 #include <malloc.h>
26 #include <asm/io.h>
27 #include <pci.h>
28
29 #include <universe.h>
30
31
32 #if (CONFIG_COMMANDS & CFG_CMD_UNIVERSE)
33
34 #undef DBG
35
36 #ifdef DBG
37 # define UNI_DBG(fmt)           printf fmt
38 #else
39 # define UNI_DBG(fmt)
40 #endif
41
42 #define UNI_PRINT(fmt)          printf fmt
43
44
45 #define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
46 #define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
47
48
49 typedef struct _UNI_DEV UNI_DEV;
50
51 struct _UNI_DEV {
52         int            bus;
53         pci_dev_t      busdevfn;
54         UNIVERSE       *uregs;
55         unsigned int   pci_bs;
56 };
57
58 static UNI_DEV   *dev;
59
60
61 int universe_init(void)
62 {
63         int j, result, lastError = 0;
64         pci_dev_t busdevfn;
65         unsigned int val;
66
67         busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
68         if (busdevfn == -1) {
69                 puts("No Tundra Universe found!\n");
70                 return -1;
71         }
72
73         /* Lets turn Latency off */
74         pci_write_config_dword(busdevfn, 0x0c, 0);
75
76         dev = malloc(sizeof(*dev));
77         if (NULL == dev) {
78                 puts("UNIVERSE: No memory!\n");
79                 result = -1;
80                 goto break_20;
81         }
82
83         memset(dev, 0, sizeof(*dev));
84         dev->busdevfn = busdevfn;
85
86         pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val);
87         val &= ~0xf;
88         dev->uregs = (UNIVERSE *)val;
89
90         UNI_DBG(("UNIVERSE-Base    : %p\n", dev->uregs));
91
92         /* check mapping  */
93         UNI_DBG((" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id)));
94         if (((PCI_DEVICE <<16) | PCI_VENDOR) !=  readl(&dev->uregs->pci_id)) {
95                 UNI_PRINT(("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
96                            readl(&dev->uregs->pci_id)));
97                 result = -1;
98                 goto break_30;
99         }
100
101         UNI_DBG(("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs)));
102
103         dev->pci_bs = readl(&dev->uregs->pci_bs);
104
105         /* turn off windows */
106         for (j=0; j <4; j ++) {
107                 writel(0x00800000, &dev->uregs->lsi[j].ctl);
108                 writel(0x00800000, &dev->uregs->vsi[j].ctl);
109         }
110
111         /*
112          * Write to Misc Register
113          * Set VME Bus Time-out
114          *   Arbitration Mode
115          *   DTACK Enable
116          */
117         writel(0x15060000, &dev->uregs->misc_ctl);
118
119         /*
120          * Lets turn off interrupts
121          */
122         writel(0x00000000,&dev->uregs->lint_en);   /* Disable interrupts in the Universe first */
123         writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */
124         eieio();
125         writel(0x0000, &dev->uregs->lint_map0);  /* Map all ints to 0 */
126         writel(0x0000, &dev->uregs->lint_map1);  /* Map all ints to 0 */
127         eieio();
128
129  break_30:
130         free(dev);
131  break_20:
132         lastError = result;
133
134         return 0;
135 }
136
137
138 /*
139  * Create pci slave window (access: pci -> vme)
140  */
141 int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw)
142 {
143         int result, i;
144         unsigned int ctl = 0;
145
146         if (NULL == dev) {
147                 result = -1;
148                 goto exit_10;
149         }
150
151         for (i = 0; i < 4; i++) {
152                 if (0x00800000 == readl(&dev->uregs->lsi[i].ctl))
153                         break;
154         }
155
156         if (i == 4) {
157                 UNI_PRINT(("universe: No Image available\n"));
158                 result = -1;
159                 goto exit_10;
160         }
161
162         UNI_DBG(("universe: Using image %d\n", i));
163
164         writel(pciAddr , &dev->uregs->lsi[i].bs);
165         writel((pciAddr + size), &dev->uregs->lsi[i].bd);
166         writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to);
167
168         switch (vam & VME_AM_Axx) {
169         case VME_AM_A16:
170                 ctl = 0x00000000;
171                 break;
172         case VME_AM_A24:
173                 ctl = 0x00010000;
174                 break;
175         case VME_AM_A32:
176                 ctl = 0x00020000;
177                 break;
178         }
179
180         switch (vam & VME_AM_Mxx) {
181         case VME_AM_DATA:
182                 ctl |= 0x00000000;
183                 break;
184         case VME_AM_PROG:
185                 ctl |= 0x00008000;
186                 break;
187         }
188
189         if (vam & VME_AM_SUP) {
190                 ctl |= 0x00001000;
191
192         }
193
194         switch (vdw & VME_FLAG_Dxx) {
195         case VME_FLAG_D8:
196                 ctl |= 0x00000000;
197                 break;
198         case VME_FLAG_D16:
199                 ctl |= 0x00400000;
200                 break;
201         case VME_FLAG_D32:
202                 ctl |= 0x00800000;
203                 break;
204         }
205
206         switch (pms & PCI_MS_Mxx) {
207         case PCI_MS_MEM:
208                 ctl = 0x00000000;
209                 break;
210         case PCI_MS_IO:
211                 ctl = 0x00000001;
212                 break;
213         case PCI_MS_CONFIG:
214                 ctl = 0x00000002;
215                 break;
216         }
217
218         ctl |= 0x80000000;    /* enable */
219
220         writel(ctl, &dev->uregs->lsi[i].ctl);
221
222         UNI_DBG(("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl));
223         UNI_DBG(("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl)));
224         UNI_DBG(("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs)));
225         UNI_DBG(("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd)));
226         UNI_DBG(("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to)));
227
228         return 0;
229
230  exit_10:
231         return -result;
232 }
233
234
235 /*
236  * Create vme slave window (access: vme -> pci)
237  */
238 int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms)
239 {
240         int result, i;
241         unsigned int ctl = 0;
242
243         if (NULL == dev) {
244                 result = -1;
245                 goto exit_10;
246         }
247
248         for (i = 0; i < 4; i++) {
249                 if (0x00800000 == readl(&dev->uregs->vsi[i].ctl))
250                         break;
251         }
252
253         if (i == 4) {
254                 UNI_PRINT(("universe: No Image available\n"));
255                 result = -1;
256                 goto exit_10;
257         }
258
259         UNI_DBG(("universe: Using image %d\n", i));
260
261         writel(vmeAddr , &dev->uregs->vsi[i].bs);
262         writel((vmeAddr + size), &dev->uregs->vsi[i].bd);
263         writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to);
264
265         switch (vam & VME_AM_Axx) {
266         case VME_AM_A16:
267                 ctl = 0x00000000;
268                 break;
269         case VME_AM_A24:
270                 ctl = 0x00010000;
271                 break;
272         case VME_AM_A32:
273                 ctl = 0x00020000;
274                 break;
275         }
276
277         switch (vam & VME_AM_Mxx) {
278         case VME_AM_DATA:
279                 ctl |= 0x00000000;
280                 break;
281         case VME_AM_PROG:
282                 ctl |= 0x00800000;
283                 break;
284         }
285
286         if (vam & VME_AM_SUP) {
287                 ctl |= 0x00100000;
288
289         }
290
291         switch (pms & PCI_MS_Mxx) {
292         case PCI_MS_MEM:
293                 ctl = 0x00000000;
294                 break;
295         case PCI_MS_IO:
296                 ctl = 0x00000001;
297                 break;
298         case PCI_MS_CONFIG:
299                 ctl = 0x00000002;
300                 break;
301         }
302
303         ctl |= 0x80f00000;    /* enable */
304
305         writel(ctl, &dev->uregs->vsi[i].ctl);
306
307         UNI_DBG(("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl));
308         UNI_DBG(("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl)));
309         UNI_DBG(("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs)));
310         UNI_DBG(("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd)));
311         UNI_DBG(("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to)));
312
313         return 0;
314
315  exit_10:
316         return -result;
317 }
318
319
320 /*
321  * Tundra Universe configuration
322  */
323 int do_universe(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
324 {
325         ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0;
326         char cmd = 'x';
327
328         /* get parameter */
329         if (argc > 1)
330                 cmd = argv[1][0];
331         if (argc > 2)
332                 addr1 = simple_strtoul(argv[2], NULL, 16);
333         if (argc > 3)
334                 addr2 = simple_strtoul(argv[3], NULL, 16);
335         if (argc > 4)
336                 size = simple_strtoul(argv[4], NULL, 16);
337         if (argc > 5)
338                 vam = simple_strtoul(argv[5], NULL, 16);
339         if (argc > 6)
340                 pms = simple_strtoul(argv[6], NULL, 16);
341         if (argc > 7)
342                 vdw = simple_strtoul(argv[7], NULL, 16);
343
344         switch (cmd) {
345         case 'i':               /* init */
346                 universe_init();
347                 break;
348         case 'v':               /* vme */
349                 printf("Configuring Universe VME Slave Window (VME->PCI):\n");
350                 printf("  vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
351                        addr1, addr2, size, vam, pms);
352                 universe_vme_slave_window(addr1, addr2, size, vam, pms);
353                 break;
354         case 'p':               /* pci */
355                 printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
356                 printf("  pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
357                        addr1, addr2, size, vam, pms, vdw);
358                 universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw);
359                 break;
360         default:
361                 printf("Universe command %s not supported!\n", argv[1]);
362         }
363
364         return 0;
365 }
366
367
368 U_BOOT_CMD(
369         universe,       8,      1,      do_universe,
370         "universe- initialize and configure Turndra Universe\n",
371         "init\n"
372         "    - initialize universe\n"
373         "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
374         "    - create vme slave window (access: vme->pci)\n"
375         "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
376         "    - create pci slave window (access: pci->vme)\n"
377         "    [vam] = VMEbus Address-Modifier:  01 -> A16 Address Space\n"
378         "                                      02 -> A24 Address Space\n"
379         "                                      03 -> A32 Address Space\n"
380         "                                      04 -> Supervisor AM Code\n"
381         "                                      10 -> Data AM Code\n"
382         "                                      20 -> Program AM Code\n"
383         "    [pms] = PCI Memory Space:         01 -> Memory Space\n"
384         "                                      02 -> I/O Space\n"
385         "                                      03 -> Configuration Space\n"
386         "    [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
387         "                                      02 -> D16 Data Width\n"
388         "                                      03 -> D32 Data Width\n"
389 );
390
391 #endif /* (CONFIG_COMMANDS & CFG_CMD_UNIVERSE) */