mach-imx6q.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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/delay.h>
  16. #include <linux/export.h>
  17. #include <linux/init.h>
  18. #include <linux/io.h>
  19. #include <linux/irq.h>
  20. #include <linux/irqchip.h>
  21. #include <linux/of.h>
  22. #include <linux/of_address.h>
  23. #include <linux/of_irq.h>
  24. #include <linux/of_platform.h>
  25. #include <linux/opp.h>
  26. #include <linux/phy.h>
  27. #include <linux/reboot.h>
  28. #include <linux/regmap.h>
  29. #include <linux/micrel_phy.h>
  30. #include <linux/mfd/syscon.h>
  31. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/map.h>
  34. #include <asm/system_misc.h>
  35. #include "common.h"
  36. #include "cpuidle.h"
  37. #include "hardware.h"
  38. static u32 chip_revision;
  39. int imx6q_revision(void)
  40. {
  41. return chip_revision;
  42. }
  43. static void __init imx6q_init_revision(void)
  44. {
  45. u32 rev = imx_anatop_get_digprog();
  46. switch (rev & 0xff) {
  47. case 0:
  48. chip_revision = IMX_CHIP_REVISION_1_0;
  49. break;
  50. case 1:
  51. chip_revision = IMX_CHIP_REVISION_1_1;
  52. break;
  53. case 2:
  54. chip_revision = IMX_CHIP_REVISION_1_2;
  55. break;
  56. default:
  57. chip_revision = IMX_CHIP_REVISION_UNKNOWN;
  58. }
  59. mxc_set_cpu_type(rev >> 16 & 0xff);
  60. }
  61. static void imx6q_restart(enum reboot_mode mode, const char *cmd)
  62. {
  63. struct device_node *np;
  64. void __iomem *wdog_base;
  65. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-wdt");
  66. wdog_base = of_iomap(np, 0);
  67. if (!wdog_base)
  68. goto soft;
  69. imx_src_prepare_restart();
  70. /* enable wdog */
  71. writew_relaxed(1 << 2, wdog_base);
  72. /* write twice to ensure the request will not get ignored */
  73. writew_relaxed(1 << 2, wdog_base);
  74. /* wait for reset to assert ... */
  75. mdelay(500);
  76. pr_err("Watchdog reset failed to assert reset\n");
  77. /* delay to allow the serial port to show the message */
  78. mdelay(50);
  79. soft:
  80. /* we'll take a jump through zero as a poor second */
  81. soft_restart(0);
  82. }
  83. /* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */
  84. static int ksz9021rn_phy_fixup(struct phy_device *phydev)
  85. {
  86. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  87. /* min rx data delay */
  88. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  89. 0x8000 | MICREL_KSZ9021_RGMII_RX_DATA_PAD_SCEW);
  90. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0x0000);
  91. /* max rx/tx clock delay, min rx/tx control delay */
  92. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  93. 0x8000 | MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  94. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0xf0f0);
  95. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  96. MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  97. }
  98. return 0;
  99. }
  100. static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
  101. {
  102. phy_write(dev, 0x0d, device);
  103. phy_write(dev, 0x0e, reg);
  104. phy_write(dev, 0x0d, (1 << 14) | device);
  105. phy_write(dev, 0x0e, val);
  106. }
  107. static int ksz9031rn_phy_fixup(struct phy_device *dev)
  108. {
  109. /*
  110. * min rx data delay, max rx/tx clock delay,
  111. * min rx/tx control delay
  112. */
  113. mmd_write_reg(dev, 2, 4, 0);
  114. mmd_write_reg(dev, 2, 5, 0);
  115. mmd_write_reg(dev, 2, 8, 0x003ff);
  116. return 0;
  117. }
  118. static int ar8031_phy_fixup(struct phy_device *dev)
  119. {
  120. u16 val;
  121. /* To enable AR8031 output a 125MHz clk from CLK_25M */
  122. phy_write(dev, 0xd, 0x7);
  123. phy_write(dev, 0xe, 0x8016);
  124. phy_write(dev, 0xd, 0x4007);
  125. val = phy_read(dev, 0xe);
  126. val &= 0xffe3;
  127. val |= 0x18;
  128. phy_write(dev, 0xe, val);
  129. /* introduce tx clock delay */
  130. phy_write(dev, 0x1d, 0x5);
  131. val = phy_read(dev, 0x1e);
  132. val |= 0x0100;
  133. phy_write(dev, 0x1e, val);
  134. return 0;
  135. }
  136. #define PHY_ID_AR8031 0x004dd074
  137. static void __init imx6q_enet_phy_init(void)
  138. {
  139. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  140. phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,
  141. ksz9021rn_phy_fixup);
  142. phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,
  143. ksz9031rn_phy_fixup);
  144. phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,
  145. ar8031_phy_fixup);
  146. }
  147. }
  148. static void __init imx6q_1588_init(void)
  149. {
  150. struct regmap *gpr;
  151. gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  152. if (!IS_ERR(gpr))
  153. regmap_update_bits(gpr, IOMUXC_GPR1,
  154. IMX6Q_GPR1_ENET_CLK_SEL_MASK,
  155. IMX6Q_GPR1_ENET_CLK_SEL_ANATOP);
  156. else
  157. pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
  158. }
  159. static void __init imx6q_init_machine(void)
  160. {
  161. imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
  162. imx6q_revision());
  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 const char *imx6q_dt_compat[] __initdata = {
  246. "fsl,imx6dl",
  247. "fsl,imx6q",
  248. NULL,
  249. };
  250. DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
  251. .smp = smp_ops(imx_smp_ops),
  252. .map_io = imx6q_map_io,
  253. .init_irq = imx6q_init_irq,
  254. .init_machine = imx6q_init_machine,
  255. .init_late = imx6q_init_late,
  256. .dt_compat = imx6q_dt_compat,
  257. .restart = imx6q_restart,
  258. MACHINE_END