]> git.sur5r.net Git - u-boot/blob - board/sc520_cdp/sc520_cdp.c
nios2: add gpio_request
[u-boot] / board / sc520_cdp / sc520_cdp.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 <asm/io.h>
27 #include <asm/ic/sc520.h>
28 #include <ali512x.h>
29 #include <spi.h>
30 #include <netdev.h>
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 #undef SC520_CDP_DEBUG
35
36 #ifdef  SC520_CDP_DEBUG
37 #define PRINTF(fmt,args...)     printf (fmt ,##args)
38 #else
39 #define PRINTF(fmt,args...)
40 #endif
41
42 /* ------------------------------------------------------------------------- */
43
44
45 /*
46  * Theory:
47  * We first set up all IRQs to be non-pci, edge triggered,
48  * when we later enumerate the pci bus and pci_sc520_fixup_irq() gets
49  * called we reallocate irqs to the pci bus with sc520_pci_set_irq()
50  * as needed. Whe choose the irqs to gram from a configurable list
51  * inside pci_sc520_fixup_irq() (If this list contains stupid irq's
52  * such as 0 thngas will not work)
53  */
54
55 static void irq_init(void)
56 {
57         /* disable global interrupt mode */
58         sc520_mmcr->picicr = 0x40;
59
60         /* set all irqs to edge */
61         sc520_mmcr->pic_mode[0] = 0x00;
62         sc520_mmcr->pic_mode[1] = 0x00;
63         sc520_mmcr->pic_mode[2] = 0x00;
64
65         /* active low polarity on PIC interrupt pins,
66          *  active high polarity on all other irq pins */
67         sc520_mmcr->intpinpol = 0x0000;
68
69         /* set irq number mapping */
70         sc520_mmcr->gp_tmr_int_map[0] = SC520_IRQ_DISABLED;     /* disable GP timer 0 INT */
71         sc520_mmcr->gp_tmr_int_map[1] = SC520_IRQ_DISABLED;     /* disable GP timer 1 INT */
72         sc520_mmcr->gp_tmr_int_map[2] = SC520_IRQ_DISABLED;     /* disable GP timer 2 INT */
73         sc520_mmcr->pit_int_map[0] = SC520_IRQ0;                /* Set PIT timer 0 INT to IRQ0 */
74         sc520_mmcr->pit_int_map[1] = SC520_IRQ_DISABLED;        /* disable PIT timer 1 INT */
75         sc520_mmcr->pit_int_map[2] = SC520_IRQ_DISABLED;        /* disable PIT timer 2 INT */
76         sc520_mmcr->pci_int_map[0] = SC520_IRQ_DISABLED;        /* disable PCI INT A */
77         sc520_mmcr->pci_int_map[1] = SC520_IRQ_DISABLED;        /* disable PCI INT B */
78         sc520_mmcr->pci_int_map[2] = SC520_IRQ_DISABLED;        /* disable PCI INT C */
79         sc520_mmcr->pci_int_map[3] = SC520_IRQ_DISABLED;        /* disable PCI INT D */
80         sc520_mmcr->dmabcintmap = SC520_IRQ_DISABLED;           /* disable DMA INT */
81         sc520_mmcr->ssimap = SC520_IRQ_DISABLED;                /* disable Synchronius serial INT */
82         sc520_mmcr->wdtmap = SC520_IRQ_DISABLED;                /* disable Watchdog INT */
83         sc520_mmcr->rtcmap = SC520_IRQ8;                        /* Set RTC int to 8 */
84         sc520_mmcr->wpvmap = SC520_IRQ_DISABLED;                /* disable write protect INT */
85         sc520_mmcr->icemap = SC520_IRQ1;                        /* Set ICE Debug Serielport INT to IRQ1 */
86         sc520_mmcr->ferrmap = SC520_IRQ13;                      /* Set FP error INT to IRQ13 */
87
88         if (CONFIG_SYS_USE_SIO_UART) {
89                 sc520_mmcr->uart_int_map[0] = SC520_IRQ_DISABLED;       /* disable internal UART1 INT */
90                 sc520_mmcr->uart_int_map[1] = SC520_IRQ_DISABLED;       /* disable internal UART2 INT */
91                 sc520_mmcr->gp_int_map[3] = SC520_IRQ3;         /* Set GPIRQ3 (ISA IRQ3) to IRQ3 */
92                 sc520_mmcr->gp_int_map[4] = SC520_IRQ4;         /* Set GPIRQ4 (ISA IRQ4) to IRQ4 */
93         } else {
94                 sc520_mmcr->uart_int_map[0] = SC520_IRQ4;               /* Set internal UART2 INT to IRQ4 */
95                 sc520_mmcr->uart_int_map[1] = SC520_IRQ3;               /* Set internal UART2 INT to IRQ3 */
96                 sc520_mmcr->gp_int_map[3] = SC520_IRQ_DISABLED; /* disable GPIRQ3 (ISA IRQ3) */
97                 sc520_mmcr->gp_int_map[4] = SC520_IRQ_DISABLED; /* disable GPIRQ4 (ISA IRQ4) */
98         }
99
100         sc520_mmcr->gp_int_map[1] = SC520_IRQ1;                 /* Set GPIRQ1 (SIO IRQ1) to IRQ1 */
101         sc520_mmcr->gp_int_map[5] = SC520_IRQ5;                 /* Set GPIRQ5 (ISA IRQ5) to IRQ5 */
102         sc520_mmcr->gp_int_map[6] = SC520_IRQ6;                 /* Set GPIRQ6 (ISA IRQ6) to IRQ6 */
103         sc520_mmcr->gp_int_map[7] = SC520_IRQ7;                 /* Set GPIRQ7 (ISA IRQ7) to IRQ7 */
104         sc520_mmcr->gp_int_map[8] = SC520_IRQ8;                 /* Set GPIRQ8 (SIO IRQ8) to IRQ8 */
105         sc520_mmcr->gp_int_map[9] = SC520_IRQ9;                 /* Set GPIRQ9 (ISA IRQ2) to IRQ9 */
106         sc520_mmcr->gp_int_map[0] = SC520_IRQ11;                /* Set GPIRQ0 (ISA IRQ11) to IRQ10 */
107         sc520_mmcr->gp_int_map[2] = SC520_IRQ12;                /* Set GPIRQ2 (ISA IRQ12) to IRQ12 */
108         sc520_mmcr->gp_int_map[10] = SC520_IRQ14;               /* Set GPIRQ10 (ISA IRQ14) to IRQ14 */
109
110         sc520_mmcr->pcihostmap = 0x11f;                         /* Map PCI hostbridge INT to NMI */
111         sc520_mmcr->eccmap = 0x100;                             /* Map SDRAM ECC failure INT to NMI */
112 }
113
114 static void silence_uart(int port)
115 {
116         outb(0, port+1);
117 }
118
119 void setup_ali_sio(int uart_primary)
120 {
121         ali512x_init();
122
123         ali512x_set_fdc(ALI_ENABLED, 0x3f2, 6, 0);
124         ali512x_set_pp(ALI_ENABLED, 0x278, 7, 3);
125         ali512x_set_uart(ALI_ENABLED, ALI_UART1, uart_primary?0x3f8:0x3e8, 4);
126         ali512x_set_uart(ALI_ENABLED, ALI_UART2, uart_primary?0x2f8:0x2e8, 3);
127         ali512x_set_rtc(ALI_DISABLED, 0, 0);
128         ali512x_set_kbc(ALI_ENABLED, 1, 12);
129         ali512x_set_cio(ALI_ENABLED);
130
131         /* IrDa pins */
132         ali512x_cio_function(12, 1, 0, 0);
133         ali512x_cio_function(13, 1, 0, 0);
134
135         /* SSI chip select pins */
136         ali512x_cio_function(14, 0, 0, 0);  /* SSI_CS */
137         ali512x_cio_function(15, 0, 0, 0);  /* SSI_MV */
138         ali512x_cio_function(16, 0, 0, 0);  /* SSI_SPI# */
139
140         /* Board REV pins */
141         ali512x_cio_function(20, 0, 0, 1);
142         ali512x_cio_function(21, 0, 0, 1);
143         ali512x_cio_function(22, 0, 0, 1);
144         ali512x_cio_function(23, 0, 0, 1);
145 }
146
147
148 /* set up the ISA bus timing and system address mappings */
149 static void bus_init(void)
150 {
151
152         /* set up the GP IO pins */
153         sc520_mmcr->piopfs31_16 = 0xf7ff;       /* set the GPIO pin function 31-16 reg */
154         sc520_mmcr->piopfs15_0 = 0xffff;        /* set the GPIO pin function 15-0 reg */
155         sc520_mmcr->cspfs = 0xf8;               /* set the CS pin function  reg */
156         sc520_mmcr->clksel = 0x70;
157
158         sc520_mmcr->gpcsrt = 1;                 /* set the GP CS offset */
159         sc520_mmcr->gpcspw = 3;                 /* set the GP CS pulse width */
160         sc520_mmcr->gpcsoff = 1;                /* set the GP CS offset */
161         sc520_mmcr->gprdw = 3;                  /* set the RD pulse width */
162         sc520_mmcr->gprdoff = 1;                /* set the GP RD offset */
163         sc520_mmcr->gpwrw = 3;                   /* set the GP WR pulse width */
164         sc520_mmcr->gpwroff = 1;                 /* set the GP WR offset */
165
166         sc520_mmcr->bootcsctl = 0x1823;         /* set up timing of BOOTCS */
167         sc520_mmcr->romcs1ctl = 0x1823;         /* set up timing of ROMCS1 */
168         sc520_mmcr->romcs2ctl = 0x1823;         /* set up timing of ROMCS2 */
169
170         /* adjust the memory map:
171          * by default the first 256MB (0x00000000 - 0x0fffffff) is mapped to SDRAM
172          * and 256MB to 1G-128k  (0x1000000 - 0x37ffffff) is mapped to PCI mmio
173          * we need to map 1G-128k - 1G (0x38000000 - 0x3fffffff) to CS1 */
174
175
176         /* SRAM = GPCS3 128k @ d0000-effff*/
177         sc520_mmcr->par[2] = 0x4e00400d;
178
179         /* IDE0 = GPCS6 1f0-1f7 */
180         sc520_mmcr->par[3] = 0x380801f0;
181
182         /* IDE1 = GPCS7 3f6 */
183         sc520_mmcr->par[4] = 0x3c0003f6;
184         /* bootcs */
185         sc520_mmcr->par[12] = 0x8bffe800;
186         /* romcs2 */
187         sc520_mmcr->par[13] = 0xcbfff000;
188         /* romcs1 */
189         sc520_mmcr->par[14] = 0xabfff800;
190         /* 680 LEDS */
191         sc520_mmcr->par[15] = 0x30000640;
192
193         sc520_mmcr->adddecctl = 0;
194
195         asm ("wbinvd\n"); /* Flush cache, req. after setting the unchached attribute ona PAR */
196
197         if (CONFIG_SYS_USE_SIO_UART) {
198                 sc520_mmcr->adddecctl = sc520_mmcr->adddecctl | UART2_DIS | UART1_DIS;
199                 setup_ali_sio(1);
200         } else {
201                 sc520_mmcr->adddecctl = sc520_mmcr->adddecctl & ~(UART2_DIS|UART1_DIS);
202                 setup_ali_sio(0);
203                 silence_uart(0x3e8);
204                 silence_uart(0x2e8);
205         }
206
207 }
208
209 /* GPCS usage
210  * GPCS0       PIO27 (NMI)
211  * GPCS1       ROMCS1
212  * GPCS2       ROMCS2
213  * GPCS3       SRAMCS       PAR2
214  * GPCS4       unused       PAR3
215  * GPCS5       unused       PAR4
216  * GPCS6       IDE
217  * GPCS7       IDE
218  */
219
220
221 /* par usage:
222  * PAR0   legacy_video
223  * PAR1   PCI ROM mapping
224  * PAR2   SRAM
225  * PAR3   IDE
226  * PAR4   IDE
227  * PAR5   legacy_video
228  * PAR6   legacy_video
229  * PAR7   legacy_video
230  * PAR8   legacy_video
231  * PAR9   legacy_video
232  * PAR10  legacy_video
233  * PAR11  ISAROM
234  * PAR12  BOOTCS
235  * PAR13  ROMCS1
236  * PAR14  ROMCS2
237  * PAR15  Port 0x680 LED display
238  */
239
240 /*
241  * Miscelaneous platform dependent initialisations
242  */
243
244 int board_init(void)
245 {
246         init_sc520();
247         bus_init();
248         irq_init();
249
250         /* max drive current on SDRAM */
251         sc520_mmcr->dsctl = 0x0100;
252
253         /* enter debug mode after next reset (only if jumper is also set) */
254         sc520_mmcr->rescfg = 0x08;
255         /* configure the software timer to 33.333MHz */
256         sc520_mmcr->swtmrcfg = 0;
257         gd->bus_clk = 33333000;
258
259         return 0;
260 }
261
262 int dram_init(void)
263 {
264         init_sc520_dram();
265         return 0;
266 }
267
268 void show_boot_progress(int val)
269 {
270         if (val < -32) val = -1;  /* let things compatible */
271         outb(val&0xff, 0x80);
272         outb((val&0xff00)>>8, 0x680);
273 }
274
275
276 int last_stage_init(void)
277 {
278         int minor;
279         int major;
280
281         major = minor = 0;
282         major |= ali512x_cio_in(23)?2:0;
283         major |= ali512x_cio_in(22)?1:0;
284         minor |= ali512x_cio_in(21)?2:0;
285         minor |= ali512x_cio_in(20)?1:0;
286
287         printf("AMD SC520 CDP revision %d.%d\n", major, minor);
288
289         return 0;
290 }
291
292
293 void ssi_chip_select(int dev)
294 {
295
296         /* Spunk board: SPI EEPROM is active-low, MW EEPROM and AUX are active high */
297         switch (dev) {
298         case 1: /* SPI EEPROM */
299                 ali512x_cio_out(16, 0);
300                 break;
301
302         case 2: /* MW EEPROM */
303                 ali512x_cio_out(15, 1);
304                 break;
305
306         case 3: /* AUX */
307                 ali512x_cio_out(14, 1);
308                 break;
309
310         case 0:
311                 ali512x_cio_out(16, 1);
312                 ali512x_cio_out(15, 0);
313                 ali512x_cio_out(14, 0);
314                 break;
315
316         default:
317                 printf("Illegal SSI device requested: %d\n", dev);
318         }
319 }
320
321 void spi_eeprom_probe(int x)
322 {
323 }
324
325 int spi_eeprom_read(int x, int offset, uchar *buffer, int len)
326 {
327        return 0;
328 }
329
330 int spi_eeprom_write(int x, int offset, uchar *buffer, int len)
331 {
332        return 0;
333 }
334
335 void spi_init_f(void)
336 {
337 #ifdef CONFIG_SYS_SC520_CDP_USE_SPI
338         spi_eeprom_probe(1);
339 #endif
340 #ifdef CONFIG_SYS_SC520_CDP_USE_MW
341         mw_eeprom_probe(2);
342 #endif
343 }
344
345 ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
346 {
347         int offset;
348         int i;
349         ssize_t res;
350
351         offset = 0;
352         for (i=0;i<alen;i++) {
353                 offset <<= 8;
354                 offset |= addr[i];
355         }
356
357 #ifdef CONFIG_SYS_SC520_CDP_USE_SPI
358         res = spi_eeprom_read(1, offset, buffer, len);
359 #endif
360 #ifdef CONFIG_SYS_SC520_CDP_USE_MW
361         res = mw_eeprom_read(2, offset, buffer, len);
362 #endif
363 #if !defined(CONFIG_SYS_SC520_CDP_USE_SPI) && !defined(CONFIG_SYS_SC520_CDP_USE_MW)
364         res = 0;
365 #endif
366         return res;
367 }
368
369 ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
370 {
371         int offset;
372         int i;
373         ssize_t res;
374
375         offset = 0;
376         for (i=0;i<alen;i++) {
377                 offset <<= 8;
378                 offset |= addr[i];
379         }
380
381 #ifdef CONFIG_SYS_SC520_CDP_USE_SPI
382         res = spi_eeprom_write(1, offset, buffer, len);
383 #endif
384 #ifdef CONFIG_SYS_SC520_CDP_USE_MW
385         res = mw_eeprom_write(2, offset, buffer, len);
386 #endif
387 #if !defined(CONFIG_SYS_SC520_CDP_USE_SPI) && !defined(CONFIG_SYS_SC520_CDP_USE_MW)
388         res = 0;
389 #endif
390         return res;
391 }
392
393 int board_eth_init(bd_t *bis)
394 {
395         return pci_eth_init(bis);
396 }