Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 1 | /* |
| 2 | * TX4938/4937 setup routines |
| 3 | * Based on linux/arch/mips/txx9/rbtx4938/setup.c, |
| 4 | * and RBTX49xx patch from CELF patch archive. |
| 5 | * |
| 6 | * 2003-2005 (c) MontaVista Software, Inc. |
| 7 | * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007 |
| 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file "COPYING" in the main directory of this archive |
| 11 | * for more details. |
| 12 | */ |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/ioport.h> |
| 15 | #include <linux/delay.h> |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 16 | #include <linux/param.h> |
Atsushi Nemoto | 51f607c | 2008-08-19 22:55:11 +0900 | [diff] [blame] | 17 | #include <linux/mtd/physmap.h> |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame^] | 18 | #include <asm/reboot.h> |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 19 | #include <asm/txx9irq.h> |
| 20 | #include <asm/txx9tmr.h> |
| 21 | #include <asm/txx9pio.h> |
| 22 | #include <asm/txx9/generic.h> |
| 23 | #include <asm/txx9/tx4938.h> |
| 24 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 25 | static void __init tx4938_wdr_init(void) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 26 | { |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame^] | 27 | /* report watchdog reset status */ |
| 28 | if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST) |
| 29 | pr_warning("Watchdog reset detected at 0x%lx\n", |
| 30 | read_c0_errorepc()); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 31 | /* clear WatchDogReset (W1C) */ |
| 32 | tx4938_ccfg_set(TX4938_CCFG_WDRST); |
| 33 | /* do reset on watchdog */ |
| 34 | tx4938_ccfg_set(TX4938_CCFG_WR); |
| 35 | } |
| 36 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 37 | void __init tx4938_wdt_init(void) |
| 38 | { |
| 39 | txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL); |
| 40 | } |
| 41 | |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame^] | 42 | static void tx4938_machine_restart(char *command) |
| 43 | { |
| 44 | local_irq_disable(); |
| 45 | pr_emerg("Rebooting (with %s watchdog reset)...\n", |
| 46 | (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ? |
| 47 | "external" : "internal"); |
| 48 | /* clear watchdog status */ |
| 49 | tx4938_ccfg_set(TX4938_CCFG_WDRST); /* W1C */ |
| 50 | txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL); |
| 51 | while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)) |
| 52 | ; |
| 53 | mdelay(10); |
| 54 | if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) { |
| 55 | pr_emerg("Rebooting (with internal watchdog reset)...\n"); |
| 56 | /* External WDRST failed. Do internal watchdog reset */ |
| 57 | tx4938_ccfg_clear(TX4938_CCFG_WDREXEN); |
| 58 | } |
| 59 | /* fallback */ |
| 60 | (*_machine_halt)(); |
| 61 | } |
| 62 | |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 63 | static struct resource tx4938_sdram_resource[4]; |
| 64 | static struct resource tx4938_sram_resource; |
| 65 | |
| 66 | #define TX4938_SRAM_SIZE 0x800 |
| 67 | |
| 68 | void __init tx4938_setup(void) |
| 69 | { |
| 70 | int i; |
| 71 | __u32 divmode; |
| 72 | int cpuclk = 0; |
| 73 | u64 ccfg; |
| 74 | |
| 75 | txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE, |
| 76 | TX4938_REG_SIZE); |
Atsushi Nemoto | d10e025 | 2008-08-19 22:55:09 +0900 | [diff] [blame] | 77 | set_c0_config(TX49_CONF_CWFON); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 78 | |
| 79 | /* SDRAMC,EBUSC are configured by PROM */ |
| 80 | for (i = 0; i < 8; i++) { |
| 81 | if (!(TX4938_EBUSC_CR(i) & 0x8)) |
| 82 | continue; /* disabled */ |
| 83 | txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i); |
| 84 | txx9_ce_res[i].end = |
| 85 | txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1; |
| 86 | request_resource(&iomem_resource, &txx9_ce_res[i]); |
| 87 | } |
| 88 | |
| 89 | /* clocks */ |
| 90 | ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg); |
| 91 | if (txx9_master_clock) { |
| 92 | /* calculate gbus_clock and cpu_clock from master_clock */ |
| 93 | divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK; |
| 94 | switch (divmode) { |
| 95 | case TX4938_CCFG_DIVMODE_8: |
| 96 | case TX4938_CCFG_DIVMODE_10: |
| 97 | case TX4938_CCFG_DIVMODE_12: |
| 98 | case TX4938_CCFG_DIVMODE_16: |
| 99 | case TX4938_CCFG_DIVMODE_18: |
| 100 | txx9_gbus_clock = txx9_master_clock * 4; break; |
| 101 | default: |
| 102 | txx9_gbus_clock = txx9_master_clock; |
| 103 | } |
| 104 | switch (divmode) { |
| 105 | case TX4938_CCFG_DIVMODE_2: |
| 106 | case TX4938_CCFG_DIVMODE_8: |
| 107 | cpuclk = txx9_gbus_clock * 2; break; |
| 108 | case TX4938_CCFG_DIVMODE_2_5: |
| 109 | case TX4938_CCFG_DIVMODE_10: |
| 110 | cpuclk = txx9_gbus_clock * 5 / 2; break; |
| 111 | case TX4938_CCFG_DIVMODE_3: |
| 112 | case TX4938_CCFG_DIVMODE_12: |
| 113 | cpuclk = txx9_gbus_clock * 3; break; |
| 114 | case TX4938_CCFG_DIVMODE_4: |
| 115 | case TX4938_CCFG_DIVMODE_16: |
| 116 | cpuclk = txx9_gbus_clock * 4; break; |
| 117 | case TX4938_CCFG_DIVMODE_4_5: |
| 118 | case TX4938_CCFG_DIVMODE_18: |
| 119 | cpuclk = txx9_gbus_clock * 9 / 2; break; |
| 120 | } |
| 121 | txx9_cpu_clock = cpuclk; |
| 122 | } else { |
| 123 | if (txx9_cpu_clock == 0) |
| 124 | txx9_cpu_clock = 300000000; /* 300MHz */ |
| 125 | /* calculate gbus_clock and master_clock from cpu_clock */ |
| 126 | cpuclk = txx9_cpu_clock; |
| 127 | divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK; |
| 128 | switch (divmode) { |
| 129 | case TX4938_CCFG_DIVMODE_2: |
| 130 | case TX4938_CCFG_DIVMODE_8: |
| 131 | txx9_gbus_clock = cpuclk / 2; break; |
| 132 | case TX4938_CCFG_DIVMODE_2_5: |
| 133 | case TX4938_CCFG_DIVMODE_10: |
| 134 | txx9_gbus_clock = cpuclk * 2 / 5; break; |
| 135 | case TX4938_CCFG_DIVMODE_3: |
| 136 | case TX4938_CCFG_DIVMODE_12: |
| 137 | txx9_gbus_clock = cpuclk / 3; break; |
| 138 | case TX4938_CCFG_DIVMODE_4: |
| 139 | case TX4938_CCFG_DIVMODE_16: |
| 140 | txx9_gbus_clock = cpuclk / 4; break; |
| 141 | case TX4938_CCFG_DIVMODE_4_5: |
| 142 | case TX4938_CCFG_DIVMODE_18: |
| 143 | txx9_gbus_clock = cpuclk * 2 / 9; break; |
| 144 | } |
| 145 | switch (divmode) { |
| 146 | case TX4938_CCFG_DIVMODE_8: |
| 147 | case TX4938_CCFG_DIVMODE_10: |
| 148 | case TX4938_CCFG_DIVMODE_12: |
| 149 | case TX4938_CCFG_DIVMODE_16: |
| 150 | case TX4938_CCFG_DIVMODE_18: |
| 151 | txx9_master_clock = txx9_gbus_clock / 4; break; |
| 152 | default: |
| 153 | txx9_master_clock = txx9_gbus_clock; |
| 154 | } |
| 155 | } |
| 156 | /* change default value to udelay/mdelay take reasonable time */ |
| 157 | loops_per_jiffy = txx9_cpu_clock / HZ / 2; |
| 158 | |
| 159 | /* CCFG */ |
| 160 | tx4938_wdr_init(); |
| 161 | /* clear BusErrorOnWrite flag (W1C) */ |
| 162 | tx4938_ccfg_set(TX4938_CCFG_BEOW); |
| 163 | /* enable Timeout BusError */ |
| 164 | if (txx9_ccfg_toeon) |
| 165 | tx4938_ccfg_set(TX4938_CCFG_TOE); |
| 166 | |
| 167 | /* DMA selection */ |
| 168 | txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL); |
| 169 | |
| 170 | /* Use external clock for external arbiter */ |
| 171 | if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB)) |
| 172 | txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL); |
| 173 | |
| 174 | printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n", |
| 175 | txx9_pcode_str, |
| 176 | (cpuclk + 500000) / 1000000, |
| 177 | (txx9_master_clock + 500000) / 1000000, |
| 178 | (__u32)____raw_readq(&tx4938_ccfgptr->crir), |
| 179 | (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg), |
| 180 | (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg)); |
| 181 | |
| 182 | printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str); |
| 183 | for (i = 0; i < 4; i++) { |
| 184 | __u64 cr = TX4938_SDRAMC_CR(i); |
| 185 | unsigned long base, size; |
| 186 | if (!((__u32)cr & 0x00000400)) |
| 187 | continue; /* disabled */ |
| 188 | base = (unsigned long)(cr >> 49) << 21; |
| 189 | size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21; |
| 190 | printk(" CR%d:%016llx", i, (unsigned long long)cr); |
| 191 | tx4938_sdram_resource[i].name = "SDRAM"; |
| 192 | tx4938_sdram_resource[i].start = base; |
| 193 | tx4938_sdram_resource[i].end = base + size - 1; |
| 194 | tx4938_sdram_resource[i].flags = IORESOURCE_MEM; |
| 195 | request_resource(&iomem_resource, &tx4938_sdram_resource[i]); |
| 196 | } |
| 197 | printk(" TR:%09llx\n", |
| 198 | (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr)); |
| 199 | |
| 200 | /* SRAM */ |
| 201 | if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) { |
| 202 | unsigned int size = TX4938_SRAM_SIZE; |
| 203 | tx4938_sram_resource.name = "SRAM"; |
| 204 | tx4938_sram_resource.start = |
| 205 | (____raw_readq(&tx4938_sramcptr->cr) >> (39-11)) |
| 206 | & ~(size - 1); |
| 207 | tx4938_sram_resource.end = |
| 208 | tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1; |
| 209 | tx4938_sram_resource.flags = IORESOURCE_MEM; |
| 210 | request_resource(&iomem_resource, &tx4938_sram_resource); |
| 211 | } |
| 212 | |
| 213 | /* TMR */ |
| 214 | /* disable all timers */ |
| 215 | for (i = 0; i < TX4938_NR_TMR; i++) |
| 216 | txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL); |
| 217 | |
| 218 | /* DMA */ |
| 219 | for (i = 0; i < 2; i++) |
| 220 | ____raw_writeq(TX4938_DMA_MCR_MSTEN, |
| 221 | (void __iomem *)(TX4938_DMA_REG(i) + 0x50)); |
| 222 | |
| 223 | /* PIO */ |
| 224 | txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO); |
| 225 | __raw_writel(0, &tx4938_pioptr->maskcpu); |
| 226 | __raw_writel(0, &tx4938_pioptr->maskext); |
| 227 | |
| 228 | if (txx9_pcode == 0x4938) { |
| 229 | __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg); |
| 230 | /* set PCIC1 reset */ |
| 231 | txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST); |
| 232 | if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) { |
| 233 | mdelay(1); /* at least 128 cpu clock */ |
| 234 | /* clear PCIC1 reset */ |
| 235 | txx9_clear64(&tx4938_ccfgptr->clkctr, |
| 236 | TX4938_CLKCTR_PCIC1RST); |
| 237 | } else { |
| 238 | printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str); |
| 239 | /* stop PCIC1 */ |
| 240 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 241 | TX4938_CLKCTR_PCIC1CKD); |
| 242 | } |
| 243 | if (!(pcfg & TX4938_PCFG_ETH0_SEL)) { |
| 244 | printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str); |
| 245 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 246 | TX4938_CLKCTR_ETH0RST); |
| 247 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 248 | TX4938_CLKCTR_ETH0CKD); |
| 249 | } |
| 250 | if (!(pcfg & TX4938_PCFG_ETH1_SEL)) { |
| 251 | printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str); |
| 252 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 253 | TX4938_CLKCTR_ETH1RST); |
| 254 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 255 | TX4938_CLKCTR_ETH1CKD); |
| 256 | } |
| 257 | } |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame^] | 258 | |
| 259 | _machine_restart = tx4938_machine_restart; |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void __init tx4938_time_init(unsigned int tmrnr) |
| 263 | { |
| 264 | if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS) |
| 265 | txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL, |
| 266 | TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr), |
| 267 | TXX9_IMCLK); |
| 268 | } |
| 269 | |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 270 | void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 271 | { |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 272 | int i; |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 273 | unsigned int ch_mask = 0; |
| 274 | |
| 275 | if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL) |
| 276 | ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */ |
| 277 | for (i = 0; i < 2; i++) { |
| 278 | if ((1 << i) & ch_mask) |
| 279 | continue; |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 280 | txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL, |
| 281 | TXX9_IRQ_BASE + TX4938_IR_SIO(i), |
| 282 | i, sclk, (1 << i) & cts_mask); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 283 | } |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 284 | } |
Atsushi Nemoto | c49f91f | 2008-07-24 00:25:20 +0900 | [diff] [blame] | 285 | |
| 286 | void __init tx4938_spi_init(int busid) |
| 287 | { |
| 288 | txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL, |
| 289 | TXX9_IRQ_BASE + TX4938_IR_SPI); |
| 290 | } |
| 291 | |
| 292 | void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1) |
| 293 | { |
| 294 | u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg); |
| 295 | |
| 296 | if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL)) |
| 297 | txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0); |
| 298 | if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL)) |
| 299 | txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1); |
| 300 | } |
Atsushi Nemoto | 51f607c | 2008-08-19 22:55:11 +0900 | [diff] [blame] | 301 | |
| 302 | void __init tx4938_mtd_init(int ch) |
| 303 | { |
| 304 | struct physmap_flash_data pdata = { |
| 305 | .width = TX4938_EBUSC_WIDTH(ch) / 8, |
| 306 | }; |
| 307 | unsigned long start = txx9_ce_res[ch].start; |
| 308 | unsigned long size = txx9_ce_res[ch].end - start + 1; |
| 309 | |
| 310 | if (!(TX4938_EBUSC_CR(ch) & 0x8)) |
| 311 | return; /* disabled */ |
| 312 | txx9_physmap_flash_init(ch, start, size, &pdata); |
| 313 | } |