setup_tx4938.c 14 KB

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