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> |
| 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/tx4927.h> |
| 22 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 23 | static void __init tx4927_wdr_init(void) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 24 | { |
| 25 | /* clear WatchDogReset (W1C) */ |
| 26 | tx4927_ccfg_set(TX4927_CCFG_WDRST); |
| 27 | /* do reset on watchdog */ |
| 28 | tx4927_ccfg_set(TX4927_CCFG_WR); |
| 29 | } |
| 30 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 31 | void __init tx4927_wdt_init(void) |
| 32 | { |
| 33 | txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL); |
| 34 | } |
| 35 | |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 36 | static struct resource tx4927_sdram_resource[4]; |
| 37 | |
| 38 | void __init tx4927_setup(void) |
| 39 | { |
| 40 | int i; |
| 41 | __u32 divmode; |
| 42 | int cpuclk = 0; |
| 43 | u64 ccfg; |
| 44 | |
| 45 | txx9_reg_res_init(TX4927_REV_PCODE(), TX4927_REG_BASE, |
| 46 | TX4927_REG_SIZE); |
| 47 | |
| 48 | /* SDRAMC,EBUSC are configured by PROM */ |
| 49 | for (i = 0; i < 8; i++) { |
| 50 | if (!(TX4927_EBUSC_CR(i) & 0x8)) |
| 51 | continue; /* disabled */ |
| 52 | txx9_ce_res[i].start = (unsigned long)TX4927_EBUSC_BA(i); |
| 53 | txx9_ce_res[i].end = |
| 54 | txx9_ce_res[i].start + TX4927_EBUSC_SIZE(i) - 1; |
| 55 | request_resource(&iomem_resource, &txx9_ce_res[i]); |
| 56 | } |
| 57 | |
| 58 | /* clocks */ |
| 59 | ccfg = ____raw_readq(&tx4927_ccfgptr->ccfg); |
| 60 | if (txx9_master_clock) { |
| 61 | /* calculate gbus_clock and cpu_clock from master_clock */ |
| 62 | divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK; |
| 63 | switch (divmode) { |
| 64 | case TX4927_CCFG_DIVMODE_8: |
| 65 | case TX4927_CCFG_DIVMODE_10: |
| 66 | case TX4927_CCFG_DIVMODE_12: |
| 67 | case TX4927_CCFG_DIVMODE_16: |
| 68 | txx9_gbus_clock = txx9_master_clock * 4; break; |
| 69 | default: |
| 70 | txx9_gbus_clock = txx9_master_clock; |
| 71 | } |
| 72 | switch (divmode) { |
| 73 | case TX4927_CCFG_DIVMODE_2: |
| 74 | case TX4927_CCFG_DIVMODE_8: |
| 75 | cpuclk = txx9_gbus_clock * 2; break; |
| 76 | case TX4927_CCFG_DIVMODE_2_5: |
| 77 | case TX4927_CCFG_DIVMODE_10: |
| 78 | cpuclk = txx9_gbus_clock * 5 / 2; break; |
| 79 | case TX4927_CCFG_DIVMODE_3: |
| 80 | case TX4927_CCFG_DIVMODE_12: |
| 81 | cpuclk = txx9_gbus_clock * 3; break; |
| 82 | case TX4927_CCFG_DIVMODE_4: |
| 83 | case TX4927_CCFG_DIVMODE_16: |
| 84 | cpuclk = txx9_gbus_clock * 4; break; |
| 85 | } |
| 86 | txx9_cpu_clock = cpuclk; |
| 87 | } else { |
| 88 | if (txx9_cpu_clock == 0) |
| 89 | txx9_cpu_clock = 200000000; /* 200MHz */ |
| 90 | /* calculate gbus_clock and master_clock from cpu_clock */ |
| 91 | cpuclk = txx9_cpu_clock; |
| 92 | divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK; |
| 93 | switch (divmode) { |
| 94 | case TX4927_CCFG_DIVMODE_2: |
| 95 | case TX4927_CCFG_DIVMODE_8: |
| 96 | txx9_gbus_clock = cpuclk / 2; break; |
| 97 | case TX4927_CCFG_DIVMODE_2_5: |
| 98 | case TX4927_CCFG_DIVMODE_10: |
| 99 | txx9_gbus_clock = cpuclk * 2 / 5; break; |
| 100 | case TX4927_CCFG_DIVMODE_3: |
| 101 | case TX4927_CCFG_DIVMODE_12: |
| 102 | txx9_gbus_clock = cpuclk / 3; break; |
| 103 | case TX4927_CCFG_DIVMODE_4: |
| 104 | case TX4927_CCFG_DIVMODE_16: |
| 105 | txx9_gbus_clock = cpuclk / 4; break; |
| 106 | } |
| 107 | switch (divmode) { |
| 108 | case TX4927_CCFG_DIVMODE_8: |
| 109 | case TX4927_CCFG_DIVMODE_10: |
| 110 | case TX4927_CCFG_DIVMODE_12: |
| 111 | case TX4927_CCFG_DIVMODE_16: |
| 112 | txx9_master_clock = txx9_gbus_clock / 4; break; |
| 113 | default: |
| 114 | txx9_master_clock = txx9_gbus_clock; |
| 115 | } |
| 116 | } |
| 117 | /* change default value to udelay/mdelay take reasonable time */ |
| 118 | loops_per_jiffy = txx9_cpu_clock / HZ / 2; |
| 119 | |
| 120 | /* CCFG */ |
| 121 | tx4927_wdr_init(); |
| 122 | /* clear BusErrorOnWrite flag (W1C) */ |
| 123 | tx4927_ccfg_set(TX4927_CCFG_BEOW); |
| 124 | /* enable Timeout BusError */ |
| 125 | if (txx9_ccfg_toeon) |
| 126 | tx4927_ccfg_set(TX4927_CCFG_TOE); |
| 127 | |
| 128 | /* DMA selection */ |
| 129 | txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_DMASEL_ALL); |
| 130 | |
| 131 | /* Use external clock for external arbiter */ |
| 132 | if (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB)) |
| 133 | txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_PCICLKEN_ALL); |
| 134 | |
| 135 | printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n", |
| 136 | txx9_pcode_str, |
| 137 | (cpuclk + 500000) / 1000000, |
| 138 | (txx9_master_clock + 500000) / 1000000, |
| 139 | (__u32)____raw_readq(&tx4927_ccfgptr->crir), |
| 140 | (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg), |
| 141 | (unsigned long long)____raw_readq(&tx4927_ccfgptr->pcfg)); |
| 142 | |
| 143 | printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str); |
| 144 | for (i = 0; i < 4; i++) { |
| 145 | __u64 cr = TX4927_SDRAMC_CR(i); |
| 146 | unsigned long base, size; |
| 147 | if (!((__u32)cr & 0x00000400)) |
| 148 | continue; /* disabled */ |
| 149 | base = (unsigned long)(cr >> 49) << 21; |
| 150 | size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21; |
| 151 | printk(" CR%d:%016llx", i, (unsigned long long)cr); |
| 152 | tx4927_sdram_resource[i].name = "SDRAM"; |
| 153 | tx4927_sdram_resource[i].start = base; |
| 154 | tx4927_sdram_resource[i].end = base + size - 1; |
| 155 | tx4927_sdram_resource[i].flags = IORESOURCE_MEM; |
| 156 | request_resource(&iomem_resource, &tx4927_sdram_resource[i]); |
| 157 | } |
| 158 | printk(" TR:%09llx\n", |
| 159 | (unsigned long long)____raw_readq(&tx4927_sdramcptr->tr)); |
| 160 | |
| 161 | /* TMR */ |
| 162 | /* disable all timers */ |
| 163 | for (i = 0; i < TX4927_NR_TMR; i++) |
| 164 | txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL); |
| 165 | |
| 166 | /* PIO */ |
| 167 | txx9_gpio_init(TX4927_PIO_REG & 0xfffffffffULL, 0, TX4927_NUM_PIO); |
| 168 | __raw_writel(0, &tx4927_pioptr->maskcpu); |
| 169 | __raw_writel(0, &tx4927_pioptr->maskext); |
| 170 | } |
| 171 | |
| 172 | void __init tx4927_time_init(unsigned int tmrnr) |
| 173 | { |
| 174 | if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS) |
| 175 | txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL, |
| 176 | TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr), |
| 177 | TXX9_IMCLK); |
| 178 | } |
| 179 | |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame^] | 180 | void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 181 | { |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 182 | int i; |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 183 | |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame^] | 184 | for (i = 0; i < 2; i++) |
| 185 | txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL, |
| 186 | TXX9_IRQ_BASE + TX4927_IR_SIO(i), |
| 187 | i, sclk, (1 << i) & cts_mask); |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 188 | } |