setup_tx4938.c 7.9 KB

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