setup_tx4938.c 13 KB

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