setup_tx4927.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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/dmac.h>
  26. #include <asm/txx9/tx4927.h>
  27. static void __init tx4927_wdr_init(void)
  28. {
  29. /* report watchdog reset status */
  30. if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST)
  31. pr_warn("Watchdog reset detected at 0x%lx\n",
  32. read_c0_errorepc());
  33. /* clear WatchDogReset (W1C) */
  34. tx4927_ccfg_set(TX4927_CCFG_WDRST);
  35. /* do reset on watchdog */
  36. tx4927_ccfg_set(TX4927_CCFG_WR);
  37. }
  38. void __init tx4927_wdt_init(void)
  39. {
  40. txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL);
  41. }
  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. void show_registers(struct pt_regs *regs);
  63. static int tx4927_be_handler(struct pt_regs *regs, int is_fixup)
  64. {
  65. int data = regs->cp0_cause & 4;
  66. console_verbose();
  67. pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);
  68. pr_err("ccfg:%llx, toea:%llx\n",
  69. (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),
  70. (unsigned long long)____raw_readq(&tx4927_ccfgptr->toea));
  71. #ifdef CONFIG_PCI
  72. tx4927_report_pcic_status();
  73. #endif
  74. show_registers(regs);
  75. panic("BusError!");
  76. }
  77. static void __init tx4927_be_init(void)
  78. {
  79. board_be_handler = tx4927_be_handler;
  80. }
  81. static struct resource tx4927_sdram_resource[4];
  82. void __init tx4927_setup(void)
  83. {
  84. int i;
  85. __u32 divmode;
  86. unsigned int cpuclk = 0;
  87. u64 ccfg;
  88. txx9_reg_res_init(TX4927_REV_PCODE(), TX4927_REG_BASE,
  89. TX4927_REG_SIZE);
  90. set_c0_config(TX49_CONF_CWFON);
  91. /* SDRAMC,EBUSC are configured by PROM */
  92. for (i = 0; i < 8; i++) {
  93. if (!(TX4927_EBUSC_CR(i) & 0x8))
  94. continue; /* disabled */
  95. txx9_ce_res[i].start = (unsigned long)TX4927_EBUSC_BA(i);
  96. txx9_ce_res[i].end =
  97. txx9_ce_res[i].start + TX4927_EBUSC_SIZE(i) - 1;
  98. request_resource(&iomem_resource, &txx9_ce_res[i]);
  99. }
  100. /* clocks */
  101. ccfg = ____raw_readq(&tx4927_ccfgptr->ccfg);
  102. if (txx9_master_clock) {
  103. /* calculate gbus_clock and cpu_clock from master_clock */
  104. divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
  105. switch (divmode) {
  106. case TX4927_CCFG_DIVMODE_8:
  107. case TX4927_CCFG_DIVMODE_10:
  108. case TX4927_CCFG_DIVMODE_12:
  109. case TX4927_CCFG_DIVMODE_16:
  110. txx9_gbus_clock = txx9_master_clock * 4; break;
  111. default:
  112. txx9_gbus_clock = txx9_master_clock;
  113. }
  114. switch (divmode) {
  115. case TX4927_CCFG_DIVMODE_2:
  116. case TX4927_CCFG_DIVMODE_8:
  117. cpuclk = txx9_gbus_clock * 2; break;
  118. case TX4927_CCFG_DIVMODE_2_5:
  119. case TX4927_CCFG_DIVMODE_10:
  120. cpuclk = txx9_gbus_clock * 5 / 2; break;
  121. case TX4927_CCFG_DIVMODE_3:
  122. case TX4927_CCFG_DIVMODE_12:
  123. cpuclk = txx9_gbus_clock * 3; break;
  124. case TX4927_CCFG_DIVMODE_4:
  125. case TX4927_CCFG_DIVMODE_16:
  126. cpuclk = txx9_gbus_clock * 4; break;
  127. }
  128. txx9_cpu_clock = cpuclk;
  129. } else {
  130. if (txx9_cpu_clock == 0)
  131. txx9_cpu_clock = 200000000; /* 200MHz */
  132. /* calculate gbus_clock and master_clock from cpu_clock */
  133. cpuclk = txx9_cpu_clock;
  134. divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
  135. switch (divmode) {
  136. case TX4927_CCFG_DIVMODE_2:
  137. case TX4927_CCFG_DIVMODE_8:
  138. txx9_gbus_clock = cpuclk / 2; break;
  139. case TX4927_CCFG_DIVMODE_2_5:
  140. case TX4927_CCFG_DIVMODE_10:
  141. txx9_gbus_clock = cpuclk * 2 / 5; break;
  142. case TX4927_CCFG_DIVMODE_3:
  143. case TX4927_CCFG_DIVMODE_12:
  144. txx9_gbus_clock = cpuclk / 3; break;
  145. case TX4927_CCFG_DIVMODE_4:
  146. case TX4927_CCFG_DIVMODE_16:
  147. txx9_gbus_clock = cpuclk / 4; break;
  148. }
  149. switch (divmode) {
  150. case TX4927_CCFG_DIVMODE_8:
  151. case TX4927_CCFG_DIVMODE_10:
  152. case TX4927_CCFG_DIVMODE_12:
  153. case TX4927_CCFG_DIVMODE_16:
  154. txx9_master_clock = txx9_gbus_clock / 4; break;
  155. default:
  156. txx9_master_clock = txx9_gbus_clock;
  157. }
  158. }
  159. /* change default value to udelay/mdelay take reasonable time */
  160. loops_per_jiffy = txx9_cpu_clock / HZ / 2;
  161. /* CCFG */
  162. tx4927_wdr_init();
  163. /* clear BusErrorOnWrite flag (W1C) */
  164. tx4927_ccfg_set(TX4927_CCFG_BEOW);
  165. /* enable Timeout BusError */
  166. if (txx9_ccfg_toeon)
  167. tx4927_ccfg_set(TX4927_CCFG_TOE);
  168. /* DMA selection */
  169. txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_DMASEL_ALL);
  170. /* Use external clock for external arbiter */
  171. if (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB))
  172. txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_PCICLKEN_ALL);
  173. printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
  174. txx9_pcode_str,
  175. (cpuclk + 500000) / 1000000,
  176. (txx9_master_clock + 500000) / 1000000,
  177. (__u32)____raw_readq(&tx4927_ccfgptr->crir),
  178. (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),
  179. (unsigned long long)____raw_readq(&tx4927_ccfgptr->pcfg));
  180. printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
  181. for (i = 0; i < 4; i++) {
  182. __u64 cr = TX4927_SDRAMC_CR(i);
  183. unsigned long base, size;
  184. if (!((__u32)cr & 0x00000400))
  185. continue; /* disabled */
  186. base = (unsigned long)(cr >> 49) << 21;
  187. size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
  188. printk(" CR%d:%016llx", i, (unsigned long long)cr);
  189. tx4927_sdram_resource[i].name = "SDRAM";
  190. tx4927_sdram_resource[i].start = base;
  191. tx4927_sdram_resource[i].end = base + size - 1;
  192. tx4927_sdram_resource[i].flags = IORESOURCE_MEM;
  193. request_resource(&iomem_resource, &tx4927_sdram_resource[i]);
  194. }
  195. printk(" TR:%09llx\n",
  196. (unsigned long long)____raw_readq(&tx4927_sdramcptr->tr));
  197. /* TMR */
  198. /* disable all timers */
  199. for (i = 0; i < TX4927_NR_TMR; i++)
  200. txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL);
  201. /* 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. void __init tx4927_dmac_init(int memcpy_chan)
  234. {
  235. struct txx9dmac_platform_data plat_data = {
  236. .memcpy_chan = memcpy_chan,
  237. .have_64bit_regs = true,
  238. };
  239. txx9_dmac_init(0, TX4927_DMA_REG & 0xfffffffffULL,
  240. TXX9_IRQ_BASE + TX4927_IR_DMA(0), &plat_data);
  241. }
  242. void __init tx4927_aclc_init(unsigned int dma_chan_out,
  243. unsigned int dma_chan_in)
  244. {
  245. u64 pcfg = __raw_readq(&tx4927_ccfgptr->pcfg);
  246. __u64 dmasel_mask = 0, dmasel = 0;
  247. unsigned long flags;
  248. if (!(pcfg & TX4927_PCFG_SEL2))
  249. return;
  250. /* setup DMASEL (playback:ACLC ch0, capture:ACLC ch1) */
  251. switch (dma_chan_out) {
  252. case 0:
  253. dmasel_mask |= TX4927_PCFG_DMASEL0_MASK;
  254. dmasel |= TX4927_PCFG_DMASEL0_ACL0;
  255. break;
  256. case 2:
  257. dmasel_mask |= TX4927_PCFG_DMASEL2_MASK;
  258. dmasel |= TX4927_PCFG_DMASEL2_ACL0;
  259. break;
  260. default:
  261. return;
  262. }
  263. switch (dma_chan_in) {
  264. case 1:
  265. dmasel_mask |= TX4927_PCFG_DMASEL1_MASK;
  266. dmasel |= TX4927_PCFG_DMASEL1_ACL1;
  267. break;
  268. case 3:
  269. dmasel_mask |= TX4927_PCFG_DMASEL3_MASK;
  270. dmasel |= TX4927_PCFG_DMASEL3_ACL1;
  271. break;
  272. default:
  273. return;
  274. }
  275. local_irq_save(flags);
  276. txx9_clear64(&tx4927_ccfgptr->pcfg, dmasel_mask);
  277. txx9_set64(&tx4927_ccfgptr->pcfg, dmasel);
  278. local_irq_restore(flags);
  279. txx9_aclc_init(TX4927_ACLC_REG & 0xfffffffffULL,
  280. TXX9_IRQ_BASE + TX4927_IR_ACLC,
  281. 0, dma_chan_out, dma_chan_in);
  282. }
  283. static void __init tx4927_stop_unused_modules(void)
  284. {
  285. __u64 pcfg, rst = 0, ckd = 0;
  286. char buf[128];
  287. buf[0] = '\0';
  288. local_irq_disable();
  289. pcfg = ____raw_readq(&tx4927_ccfgptr->pcfg);
  290. if (!(pcfg & TX4927_PCFG_SEL2)) {
  291. rst |= TX4927_CLKCTR_ACLRST;
  292. ckd |= TX4927_CLKCTR_ACLCKD;
  293. strcat(buf, " ACLC");
  294. }
  295. if (rst | ckd) {
  296. txx9_set64(&tx4927_ccfgptr->clkctr, rst);
  297. txx9_set64(&tx4927_ccfgptr->clkctr, ckd);
  298. }
  299. local_irq_enable();
  300. if (buf[0])
  301. pr_info("%s: stop%s\n", txx9_pcode_str, buf);
  302. }
  303. static int __init tx4927_late_init(void)
  304. {
  305. if (txx9_pcode != 0x4927)
  306. return -ENODEV;
  307. tx4927_stop_unused_modules();
  308. return 0;
  309. }
  310. late_initcall(tx4927_late_init);