setup_tx4927.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. mips_set_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. pr_info("%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
  174. txx9_pcode_str, (cpuclk + 500000) / 1000000,
  175. (txx9_master_clock + 500000) / 1000000,
  176. (__u32)____raw_readq(&tx4927_ccfgptr->crir),
  177. ____raw_readq(&tx4927_ccfgptr->ccfg),
  178. ____raw_readq(&tx4927_ccfgptr->pcfg));
  179. pr_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. pr_cont(" CR%d:%016llx", i, 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. pr_cont(" TR:%09llx\n", ____raw_readq(&tx4927_sdramcptr->tr));
  195. /* TMR */
  196. /* disable all timers */
  197. for (i = 0; i < TX4927_NR_TMR; i++)
  198. txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL);
  199. /* PIO */
  200. __raw_writel(0, &tx4927_pioptr->maskcpu);
  201. __raw_writel(0, &tx4927_pioptr->maskext);
  202. _machine_restart = tx4927_machine_restart;
  203. board_be_init = tx4927_be_init;
  204. }
  205. void __init tx4927_time_init(unsigned int tmrnr)
  206. {
  207. if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS)
  208. txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL,
  209. TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr),
  210. TXX9_IMCLK);
  211. }
  212. void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask)
  213. {
  214. int i;
  215. for (i = 0; i < 2; i++)
  216. txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL,
  217. TXX9_IRQ_BASE + TX4927_IR_SIO(i),
  218. i, sclk, (1 << i) & cts_mask);
  219. }
  220. void __init tx4927_mtd_init(int ch)
  221. {
  222. struct physmap_flash_data pdata = {
  223. .width = TX4927_EBUSC_WIDTH(ch) / 8,
  224. };
  225. unsigned long start = txx9_ce_res[ch].start;
  226. unsigned long size = txx9_ce_res[ch].end - start + 1;
  227. if (!(TX4927_EBUSC_CR(ch) & 0x8))
  228. return; /* disabled */
  229. txx9_physmap_flash_init(ch, start, size, &pdata);
  230. }
  231. void __init tx4927_dmac_init(int memcpy_chan)
  232. {
  233. struct txx9dmac_platform_data plat_data = {
  234. .memcpy_chan = memcpy_chan,
  235. .have_64bit_regs = true,
  236. };
  237. txx9_dmac_init(0, TX4927_DMA_REG & 0xfffffffffULL,
  238. TXX9_IRQ_BASE + TX4927_IR_DMA(0), &plat_data);
  239. }
  240. void __init tx4927_aclc_init(unsigned int dma_chan_out,
  241. unsigned int dma_chan_in)
  242. {
  243. u64 pcfg = __raw_readq(&tx4927_ccfgptr->pcfg);
  244. __u64 dmasel_mask = 0, dmasel = 0;
  245. unsigned long flags;
  246. if (!(pcfg & TX4927_PCFG_SEL2))
  247. return;
  248. /* setup DMASEL (playback:ACLC ch0, capture:ACLC ch1) */
  249. switch (dma_chan_out) {
  250. case 0:
  251. dmasel_mask |= TX4927_PCFG_DMASEL0_MASK;
  252. dmasel |= TX4927_PCFG_DMASEL0_ACL0;
  253. break;
  254. case 2:
  255. dmasel_mask |= TX4927_PCFG_DMASEL2_MASK;
  256. dmasel |= TX4927_PCFG_DMASEL2_ACL0;
  257. break;
  258. default:
  259. return;
  260. }
  261. switch (dma_chan_in) {
  262. case 1:
  263. dmasel_mask |= TX4927_PCFG_DMASEL1_MASK;
  264. dmasel |= TX4927_PCFG_DMASEL1_ACL1;
  265. break;
  266. case 3:
  267. dmasel_mask |= TX4927_PCFG_DMASEL3_MASK;
  268. dmasel |= TX4927_PCFG_DMASEL3_ACL1;
  269. break;
  270. default:
  271. return;
  272. }
  273. local_irq_save(flags);
  274. txx9_clear64(&tx4927_ccfgptr->pcfg, dmasel_mask);
  275. txx9_set64(&tx4927_ccfgptr->pcfg, dmasel);
  276. local_irq_restore(flags);
  277. txx9_aclc_init(TX4927_ACLC_REG & 0xfffffffffULL,
  278. TXX9_IRQ_BASE + TX4927_IR_ACLC,
  279. 0, dma_chan_out, dma_chan_in);
  280. }
  281. static void __init tx4927_stop_unused_modules(void)
  282. {
  283. __u64 pcfg, rst = 0, ckd = 0;
  284. char buf[128];
  285. buf[0] = '\0';
  286. local_irq_disable();
  287. pcfg = ____raw_readq(&tx4927_ccfgptr->pcfg);
  288. if (!(pcfg & TX4927_PCFG_SEL2)) {
  289. rst |= TX4927_CLKCTR_ACLRST;
  290. ckd |= TX4927_CLKCTR_ACLCKD;
  291. strcat(buf, " ACLC");
  292. }
  293. if (rst | ckd) {
  294. txx9_set64(&tx4927_ccfgptr->clkctr, rst);
  295. txx9_set64(&tx4927_ccfgptr->clkctr, ckd);
  296. }
  297. local_irq_enable();
  298. if (buf[0])
  299. pr_info("%s: stop%s\n", txx9_pcode_str, buf);
  300. }
  301. static int __init tx4927_late_init(void)
  302. {
  303. if (txx9_pcode != 0x4927)
  304. return -ENODEV;
  305. tx4927_stop_unused_modules();
  306. return 0;
  307. }
  308. late_initcall(tx4927_late_init);