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