blob: dbb5c48d683cac476664a99b373050b5bbe56035 [file] [log] [blame]
wdenk7a8e9bed2003-05-31 18:35:21 +00001/*
wdenk8bde7f72003-06-27 21:31:46 +00002 *
wdenk7a8e9bed2003-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>
Ben Warren10efa022008-08-31 20:37:00 -070027#include <netdev.h>
Graeme Russ91ee4e12009-08-23 12:59:54 +100028#include <ds1722.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000029#include <asm/io.h>
30#include <asm/pci.h>
31#include <asm/ic/sc520.h>
Graeme Russ91ee4e12009-08-23 12:59:54 +100032#include <asm/ic/pci.h>
33#include <asm/ic/ssi.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000034
Wolfgang Denkd87080b2006-03-31 18:32:53 +020035DECLARE_GLOBAL_DATA_PTR;
wdenk8bde7f72003-06-27 21:31:46 +000036
37/*
wdenk7a8e9bed2003-05-31 18:35:21 +000038 * Theory:
39 * We first set up all IRQs to be non-pci, edge triggered,
wdenk8bde7f72003-06-27 21:31:46 +000040 * when we later enumerate the pci bus and pci_sc520_fixup_irq() gets
wdenk7a8e9bed2003-05-31 18:35:21 +000041 * called we reallocate irqs to the pci bus with sc520_pci_set_irq()
42 * as needed. Whe choose the irqs to gram from a configurable list
43 * inside pci_sc520_fixup_irq() (If this list contains stupid irq's
44 * such as 0 thngas will not work)
45 */
46
47static void irq_init(void)
48{
49 /* disable global interrupt mode */
Graeme Russed7a1b62009-08-23 12:59:56 +100050 sc520_mmcr->picicr = 0x40;
wdenk8bde7f72003-06-27 21:31:46 +000051
wdenk7a8e9bed2003-05-31 18:35:21 +000052 /* set all irqs to edge */
Graeme Russed7a1b62009-08-23 12:59:56 +100053 sc520_mmcr->pic_mode[0] = 0x00;
54 sc520_mmcr->pic_mode[1] = 0x00;
55 sc520_mmcr->pic_mode[2] = 0x00;
wdenk8bde7f72003-06-27 21:31:46 +000056
57 /* active low polarity on PIC interrupt pins,
wdenk7a8e9bed2003-05-31 18:35:21 +000058 * active high polarity on all other irq pins */
Graeme Russed7a1b62009-08-23 12:59:56 +100059 sc520_mmcr->intpinpol = 0x0000;
wdenk7a8e9bed2003-05-31 18:35:21 +000060
61 /* set irq number mapping */
Graeme Russed7a1b62009-08-23 12:59:56 +100062 sc520_mmcr->gp_tmr_int_map[0] = SC520_IRQ_DISABLED; /* disable GP timer 0 INT */
63 sc520_mmcr->gp_tmr_int_map[1] = SC520_IRQ_DISABLED; /* disable GP timer 1 INT */
64 sc520_mmcr->gp_tmr_int_map[2] = SC520_IRQ_DISABLED; /* disable GP timer 2 INT */
65 sc520_mmcr->pit_int_map[0] = SC520_IRQ0; /* Set PIT timer 0 INT to IRQ0 */
66 sc520_mmcr->pit_int_map[1] = SC520_IRQ_DISABLED; /* disable PIT timer 1 INT */
67 sc520_mmcr->pit_int_map[2] = SC520_IRQ_DISABLED; /* disable PIT timer 2 INT */
68 sc520_mmcr->pci_int_map[0] = SC520_IRQ_DISABLED; /* disable PCI INT A */
69 sc520_mmcr->pci_int_map[1] = SC520_IRQ_DISABLED; /* disable PCI INT B */
70 sc520_mmcr->pci_int_map[2] = SC520_IRQ_DISABLED; /* disable PCI INT C */
71 sc520_mmcr->pci_int_map[3] = SC520_IRQ_DISABLED; /* disable PCI INT D */
72 sc520_mmcr->dmabcintmap = SC520_IRQ_DISABLED; /* disable DMA INT */
73 sc520_mmcr->ssimap = SC520_IRQ6; /* Set Synchronius serial INT to IRQ6*/
74 sc520_mmcr->wdtmap = SC520_IRQ_DISABLED; /* disable Watchdog INT */
75 sc520_mmcr->rtcmap = SC520_IRQ8; /* Set RTC int to 8 */
76 sc520_mmcr->wpvmap = SC520_IRQ_DISABLED; /* disable write protect INT */
77 sc520_mmcr->icemap = SC520_IRQ1; /* Set ICE Debug Serielport INT to IRQ1 */
78 sc520_mmcr->ferrmap = SC520_IRQ13; /* Set FP error INT to IRQ13 */
wdenk8bde7f72003-06-27 21:31:46 +000079
wdenk8bde7f72003-06-27 21:31:46 +000080
Graeme Russed7a1b62009-08-23 12:59:56 +100081 sc520_mmcr->uart_int_map[0] = SC520_IRQ4; /* Set internal UART1 INT to IRQ4 */
82 sc520_mmcr->uart_int_map[1] = SC520_IRQ3; /* Set internal UART2 INT to IRQ3 */
wdenk8bde7f72003-06-27 21:31:46 +000083
Graeme Russed7a1b62009-08-23 12:59:56 +100084 sc520_mmcr->gp_int_map[0] = SC520_IRQ7; /* Set GPIRQ0 (PC-Card AUX IRQ) to IRQ7 */
85 sc520_mmcr->gp_int_map[1] = SC520_IRQ14; /* Set GPIRQ1 (CF IRQ) to IRQ14 */
86 sc520_mmcr->gp_int_map[3] = SC520_IRQ5; /* Set GPIRQ3 ( CAN IRQ ) ti IRQ5 */
87 sc520_mmcr->gp_int_map[4] = SC520_IRQ_DISABLED; /* disbale GIRQ4 ( IRR IRQ ) */
88 sc520_mmcr->gp_int_map[5] = SC520_IRQ_DISABLED; /* disable GPIRQ5 */
89 sc520_mmcr->gp_int_map[6] = SC520_IRQ_DISABLED; /* disable GPIRQ6 */
90 sc520_mmcr->gp_int_map[7] = SC520_IRQ_DISABLED; /* disable GPIRQ7 */
91 sc520_mmcr->gp_int_map[8] = SC520_IRQ_DISABLED; /* disable GPIRQ8 */
92 sc520_mmcr->gp_int_map[9] = SC520_IRQ_DISABLED; /* disable GPIRQ9 */
93 sc520_mmcr->gp_int_map[2] = SC520_IRQ_DISABLED; /* disable GPIRQ2 */
94 sc520_mmcr->gp_int_map[10] = SC520_IRQ_DISABLED; /* disable GPIRQ10 */
95
96 sc520_mmcr->pcihostmap = 0x11f; /* Map PCI hostbridge INT to NMI */
97 sc520_mmcr->eccmap = 0x100; /* Map SDRAM ECC failure INT to NMI */
wdenk8bde7f72003-06-27 21:31:46 +000098
wdenk7a8e9bed2003-05-31 18:35:21 +000099}
100
wdenk8bde7f72003-06-27 21:31:46 +0000101
wdenk7a8e9bed2003-05-31 18:35:21 +0000102/* PCI stuff */
103static void pci_sc520_spunk_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
104{
Graeme Russed7a1b62009-08-23 12:59:56 +1000105 int version = sc520_mmcr->sysinfo;
wdenk8bde7f72003-06-27 21:31:46 +0000106
wdenk7a8e9bed2003-05-31 18:35:21 +0000107 /* a configurable lists of irqs to steal
108 * when we need one (a board with more pci interrupt pins
109 * would use a larger table */
110 static int irq_list[] = {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200111 CONFIG_SYS_FIRST_PCI_IRQ,
112 CONFIG_SYS_SECOND_PCI_IRQ,
113 CONFIG_SYS_THIRD_PCI_IRQ,
114 CONFIG_SYS_FORTH_PCI_IRQ
wdenk7a8e9bed2003-05-31 18:35:21 +0000115 };
116 static int next_irq_index=0;
wdenk8bde7f72003-06-27 21:31:46 +0000117
Graeme Russ91ee4e12009-08-23 12:59:54 +1000118 uchar tmp_pin;
wdenk7a8e9bed2003-05-31 18:35:21 +0000119 int pin;
wdenk8bde7f72003-06-27 21:31:46 +0000120
wdenk7a8e9bed2003-05-31 18:35:21 +0000121 pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin);
122 pin = tmp_pin;
wdenk8bde7f72003-06-27 21:31:46 +0000123
wdenk7a8e9bed2003-05-31 18:35:21 +0000124 pin-=1; /* pci config space use 1-based numbering */
125 if (-1 == pin) {
126 return; /* device use no irq */
127 }
wdenk8bde7f72003-06-27 21:31:46 +0000128
129
wdenk7a8e9bed2003-05-31 18:35:21 +0000130 /* map device number + pin to a pin on the sc520 */
131 switch (PCI_DEV(dev)) {
wdenk8bde7f72003-06-27 21:31:46 +0000132 case 6: /* ETH0 */
wdenk7a8e9bed2003-05-31 18:35:21 +0000133 pin+=SC520_PCI_INTA;
134 break;
wdenk8bde7f72003-06-27 21:31:46 +0000135
wdenk7a8e9bed2003-05-31 18:35:21 +0000136 case 7: /* ETH1 */
137 pin+=SC520_PCI_INTB;
138 break;
wdenk8bde7f72003-06-27 21:31:46 +0000139
wdenk7a8e9bed2003-05-31 18:35:21 +0000140 case 8: /* Crypto */
141 pin+=SC520_PCI_INTC;
142 break;
wdenk8bde7f72003-06-27 21:31:46 +0000143
wdenk7a8e9bed2003-05-31 18:35:21 +0000144 case 9: /* PMC slot */
145 pin+=SC520_PCI_INTD;
146 break;
wdenk8bde7f72003-06-27 21:31:46 +0000147
wdenk7a8e9bed2003-05-31 18:35:21 +0000148 case 10: /* PC-Card */
wdenk8bde7f72003-06-27 21:31:46 +0000149
150 if (version < 10) {
wdenk7a8e9bed2003-05-31 18:35:21 +0000151 pin+=SC520_PCI_INTD;
152 } else {
153 pin+=SC520_PCI_INTC;
154 }
155 break;
wdenk8bde7f72003-06-27 21:31:46 +0000156
157 default:
wdenk7a8e9bed2003-05-31 18:35:21 +0000158 return;
159 }
wdenk8bde7f72003-06-27 21:31:46 +0000160
wdenk7a8e9bed2003-05-31 18:35:21 +0000161 pin&=3; /* wrap around */
wdenk8bde7f72003-06-27 21:31:46 +0000162
wdenk7a8e9bed2003-05-31 18:35:21 +0000163 if (sc520_pci_ints[pin] == -1) {
wdenk8bde7f72003-06-27 21:31:46 +0000164 /* re-route one interrupt for us */
wdenk7a8e9bed2003-05-31 18:35:21 +0000165 if (next_irq_index > 3) {
166 return;
167 }
wdenk8bde7f72003-06-27 21:31:46 +0000168 if (pci_sc520_set_irq(pin, irq_list[next_irq_index])) {
wdenk7a8e9bed2003-05-31 18:35:21 +0000169 return;
170 }
171 next_irq_index++;
172 }
173
wdenk8bde7f72003-06-27 21:31:46 +0000174
wdenk7a8e9bed2003-05-31 18:35:21 +0000175 if (-1 != sc520_pci_ints[pin]) {
wdenk8bde7f72003-06-27 21:31:46 +0000176 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
wdenk7a8e9bed2003-05-31 18:35:21 +0000177 sc520_pci_ints[pin]);
178 }
wdenk8bde7f72003-06-27 21:31:46 +0000179#if 0
180 printf("fixup_irq: device %d pin %c irq %d\n",
wdenk7a8e9bed2003-05-31 18:35:21 +0000181 PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]);
182#endif
183}
184
185
wdenk8bde7f72003-06-27 21:31:46 +0000186static void pci_sc520_spunk_configure_cardbus(struct pci_controller *hose,
wdenk7a8e9bed2003-05-31 18:35:21 +0000187 pci_dev_t dev, struct pci_config_table *te)
188{
189 u32 io_base;
190 u32 temp;
wdenk8bde7f72003-06-27 21:31:46 +0000191
wdenk7a8e9bed2003-05-31 18:35:21 +0000192 pciauto_config_device(hose, dev);
wdenk8bde7f72003-06-27 21:31:46 +0000193
wdenk7a8e9bed2003-05-31 18:35:21 +0000194 pci_hose_write_config_word(hose, dev, PCI_COMMAND, 0x07); /* enable device */
195 pci_hose_write_config_byte(hose, dev, 0x0c, 0x10); /* cacheline size */
196 pci_hose_write_config_byte(hose, dev, 0x0d, 0x40); /* latency timer */
197 pci_hose_write_config_byte(hose, dev, 0x1b, 0x40); /* cardbus latency timer */
198 pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0040); /* reset cardbus */
199 pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0080); /* route interrupts though ExCA */
200 pci_hose_write_config_word(hose, dev, 0x44, 0x3e0); /* map legacy I/O port to 0x3e0 */
wdenk8bde7f72003-06-27 21:31:46 +0000201
202 pci_hose_read_config_dword(hose, dev, 0x80, &temp); /* System control */
203 pci_hose_write_config_dword(hose, dev, 0x80, temp | 0x60); /* System control: disable clockrun */
204 /* route MF0 to ~INT and MF3 to IRQ7
wdenk7a8e9bed2003-05-31 18:35:21 +0000205 * reserve all others */
wdenk8bde7f72003-06-27 21:31:46 +0000206 pci_hose_write_config_dword(hose, dev, 0x8c, 0x00007002);
wdenk7a8e9bed2003-05-31 18:35:21 +0000207 pci_hose_write_config_byte(hose, dev, 0x91, 0x00); /* card control */
208 pci_hose_write_config_byte(hose, dev, 0x92, 0x62); /* device control */
wdenk8bde7f72003-06-27 21:31:46 +0000209
wdenk7a8e9bed2003-05-31 18:35:21 +0000210 if (te->device != 0xac56) {
211 pci_hose_write_config_byte(hose, dev, 0x93, 0x21); /* async interrupt enable */
212 pci_hose_write_config_word(hose, dev, 0xa8, 0x0000); /* reset GPIO */
213 pci_hose_write_config_word(hose, dev, 0xac, 0x0000); /* reset GPIO */
214 pci_hose_write_config_word(hose, dev, 0xaa, 0x0000); /* reset GPIO */
215 pci_hose_write_config_word(hose, dev, 0xae, 0x0000); /* reset GPIO */
216 } else {
217 pci_hose_write_config_byte(hose, dev, 0x93, 0x20); /* */
218 }
219 pci_hose_write_config_word(hose, dev, 0xa4, 0x8000); /* reset power management */
wdenk8bde7f72003-06-27 21:31:46 +0000220
221
wdenk7a8e9bed2003-05-31 18:35:21 +0000222 pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &io_base);
223 io_base &= ~0xfL;
wdenk8bde7f72003-06-27 21:31:46 +0000224
wdenk7a8e9bed2003-05-31 18:35:21 +0000225 writeb(0x07, io_base+0x803); /* route CSC irq though ExCA and enable IRQ7 */
226 writel(0, io_base+0x10); /* CLKRUN default */
227 writel(0, io_base+0x20); /* CLKRUN default */
wdenk8bde7f72003-06-27 21:31:46 +0000228
wdenk7a8e9bed2003-05-31 18:35:21 +0000229}
230
231
wdenk7a8e9bed2003-05-31 18:35:21 +0000232static struct pci_config_table pci_sc520_spunk_config_table[] = {
wdenk8bde7f72003-06-27 21:31:46 +0000233 { 0x104c, 0xac50, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
234 { 0x104c, 0xac56, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
wdenk7a8e9bed2003-05-31 18:35:21 +0000235 { 0, 0, 0, 0, 0, 0, NULL, {0,0,0}}
236};
237
238static struct pci_controller sc520_spunk_hose = {
239 fixup_irq: pci_sc520_spunk_fixup_irq,
240 config_table: pci_sc520_spunk_config_table,
241 first_busno: 0x00,
242 last_busno: 0xff,
243};
244
245void pci_init_board(void)
246{
247 pci_sc520_init(&sc520_spunk_hose);
248}
249
250
251/* set up the ISA bus timing and system address mappings */
252static void bus_init(void)
253{
wdenk8bde7f72003-06-27 21:31:46 +0000254 /* versions
wdenk7a8e9bed2003-05-31 18:35:21 +0000255 * 0 Hyglo versions 0.95 and 0.96 (large baords)
256 * ?? Hyglo version 0.97 (small board)
257 * 10 Spunk board
258 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000259 int version = sc520_mmcr->sysinfo;
wdenk8bde7f72003-06-27 21:31:46 +0000260
wdenk7a8e9bed2003-05-31 18:35:21 +0000261 if (version) {
262 /* set up the GP IO pins (for the Spunk board) */
Graeme Russed7a1b62009-08-23 12:59:56 +1000263 sc520_mmcr->piopfs31_16 = 0xfff0; /* set the GPIO pin function 31-16 reg */
264 sc520_mmcr->piopfs15_0 = 0x000f; /* set the GPIO pin function 15-0 reg */
265 sc520_mmcr->piodir31_16 = 0x000f; /* set the GPIO direction 31-16 reg */
266 sc520_mmcr->piodir15_0 = 0x1ff0; /* set the GPIO direction 15-0 reg */
267 sc520_mmcr->cspfs = 0xc0; /* set the CS pin function reg */
268 sc520_mmcr->clksel = 0x70;
wdenk8bde7f72003-06-27 21:31:46 +0000269
Graeme Russed7a1b62009-08-23 12:59:56 +1000270 sc520_mmcr->pioclr31_16 = 0x0003; /* reset SSI chip-selects */
271 sc520_mmcr->pioset31_16 = 0x000c;
wdenk7a8e9bed2003-05-31 18:35:21 +0000272
273 } else {
274 /* set up the GP IO pins (for the Hyglo board) */
Graeme Russed7a1b62009-08-23 12:59:56 +1000275 sc520_mmcr->piopfs31_16 = 0xffc0; /* set the GPIO pin function 31-16 reg */
276 sc520_mmcr->piopfs15_0 = 0x1e7f; /* set the GPIO pin function 15-0 reg */
277 sc520_mmcr->piodir31_16 = 0x003f; /* set the GPIO direction 31-16 reg */
278 sc520_mmcr->piodir15_0 = 0xe180; /* set the GPIO direction 15-0 reg */
279 sc520_mmcr->cspfs = 0x00; /* set the CS pin function reg */
280 sc520_mmcr->clksel = 0x70;
wdenk8bde7f72003-06-27 21:31:46 +0000281
Graeme Russed7a1b62009-08-23 12:59:56 +1000282 sc520_mmcr->pioclr15_0 = 0x0180; /* reset SSI chip-selects */
wdenk7a8e9bed2003-05-31 18:35:21 +0000283 }
wdenk8bde7f72003-06-27 21:31:46 +0000284
Graeme Russed7a1b62009-08-23 12:59:56 +1000285 sc520_mmcr->gpcsrt = 1; /* set the GP CS offset */
286 sc520_mmcr->gpcspw = 3; /* set the GP CS pulse width */
287 sc520_mmcr->gpcsoff = 1; /* set the GP CS offset */
288 sc520_mmcr->gprdw = 3; /* set the RD pulse width */
289 sc520_mmcr->gprdoff = 1; /* set the GP RD offset */
290 sc520_mmcr->gpwrw = 3; /* set the GP WR pulse width */
291 sc520_mmcr->gpwroff = 1; /* set the GP WR offset */
wdenk7a8e9bed2003-05-31 18:35:21 +0000292
Graeme Russed7a1b62009-08-23 12:59:56 +1000293 sc520_mmcr->bootcsctl = 0x0407; /* set up timing of BOOTCS */
wdenk8bde7f72003-06-27 21:31:46 +0000294
wdenk7a8e9bed2003-05-31 18:35:21 +0000295 /* adjust the memory map:
296 * by default the first 256MB (0x00000000 - 0x0fffffff) is mapped to SDRAM
297 * and 256MB to 1G-128k (0x1000000 - 0x37ffffff) is mapped to PCI mmio
wdenk8bde7f72003-06-27 21:31:46 +0000298 * we need to map 1G-128k - 1G (0x38000000 - 0x3fffffff) to CS1 */
299
300
wdenk7a8e9bed2003-05-31 18:35:21 +0000301 /* bootcs */
Graeme Russed7a1b62009-08-23 12:59:56 +1000302 sc520_mmcr->par[12] = 0x8bffe800;
wdenk8bde7f72003-06-27 21:31:46 +0000303
wdenk7a8e9bed2003-05-31 18:35:21 +0000304 /* IDE0 = GPCS6 1f0-1f7 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000305 sc520_mmcr->par[3] = 0x380801f0;
wdenk7a8e9bed2003-05-31 18:35:21 +0000306
307 /* IDE1 = GPCS7 3f6 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000308 sc520_mmcr->par[4] = 0x3c0003f6;
wdenk7a8e9bed2003-05-31 18:35:21 +0000309
wdenk8bde7f72003-06-27 21:31:46 +0000310 asm ("wbinvd\n"); /* Flush cache, req. after setting the unchached attribute ona PAR */
wdenk7a8e9bed2003-05-31 18:35:21 +0000311
Graeme Russed7a1b62009-08-23 12:59:56 +1000312 sc520_mmcr->adddecctl = sc520_mmcr->adddecctl & ~(UART2_DIS|UART1_DIS);
wdenk7a8e9bed2003-05-31 18:35:21 +0000313
314}
315
316
wdenk7a8e9bed2003-05-31 18:35:21 +0000317/* par usage:
318 * PAR0 (legacy_video)
319 * PAR1 (PCI ROM mapping)
wdenk8bde7f72003-06-27 21:31:46 +0000320 * PAR2
321 * PAR3 IDE
wdenk7a8e9bed2003-05-31 18:35:21 +0000322 * PAR4 IDE
323 * PAR5 (legacy_video)
wdenk8bde7f72003-06-27 21:31:46 +0000324 * PAR6
wdenk7a8e9bed2003-05-31 18:35:21 +0000325 * PAR7 (legacy_video)
326 * PAR8 (legacy_video)
327 * PAR9 (legacy_video)
328 * PAR10
329 * PAR11 (ISAROM)
330 * PAR12 BOOTCS
331 * PAR13
332 * PAR14
333 * PAR15
334 */
335
wdenk8bde7f72003-06-27 21:31:46 +0000336/*
wdenk7a8e9bed2003-05-31 18:35:21 +0000337 * This function should map a chunk of size bytes
338 * of the system address space to the ISA bus
wdenk8bde7f72003-06-27 21:31:46 +0000339 *
wdenk7a8e9bed2003-05-31 18:35:21 +0000340 * The function will return the memory address
341 * as seen by the host (which may very will be the
342 * same as the bus address)
343 */
wdenk8bde7f72003-06-27 21:31:46 +0000344u32 isa_map_rom(u32 bus_addr, int size)
wdenk7a8e9bed2003-05-31 18:35:21 +0000345{
346 u32 par;
wdenk8bde7f72003-06-27 21:31:46 +0000347
348 printf("isa_map_rom asked to map %d bytes at %x\n",
wdenk7a8e9bed2003-05-31 18:35:21 +0000349 size, bus_addr);
wdenk8bde7f72003-06-27 21:31:46 +0000350
wdenk7a8e9bed2003-05-31 18:35:21 +0000351 par = size;
352 if (par < 0x80000) {
353 par = 0x80000;
354 }
355 par >>= 12;
356 par--;
357 par&=0x7f;
358 par <<= 18;
359 par |= (bus_addr>>12);
360 par |= 0x50000000;
wdenk8bde7f72003-06-27 21:31:46 +0000361
wdenk7a8e9bed2003-05-31 18:35:21 +0000362 printf ("setting PAR11 to %x\n", par);
wdenk8bde7f72003-06-27 21:31:46 +0000363
wdenk7a8e9bed2003-05-31 18:35:21 +0000364 /* Map rom 0x10000 with PAR1 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000365 sc520_mmcr->par[11] = par;
wdenk8bde7f72003-06-27 21:31:46 +0000366
wdenk7a8e9bed2003-05-31 18:35:21 +0000367 return bus_addr;
368}
369
370/*
371 * this function removed any mapping created
372 * with pci_get_rom_window()
373 */
374void isa_unmap_rom(u32 addr)
375{
376 printf("isa_unmap_rom asked to unmap %x", addr);
Graeme Russed7a1b62009-08-23 12:59:56 +1000377 if ((addr>>12) == (sc520_mmcr->par[11] & 0x3ffff)) {
378 sc520_mmcr->par[11] = 0;
wdenk7a8e9bed2003-05-31 18:35:21 +0000379 printf(" done\n");
380 return;
381 }
382 printf(" not ours\n");
383}
384
385#ifdef CONFIG_PCI
386#define PCI_ROM_TEMP_SPACE 0x10000
wdenk8bde7f72003-06-27 21:31:46 +0000387/*
wdenk7a8e9bed2003-05-31 18:35:21 +0000388 * This function should map a chunk of size bytes
389 * of the system address space to the PCI bus,
390 * suitable to map PCI ROMS (bus address < 16M)
391 * the function will return the host memory address
392 * which should be converted into a bus address
wdenk8bde7f72003-06-27 21:31:46 +0000393 * before used to configure the PCI rom address
wdenk7a8e9bed2003-05-31 18:35:21 +0000394 * decoder
395 */
wdenk8bde7f72003-06-27 21:31:46 +0000396u32 pci_get_rom_window(struct pci_controller *hose, int size)
wdenk7a8e9bed2003-05-31 18:35:21 +0000397{
398 u32 par;
wdenk8bde7f72003-06-27 21:31:46 +0000399
wdenk7a8e9bed2003-05-31 18:35:21 +0000400 par = size;
401 if (par < 0x80000) {
402 par = 0x80000;
403 }
404 par >>= 16;
405 par--;
406 par&=0x7ff;
407 par <<= 14;
408 par |= (PCI_ROM_TEMP_SPACE>>16);
409 par |= 0x72000000;
wdenk8bde7f72003-06-27 21:31:46 +0000410
wdenk7a8e9bed2003-05-31 18:35:21 +0000411 printf ("setting PAR1 to %x\n", par);
wdenk8bde7f72003-06-27 21:31:46 +0000412
wdenk7a8e9bed2003-05-31 18:35:21 +0000413 /* Map rom 0x10000 with PAR1 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000414 sc520_mmcr->par[1] = par;
wdenk8bde7f72003-06-27 21:31:46 +0000415
wdenk7a8e9bed2003-05-31 18:35:21 +0000416 return PCI_ROM_TEMP_SPACE;
417}
418
419/*
420 * this function removed any mapping created
421 * with pci_get_rom_window()
422 */
423void pci_remove_rom_window(struct pci_controller *hose, u32 addr)
424{
425 printf("pci_remove_rom_window: %x", addr);
426 if (addr == PCI_ROM_TEMP_SPACE) {
Graeme Russed7a1b62009-08-23 12:59:56 +1000427 sc520_mmcr->par[1] = 0;
wdenk7a8e9bed2003-05-31 18:35:21 +0000428 printf(" done\n");
429 return;
430 }
431 printf(" not ours\n");
wdenk8bde7f72003-06-27 21:31:46 +0000432
wdenk7a8e9bed2003-05-31 18:35:21 +0000433}
434
435/*
436 * This function is called in order to provide acces to the
wdenk8bde7f72003-06-27 21:31:46 +0000437 * legacy video I/O ports on the PCI bus.
438 * After this function accesses to I/O ports 0x3b0-0x3bb and
wdenk7a8e9bed2003-05-31 18:35:21 +0000439 * 0x3c0-0x3df shuld result in transactions on the PCI bus.
wdenk8bde7f72003-06-27 21:31:46 +0000440 *
wdenk7a8e9bed2003-05-31 18:35:21 +0000441 */
442int pci_enable_legacy_video_ports(struct pci_controller *hose)
443{
444 /* Map video memory to 0xa0000*/
Graeme Russed7a1b62009-08-23 12:59:56 +1000445 sc520_mmcr->par[0] = 0x7200400a;
wdenk8bde7f72003-06-27 21:31:46 +0000446
wdenk7a8e9bed2003-05-31 18:35:21 +0000447 /* forward all I/O accesses to PCI */
Graeme Russed7a1b62009-08-23 12:59:56 +1000448 sc520_mmcr->adddecctl = sc520_mmcr->adddecctl | IO_HOLE_DEST_PCI;
wdenk8bde7f72003-06-27 21:31:46 +0000449
450
wdenk7a8e9bed2003-05-31 18:35:21 +0000451 /* so we map away all io ports to pci (only way to access pci io
452 * below 0x400. But then we have to map back the portions that we dont
453 * use so that the generate cycles on the GPIO bus where the sio and
wdenk8bde7f72003-06-27 21:31:46 +0000454 * ISA slots are connected, this requre the use of several PAR registers
wdenk7a8e9bed2003-05-31 18:35:21 +0000455 */
wdenk8bde7f72003-06-27 21:31:46 +0000456
wdenk7a8e9bed2003-05-31 18:35:21 +0000457 /* bring 0x100 - 0x2f7 back to ISA using PAR5 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000458 sc520_mmcr->par[5] = 0x31f70100;
wdenk8bde7f72003-06-27 21:31:46 +0000459
wdenk7a8e9bed2003-05-31 18:35:21 +0000460 /* com2 use 2f8-2ff */
wdenk8bde7f72003-06-27 21:31:46 +0000461
wdenk7a8e9bed2003-05-31 18:35:21 +0000462 /* bring 0x300 - 0x3af back to ISA using PAR7 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000463 sc520_mmcr->par[7] = 0x30af0300;
wdenk8bde7f72003-06-27 21:31:46 +0000464
wdenk7a8e9bed2003-05-31 18:35:21 +0000465 /* vga use 3b0-3bb */
wdenk8bde7f72003-06-27 21:31:46 +0000466
wdenk7a8e9bed2003-05-31 18:35:21 +0000467 /* bring 0x3bc - 0x3bf back to ISA using PAR8 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000468 sc520_mmcr->par[8] = 0x300303bc;
wdenk8bde7f72003-06-27 21:31:46 +0000469
wdenk7a8e9bed2003-05-31 18:35:21 +0000470 /* vga use 3c0-3df */
wdenk8bde7f72003-06-27 21:31:46 +0000471
wdenk7a8e9bed2003-05-31 18:35:21 +0000472 /* bring 0x3e0 - 0x3f7 back to ISA using PAR9 */
Graeme Russed7a1b62009-08-23 12:59:56 +1000473 sc520_mmcr->par[9] = 0x301703e0;
wdenk8bde7f72003-06-27 21:31:46 +0000474
475 /* com1 use 3f8-3ff */
wdenk7a8e9bed2003-05-31 18:35:21 +0000476
477 return 0;
478}
479#endif
480
481/*
482 * Miscelaneous platform dependent initialisations
483 */
484
485int board_init(void)
486{
wdenk8bde7f72003-06-27 21:31:46 +0000487 init_sc520();
wdenk7a8e9bed2003-05-31 18:35:21 +0000488 bus_init();
489 irq_init();
wdenk8bde7f72003-06-27 21:31:46 +0000490
wdenk7a8e9bed2003-05-31 18:35:21 +0000491 /* max drive current on SDRAM */
Graeme Russed7a1b62009-08-23 12:59:56 +1000492 sc520_mmcr->dsctl = 0x0100;
wdenk8bde7f72003-06-27 21:31:46 +0000493
wdenk7a8e9bed2003-05-31 18:35:21 +0000494 /* enter debug mode after next reset (only if jumper is also set) */
Graeme Russed7a1b62009-08-23 12:59:56 +1000495 sc520_mmcr->rescfg = 0x08;
wdenk7a8e9bed2003-05-31 18:35:21 +0000496 /* configure the software timer to 33.000MHz */
Graeme Russed7a1b62009-08-23 12:59:56 +1000497 sc520_mmcr->swtmrcfg = 1;
wdenk7a8e9bed2003-05-31 18:35:21 +0000498 gd->bus_clk = 33000000;
wdenk8bde7f72003-06-27 21:31:46 +0000499
wdenk7a8e9bed2003-05-31 18:35:21 +0000500 return 0;
501}
502
503int dram_init(void)
504{
505 init_sc520_dram();
506 return 0;
507}
508
509void show_boot_progress(int val)
510{
Graeme Russed7a1b62009-08-23 12:59:56 +1000511 int version = sc520_mmcr->sysinfo;
wdenk8bde7f72003-06-27 21:31:46 +0000512
Heiko Schocher566a4942007-06-22 19:11:54 +0200513 if (val < -32) val = -1; /* let things compatible */
wdenk7a8e9bed2003-05-31 18:35:21 +0000514 if (version == 0) {
515 /* PIO31-PIO16 Data */
Graeme Russed7a1b62009-08-23 12:59:56 +1000516 sc520_mmcr->piodata31_16 = (sc520_mmcr->piodata31_16 & 0xffc0) | ((val&0x7e)>>1); /* 0x1f8 >> 3 */
wdenk8bde7f72003-06-27 21:31:46 +0000517
wdenk7a8e9bed2003-05-31 18:35:21 +0000518 /* PIO0-PIO15 Data */
Graeme Russed7a1b62009-08-23 12:59:56 +1000519 sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0x1fff)| ((val&0x7)<<13);
wdenk7a8e9bed2003-05-31 18:35:21 +0000520 } else {
521 /* newer boards use PIO4-PIO12 */
522 /* PIO0-PIO15 Data */
wdenk8bde7f72003-06-27 21:31:46 +0000523#if 0
524 val = (val & 0x007) | ((val & 0x038) << 3) | ((val & 0x1c0) >> 3);
wdenk7a8e9bed2003-05-31 18:35:21 +0000525#else
wdenk8bde7f72003-06-27 21:31:46 +0000526 val = (val & 0x007) | ((val & 0x07e) << 2);
wdenk7a8e9bed2003-05-31 18:35:21 +0000527#endif
Graeme Russed7a1b62009-08-23 12:59:56 +1000528 sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0xe00f) | ((val&0x01ff)<<4);
wdenk7a8e9bed2003-05-31 18:35:21 +0000529 }
530}
531
532
533int last_stage_init(void)
534{
wdenk8bde7f72003-06-27 21:31:46 +0000535
Graeme Russed7a1b62009-08-23 12:59:56 +1000536 int version = sc520_mmcr->sysinfo;
wdenk8bde7f72003-06-27 21:31:46 +0000537
wdenk7a8e9bed2003-05-31 18:35:21 +0000538 printf("Omicron Ceti SC520 Spunk revision %x\n", version);
wdenk8bde7f72003-06-27 21:31:46 +0000539
wdenk7a8e9bed2003-05-31 18:35:21 +0000540#if 0
541 if (version) {
542 int x, y;
wdenk8bde7f72003-06-27 21:31:46 +0000543
wdenk7a8e9bed2003-05-31 18:35:21 +0000544 printf("eeprom probe %d\n", spi_eeprom_probe(1));
wdenk8bde7f72003-06-27 21:31:46 +0000545
wdenk7a8e9bed2003-05-31 18:35:21 +0000546 spi_eeprom_read(1, 0, (u8*)&x, 2);
547 spi_eeprom_read(1, 1, (u8*)&y, 2);
548 printf("eeprom bytes %04x%04x\n", x, y);
549 x ^= 0xffff;
550 y ^= 0xffff;
551 spi_eeprom_write(1, 0, (u8*)&x, 2);
552 spi_eeprom_write(1, 1, (u8*)&y, 2);
wdenk8bde7f72003-06-27 21:31:46 +0000553
wdenk7a8e9bed2003-05-31 18:35:21 +0000554 spi_eeprom_read(1, 0, (u8*)&x, 2);
555 spi_eeprom_read(1, 1, (u8*)&y, 2);
556 printf("eeprom bytes %04x%04x\n", x, y);
wdenk8bde7f72003-06-27 21:31:46 +0000557
wdenk7a8e9bed2003-05-31 18:35:21 +0000558 } else {
559 int x, y;
wdenk8bde7f72003-06-27 21:31:46 +0000560
wdenk7a8e9bed2003-05-31 18:35:21 +0000561 printf("eeprom probe %d\n", mw_eeprom_probe(1));
wdenk8bde7f72003-06-27 21:31:46 +0000562
wdenk7a8e9bed2003-05-31 18:35:21 +0000563 mw_eeprom_read(1, 0, (u8*)&x, 2);
564 mw_eeprom_read(1, 1, (u8*)&y, 2);
565 printf("eeprom bytes %04x%04x\n", x, y);
wdenk8bde7f72003-06-27 21:31:46 +0000566
wdenk7a8e9bed2003-05-31 18:35:21 +0000567 x ^= 0xffff;
568 y ^= 0xffff;
569 mw_eeprom_write(1, 0, (u8*)&x, 2);
570 mw_eeprom_write(1, 1, (u8*)&y, 2);
wdenk8bde7f72003-06-27 21:31:46 +0000571
wdenk7a8e9bed2003-05-31 18:35:21 +0000572 mw_eeprom_read(1, 0, (u8*)&x, 2);
573 mw_eeprom_read(1, 1, (u8*)&y, 2);
574 printf("eeprom bytes %04x%04x\n", x, y);
wdenk8bde7f72003-06-27 21:31:46 +0000575
576
wdenk7a8e9bed2003-05-31 18:35:21 +0000577 }
578#endif
579
580 ds1722_probe(2);
wdenk8bde7f72003-06-27 21:31:46 +0000581
wdenk7a8e9bed2003-05-31 18:35:21 +0000582 return 0;
583}
584
wdenk8bde7f72003-06-27 21:31:46 +0000585void ssi_chip_select(int dev)
wdenk7a8e9bed2003-05-31 18:35:21 +0000586{
Graeme Russed7a1b62009-08-23 12:59:56 +1000587 int version = sc520_mmcr->sysinfo;
wdenk8bde7f72003-06-27 21:31:46 +0000588
wdenk7a8e9bed2003-05-31 18:35:21 +0000589 if (version) {
590 /* Spunk board: EEPROM and CAN are actove-low, TEMP and AUX are active high */
591 switch (dev) {
592 case 1: /* EEPROM */
Graeme Russed7a1b62009-08-23 12:59:56 +1000593 sc520_mmcr->pioclr31_16 = 0x0004;
wdenk7a8e9bed2003-05-31 18:35:21 +0000594 break;
wdenk8bde7f72003-06-27 21:31:46 +0000595
wdenk7a8e9bed2003-05-31 18:35:21 +0000596 case 2: /* Temp Probe */
Graeme Russed7a1b62009-08-23 12:59:56 +1000597 sc520_mmcr->pioset31_16 = 0x0002;
wdenk7a8e9bed2003-05-31 18:35:21 +0000598 break;
wdenk8bde7f72003-06-27 21:31:46 +0000599
wdenk7a8e9bed2003-05-31 18:35:21 +0000600 case 3: /* CAN */
Graeme Russed7a1b62009-08-23 12:59:56 +1000601 sc520_mmcr->pioclr31_16 = 0x0008;
wdenk7a8e9bed2003-05-31 18:35:21 +0000602 break;
wdenk8bde7f72003-06-27 21:31:46 +0000603
604 case 4: /* AUX */
Graeme Russed7a1b62009-08-23 12:59:56 +1000605 sc520_mmcr->pioset31_16 = 0x0001;
wdenk7a8e9bed2003-05-31 18:35:21 +0000606 break;
wdenk8bde7f72003-06-27 21:31:46 +0000607
wdenk7a8e9bed2003-05-31 18:35:21 +0000608 case 0:
Graeme Russed7a1b62009-08-23 12:59:56 +1000609 sc520_mmcr->pioclr31_16 = 0x0003;
610 sc520_mmcr->pioset31_16 = 0x000c;
wdenk7a8e9bed2003-05-31 18:35:21 +0000611 break;
wdenk8bde7f72003-06-27 21:31:46 +0000612
wdenk7a8e9bed2003-05-31 18:35:21 +0000613 default:
614 printf("Illegal SSI device requested: %d\n", dev);
615 }
616 } else {
wdenk8bde7f72003-06-27 21:31:46 +0000617
wdenk7a8e9bed2003-05-31 18:35:21 +0000618 /* Globox board: Both EEPROM and TEMP are active-high */
619
620 switch (dev) {
621 case 1: /* EEPROM */
Graeme Russed7a1b62009-08-23 12:59:56 +1000622 sc520_mmcr->pioset15_0 = 0x0100;
wdenk7a8e9bed2003-05-31 18:35:21 +0000623 break;
wdenk8bde7f72003-06-27 21:31:46 +0000624
wdenk7a8e9bed2003-05-31 18:35:21 +0000625 case 2: /* Temp Probe */
Graeme Russed7a1b62009-08-23 12:59:56 +1000626 sc520_mmcr->pioset15_0 = 0x0080;
wdenk7a8e9bed2003-05-31 18:35:21 +0000627 break;
wdenk8bde7f72003-06-27 21:31:46 +0000628
wdenk7a8e9bed2003-05-31 18:35:21 +0000629 case 0:
Graeme Russed7a1b62009-08-23 12:59:56 +1000630 sc520_mmcr->pioclr15_0 = 0x0180;
wdenk7a8e9bed2003-05-31 18:35:21 +0000631 break;
wdenk8bde7f72003-06-27 21:31:46 +0000632
wdenk7a8e9bed2003-05-31 18:35:21 +0000633 default:
634 printf("Illegal SSI device requested: %d\n", dev);
635 }
wdenk8bde7f72003-06-27 21:31:46 +0000636 }
wdenk7a8e9bed2003-05-31 18:35:21 +0000637}
638
Graeme Russ91ee4e12009-08-23 12:59:54 +1000639void spi_eeprom_probe(int x)
640{
641}
642
643int spi_eeprom_read(int x, int offset, uchar *buffer, int len)
644{
645 return 0;
646}
647
648int spi_eeprom_write(int x, int offset, uchar *buffer, int len)
649{
650 return 0;
651}
652
653void mw_eeprom_probe(int x)
654{
655}
656
657int mw_eeprom_read(int x, int offset, uchar *buffer, int len)
658{
659 return 0;
660}
661
662int mw_eeprom_write(int x, int offset, uchar *buffer, int len)
663{
664 return 0;
665}
wdenk7a8e9bed2003-05-31 18:35:21 +0000666
wdenk8bde7f72003-06-27 21:31:46 +0000667void spi_init_f(void)
wdenk7a8e9bed2003-05-31 18:35:21 +0000668{
Graeme Russed7a1b62009-08-23 12:59:56 +1000669 sc520_mmcr->sysinfo ? spi_eeprom_probe(1) : mw_eeprom_probe(1);
wdenk8bde7f72003-06-27 21:31:46 +0000670
wdenk7a8e9bed2003-05-31 18:35:21 +0000671}
672
wdenk8bde7f72003-06-27 21:31:46 +0000673ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
wdenk7a8e9bed2003-05-31 18:35:21 +0000674{
675 int offset;
676 int i;
wdenk8bde7f72003-06-27 21:31:46 +0000677
wdenk7a8e9bed2003-05-31 18:35:21 +0000678 offset = 0;
679 for (i=0;i<alen;i++) {
680 offset <<= 8;
681 offset |= addr[i];
682 }
wdenk8bde7f72003-06-27 21:31:46 +0000683
Graeme Russed7a1b62009-08-23 12:59:56 +1000684 return sc520_mmcr->sysinfo ?
wdenk8bde7f72003-06-27 21:31:46 +0000685 spi_eeprom_read(1, offset, buffer, len) :
wdenk7a8e9bed2003-05-31 18:35:21 +0000686 mw_eeprom_read(1, offset, buffer, len);
687}
688
wdenk8bde7f72003-06-27 21:31:46 +0000689ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
wdenk7a8e9bed2003-05-31 18:35:21 +0000690{
691 int offset;
692 int i;
wdenk8bde7f72003-06-27 21:31:46 +0000693
wdenk7a8e9bed2003-05-31 18:35:21 +0000694 offset = 0;
695 for (i=0;i<alen;i++) {
696 offset <<= 8;
697 offset |= addr[i];
698 }
wdenk8bde7f72003-06-27 21:31:46 +0000699
Graeme Russed7a1b62009-08-23 12:59:56 +1000700 return sc520_mmcr->sysinfo ?
wdenk8bde7f72003-06-27 21:31:46 +0000701 spi_eeprom_write(1, offset, buffer, len) :
wdenk7a8e9bed2003-05-31 18:35:21 +0000702 mw_eeprom_write(1, offset, buffer, len);
703}
Ben Warren10efa022008-08-31 20:37:00 -0700704
705int board_eth_init(bd_t *bis)
706{
707 return pci_eth_init(bis);
708}