mach-imx6q.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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/clkdev.h>
  14. #include <linux/cpu.h>
  15. #include <linux/export.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/irq.h>
  19. #include <linux/irqchip.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/of_platform.h>
  24. #include <linux/pm_opp.h>
  25. #include <linux/phy.h>
  26. #include <linux/reboot.h>
  27. #include <linux/regmap.h>
  28. #include <linux/micrel_phy.h>
  29. #include <linux/mfd/syscon.h>
  30. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/system_misc.h>
  34. #include "common.h"
  35. #include "cpuidle.h"
  36. #include "hardware.h"
  37. /* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */
  38. static int ksz9021rn_phy_fixup(struct phy_device *phydev)
  39. {
  40. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  41. /* min rx data delay */
  42. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  43. 0x8000 | MICREL_KSZ9021_RGMII_RX_DATA_PAD_SCEW);
  44. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0x0000);
  45. /* max rx/tx clock delay, min rx/tx control delay */
  46. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  47. 0x8000 | MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  48. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0xf0f0);
  49. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  50. MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  51. }
  52. return 0;
  53. }
  54. static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
  55. {
  56. phy_write(dev, 0x0d, device);
  57. phy_write(dev, 0x0e, reg);
  58. phy_write(dev, 0x0d, (1 << 14) | device);
  59. phy_write(dev, 0x0e, val);
  60. }
  61. static int ksz9031rn_phy_fixup(struct phy_device *dev)
  62. {
  63. /*
  64. * min rx data delay, max rx/tx clock delay,
  65. * min rx/tx control delay
  66. */
  67. mmd_write_reg(dev, 2, 4, 0);
  68. mmd_write_reg(dev, 2, 5, 0);
  69. mmd_write_reg(dev, 2, 8, 0x003ff);
  70. return 0;
  71. }
  72. static int ar8031_phy_fixup(struct phy_device *dev)
  73. {
  74. u16 val;
  75. /* To enable AR8031 output a 125MHz clk from CLK_25M */
  76. phy_write(dev, 0xd, 0x7);
  77. phy_write(dev, 0xe, 0x8016);
  78. phy_write(dev, 0xd, 0x4007);
  79. val = phy_read(dev, 0xe);
  80. val &= 0xffe3;
  81. val |= 0x18;
  82. phy_write(dev, 0xe, val);
  83. /* introduce tx clock delay */
  84. phy_write(dev, 0x1d, 0x5);
  85. val = phy_read(dev, 0x1e);
  86. val |= 0x0100;
  87. phy_write(dev, 0x1e, val);
  88. return 0;
  89. }
  90. #define PHY_ID_AR8031 0x004dd074
  91. static void __init imx6q_enet_phy_init(void)
  92. {
  93. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  94. phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,
  95. ksz9021rn_phy_fixup);
  96. phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,
  97. ksz9031rn_phy_fixup);
  98. phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,
  99. ar8031_phy_fixup);
  100. }
  101. }
  102. static void __init imx6q_1588_init(void)
  103. {
  104. struct regmap *gpr;
  105. gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  106. if (!IS_ERR(gpr))
  107. regmap_update_bits(gpr, IOMUXC_GPR1,
  108. IMX6Q_GPR1_ENET_CLK_SEL_MASK,
  109. IMX6Q_GPR1_ENET_CLK_SEL_ANATOP);
  110. else
  111. pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
  112. }
  113. static void __init imx6q_init_machine(void)
  114. {
  115. struct device *parent;
  116. imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
  117. imx_get_soc_revision());
  118. mxc_arch_reset_init_dt();
  119. parent = imx_soc_device_init();
  120. if (parent == NULL)
  121. pr_warn("failed to initialize soc device\n");
  122. imx6q_enet_phy_init();
  123. of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
  124. imx_anatop_init();
  125. imx6q_pm_init();
  126. imx6q_1588_init();
  127. }
  128. #define OCOTP_CFG3 0x440
  129. #define OCOTP_CFG3_SPEED_SHIFT 16
  130. #define OCOTP_CFG3_SPEED_1P2GHZ 0x3
  131. static void __init imx6q_opp_check_1p2ghz(struct device *cpu_dev)
  132. {
  133. struct device_node *np;
  134. void __iomem *base;
  135. u32 val;
  136. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
  137. if (!np) {
  138. pr_warn("failed to find ocotp node\n");
  139. return;
  140. }
  141. base = of_iomap(np, 0);
  142. if (!base) {
  143. pr_warn("failed to map ocotp\n");
  144. goto put_node;
  145. }
  146. val = readl_relaxed(base + OCOTP_CFG3);
  147. val >>= OCOTP_CFG3_SPEED_SHIFT;
  148. if ((val & 0x3) != OCOTP_CFG3_SPEED_1P2GHZ)
  149. if (dev_pm_opp_disable(cpu_dev, 1200000000))
  150. pr_warn("failed to disable 1.2 GHz OPP\n");
  151. put_node:
  152. of_node_put(np);
  153. }
  154. static void __init imx6q_opp_init(void)
  155. {
  156. struct device_node *np;
  157. struct device *cpu_dev = get_cpu_device(0);
  158. if (!cpu_dev) {
  159. pr_warn("failed to get cpu0 device\n");
  160. return;
  161. }
  162. np = of_node_get(cpu_dev->of_node);
  163. if (!np) {
  164. pr_warn("failed to find cpu0 node\n");
  165. return;
  166. }
  167. if (of_init_opp_table(cpu_dev)) {
  168. pr_warn("failed to init OPP table\n");
  169. goto put_node;
  170. }
  171. imx6q_opp_check_1p2ghz(cpu_dev);
  172. put_node:
  173. of_node_put(np);
  174. }
  175. static struct platform_device imx6q_cpufreq_pdev = {
  176. .name = "imx6q-cpufreq",
  177. };
  178. static void __init imx6q_init_late(void)
  179. {
  180. /*
  181. * WAIT mode is broken on TO 1.0 and 1.1, so there is no point
  182. * to run cpuidle on them.
  183. */
  184. if (imx_get_soc_revision() > IMX_CHIP_REVISION_1_1)
  185. imx6q_cpuidle_init();
  186. if (IS_ENABLED(CONFIG_ARM_IMX6Q_CPUFREQ)) {
  187. imx6q_opp_init();
  188. platform_device_register(&imx6q_cpufreq_pdev);
  189. }
  190. }
  191. static void __init imx6q_map_io(void)
  192. {
  193. debug_ll_io_init();
  194. imx_scu_map_io();
  195. }
  196. static void __init imx6q_init_irq(void)
  197. {
  198. imx_init_revision_from_anatop();
  199. imx_init_l2cache();
  200. imx_src_init();
  201. imx_gpc_init();
  202. irqchip_init();
  203. }
  204. static const char *imx6q_dt_compat[] __initdata = {
  205. "fsl,imx6dl",
  206. "fsl,imx6q",
  207. NULL,
  208. };
  209. DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
  210. .smp = smp_ops(imx_smp_ops),
  211. .map_io = imx6q_map_io,
  212. .init_irq = imx6q_init_irq,
  213. .init_machine = imx6q_init_machine,
  214. .init_late = imx6q_init_late,
  215. .dt_compat = imx6q_dt_compat,
  216. .restart = mxc_restart,
  217. MACHINE_END