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> |
| 17 | #include <asm/txx9irq.h> |
| 18 | #include <asm/txx9tmr.h> |
| 19 | #include <asm/txx9pio.h> |
| 20 | #include <asm/txx9/generic.h> |
| 21 | #include <asm/txx9/tx4938.h> |
| 22 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 23 | static void __init tx4938_wdr_init(void) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 24 | { |
| 25 | /* clear WatchDogReset (W1C) */ |
| 26 | tx4938_ccfg_set(TX4938_CCFG_WDRST); |
| 27 | /* do reset on watchdog */ |
| 28 | tx4938_ccfg_set(TX4938_CCFG_WR); |
| 29 | } |
| 30 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 31 | void __init tx4938_wdt_init(void) |
| 32 | { |
| 33 | txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL); |
| 34 | } |
| 35 | |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 36 | static struct resource tx4938_sdram_resource[4]; |
| 37 | static struct resource tx4938_sram_resource; |
| 38 | |
| 39 | #define TX4938_SRAM_SIZE 0x800 |
| 40 | |
| 41 | void __init tx4938_setup(void) |
| 42 | { |
| 43 | int i; |
| 44 | __u32 divmode; |
| 45 | int cpuclk = 0; |
| 46 | u64 ccfg; |
| 47 | |
| 48 | txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE, |
| 49 | TX4938_REG_SIZE); |
Atsushi Nemoto | d10e025 | 2008-08-19 22:55:09 +0900 | [diff] [blame^] | 50 | set_c0_config(TX49_CONF_CWFON); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 51 | |
| 52 | /* SDRAMC,EBUSC are configured by PROM */ |
| 53 | for (i = 0; i < 8; i++) { |
| 54 | if (!(TX4938_EBUSC_CR(i) & 0x8)) |
| 55 | continue; /* disabled */ |
| 56 | txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i); |
| 57 | txx9_ce_res[i].end = |
| 58 | txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1; |
| 59 | request_resource(&iomem_resource, &txx9_ce_res[i]); |
| 60 | } |
| 61 | |
| 62 | /* clocks */ |
| 63 | ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg); |
| 64 | if (txx9_master_clock) { |
| 65 | /* calculate gbus_clock and cpu_clock from master_clock */ |
| 66 | divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK; |
| 67 | switch (divmode) { |
| 68 | case TX4938_CCFG_DIVMODE_8: |
| 69 | case TX4938_CCFG_DIVMODE_10: |
| 70 | case TX4938_CCFG_DIVMODE_12: |
| 71 | case TX4938_CCFG_DIVMODE_16: |
| 72 | case TX4938_CCFG_DIVMODE_18: |
| 73 | txx9_gbus_clock = txx9_master_clock * 4; break; |
| 74 | default: |
| 75 | txx9_gbus_clock = txx9_master_clock; |
| 76 | } |
| 77 | switch (divmode) { |
| 78 | case TX4938_CCFG_DIVMODE_2: |
| 79 | case TX4938_CCFG_DIVMODE_8: |
| 80 | cpuclk = txx9_gbus_clock * 2; break; |
| 81 | case TX4938_CCFG_DIVMODE_2_5: |
| 82 | case TX4938_CCFG_DIVMODE_10: |
| 83 | cpuclk = txx9_gbus_clock * 5 / 2; break; |
| 84 | case TX4938_CCFG_DIVMODE_3: |
| 85 | case TX4938_CCFG_DIVMODE_12: |
| 86 | cpuclk = txx9_gbus_clock * 3; break; |
| 87 | case TX4938_CCFG_DIVMODE_4: |
| 88 | case TX4938_CCFG_DIVMODE_16: |
| 89 | cpuclk = txx9_gbus_clock * 4; break; |
| 90 | case TX4938_CCFG_DIVMODE_4_5: |
| 91 | case TX4938_CCFG_DIVMODE_18: |
| 92 | cpuclk = txx9_gbus_clock * 9 / 2; break; |
| 93 | } |
| 94 | txx9_cpu_clock = cpuclk; |
| 95 | } else { |
| 96 | if (txx9_cpu_clock == 0) |
| 97 | txx9_cpu_clock = 300000000; /* 300MHz */ |
| 98 | /* calculate gbus_clock and master_clock from cpu_clock */ |
| 99 | cpuclk = txx9_cpu_clock; |
| 100 | divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK; |
| 101 | switch (divmode) { |
| 102 | case TX4938_CCFG_DIVMODE_2: |
| 103 | case TX4938_CCFG_DIVMODE_8: |
| 104 | txx9_gbus_clock = cpuclk / 2; break; |
| 105 | case TX4938_CCFG_DIVMODE_2_5: |
| 106 | case TX4938_CCFG_DIVMODE_10: |
| 107 | txx9_gbus_clock = cpuclk * 2 / 5; break; |
| 108 | case TX4938_CCFG_DIVMODE_3: |
| 109 | case TX4938_CCFG_DIVMODE_12: |
| 110 | txx9_gbus_clock = cpuclk / 3; break; |
| 111 | case TX4938_CCFG_DIVMODE_4: |
| 112 | case TX4938_CCFG_DIVMODE_16: |
| 113 | txx9_gbus_clock = cpuclk / 4; break; |
| 114 | case TX4938_CCFG_DIVMODE_4_5: |
| 115 | case TX4938_CCFG_DIVMODE_18: |
| 116 | txx9_gbus_clock = cpuclk * 2 / 9; break; |
| 117 | } |
| 118 | switch (divmode) { |
| 119 | case TX4938_CCFG_DIVMODE_8: |
| 120 | case TX4938_CCFG_DIVMODE_10: |
| 121 | case TX4938_CCFG_DIVMODE_12: |
| 122 | case TX4938_CCFG_DIVMODE_16: |
| 123 | case TX4938_CCFG_DIVMODE_18: |
| 124 | txx9_master_clock = txx9_gbus_clock / 4; break; |
| 125 | default: |
| 126 | txx9_master_clock = txx9_gbus_clock; |
| 127 | } |
| 128 | } |
| 129 | /* change default value to udelay/mdelay take reasonable time */ |
| 130 | loops_per_jiffy = txx9_cpu_clock / HZ / 2; |
| 131 | |
| 132 | /* CCFG */ |
| 133 | tx4938_wdr_init(); |
| 134 | /* clear BusErrorOnWrite flag (W1C) */ |
| 135 | tx4938_ccfg_set(TX4938_CCFG_BEOW); |
| 136 | /* enable Timeout BusError */ |
| 137 | if (txx9_ccfg_toeon) |
| 138 | tx4938_ccfg_set(TX4938_CCFG_TOE); |
| 139 | |
| 140 | /* DMA selection */ |
| 141 | txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL); |
| 142 | |
| 143 | /* Use external clock for external arbiter */ |
| 144 | if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB)) |
| 145 | txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL); |
| 146 | |
| 147 | printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n", |
| 148 | txx9_pcode_str, |
| 149 | (cpuclk + 500000) / 1000000, |
| 150 | (txx9_master_clock + 500000) / 1000000, |
| 151 | (__u32)____raw_readq(&tx4938_ccfgptr->crir), |
| 152 | (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg), |
| 153 | (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg)); |
| 154 | |
| 155 | printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str); |
| 156 | for (i = 0; i < 4; i++) { |
| 157 | __u64 cr = TX4938_SDRAMC_CR(i); |
| 158 | unsigned long base, size; |
| 159 | if (!((__u32)cr & 0x00000400)) |
| 160 | continue; /* disabled */ |
| 161 | base = (unsigned long)(cr >> 49) << 21; |
| 162 | size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21; |
| 163 | printk(" CR%d:%016llx", i, (unsigned long long)cr); |
| 164 | tx4938_sdram_resource[i].name = "SDRAM"; |
| 165 | tx4938_sdram_resource[i].start = base; |
| 166 | tx4938_sdram_resource[i].end = base + size - 1; |
| 167 | tx4938_sdram_resource[i].flags = IORESOURCE_MEM; |
| 168 | request_resource(&iomem_resource, &tx4938_sdram_resource[i]); |
| 169 | } |
| 170 | printk(" TR:%09llx\n", |
| 171 | (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr)); |
| 172 | |
| 173 | /* SRAM */ |
| 174 | if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) { |
| 175 | unsigned int size = TX4938_SRAM_SIZE; |
| 176 | tx4938_sram_resource.name = "SRAM"; |
| 177 | tx4938_sram_resource.start = |
| 178 | (____raw_readq(&tx4938_sramcptr->cr) >> (39-11)) |
| 179 | & ~(size - 1); |
| 180 | tx4938_sram_resource.end = |
| 181 | tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1; |
| 182 | tx4938_sram_resource.flags = IORESOURCE_MEM; |
| 183 | request_resource(&iomem_resource, &tx4938_sram_resource); |
| 184 | } |
| 185 | |
| 186 | /* TMR */ |
| 187 | /* disable all timers */ |
| 188 | for (i = 0; i < TX4938_NR_TMR; i++) |
| 189 | txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL); |
| 190 | |
| 191 | /* DMA */ |
| 192 | for (i = 0; i < 2; i++) |
| 193 | ____raw_writeq(TX4938_DMA_MCR_MSTEN, |
| 194 | (void __iomem *)(TX4938_DMA_REG(i) + 0x50)); |
| 195 | |
| 196 | /* PIO */ |
| 197 | txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO); |
| 198 | __raw_writel(0, &tx4938_pioptr->maskcpu); |
| 199 | __raw_writel(0, &tx4938_pioptr->maskext); |
| 200 | |
| 201 | if (txx9_pcode == 0x4938) { |
| 202 | __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg); |
| 203 | /* set PCIC1 reset */ |
| 204 | txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST); |
| 205 | if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) { |
| 206 | mdelay(1); /* at least 128 cpu clock */ |
| 207 | /* clear PCIC1 reset */ |
| 208 | txx9_clear64(&tx4938_ccfgptr->clkctr, |
| 209 | TX4938_CLKCTR_PCIC1RST); |
| 210 | } else { |
| 211 | printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str); |
| 212 | /* stop PCIC1 */ |
| 213 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 214 | TX4938_CLKCTR_PCIC1CKD); |
| 215 | } |
| 216 | if (!(pcfg & TX4938_PCFG_ETH0_SEL)) { |
| 217 | printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str); |
| 218 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 219 | TX4938_CLKCTR_ETH0RST); |
| 220 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 221 | TX4938_CLKCTR_ETH0CKD); |
| 222 | } |
| 223 | if (!(pcfg & TX4938_PCFG_ETH1_SEL)) { |
| 224 | printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str); |
| 225 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 226 | TX4938_CLKCTR_ETH1RST); |
| 227 | txx9_set64(&tx4938_ccfgptr->clkctr, |
| 228 | TX4938_CLKCTR_ETH1CKD); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void __init tx4938_time_init(unsigned int tmrnr) |
| 234 | { |
| 235 | if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS) |
| 236 | txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL, |
| 237 | TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr), |
| 238 | TXX9_IMCLK); |
| 239 | } |
| 240 | |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 241 | void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 242 | { |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 243 | int i; |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 244 | unsigned int ch_mask = 0; |
| 245 | |
| 246 | if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL) |
| 247 | ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */ |
| 248 | for (i = 0; i < 2; i++) { |
| 249 | if ((1 << i) & ch_mask) |
| 250 | continue; |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 251 | txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL, |
| 252 | TXX9_IRQ_BASE + TX4938_IR_SIO(i), |
| 253 | i, sclk, (1 << i) & cts_mask); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 254 | } |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 255 | } |
Atsushi Nemoto | c49f91f | 2008-07-24 00:25:20 +0900 | [diff] [blame] | 256 | |
| 257 | void __init tx4938_spi_init(int busid) |
| 258 | { |
| 259 | txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL, |
| 260 | TXX9_IRQ_BASE + TX4938_IR_SPI); |
| 261 | } |
| 262 | |
| 263 | void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1) |
| 264 | { |
| 265 | u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg); |
| 266 | |
| 267 | if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL)) |
| 268 | txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0); |
| 269 | if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL)) |
| 270 | txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1); |
| 271 | } |