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