blob: e7a7d5188cfdc7fb079de7ce06906a49ce5effaa [file] [log] [blame]
wdenkabda5ca2003-05-31 18:35:21 +00001/*
wdenk57b2d802003-06-27 21:31:46 +00002 *
wdenkabda5ca2003-05-31 18:35:21 +00003 * (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 <pci.h>
27#include <ssi.h>
28#include <asm/io.h>
29#include <asm/pci.h>
30#include <asm/ic/sc520.h>
31
32
33/* ------------------------------------------------------------------------- */
34
wdenk57b2d802003-06-27 21:31:46 +000035
36/*
wdenkabda5ca2003-05-31 18:35:21 +000037 * Theory:
38 * We first set up all IRQs to be non-pci, edge triggered,
wdenk57b2d802003-06-27 21:31:46 +000039 * when we later enumerate the pci bus and pci_sc520_fixup_irq() gets
wdenkabda5ca2003-05-31 18:35:21 +000040 * called we reallocate irqs to the pci bus with sc520_pci_set_irq()
41 * as needed. Whe choose the irqs to gram from a configurable list
42 * inside pci_sc520_fixup_irq() (If this list contains stupid irq's
43 * such as 0 thngas will not work)
44 */
45
46static void irq_init(void)
47{
48 /* disable global interrupt mode */
wdenk57b2d802003-06-27 21:31:46 +000049 write_mmcr_byte(SC520_PICICR, 0x40);
50
wdenkabda5ca2003-05-31 18:35:21 +000051 /* set all irqs to edge */
52 write_mmcr_byte(SC520_MPICMODE, 0x00);
53 write_mmcr_byte(SC520_SL1PICMODE, 0x00);
54 write_mmcr_byte(SC520_SL2PICMODE, 0x00);
wdenk57b2d802003-06-27 21:31:46 +000055
56 /* active low polarity on PIC interrupt pins,
wdenkabda5ca2003-05-31 18:35:21 +000057 * active high polarity on all other irq pins */
58 write_mmcr_word(SC520_INTPINPOL, 0x0000);
59
60 /* set irq number mapping */
wdenk57b2d802003-06-27 21:31:46 +000061 write_mmcr_byte(SC520_GPTMR0MAP, SC520_IRQ_DISABLED); /* disable GP timer 0 INT */
wdenkabda5ca2003-05-31 18:35:21 +000062 write_mmcr_byte(SC520_GPTMR1MAP, SC520_IRQ_DISABLED); /* disable GP timer 1 INT */
63 write_mmcr_byte(SC520_GPTMR2MAP, SC520_IRQ_DISABLED); /* disable GP timer 2 INT */
wdenk57b2d802003-06-27 21:31:46 +000064 write_mmcr_byte(SC520_PIT0MAP, SC520_IRQ0); /* Set PIT timer 0 INT to IRQ0 */
wdenkabda5ca2003-05-31 18:35:21 +000065 write_mmcr_byte(SC520_PIT1MAP, SC520_IRQ_DISABLED); /* disable PIT timer 1 INT */
66 write_mmcr_byte(SC520_PIT2MAP, SC520_IRQ_DISABLED); /* disable PIT timer 2 INT */
67 write_mmcr_byte(SC520_PCIINTAMAP, SC520_IRQ_DISABLED); /* disable PCI INT A */
68 write_mmcr_byte(SC520_PCIINTBMAP, SC520_IRQ_DISABLED); /* disable PCI INT B */
69 write_mmcr_byte(SC520_PCIINTCMAP, SC520_IRQ_DISABLED); /* disable PCI INT C */
70 write_mmcr_byte(SC520_PCIINTDMAP, SC520_IRQ_DISABLED); /* disable PCI INT D */
wdenk57b2d802003-06-27 21:31:46 +000071 write_mmcr_byte(SC520_DMABCINTMAP, SC520_IRQ_DISABLED); /* disable DMA INT */
wdenkabda5ca2003-05-31 18:35:21 +000072 write_mmcr_byte(SC520_SSIMAP, SC520_IRQ6); /* Set Synchronius serial INT to IRQ6*/
73 write_mmcr_byte(SC520_WDTMAP, SC520_IRQ_DISABLED); /* disable Watchdog INT */
74 write_mmcr_byte(SC520_RTCMAP, SC520_IRQ8); /* Set RTC int to 8 */
75 write_mmcr_byte(SC520_WPVMAP, SC520_IRQ_DISABLED); /* disable write protect INT */
76 write_mmcr_byte(SC520_ICEMAP, SC520_IRQ1); /* Set ICE Debug Serielport INT to IRQ1 */
77 write_mmcr_byte(SC520_FERRMAP,SC520_IRQ13); /* Set FP error INT to IRQ13 */
wdenk57b2d802003-06-27 21:31:46 +000078
wdenkabda5ca2003-05-31 18:35:21 +000079 write_mmcr_byte(SC520_UART1MAP, SC520_IRQ4); /* Set internal UART2 INT to IRQ4 */
80 write_mmcr_byte(SC520_UART2MAP, SC520_IRQ3); /* Set internal UART2 INT to IRQ3 */
wdenk57b2d802003-06-27 21:31:46 +000081
wdenkabda5ca2003-05-31 18:35:21 +000082 write_mmcr_byte(SC520_GP0IMAP, SC520_IRQ7); /* Set GPIRQ0 (PC-Card AUX IRQ) to IRQ7 */
83 write_mmcr_byte(SC520_GP1IMAP, SC520_IRQ14); /* Set GPIRQ1 (CF IRQ) to IRQ14 */
wdenk57b2d802003-06-27 21:31:46 +000084 write_mmcr_byte(SC520_GP3IMAP, SC520_IRQ5); /* Set GPIRQ3 ( CAN IRQ ) ti IRQ5 */
wdenkabda5ca2003-05-31 18:35:21 +000085 write_mmcr_byte(SC520_GP4IMAP, SC520_IRQ_DISABLED); /* disbale GIRQ4 ( IRR IRQ ) */
86 write_mmcr_byte(SC520_GP5IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ5 */
87 write_mmcr_byte(SC520_GP6IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ6 */
88 write_mmcr_byte(SC520_GP7IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ7 */
89 write_mmcr_byte(SC520_GP8IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ8 */
90 write_mmcr_byte(SC520_GP9IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ9 */
91 write_mmcr_byte(SC520_GP2IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ2 */
wdenk57b2d802003-06-27 21:31:46 +000092 write_mmcr_byte(SC520_GP10IMAP,SC520_IRQ_DISABLED); /* disable GPIRQ10 */
93
wdenkabda5ca2003-05-31 18:35:21 +000094 write_mmcr_word(SC520_PCIHOSTMAP, 0x11f); /* Map PCI hostbridge INT to NMI */
95 write_mmcr_word(SC520_ECCMAP, 0x100); /* Map SDRAM ECC failure INT to NMI */
wdenk57b2d802003-06-27 21:31:46 +000096
wdenkabda5ca2003-05-31 18:35:21 +000097}
98
wdenk57b2d802003-06-27 21:31:46 +000099
wdenkabda5ca2003-05-31 18:35:21 +0000100/* PCI stuff */
101static void pci_sc520_spunk_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
102{
103 int version = read_mmcr_byte(SC520_SYSINFO);
wdenk57b2d802003-06-27 21:31:46 +0000104
wdenkabda5ca2003-05-31 18:35:21 +0000105 /* a configurable lists of irqs to steal
106 * when we need one (a board with more pci interrupt pins
107 * would use a larger table */
108 static int irq_list[] = {
109 CFG_FIRST_PCI_IRQ,
110 CFG_SECOND_PCI_IRQ,
111 CFG_THIRD_PCI_IRQ,
112 CFG_FORTH_PCI_IRQ
113 };
114 static int next_irq_index=0;
wdenk57b2d802003-06-27 21:31:46 +0000115
116 char tmp_pin;
wdenkabda5ca2003-05-31 18:35:21 +0000117 int pin;
wdenk57b2d802003-06-27 21:31:46 +0000118
wdenkabda5ca2003-05-31 18:35:21 +0000119 pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin);
120 pin = tmp_pin;
wdenk57b2d802003-06-27 21:31:46 +0000121
wdenkabda5ca2003-05-31 18:35:21 +0000122 pin-=1; /* pci config space use 1-based numbering */
123 if (-1 == pin) {
124 return; /* device use no irq */
125 }
wdenk57b2d802003-06-27 21:31:46 +0000126
127
wdenkabda5ca2003-05-31 18:35:21 +0000128 /* map device number + pin to a pin on the sc520 */
129 switch (PCI_DEV(dev)) {
wdenk57b2d802003-06-27 21:31:46 +0000130 case 6: /* ETH0 */
wdenkabda5ca2003-05-31 18:35:21 +0000131 pin+=SC520_PCI_INTA;
132 break;
wdenk57b2d802003-06-27 21:31:46 +0000133
wdenkabda5ca2003-05-31 18:35:21 +0000134 case 7: /* ETH1 */
135 pin+=SC520_PCI_INTB;
136 break;
wdenk57b2d802003-06-27 21:31:46 +0000137
wdenkabda5ca2003-05-31 18:35:21 +0000138 case 8: /* Crypto */
139 pin+=SC520_PCI_INTC;
140 break;
wdenk57b2d802003-06-27 21:31:46 +0000141
wdenkabda5ca2003-05-31 18:35:21 +0000142 case 9: /* PMC slot */
143 pin+=SC520_PCI_INTD;
144 break;
wdenk57b2d802003-06-27 21:31:46 +0000145
wdenkabda5ca2003-05-31 18:35:21 +0000146 case 10: /* PC-Card */
wdenk57b2d802003-06-27 21:31:46 +0000147
148 if (version < 10) {
wdenkabda5ca2003-05-31 18:35:21 +0000149 pin+=SC520_PCI_INTD;
150 } else {
151 pin+=SC520_PCI_INTC;
152 }
153 break;
wdenk57b2d802003-06-27 21:31:46 +0000154
155 default:
wdenkabda5ca2003-05-31 18:35:21 +0000156 return;
157 }
wdenk57b2d802003-06-27 21:31:46 +0000158
wdenkabda5ca2003-05-31 18:35:21 +0000159 pin&=3; /* wrap around */
wdenk57b2d802003-06-27 21:31:46 +0000160
wdenkabda5ca2003-05-31 18:35:21 +0000161 if (sc520_pci_ints[pin] == -1) {
wdenk57b2d802003-06-27 21:31:46 +0000162 /* re-route one interrupt for us */
wdenkabda5ca2003-05-31 18:35:21 +0000163 if (next_irq_index > 3) {
164 return;
165 }
wdenk57b2d802003-06-27 21:31:46 +0000166 if (pci_sc520_set_irq(pin, irq_list[next_irq_index])) {
wdenkabda5ca2003-05-31 18:35:21 +0000167 return;
168 }
169 next_irq_index++;
170 }
171
wdenk57b2d802003-06-27 21:31:46 +0000172
wdenkabda5ca2003-05-31 18:35:21 +0000173 if (-1 != sc520_pci_ints[pin]) {
wdenk57b2d802003-06-27 21:31:46 +0000174 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
wdenkabda5ca2003-05-31 18:35:21 +0000175 sc520_pci_ints[pin]);
176 }
wdenk57b2d802003-06-27 21:31:46 +0000177#if 0
178 printf("fixup_irq: device %d pin %c irq %d\n",
wdenkabda5ca2003-05-31 18:35:21 +0000179 PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]);
180#endif
181}
182
183
wdenk57b2d802003-06-27 21:31:46 +0000184static void pci_sc520_spunk_configure_cardbus(struct pci_controller *hose,
wdenkabda5ca2003-05-31 18:35:21 +0000185 pci_dev_t dev, struct pci_config_table *te)
186{
187 u32 io_base;
188 u32 temp;
wdenk57b2d802003-06-27 21:31:46 +0000189
wdenkabda5ca2003-05-31 18:35:21 +0000190 pciauto_config_device(hose, dev);
wdenk57b2d802003-06-27 21:31:46 +0000191
wdenkabda5ca2003-05-31 18:35:21 +0000192 pci_hose_write_config_word(hose, dev, PCI_COMMAND, 0x07); /* enable device */
193 pci_hose_write_config_byte(hose, dev, 0x0c, 0x10); /* cacheline size */
194 pci_hose_write_config_byte(hose, dev, 0x0d, 0x40); /* latency timer */
195 pci_hose_write_config_byte(hose, dev, 0x1b, 0x40); /* cardbus latency timer */
196 pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0040); /* reset cardbus */
197 pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0080); /* route interrupts though ExCA */
198 pci_hose_write_config_word(hose, dev, 0x44, 0x3e0); /* map legacy I/O port to 0x3e0 */
wdenk57b2d802003-06-27 21:31:46 +0000199
200 pci_hose_read_config_dword(hose, dev, 0x80, &temp); /* System control */
201 pci_hose_write_config_dword(hose, dev, 0x80, temp | 0x60); /* System control: disable clockrun */
202 /* route MF0 to ~INT and MF3 to IRQ7
wdenkabda5ca2003-05-31 18:35:21 +0000203 * reserve all others */
wdenk57b2d802003-06-27 21:31:46 +0000204 pci_hose_write_config_dword(hose, dev, 0x8c, 0x00007002);
wdenkabda5ca2003-05-31 18:35:21 +0000205 pci_hose_write_config_byte(hose, dev, 0x91, 0x00); /* card control */
206 pci_hose_write_config_byte(hose, dev, 0x92, 0x62); /* device control */
wdenk57b2d802003-06-27 21:31:46 +0000207
wdenkabda5ca2003-05-31 18:35:21 +0000208 if (te->device != 0xac56) {
209 pci_hose_write_config_byte(hose, dev, 0x93, 0x21); /* async interrupt enable */
210 pci_hose_write_config_word(hose, dev, 0xa8, 0x0000); /* reset GPIO */
211 pci_hose_write_config_word(hose, dev, 0xac, 0x0000); /* reset GPIO */
212 pci_hose_write_config_word(hose, dev, 0xaa, 0x0000); /* reset GPIO */
213 pci_hose_write_config_word(hose, dev, 0xae, 0x0000); /* reset GPIO */
214 } else {
215 pci_hose_write_config_byte(hose, dev, 0x93, 0x20); /* */
216 }
217 pci_hose_write_config_word(hose, dev, 0xa4, 0x8000); /* reset power management */
wdenk57b2d802003-06-27 21:31:46 +0000218
219
wdenkabda5ca2003-05-31 18:35:21 +0000220 pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &io_base);
221 io_base &= ~0xfL;
wdenk57b2d802003-06-27 21:31:46 +0000222
wdenkabda5ca2003-05-31 18:35:21 +0000223 writeb(0x07, io_base+0x803); /* route CSC irq though ExCA and enable IRQ7 */
224 writel(0, io_base+0x10); /* CLKRUN default */
225 writel(0, io_base+0x20); /* CLKRUN default */
wdenkabda5ca2003-05-31 18:35:21 +0000226
wdenk57b2d802003-06-27 21:31:46 +0000227}
wdenkabda5ca2003-05-31 18:35:21 +0000228
229
230static struct pci_config_table pci_sc520_spunk_config_table[] = {
wdenk57b2d802003-06-27 21:31:46 +0000231 { 0x104c, 0xac50, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
232 { 0x104c, 0xac56, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
wdenkabda5ca2003-05-31 18:35:21 +0000233 { 0, 0, 0, 0, 0, 0, NULL, {0,0,0}}
234};
235
236static struct pci_controller sc520_spunk_hose = {
237 fixup_irq: pci_sc520_spunk_fixup_irq,
238 config_table: pci_sc520_spunk_config_table,
239 first_busno: 0x00,
240 last_busno: 0xff,
241};
242
243void pci_init_board(void)
244{
245 pci_sc520_init(&sc520_spunk_hose);
246}
247
248
249/* set up the ISA bus timing and system address mappings */
250static void bus_init(void)
251{
wdenk57b2d802003-06-27 21:31:46 +0000252 /* versions
wdenkabda5ca2003-05-31 18:35:21 +0000253 * 0 Hyglo versions 0.95 and 0.96 (large baords)
254 * ?? Hyglo version 0.97 (small board)
255 * 10 Spunk board
256 */
257 int version = read_mmcr_byte(SC520_SYSINFO);
wdenk57b2d802003-06-27 21:31:46 +0000258
wdenkabda5ca2003-05-31 18:35:21 +0000259 if (version) {
260 /* set up the GP IO pins (for the Spunk board) */
261 write_mmcr_word(SC520_PIOPFS31_16, 0xfff0); /* set the GPIO pin function 31-16 reg */
262 write_mmcr_word(SC520_PIOPFS15_0, 0x000f); /* set the GPIO pin function 15-0 reg */
263 write_mmcr_word(SC520_PIODIR31_16, 0x000f); /* set the GPIO direction 31-16 reg */
264 write_mmcr_word(SC520_PIODIR15_0, 0x1ff0); /* set the GPIO direction 15-0 reg */
wdenk57b2d802003-06-27 21:31:46 +0000265 write_mmcr_byte(SC520_CSPFS, 0xc0); /* set the CS pin function reg */
wdenkabda5ca2003-05-31 18:35:21 +0000266 write_mmcr_byte(SC520_CLKSEL, 0x70);
wdenk57b2d802003-06-27 21:31:46 +0000267
wdenkabda5ca2003-05-31 18:35:21 +0000268 write_mmcr_word(SC520_PIOCLR31_16, 0x0003); /* reset SSI chip-selects */
269 write_mmcr_word(SC520_PIOSET31_16, 0x000c);
270
271 } else {
272 /* set up the GP IO pins (for the Hyglo board) */
273 write_mmcr_word(SC520_PIOPFS31_16, 0xffc0); /* set the GPIO pin function 31-16 reg */
274 write_mmcr_word(SC520_PIOPFS15_0, 0x1e7f); /* set the GPIO pin function 15-0 reg */
275 write_mmcr_word(SC520_PIODIR31_16, 0x003f); /* set the GPIO direction 31-16 reg */
276 write_mmcr_word(SC520_PIODIR15_0, 0xe180); /* set the GPIO direction 15-0 reg */
wdenk57b2d802003-06-27 21:31:46 +0000277 write_mmcr_byte(SC520_CSPFS, 0x00); /* set the CS pin function reg */
wdenkabda5ca2003-05-31 18:35:21 +0000278 write_mmcr_byte(SC520_CLKSEL, 0x70);
wdenk57b2d802003-06-27 21:31:46 +0000279
wdenkabda5ca2003-05-31 18:35:21 +0000280 write_mmcr_word(SC520_PIOCLR15_0, 0x0180); /* reset SSI chip-selects */
281 }
wdenk57b2d802003-06-27 21:31:46 +0000282
283 write_mmcr_byte(SC520_GPCSRT, 1); /* set the GP CS offset */
wdenkabda5ca2003-05-31 18:35:21 +0000284 write_mmcr_byte(SC520_GPCSPW, 3); /* set the GP CS pulse width */
285 write_mmcr_byte(SC520_GPCSOFF, 1); /* set the GP CS offset */
286 write_mmcr_byte(SC520_GPRDW, 3); /* set the RD pulse width */
287 write_mmcr_byte(SC520_GPRDOFF, 1); /* set the GP RD offset */
wdenk57b2d802003-06-27 21:31:46 +0000288 write_mmcr_byte(SC520_GPWRW, 3); /* set the GP WR pulse width */
wdenkabda5ca2003-05-31 18:35:21 +0000289 write_mmcr_byte(SC520_GPWROFF, 1); /* set the GP WR offset */
290
wdenk57b2d802003-06-27 21:31:46 +0000291 write_mmcr_word(SC520_BOOTCSCTL, 0x0407); /* set up timing of BOOTCS */
292
wdenkabda5ca2003-05-31 18:35:21 +0000293 /* adjust the memory map:
294 * by default the first 256MB (0x00000000 - 0x0fffffff) is mapped to SDRAM
295 * and 256MB to 1G-128k (0x1000000 - 0x37ffffff) is mapped to PCI mmio
wdenk57b2d802003-06-27 21:31:46 +0000296 * we need to map 1G-128k - 1G (0x38000000 - 0x3fffffff) to CS1 */
297
298
wdenkabda5ca2003-05-31 18:35:21 +0000299 /* bootcs */
wdenk57b2d802003-06-27 21:31:46 +0000300 write_mmcr_long(SC520_PAR12, 0x8bffe800);
301
wdenkabda5ca2003-05-31 18:35:21 +0000302 /* IDE0 = GPCS6 1f0-1f7 */
wdenk57b2d802003-06-27 21:31:46 +0000303 write_mmcr_long(SC520_PAR3, 0x380801f0);
wdenkabda5ca2003-05-31 18:35:21 +0000304
305 /* IDE1 = GPCS7 3f6 */
wdenk57b2d802003-06-27 21:31:46 +0000306 write_mmcr_long(SC520_PAR4, 0x3c0003f6);
wdenkabda5ca2003-05-31 18:35:21 +0000307
wdenk57b2d802003-06-27 21:31:46 +0000308 asm ("wbinvd\n"); /* Flush cache, req. after setting the unchached attribute ona PAR */
wdenkabda5ca2003-05-31 18:35:21 +0000309
wdenk57b2d802003-06-27 21:31:46 +0000310 write_mmcr_byte(SC520_ADDDECCTL, read_mmcr_byte(SC520_ADDDECCTL) & ~(UART2_DIS|UART1_DIS));
wdenkabda5ca2003-05-31 18:35:21 +0000311
312}
313
314
wdenkabda5ca2003-05-31 18:35:21 +0000315/* par usage:
316 * PAR0 (legacy_video)
317 * PAR1 (PCI ROM mapping)
wdenk57b2d802003-06-27 21:31:46 +0000318 * PAR2
319 * PAR3 IDE
wdenkabda5ca2003-05-31 18:35:21 +0000320 * PAR4 IDE
321 * PAR5 (legacy_video)
wdenk57b2d802003-06-27 21:31:46 +0000322 * PAR6
wdenkabda5ca2003-05-31 18:35:21 +0000323 * PAR7 (legacy_video)
324 * PAR8 (legacy_video)
325 * PAR9 (legacy_video)
326 * PAR10
327 * PAR11 (ISAROM)
328 * PAR12 BOOTCS
329 * PAR13
330 * PAR14
331 * PAR15
332 */
333
wdenk57b2d802003-06-27 21:31:46 +0000334/*
wdenkabda5ca2003-05-31 18:35:21 +0000335 * This function should map a chunk of size bytes
336 * of the system address space to the ISA bus
wdenk57b2d802003-06-27 21:31:46 +0000337 *
wdenkabda5ca2003-05-31 18:35:21 +0000338 * The function will return the memory address
339 * as seen by the host (which may very will be the
340 * same as the bus address)
341 */
wdenk57b2d802003-06-27 21:31:46 +0000342u32 isa_map_rom(u32 bus_addr, int size)
wdenkabda5ca2003-05-31 18:35:21 +0000343{
344 u32 par;
wdenk57b2d802003-06-27 21:31:46 +0000345
346 printf("isa_map_rom asked to map %d bytes at %x\n",
wdenkabda5ca2003-05-31 18:35:21 +0000347 size, bus_addr);
wdenk57b2d802003-06-27 21:31:46 +0000348
wdenkabda5ca2003-05-31 18:35:21 +0000349 par = size;
350 if (par < 0x80000) {
351 par = 0x80000;
352 }
353 par >>= 12;
354 par--;
355 par&=0x7f;
356 par <<= 18;
357 par |= (bus_addr>>12);
358 par |= 0x50000000;
wdenk57b2d802003-06-27 21:31:46 +0000359
wdenkabda5ca2003-05-31 18:35:21 +0000360 printf ("setting PAR11 to %x\n", par);
wdenk57b2d802003-06-27 21:31:46 +0000361
wdenkabda5ca2003-05-31 18:35:21 +0000362 /* Map rom 0x10000 with PAR1 */
363 write_mmcr_long(SC520_PAR11, par);
wdenk57b2d802003-06-27 21:31:46 +0000364
wdenkabda5ca2003-05-31 18:35:21 +0000365 return bus_addr;
366}
367
368/*
369 * this function removed any mapping created
370 * with pci_get_rom_window()
371 */
372void isa_unmap_rom(u32 addr)
373{
374 printf("isa_unmap_rom asked to unmap %x", addr);
375 if ((addr>>12) == (read_mmcr_long(SC520_PAR11)&0x3ffff)) {
376 write_mmcr_long(SC520_PAR11, 0);
377 printf(" done\n");
378 return;
379 }
380 printf(" not ours\n");
381}
382
383#ifdef CONFIG_PCI
384#define PCI_ROM_TEMP_SPACE 0x10000
wdenk57b2d802003-06-27 21:31:46 +0000385/*
wdenkabda5ca2003-05-31 18:35:21 +0000386 * This function should map a chunk of size bytes
387 * of the system address space to the PCI bus,
388 * suitable to map PCI ROMS (bus address < 16M)
389 * the function will return the host memory address
390 * which should be converted into a bus address
wdenk57b2d802003-06-27 21:31:46 +0000391 * before used to configure the PCI rom address
wdenkabda5ca2003-05-31 18:35:21 +0000392 * decoder
393 */
wdenk57b2d802003-06-27 21:31:46 +0000394u32 pci_get_rom_window(struct pci_controller *hose, int size)
wdenkabda5ca2003-05-31 18:35:21 +0000395{
396 u32 par;
wdenk57b2d802003-06-27 21:31:46 +0000397
wdenkabda5ca2003-05-31 18:35:21 +0000398 par = size;
399 if (par < 0x80000) {
400 par = 0x80000;
401 }
402 par >>= 16;
403 par--;
404 par&=0x7ff;
405 par <<= 14;
406 par |= (PCI_ROM_TEMP_SPACE>>16);
407 par |= 0x72000000;
wdenk57b2d802003-06-27 21:31:46 +0000408
wdenkabda5ca2003-05-31 18:35:21 +0000409 printf ("setting PAR1 to %x\n", par);
wdenk57b2d802003-06-27 21:31:46 +0000410
wdenkabda5ca2003-05-31 18:35:21 +0000411 /* Map rom 0x10000 with PAR1 */
412 write_mmcr_long(SC520_PAR1, par);
wdenk57b2d802003-06-27 21:31:46 +0000413
wdenkabda5ca2003-05-31 18:35:21 +0000414 return PCI_ROM_TEMP_SPACE;
415}
416
417/*
418 * this function removed any mapping created
419 * with pci_get_rom_window()
420 */
421void pci_remove_rom_window(struct pci_controller *hose, u32 addr)
422{
423 printf("pci_remove_rom_window: %x", addr);
424 if (addr == PCI_ROM_TEMP_SPACE) {
425 write_mmcr_long(SC520_PAR1, 0);
426 printf(" done\n");
427 return;
428 }
429 printf(" not ours\n");
wdenk57b2d802003-06-27 21:31:46 +0000430
wdenkabda5ca2003-05-31 18:35:21 +0000431}
432
433/*
434 * This function is called in order to provide acces to the
wdenk57b2d802003-06-27 21:31:46 +0000435 * legacy video I/O ports on the PCI bus.
436 * After this function accesses to I/O ports 0x3b0-0x3bb and
wdenkabda5ca2003-05-31 18:35:21 +0000437 * 0x3c0-0x3df shuld result in transactions on the PCI bus.
wdenk57b2d802003-06-27 21:31:46 +0000438 *
wdenkabda5ca2003-05-31 18:35:21 +0000439 */
440int pci_enable_legacy_video_ports(struct pci_controller *hose)
441{
442 /* Map video memory to 0xa0000*/
443 write_mmcr_long(SC520_PAR0, 0x7200400a);
wdenk57b2d802003-06-27 21:31:46 +0000444
wdenkabda5ca2003-05-31 18:35:21 +0000445 /* forward all I/O accesses to PCI */
wdenk57b2d802003-06-27 21:31:46 +0000446 write_mmcr_byte(SC520_ADDDECCTL,
447 read_mmcr_byte(SC520_ADDDECCTL) | IO_HOLE_DEST_PCI);
448
449
wdenkabda5ca2003-05-31 18:35:21 +0000450 /* so we map away all io ports to pci (only way to access pci io
451 * below 0x400. But then we have to map back the portions that we dont
452 * use so that the generate cycles on the GPIO bus where the sio and
wdenk57b2d802003-06-27 21:31:46 +0000453 * ISA slots are connected, this requre the use of several PAR registers
wdenkabda5ca2003-05-31 18:35:21 +0000454 */
wdenk57b2d802003-06-27 21:31:46 +0000455
wdenkabda5ca2003-05-31 18:35:21 +0000456 /* bring 0x100 - 0x2f7 back to ISA using PAR5 */
wdenk57b2d802003-06-27 21:31:46 +0000457 write_mmcr_long(SC520_PAR5, 0x31f70100);
458
wdenkabda5ca2003-05-31 18:35:21 +0000459 /* com2 use 2f8-2ff */
wdenk57b2d802003-06-27 21:31:46 +0000460
wdenkabda5ca2003-05-31 18:35:21 +0000461 /* bring 0x300 - 0x3af back to ISA using PAR7 */
wdenk57b2d802003-06-27 21:31:46 +0000462 write_mmcr_long(SC520_PAR7, 0x30af0300);
463
wdenkabda5ca2003-05-31 18:35:21 +0000464 /* vga use 3b0-3bb */
wdenk57b2d802003-06-27 21:31:46 +0000465
wdenkabda5ca2003-05-31 18:35:21 +0000466 /* bring 0x3bc - 0x3bf back to ISA using PAR8 */
wdenk57b2d802003-06-27 21:31:46 +0000467 write_mmcr_long(SC520_PAR8, 0x300303bc);
468
wdenkabda5ca2003-05-31 18:35:21 +0000469 /* vga use 3c0-3df */
wdenk57b2d802003-06-27 21:31:46 +0000470
wdenkabda5ca2003-05-31 18:35:21 +0000471 /* bring 0x3e0 - 0x3f7 back to ISA using PAR9 */
wdenk57b2d802003-06-27 21:31:46 +0000472 write_mmcr_long(SC520_PAR9, 0x301703e0);
473
474 /* com1 use 3f8-3ff */
wdenkabda5ca2003-05-31 18:35:21 +0000475
476 return 0;
477}
478#endif
479
480/*
481 * Miscelaneous platform dependent initialisations
482 */
483
484int board_init(void)
485{
486 DECLARE_GLOBAL_DATA_PTR;
wdenk57b2d802003-06-27 21:31:46 +0000487
488 init_sc520();
wdenkabda5ca2003-05-31 18:35:21 +0000489 bus_init();
490 irq_init();
wdenk57b2d802003-06-27 21:31:46 +0000491
wdenkabda5ca2003-05-31 18:35:21 +0000492 /* max drive current on SDRAM */
493 write_mmcr_word(SC520_DSCTL, 0x0100);
wdenk57b2d802003-06-27 21:31:46 +0000494
wdenkabda5ca2003-05-31 18:35:21 +0000495 /* enter debug mode after next reset (only if jumper is also set) */
496 write_mmcr_byte(SC520_RESCFG, 0x08);
497 /* configure the software timer to 33.000MHz */
498 write_mmcr_byte(SC520_SWTMRCFG, 1);
499 gd->bus_clk = 33000000;
wdenk57b2d802003-06-27 21:31:46 +0000500
wdenkabda5ca2003-05-31 18:35:21 +0000501 return 0;
502}
503
504int dram_init(void)
505{
506 init_sc520_dram();
507 return 0;
508}
509
510void show_boot_progress(int val)
511{
wdenk57b2d802003-06-27 21:31:46 +0000512 int version = read_mmcr_byte(SC520_SYSINFO);
513
wdenkabda5ca2003-05-31 18:35:21 +0000514 if (version == 0) {
515 /* PIO31-PIO16 Data */
wdenk57b2d802003-06-27 21:31:46 +0000516 write_mmcr_word(SC520_PIODATA31_16,
wdenkabda5ca2003-05-31 18:35:21 +0000517 (read_mmcr_word(SC520_PIODATA31_16) & 0xffc0)| ((val&0x7e)>>1)); /* 0x1f8 >> 3 */
wdenk57b2d802003-06-27 21:31:46 +0000518
wdenkabda5ca2003-05-31 18:35:21 +0000519 /* PIO0-PIO15 Data */
wdenk57b2d802003-06-27 21:31:46 +0000520 write_mmcr_word(SC520_PIODATA15_0,
wdenkabda5ca2003-05-31 18:35:21 +0000521 (read_mmcr_word(SC520_PIODATA15_0) & 0x1fff)| ((val&0x7)<<13));
522 } else {
523 /* newer boards use PIO4-PIO12 */
524 /* PIO0-PIO15 Data */
wdenk57b2d802003-06-27 21:31:46 +0000525#if 0
526 val = (val & 0x007) | ((val & 0x038) << 3) | ((val & 0x1c0) >> 3);
wdenkabda5ca2003-05-31 18:35:21 +0000527#else
wdenk57b2d802003-06-27 21:31:46 +0000528 val = (val & 0x007) | ((val & 0x07e) << 2);
wdenkabda5ca2003-05-31 18:35:21 +0000529#endif
wdenk57b2d802003-06-27 21:31:46 +0000530 write_mmcr_word(SC520_PIODATA15_0,
wdenkabda5ca2003-05-31 18:35:21 +0000531 (read_mmcr_word(SC520_PIODATA15_0) & 0xe00f) | ((val&0x01ff)<<4));
532 }
533}
534
535
536int last_stage_init(void)
537{
wdenk57b2d802003-06-27 21:31:46 +0000538
wdenkabda5ca2003-05-31 18:35:21 +0000539 int version = read_mmcr_byte(SC520_SYSINFO);
wdenk57b2d802003-06-27 21:31:46 +0000540
wdenkabda5ca2003-05-31 18:35:21 +0000541 printf("Omicron Ceti SC520 Spunk revision %x\n", version);
wdenk57b2d802003-06-27 21:31:46 +0000542
wdenkabda5ca2003-05-31 18:35:21 +0000543#if 0
544 if (version) {
545 int x, y;
wdenk57b2d802003-06-27 21:31:46 +0000546
wdenkabda5ca2003-05-31 18:35:21 +0000547 printf("eeprom probe %d\n", spi_eeprom_probe(1));
wdenk57b2d802003-06-27 21:31:46 +0000548
wdenkabda5ca2003-05-31 18:35:21 +0000549 spi_eeprom_read(1, 0, (u8*)&x, 2);
550 spi_eeprom_read(1, 1, (u8*)&y, 2);
551 printf("eeprom bytes %04x%04x\n", x, y);
552 x ^= 0xffff;
553 y ^= 0xffff;
554 spi_eeprom_write(1, 0, (u8*)&x, 2);
555 spi_eeprom_write(1, 1, (u8*)&y, 2);
wdenk57b2d802003-06-27 21:31:46 +0000556
wdenkabda5ca2003-05-31 18:35:21 +0000557 spi_eeprom_read(1, 0, (u8*)&x, 2);
558 spi_eeprom_read(1, 1, (u8*)&y, 2);
559 printf("eeprom bytes %04x%04x\n", x, y);
wdenk57b2d802003-06-27 21:31:46 +0000560
wdenkabda5ca2003-05-31 18:35:21 +0000561 } else {
562 int x, y;
wdenk57b2d802003-06-27 21:31:46 +0000563
wdenkabda5ca2003-05-31 18:35:21 +0000564 printf("eeprom probe %d\n", mw_eeprom_probe(1));
wdenk57b2d802003-06-27 21:31:46 +0000565
wdenkabda5ca2003-05-31 18:35:21 +0000566 mw_eeprom_read(1, 0, (u8*)&x, 2);
567 mw_eeprom_read(1, 1, (u8*)&y, 2);
568 printf("eeprom bytes %04x%04x\n", x, y);
wdenk57b2d802003-06-27 21:31:46 +0000569
wdenkabda5ca2003-05-31 18:35:21 +0000570 x ^= 0xffff;
571 y ^= 0xffff;
572 mw_eeprom_write(1, 0, (u8*)&x, 2);
573 mw_eeprom_write(1, 1, (u8*)&y, 2);
wdenk57b2d802003-06-27 21:31:46 +0000574
wdenkabda5ca2003-05-31 18:35:21 +0000575 mw_eeprom_read(1, 0, (u8*)&x, 2);
576 mw_eeprom_read(1, 1, (u8*)&y, 2);
577 printf("eeprom bytes %04x%04x\n", x, y);
wdenk57b2d802003-06-27 21:31:46 +0000578
579
wdenkabda5ca2003-05-31 18:35:21 +0000580 }
581#endif
582
583 ds1722_probe(2);
wdenk57b2d802003-06-27 21:31:46 +0000584
wdenkabda5ca2003-05-31 18:35:21 +0000585 return 0;
586}
587
wdenk57b2d802003-06-27 21:31:46 +0000588void ssi_chip_select(int dev)
wdenkabda5ca2003-05-31 18:35:21 +0000589{
590 int version = read_mmcr_byte(SC520_SYSINFO);
wdenk57b2d802003-06-27 21:31:46 +0000591
wdenkabda5ca2003-05-31 18:35:21 +0000592 if (version) {
593 /* Spunk board: EEPROM and CAN are actove-low, TEMP and AUX are active high */
594 switch (dev) {
595 case 1: /* EEPROM */
596 write_mmcr_word(SC520_PIOCLR31_16, 0x0004);
597 break;
wdenk57b2d802003-06-27 21:31:46 +0000598
wdenkabda5ca2003-05-31 18:35:21 +0000599 case 2: /* Temp Probe */
600 write_mmcr_word(SC520_PIOSET31_16, 0x0002);
601 break;
wdenk57b2d802003-06-27 21:31:46 +0000602
wdenkabda5ca2003-05-31 18:35:21 +0000603 case 3: /* CAN */
604 write_mmcr_word(SC520_PIOCLR31_16, 0x0008);
605 break;
wdenk57b2d802003-06-27 21:31:46 +0000606
607 case 4: /* AUX */
wdenkabda5ca2003-05-31 18:35:21 +0000608 write_mmcr_word(SC520_PIOSET31_16, 0x0001);
609 break;
wdenk57b2d802003-06-27 21:31:46 +0000610
wdenkabda5ca2003-05-31 18:35:21 +0000611 case 0:
612 write_mmcr_word(SC520_PIOCLR31_16, 0x0003);
613 write_mmcr_word(SC520_PIOSET31_16, 0x000c);
614 break;
wdenk57b2d802003-06-27 21:31:46 +0000615
wdenkabda5ca2003-05-31 18:35:21 +0000616 default:
617 printf("Illegal SSI device requested: %d\n", dev);
618 }
619 } else {
wdenk57b2d802003-06-27 21:31:46 +0000620
wdenkabda5ca2003-05-31 18:35:21 +0000621 /* Globox board: Both EEPROM and TEMP are active-high */
622
623 switch (dev) {
624 case 1: /* EEPROM */
625 write_mmcr_word(SC520_PIOSET15_0, 0x0100);
626 break;
wdenk57b2d802003-06-27 21:31:46 +0000627
wdenkabda5ca2003-05-31 18:35:21 +0000628 case 2: /* Temp Probe */
629 write_mmcr_word(SC520_PIOSET15_0, 0x0080);
630 break;
wdenk57b2d802003-06-27 21:31:46 +0000631
wdenkabda5ca2003-05-31 18:35:21 +0000632 case 0:
633 write_mmcr_word(SC520_PIOCLR15_0, 0x0180);
634 break;
wdenk57b2d802003-06-27 21:31:46 +0000635
wdenkabda5ca2003-05-31 18:35:21 +0000636 default:
637 printf("Illegal SSI device requested: %d\n", dev);
638 }
wdenk57b2d802003-06-27 21:31:46 +0000639 }
wdenkabda5ca2003-05-31 18:35:21 +0000640}
641
642
wdenk57b2d802003-06-27 21:31:46 +0000643void spi_init_f(void)
wdenkabda5ca2003-05-31 18:35:21 +0000644{
645 read_mmcr_byte(SC520_SYSINFO) ?
wdenk57b2d802003-06-27 21:31:46 +0000646 spi_eeprom_probe(1) :
wdenkabda5ca2003-05-31 18:35:21 +0000647 mw_eeprom_probe(1);
wdenk57b2d802003-06-27 21:31:46 +0000648
wdenkabda5ca2003-05-31 18:35:21 +0000649}
650
wdenk57b2d802003-06-27 21:31:46 +0000651ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
wdenkabda5ca2003-05-31 18:35:21 +0000652{
653 int offset;
654 int i;
wdenk57b2d802003-06-27 21:31:46 +0000655
wdenkabda5ca2003-05-31 18:35:21 +0000656 offset = 0;
657 for (i=0;i<alen;i++) {
658 offset <<= 8;
659 offset |= addr[i];
660 }
wdenk57b2d802003-06-27 21:31:46 +0000661
wdenkabda5ca2003-05-31 18:35:21 +0000662 return read_mmcr_byte(SC520_SYSINFO) ?
wdenk57b2d802003-06-27 21:31:46 +0000663 spi_eeprom_read(1, offset, buffer, len) :
wdenkabda5ca2003-05-31 18:35:21 +0000664 mw_eeprom_read(1, offset, buffer, len);
665}
666
wdenk57b2d802003-06-27 21:31:46 +0000667ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
wdenkabda5ca2003-05-31 18:35:21 +0000668{
669 int offset;
670 int i;
wdenk57b2d802003-06-27 21:31:46 +0000671
wdenkabda5ca2003-05-31 18:35:21 +0000672 offset = 0;
673 for (i=0;i<alen;i++) {
674 offset <<= 8;
675 offset |= addr[i];
676 }
wdenk57b2d802003-06-27 21:31:46 +0000677
wdenkabda5ca2003-05-31 18:35:21 +0000678 return read_mmcr_byte(SC520_SYSINFO) ?
wdenk57b2d802003-06-27 21:31:46 +0000679 spi_eeprom_write(1, offset, buffer, len) :
wdenkabda5ca2003-05-31 18:35:21 +0000680 mw_eeprom_write(1, offset, buffer, len);
681}