mach-ox820.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. #include <linux/init.h>
  2. #include <linux/kernel.h>
  3. #include <linux/bug.h>
  4. #include <linux/of_platform.h>
  5. #include <linux/clocksource.h>
  6. #include <linux/clk-provider.h>
  7. #include <linux/clk.h>
  8. #include <linux/stmmac.h>
  9. #include <linux/slab.h>
  10. #include <linux/gfp.h>
  11. #include <linux/reset.h>
  12. #include <asm/mach-types.h>
  13. #include <asm/mach/map.h>
  14. #include <asm/mach/arch.h>
  15. #include <asm/page.h>
  16. #include <mach/iomap.h>
  17. #include <mach/hardware.h>
  18. #include <mach/utils.h>
  19. #include <mach/smp.h>
  20. static struct map_desc ox820_io_desc[] __initdata = {
  21. {
  22. .virtual = (unsigned long)OXNAS_PERCPU_BASE_VA,
  23. .pfn = __phys_to_pfn(OXNAS_PERCPU_BASE),
  24. .length = OXNAS_PERCPU_SIZE,
  25. .type = MT_DEVICE,
  26. },
  27. {
  28. .virtual = (unsigned long)OXNAS_SYSCRTL_BASE_VA,
  29. .pfn = __phys_to_pfn(OXNAS_SYSCRTL_BASE),
  30. .length = OXNAS_SYSCRTL_SIZE,
  31. .type = MT_DEVICE,
  32. },
  33. {
  34. .virtual = (unsigned long)OXNAS_SECCRTL_BASE_VA,
  35. .pfn = __phys_to_pfn(OXNAS_SECCRTL_BASE),
  36. .length = OXNAS_SECCRTL_SIZE,
  37. .type = MT_DEVICE,
  38. },
  39. {
  40. .virtual = (unsigned long)OXNAS_RPSA_BASE_VA,
  41. .pfn = __phys_to_pfn(OXNAS_RPSA_BASE),
  42. .length = OXNAS_RPSA_SIZE,
  43. .type = MT_DEVICE,
  44. },
  45. {
  46. .virtual = (unsigned long)OXNAS_RPSC_BASE_VA,
  47. .pfn = __phys_to_pfn(OXNAS_RPSC_BASE),
  48. .length = OXNAS_RPSC_SIZE,
  49. .type = MT_DEVICE,
  50. },
  51. };
  52. void __init ox820_map_common_io(void)
  53. {
  54. debug_ll_io_init();
  55. iotable_init(ox820_io_desc, ARRAY_SIZE(ox820_io_desc));
  56. }
  57. struct plat_gmac_data {
  58. struct plat_stmmacenet_data stmmac;
  59. struct clk *clk;
  60. };
  61. void *ox820_gmac_setup(struct platform_device *pdev)
  62. {
  63. struct plat_gmac_data *pdata = pdev->dev.platform_data;
  64. pdata->clk = clk_get(&pdev->dev, "gmac");
  65. return (void *) pdata->clk;
  66. };
  67. int ox820_gmac_init(struct platform_device *pdev, void *priv)
  68. {
  69. int ret;
  70. unsigned value;
  71. ret = device_reset(&pdev->dev);
  72. if (ret)
  73. return ret;
  74. if (IS_ERR(priv))
  75. return PTR_ERR(priv);
  76. clk_prepare_enable(priv);
  77. value = readl(SYS_CTRL_GMAC_CTRL);
  78. /* Enable GMII_GTXCLK to follow GMII_REFCLK, required for gigabit PHY */
  79. value |= BIT(SYS_CTRL_GMAC_CKEN_GTX);
  80. /* Use simple mux for 25/125 Mhz clock switching */
  81. value |= BIT(SYS_CTRL_GMAC_SIMPLE_MUX);
  82. /* set auto switch tx clock source */
  83. value |= BIT(SYS_CTRL_GMAC_AUTO_TX_SOURCE);
  84. /* enable tx & rx vardelay */
  85. value |= BIT(SYS_CTRL_GMAC_CKEN_TX_OUT);
  86. value |= BIT(SYS_CTRL_GMAC_CKEN_TXN_OUT);
  87. value |= BIT(SYS_CTRL_GMAC_CKEN_TX_IN);
  88. value |= BIT(SYS_CTRL_GMAC_CKEN_RX_OUT);
  89. value |= BIT(SYS_CTRL_GMAC_CKEN_RXN_OUT);
  90. value |= BIT(SYS_CTRL_GMAC_CKEN_RX_IN);
  91. writel(value, SYS_CTRL_GMAC_CTRL);
  92. /* set tx & rx vardelay */
  93. value = 0;
  94. value |= SYS_CTRL_GMAC_TX_VARDELAY(4);
  95. value |= SYS_CTRL_GMAC_TXN_VARDELAY(2);
  96. value |= SYS_CTRL_GMAC_RX_VARDELAY(10);
  97. value |= SYS_CTRL_GMAC_RXN_VARDELAY(8);
  98. writel(value, SYS_CTRL_GMAC_DELAY_CTRL);
  99. return 0;
  100. }
  101. void ox820_gmac_exit(struct platform_device *pdev, void *priv)
  102. {
  103. struct reset_control *rstc;
  104. clk_disable_unprepare(priv);
  105. clk_put(priv);
  106. rstc = reset_control_get(&pdev->dev, NULL);
  107. if (!IS_ERR(rstc)) {
  108. reset_control_assert(rstc);
  109. reset_control_put(rstc);
  110. }
  111. }
  112. static int __init ox820_ether_init(void)
  113. {
  114. struct device_node *node;
  115. struct platform_device *pdev;
  116. struct plat_gmac_data *pdata;
  117. node = of_find_compatible_node(NULL, NULL, "plxtech,nas782x-gmac");
  118. if (!node)
  119. return -ENOENT;
  120. pdev = of_find_device_by_node(node);
  121. of_node_put(node);
  122. if (!pdev)
  123. return -EINVAL;
  124. pdata = kzalloc(sizeof(struct plat_gmac_data), GFP_KERNEL);
  125. if (!pdata)
  126. return -ENOMEM;
  127. pdata->stmmac.setup = ox820_gmac_setup;
  128. pdata->stmmac.init = ox820_gmac_init;
  129. pdata->stmmac.exit = ox820_gmac_exit;
  130. pdev->dev.platform_data = pdata;
  131. return 0;
  132. }
  133. static void __init ox820_dt_init(void)
  134. {
  135. int ret;
  136. ret = of_platform_populate(NULL, of_default_bus_match_table, NULL,
  137. NULL);
  138. if (ret) {
  139. pr_err("of_platform_populate failed: %d\n", ret);
  140. BUG();
  141. }
  142. ret = ox820_ether_init();
  143. if (ret)
  144. pr_info("ox820_ether_init failed: %d\n", ret);
  145. }
  146. static void __init ox820_timer_init(void)
  147. {
  148. of_clk_init(NULL);
  149. clocksource_of_init();
  150. }
  151. void ox820_init_early(void)
  152. {
  153. }
  154. void ox820_assert_system_reset(enum reboot_mode mode, const char *cmd)
  155. {
  156. u32 value;
  157. /* Assert reset to cores as per power on defaults
  158. * Don't touch the DDR interface as things will come to an impromptu stop
  159. * NB Possibly should be asserting reset for PLLB, but there are timing
  160. * concerns here according to the docs */
  161. value = BIT(SYS_CTRL_RST_COPRO) |
  162. BIT(SYS_CTRL_RST_USBHS) |
  163. BIT(SYS_CTRL_RST_USBHSPHYA) |
  164. BIT(SYS_CTRL_RST_MACA) |
  165. BIT(SYS_CTRL_RST_PCIEA) |
  166. BIT(SYS_CTRL_RST_SGDMA) |
  167. BIT(SYS_CTRL_RST_CIPHER) |
  168. BIT(SYS_CTRL_RST_SATA) |
  169. BIT(SYS_CTRL_RST_SATA_LINK) |
  170. BIT(SYS_CTRL_RST_SATA_PHY) |
  171. BIT(SYS_CTRL_RST_PCIEPHY) |
  172. BIT(SYS_CTRL_RST_STATIC) |
  173. BIT(SYS_CTRL_RST_UART1) |
  174. BIT(SYS_CTRL_RST_UART2) |
  175. BIT(SYS_CTRL_RST_MISC) |
  176. BIT(SYS_CTRL_RST_I2S) |
  177. BIT(SYS_CTRL_RST_SD) |
  178. BIT(SYS_CTRL_RST_MACB) |
  179. BIT(SYS_CTRL_RST_PCIEB) |
  180. BIT(SYS_CTRL_RST_VIDEO) |
  181. BIT(SYS_CTRL_RST_USBHSPHYB) |
  182. BIT(SYS_CTRL_RST_USBDEV);
  183. writel(value, SYS_CTRL_RST_SET_CTRL);
  184. /* Release reset to cores as per power on defaults */
  185. writel(BIT(SYS_CTRL_RST_GPIO), SYS_CTRL_RST_CLR_CTRL);
  186. /* Disable clocks to cores as per power-on defaults - must leave DDR
  187. * related clocks enabled otherwise we'll stop rather abruptly. */
  188. value =
  189. BIT(SYS_CTRL_CLK_COPRO) |
  190. BIT(SYS_CTRL_CLK_DMA) |
  191. BIT(SYS_CTRL_CLK_CIPHER) |
  192. BIT(SYS_CTRL_CLK_SD) |
  193. BIT(SYS_CTRL_CLK_SATA) |
  194. BIT(SYS_CTRL_CLK_I2S) |
  195. BIT(SYS_CTRL_CLK_USBHS) |
  196. BIT(SYS_CTRL_CLK_MAC) |
  197. BIT(SYS_CTRL_CLK_PCIEA) |
  198. BIT(SYS_CTRL_CLK_STATIC) |
  199. BIT(SYS_CTRL_CLK_MACB) |
  200. BIT(SYS_CTRL_CLK_PCIEB) |
  201. BIT(SYS_CTRL_CLK_REF600) |
  202. BIT(SYS_CTRL_CLK_USBDEV);
  203. writel(value, SYS_CTRL_CLK_CLR_CTRL);
  204. /* Enable clocks to cores as per power-on defaults */
  205. /* Set sys-control pin mux'ing as per power-on defaults */
  206. writel(0, SYS_CTRL_SECONDARY_SEL);
  207. writel(0, SYS_CTRL_TERTIARY_SEL);
  208. writel(0, SYS_CTRL_QUATERNARY_SEL);
  209. writel(0, SYS_CTRL_DEBUG_SEL);
  210. writel(0, SYS_CTRL_ALTERNATIVE_SEL);
  211. writel(0, SYS_CTRL_PULLUP_SEL);
  212. writel(0, SYS_CTRL_SECONDARY_SEL);
  213. writel(0, SYS_CTRL_TERTIARY_SEL);
  214. writel(0, SYS_CTRL_QUATERNARY_SEL);
  215. writel(0, SYS_CTRL_DEBUG_SEL);
  216. writel(0, SYS_CTRL_ALTERNATIVE_SEL);
  217. writel(0, SYS_CTRL_PULLUP_SEL);
  218. /* No need to save any state, as the ROM loader can determine whether
  219. * reset is due to power cycling or programatic action, just hit the
  220. * (self-clearing) CPU reset bit of the block reset register */
  221. value =
  222. BIT(SYS_CTRL_RST_SCU) |
  223. BIT(SYS_CTRL_RST_ARM0) |
  224. BIT(SYS_CTRL_RST_ARM1);
  225. writel(value, SYS_CTRL_RST_SET_CTRL);
  226. }
  227. static const char * const ox820_dt_board_compat[] = {
  228. "plxtech,nas7820",
  229. "plxtech,nas7821",
  230. "plxtech,nas7825",
  231. NULL
  232. };
  233. DT_MACHINE_START(OX820_DT, "PLXTECH NAS782X SoC (Flattened Device Tree)")
  234. .map_io = ox820_map_common_io,
  235. .smp = smp_ops(ox820_smp_ops),
  236. .init_early = ox820_init_early,
  237. .init_time = ox820_timer_init,
  238. .init_machine = ox820_dt_init,
  239. .restart = ox820_assert_system_reset,
  240. .dt_compat = ox820_dt_board_compat,
  241. MACHINE_END