mach-imx6q.c 10 KB

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