setup_tx4938.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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/serial_core.h>
  17. #include <linux/param.h>
  18. #include <asm/txx9irq.h>
  19. #include <asm/txx9tmr.h>
  20. #include <asm/txx9pio.h>
  21. #include <asm/txx9/generic.h>
  22. #include <asm/txx9/tx4938.h>
  23. static void __init tx4938_wdr_init(void)
  24. {
  25. /* clear WatchDogReset (W1C) */
  26. tx4938_ccfg_set(TX4938_CCFG_WDRST);
  27. /* do reset on watchdog */
  28. tx4938_ccfg_set(TX4938_CCFG_WR);
  29. }
  30. void __init tx4938_wdt_init(void)
  31. {
  32. txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
  33. }
  34. static struct resource tx4938_sdram_resource[4];
  35. static struct resource tx4938_sram_resource;
  36. #define TX4938_SRAM_SIZE 0x800
  37. void __init tx4938_setup(void)
  38. {
  39. int i;
  40. __u32 divmode;
  41. int cpuclk = 0;
  42. u64 ccfg;
  43. txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
  44. TX4938_REG_SIZE);
  45. /* SDRAMC,EBUSC are configured by PROM */
  46. for (i = 0; i < 8; i++) {
  47. if (!(TX4938_EBUSC_CR(i) & 0x8))
  48. continue; /* disabled */
  49. txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
  50. txx9_ce_res[i].end =
  51. txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
  52. request_resource(&iomem_resource, &txx9_ce_res[i]);
  53. }
  54. /* clocks */
  55. ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
  56. if (txx9_master_clock) {
  57. /* calculate gbus_clock and cpu_clock from master_clock */
  58. divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
  59. switch (divmode) {
  60. case TX4938_CCFG_DIVMODE_8:
  61. case TX4938_CCFG_DIVMODE_10:
  62. case TX4938_CCFG_DIVMODE_12:
  63. case TX4938_CCFG_DIVMODE_16:
  64. case TX4938_CCFG_DIVMODE_18:
  65. txx9_gbus_clock = txx9_master_clock * 4; break;
  66. default:
  67. txx9_gbus_clock = txx9_master_clock;
  68. }
  69. switch (divmode) {
  70. case TX4938_CCFG_DIVMODE_2:
  71. case TX4938_CCFG_DIVMODE_8:
  72. cpuclk = txx9_gbus_clock * 2; break;
  73. case TX4938_CCFG_DIVMODE_2_5:
  74. case TX4938_CCFG_DIVMODE_10:
  75. cpuclk = txx9_gbus_clock * 5 / 2; break;
  76. case TX4938_CCFG_DIVMODE_3:
  77. case TX4938_CCFG_DIVMODE_12:
  78. cpuclk = txx9_gbus_clock * 3; break;
  79. case TX4938_CCFG_DIVMODE_4:
  80. case TX4938_CCFG_DIVMODE_16:
  81. cpuclk = txx9_gbus_clock * 4; break;
  82. case TX4938_CCFG_DIVMODE_4_5:
  83. case TX4938_CCFG_DIVMODE_18:
  84. cpuclk = txx9_gbus_clock * 9 / 2; break;
  85. }
  86. txx9_cpu_clock = cpuclk;
  87. } else {
  88. if (txx9_cpu_clock == 0)
  89. txx9_cpu_clock = 300000000; /* 300MHz */
  90. /* calculate gbus_clock and master_clock from cpu_clock */
  91. cpuclk = txx9_cpu_clock;
  92. divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
  93. switch (divmode) {
  94. case TX4938_CCFG_DIVMODE_2:
  95. case TX4938_CCFG_DIVMODE_8:
  96. txx9_gbus_clock = cpuclk / 2; break;
  97. case TX4938_CCFG_DIVMODE_2_5:
  98. case TX4938_CCFG_DIVMODE_10:
  99. txx9_gbus_clock = cpuclk * 2 / 5; break;
  100. case TX4938_CCFG_DIVMODE_3:
  101. case TX4938_CCFG_DIVMODE_12:
  102. txx9_gbus_clock = cpuclk / 3; break;
  103. case TX4938_CCFG_DIVMODE_4:
  104. case TX4938_CCFG_DIVMODE_16:
  105. txx9_gbus_clock = cpuclk / 4; break;
  106. case TX4938_CCFG_DIVMODE_4_5:
  107. case TX4938_CCFG_DIVMODE_18:
  108. txx9_gbus_clock = cpuclk * 2 / 9; break;
  109. }
  110. switch (divmode) {
  111. case TX4938_CCFG_DIVMODE_8:
  112. case TX4938_CCFG_DIVMODE_10:
  113. case TX4938_CCFG_DIVMODE_12:
  114. case TX4938_CCFG_DIVMODE_16:
  115. case TX4938_CCFG_DIVMODE_18:
  116. txx9_master_clock = txx9_gbus_clock / 4; break;
  117. default:
  118. txx9_master_clock = txx9_gbus_clock;
  119. }
  120. }
  121. /* change default value to udelay/mdelay take reasonable time */
  122. loops_per_jiffy = txx9_cpu_clock / HZ / 2;
  123. /* CCFG */
  124. tx4938_wdr_init();
  125. /* clear BusErrorOnWrite flag (W1C) */
  126. tx4938_ccfg_set(TX4938_CCFG_BEOW);
  127. /* enable Timeout BusError */
  128. if (txx9_ccfg_toeon)
  129. tx4938_ccfg_set(TX4938_CCFG_TOE);
  130. /* DMA selection */
  131. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
  132. /* Use external clock for external arbiter */
  133. if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
  134. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
  135. printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
  136. txx9_pcode_str,
  137. (cpuclk + 500000) / 1000000,
  138. (txx9_master_clock + 500000) / 1000000,
  139. (__u32)____raw_readq(&tx4938_ccfgptr->crir),
  140. (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
  141. (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
  142. printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
  143. for (i = 0; i < 4; i++) {
  144. __u64 cr = TX4938_SDRAMC_CR(i);
  145. unsigned long base, size;
  146. if (!((__u32)cr & 0x00000400))
  147. continue; /* disabled */
  148. base = (unsigned long)(cr >> 49) << 21;
  149. size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
  150. printk(" CR%d:%016llx", i, (unsigned long long)cr);
  151. tx4938_sdram_resource[i].name = "SDRAM";
  152. tx4938_sdram_resource[i].start = base;
  153. tx4938_sdram_resource[i].end = base + size - 1;
  154. tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
  155. request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
  156. }
  157. printk(" TR:%09llx\n",
  158. (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
  159. /* SRAM */
  160. if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
  161. unsigned int size = TX4938_SRAM_SIZE;
  162. tx4938_sram_resource.name = "SRAM";
  163. tx4938_sram_resource.start =
  164. (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
  165. & ~(size - 1);
  166. tx4938_sram_resource.end =
  167. tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
  168. tx4938_sram_resource.flags = IORESOURCE_MEM;
  169. request_resource(&iomem_resource, &tx4938_sram_resource);
  170. }
  171. /* TMR */
  172. /* disable all timers */
  173. for (i = 0; i < TX4938_NR_TMR; i++)
  174. txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
  175. /* DMA */
  176. for (i = 0; i < 2; i++)
  177. ____raw_writeq(TX4938_DMA_MCR_MSTEN,
  178. (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
  179. /* PIO */
  180. txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
  181. __raw_writel(0, &tx4938_pioptr->maskcpu);
  182. __raw_writel(0, &tx4938_pioptr->maskext);
  183. if (txx9_pcode == 0x4938) {
  184. __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
  185. /* set PCIC1 reset */
  186. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
  187. if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
  188. mdelay(1); /* at least 128 cpu clock */
  189. /* clear PCIC1 reset */
  190. txx9_clear64(&tx4938_ccfgptr->clkctr,
  191. TX4938_CLKCTR_PCIC1RST);
  192. } else {
  193. printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
  194. /* stop PCIC1 */
  195. txx9_set64(&tx4938_ccfgptr->clkctr,
  196. TX4938_CLKCTR_PCIC1CKD);
  197. }
  198. if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
  199. printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
  200. txx9_set64(&tx4938_ccfgptr->clkctr,
  201. TX4938_CLKCTR_ETH0RST);
  202. txx9_set64(&tx4938_ccfgptr->clkctr,
  203. TX4938_CLKCTR_ETH0CKD);
  204. }
  205. if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
  206. printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
  207. txx9_set64(&tx4938_ccfgptr->clkctr,
  208. TX4938_CLKCTR_ETH1RST);
  209. txx9_set64(&tx4938_ccfgptr->clkctr,
  210. TX4938_CLKCTR_ETH1CKD);
  211. }
  212. }
  213. }
  214. void __init tx4938_time_init(unsigned int tmrnr)
  215. {
  216. if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
  217. txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
  218. TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
  219. TXX9_IMCLK);
  220. }
  221. void __init tx4938_setup_serial(void)
  222. {
  223. #ifdef CONFIG_SERIAL_TXX9
  224. int i;
  225. struct uart_port req;
  226. unsigned int ch_mask = 0;
  227. if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
  228. ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
  229. for (i = 0; i < 2; i++) {
  230. if ((1 << i) & ch_mask)
  231. continue;
  232. memset(&req, 0, sizeof(req));
  233. req.line = i;
  234. req.iotype = UPIO_MEM;
  235. req.membase = (unsigned char __iomem *)TX4938_SIO_REG(i);
  236. req.mapbase = TX4938_SIO_REG(i) & 0xfffffffffULL;
  237. req.irq = TXX9_IRQ_BASE + TX4938_IR_SIO(i);
  238. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  239. req.uartclk = TXX9_IMCLK;
  240. early_serial_txx9_setup(&req);
  241. }
  242. #endif /* CONFIG_SERIAL_TXX9 */
  243. }