2 * Copyright 2011-2013 Freescale Semiconductor, Inc.
3 * Copyright 2011 Linaro Ltd.
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:
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
13 #include <linux/clk.h>
14 #include <linux/clkdev.h>
15 #include <linux/cpu.h>
16 #include <linux/delay.h>
17 #include <linux/export.h>
18 #include <linux/gpio.h>
19 #include <linux/init.h>
21 #include <linux/irq.h>
22 #include <linux/irqchip.h>
24 #include <linux/of_address.h>
25 #include <linux/of_irq.h>
26 #include <linux/of_gpio.h>
27 #include <linux/of_platform.h>
28 #include <linux/pm_opp.h>
29 #include <linux/pci.h>
30 #include <linux/phy.h>
31 #include <linux/reboot.h>
32 #include <linux/regmap.h>
33 #include <linux/micrel_phy.h>
34 #include <linux/mfd/syscon.h>
35 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/map.h>
38 #include <asm/system_misc.h>
44 /* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */
45 static int ksz9021rn_phy_fixup(struct phy_device *phydev)
47 if (IS_BUILTIN(CONFIG_PHYLIB)) {
48 /* min rx data delay */
49 phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
50 0x8000 | MICREL_KSZ9021_RGMII_RX_DATA_PAD_SCEW);
51 phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0x0000);
53 /* max rx/tx clock delay, min rx/tx control delay */
54 phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
55 0x8000 | MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
56 phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0xf0f0);
57 phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
58 MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW);
64 static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
66 phy_write(dev, 0x0d, device);
67 phy_write(dev, 0x0e, reg);
68 phy_write(dev, 0x0d, (1 << 14) | device);
69 phy_write(dev, 0x0e, val);
72 static int ksz9031rn_phy_fixup(struct phy_device *dev)
75 * min rx data delay, max rx/tx clock delay,
76 * min rx/tx control delay
78 mmd_write_reg(dev, 2, 4, 0);
79 mmd_write_reg(dev, 2, 5, 0);
80 mmd_write_reg(dev, 2, 8, 0x003ff);
86 * fixup for PLX PEX8909 bridge to configure GPIO1-7 as output High
87 * as they are used for slots1-7 PERST#
89 static void ventana_pciesw_early_fixup(struct pci_dev *dev)
93 if (!of_machine_is_compatible("gw,ventana"))
99 pci_read_config_dword(dev, 0x62c, &dw);
100 dw |= 0xaaa8; // GPIO1-7 outputs
101 pci_write_config_dword(dev, 0x62c, dw);
103 pci_read_config_dword(dev, 0x644, &dw);
104 dw |= 0xfe; // GPIO1-7 output high
105 pci_write_config_dword(dev, 0x644, dw);
109 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8609, ventana_pciesw_early_fixup);
110 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8606, ventana_pciesw_early_fixup);
111 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8604, ventana_pciesw_early_fixup);
113 static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
115 phy_write(dev, 0x0d, device);
116 phy_write(dev, 0x0e, reg);
117 phy_write(dev, 0x0d, (1 << 14) | device);
118 phy_write(dev, 0x0e, val);
121 static int ksz9031rn_phy_fixup(struct phy_device *dev)
124 * min rx data delay, max rx/tx clock delay,
125 * min rx/tx control delay
127 mmd_write_reg(dev, 2, 4, 0);
128 mmd_write_reg(dev, 2, 5, 0);
129 mmd_write_reg(dev, 2, 8, 0x003ff);
134 static int ar8031_phy_fixup(struct phy_device *dev)
138 /* To enable AR8031 output a 125MHz clk from CLK_25M */
139 phy_write(dev, 0xd, 0x7);
140 phy_write(dev, 0xe, 0x8016);
141 phy_write(dev, 0xd, 0x4007);
143 val = phy_read(dev, 0xe);
146 phy_write(dev, 0xe, val);
148 /* introduce tx clock delay */
149 phy_write(dev, 0x1d, 0x5);
150 val = phy_read(dev, 0x1e);
152 phy_write(dev, 0x1e, val);
157 #define PHY_ID_AR8031 0x004dd074
159 static int ar8035_phy_fixup(struct phy_device *dev)
163 /* Ar803x phy SmartEEE feature cause link status generates glitch,
164 * which cause ethernet link down/up issue, so disable SmartEEE
166 phy_write(dev, 0xd, 0x3);
167 phy_write(dev, 0xe, 0x805d);
168 phy_write(dev, 0xd, 0x4003);
170 val = phy_read(dev, 0xe);
171 phy_write(dev, 0xe, val & ~(1 << 8));
174 * Enable 125MHz clock from CLK_25M on the AR8031. This
175 * is fed in to the IMX6 on the ENET_REF_CLK (V22) pad.
176 * Also, introduce a tx clock delay.
178 * This is the same as is the AR8031 fixup.
180 ar8031_phy_fixup(dev);
183 val = phy_read(dev, 0x0);
184 if (val & BMCR_PDOWN)
185 phy_write(dev, 0x0, val & ~BMCR_PDOWN);
190 #define PHY_ID_AR8035 0x004dd072
192 static void __init imx6q_enet_phy_init(void)
194 if (IS_BUILTIN(CONFIG_PHYLIB)) {
195 phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,
196 ksz9021rn_phy_fixup);
197 phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,
198 ksz9031rn_phy_fixup);
199 phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,
201 phy_register_fixup_for_uid(PHY_ID_AR8035, 0xffffffef,
206 static void __init imx6q_1588_init(void)
208 struct device_node *np;
210 struct clk *enet_ref;
214 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-fec");
216 pr_warn("%s: failed to find fec node\n", __func__);
220 ptp_clk = of_clk_get(np, 2);
221 if (IS_ERR(ptp_clk)) {
222 pr_warn("%s: failed to get ptp clock\n", __func__);
226 enet_ref = clk_get_sys(NULL, "enet_ref");
227 if (IS_ERR(enet_ref)) {
228 pr_warn("%s: failed to get enet clock\n", __func__);
233 * If enet_ref from ANATOP/CCM is the PTP clock source, we need to
234 * set bit IOMUXC_GPR1[21]. Or the PTP clock must be from pad
235 * (external OSC), and we need to clear the bit.
237 clksel = ptp_clk == enet_ref ? IMX6Q_GPR1_ENET_CLK_SEL_ANATOP :
238 IMX6Q_GPR1_ENET_CLK_SEL_PAD;
239 gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
241 regmap_update_bits(gpr, IOMUXC_GPR1,
242 IMX6Q_GPR1_ENET_CLK_SEL_MASK,
245 pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
254 static void __init imx6q_axi_init(void)
259 gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
262 * Enable the cacheable attribute of VPU and IPU
265 mask = IMX6Q_GPR4_VPU_WR_CACHE_SEL |
266 IMX6Q_GPR4_VPU_RD_CACHE_SEL |
267 IMX6Q_GPR4_VPU_P_WR_CACHE_VAL |
268 IMX6Q_GPR4_VPU_P_RD_CACHE_VAL_MASK |
269 IMX6Q_GPR4_IPU_WR_CACHE_CTL |
270 IMX6Q_GPR4_IPU_RD_CACHE_CTL;
271 regmap_update_bits(gpr, IOMUXC_GPR4, mask, mask);
273 /* Increase IPU read QoS priority */
274 regmap_update_bits(gpr, IOMUXC_GPR6,
275 IMX6Q_GPR6_IPU1_ID00_RD_QOS_MASK |
276 IMX6Q_GPR6_IPU1_ID01_RD_QOS_MASK,
277 (0xf << 16) | (0x7 << 20));
278 regmap_update_bits(gpr, IOMUXC_GPR7,
279 IMX6Q_GPR7_IPU2_ID00_RD_QOS_MASK |
280 IMX6Q_GPR7_IPU2_ID01_RD_QOS_MASK,
281 (0xf << 16) | (0x7 << 20));
283 pr_warn("failed to find fsl,imx6q-iomuxc-gpr regmap\n");
288 * Disable Hannstar LVDS panel CABC function.
289 * This function turns the panel's backlight density automatically
290 * according to the content shown on the panel which may cause
291 * annoying unstable backlight issue.
293 static void __init imx6q_lvds_cabc_init(void)
295 struct device_node *np = NULL;
296 int ret, lvds0_gpio, lvds1_gpio;
298 np = of_find_node_by_name(NULL, "lvds_cabc_ctrl");
302 lvds0_gpio = of_get_named_gpio(np, "lvds0-gpios", 0);
303 if (gpio_is_valid(lvds0_gpio)) {
304 ret = gpio_request_one(lvds0_gpio, GPIOF_OUT_INIT_LOW,
305 "LVDS0 CABC enable");
307 pr_warn("failed to request LVDS0 CABC gpio\n");
310 lvds1_gpio = of_get_named_gpio(np, "lvds1-gpios", 0);
311 if (gpio_is_valid(lvds1_gpio)) {
312 ret = gpio_request_one(lvds1_gpio, GPIOF_OUT_INIT_LOW,
313 "LVDS1 CABC enable");
315 pr_warn("failed to request LVDS1 CABC gpio\n");
319 static void __init imx6q_init_machine(void)
321 struct device *parent;
323 imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
324 imx_get_soc_revision());
326 mxc_arch_reset_init_dt();
328 parent = imx_soc_device_init();
330 pr_warn("failed to initialize soc device\n");
332 imx6q_enet_phy_init();
334 of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
337 cpu_is_imx6q() ? imx6q_pm_init() : imx6dl_pm_init();
340 imx6q_lvds_cabc_init();
343 #define OCOTP_CFG3 0x440
344 #define OCOTP_CFG3_SPEED_SHIFT 16
345 #define OCOTP_CFG3_SPEED_1P2GHZ 0x3
346 #define OCOTP_CFG3_SPEED_996MHZ 0x2
347 #define OCOTP_CFG3_SPEED_852MHZ 0x1
349 static void __init imx6q_opp_check_speed_grading(struct device *cpu_dev)
351 struct device_node *np;
355 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
357 pr_warn("failed to find ocotp node\n");
361 base = of_iomap(np, 0);
363 pr_warn("failed to map ocotp\n");
368 * SPEED_GRADING[1:0] defines the max speed of ARM:
369 * 2b'11: 1200000000Hz;
370 * 2b'10: 996000000Hz;
371 * 2b'01: 852000000Hz; -- i.MX6Q Only, exclusive with 996MHz.
372 * 2b'00: 792000000Hz;
373 * We need to set the max speed of ARM according to fuse map.
375 val = readl_relaxed(base + OCOTP_CFG3);
376 val >>= OCOTP_CFG3_SPEED_SHIFT;
379 if (val != OCOTP_CFG3_SPEED_1P2GHZ)
380 if (dev_pm_opp_disable(cpu_dev, 1200000000))
381 pr_warn("failed to disable 1.2 GHz OPP\n");
382 if (val < OCOTP_CFG3_SPEED_996MHZ)
383 if (dev_pm_opp_disable(cpu_dev, 996000000))
384 pr_warn("failed to disable 996 MHz OPP\n");
385 if (cpu_is_imx6q()) {
386 if (val != OCOTP_CFG3_SPEED_852MHZ)
387 if (dev_pm_opp_disable(cpu_dev, 852000000))
388 pr_warn("failed to disable 852 MHz OPP\n");
395 static void __init imx6q_opp_init(void)
397 struct device_node *np;
398 struct device *cpu_dev = get_cpu_device(0);
401 pr_warn("failed to get cpu0 device\n");
404 np = of_node_get(cpu_dev->of_node);
406 pr_warn("failed to find cpu0 node\n");
410 if (of_init_opp_table(cpu_dev)) {
411 pr_warn("failed to init OPP table\n");
415 imx6q_opp_check_speed_grading(cpu_dev);
421 static struct platform_device imx6q_cpufreq_pdev = {
422 .name = "imx6q-cpufreq",
425 static void __init imx6q_init_late(void)
428 * WAIT mode is broken on TO 1.0 and 1.1, so there is no point
429 * to run cpuidle on them.
431 if (imx_get_soc_revision() > IMX_CHIP_REVISION_1_1)
432 imx6q_cpuidle_init();
434 if (IS_ENABLED(CONFIG_ARM_IMX6Q_CPUFREQ)) {
436 platform_device_register(&imx6q_cpufreq_pdev);
440 static void __init imx6q_map_io(void)
447 static void __init imx6q_init_irq(void)
449 imx_init_revision_from_anatop();
456 static const char *imx6q_dt_compat[] __initconst = {
462 DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
464 * i.MX6Q/DL maps system memory at 0x10000000 (offset 256MiB), and
465 * GPU has a limit on physical address that it accesses, which must
468 .dma_zone_size = (SZ_2G - SZ_256M),
469 .smp = smp_ops(imx_smp_ops),
470 .map_io = imx6q_map_io,
471 .init_irq = imx6q_init_irq,
472 .init_machine = imx6q_init_machine,
473 .init_late = imx6q_init_late,
474 .dt_compat = imx6q_dt_compat,
475 .restart = mxc_restart,