setup_tx4938.c 13 KB

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