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 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | /* |
| 40 | * utility functions for boards based on the AMD sc520 |
| 41 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 42 | * void write_mmcr_byte(u16 mmcr, u8 data) |
| 43 | * void write_mmcr_word(u16 mmcr, u16 data) |
| 44 | * void write_mmcr_long(u16 mmcr, u32 data) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 45 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 46 | * u8 read_mmcr_byte(u16 mmcr) |
| 47 | * u16 read_mmcr_word(u16 mmcr) |
| 48 | * u32 read_mmcr_long(u16 mmcr) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 49 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | * void init_sc520(void) |
| 51 | * unsigned long init_sc520_dram(void) |
| 52 | * void pci_sc520_init(struct pci_controller *hose) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 53 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 54 | * void reset_timer(void) |
| 55 | * ulong get_timer(ulong base) |
| 56 | * void set_timer(ulong t) |
| 57 | * void udelay(unsigned long usec) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 58 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 59 | */ |
| 60 | |
| 61 | static u32 mmcr_base= 0xfffef000; |
| 62 | |
| 63 | void write_mmcr_byte(u16 mmcr, u8 data) |
| 64 | { |
| 65 | writeb(data, mmcr+mmcr_base); |
| 66 | } |
| 67 | |
| 68 | void write_mmcr_word(u16 mmcr, u16 data) |
| 69 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 70 | writew(data, mmcr+mmcr_base); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void write_mmcr_long(u16 mmcr, u32 data) |
| 74 | { |
| 75 | writel(data, mmcr+mmcr_base); |
| 76 | } |
| 77 | |
| 78 | u8 read_mmcr_byte(u16 mmcr) |
| 79 | { |
| 80 | return readb(mmcr+mmcr_base); |
| 81 | } |
| 82 | |
| 83 | u16 read_mmcr_word(u16 mmcr) |
| 84 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 85 | return readw(mmcr+mmcr_base); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | u32 read_mmcr_long(u16 mmcr) |
| 89 | { |
| 90 | return readl(mmcr+mmcr_base); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | void init_sc520(void) |
| 95 | { |
| 96 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 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 | { |
| 142 | DECLARE_GLOBAL_DATA_PTR; |
| 143 | bd_t *bd = gd->bd; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 144 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 145 | u32 dram_present=0; |
| 146 | u32 dram_ctrl; |
| 147 | |
| 148 | int val; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 149 | |
| 150 | int cas_precharge_delay = CFG_SDRAM_PRECHARGE_DELAY; |
| 151 | int refresh_rate = CFG_SDRAM_REFRESH_RATE; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 152 | int ras_cas_delay = CFG_SDRAM_RAS_CAS_DELAY; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 153 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 154 | /* set SDRAM speed here */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 155 | |
| 156 | refresh_rate/=78; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 157 | if (refresh_rate<=1) { |
| 158 | val = 0; /* 7.8us */ |
| 159 | } else if (refresh_rate==2) { |
| 160 | val = 1; /* 15.6us */ |
| 161 | } else if (refresh_rate==3 || refresh_rate==4) { |
| 162 | val = 2; /* 31.2us */ |
| 163 | } else { |
| 164 | val = 3; /* 62.4us */ |
| 165 | } |
| 166 | write_mmcr_byte(SC520_DRCCTL, (read_mmcr_byte(SC520_DRCCTL) & 0xcf) | (val<<4)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 167 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 168 | val = read_mmcr_byte(SC520_DRCTMCTL); |
| 169 | val &= 0xf0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 170 | |
| 171 | if (cas_precharge_delay==3) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 172 | val |= 0x04; /* 3T */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 173 | } else if (cas_precharge_delay==4) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 174 | val |= 0x08; /* 4T */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 175 | } else if (cas_precharge_delay>4) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 176 | val |= 0x0c; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 177 | } |
| 178 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 179 | if (ras_cas_delay > 3) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 180 | val |= 2; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 181 | } else { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 182 | val |= 1; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 183 | } |
| 184 | write_mmcr_byte(SC520_DRCTMCTL, val); |
| 185 | |
| 186 | |
| 187 | /* We read-back the configuration of the dram |
| 188 | * controller that the assembly code wrote */ |
| 189 | dram_ctrl = read_mmcr_long(SC520_DRCBENDADR); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 190 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 191 | |
| 192 | bd->bi_dram[0].start = 0; |
| 193 | if (dram_ctrl & 0x80) { |
| 194 | /* bank 0 enabled */ |
| 195 | dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 196 | bd->bi_dram[0].size = bd->bi_dram[1].start; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 197 | |
| 198 | } else { |
| 199 | bd->bi_dram[0].size = 0; |
| 200 | bd->bi_dram[1].start = bd->bi_dram[0].start; |
| 201 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 202 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 203 | if (dram_ctrl & 0x8000) { |
| 204 | /* bank 1 enabled */ |
| 205 | dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | 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] | 207 | } else { |
| 208 | bd->bi_dram[1].size = 0; |
| 209 | bd->bi_dram[2].start = bd->bi_dram[1].start; |
| 210 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 211 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 212 | if (dram_ctrl & 0x800000) { |
| 213 | /* bank 2 enabled */ |
| 214 | dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 215 | 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] | 216 | } else { |
| 217 | bd->bi_dram[2].size = 0; |
| 218 | bd->bi_dram[3].start = bd->bi_dram[2].start; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 219 | } |
| 220 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 221 | if (dram_ctrl & 0x80000000) { |
| 222 | /* bank 3 enabled */ |
| 223 | dram_present = (dram_ctrl & 0x7f000000) >> 2; |
| 224 | bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start; |
| 225 | } else { |
| 226 | bd->bi_dram[3].size = 0; |
| 227 | } |
| 228 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 229 | |
| 230 | #if 0 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 231 | printf("Configured %d bytes of dram\n", dram_present); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 232 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 233 | gd->ram_size = dram_present; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 234 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 235 | return dram_present; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | #ifdef CONFIG_PCI |
| 240 | |
| 241 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 242 | static struct { |
| 243 | u8 priority; |
| 244 | u16 level_reg; |
| 245 | u8 level_bit; |
| 246 | } sc520_irq[] = { |
| 247 | { SC520_IRQ0, SC520_MPICMODE, 0x01 }, |
| 248 | { SC520_IRQ1, SC520_MPICMODE, 0x02 }, |
| 249 | { SC520_IRQ2, SC520_SL1PICMODE, 0x02 }, |
| 250 | { SC520_IRQ3, SC520_MPICMODE, 0x08 }, |
| 251 | { SC520_IRQ4, SC520_MPICMODE, 0x10 }, |
| 252 | { SC520_IRQ5, SC520_MPICMODE, 0x20 }, |
| 253 | { SC520_IRQ6, SC520_MPICMODE, 0x40 }, |
| 254 | { SC520_IRQ7, SC520_MPICMODE, 0x80 }, |
| 255 | |
| 256 | { SC520_IRQ8, SC520_SL1PICMODE, 0x01 }, |
| 257 | { SC520_IRQ9, SC520_SL1PICMODE, 0x02 }, |
| 258 | { SC520_IRQ10, SC520_SL1PICMODE, 0x04 }, |
| 259 | { SC520_IRQ11, SC520_SL1PICMODE, 0x08 }, |
| 260 | { SC520_IRQ12, SC520_SL1PICMODE, 0x10 }, |
| 261 | { SC520_IRQ13, SC520_SL1PICMODE, 0x20 }, |
| 262 | { SC520_IRQ14, SC520_SL1PICMODE, 0x40 }, |
| 263 | { SC520_IRQ15, SC520_SL1PICMODE, 0x80 } |
| 264 | }; |
| 265 | |
| 266 | |
| 267 | /* The interrupt used for PCI INTA-INTD */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 268 | int sc520_pci_ints[15] = { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 269 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 270 | -1, -1, -1, -1, -1, -1, -1 |
| 271 | }; |
| 272 | |
| 273 | /* utility function to configure a pci interrupt */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 274 | int pci_sc520_set_irq(int pci_pin, int irq) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 275 | { |
| 276 | int i; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 277 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 278 | # if 0 |
| 279 | 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] | 280 | #endif |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 281 | if (irq < 0 || irq > 15) { |
| 282 | return -1; /* illegal irq */ |
| 283 | } |
| 284 | |
| 285 | if (pci_pin < 0 || pci_pin > 15) { |
| 286 | return -1; /* illegal pci int pin */ |
| 287 | } |
| 288 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 289 | /* first disable any non-pci interrupt source that use |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 290 | * this level */ |
| 291 | for (i=SC520_GPTMR0MAP;i<=SC520_GP10IMAP;i++) { |
| 292 | if (i>=SC520_PCIINTAMAP&&i<=SC520_PCIINTDMAP) { |
| 293 | continue; |
| 294 | } |
| 295 | if (read_mmcr_byte(i) == sc520_irq[irq].priority) { |
| 296 | write_mmcr_byte(i, SC520_IRQ_DISABLED); |
| 297 | } |
| 298 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 299 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 300 | /* Set the trigger to level */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 301 | write_mmcr_byte(sc520_irq[irq].level_reg, |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 302 | read_mmcr_byte(sc520_irq[irq].level_reg) | sc520_irq[irq].level_bit); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 303 | |
| 304 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 305 | if (pci_pin < 4) { |
| 306 | /* PCI INTA-INTD */ |
| 307 | /* route the interrupt */ |
| 308 | write_mmcr_byte(SC520_PCIINTAMAP + pci_pin, sc520_irq[irq].priority); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 309 | |
| 310 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 311 | } else { |
| 312 | /* GPIRQ0-GPIRQ10 used for additional PCI INTS */ |
| 313 | write_mmcr_byte(SC520_GP0IMAP + pci_pin - 4, sc520_irq[irq].priority); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 314 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 315 | /* also set the polarity in this case */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 316 | write_mmcr_word(SC520_INTPINPOL, |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 317 | read_mmcr_word(SC520_INTPINPOL) | (1 << (pci_pin-4))); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 318 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 319 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 320 | |
| 321 | /* register the pin */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 322 | sc520_pci_ints[pci_pin] = irq; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 323 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 324 | |
| 325 | return 0; /* OK */ |
| 326 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 327 | |
| 328 | void pci_sc520_init(struct pci_controller *hose) |
| 329 | { |
| 330 | hose->first_busno = 0; |
| 331 | hose->last_busno = 0xff; |
| 332 | |
| 333 | /* System memory space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 334 | pci_set_region(hose->regions + 0, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 335 | SC520_PCI_MEMORY_BUS, |
| 336 | SC520_PCI_MEMORY_PHYS, |
| 337 | SC520_PCI_MEMORY_SIZE, |
| 338 | PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 339 | |
| 340 | /* PCI memory space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 341 | pci_set_region(hose->regions + 1, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 342 | SC520_PCI_MEM_BUS, |
| 343 | SC520_PCI_MEM_PHYS, |
| 344 | SC520_PCI_MEM_SIZE, |
| 345 | PCI_REGION_MEM); |
| 346 | |
| 347 | /* ISA/PCI memory space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 348 | pci_set_region(hose->regions + 2, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 349 | SC520_ISA_MEM_BUS, |
| 350 | SC520_ISA_MEM_PHYS, |
| 351 | SC520_ISA_MEM_SIZE, |
| 352 | PCI_REGION_MEM); |
| 353 | |
| 354 | /* PCI I/O space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 355 | pci_set_region(hose->regions + 3, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 356 | SC520_PCI_IO_BUS, |
| 357 | SC520_PCI_IO_PHYS, |
| 358 | SC520_PCI_IO_SIZE, |
| 359 | PCI_REGION_IO); |
| 360 | |
| 361 | /* ISA/PCI I/O space */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 362 | pci_set_region(hose->regions + 4, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 363 | SC520_ISA_IO_BUS, |
| 364 | SC520_ISA_IO_PHYS, |
| 365 | SC520_ISA_IO_SIZE, |
| 366 | PCI_REGION_IO); |
| 367 | |
| 368 | hose->region_count = 5; |
| 369 | |
| 370 | pci_setup_type1(hose, |
| 371 | SC520_REG_ADDR, |
| 372 | SC520_REG_DATA); |
| 373 | |
| 374 | pci_register_hose(hose); |
| 375 | |
| 376 | hose->last_busno = pci_hose_scan(hose); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 377 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 378 | /* enable target memory acceses on host brige */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 379 | pci_write_config_word(0, PCI_COMMAND, |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 380 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
| 381 | |
| 382 | } |
| 383 | |
| 384 | |
| 385 | #endif |
| 386 | |
| 387 | #ifdef CFG_TIMER_SC520 |
| 388 | |
| 389 | |
| 390 | void reset_timer(void) |
| 391 | { |
| 392 | write_mmcr_word(SC520_GPTMR0CNT, 0); |
| 393 | write_mmcr_word(SC520_GPTMR0CTL, 0x6001); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 394 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | ulong get_timer(ulong base) |
| 398 | { |
| 399 | /* fixme: 30 or 33 */ |
| 400 | return read_mmcr_word(SC520_GPTMR0CNT) / 33; |
| 401 | } |
| 402 | |
| 403 | void set_timer(ulong t) |
| 404 | { |
| 405 | /* FixMe: use two cascade coupled timers */ |
| 406 | write_mmcr_word(SC520_GPTMR0CTL, 0x4001); |
| 407 | write_mmcr_word(SC520_GPTMR0CNT, t*33); |
| 408 | write_mmcr_word(SC520_GPTMR0CTL, 0x6001); |
| 409 | } |
| 410 | |
| 411 | |
| 412 | void udelay(unsigned long usec) |
| 413 | { |
| 414 | int m=0; |
| 415 | long u; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 416 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 417 | read_mmcr_word(SC520_SWTMRMILLI); |
| 418 | read_mmcr_word(SC520_SWTMRMICRO); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 419 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 420 | #if 0 |
| 421 | /* do not enable this line, udelay is used in the serial driver -> recursion */ |
| 422 | 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] | 423 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 424 | while (1) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 425 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 426 | m += read_mmcr_word(SC520_SWTMRMILLI); |
| 427 | u = read_mmcr_word(SC520_SWTMRMICRO) + (m * 1000); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 428 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 429 | if (usec <= u) { |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | #endif |
| 436 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 437 | int ssi_set_interface(int freq, int lsb_first, int inv_clock, int inv_phase) |
| 438 | { |
| 439 | u8 temp=0; |
| 440 | |
| 441 | if (freq >= 8192) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 442 | temp |= CTL_CLK_SEL_4; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 443 | } else if (freq >= 4096) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 444 | temp |= CTL_CLK_SEL_8; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 445 | } else if (freq >= 2048) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 446 | temp |= CTL_CLK_SEL_16; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 447 | } else if (freq >= 1024) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 448 | temp |= CTL_CLK_SEL_32; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 449 | } else if (freq >= 512) { |
| 450 | temp |= CTL_CLK_SEL_64; |
| 451 | } else if (freq >= 256) { |
| 452 | temp |= CTL_CLK_SEL_128; |
| 453 | } else if (freq >= 128) { |
| 454 | temp |= CTL_CLK_SEL_256; |
| 455 | } else { |
| 456 | temp |= CTL_CLK_SEL_512; |
| 457 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 458 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 459 | if (!lsb_first) { |
| 460 | temp |= MSBF_ENB; |
| 461 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 462 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 463 | if (inv_clock) { |
| 464 | temp |= CLK_INV_ENB; |
| 465 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 466 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 467 | if (inv_phase) { |
| 468 | temp |= PHS_INV_ENB; |
| 469 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 470 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 471 | write_mmcr_byte(SC520_SSICTL, temp); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 472 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 473 | return 0; |
| 474 | } |
| 475 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 476 | u8 ssi_txrx_byte(u8 data) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 477 | { |
| 478 | write_mmcr_byte(SC520_SSIXMIT, data); |
| 479 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
| 480 | write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMITRCV); |
| 481 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 482 | return read_mmcr_byte(SC520_SSIRCV); |
| 483 | } |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 484 | |
| 485 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 486 | void ssi_tx_byte(u8 data) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 487 | { |
| 488 | write_mmcr_byte(SC520_SSIXMIT, data); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 489 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 490 | write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMIT); |
| 491 | } |
| 492 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 493 | u8 ssi_rx_byte(void) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 494 | { |
| 495 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
| 496 | write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_RCV); |
| 497 | while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY); |
| 498 | return read_mmcr_byte(SC520_SSIRCV); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 499 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 500 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 501 | #endif /* CONFIG_SC520 */ |