mach-imx6q.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright 2011-2013 Freescale Semiconductor, Inc.
  3. * Copyright 2011 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/clk-provider.h>
  14. #include <linux/clkdev.h>
  15. #include <linux/clocksource.h>
  16. #include <linux/cpu.h>
  17. #include <linux/delay.h>
  18. #include <linux/export.h>
  19. #include <linux/init.h>
  20. #include <linux/io.h>
  21. #include <linux/irq.h>
  22. #include <linux/irqchip.h>
  23. #include <linux/of.h>
  24. #include <linux/of_address.h>
  25. #include <linux/of_irq.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/opp.h>
  28. #include <linux/phy.h>
  29. #include <linux/reboot.h>
  30. #include <linux/regmap.h>
  31. #include <linux/micrel_phy.h>
  32. #include <linux/mfd/syscon.h>
  33. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  34. #include <asm/mach/arch.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/system_misc.h>
  37. #include "common.h"
  38. #include "cpuidle.h"
  39. #include "hardware.h"
  40. static u32 chip_revision;
  41. int imx6q_revision(void)
  42. {
  43. return chip_revision;
  44. }
  45. static void __init imx6q_init_revision(void)
  46. {
  47. u32 rev = imx_anatop_get_digprog();
  48. switch (rev & 0xff) {
  49. case 0:
  50. chip_revision = IMX_CHIP_REVISION_1_0;
  51. break;
  52. case 1:
  53. chip_revision = IMX_CHIP_REVISION_1_1;
  54. break;
  55. case 2:
  56. chip_revision = IMX_CHIP_REVISION_1_2;
  57. break;
  58. default:
  59. chip_revision = IMX_CHIP_REVISION_UNKNOWN;
  60. }
  61. mxc_set_cpu_type(rev >> 16 & 0xff);
  62. }
  63. static void imx6q_restart(enum reboot_mode mode, const char *cmd)
  64. {
  65. struct device_node *np;
  66. void __iomem *wdog_base;
  67. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-wdt");
  68. wdog_base = of_iomap(np, 0);
  69. if (!wdog_base)
  70. goto soft;
  71. imx_src_prepare_restart();
  72. /* enable wdog */
  73. writew_relaxed(1 << 2, wdog_base);
  74. /* write twice to ensure the request will not get ignored */
  75. writew_relaxed(1 << 2, wdog_base);
  76. /* wait for reset to assert ... */
  77. mdelay(500);
  78. pr_err("Watchdog reset failed to assert reset\n");
  79. /* delay to allow the serial port to show the message */
  80. mdelay(50);
  81. soft:
  82. /* we'll take a jump through zero as a poor second */
  83. soft_restart(0);
  84. }
  85. /* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */
  86. static int ksz9021rn_phy_fixup(struct phy_device *phydev)
  87. {
  88. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  89. /* min rx data delay */
  90. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  91. 0x8000 | MICREL_KSZ9021_RGMII_RX_DATA_PAD_SCEW);
  92. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0x0000);
  93. /* max rx/tx clock delay, min rx/tx control delay */
  94. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  95. 0x8000 | MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  96. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0xf0f0);
  97. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  98. MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  99. }
  100. return 0;
  101. }
  102. static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
  103. {
  104. phy_write(dev, 0x0d, device);
  105. phy_write(dev, 0x0e, reg);
  106. phy_write(dev, 0x0d, (1 << 14) | device);
  107. phy_write(dev, 0x0e, val);
  108. }
  109. static int ksz9031rn_phy_fixup(struct phy_device *dev)
  110. {
  111. /*
  112. * min rx data delay, max rx/tx clock delay,
  113. * min rx/tx control delay
  114. */
  115. mmd_write_reg(dev, 2, 4, 0);
  116. mmd_write_reg(dev, 2, 5, 0);
  117. mmd_write_reg(dev, 2, 8, 0x003ff);
  118. return 0;
  119. }
  120. static int ar8031_phy_fixup(struct phy_device *dev)
  121. {
  122. u16 val;
  123. /* To enable AR8031 output a 125MHz clk from CLK_25M */
  124. phy_write(dev, 0xd, 0x7);
  125. phy_write(dev, 0xe, 0x8016);
  126. phy_write(dev, 0xd, 0x4007);
  127. val = phy_read(dev, 0xe);
  128. val &= 0xffe3;
  129. val |= 0x18;
  130. phy_write(dev, 0xe, val);
  131. /* introduce tx clock delay */
  132. phy_write(dev, 0x1d, 0x5);
  133. val = phy_read(dev, 0x1e);
  134. val |= 0x0100;
  135. phy_write(dev, 0x1e, val);
  136. return 0;
  137. }
  138. #define PHY_ID_AR8031 0x004dd074
  139. static void __init imx6q_enet_phy_init(void)
  140. {
  141. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  142. phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,
  143. ksz9021rn_phy_fixup);
  144. phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,
  145. ksz9031rn_phy_fixup);
  146. phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,
  147. ar8031_phy_fixup);
  148. }
  149. }
  150. static void __init imx6q_1588_init(void)
  151. {
  152. struct regmap *gpr;
  153. gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  154. if (!IS_ERR(gpr))
  155. regmap_update_bits(gpr, IOMUXC_GPR1,
  156. IMX6Q_GPR1_ENET_CLK_SEL_MASK,
  157. IMX6Q_GPR1_ENET_CLK_SEL_ANATOP);
  158. else
  159. pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
  160. }
  161. static void __init imx6q_init_machine(void)
  162. {
  163. imx6q_enet_phy_init();
  164. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  165. imx_anatop_init();
  166. imx6q_pm_init();
  167. imx6q_1588_init();
  168. }
  169. #define OCOTP_CFG3 0x440
  170. #define OCOTP_CFG3_SPEED_SHIFT 16
  171. #define OCOTP_CFG3_SPEED_1P2GHZ 0x3
  172. static void __init imx6q_opp_check_1p2ghz(struct device *cpu_dev)
  173. {
  174. struct device_node *np;
  175. void __iomem *base;
  176. u32 val;
  177. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
  178. if (!np) {
  179. pr_warn("failed to find ocotp node\n");
  180. return;
  181. }
  182. base = of_iomap(np, 0);
  183. if (!base) {
  184. pr_warn("failed to map ocotp\n");
  185. goto put_node;
  186. }
  187. val = readl_relaxed(base + OCOTP_CFG3);
  188. val >>= OCOTP_CFG3_SPEED_SHIFT;
  189. if ((val & 0x3) != OCOTP_CFG3_SPEED_1P2GHZ)
  190. if (opp_disable(cpu_dev, 1200000000))
  191. pr_warn("failed to disable 1.2 GHz OPP\n");
  192. put_node:
  193. of_node_put(np);
  194. }
  195. static void __init imx6q_opp_init(void)
  196. {
  197. struct device_node *np;
  198. struct device *cpu_dev = get_cpu_device(0);
  199. if (!cpu_dev) {
  200. pr_warn("failed to get cpu0 device\n");
  201. return;
  202. }
  203. np = of_node_get(cpu_dev->of_node);
  204. if (!np) {
  205. pr_warn("failed to find cpu0 node\n");
  206. return;
  207. }
  208. if (of_init_opp_table(cpu_dev)) {
  209. pr_warn("failed to init OPP table\n");
  210. goto put_node;
  211. }
  212. imx6q_opp_check_1p2ghz(cpu_dev);
  213. put_node:
  214. of_node_put(np);
  215. }
  216. static struct platform_device imx6q_cpufreq_pdev = {
  217. .name = "imx6q-cpufreq",
  218. };
  219. static void __init imx6q_init_late(void)
  220. {
  221. /*
  222. * WAIT mode is broken on TO 1.0 and 1.1, so there is no point
  223. * to run cpuidle on them.
  224. */
  225. if (imx6q_revision() > IMX_CHIP_REVISION_1_1)
  226. imx6q_cpuidle_init();
  227. if (IS_ENABLED(CONFIG_ARM_IMX6Q_CPUFREQ)) {
  228. imx6q_opp_init();
  229. platform_device_register(&imx6q_cpufreq_pdev);
  230. }
  231. }
  232. static void __init imx6q_map_io(void)
  233. {
  234. debug_ll_io_init();
  235. imx_scu_map_io();
  236. }
  237. static void __init imx6q_init_irq(void)
  238. {
  239. imx6q_init_revision();
  240. imx_init_l2cache();
  241. imx_src_init();
  242. imx_gpc_init();
  243. irqchip_init();
  244. }
  245. static void __init imx6q_timer_init(void)
  246. {
  247. of_clk_init(NULL);
  248. clocksource_of_init();
  249. imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
  250. imx6q_revision());
  251. }
  252. static const char *imx6q_dt_compat[] __initdata = {
  253. "fsl,imx6dl",
  254. "fsl,imx6q",
  255. NULL,
  256. };
  257. DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
  258. .smp = smp_ops(imx_smp_ops),
  259. .map_io = imx6q_map_io,
  260. .init_irq = imx6q_init_irq,
  261. .init_time = imx6q_timer_init,
  262. .init_machine = imx6q_init_machine,
  263. .init_late = imx6q_init_late,
  264. .dt_compat = imx6q_dt_compat,
  265. .restart = imx6q_restart,
  266. MACHINE_END