Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 1 | /* |
| 2 | * TX4927 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/tx4927.h> |
| 24 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 25 | static void __init tx4927_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(&tx4927_ccfgptr->ccfg) & TX4927_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 | tx4927_ccfg_set(TX4927_CCFG_WDRST); |
| 33 | /* do reset on watchdog */ |
| 34 | tx4927_ccfg_set(TX4927_CCFG_WR); |
| 35 | } |
| 36 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 37 | void __init tx4927_wdt_init(void) |
| 38 | { |
| 39 | txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL); |
| 40 | } |
| 41 | |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame^] | 42 | static void tx4927_machine_restart(char *command) |
| 43 | { |
| 44 | local_irq_disable(); |
| 45 | pr_emerg("Rebooting (with %s watchdog reset)...\n", |
| 46 | (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) ? |
| 47 | "external" : "internal"); |
| 48 | /* clear watchdog status */ |
| 49 | tx4927_ccfg_set(TX4927_CCFG_WDRST); /* W1C */ |
| 50 | txx9_wdt_now(TX4927_TMR_REG(2) & 0xfffffffffULL); |
| 51 | while (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST)) |
| 52 | ; |
| 53 | mdelay(10); |
| 54 | if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) { |
| 55 | pr_emerg("Rebooting (with internal watchdog reset)...\n"); |
| 56 | /* External WDRST failed. Do internal watchdog reset */ |
| 57 | tx4927_ccfg_clear(TX4927_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 tx4927_sdram_resource[4]; |
| 64 | |
| 65 | void __init tx4927_setup(void) |
| 66 | { |
| 67 | int i; |
| 68 | __u32 divmode; |
| 69 | int cpuclk = 0; |
| 70 | u64 ccfg; |
| 71 | |
| 72 | txx9_reg_res_init(TX4927_REV_PCODE(), TX4927_REG_BASE, |
| 73 | TX4927_REG_SIZE); |
Atsushi Nemoto | d10e025 | 2008-08-19 22:55:09 +0900 | [diff] [blame] | 74 | set_c0_config(TX49_CONF_CWFON); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 75 | |
| 76 | /* SDRAMC,EBUSC are configured by PROM */ |
| 77 | for (i = 0; i < 8; i++) { |
| 78 | if (!(TX4927_EBUSC_CR(i) & 0x8)) |
| 79 | continue; /* disabled */ |
| 80 | txx9_ce_res[i].start = (unsigned long)TX4927_EBUSC_BA(i); |
| 81 | txx9_ce_res[i].end = |
| 82 | txx9_ce_res[i].start + TX4927_EBUSC_SIZE(i) - 1; |
| 83 | request_resource(&iomem_resource, &txx9_ce_res[i]); |
| 84 | } |
| 85 | |
| 86 | /* clocks */ |
| 87 | ccfg = ____raw_readq(&tx4927_ccfgptr->ccfg); |
| 88 | if (txx9_master_clock) { |
| 89 | /* calculate gbus_clock and cpu_clock from master_clock */ |
| 90 | divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK; |
| 91 | switch (divmode) { |
| 92 | case TX4927_CCFG_DIVMODE_8: |
| 93 | case TX4927_CCFG_DIVMODE_10: |
| 94 | case TX4927_CCFG_DIVMODE_12: |
| 95 | case TX4927_CCFG_DIVMODE_16: |
| 96 | txx9_gbus_clock = txx9_master_clock * 4; break; |
| 97 | default: |
| 98 | txx9_gbus_clock = txx9_master_clock; |
| 99 | } |
| 100 | switch (divmode) { |
| 101 | case TX4927_CCFG_DIVMODE_2: |
| 102 | case TX4927_CCFG_DIVMODE_8: |
| 103 | cpuclk = txx9_gbus_clock * 2; break; |
| 104 | case TX4927_CCFG_DIVMODE_2_5: |
| 105 | case TX4927_CCFG_DIVMODE_10: |
| 106 | cpuclk = txx9_gbus_clock * 5 / 2; break; |
| 107 | case TX4927_CCFG_DIVMODE_3: |
| 108 | case TX4927_CCFG_DIVMODE_12: |
| 109 | cpuclk = txx9_gbus_clock * 3; break; |
| 110 | case TX4927_CCFG_DIVMODE_4: |
| 111 | case TX4927_CCFG_DIVMODE_16: |
| 112 | cpuclk = txx9_gbus_clock * 4; break; |
| 113 | } |
| 114 | txx9_cpu_clock = cpuclk; |
| 115 | } else { |
| 116 | if (txx9_cpu_clock == 0) |
| 117 | txx9_cpu_clock = 200000000; /* 200MHz */ |
| 118 | /* calculate gbus_clock and master_clock from cpu_clock */ |
| 119 | cpuclk = txx9_cpu_clock; |
| 120 | divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK; |
| 121 | switch (divmode) { |
| 122 | case TX4927_CCFG_DIVMODE_2: |
| 123 | case TX4927_CCFG_DIVMODE_8: |
| 124 | txx9_gbus_clock = cpuclk / 2; break; |
| 125 | case TX4927_CCFG_DIVMODE_2_5: |
| 126 | case TX4927_CCFG_DIVMODE_10: |
| 127 | txx9_gbus_clock = cpuclk * 2 / 5; break; |
| 128 | case TX4927_CCFG_DIVMODE_3: |
| 129 | case TX4927_CCFG_DIVMODE_12: |
| 130 | txx9_gbus_clock = cpuclk / 3; break; |
| 131 | case TX4927_CCFG_DIVMODE_4: |
| 132 | case TX4927_CCFG_DIVMODE_16: |
| 133 | txx9_gbus_clock = cpuclk / 4; break; |
| 134 | } |
| 135 | switch (divmode) { |
| 136 | case TX4927_CCFG_DIVMODE_8: |
| 137 | case TX4927_CCFG_DIVMODE_10: |
| 138 | case TX4927_CCFG_DIVMODE_12: |
| 139 | case TX4927_CCFG_DIVMODE_16: |
| 140 | txx9_master_clock = txx9_gbus_clock / 4; break; |
| 141 | default: |
| 142 | txx9_master_clock = txx9_gbus_clock; |
| 143 | } |
| 144 | } |
| 145 | /* change default value to udelay/mdelay take reasonable time */ |
| 146 | loops_per_jiffy = txx9_cpu_clock / HZ / 2; |
| 147 | |
| 148 | /* CCFG */ |
| 149 | tx4927_wdr_init(); |
| 150 | /* clear BusErrorOnWrite flag (W1C) */ |
| 151 | tx4927_ccfg_set(TX4927_CCFG_BEOW); |
| 152 | /* enable Timeout BusError */ |
| 153 | if (txx9_ccfg_toeon) |
| 154 | tx4927_ccfg_set(TX4927_CCFG_TOE); |
| 155 | |
| 156 | /* DMA selection */ |
| 157 | txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_DMASEL_ALL); |
| 158 | |
| 159 | /* Use external clock for external arbiter */ |
| 160 | if (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB)) |
| 161 | txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_PCICLKEN_ALL); |
| 162 | |
| 163 | printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n", |
| 164 | txx9_pcode_str, |
| 165 | (cpuclk + 500000) / 1000000, |
| 166 | (txx9_master_clock + 500000) / 1000000, |
| 167 | (__u32)____raw_readq(&tx4927_ccfgptr->crir), |
| 168 | (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg), |
| 169 | (unsigned long long)____raw_readq(&tx4927_ccfgptr->pcfg)); |
| 170 | |
| 171 | printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str); |
| 172 | for (i = 0; i < 4; i++) { |
| 173 | __u64 cr = TX4927_SDRAMC_CR(i); |
| 174 | unsigned long base, size; |
| 175 | if (!((__u32)cr & 0x00000400)) |
| 176 | continue; /* disabled */ |
| 177 | base = (unsigned long)(cr >> 49) << 21; |
| 178 | size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21; |
| 179 | printk(" CR%d:%016llx", i, (unsigned long long)cr); |
| 180 | tx4927_sdram_resource[i].name = "SDRAM"; |
| 181 | tx4927_sdram_resource[i].start = base; |
| 182 | tx4927_sdram_resource[i].end = base + size - 1; |
| 183 | tx4927_sdram_resource[i].flags = IORESOURCE_MEM; |
| 184 | request_resource(&iomem_resource, &tx4927_sdram_resource[i]); |
| 185 | } |
| 186 | printk(" TR:%09llx\n", |
| 187 | (unsigned long long)____raw_readq(&tx4927_sdramcptr->tr)); |
| 188 | |
| 189 | /* TMR */ |
| 190 | /* disable all timers */ |
| 191 | for (i = 0; i < TX4927_NR_TMR; i++) |
| 192 | txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL); |
| 193 | |
| 194 | /* PIO */ |
| 195 | txx9_gpio_init(TX4927_PIO_REG & 0xfffffffffULL, 0, TX4927_NUM_PIO); |
| 196 | __raw_writel(0, &tx4927_pioptr->maskcpu); |
| 197 | __raw_writel(0, &tx4927_pioptr->maskext); |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame^] | 198 | |
| 199 | _machine_restart = tx4927_machine_restart; |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void __init tx4927_time_init(unsigned int tmrnr) |
| 203 | { |
| 204 | if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS) |
| 205 | txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL, |
| 206 | TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr), |
| 207 | TXX9_IMCLK); |
| 208 | } |
| 209 | |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 210 | void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 211 | { |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 212 | int i; |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 213 | |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 214 | for (i = 0; i < 2; i++) |
| 215 | txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL, |
| 216 | TXX9_IRQ_BASE + TX4927_IR_SIO(i), |
| 217 | i, sclk, (1 << i) & cts_mask); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 218 | } |
Atsushi Nemoto | 51f607c | 2008-08-19 22:55:11 +0900 | [diff] [blame] | 219 | |
| 220 | void __init tx4927_mtd_init(int ch) |
| 221 | { |
| 222 | struct physmap_flash_data pdata = { |
| 223 | .width = TX4927_EBUSC_WIDTH(ch) / 8, |
| 224 | }; |
| 225 | unsigned long start = txx9_ce_res[ch].start; |
| 226 | unsigned long size = txx9_ce_res[ch].end - start + 1; |
| 227 | |
| 228 | if (!(TX4927_EBUSC_CR(ch) & 0x8)) |
| 229 | return; /* disabled */ |
| 230 | txx9_physmap_flash_init(ch, start, size, &pdata); |
| 231 | } |