]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-imx/mach-imx6q.c
47af9aeedfe5e909f15335554bd7ea3f22948eee
[karo-tx-linux.git] / arch / arm / mach-imx / mach-imx6q.c
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
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>
20 #include <linux/io.h>
21 #include <linux/irq.h>
22 #include <linux/irqchip.h>
23 #include <linux/of.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>
39
40 #include "common.h"
41 #include "cpuidle.h"
42 #include "hardware.h"
43
44 /* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */
45 static int ksz9021rn_phy_fixup(struct phy_device *phydev)
46 {
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);
52
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);
59         }
60
61         return 0;
62 }
63
64 static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
65 {
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);
70 }
71
72 static int ksz9031rn_phy_fixup(struct phy_device *dev)
73 {
74         /*
75          * min rx data delay, max rx/tx clock delay,
76          * min rx/tx control delay
77          */
78         mmd_write_reg(dev, 2, 4, 0);
79         mmd_write_reg(dev, 2, 5, 0);
80         mmd_write_reg(dev, 2, 8, 0x003ff);
81
82         return 0;
83 }
84
85 /*
86  * fixup for PLX PEX8909 bridge to configure GPIO1-7 as output High
87  * as they are used for slots1-7 PERST#
88  */
89 static void ventana_pciesw_early_fixup(struct pci_dev *dev)
90 {
91         u32 dw;
92
93         if (!of_machine_is_compatible("gw,ventana"))
94                 return;
95
96         if (dev->devfn != 0)
97                 return;
98
99         pci_read_config_dword(dev, 0x62c, &dw);
100         dw |= 0xaaa8; // GPIO1-7 outputs
101         pci_write_config_dword(dev, 0x62c, dw);
102
103         pci_read_config_dword(dev, 0x644, &dw);
104         dw |= 0xfe;   // GPIO1-7 output high
105         pci_write_config_dword(dev, 0x644, dw);
106
107         msleep(100);
108 }
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);
112
113 static void mmd_write_reg(struct phy_device *dev, int device, int reg, int val)
114 {
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);
119 }
120
121 static int ksz9031rn_phy_fixup(struct phy_device *dev)
122 {
123         /*
124          * min rx data delay, max rx/tx clock delay,
125          * min rx/tx control delay
126          */
127         mmd_write_reg(dev, 2, 4, 0);
128         mmd_write_reg(dev, 2, 5, 0);
129         mmd_write_reg(dev, 2, 8, 0x003ff);
130
131         return 0;
132 }
133
134 static int ar8031_phy_fixup(struct phy_device *dev)
135 {
136         u16 val;
137
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);
142
143         val = phy_read(dev, 0xe);
144         val &= 0xffe3;
145         val |= 0x18;
146         phy_write(dev, 0xe, val);
147
148         /* introduce tx clock delay */
149         phy_write(dev, 0x1d, 0x5);
150         val = phy_read(dev, 0x1e);
151         val |= 0x0100;
152         phy_write(dev, 0x1e, val);
153
154         return 0;
155 }
156
157 #define PHY_ID_AR8031   0x004dd074
158
159 static int ar8035_phy_fixup(struct phy_device *dev)
160 {
161         u16 val;
162
163         /* Ar803x phy SmartEEE feature cause link status generates glitch,
164          * which cause ethernet link down/up issue, so disable SmartEEE
165          */
166         phy_write(dev, 0xd, 0x3);
167         phy_write(dev, 0xe, 0x805d);
168         phy_write(dev, 0xd, 0x4003);
169
170         val = phy_read(dev, 0xe);
171         phy_write(dev, 0xe, val & ~(1 << 8));
172
173         /*
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.
177          *
178          * This is the same as is the AR8031 fixup.
179          */
180         ar8031_phy_fixup(dev);
181
182         /*check phy power*/
183         val = phy_read(dev, 0x0);
184         if (val & BMCR_PDOWN)
185                 phy_write(dev, 0x0, val & ~BMCR_PDOWN);
186
187         return 0;
188 }
189
190 #define PHY_ID_AR8035 0x004dd072
191
192 static void __init imx6q_enet_phy_init(void)
193 {
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,
200                                 ar8031_phy_fixup);
201                 phy_register_fixup_for_uid(PHY_ID_AR8035, 0xffffffef,
202                                 ar8035_phy_fixup);
203         }
204 }
205
206 static void __init imx6q_1588_init(void)
207 {
208         struct device_node *np;
209         struct clk *ptp_clk;
210         struct clk *enet_ref;
211         struct regmap *gpr;
212         u32 clksel;
213
214         np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-fec");
215         if (!np) {
216                 pr_warn("%s: failed to find fec node\n", __func__);
217                 return;
218         }
219
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__);
223                 goto put_node;
224         }
225
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__);
229                 goto put_ptp_clk;
230         }
231
232         /*
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.
236          */
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");
240         if (!IS_ERR(gpr))
241                 regmap_update_bits(gpr, IOMUXC_GPR1,
242                                 IMX6Q_GPR1_ENET_CLK_SEL_MASK,
243                                 clksel);
244         else
245                 pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
246
247         clk_put(enet_ref);
248 put_ptp_clk:
249         clk_put(ptp_clk);
250 put_node:
251         of_node_put(np);
252 }
253
254 static void __init imx6q_axi_init(void)
255 {
256         struct regmap *gpr;
257         unsigned int mask;
258
259         gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
260         if (!IS_ERR(gpr)) {
261                 /*
262                  * Enable the cacheable attribute of VPU and IPU
263                  * AXI transactions.
264                  */
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);
272
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));
282         } else {
283                 pr_warn("failed to find fsl,imx6q-iomuxc-gpr regmap\n");
284         }
285 }
286
287 /*
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.
292  */
293 static void __init imx6q_lvds_cabc_init(void)
294 {
295         struct device_node *np = NULL;
296         int ret, lvds0_gpio, lvds1_gpio;
297
298         np = of_find_node_by_name(NULL, "lvds_cabc_ctrl");
299         if (!np)
300                 return;
301
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");
306                 if (ret)
307                         pr_warn("failed to request LVDS0 CABC gpio\n");
308         }
309
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");
314                 if (ret)
315                         pr_warn("failed to request LVDS1 CABC gpio\n");
316         }
317 }
318
319 static void __init imx6q_init_machine(void)
320 {
321         struct device *parent;
322
323         imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
324                               imx_get_soc_revision());
325
326         mxc_arch_reset_init_dt();
327
328         parent = imx_soc_device_init();
329         if (parent == NULL)
330                 pr_warn("failed to initialize soc device\n");
331
332         imx6q_enet_phy_init();
333
334         of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
335
336         imx_anatop_init();
337         cpu_is_imx6q() ?  imx6q_pm_init() : imx6dl_pm_init();
338         imx6q_1588_init();
339         imx6q_axi_init();
340         imx6q_lvds_cabc_init();
341 }
342
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
348
349 static void __init imx6q_opp_check_speed_grading(struct device *cpu_dev)
350 {
351         struct device_node *np;
352         void __iomem *base;
353         u32 val;
354
355         np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
356         if (!np) {
357                 pr_warn("failed to find ocotp node\n");
358                 return;
359         }
360
361         base = of_iomap(np, 0);
362         if (!base) {
363                 pr_warn("failed to map ocotp\n");
364                 goto put_node;
365         }
366
367         /*
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.
374          */
375         val = readl_relaxed(base + OCOTP_CFG3);
376         val >>= OCOTP_CFG3_SPEED_SHIFT;
377         val &= 0x3;
378
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");
389         }
390
391 put_node:
392         of_node_put(np);
393 }
394
395 static void __init imx6q_opp_init(void)
396 {
397         struct device_node *np;
398         struct device *cpu_dev = get_cpu_device(0);
399
400         if (!cpu_dev) {
401                 pr_warn("failed to get cpu0 device\n");
402                 return;
403         }
404         np = of_node_get(cpu_dev->of_node);
405         if (!np) {
406                 pr_warn("failed to find cpu0 node\n");
407                 return;
408         }
409
410         if (of_init_opp_table(cpu_dev)) {
411                 pr_warn("failed to init OPP table\n");
412                 goto put_node;
413         }
414
415         imx6q_opp_check_speed_grading(cpu_dev);
416
417 put_node:
418         of_node_put(np);
419 }
420
421 static struct platform_device imx6q_cpufreq_pdev = {
422         .name = "imx6q-cpufreq",
423 };
424
425 static void __init imx6q_init_late(void)
426 {
427         /*
428          * WAIT mode is broken on TO 1.0 and 1.1, so there is no point
429          * to run cpuidle on them.
430          */
431         if (imx_get_soc_revision() > IMX_CHIP_REVISION_1_1)
432                 imx6q_cpuidle_init();
433
434         if (IS_ENABLED(CONFIG_ARM_IMX6Q_CPUFREQ)) {
435                 imx6q_opp_init();
436                 platform_device_register(&imx6q_cpufreq_pdev);
437         }
438 }
439
440 static void __init imx6q_map_io(void)
441 {
442         debug_ll_io_init();
443         imx_scu_map_io();
444         imx6_pm_map_io();
445 }
446
447 static void __init imx6q_init_irq(void)
448 {
449         imx_init_revision_from_anatop();
450         imx_init_l2cache();
451         imx_src_init();
452         imx_gpc_init();
453         irqchip_init();
454 }
455
456 static const char *imx6q_dt_compat[] __initconst = {
457         "fsl,imx6dl",
458         "fsl,imx6q",
459         NULL,
460 };
461
462 DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
463         /*
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
466          * be below 2GiB.
467          */
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,
476 MACHINE_END