setup_tx4938.c 14 KB

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