setup_tx4938.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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/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. board_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. printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
  186. txx9_pcode_str,
  187. (cpuclk + 500000) / 1000000,
  188. (txx9_master_clock + 500000) / 1000000,
  189. (__u32)____raw_readq(&tx4938_ccfgptr->crir),
  190. (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
  191. (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
  192. printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
  193. for (i = 0; i < 4; i++) {
  194. __u64 cr = TX4938_SDRAMC_CR(i);
  195. unsigned long base, size;
  196. if (!((__u32)cr & 0x00000400))
  197. continue; /* disabled */
  198. base = (unsigned long)(cr >> 49) << 21;
  199. size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
  200. printk(" CR%d:%016llx", i, (unsigned long long)cr);
  201. tx4938_sdram_resource[i].name = "SDRAM";
  202. tx4938_sdram_resource[i].start = base;
  203. tx4938_sdram_resource[i].end = base + size - 1;
  204. tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
  205. request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
  206. }
  207. printk(" TR:%09llx\n",
  208. (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
  209. /* SRAM */
  210. if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
  211. unsigned int size = TX4938_SRAM_SIZE;
  212. tx4938_sram_resource.name = "SRAM";
  213. tx4938_sram_resource.start =
  214. (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
  215. & ~(size - 1);
  216. tx4938_sram_resource.end =
  217. tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
  218. tx4938_sram_resource.flags = IORESOURCE_MEM;
  219. request_resource(&iomem_resource, &tx4938_sram_resource);
  220. }
  221. /* TMR */
  222. /* disable all timers */
  223. for (i = 0; i < TX4938_NR_TMR; i++)
  224. txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
  225. /* PIO */
  226. __raw_writel(0, &tx4938_pioptr->maskcpu);
  227. __raw_writel(0, &tx4938_pioptr->maskext);
  228. if (txx9_pcode == 0x4938) {
  229. __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
  230. /* set PCIC1 reset */
  231. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
  232. if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
  233. mdelay(1); /* at least 128 cpu clock */
  234. /* clear PCIC1 reset */
  235. txx9_clear64(&tx4938_ccfgptr->clkctr,
  236. TX4938_CLKCTR_PCIC1RST);
  237. } else {
  238. printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
  239. /* stop PCIC1 */
  240. txx9_set64(&tx4938_ccfgptr->clkctr,
  241. TX4938_CLKCTR_PCIC1CKD);
  242. }
  243. if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
  244. printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
  245. txx9_set64(&tx4938_ccfgptr->clkctr,
  246. TX4938_CLKCTR_ETH0RST);
  247. txx9_set64(&tx4938_ccfgptr->clkctr,
  248. TX4938_CLKCTR_ETH0CKD);
  249. }
  250. if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
  251. printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
  252. txx9_set64(&tx4938_ccfgptr->clkctr,
  253. TX4938_CLKCTR_ETH1RST);
  254. txx9_set64(&tx4938_ccfgptr->clkctr,
  255. TX4938_CLKCTR_ETH1CKD);
  256. }
  257. }
  258. _machine_restart = tx4938_machine_restart;
  259. board_be_init = tx4938_be_init;
  260. }
  261. void __init tx4938_time_init(unsigned int tmrnr)
  262. {
  263. if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
  264. txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
  265. TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
  266. TXX9_IMCLK);
  267. }
  268. void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
  269. {
  270. int i;
  271. unsigned int ch_mask = 0;
  272. if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
  273. ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
  274. for (i = 0; i < 2; i++) {
  275. if ((1 << i) & ch_mask)
  276. continue;
  277. txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
  278. TXX9_IRQ_BASE + TX4938_IR_SIO(i),
  279. i, sclk, (1 << i) & cts_mask);
  280. }
  281. }
  282. void __init tx4938_spi_init(int busid)
  283. {
  284. txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
  285. TXX9_IRQ_BASE + TX4938_IR_SPI);
  286. }
  287. void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
  288. {
  289. u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
  290. if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
  291. txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
  292. if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
  293. txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
  294. }
  295. void __init tx4938_mtd_init(int ch)
  296. {
  297. struct physmap_flash_data pdata = {
  298. .width = TX4938_EBUSC_WIDTH(ch) / 8,
  299. };
  300. unsigned long start = txx9_ce_res[ch].start;
  301. unsigned long size = txx9_ce_res[ch].end - start + 1;
  302. if (!(TX4938_EBUSC_CR(ch) & 0x8))
  303. return; /* disabled */
  304. txx9_physmap_flash_init(ch, start, size, &pdata);
  305. }
  306. void __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)
  307. {
  308. struct platform_device *pdev;
  309. struct resource res[] = {
  310. {
  311. /* .start and .end are filled in later */
  312. .flags = IORESOURCE_MEM,
  313. }, {
  314. .start = irq,
  315. .flags = IORESOURCE_IRQ,
  316. },
  317. };
  318. struct tx4938ide_platform_info pdata = {
  319. .ioport_shift = shift,
  320. /*
  321. * The IDE driver should not change bus timings if other ISA
  322. * devices existed.
  323. */
  324. .gbus_clock = tune ? txx9_gbus_clock : 0,
  325. };
  326. u64 ebccr;
  327. int i;
  328. if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
  329. (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL))
  330. != TX4938_PCFG_ATA_SEL)
  331. return;
  332. for (i = 0; i < 8; i++) {
  333. /* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */
  334. ebccr = __raw_readq(&tx4938_ebuscptr->cr[i]);
  335. if ((ebccr & 0x00f00008) == 0x00e00008)
  336. break;
  337. }
  338. if (i == 8)
  339. return;
  340. pdata.ebus_ch = i;
  341. res[0].start = ((ebccr >> 48) << 20) + 0x10000;
  342. res[0].end = res[0].start + 0x20000 - 1;
  343. pdev = platform_device_alloc("tx4938ide", -1);
  344. if (!pdev ||
  345. platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
  346. platform_device_add_data(pdev, &pdata, sizeof(pdata)) ||
  347. platform_device_add(pdev))
  348. platform_device_put(pdev);
  349. }
  350. void __init tx4938_ndfmc_init(unsigned int hold, unsigned int spw)
  351. {
  352. struct txx9ndfmc_platform_data plat_data = {
  353. .shift = 1,
  354. .gbus_clock = txx9_gbus_clock,
  355. .hold = hold,
  356. .spw = spw,
  357. .ch_mask = 1,
  358. };
  359. unsigned long baseaddr = TX4938_NDFMC_REG & 0xfffffffffULL;
  360. #ifdef __BIG_ENDIAN
  361. baseaddr += 4;
  362. #endif
  363. if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
  364. (TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) ==
  365. TX4938_PCFG_NDF_SEL)
  366. txx9_ndfmc_init(baseaddr, &plat_data);
  367. }
  368. void __init tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1)
  369. {
  370. struct txx9dmac_platform_data plat_data = {
  371. .have_64bit_regs = true,
  372. };
  373. int i;
  374. for (i = 0; i < 2; i++) {
  375. plat_data.memcpy_chan = i ? memcpy_chan1 : memcpy_chan0;
  376. txx9_dmac_init(i, TX4938_DMA_REG(i) & 0xfffffffffULL,
  377. TXX9_IRQ_BASE + TX4938_IR_DMA(i, 0),
  378. &plat_data);
  379. }
  380. }
  381. void __init tx4938_aclc_init(void)
  382. {
  383. u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
  384. if ((pcfg & TX4938_PCFG_SEL2) &&
  385. !(pcfg & TX4938_PCFG_ETH0_SEL))
  386. txx9_aclc_init(TX4938_ACLC_REG & 0xfffffffffULL,
  387. TXX9_IRQ_BASE + TX4938_IR_ACLC,
  388. 1, 0, 1);
  389. }
  390. void __init tx4938_sramc_init(void)
  391. {
  392. if (tx4938_sram_resource.start)
  393. txx9_sramc_init(&tx4938_sram_resource);
  394. }
  395. static void __init tx4938_stop_unused_modules(void)
  396. {
  397. __u64 pcfg, rst = 0, ckd = 0;
  398. char buf[128];
  399. buf[0] = '\0';
  400. local_irq_disable();
  401. pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
  402. switch (txx9_pcode) {
  403. case 0x4937:
  404. if (!(pcfg & TX4938_PCFG_SEL2)) {
  405. rst |= TX4938_CLKCTR_ACLRST;
  406. ckd |= TX4938_CLKCTR_ACLCKD;
  407. strcat(buf, " ACLC");
  408. }
  409. break;
  410. case 0x4938:
  411. if (!(pcfg & TX4938_PCFG_SEL2) ||
  412. (pcfg & TX4938_PCFG_ETH0_SEL)) {
  413. rst |= TX4938_CLKCTR_ACLRST;
  414. ckd |= TX4938_CLKCTR_ACLCKD;
  415. strcat(buf, " ACLC");
  416. }
  417. if ((pcfg &
  418. (TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |
  419. TX4938_PCFG_NDF_SEL))
  420. != TX4938_PCFG_NDF_SEL) {
  421. rst |= TX4938_CLKCTR_NDFRST;
  422. ckd |= TX4938_CLKCTR_NDFCKD;
  423. strcat(buf, " NDFMC");
  424. }
  425. if (!(pcfg & TX4938_PCFG_SPI_SEL)) {
  426. rst |= TX4938_CLKCTR_SPIRST;
  427. ckd |= TX4938_CLKCTR_SPICKD;
  428. strcat(buf, " SPI");
  429. }
  430. break;
  431. }
  432. if (rst | ckd) {
  433. txx9_set64(&tx4938_ccfgptr->clkctr, rst);
  434. txx9_set64(&tx4938_ccfgptr->clkctr, ckd);
  435. }
  436. local_irq_enable();
  437. if (buf[0])
  438. pr_info("%s: stop%s\n", txx9_pcode_str, buf);
  439. }
  440. static int __init tx4938_late_init(void)
  441. {
  442. if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)
  443. return -ENODEV;
  444. tx4938_stop_unused_modules();
  445. return 0;
  446. }
  447. late_initcall(tx4938_late_init);