setup_tx4927.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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>
  16. #include <linux/param.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/mtd/physmap.h>
  19. #include <asm/reboot.h>
  20. #include <asm/traps.h>
  21. #include <asm/txx9irq.h>
  22. #include <asm/txx9tmr.h>
  23. #include <asm/txx9pio.h>
  24. #include <asm/txx9/generic.h>
  25. #include <asm/txx9/tx4927.h>
  26. static void __init tx4927_wdr_init(void)
  27. {
  28. /* report watchdog reset status */
  29. if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST)
  30. pr_warning("Watchdog reset detected at 0x%lx\n",
  31. read_c0_errorepc());
  32. /* clear WatchDogReset (W1C) */
  33. tx4927_ccfg_set(TX4927_CCFG_WDRST);
  34. /* do reset on watchdog */
  35. tx4927_ccfg_set(TX4927_CCFG_WR);
  36. }
  37. void __init tx4927_wdt_init(void)
  38. {
  39. txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL);
  40. }
  41. static void tx4927_machine_restart(char *command)
  42. {
  43. local_irq_disable();
  44. pr_emerg("Rebooting (with %s watchdog reset)...\n",
  45. (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) ?
  46. "external" : "internal");
  47. /* clear watchdog status */
  48. tx4927_ccfg_set(TX4927_CCFG_WDRST); /* W1C */
  49. txx9_wdt_now(TX4927_TMR_REG(2) & 0xfffffffffULL);
  50. while (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST))
  51. ;
  52. mdelay(10);
  53. if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) {
  54. pr_emerg("Rebooting (with internal watchdog reset)...\n");
  55. /* External WDRST failed. Do internal watchdog reset */
  56. tx4927_ccfg_clear(TX4927_CCFG_WDREXEN);
  57. }
  58. /* fallback */
  59. (*_machine_halt)();
  60. }
  61. void show_registers(struct pt_regs *regs);
  62. static int tx4927_be_handler(struct pt_regs *regs, int is_fixup)
  63. {
  64. int data = regs->cp0_cause & 4;
  65. console_verbose();
  66. pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);
  67. pr_err("ccfg:%llx, toea:%llx\n",
  68. (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),
  69. (unsigned long long)____raw_readq(&tx4927_ccfgptr->toea));
  70. #ifdef CONFIG_PCI
  71. tx4927_report_pcic_status();
  72. #endif
  73. show_registers(regs);
  74. panic("BusError!");
  75. }
  76. static void __init tx4927_be_init(void)
  77. {
  78. board_be_handler = tx4927_be_handler;
  79. }
  80. static struct resource tx4927_sdram_resource[4];
  81. void __init tx4927_setup(void)
  82. {
  83. int i;
  84. __u32 divmode;
  85. int cpuclk = 0;
  86. u64 ccfg;
  87. txx9_reg_res_init(TX4927_REV_PCODE(), TX4927_REG_BASE,
  88. TX4927_REG_SIZE);
  89. set_c0_config(TX49_CONF_CWFON);
  90. /* SDRAMC,EBUSC are configured by PROM */
  91. for (i = 0; i < 8; i++) {
  92. if (!(TX4927_EBUSC_CR(i) & 0x8))
  93. continue; /* disabled */
  94. txx9_ce_res[i].start = (unsigned long)TX4927_EBUSC_BA(i);
  95. txx9_ce_res[i].end =
  96. txx9_ce_res[i].start + TX4927_EBUSC_SIZE(i) - 1;
  97. request_resource(&iomem_resource, &txx9_ce_res[i]);
  98. }
  99. /* clocks */
  100. ccfg = ____raw_readq(&tx4927_ccfgptr->ccfg);
  101. if (txx9_master_clock) {
  102. /* calculate gbus_clock and cpu_clock from master_clock */
  103. divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
  104. switch (divmode) {
  105. case TX4927_CCFG_DIVMODE_8:
  106. case TX4927_CCFG_DIVMODE_10:
  107. case TX4927_CCFG_DIVMODE_12:
  108. case TX4927_CCFG_DIVMODE_16:
  109. txx9_gbus_clock = txx9_master_clock * 4; break;
  110. default:
  111. txx9_gbus_clock = txx9_master_clock;
  112. }
  113. switch (divmode) {
  114. case TX4927_CCFG_DIVMODE_2:
  115. case TX4927_CCFG_DIVMODE_8:
  116. cpuclk = txx9_gbus_clock * 2; break;
  117. case TX4927_CCFG_DIVMODE_2_5:
  118. case TX4927_CCFG_DIVMODE_10:
  119. cpuclk = txx9_gbus_clock * 5 / 2; break;
  120. case TX4927_CCFG_DIVMODE_3:
  121. case TX4927_CCFG_DIVMODE_12:
  122. cpuclk = txx9_gbus_clock * 3; break;
  123. case TX4927_CCFG_DIVMODE_4:
  124. case TX4927_CCFG_DIVMODE_16:
  125. cpuclk = txx9_gbus_clock * 4; break;
  126. }
  127. txx9_cpu_clock = cpuclk;
  128. } else {
  129. if (txx9_cpu_clock == 0)
  130. txx9_cpu_clock = 200000000; /* 200MHz */
  131. /* calculate gbus_clock and master_clock from cpu_clock */
  132. cpuclk = txx9_cpu_clock;
  133. divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
  134. switch (divmode) {
  135. case TX4927_CCFG_DIVMODE_2:
  136. case TX4927_CCFG_DIVMODE_8:
  137. txx9_gbus_clock = cpuclk / 2; break;
  138. case TX4927_CCFG_DIVMODE_2_5:
  139. case TX4927_CCFG_DIVMODE_10:
  140. txx9_gbus_clock = cpuclk * 2 / 5; break;
  141. case TX4927_CCFG_DIVMODE_3:
  142. case TX4927_CCFG_DIVMODE_12:
  143. txx9_gbus_clock = cpuclk / 3; break;
  144. case TX4927_CCFG_DIVMODE_4:
  145. case TX4927_CCFG_DIVMODE_16:
  146. txx9_gbus_clock = cpuclk / 4; break;
  147. }
  148. switch (divmode) {
  149. case TX4927_CCFG_DIVMODE_8:
  150. case TX4927_CCFG_DIVMODE_10:
  151. case TX4927_CCFG_DIVMODE_12:
  152. case TX4927_CCFG_DIVMODE_16:
  153. txx9_master_clock = txx9_gbus_clock / 4; break;
  154. default:
  155. txx9_master_clock = txx9_gbus_clock;
  156. }
  157. }
  158. /* change default value to udelay/mdelay take reasonable time */
  159. loops_per_jiffy = txx9_cpu_clock / HZ / 2;
  160. /* CCFG */
  161. tx4927_wdr_init();
  162. /* clear BusErrorOnWrite flag (W1C) */
  163. tx4927_ccfg_set(TX4927_CCFG_BEOW);
  164. /* enable Timeout BusError */
  165. if (txx9_ccfg_toeon)
  166. tx4927_ccfg_set(TX4927_CCFG_TOE);
  167. /* DMA selection */
  168. txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_DMASEL_ALL);
  169. /* Use external clock for external arbiter */
  170. if (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB))
  171. txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_PCICLKEN_ALL);
  172. printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
  173. txx9_pcode_str,
  174. (cpuclk + 500000) / 1000000,
  175. (txx9_master_clock + 500000) / 1000000,
  176. (__u32)____raw_readq(&tx4927_ccfgptr->crir),
  177. (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),
  178. (unsigned long long)____raw_readq(&tx4927_ccfgptr->pcfg));
  179. printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
  180. for (i = 0; i < 4; i++) {
  181. __u64 cr = TX4927_SDRAMC_CR(i);
  182. unsigned long base, size;
  183. if (!((__u32)cr & 0x00000400))
  184. continue; /* disabled */
  185. base = (unsigned long)(cr >> 49) << 21;
  186. size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
  187. printk(" CR%d:%016llx", i, (unsigned long long)cr);
  188. tx4927_sdram_resource[i].name = "SDRAM";
  189. tx4927_sdram_resource[i].start = base;
  190. tx4927_sdram_resource[i].end = base + size - 1;
  191. tx4927_sdram_resource[i].flags = IORESOURCE_MEM;
  192. request_resource(&iomem_resource, &tx4927_sdram_resource[i]);
  193. }
  194. printk(" TR:%09llx\n",
  195. (unsigned long long)____raw_readq(&tx4927_sdramcptr->tr));
  196. /* TMR */
  197. /* disable all timers */
  198. for (i = 0; i < TX4927_NR_TMR; i++)
  199. txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL);
  200. /* PIO */
  201. txx9_gpio_init(TX4927_PIO_REG & 0xfffffffffULL, 0, TX4927_NUM_PIO);
  202. __raw_writel(0, &tx4927_pioptr->maskcpu);
  203. __raw_writel(0, &tx4927_pioptr->maskext);
  204. _machine_restart = tx4927_machine_restart;
  205. board_be_init = tx4927_be_init;
  206. }
  207. void __init tx4927_time_init(unsigned int tmrnr)
  208. {
  209. if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS)
  210. txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL,
  211. TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr),
  212. TXX9_IMCLK);
  213. }
  214. void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask)
  215. {
  216. int i;
  217. for (i = 0; i < 2; i++)
  218. txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL,
  219. TXX9_IRQ_BASE + TX4927_IR_SIO(i),
  220. i, sclk, (1 << i) & cts_mask);
  221. }
  222. void __init tx4927_mtd_init(int ch)
  223. {
  224. struct physmap_flash_data pdata = {
  225. .width = TX4927_EBUSC_WIDTH(ch) / 8,
  226. };
  227. unsigned long start = txx9_ce_res[ch].start;
  228. unsigned long size = txx9_ce_res[ch].end - start + 1;
  229. if (!(TX4927_EBUSC_CR(ch) & 0x8))
  230. return; /* disabled */
  231. txx9_physmap_flash_init(ch, start, size, &pdata);
  232. }
  233. static void __init tx4927_stop_unused_modules(void)
  234. {
  235. __u64 pcfg, rst = 0, ckd = 0;
  236. char buf[128];
  237. buf[0] = '\0';
  238. local_irq_disable();
  239. pcfg = ____raw_readq(&tx4927_ccfgptr->pcfg);
  240. if (!(pcfg & TX4927_PCFG_SEL2)) {
  241. rst |= TX4927_CLKCTR_ACLRST;
  242. ckd |= TX4927_CLKCTR_ACLCKD;
  243. strcat(buf, " ACLC");
  244. }
  245. if (rst | ckd) {
  246. txx9_set64(&tx4927_ccfgptr->clkctr, rst);
  247. txx9_set64(&tx4927_ccfgptr->clkctr, ckd);
  248. }
  249. local_irq_enable();
  250. if (buf[0])
  251. pr_info("%s: stop%s\n", txx9_pcode_str, buf);
  252. }
  253. static int __init tx4927_late_init(void)
  254. {
  255. if (txx9_pcode != 0x4927)
  256. return -ENODEV;
  257. tx4927_stop_unused_modules();
  258. return 0;
  259. }
  260. late_initcall(tx4927_late_init);