mach-imx6q.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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/pm_opp.h>
  26. #include <linux/pci.h>
  27. #include <linux/phy.h>
  28. #include <linux/reboot.h>
  29. #include <linux/regmap.h>
  30. #include <linux/micrel_phy.h>
  31. #include <linux/mfd/syscon.h>
  32. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  33. #include <linux/fec.h>
  34. #include <linux/netdevice.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/system_misc.h>
  38. #include "common.h"
  39. #include "cpuidle.h"
  40. #include "hardware.h"
  41. static struct fec_platform_data fec_pdata;
  42. static void imx6q_fec_sleep_enable(int enabled)
  43. {
  44. struct regmap *gpr;
  45. gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  46. if (!IS_ERR(gpr)) {
  47. if (enabled)
  48. regmap_update_bits(gpr, IOMUXC_GPR13,
  49. IMX6Q_GPR13_ENET_STOP_REQ,
  50. IMX6Q_GPR13_ENET_STOP_REQ);
  51. else
  52. regmap_update_bits(gpr, IOMUXC_GPR13,
  53. IMX6Q_GPR13_ENET_STOP_REQ, 0);
  54. } else
  55. pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
  56. }
  57. static void __init imx6q_enet_plt_init(void)
  58. {
  59. struct device_node *np;
  60. np = of_find_node_by_path("/soc/aips-bus@02100000/ethernet@02188000");
  61. if (np && of_get_property(np, "fsl,magic-packet", NULL))
  62. fec_pdata.sleep_mode_enable = imx6q_fec_sleep_enable;
  63. }
  64. /* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */
  65. static int ksz9021rn_phy_fixup(struct phy_device *phydev)
  66. {
  67. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  68. /* min rx data delay */
  69. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  70. 0x8000 | MICREL_KSZ9021_RGMII_RX_DATA_PAD_SCEW);
  71. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0x0000);
  72. /* max rx/tx clock delay, min rx/tx control delay */
  73. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  74. 0x8000 | MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  75. phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0xf0f0);
  76. phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
  77. MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
  78. }
  79. return 0;
  80. }
  81. static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
  82. {
  83. phy_write(dev, 0x0d, device);
  84. phy_write(dev, 0x0e, reg);
  85. phy_write(dev, 0x0d, (1 << 14) | device);
  86. phy_write(dev, 0x0e, val);
  87. }
  88. static int ksz9031rn_phy_fixup(struct phy_device *dev)
  89. {
  90. /*
  91. * min rx data delay, max rx/tx clock delay,
  92. * min rx/tx control delay
  93. */
  94. mmd_write_reg(dev, 2, 4, 0);
  95. mmd_write_reg(dev, 2, 5, 0);
  96. mmd_write_reg(dev, 2, 8, 0x003ff);
  97. return 0;
  98. }
  99. /*
  100. * fixup for PLX PEX8909 bridge to configure GPIO1-7 as output High
  101. * as they are used for slots1-7 PERST#
  102. */
  103. static void ventana_pciesw_early_fixup(struct pci_dev *dev)
  104. {
  105. u32 dw;
  106. if (!of_machine_is_compatible("gw,ventana"))
  107. return;
  108. if (dev->devfn != 0)
  109. return;
  110. pci_read_config_dword(dev, 0x62c, &dw);
  111. dw |= 0xaaa8; // GPIO1-7 outputs
  112. pci_write_config_dword(dev, 0x62c, dw);
  113. pci_read_config_dword(dev, 0x644, &dw);
  114. dw |= 0xfe; // GPIO1-7 output high
  115. pci_write_config_dword(dev, 0x644, dw);
  116. msleep(100);
  117. }
  118. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8609, ventana_pciesw_early_fixup);
  119. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8606, ventana_pciesw_early_fixup);
  120. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8604, ventana_pciesw_early_fixup);
  121. static int ar8031_phy_fixup(struct phy_device *dev)
  122. {
  123. u16 val;
  124. /* To enable AR8031 output a 125MHz clk from CLK_25M */
  125. phy_write(dev, 0xd, 0x7);
  126. phy_write(dev, 0xe, 0x8016);
  127. phy_write(dev, 0xd, 0x4007);
  128. val = phy_read(dev, 0xe);
  129. val &= 0xffe3;
  130. val |= 0x18;
  131. phy_write(dev, 0xe, val);
  132. /* introduce tx clock delay */
  133. phy_write(dev, 0x1d, 0x5);
  134. val = phy_read(dev, 0x1e);
  135. val |= 0x0100;
  136. phy_write(dev, 0x1e, val);
  137. return 0;
  138. }
  139. #define PHY_ID_AR8031 0x004dd074
  140. static int ar8035_phy_fixup(struct phy_device *dev)
  141. {
  142. u16 val;
  143. /* Ar803x phy SmartEEE feature cause link status generates glitch,
  144. * which cause ethernet link down/up issue, so disable SmartEEE
  145. */
  146. phy_write(dev, 0xd, 0x3);
  147. phy_write(dev, 0xe, 0x805d);
  148. phy_write(dev, 0xd, 0x4003);
  149. val = phy_read(dev, 0xe);
  150. phy_write(dev, 0xe, val & ~(1 << 8));
  151. /*
  152. * Enable 125MHz clock from CLK_25M on the AR8031. This
  153. * is fed in to the IMX6 on the ENET_REF_CLK (V22) pad.
  154. * Also, introduce a tx clock delay.
  155. *
  156. * This is the same as is the AR8031 fixup.
  157. */
  158. ar8031_phy_fixup(dev);
  159. /*check phy power*/
  160. val = phy_read(dev, 0x0);
  161. if (val & BMCR_PDOWN)
  162. phy_write(dev, 0x0, val & ~BMCR_PDOWN);
  163. return 0;
  164. }
  165. #define PHY_ID_AR8035 0x004dd072
  166. static void __init imx6q_enet_phy_init(void)
  167. {
  168. if (IS_BUILTIN(CONFIG_PHYLIB)) {
  169. phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,
  170. ksz9021rn_phy_fixup);
  171. phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,
  172. ksz9031rn_phy_fixup);
  173. phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,
  174. ar8031_phy_fixup);
  175. phy_register_fixup_for_uid(PHY_ID_AR8035, 0xffffffef,
  176. ar8035_phy_fixup);
  177. }
  178. }
  179. static void __init imx6q_1588_init(void)
  180. {
  181. struct device_node *np;
  182. struct clk *ptp_clk;
  183. struct clk *enet_ref;
  184. struct regmap *gpr;
  185. u32 clksel;
  186. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-fec");
  187. if (!np) {
  188. pr_warn("%s: failed to find fec node\n", __func__);
  189. return;
  190. }
  191. ptp_clk = of_clk_get(np, 2);
  192. if (IS_ERR(ptp_clk)) {
  193. pr_warn("%s: failed to get ptp clock\n", __func__);
  194. goto put_node;
  195. }
  196. enet_ref = clk_get_sys(NULL, "enet_ref");
  197. if (IS_ERR(enet_ref)) {
  198. pr_warn("%s: failed to get enet clock\n", __func__);
  199. goto put_ptp_clk;
  200. }
  201. /*
  202. * If enet_ref from ANATOP/CCM is the PTP clock source, we need to
  203. * set bit IOMUXC_GPR1[21]. Or the PTP clock must be from pad
  204. * (external OSC), and we need to clear the bit.
  205. */
  206. clksel = ptp_clk == enet_ref ? IMX6Q_GPR1_ENET_CLK_SEL_ANATOP :
  207. IMX6Q_GPR1_ENET_CLK_SEL_PAD;
  208. gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  209. if (!IS_ERR(gpr))
  210. regmap_update_bits(gpr, IOMUXC_GPR1,
  211. IMX6Q_GPR1_ENET_CLK_SEL_MASK,
  212. clksel);
  213. else
  214. pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
  215. clk_put(enet_ref);
  216. put_ptp_clk:
  217. clk_put(ptp_clk);
  218. put_node:
  219. of_node_put(np);
  220. }
  221. static void __init imx6q_axi_init(void)
  222. {
  223. struct regmap *gpr;
  224. unsigned int mask;
  225. gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  226. if (!IS_ERR(gpr)) {
  227. /*
  228. * Enable the cacheable attribute of VPU and IPU
  229. * AXI transactions.
  230. */
  231. mask = IMX6Q_GPR4_VPU_WR_CACHE_SEL |
  232. IMX6Q_GPR4_VPU_RD_CACHE_SEL |
  233. IMX6Q_GPR4_VPU_P_WR_CACHE_VAL |
  234. IMX6Q_GPR4_VPU_P_RD_CACHE_VAL_MASK |
  235. IMX6Q_GPR4_IPU_WR_CACHE_CTL |
  236. IMX6Q_GPR4_IPU_RD_CACHE_CTL;
  237. regmap_update_bits(gpr, IOMUXC_GPR4, mask, mask);
  238. /* Increase IPU read QoS priority */
  239. regmap_update_bits(gpr, IOMUXC_GPR6,
  240. IMX6Q_GPR6_IPU1_ID00_RD_QOS_MASK |
  241. IMX6Q_GPR6_IPU1_ID01_RD_QOS_MASK,
  242. (0xf << 16) | (0x7 << 20));
  243. regmap_update_bits(gpr, IOMUXC_GPR7,
  244. IMX6Q_GPR7_IPU2_ID00_RD_QOS_MASK |
  245. IMX6Q_GPR7_IPU2_ID01_RD_QOS_MASK,
  246. (0xf << 16) | (0x7 << 20));
  247. } else {
  248. pr_warn("failed to find fsl,imx6q-iomuxc-gpr regmap\n");
  249. }
  250. }
  251. /* Add auxdata to pass platform data */
  252. static const struct of_dev_auxdata imx6q_auxdata_lookup[] __initconst = {
  253. OF_DEV_AUXDATA("fsl,imx6q-fec", 0x02188000, NULL, &fec_pdata),
  254. { /* sentinel */ }
  255. };
  256. static void __init imx6q_init_machine(void)
  257. {
  258. struct device *parent;
  259. imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
  260. imx_get_soc_revision());
  261. parent = imx_soc_device_init();
  262. if (parent == NULL)
  263. pr_warn("failed to initialize soc device\n");
  264. imx6q_enet_phy_init();
  265. of_platform_populate(NULL, of_default_bus_match_table,
  266. imx6q_auxdata_lookup, parent);
  267. imx_anatop_init();
  268. cpu_is_imx6q() ? imx6q_pm_init() : imx6dl_pm_init();
  269. imx6q_1588_init();
  270. imx6q_enet_plt_init();
  271. imx6q_axi_init();
  272. }
  273. #define OCOTP_CFG3 0x440
  274. #define OCOTP_CFG3_SPEED_SHIFT 16
  275. #define OCOTP_CFG3_SPEED_1P2GHZ 0x3
  276. #define OCOTP_CFG3_SPEED_996MHZ 0x2
  277. #define OCOTP_CFG3_SPEED_852MHZ 0x1
  278. static void __init imx6q_opp_check_speed_grading(struct device *cpu_dev)
  279. {
  280. struct device_node *np;
  281. void __iomem *base;
  282. u32 val;
  283. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
  284. if (!np) {
  285. pr_warn("failed to find ocotp node\n");
  286. return;
  287. }
  288. base = of_iomap(np, 0);
  289. if (!base) {
  290. pr_warn("failed to map ocotp\n");
  291. goto put_node;
  292. }
  293. /*
  294. * SPEED_GRADING[1:0] defines the max speed of ARM:
  295. * 2b'11: 1200000000Hz;
  296. * 2b'10: 996000000Hz;
  297. * 2b'01: 852000000Hz; -- i.MX6Q Only, exclusive with 996MHz.
  298. * 2b'00: 792000000Hz;
  299. * We need to set the max speed of ARM according to fuse map.
  300. */
  301. val = readl_relaxed(base + OCOTP_CFG3);
  302. val >>= OCOTP_CFG3_SPEED_SHIFT;
  303. val &= 0x3;
  304. if ((val != OCOTP_CFG3_SPEED_1P2GHZ) && cpu_is_imx6q())
  305. if (dev_pm_opp_disable(cpu_dev, 1200000000))
  306. pr_warn("failed to disable 1.2 GHz OPP\n");
  307. if (val < OCOTP_CFG3_SPEED_996MHZ)
  308. if (dev_pm_opp_disable(cpu_dev, 996000000))
  309. pr_warn("failed to disable 996 MHz OPP\n");
  310. if (cpu_is_imx6q()) {
  311. if (val != OCOTP_CFG3_SPEED_852MHZ)
  312. if (dev_pm_opp_disable(cpu_dev, 852000000))
  313. pr_warn("failed to disable 852 MHz OPP\n");
  314. }
  315. put_node:
  316. of_node_put(np);
  317. }
  318. static void __init imx6q_opp_init(void)
  319. {
  320. struct device_node *np;
  321. struct device *cpu_dev = get_cpu_device(0);
  322. if (!cpu_dev) {
  323. pr_warn("failed to get cpu0 device\n");
  324. return;
  325. }
  326. np = of_node_get(cpu_dev->of_node);
  327. if (!np) {
  328. pr_warn("failed to find cpu0 node\n");
  329. return;
  330. }
  331. if (of_init_opp_table(cpu_dev)) {
  332. pr_warn("failed to init OPP table\n");
  333. goto put_node;
  334. }
  335. imx6q_opp_check_speed_grading(cpu_dev);
  336. put_node:
  337. of_node_put(np);
  338. }
  339. static struct platform_device imx6q_cpufreq_pdev = {
  340. .name = "imx6q-cpufreq",
  341. };
  342. static void __init imx6q_init_late(void)
  343. {
  344. /*
  345. * WAIT mode is broken on TO 1.0 and 1.1, so there is no point
  346. * to run cpuidle on them.
  347. */
  348. if (imx_get_soc_revision() > IMX_CHIP_REVISION_1_1)
  349. imx6q_cpuidle_init();
  350. if (IS_ENABLED(CONFIG_ARM_IMX6Q_CPUFREQ)) {
  351. imx6q_opp_init();
  352. platform_device_register(&imx6q_cpufreq_pdev);
  353. }
  354. }
  355. static void __init imx6q_map_io(void)
  356. {
  357. debug_ll_io_init();
  358. imx_scu_map_io();
  359. }
  360. static void __init imx6q_init_irq(void)
  361. {
  362. imx_init_revision_from_anatop();
  363. imx_init_l2cache();
  364. imx_src_init();
  365. imx_gpc_init();
  366. irqchip_init();
  367. }
  368. static const char * const imx6q_dt_compat[] __initconst = {
  369. "fsl,imx6dl",
  370. "fsl,imx6q",
  371. NULL,
  372. };
  373. DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
  374. .smp = smp_ops(imx_smp_ops),
  375. .map_io = imx6q_map_io,
  376. .init_irq = imx6q_init_irq,
  377. .init_machine = imx6q_init_machine,
  378. .init_late = imx6q_init_late,
  379. .dt_compat = imx6q_dt_compat,
  380. MACHINE_END