wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 1 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2 | * |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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 <pci.h> |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 27 | #include <netdev.h> |
Graeme Russ | 91ee4e1 | 2009-08-23 12:59:54 +1000 | [diff] [blame] | 28 | #include <ds1722.h> |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 29 | #include <asm/io.h> |
| 30 | #include <asm/pci.h> |
| 31 | #include <asm/ic/sc520.h> |
Graeme Russ | 91ee4e1 | 2009-08-23 12:59:54 +1000 | [diff] [blame] | 32 | #include <asm/ic/pci.h> |
| 33 | #include <asm/ic/ssi.h> |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 34 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 35 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 36 | |
| 37 | /* |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 38 | * Theory: |
| 39 | * We first set up all IRQs to be non-pci, edge triggered, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 40 | * when we later enumerate the pci bus and pci_sc520_fixup_irq() gets |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 41 | * 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 | |
| 47 | static void irq_init(void) |
| 48 | { |
| 49 | /* disable global interrupt mode */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 50 | sc520_mmcr->picicr = 0x40; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 51 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 52 | /* set all irqs to edge */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 53 | sc520_mmcr->pic_mode[0] = 0x00; |
| 54 | sc520_mmcr->pic_mode[1] = 0x00; |
| 55 | sc520_mmcr->pic_mode[2] = 0x00; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | |
| 57 | /* active low polarity on PIC interrupt pins, |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 58 | * active high polarity on all other irq pins */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 59 | sc520_mmcr->intpinpol = 0x0000; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 60 | |
| 61 | /* set irq number mapping */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 62 | 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 */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 79 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 80 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 81 | 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 */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 83 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 84 | 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 */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 98 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 99 | } |
| 100 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 101 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 102 | /* PCI stuff */ |
| 103 | static void pci_sc520_spunk_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 104 | { |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 105 | int version = sc520_mmcr->sysinfo; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 107 | /* 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 111 | CONFIG_SYS_FIRST_PCI_IRQ, |
| 112 | CONFIG_SYS_SECOND_PCI_IRQ, |
| 113 | CONFIG_SYS_THIRD_PCI_IRQ, |
| 114 | CONFIG_SYS_FORTH_PCI_IRQ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 115 | }; |
| 116 | static int next_irq_index=0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 117 | |
Graeme Russ | 91ee4e1 | 2009-08-23 12:59:54 +1000 | [diff] [blame] | 118 | uchar tmp_pin; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 119 | int pin; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 120 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 121 | pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin); |
| 122 | pin = tmp_pin; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 123 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 124 | pin-=1; /* pci config space use 1-based numbering */ |
| 125 | if (-1 == pin) { |
| 126 | return; /* device use no irq */ |
| 127 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 128 | |
| 129 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 130 | /* map device number + pin to a pin on the sc520 */ |
| 131 | switch (PCI_DEV(dev)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 132 | case 6: /* ETH0 */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 133 | pin+=SC520_PCI_INTA; |
| 134 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 136 | case 7: /* ETH1 */ |
| 137 | pin+=SC520_PCI_INTB; |
| 138 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 139 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 140 | case 8: /* Crypto */ |
| 141 | pin+=SC520_PCI_INTC; |
| 142 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 143 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 144 | case 9: /* PMC slot */ |
| 145 | pin+=SC520_PCI_INTD; |
| 146 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 147 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 148 | case 10: /* PC-Card */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 149 | |
| 150 | if (version < 10) { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 151 | pin+=SC520_PCI_INTD; |
| 152 | } else { |
| 153 | pin+=SC520_PCI_INTC; |
| 154 | } |
| 155 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 156 | |
| 157 | default: |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 158 | return; |
| 159 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 161 | pin&=3; /* wrap around */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 162 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 163 | if (sc520_pci_ints[pin] == -1) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 164 | /* re-route one interrupt for us */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 165 | if (next_irq_index > 3) { |
| 166 | return; |
| 167 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 168 | if (pci_sc520_set_irq(pin, irq_list[next_irq_index])) { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 169 | return; |
| 170 | } |
| 171 | next_irq_index++; |
| 172 | } |
| 173 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 174 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 175 | if (-1 != sc520_pci_ints[pin]) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 176 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 177 | sc520_pci_ints[pin]); |
| 178 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 179 | #if 0 |
| 180 | printf("fixup_irq: device %d pin %c irq %d\n", |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 181 | PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]); |
| 182 | #endif |
| 183 | } |
| 184 | |
| 185 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 186 | static void pci_sc520_spunk_configure_cardbus(struct pci_controller *hose, |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 187 | pci_dev_t dev, struct pci_config_table *te) |
| 188 | { |
| 189 | u32 io_base; |
| 190 | u32 temp; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 191 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 192 | pciauto_config_device(hose, dev); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 193 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 194 | 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 */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 201 | |
| 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 |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 205 | * reserve all others */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | pci_hose_write_config_dword(hose, dev, 0x8c, 0x00007002); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 207 | pci_hose_write_config_byte(hose, dev, 0x91, 0x00); /* card control */ |
| 208 | pci_hose_write_config_byte(hose, dev, 0x92, 0x62); /* device control */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 209 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 210 | 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 */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 220 | |
| 221 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 222 | pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &io_base); |
| 223 | io_base &= ~0xfL; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 224 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 225 | 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 */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 228 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 232 | static struct pci_config_table pci_sc520_spunk_config_table[] = { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 233 | { 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} }, |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 235 | { 0, 0, 0, 0, 0, 0, NULL, {0,0,0}} |
| 236 | }; |
| 237 | |
| 238 | static 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 | |
| 245 | void 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 */ |
| 252 | static void bus_init(void) |
| 253 | { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 254 | /* versions |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 255 | * 0 Hyglo versions 0.95 and 0.96 (large baords) |
| 256 | * ?? Hyglo version 0.97 (small board) |
| 257 | * 10 Spunk board |
| 258 | */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 259 | int version = sc520_mmcr->sysinfo; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 260 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 261 | if (version) { |
| 262 | /* set up the GP IO pins (for the Spunk board) */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 263 | 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; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 269 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 270 | sc520_mmcr->pioclr31_16 = 0x0003; /* reset SSI chip-selects */ |
| 271 | sc520_mmcr->pioset31_16 = 0x000c; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 272 | |
| 273 | } else { |
| 274 | /* set up the GP IO pins (for the Hyglo board) */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 275 | 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; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 281 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 282 | sc520_mmcr->pioclr15_0 = 0x0180; /* reset SSI chip-selects */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 283 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 284 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 285 | 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 */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 292 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 293 | sc520_mmcr->bootcsctl = 0x0407; /* set up timing of BOOTCS */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 294 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 295 | /* 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 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 298 | * we need to map 1G-128k - 1G (0x38000000 - 0x3fffffff) to CS1 */ |
| 299 | |
| 300 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 301 | /* bootcs */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 302 | sc520_mmcr->par[12] = 0x8bffe800; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 303 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 304 | /* IDE0 = GPCS6 1f0-1f7 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 305 | sc520_mmcr->par[3] = 0x380801f0; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 306 | |
| 307 | /* IDE1 = GPCS7 3f6 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 308 | sc520_mmcr->par[4] = 0x3c0003f6; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 309 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 310 | asm ("wbinvd\n"); /* Flush cache, req. after setting the unchached attribute ona PAR */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 311 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 312 | sc520_mmcr->adddecctl = sc520_mmcr->adddecctl & ~(UART2_DIS|UART1_DIS); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 313 | |
| 314 | } |
| 315 | |
| 316 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 317 | /* par usage: |
| 318 | * PAR0 (legacy_video) |
| 319 | * PAR1 (PCI ROM mapping) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 320 | * PAR2 |
| 321 | * PAR3 IDE |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 322 | * PAR4 IDE |
| 323 | * PAR5 (legacy_video) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 324 | * PAR6 |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 325 | * 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 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 336 | /* |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 337 | * This function should map a chunk of size bytes |
| 338 | * of the system address space to the ISA bus |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 339 | * |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 340 | * 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 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 344 | u32 isa_map_rom(u32 bus_addr, int size) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 345 | { |
| 346 | u32 par; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 347 | |
| 348 | printf("isa_map_rom asked to map %d bytes at %x\n", |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 349 | size, bus_addr); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 350 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 351 | 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; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 361 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 362 | printf ("setting PAR11 to %x\n", par); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 363 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 364 | /* Map rom 0x10000 with PAR1 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 365 | sc520_mmcr->par[11] = par; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 366 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 367 | return bus_addr; |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * this function removed any mapping created |
| 372 | * with pci_get_rom_window() |
| 373 | */ |
| 374 | void isa_unmap_rom(u32 addr) |
| 375 | { |
| 376 | printf("isa_unmap_rom asked to unmap %x", addr); |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 377 | if ((addr>>12) == (sc520_mmcr->par[11] & 0x3ffff)) { |
| 378 | sc520_mmcr->par[11] = 0; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 379 | printf(" done\n"); |
| 380 | return; |
| 381 | } |
| 382 | printf(" not ours\n"); |
| 383 | } |
| 384 | |
| 385 | #ifdef CONFIG_PCI |
| 386 | #define PCI_ROM_TEMP_SPACE 0x10000 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 387 | /* |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 388 | * 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 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 393 | * before used to configure the PCI rom address |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 394 | * decoder |
| 395 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 396 | u32 pci_get_rom_window(struct pci_controller *hose, int size) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 397 | { |
| 398 | u32 par; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 399 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 400 | 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; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 410 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 411 | printf ("setting PAR1 to %x\n", par); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 412 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 413 | /* Map rom 0x10000 with PAR1 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 414 | sc520_mmcr->par[1] = par; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 415 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 416 | return PCI_ROM_TEMP_SPACE; |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * this function removed any mapping created |
| 421 | * with pci_get_rom_window() |
| 422 | */ |
| 423 | void 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 Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 427 | sc520_mmcr->par[1] = 0; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 428 | printf(" done\n"); |
| 429 | return; |
| 430 | } |
| 431 | printf(" not ours\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 432 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* |
| 436 | * This function is called in order to provide acces to the |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 437 | * legacy video I/O ports on the PCI bus. |
| 438 | * After this function accesses to I/O ports 0x3b0-0x3bb and |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 439 | * 0x3c0-0x3df shuld result in transactions on the PCI bus. |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 440 | * |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 441 | */ |
| 442 | int pci_enable_legacy_video_ports(struct pci_controller *hose) |
| 443 | { |
| 444 | /* Map video memory to 0xa0000*/ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 445 | sc520_mmcr->par[0] = 0x7200400a; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 446 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 447 | /* forward all I/O accesses to PCI */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 448 | sc520_mmcr->adddecctl = sc520_mmcr->adddecctl | IO_HOLE_DEST_PCI; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 449 | |
| 450 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 451 | /* 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 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 454 | * ISA slots are connected, this requre the use of several PAR registers |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 455 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 456 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 457 | /* bring 0x100 - 0x2f7 back to ISA using PAR5 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 458 | sc520_mmcr->par[5] = 0x31f70100; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 459 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 460 | /* com2 use 2f8-2ff */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 461 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 462 | /* bring 0x300 - 0x3af back to ISA using PAR7 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 463 | sc520_mmcr->par[7] = 0x30af0300; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 464 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 465 | /* vga use 3b0-3bb */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 466 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 467 | /* bring 0x3bc - 0x3bf back to ISA using PAR8 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 468 | sc520_mmcr->par[8] = 0x300303bc; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 469 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 470 | /* vga use 3c0-3df */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 471 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 472 | /* bring 0x3e0 - 0x3f7 back to ISA using PAR9 */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 473 | sc520_mmcr->par[9] = 0x301703e0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 474 | |
| 475 | /* com1 use 3f8-3ff */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | #endif |
| 480 | |
| 481 | /* |
| 482 | * Miscelaneous platform dependent initialisations |
| 483 | */ |
| 484 | |
| 485 | int board_init(void) |
| 486 | { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 487 | init_sc520(); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 488 | bus_init(); |
| 489 | irq_init(); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 490 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 491 | /* max drive current on SDRAM */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 492 | sc520_mmcr->dsctl = 0x0100; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 493 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 494 | /* enter debug mode after next reset (only if jumper is also set) */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 495 | sc520_mmcr->rescfg = 0x08; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 496 | /* configure the software timer to 33.000MHz */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 497 | sc520_mmcr->swtmrcfg = 1; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 498 | gd->bus_clk = 33000000; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 499 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | int dram_init(void) |
| 504 | { |
| 505 | init_sc520_dram(); |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | void show_boot_progress(int val) |
| 510 | { |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 511 | int version = sc520_mmcr->sysinfo; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 512 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 513 | if (val < -32) val = -1; /* let things compatible */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 514 | if (version == 0) { |
| 515 | /* PIO31-PIO16 Data */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 516 | sc520_mmcr->piodata31_16 = (sc520_mmcr->piodata31_16 & 0xffc0) | ((val&0x7e)>>1); /* 0x1f8 >> 3 */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 517 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 518 | /* PIO0-PIO15 Data */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 519 | sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0x1fff)| ((val&0x7)<<13); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 520 | } else { |
| 521 | /* newer boards use PIO4-PIO12 */ |
| 522 | /* PIO0-PIO15 Data */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 523 | #if 0 |
| 524 | val = (val & 0x007) | ((val & 0x038) << 3) | ((val & 0x1c0) >> 3); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 525 | #else |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 526 | val = (val & 0x007) | ((val & 0x07e) << 2); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 527 | #endif |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 528 | sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0xe00f) | ((val&0x01ff)<<4); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
| 532 | |
| 533 | int last_stage_init(void) |
| 534 | { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 535 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 536 | int version = sc520_mmcr->sysinfo; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 537 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 538 | printf("Omicron Ceti SC520 Spunk revision %x\n", version); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 539 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 540 | #if 0 |
| 541 | if (version) { |
| 542 | int x, y; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 543 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 544 | printf("eeprom probe %d\n", spi_eeprom_probe(1)); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 545 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 546 | 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); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 553 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 554 | 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); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 557 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 558 | } else { |
| 559 | int x, y; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 560 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 561 | printf("eeprom probe %d\n", mw_eeprom_probe(1)); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 562 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 563 | 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); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 566 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 567 | x ^= 0xffff; |
| 568 | y ^= 0xffff; |
| 569 | mw_eeprom_write(1, 0, (u8*)&x, 2); |
| 570 | mw_eeprom_write(1, 1, (u8*)&y, 2); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 571 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 572 | 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); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 575 | |
| 576 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 577 | } |
| 578 | #endif |
| 579 | |
| 580 | ds1722_probe(2); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 581 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 582 | return 0; |
| 583 | } |
| 584 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 585 | void ssi_chip_select(int dev) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 586 | { |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 587 | int version = sc520_mmcr->sysinfo; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 588 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 589 | 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 Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 593 | sc520_mmcr->pioclr31_16 = 0x0004; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 594 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 595 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 596 | case 2: /* Temp Probe */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 597 | sc520_mmcr->pioset31_16 = 0x0002; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 598 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 599 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 600 | case 3: /* CAN */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 601 | sc520_mmcr->pioclr31_16 = 0x0008; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 602 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 603 | |
| 604 | case 4: /* AUX */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 605 | sc520_mmcr->pioset31_16 = 0x0001; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 606 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 607 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 608 | case 0: |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 609 | sc520_mmcr->pioclr31_16 = 0x0003; |
| 610 | sc520_mmcr->pioset31_16 = 0x000c; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 611 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 612 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 613 | default: |
| 614 | printf("Illegal SSI device requested: %d\n", dev); |
| 615 | } |
| 616 | } else { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 617 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 618 | /* Globox board: Both EEPROM and TEMP are active-high */ |
| 619 | |
| 620 | switch (dev) { |
| 621 | case 1: /* EEPROM */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 622 | sc520_mmcr->pioset15_0 = 0x0100; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 623 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 624 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 625 | case 2: /* Temp Probe */ |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 626 | sc520_mmcr->pioset15_0 = 0x0080; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 627 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 628 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 629 | case 0: |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 630 | sc520_mmcr->pioclr15_0 = 0x0180; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 631 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 632 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 633 | default: |
| 634 | printf("Illegal SSI device requested: %d\n", dev); |
| 635 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 636 | } |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Graeme Russ | 91ee4e1 | 2009-08-23 12:59:54 +1000 | [diff] [blame] | 639 | void spi_eeprom_probe(int x) |
| 640 | { |
| 641 | } |
| 642 | |
| 643 | int spi_eeprom_read(int x, int offset, uchar *buffer, int len) |
| 644 | { |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | int spi_eeprom_write(int x, int offset, uchar *buffer, int len) |
| 649 | { |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | void mw_eeprom_probe(int x) |
| 654 | { |
| 655 | } |
| 656 | |
| 657 | int mw_eeprom_read(int x, int offset, uchar *buffer, int len) |
| 658 | { |
| 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | int mw_eeprom_write(int x, int offset, uchar *buffer, int len) |
| 663 | { |
| 664 | return 0; |
| 665 | } |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 666 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 667 | void spi_init_f(void) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 668 | { |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 669 | sc520_mmcr->sysinfo ? spi_eeprom_probe(1) : mw_eeprom_probe(1); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 670 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 671 | } |
| 672 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 673 | ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 674 | { |
| 675 | int offset; |
| 676 | int i; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 677 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 678 | offset = 0; |
| 679 | for (i=0;i<alen;i++) { |
| 680 | offset <<= 8; |
| 681 | offset |= addr[i]; |
| 682 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 683 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 684 | return sc520_mmcr->sysinfo ? |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 685 | spi_eeprom_read(1, offset, buffer, len) : |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 686 | mw_eeprom_read(1, offset, buffer, len); |
| 687 | } |
| 688 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 689 | ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 690 | { |
| 691 | int offset; |
| 692 | int i; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 693 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 694 | offset = 0; |
| 695 | for (i=0;i<alen;i++) { |
| 696 | offset <<= 8; |
| 697 | offset |= addr[i]; |
| 698 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 699 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame^] | 700 | return sc520_mmcr->sysinfo ? |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 701 | spi_eeprom_write(1, offset, buffer, len) : |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 702 | mw_eeprom_write(1, offset, buffer, len); |
| 703 | } |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 704 | |
| 705 | int board_eth_init(bd_t *bis) |
| 706 | { |
| 707 | return pci_eth_init(bis); |
| 708 | } |