]> git.sur5r.net Git - u-boot/blob - board/sc520_spunk/sc520_spunk.c
Merge branch 'master' of git://git.denx.de/u-boot-usb
[u-boot] / board / sc520_spunk / sc520_spunk.c
1 /*
2  *
3  * (C) Copyright 2002
4  * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 #include <common.h>
26 #include <netdev.h>
27 #include <ds1722.h>
28 #include <asm/io.h>
29 #include <asm/ic/sc520.h>
30 #include <asm/ic/ssi.h>
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 /*
35  * Theory:
36  * We first set up all IRQs to be non-pci, edge triggered,
37  * when we later enumerate the pci bus and pci_sc520_fixup_irq() gets
38  * called we reallocate irqs to the pci bus with sc520_pci_set_irq()
39  * as needed. Whe choose the irqs to gram from a configurable list
40  * inside pci_sc520_fixup_irq() (If this list contains stupid irq's
41  * such as 0 thngas will not work)
42  */
43
44 static void irq_init(void)
45 {
46         /* disable global interrupt mode */
47         sc520_mmcr->picicr = 0x40;
48
49         /* set all irqs to edge */
50         sc520_mmcr->pic_mode[0] = 0x00;
51         sc520_mmcr->pic_mode[1] = 0x00;
52         sc520_mmcr->pic_mode[2] = 0x00;
53
54         /* active low polarity on PIC interrupt pins,
55          *  active high polarity on all other irq pins */
56         sc520_mmcr->intpinpol = 0x0000;
57
58         /* set irq number mapping */
59         sc520_mmcr->gp_tmr_int_map[0] = SC520_IRQ_DISABLED;     /* disable GP timer 0 INT */
60         sc520_mmcr->gp_tmr_int_map[1] = SC520_IRQ_DISABLED;     /* disable GP timer 1 INT */
61         sc520_mmcr->gp_tmr_int_map[2] = SC520_IRQ_DISABLED;     /* disable GP timer 2 INT */
62         sc520_mmcr->pit_int_map[0] = SC520_IRQ0;                /* Set PIT timer 0 INT to IRQ0 */
63         sc520_mmcr->pit_int_map[1] = SC520_IRQ_DISABLED;        /* disable PIT timer 1 INT */
64         sc520_mmcr->pit_int_map[2] = SC520_IRQ_DISABLED;        /* disable PIT timer 2 INT */
65         sc520_mmcr->pci_int_map[0] = SC520_IRQ_DISABLED;        /* disable PCI INT A */
66         sc520_mmcr->pci_int_map[1] = SC520_IRQ_DISABLED;        /* disable PCI INT B */
67         sc520_mmcr->pci_int_map[2] = SC520_IRQ_DISABLED;        /* disable PCI INT C */
68         sc520_mmcr->pci_int_map[3] = SC520_IRQ_DISABLED;        /* disable PCI INT D */
69         sc520_mmcr->dmabcintmap = SC520_IRQ_DISABLED;           /* disable DMA INT */
70         sc520_mmcr->ssimap = SC520_IRQ6;                        /* Set Synchronius serial INT to IRQ6*/
71         sc520_mmcr->wdtmap = SC520_IRQ_DISABLED;                /* disable Watchdog INT */
72         sc520_mmcr->rtcmap = SC520_IRQ8;                        /* Set RTC int to 8 */
73         sc520_mmcr->wpvmap = SC520_IRQ_DISABLED;                /* disable write protect INT */
74         sc520_mmcr->icemap = SC520_IRQ1;                        /* Set ICE Debug Serielport INT to IRQ1 */
75         sc520_mmcr->ferrmap = SC520_IRQ13;                      /* Set FP error INT to IRQ13 */
76
77
78         sc520_mmcr->uart_int_map[0] = SC520_IRQ4;               /* Set internal UART1 INT to IRQ4 */
79         sc520_mmcr->uart_int_map[1] = SC520_IRQ3;               /* Set internal UART2 INT to IRQ3 */
80
81         sc520_mmcr->gp_int_map[0] = SC520_IRQ7;                 /* Set GPIRQ0 (PC-Card AUX IRQ) to IRQ7 */
82         sc520_mmcr->gp_int_map[1] = SC520_IRQ14;                /* Set GPIRQ1 (CF IRQ) to IRQ14 */
83         sc520_mmcr->gp_int_map[3] = SC520_IRQ5;                 /* Set GPIRQ3 ( CAN IRQ ) ti IRQ5 */
84         sc520_mmcr->gp_int_map[4] = SC520_IRQ_DISABLED;         /* disbale GIRQ4 ( IRR IRQ ) */
85         sc520_mmcr->gp_int_map[5] = SC520_IRQ_DISABLED;         /* disable GPIRQ5 */
86         sc520_mmcr->gp_int_map[6] = SC520_IRQ_DISABLED;         /* disable GPIRQ6 */
87         sc520_mmcr->gp_int_map[7] = SC520_IRQ_DISABLED;         /* disable GPIRQ7 */
88         sc520_mmcr->gp_int_map[8] = SC520_IRQ_DISABLED;         /* disable GPIRQ8 */
89         sc520_mmcr->gp_int_map[9] = SC520_IRQ_DISABLED;         /* disable GPIRQ9 */
90         sc520_mmcr->gp_int_map[2] = SC520_IRQ_DISABLED;         /* disable GPIRQ2 */
91         sc520_mmcr->gp_int_map[10] = SC520_IRQ_DISABLED;        /* disable GPIRQ10 */
92
93         sc520_mmcr->pcihostmap = 0x11f;                         /* Map PCI hostbridge INT to NMI */
94         sc520_mmcr->eccmap = 0x100;                             /* Map SDRAM ECC failure INT to NMI */
95
96 }
97
98 /* set up the ISA bus timing and system address mappings */
99 static void bus_init(void)
100 {
101         /* versions
102          * 0   Hyglo versions 0.95 and 0.96 (large baords)
103          * ??  Hyglo version 0.97 (small board)
104          * 10  Spunk board
105          */
106         int version = sc520_mmcr->sysinfo;
107
108         if (version) {
109                 /* set up the GP IO pins (for the Spunk board) */
110                 sc520_mmcr->piopfs31_16 = 0xfff0;       /* set the GPIO pin function 31-16 reg */
111                 sc520_mmcr->piopfs15_0 = 0x000f;        /* set the GPIO pin function 15-0 reg */
112                 sc520_mmcr->piodir31_16 = 0x000f;       /* set the GPIO direction 31-16 reg */
113                 sc520_mmcr->piodir15_0 = 0x1ff0;        /* set the GPIO direction 15-0 reg */
114                 sc520_mmcr->cspfs = 0xc0;               /* set the CS pin function reg */
115                 sc520_mmcr->clksel = 0x70;
116
117                 sc520_mmcr->pioclr31_16 = 0x0003;       /* reset SSI chip-selects */
118                 sc520_mmcr->pioset31_16 = 0x000c;
119
120         } else {
121                 /* set up the GP IO pins (for the Hyglo board) */
122                 sc520_mmcr->piopfs31_16 = 0xffc0;       /* set the GPIO pin function 31-16 reg */
123                 sc520_mmcr->piopfs15_0 = 0x1e7f;        /* set the GPIO pin function 15-0 reg */
124                 sc520_mmcr->piodir31_16 = 0x003f;       /* set the GPIO direction 31-16 reg */
125                 sc520_mmcr->piodir15_0 = 0xe180;        /* set the GPIO direction 15-0 reg */
126                 sc520_mmcr->cspfs = 0x00;               /* set the CS pin function reg */
127                 sc520_mmcr->clksel = 0x70;
128
129                 sc520_mmcr->pioclr15_0 = 0x0180;        /* reset SSI chip-selects */
130         }
131
132         sc520_mmcr->gpcsrt = 1;         /* set the GP CS offset */
133         sc520_mmcr->gpcspw = 3;         /* set the GP CS pulse width */
134         sc520_mmcr->gpcsoff = 1;        /* set the GP CS offset */
135         sc520_mmcr->gprdw = 3;          /* set the RD pulse width */
136         sc520_mmcr->gprdoff = 1;        /* set the GP RD offset */
137         sc520_mmcr->gpwrw = 3;          /* set the GP WR pulse width */
138         sc520_mmcr->gpwroff = 1;        /* set the GP WR offset */
139
140         sc520_mmcr->bootcsctl = 0x0407; /* set up timing of BOOTCS */
141
142         /* adjust the memory map:
143          * by default the first 256MB (0x00000000 - 0x0fffffff) is mapped to SDRAM
144          * and 256MB to 1G-128k  (0x1000000 - 0x37ffffff) is mapped to PCI mmio
145          * we need to map 1G-128k - 1G (0x38000000 - 0x3fffffff) to CS1 */
146
147
148         /* bootcs */
149         sc520_mmcr->par[12] = 0x8bffe800;
150
151         /* IDE0 = GPCS6 1f0-1f7 */
152         sc520_mmcr->par[3] = 0x380801f0;
153
154         /* IDE1 = GPCS7 3f6 */
155         sc520_mmcr->par[4] = 0x3c0003f6;
156
157         asm ("wbinvd\n"); /* Flush cache, req. after setting the unchached attribute ona PAR */
158
159         sc520_mmcr->adddecctl = sc520_mmcr->adddecctl & ~(UART2_DIS|UART1_DIS);
160
161 }
162
163
164 /* par usage:
165  * PAR0   (legacy_video)
166  * PAR1   (PCI ROM mapping)
167  * PAR2
168  * PAR3   IDE
169  * PAR4   IDE
170  * PAR5   (legacy_video)
171  * PAR6
172  * PAR7   (legacy_video)
173  * PAR8   (legacy_video)
174  * PAR9   (legacy_video)
175  * PAR10
176  * PAR11  (ISAROM)
177  * PAR12  BOOTCS
178  * PAR13
179  * PAR14
180  * PAR15
181  */
182
183 /*
184  * Miscelaneous platform dependent initialisations
185  */
186
187 int board_init(void)
188 {
189         init_sc520();
190         bus_init();
191         irq_init();
192
193         /* max drive current on SDRAM */
194         sc520_mmcr->dsctl = 0x0100;
195
196         /* enter debug mode after next reset (only if jumper is also set) */
197         sc520_mmcr->rescfg = 0x08;
198         /* configure the software timer to 33.000MHz */
199         sc520_mmcr->swtmrcfg = 1;
200         gd->bus_clk = 33000000;
201
202         return 0;
203 }
204
205 int dram_init(void)
206 {
207         init_sc520_dram();
208         return 0;
209 }
210
211 void show_boot_progress(int val)
212 {
213         int version = sc520_mmcr->sysinfo;
214
215         if (val < -32) val = -1;  /* let things compatible */
216         if (version == 0) {
217                 /* PIO31-PIO16 Data */
218                 sc520_mmcr->piodata31_16 = (sc520_mmcr->piodata31_16 & 0xffc0) | ((val&0x7e)>>1); /* 0x1f8 >> 3 */
219
220                 /* PIO0-PIO15 Data */
221                 sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0x1fff)| ((val&0x7)<<13);
222         } else {
223                 /* newer boards use PIO4-PIO12 */
224                 /* PIO0-PIO15 Data */
225 #if 0
226                 val = (val & 0x007) | ((val & 0x038) << 3) | ((val & 0x1c0) >> 3);
227 #else
228                 val = (val & 0x007) | ((val & 0x07e) << 2);
229 #endif
230                 sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0xe00f) | ((val&0x01ff)<<4);
231         }
232 }
233
234
235 int last_stage_init(void)
236 {
237
238         int version = sc520_mmcr->sysinfo;
239
240         printf("Omicron Ceti SC520 Spunk revision %x\n", version);
241
242 #if 0
243         if (version) {
244                 int x, y;
245
246                 printf("eeprom probe %d\n", spi_eeprom_probe(1));
247
248                 spi_eeprom_read(1, 0, (u8*)&x, 2);
249                 spi_eeprom_read(1, 1, (u8*)&y, 2);
250                 printf("eeprom bytes %04x%04x\n", x, y);
251                 x ^= 0xffff;
252                 y ^= 0xffff;
253                 spi_eeprom_write(1, 0, (u8*)&x, 2);
254                 spi_eeprom_write(1, 1, (u8*)&y, 2);
255
256                 spi_eeprom_read(1, 0, (u8*)&x, 2);
257                 spi_eeprom_read(1, 1, (u8*)&y, 2);
258                 printf("eeprom bytes %04x%04x\n", x, y);
259
260         } else {
261                 int x, y;
262
263                 printf("eeprom probe %d\n", mw_eeprom_probe(1));
264
265                 mw_eeprom_read(1, 0, (u8*)&x, 2);
266                 mw_eeprom_read(1, 1, (u8*)&y, 2);
267                 printf("eeprom bytes %04x%04x\n", x, y);
268
269                 x ^= 0xffff;
270                 y ^= 0xffff;
271                 mw_eeprom_write(1, 0, (u8*)&x, 2);
272                 mw_eeprom_write(1, 1, (u8*)&y, 2);
273
274                 mw_eeprom_read(1, 0, (u8*)&x, 2);
275                 mw_eeprom_read(1, 1, (u8*)&y, 2);
276                 printf("eeprom bytes %04x%04x\n", x, y);
277
278
279         }
280 #endif
281
282         ds1722_probe(2);
283
284         return 0;
285 }
286
287 void ssi_chip_select(int dev)
288 {
289         int version = sc520_mmcr->sysinfo;
290
291         if (version) {
292                 /* Spunk board: EEPROM and CAN are actove-low, TEMP and AUX are active high */
293                 switch (dev) {
294                 case 1: /* EEPROM */
295                         sc520_mmcr->pioclr31_16 = 0x0004;
296                         break;
297
298                 case 2: /* Temp Probe */
299                         sc520_mmcr->pioset31_16 = 0x0002;
300                         break;
301
302                 case 3: /* CAN */
303                         sc520_mmcr->pioclr31_16 = 0x0008;
304                         break;
305
306                 case 4: /* AUX */
307                         sc520_mmcr->pioset31_16 = 0x0001;
308                         break;
309
310                 case 0:
311                         sc520_mmcr->pioclr31_16 = 0x0003;
312                         sc520_mmcr->pioset31_16 = 0x000c;
313                         break;
314
315                 default:
316                         printf("Illegal SSI device requested: %d\n", dev);
317                 }
318         } else {
319
320                 /* Globox board: Both EEPROM and TEMP are active-high */
321
322                 switch (dev) {
323                 case 1: /* EEPROM */
324                         sc520_mmcr->pioset15_0 = 0x0100;
325                         break;
326
327                 case 2: /* Temp Probe */
328                         sc520_mmcr->pioset15_0 = 0x0080;
329                         break;
330
331                 case 0:
332                         sc520_mmcr->pioclr15_0 = 0x0180;
333                         break;
334
335                 default:
336                         printf("Illegal SSI device requested: %d\n", dev);
337                 }
338         }
339 }
340
341 void spi_eeprom_probe(int x)
342 {
343 }
344
345 int spi_eeprom_read(int x, int offset, uchar *buffer, int len)
346 {
347        return 0;
348 }
349
350 int spi_eeprom_write(int x, int offset, uchar *buffer, int len)
351 {
352        return 0;
353 }
354
355 void mw_eeprom_probe(int x)
356 {
357 }
358
359 int mw_eeprom_read(int x, int offset, uchar *buffer, int len)
360 {
361        return 0;
362 }
363
364 int mw_eeprom_write(int x, int offset, uchar *buffer, int len)
365 {
366        return 0;
367 }
368
369 void spi_init_f(void)
370 {
371         sc520_mmcr->sysinfo ? spi_eeprom_probe(1) : mw_eeprom_probe(1);
372
373 }
374
375 ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
376 {
377         int offset;
378         int i;
379
380         offset = 0;
381         for (i=0;i<alen;i++) {
382                 offset <<= 8;
383                 offset |= addr[i];
384         }
385
386         return  sc520_mmcr->sysinfo ?
387                 spi_eeprom_read(1, offset, buffer, len) :
388         mw_eeprom_read(1, offset, buffer, len);
389 }
390
391 ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
392 {
393         int offset;
394         int i;
395
396         offset = 0;
397         for (i=0;i<alen;i++) {
398                 offset <<= 8;
399                 offset |= addr[i];
400         }
401
402         return  sc520_mmcr->sysinfo ?
403                 spi_eeprom_write(1, offset, buffer, len) :
404         mw_eeprom_write(1, offset, buffer, len);
405 }
406
407 int board_eth_init(bd_t *bis)
408 {
409         return pci_eth_init(bis);
410 }