wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* stuff specific for the sc520, |
| 25 | * but idependent of implementation */ |
| 26 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 27 | #include <config.h> |
| 28 | |
| 29 | #ifdef CONFIG_SC520 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 30 | |
| 31 | #include <common.h> |
| 32 | #include <config.h> |
| 33 | #include <pci.h> |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 34 | #include <ssi.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 35 | #include <asm/io.h> |
| 36 | #include <asm/pci.h> |
| 37 | #include <asm/ic/sc520.h> |
| 38 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame^] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 41 | /* |
| 42 | * utility functions for boards based on the AMD sc520 |
| 43 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | * void write_mmcr_byte(u16 mmcr, u8 data) |
| 45 | * void write_mmcr_word(u16 mmcr, u16 data) |
| 46 | * void write_mmcr_long(u16 mmcr, u32 data) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 48 | * u8 read_mmcr_byte(u16 mmcr) |
| 49 | * u16 read_mmcr_word(u16 mmcr) |
| 50 | * u32 read_mmcr_long(u16 mmcr) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 51 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 52 | * void init_sc520(void) |
| 53 | * unsigned long init_sc520_dram(void) |
| 54 | * void pci_sc520_init(struct pci_controller *hose) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 56 | * void reset_timer(void) |
| 57 | * ulong get_timer(ulong base) |
| 58 | * void set_timer(ulong t) |
| 59 | * void udelay(unsigned long usec) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 60 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 61 | */ |
| 62 | |
| 63 | static u32 mmcr_base= 0xfffef000; |
| 64 | |
| 65 | void write_mmcr_byte(u16 mmcr, u8 data) |
| 66 | { |
| 67 | writeb(data, mmcr+mmcr_base); |
| 68 | } |
| 69 | |
| 70 | void write_mmcr_word(u16 mmcr, u16 data) |
| 71 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | writew(data, mmcr+mmcr_base); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void write_mmcr_long(u16 mmcr, u32 data) |
| 76 | { |
| 77 | writel(data, mmcr+mmcr_base); |
| 78 | } |
| 79 | |
| 80 | u8 read_mmcr_byte(u16 mmcr) |
| 81 | { |
| 82 | return readb(mmcr+mmcr_base); |
| 83 | } |
| 84 | |
| 85 | u16 read_mmcr_word(u16 mmcr) |
| 86 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 87 | return readw(mmcr+mmcr_base); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | u32 read_mmcr_long(u16 mmcr) |
| 91 | { |
| 92 | return readl(mmcr+mmcr_base); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | void init_sc520(void) |
| 97 | { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 98 | /* Set the UARTxCTL register at it's slower, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 99 | * baud clock giving us a 1.8432 MHz reference |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 100 | */ |
| 101 | write_mmcr_byte(SC520_UART1CTL, 7); |
| 102 | write_mmcr_byte(SC520_UART2CTL, 7); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 104 | /* first set the timer pin mapping */ |
| 105 | write_mmcr_byte(SC520_CLKSEL, 0x72); /* no clock frequency selected, use 1.1892MHz */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 107 | /* enable PCI bus arbitrer */ |
| 108 | write_mmcr_byte(SC520_SYSARBCTL,0x02); /* enable concurrent mode */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 109 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 110 | write_mmcr_word(SC520_SYSARBMENB,0x1f); /* enable external grants */ |
| 111 | write_mmcr_word(SC520_HBCTL,0x04); /* enable posted-writes */ |
| 112 | |
| 113 | |
| 114 | if (CFG_SC520_HIGH_SPEED) { |
| 115 | write_mmcr_byte(SC520_CPUCTL, 0x2); /* set it to 133 MHz and write back */ |
| 116 | gd->cpu_clk = 133000000; |
| 117 | printf("## CPU Speed set to 133MHz\n"); |
| 118 | } else { |
| 119 | write_mmcr_byte(SC520_CPUCTL, 1); /* set CPU to 100 MHz and write back cache */ |
| 120 | printf("## CPU Speed set to 100MHz\n"); |
| 121 | gd->cpu_clk = 100000000; |
| 122 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 123 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 124 | |
| 125 | /* wait at least one millisecond */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 126 | asm("movl $0x2000,%%ecx\n" |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 127 | "wait_loop: pushl %%ecx\n" |
| 128 | "popl %%ecx\n" |
| 129 | "loop wait_loop\n": : : "ecx"); |
| 130 | |
| 131 | /* turn on the SDRAM write buffer */ |
| 132 | write_mmcr_byte(SC520_DBCTL, 0x11); |
| 133 | |
| 134 | /* turn on the cache and disable write through */ |
| 135 | asm("movl %%cr0, %%eax\n" |
| 136 | "andl $0x9fffffff, %%eax\n" |
| 137 | "movl %%eax, %%cr0\n" : : : "eax"); |
| 138 | } |
| 139 | |
| 140 | unsigned long init_sc520_dram(void) |
| 141 | { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 142 | bd_t *bd = gd->bd; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 143 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 144 | u32 dram_present=0; |
| 145 | u32 dram_ctrl; |
| 146 | |
| 147 | int val; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 148 | |
| 149 | int cas_precharge_delay = CFG_SDRAM_PRECHARGE_DELAY; |
| 150 | int refresh_rate = CFG_SDRAM_REFRESH_RATE; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 151 | int ras_cas_delay = CFG_SDRAM_RAS_CAS_DELAY; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 152 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 153 | /* set SDRAM speed here */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 154 | |
| 155 | refresh_rate/=78; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 156 | if (refresh_rate<=1) { |
| 157 | val = 0; /* 7.8us */ |
| 158 | } else if (refresh_rate==2) { |
| 159 | val = 1; /* 15.6us */ |
| 160 | } else if (refresh_rate==3 || refresh_rate==4) { |
| 161 | val = 2; /* 31.2us */ |
| 162 | } else { |
| 163 | val = 3; /* 62.4us */ |
| 164 | } |
| 165 | write_mmcr_byte(SC520_DRCCTL, (read_mmcr_byte(SC520_DRCCTL) & 0xcf) | (val<<4)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 166 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 167 | val = read_mmcr_byte(SC520_DRCTMCTL); |
| 168 | val &= 0xf0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 169 | |
| 170 | if (cas_precharge_delay==3) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 171 | val |= 0x04; /* 3T */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 172 | } else if (cas_precharge_delay==4) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 173 | val |= 0x08; /* 4T */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 174 | } else if (cas_precharge_delay>4) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 175 | val |= 0x0c; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 176 | } |
| 177 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 178 | if (ras_cas_delay > 3) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 179 | val |= 2; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 180 | } else { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 181 | val |= 1; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 182 | } |
| 183 | write_mmcr_byte(SC520_DRCTMCTL, val); |
| 184 | |
| 185 | |
| 186 | /* We read-back the configuration of the dram |
| 187 | * controller that the assembly code wrote */ |
| 188 | dram_ctrl = read_mmcr_long(SC520_DRCBENDADR); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 189 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 190 | |
| 191 | bd->bi_dram[0].start = 0; |
| 192 | if (dram_ctrl & 0x80) { |
| 193 | /* bank 0 enabled */ |
| 194 | dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 195 | bd->bi_dram[0].size = bd->bi_dram[1].start; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 196 | |
| 197 | } else { |
| 198 | bd->bi_dram[0].size = 0; |
| 199 | bd->bi_dram[1].start = bd->bi_dram[0].start; |
| 200 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 201 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 202 | if (dram_ctrl & 0x8000) { |
| 203 | /* bank 1 enabled */ |
| 204 | dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 205 | bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 206 | } else { |
| 207 | bd->bi_dram[1].size = 0; |
| 208 | bd->bi_dram[2].start = bd->bi_dram[1].start; |
| 209 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 210 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 211 | if (dram_ctrl & 0x800000) { |
| 212 | /* bank 2 enabled */ |
| 213 | dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 214 | bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 215 | } else { |
| 216 | bd->bi_dram[2].size = 0; |
| 217 | bd->bi_dram[3].start = bd->bi_dram[2].start; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 218 | } |
| 219 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 220 | if (dram_ctrl & 0x80000000) { |
| 221 | /* bank 3 enabled */ |
| 222 | dram_present = (dram_ctrl & 0x7f000000) >> 2; |
| 223 | bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start; |
| 224 | } else { |
| 225 | bd->bi_dram[3].size = 0; |
| 226 | } |
| 227 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 228 | |
| 229 | #if 0 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 230 | printf("Configured %d bytes of dram\n", dram_present); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 231 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 232 | gd->ram_size = dram_present; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 233 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 234 | return dram_present; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | #ifdef CONFIG_PCI |
| 239 | |
| 240 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 241 | static struct { |
| 242 | u8 priority; |
| 243 | u16 level_reg; |
| 244 | u8 level_bit; |
| 245 | } sc520_irq[] = { |
| 246 | { SC520_IRQ0, SC520_MPICMODE, 0x01 }, |
| 247 | { SC520_IRQ1, SC520_MPICMODE, 0x02 }, |
| 248 | { SC520_IRQ2, SC520_SL1PICMODE, 0x02 }, |
| 249 | { SC520_IRQ3, SC520_MPICMODE, 0x08 }, |
| 250 | { SC520_IRQ4, SC520_MPICMODE, 0x10 }, |
| 251 | { SC520_IRQ5, SC520_MPICMODE, 0x20 }, |
| 252 | { SC520_IRQ6, SC520_MPICMODE, 0x40 }, |
| 253 | { SC520_IRQ7, SC520_MPICMODE, 0x80 }, |
| 254 | |
| 255 | { SC520_IRQ8, SC520_SL1PICMODE, 0x01 }, |
| 256 | { SC520_IRQ9, SC520_SL1PICMODE, 0x02 }, |
| 257 | { SC520_IRQ10, SC520_SL1PICMODE, 0x04 }, |
| 258 | { SC520_IRQ11, SC520_SL1PICMODE, 0x08 }, |
| 259 | { SC520_IRQ12, SC520_SL1PICMODE, 0x10 }, |
| 260 | { SC520_IRQ13, SC520_SL1PICMODE, 0x20 }, |
| 261 | { SC520_IRQ14, SC520_SL1PICMODE, 0x40 }, |
| 262 | { SC520_IRQ15, SC520_SL1PICMODE, 0x80 } |
| 263 | }; |
| 264 | |
| 265 | |
| 266 | /* The interrupt used for PCI INTA-INTD */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 267 | int sc520_pci_ints[15] = { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 268 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 269 | -1, -1, -1, -1, -1, -1, -1 |
| 270 | }; |
| 271 | |
| 272 | /* utility function to configure a pci interrupt */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 273 | int pci_sc520_set_irq(int pci_pin, int irq) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 274 | { |
| 275 | int i; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 276 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 277 | # if 0 |
| 278 | printf("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 279 | #endif |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 280 | if (irq < 0 || irq > 15) { |
| 281 | return -1; /* illegal irq */ |
| 282 | } |
| 283 | |
| 284 | if (pci_pin < 0 || pci_pin > 15) { |
| 285 | return -1; /* illegal pci int pin */ |
| 286 | } |
| 287 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 288 | /* first disable any non-pci interrupt source that use |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 289 | * this level */ |
| 290 | for (i=SC520_GPTMR0MAP;i<=SC520_GP10IMAP;i++) { |
| 291 | if (i>=SC520_PCIINTAMAP&&i<=SC520_PCIINTDMAP) { |
| 292 | continue; |
| 293 | } |
| 294 | if (read_mmcr_byte(i) == sc520_irq[irq].priority) { |
| 295 | write_mmcr_byte(i, SC520_IRQ_DISABLED); |
| 296 | } |
| 297 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 298 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 299 | /* Set the trigger to level */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 300 | write_mmcr_byte(sc520_irq[irq].level_reg, |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 301 | read_mmcr_byte(sc520_irq[irq].level_reg) | sc520_irq[irq].level_bit); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 302 | |
| 303 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 304 | if (pci_pin < 4) { |
| 305 | /* PCI INTA-INTD */ |
| 306 | /* route the interrupt */ |
| 307 | write_mmcr_byte(SC520_PCIINTAMAP + pci_pin, sc520_irq[irq].priority); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 308 | |
| 309 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 310 | } else { |
| 311 | /* GPIRQ0-GPIRQ10 used for additional PCI INTS */ |
| 312 | write_mmcr_byte(SC520_GP0IMAP + pci_pin - 4, sc520_irq[irq].priority); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 313 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 314 | /* also set the polarity in this case */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 315 | write_mmcr_word(SC520_INTPINPOL, |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 316 | read_mmcr_word(SC520_INTPINPOL) | (1 << (pci_pin-4))); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 317 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 318 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 319 | |
| 320 | /* register the pin */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 321 | sc520_pci_ints[pci_pin] = irq; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 322 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 323 | |
| 324 | return 0; /* OK */ |
| 325 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 326 | |
| 327 | void pci_sc520_init(struct pci_controller *hose) |
| 328 | { |
| 329 | hose->first_busno = 0; |
| 330 | hose->last_busno = 0xff; |
| 331 | |
| 332 | /* System memory space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 333 | pci_set_region(hose->regions + 0, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 334 | SC520_PCI_MEMORY_BUS, |
| 335 | SC520_PCI_MEMORY_PHYS, |
| 336 | SC520_PCI_MEMORY_SIZE, |
| 337 | PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 338 | |
| 339 | /* PCI memory space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 340 | pci_set_region(hose->regions + 1, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 341 | SC520_PCI_MEM_BUS, |
| 342 | SC520_PCI_MEM_PHYS, |
| 343 | SC520_PCI_MEM_SIZE, |
| 344 | PCI_REGION_MEM); |
| 345 | |
| 346 | /* ISA/PCI memory space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 347 | pci_set_region(hose->regions + 2, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 348 | SC520_ISA_MEM_BUS, |
| 349 | SC520_ISA_MEM_PHYS, |
| 350 | SC520_ISA_MEM_SIZE, |
| 351 | PCI_REGION_MEM); |
| 352 | |
| 353 | /* PCI I/O space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 354 | pci_set_region(hose->regions + 3, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 355 | SC520_PCI_IO_BUS, |
| 356 | SC520_PCI_IO_PHYS, |
| 357 | SC520_PCI_IO_SIZE, |
| 358 | PCI_REGION_IO); |
| 359 | |
| 360 | /* ISA/PCI I/O space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 361 | pci_set_region(hose->regions + 4, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 362 | SC520_ISA_IO_BUS, |
| 363 | SC520_ISA_IO_PHYS, |
| 364 | SC520_ISA_IO_SIZE, |
| 365 | PCI_REGION_IO); |
| 366 | |
| 367 | hose->region_count = 5; |
| 368 | |
| 369 | pci_setup_type1(hose, |
| 370 | SC520_REG_ADDR, |
| 371 | SC520_REG_DATA); |
| 372 | |
| 373 | pci_register_hose(hose); |
| 374 | |
| 375 | hose->last_busno = pci_hose_scan(hose); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 376 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 377 | /* enable target memory acceses on host brige */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 378 | pci_write_config_word(0, PCI_COMMAND, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 379 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
| 380 | |
| 381 | } |
| 382 | |
| 383 | |
| 384 | #endif |
| 385 | |
| 386 | #ifdef CFG_TIMER_SC520 |
| 387 | |
| 388 | |
| 389 | void reset_timer(void) |
| 390 | { |
| 391 | write_mmcr_word(SC520_GPTMR0CNT, 0); |
| 392 | write_mmcr_word(SC520_GPTMR0CTL, 0x6001); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 393 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | ulong get_timer(ulong base) |
| 397 | { |
| 398 | /* fixme: 30 or 33 */ |
| 399 | return read_mmcr_word(SC520_GPTMR0CNT) / 33; |
| 400 | } |
| 401 | |
| 402 | void set_timer(ulong t) |
| 403 | { |
| 404 | /* FixMe: use two cascade coupled timers */ |
| 405 | write_mmcr_word(SC520_GPTMR0CTL, 0x4001); |
| 406 | write_mmcr_word(SC520_GPTMR0CNT, t*33); |
| 407 | write_mmcr_word(SC520_GPTMR0CTL, 0x6001); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | void udelay(unsigned long usec) |
| 412 | { |
| 413 | int m=0; |
| 414 | long u; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 415 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 416 | read_mmcr_word(SC520_SWTMRMILLI); |
| 417 | read_mmcr_word(SC520_SWTMRMICRO); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 418 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 419 | #if 0 |
| 420 | /* do not enable this line, udelay is used in the serial driver -> recursion */ |
| 421 | printf("udelay: %ld m.u %d.%d tm.tu %d.%d\n", usec, m, u, tm, tu); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 422 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 423 | while (1) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 424 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 425 | m += read_mmcr_word(SC520_SWTMRMILLI); |
| 426 | u = read_mmcr_word(SC520_SWTMRMICRO) + (m * 1000); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 427 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 428 | if (usec <= u) { |
| 429 | break; |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | #endif |
| 435 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 436 | int ssi_set_interface(int freq, int lsb_first, int inv_clock, int inv_phase) |
| 437 | { |
| 438 | u8 temp=0; |
| 439 | |
| 440 | if (freq >= 8192) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 441 | temp |= CTL_CLK_SEL_4; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 442 | } else if (freq >= 4096) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 443 | temp |= CTL_CLK_SEL_8; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 444 | } else if (freq >= 2048) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 445 | temp |= CTL_CLK_SEL_16; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 446 | } else if (freq >= 1024) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 447 | temp |= CTL_CLK_SEL_32; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 448 | } else if (freq >= 512) { |
| 449 | temp |= CTL_CLK_SEL_64; |
| 450 | } else if (freq >= 256) { |
| 451 | temp |= CTL_CLK_SEL_128; |
| 452 | } else if (freq >= 128) { |
| 453 | temp |= CTL_CLK_SEL_256; |
| 454 | } else { |
| 455 | temp |= CTL_CLK_SEL_512; |
| 456 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 457 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 458 | if (!lsb_first) { |
| 459 | temp |= MSBF_ENB; |
| 460 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 461 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 462 | if (inv_clock) { |
| 463 | temp |= CLK_INV_ENB; |
| 464 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 465 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 466 | if (inv_phase) { |
| 467 | temp |= PHS_INV_ENB; |
| 468 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 469 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 470 | write_mmcr_byte(SC520_SSICTL, temp); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 471 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 475 | u8 ssi_txrx_byte(u8 data) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 476 | { |
| 477 | write_mmcr_byte(SC520_SSIXMIT, data); |
| 478 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
| 479 | write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMITRCV); |
| 480 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 481 | return read_mmcr_byte(SC520_SSIRCV); |
| 482 | } |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 483 | |
| 484 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 485 | void ssi_tx_byte(u8 data) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 486 | { |
| 487 | write_mmcr_byte(SC520_SSIXMIT, data); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 488 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 489 | write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMIT); |
| 490 | } |
| 491 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 492 | u8 ssi_rx_byte(void) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 493 | { |
| 494 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
| 495 | write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_RCV); |
| 496 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
| 497 | return read_mmcr_byte(SC520_SSIRCV); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 498 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 499 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 500 | #endif /* CONFIG_SC520 */ |