]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-imx/mach-imx6q.c
ARM i.MX53: set CLK_SET_RATE_PARENT flag on the tve_ext_sel clock
[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/init.h>
19 #include <linux/io.h>
20 #include <linux/irq.h>
21 #include <linux/irqchip.h>
22 #include <linux/of.h>
23 #include <linux/of_address.h>
24 #include <linux/of_irq.h>
25 #include <linux/of_platform.h>
26 #include <linux/opp.h>
27 #include <linux/phy.h>
28 #include <linux/regmap.h>
29 #include <linux/micrel_phy.h>
30 #include <linux/mfd/syscon.h>
31 #include <asm/smp_twd.h>
32 #include <asm/hardware/cache-l2x0.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/time.h>
36 #include <asm/system_misc.h>
37
38 #include "common.h"
39 #include "cpuidle.h"
40 #include "hardware.h"
41
42 static u32 chip_revision;
43
44 int imx6q_revision(void)
45 {
46         return chip_revision;
47 }
48
49 static void __init imx6q_init_revision(void)
50 {
51         u32 rev = imx_anatop_get_digprog();
52
53         switch (rev & 0xff) {
54         case 0:
55                 chip_revision = IMX_CHIP_REVISION_1_0;
56                 break;
57         case 1:
58                 chip_revision = IMX_CHIP_REVISION_1_1;
59                 break;
60         case 2:
61                 chip_revision = IMX_CHIP_REVISION_1_2;
62                 break;
63         default:
64                 chip_revision = IMX_CHIP_REVISION_UNKNOWN;
65         }
66
67         mxc_set_cpu_type(rev >> 16 & 0xff);
68 }
69
70 void imx6q_restart(char mode, const char *cmd)
71 {
72         struct device_node *np;
73         void __iomem *wdog_base;
74
75         np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-wdt");
76         wdog_base = of_iomap(np, 0);
77         if (!wdog_base)
78                 goto soft;
79
80         imx_src_prepare_restart();
81
82         /* enable wdog */
83         writew_relaxed(1 << 2, wdog_base);
84         /* write twice to ensure the request will not get ignored */
85         writew_relaxed(1 << 2, wdog_base);
86
87         /* wait for reset to assert ... */
88         mdelay(500);
89
90         pr_err("Watchdog reset failed to assert reset\n");
91
92         /* delay to allow the serial port to show the message */
93         mdelay(50);
94
95 soft:
96         /* we'll take a jump through zero as a poor second */
97         soft_restart(0);
98 }
99
100 /* For imx6q sabrelite board: set KSZ9021RN RGMII pad skew */
101 static int ksz9021rn_phy_fixup(struct phy_device *phydev)
102 {
103         if (IS_BUILTIN(CONFIG_PHYLIB)) {
104                 /* min rx data delay */
105                 phy_write(phydev, 0x0b, 0x8105);
106                 phy_write(phydev, 0x0c, 0x0000);
107
108                 /* max rx/tx clock delay, min rx/tx control delay */
109                 phy_write(phydev, 0x0b, 0x8104);
110                 phy_write(phydev, 0x0c, 0xf0f0);
111                 phy_write(phydev, 0x0b, 0x104);
112         }
113
114         return 0;
115 }
116
117 static void __init imx6q_sabrelite_cko1_setup(void)
118 {
119         struct clk *cko1_sel, *ahb, *cko1;
120         unsigned long rate;
121
122         cko1_sel = clk_get_sys(NULL, "cko1_sel");
123         ahb = clk_get_sys(NULL, "ahb");
124         cko1 = clk_get_sys(NULL, "cko1");
125         if (IS_ERR(cko1_sel) || IS_ERR(ahb) || IS_ERR(cko1)) {
126                 pr_err("cko1 setup failed!\n");
127                 goto put_clk;
128         }
129         clk_set_parent(cko1_sel, ahb);
130         rate = clk_round_rate(cko1, 16000000);
131         clk_set_rate(cko1, rate);
132 put_clk:
133         if (!IS_ERR(cko1_sel))
134                 clk_put(cko1_sel);
135         if (!IS_ERR(ahb))
136                 clk_put(ahb);
137         if (!IS_ERR(cko1))
138                 clk_put(cko1);
139 }
140
141 static void __init imx6q_sabrelite_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         imx6q_sabrelite_cko1_setup();
147 }
148
149 static void __init imx6q_1588_init(void)
150 {
151         struct regmap *gpr;
152
153         gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
154         if (!IS_ERR(gpr))
155                 regmap_update_bits(gpr, 0x4, 1 << 21, 1 << 21);
156         else
157                 pr_err("failed to find fsl,imx6q-iomux-gpr regmap\n");
158
159 }
160 static void __init imx6q_usb_init(void)
161 {
162         imx_anatop_usb_chrg_detect_disable();
163 }
164
165 static void __init imx6q_init_machine(void)
166 {
167         if (of_machine_is_compatible("fsl,imx6q-sabrelite"))
168                 imx6q_sabrelite_init();
169
170         of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
171
172         imx_anatop_init();
173         imx6q_pm_init();
174         imx6q_usb_init();
175         imx6q_1588_init();
176 }
177
178 #define OCOTP_CFG3                      0x440
179 #define OCOTP_CFG3_SPEED_SHIFT          16
180 #define OCOTP_CFG3_SPEED_1P2GHZ         0x3
181
182 static void __init imx6q_opp_check_1p2ghz(struct device *cpu_dev)
183 {
184         struct device_node *np;
185         void __iomem *base;
186         u32 val;
187
188         np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
189         if (!np) {
190                 pr_warn("failed to find ocotp node\n");
191                 return;
192         }
193
194         base = of_iomap(np, 0);
195         if (!base) {
196                 pr_warn("failed to map ocotp\n");
197                 goto put_node;
198         }
199
200         val = readl_relaxed(base + OCOTP_CFG3);
201         val >>= OCOTP_CFG3_SPEED_SHIFT;
202         if ((val & 0x3) != OCOTP_CFG3_SPEED_1P2GHZ)
203                 if (opp_disable(cpu_dev, 1200000000))
204                         pr_warn("failed to disable 1.2 GHz OPP\n");
205
206 put_node:
207         of_node_put(np);
208 }
209
210 static void __init imx6q_opp_init(struct device *cpu_dev)
211 {
212         struct device_node *np;
213
214         np = of_find_node_by_path("/cpus/cpu@0");
215         if (!np) {
216                 pr_warn("failed to find cpu0 node\n");
217                 return;
218         }
219
220         cpu_dev->of_node = np;
221         if (of_init_opp_table(cpu_dev)) {
222                 pr_warn("failed to init OPP table\n");
223                 goto put_node;
224         }
225
226         imx6q_opp_check_1p2ghz(cpu_dev);
227
228 put_node:
229         of_node_put(np);
230 }
231
232 struct platform_device imx6q_cpufreq_pdev = {
233         .name = "imx6q-cpufreq",
234 };
235
236 static void __init imx6q_init_late(void)
237 {
238         /*
239          * WAIT mode is broken on TO 1.0 and 1.1, so there is no point
240          * to run cpuidle on them.
241          */
242         if (imx6q_revision() > IMX_CHIP_REVISION_1_1)
243                 imx6q_cpuidle_init();
244
245         if (IS_ENABLED(CONFIG_ARM_IMX6Q_CPUFREQ)) {
246                 imx6q_opp_init(&imx6q_cpufreq_pdev.dev);
247                 platform_device_register(&imx6q_cpufreq_pdev);
248         }
249 }
250
251 static void __init imx6q_map_io(void)
252 {
253         debug_ll_io_init();
254         imx_scu_map_io();
255 }
256
257 static void __init imx6q_init_irq(void)
258 {
259         imx6q_init_revision();
260         l2x0_of_init(0, ~0UL);
261         imx_src_init();
262         imx_gpc_init();
263         irqchip_init();
264 }
265
266 static void __init imx6q_timer_init(void)
267 {
268         mx6q_clocks_init();
269         twd_local_timer_of_register();
270         imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
271                               imx6q_revision());
272 }
273
274 static const char *imx6q_dt_compat[] __initdata = {
275         "fsl,imx6dl",
276         "fsl,imx6q",
277         NULL,
278 };
279
280 DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
281         .smp            = smp_ops(imx_smp_ops),
282         .map_io         = imx6q_map_io,
283         .init_irq       = imx6q_init_irq,
284         .init_time      = imx6q_timer_init,
285         .init_machine   = imx6q_init_machine,
286         .init_late      = imx6q_init_late,
287         .dt_compat      = imx6q_dt_compat,
288         .restart        = imx6q_restart,
289 MACHINE_END