setup_tx4938.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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>
  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/tx4938.h>
  26. static void __init tx4938_wdr_init(void)
  27. {
  28. /* report watchdog reset status */
  29. if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)
  30. pr_warning("Watchdog reset detected at 0x%lx\n",
  31. read_c0_errorepc());
  32. /* clear WatchDogReset (W1C) */
  33. tx4938_ccfg_set(TX4938_CCFG_WDRST);
  34. /* do reset on watchdog */
  35. tx4938_ccfg_set(TX4938_CCFG_WR);
  36. }
  37. void __init tx4938_wdt_init(void)
  38. {
  39. txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
  40. }
  41. static void tx4938_machine_restart(char *command)
  42. {
  43. local_irq_disable();
  44. pr_emerg("Rebooting (with %s watchdog reset)...\n",
  45. (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?
  46. "external" : "internal");
  47. /* clear watchdog status */
  48. tx4938_ccfg_set(TX4938_CCFG_WDRST); /* W1C */
  49. txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);
  50. while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))
  51. ;
  52. mdelay(10);
  53. if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {
  54. pr_emerg("Rebooting (with internal watchdog reset)...\n");
  55. /* External WDRST failed. Do internal watchdog reset */
  56. tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);
  57. }
  58. /* fallback */
  59. (*_machine_halt)();
  60. }
  61. void show_registers(struct pt_regs *regs);
  62. static int tx4938_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(&tx4938_ccfgptr->ccfg),
  69. (unsigned long long)____raw_readq(&tx4938_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 tx4938_be_init(void)
  77. {
  78. board_be_handler = tx4938_be_handler;
  79. }
  80. static struct resource tx4938_sdram_resource[4];
  81. static struct resource tx4938_sram_resource;
  82. #define TX4938_SRAM_SIZE 0x800
  83. void __init tx4938_setup(void)
  84. {
  85. int i;
  86. __u32 divmode;
  87. int cpuclk = 0;
  88. u64 ccfg;
  89. txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
  90. TX4938_REG_SIZE);
  91. set_c0_config(TX49_CONF_CWFON);
  92. /* SDRAMC,EBUSC are configured by PROM */
  93. for (i = 0; i < 8; i++) {
  94. if (!(TX4938_EBUSC_CR(i) & 0x8))
  95. continue; /* disabled */
  96. txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
  97. txx9_ce_res[i].end =
  98. txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
  99. request_resource(&iomem_resource, &txx9_ce_res[i]);
  100. }
  101. /* clocks */
  102. ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
  103. if (txx9_master_clock) {
  104. /* calculate gbus_clock and cpu_clock from master_clock */
  105. divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
  106. switch (divmode) {
  107. case TX4938_CCFG_DIVMODE_8:
  108. case TX4938_CCFG_DIVMODE_10:
  109. case TX4938_CCFG_DIVMODE_12:
  110. case TX4938_CCFG_DIVMODE_16:
  111. case TX4938_CCFG_DIVMODE_18:
  112. txx9_gbus_clock = txx9_master_clock * 4; break;
  113. default:
  114. txx9_gbus_clock = txx9_master_clock;
  115. }
  116. switch (divmode) {
  117. case TX4938_CCFG_DIVMODE_2:
  118. case TX4938_CCFG_DIVMODE_8:
  119. cpuclk = txx9_gbus_clock * 2; break;
  120. case TX4938_CCFG_DIVMODE_2_5:
  121. case TX4938_CCFG_DIVMODE_10:
  122. cpuclk = txx9_gbus_clock * 5 / 2; break;
  123. case TX4938_CCFG_DIVMODE_3:
  124. case TX4938_CCFG_DIVMODE_12:
  125. cpuclk = txx9_gbus_clock * 3; break;
  126. case TX4938_CCFG_DIVMODE_4:
  127. case TX4938_CCFG_DIVMODE_16:
  128. cpuclk = txx9_gbus_clock * 4; break;
  129. case TX4938_CCFG_DIVMODE_4_5:
  130. case TX4938_CCFG_DIVMODE_18:
  131. cpuclk = txx9_gbus_clock * 9 / 2; break;
  132. }
  133. txx9_cpu_clock = cpuclk;
  134. } else {
  135. if (txx9_cpu_clock == 0)
  136. txx9_cpu_clock = 300000000; /* 300MHz */
  137. /* calculate gbus_clock and master_clock from cpu_clock */
  138. cpuclk = txx9_cpu_clock;
  139. divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
  140. switch (divmode) {
  141. case TX4938_CCFG_DIVMODE_2:
  142. case TX4938_CCFG_DIVMODE_8:
  143. txx9_gbus_clock = cpuclk / 2; break;
  144. case TX4938_CCFG_DIVMODE_2_5:
  145. case TX4938_CCFG_DIVMODE_10:
  146. txx9_gbus_clock = cpuclk * 2 / 5; break;
  147. case TX4938_CCFG_DIVMODE_3:
  148. case TX4938_CCFG_DIVMODE_12:
  149. txx9_gbus_clock = cpuclk / 3; break;
  150. case TX4938_CCFG_DIVMODE_4:
  151. case TX4938_CCFG_DIVMODE_16:
  152. txx9_gbus_clock = cpuclk / 4; break;
  153. case TX4938_CCFG_DIVMODE_4_5:
  154. case TX4938_CCFG_DIVMODE_18:
  155. txx9_gbus_clock = cpuclk * 2 / 9; break;
  156. }
  157. switch (divmode) {
  158. case TX4938_CCFG_DIVMODE_8:
  159. case TX4938_CCFG_DIVMODE_10:
  160. case TX4938_CCFG_DIVMODE_12:
  161. case TX4938_CCFG_DIVMODE_16:
  162. case TX4938_CCFG_DIVMODE_18:
  163. txx9_master_clock = txx9_gbus_clock / 4; break;
  164. default:
  165. txx9_master_clock = txx9_gbus_clock;
  166. }
  167. }
  168. /* change default value to udelay/mdelay take reasonable time */
  169. loops_per_jiffy = txx9_cpu_clock / HZ / 2;
  170. /* CCFG */
  171. tx4938_wdr_init();
  172. /* clear BusErrorOnWrite flag (W1C) */
  173. tx4938_ccfg_set(TX4938_CCFG_BEOW);
  174. /* enable Timeout BusError */
  175. if (txx9_ccfg_toeon)
  176. tx4938_ccfg_set(TX4938_CCFG_TOE);
  177. /* DMA selection */
  178. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
  179. /* Use external clock for external arbiter */
  180. if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
  181. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
  182. printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
  183. txx9_pcode_str,
  184. (cpuclk + 500000) / 1000000,
  185. (txx9_master_clock + 500000) / 1000000,
  186. (__u32)____raw_readq(&tx4938_ccfgptr->crir),
  187. (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
  188. (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
  189. printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
  190. for (i = 0; i < 4; i++) {
  191. __u64 cr = TX4938_SDRAMC_CR(i);
  192. unsigned long base, size;
  193. if (!((__u32)cr & 0x00000400))
  194. continue; /* disabled */
  195. base = (unsigned long)(cr >> 49) << 21;
  196. size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
  197. printk(" CR%d:%016llx", i, (unsigned long long)cr);
  198. tx4938_sdram_resource[i].name = "SDRAM";
  199. tx4938_sdram_resource[i].start = base;
  200. tx4938_sdram_resource[i].end = base + size - 1;
  201. tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
  202. request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
  203. }
  204. printk(" TR:%09llx\n",
  205. (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
  206. /* SRAM */
  207. if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
  208. unsigned int size = TX4938_SRAM_SIZE;
  209. tx4938_sram_resource.name = "SRAM";
  210. tx4938_sram_resource.start =
  211. (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
  212. & ~(size - 1);
  213. tx4938_sram_resource.end =
  214. tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
  215. tx4938_sram_resource.flags = IORESOURCE_MEM;
  216. request_resource(&iomem_resource, &tx4938_sram_resource);
  217. }
  218. /* TMR */
  219. /* disable all timers */
  220. for (i = 0; i < TX4938_NR_TMR; i++)
  221. txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
  222. /* DMA */
  223. for (i = 0; i < 2; i++)
  224. ____raw_writeq(TX4938_DMA_MCR_MSTEN,
  225. (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
  226. /* PIO */
  227. txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
  228. __raw_writel(0, &tx4938_pioptr->maskcpu);
  229. __raw_writel(0, &tx4938_pioptr->maskext);
  230. if (txx9_pcode == 0x4938) {
  231. __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
  232. /* set PCIC1 reset */
  233. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
  234. if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
  235. mdelay(1); /* at least 128 cpu clock */
  236. /* clear PCIC1 reset */
  237. txx9_clear64(&tx4938_ccfgptr->clkctr,
  238. TX4938_CLKCTR_PCIC1RST);
  239. } else {
  240. printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
  241. /* stop PCIC1 */
  242. txx9_set64(&tx4938_ccfgptr->clkctr,
  243. TX4938_CLKCTR_PCIC1CKD);
  244. }
  245. if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
  246. printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
  247. txx9_set64(&tx4938_ccfgptr->clkctr,
  248. TX4938_CLKCTR_ETH0RST);
  249. txx9_set64(&tx4938_ccfgptr->clkctr,
  250. TX4938_CLKCTR_ETH0CKD);
  251. }
  252. if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
  253. printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
  254. txx9_set64(&tx4938_ccfgptr->clkctr,
  255. TX4938_CLKCTR_ETH1RST);
  256. txx9_set64(&tx4938_ccfgptr->clkctr,
  257. TX4938_CLKCTR_ETH1CKD);
  258. }
  259. }
  260. _machine_restart = tx4938_machine_restart;
  261. board_be_init = tx4938_be_init;
  262. }
  263. void __init tx4938_time_init(unsigned int tmrnr)
  264. {
  265. if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
  266. txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
  267. TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
  268. TXX9_IMCLK);
  269. }
  270. void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
  271. {
  272. int i;
  273. unsigned int ch_mask = 0;
  274. if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
  275. ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
  276. for (i = 0; i < 2; i++) {
  277. if ((1 << i) & ch_mask)
  278. continue;
  279. txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
  280. TXX9_IRQ_BASE + TX4938_IR_SIO(i),
  281. i, sclk, (1 << i) & cts_mask);
  282. }
  283. }
  284. void __init tx4938_spi_init(int busid)
  285. {
  286. txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
  287. TXX9_IRQ_BASE + TX4938_IR_SPI);
  288. }
  289. void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
  290. {
  291. u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
  292. if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
  293. txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
  294. if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
  295. txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
  296. }
  297. void __init tx4938_mtd_init(int ch)
  298. {
  299. struct physmap_flash_data pdata = {
  300. .width = TX4938_EBUSC_WIDTH(ch) / 8,
  301. };
  302. unsigned long start = txx9_ce_res[ch].start;
  303. unsigned long size = txx9_ce_res[ch].end - start + 1;
  304. if (!(TX4938_EBUSC_CR(ch) & 0x8))
  305. return; /* disabled */
  306. txx9_physmap_flash_init(ch, start, size, &pdata);
  307. }
  308. static void __init tx4938_stop_unused_modules(void)
  309. {
  310. __u64 pcfg, rst = 0, ckd = 0;
  311. char buf[128];
  312. buf[0] = '\0';
  313. local_irq_disable();
  314. pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
  315. switch (txx9_pcode) {
  316. case 0x4937:
  317. if (!(pcfg & TX4938_PCFG_SEL2)) {
  318. rst |= TX4938_CLKCTR_ACLRST;
  319. ckd |= TX4938_CLKCTR_ACLCKD;
  320. strcat(buf, " ACLC");
  321. }
  322. break;
  323. case 0x4938:
  324. if (!(pcfg & TX4938_PCFG_SEL2) ||
  325. (pcfg & TX4938_PCFG_ETH0_SEL)) {
  326. rst |= TX4938_CLKCTR_ACLRST;
  327. ckd |= TX4938_CLKCTR_ACLCKD;
  328. strcat(buf, " ACLC");
  329. }
  330. if ((pcfg &
  331. (TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |
  332. TX4938_PCFG_NDF_SEL))
  333. != TX4938_PCFG_NDF_SEL) {
  334. rst |= TX4938_CLKCTR_NDFRST;
  335. ckd |= TX4938_CLKCTR_NDFCKD;
  336. strcat(buf, " NDFMC");
  337. }
  338. if (!(pcfg & TX4938_PCFG_SPI_SEL)) {
  339. rst |= TX4938_CLKCTR_SPIRST;
  340. ckd |= TX4938_CLKCTR_SPICKD;
  341. strcat(buf, " SPI");
  342. }
  343. break;
  344. }
  345. if (rst | ckd) {
  346. txx9_set64(&tx4938_ccfgptr->clkctr, rst);
  347. txx9_set64(&tx4938_ccfgptr->clkctr, ckd);
  348. }
  349. local_irq_enable();
  350. if (buf[0])
  351. pr_info("%s: stop%s\n", txx9_pcode_str, buf);
  352. }
  353. static int __init tx4938_late_init(void)
  354. {
  355. if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)
  356. return -ENODEV;
  357. tx4938_stop_unused_modules();
  358. return 0;
  359. }
  360. late_initcall(tx4938_late_init);