blob: b5c1bdd3dcdf7259ea7061814af1653bffb19648 [file] [log] [blame]
Dong Aishengbc3a59c2012-03-31 21:26:57 +08001/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright 2012 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>
Shawn Guo3cb78252013-03-29 13:36:05 +080014#include <linux/clk/mxs.h>
Dong Aishengbc3a59c2012-03-31 21:26:57 +080015#include <linux/clkdev.h>
Shawn Guo633ef4c2013-03-25 14:53:08 +080016#include <linux/clocksource.h>
Shawn Guo44ffb782012-08-06 22:00:45 +080017#include <linux/can/platform/flexcan.h>
Shawn Guo2c7c2c12012-07-13 14:15:34 +080018#include <linux/delay.h>
Dong Aishengbc3a59c2012-03-31 21:26:57 +080019#include <linux/err.h>
Shawn Guo2c7c2c12012-07-13 14:15:34 +080020#include <linux/gpio.h>
Dong Aishengbc3a59c2012-03-31 21:26:57 +080021#include <linux/init.h>
Shawn Guo6a8e95b2013-03-25 21:34:51 +080022#include <linux/irqchip.h>
23#include <linux/irqchip/mxs.h>
Shawn Guo3143bbb2012-07-07 23:12:03 +080024#include <linux/micrel_phy.h>
Shawn Guoab2815c2012-06-25 21:21:46 +080025#include <linux/mxsfb.h>
Shawn Guo974a9af2013-03-29 09:45:31 +080026#include <linux/of_address.h>
Dong Aishengbc3a59c2012-03-31 21:26:57 +080027#include <linux/of_platform.h>
Shawn Guo3143bbb2012-07-07 23:12:03 +080028#include <linux/phy.h>
Shawn Guo2c7c2c12012-07-13 14:15:34 +080029#include <linux/pinctrl/consumer.h>
Dong Aishengbc3a59c2012-03-31 21:26:57 +080030#include <asm/mach/arch.h>
Shawn Guo1f629562013-03-29 13:07:34 +080031#include <asm/mach/map.h>
Dong Aishengbc3a59c2012-03-31 21:26:57 +080032#include <asm/mach/time.h>
Shawn Guo974a9af2013-03-29 09:45:31 +080033#include <asm/system_misc.h>
Shawn Guo0b48d3a2013-03-29 13:53:11 +080034
Shawn Guo45680992013-03-29 14:41:27 +080035#include "pm.h"
36
Shawn Guo0b48d3a2013-03-29 13:53:11 +080037/* MXS DIGCTL SAIF CLKMUX */
38#define MXS_DIGCTL_SAIF_CLKMUX_DIRECT 0x0
39#define MXS_DIGCTL_SAIF_CLKMUX_CROSSINPUT 0x1
40#define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0 0x2
41#define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR1 0x3
42
43#define MXS_GPIO_NR(bank, nr) ((bank) * 32 + (nr))
44
45#define MXS_SET_ADDR 0x4
46#define MXS_CLR_ADDR 0x8
47#define MXS_TOG_ADDR 0xc
48
49static inline void __mxs_setl(u32 mask, void __iomem *reg)
50{
51 __raw_writel(mask, reg + MXS_SET_ADDR);
52}
53
54static inline void __mxs_clrl(u32 mask, void __iomem *reg)
55{
56 __raw_writel(mask, reg + MXS_CLR_ADDR);
57}
58
59static inline void __mxs_togl(u32 mask, void __iomem *reg)
60{
61 __raw_writel(mask, reg + MXS_TOG_ADDR);
62}
Dong Aishengbc3a59c2012-03-31 21:26:57 +080063
Shawn Guoab2815c2012-06-25 21:21:46 +080064static struct fb_videomode mx23evk_video_modes[] = {
65 {
66 .name = "Samsung-LMS430HF02",
67 .refresh = 60,
68 .xres = 480,
69 .yres = 272,
70 .pixclock = 108096, /* picosecond (9.2 MHz) */
71 .left_margin = 15,
72 .right_margin = 8,
73 .upper_margin = 12,
74 .lower_margin = 4,
75 .hsync_len = 1,
76 .vsync_len = 1,
Shawn Guoab2815c2012-06-25 21:21:46 +080077 },
78};
79
80static struct fb_videomode mx28evk_video_modes[] = {
81 {
82 .name = "Seiko-43WVF1G",
83 .refresh = 60,
84 .xres = 800,
85 .yres = 480,
86 .pixclock = 29851, /* picosecond (33.5 MHz) */
87 .left_margin = 89,
88 .right_margin = 164,
89 .upper_margin = 23,
90 .lower_margin = 10,
91 .hsync_len = 10,
92 .vsync_len = 10,
Shawn Guoab2815c2012-06-25 21:21:46 +080093 },
94};
95
Marek Vasut8fa62e12012-07-07 21:21:38 +080096static struct fb_videomode m28evk_video_modes[] = {
97 {
98 .name = "Ampire AM-800480R2TMQW-T01H",
99 .refresh = 60,
100 .xres = 800,
101 .yres = 480,
102 .pixclock = 30066, /* picosecond (33.26 MHz) */
103 .left_margin = 0,
104 .right_margin = 256,
105 .upper_margin = 0,
106 .lower_margin = 45,
107 .hsync_len = 1,
108 .vsync_len = 1,
Marek Vasut8fa62e12012-07-07 21:21:38 +0800109 },
110};
111
Lauri Hintsalad8bb8232012-07-10 10:08:08 +0300112static struct fb_videomode apx4devkit_video_modes[] = {
113 {
114 .name = "HannStar PJ70112A",
115 .refresh = 60,
116 .xres = 800,
117 .yres = 480,
118 .pixclock = 33333, /* picosecond (30.00 MHz) */
119 .left_margin = 88,
120 .right_margin = 40,
121 .upper_margin = 32,
122 .lower_margin = 13,
123 .hsync_len = 48,
124 .vsync_len = 3,
Marek Vasut6a150752013-03-18 19:24:02 +0100125 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Lauri Hintsalad8bb8232012-07-10 10:08:08 +0300126 },
127};
128
Gwenhael Goavec-Meroua4dabca2012-11-02 19:01:48 +0100129static struct fb_videomode apf28dev_video_modes[] = {
130 {
131 .name = "LW700",
132 .refresh = 60,
133 .xres = 800,
134 .yres = 480,
135 .pixclock = 30303, /* picosecond */
136 .left_margin = 96,
137 .right_margin = 96, /* at least 3 & 1 */
138 .upper_margin = 0x14,
139 .lower_margin = 0x15,
140 .hsync_len = 64,
141 .vsync_len = 4,
Marek Vasut6a150752013-03-18 19:24:02 +0100142 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Gwenhael Goavec-Meroua4dabca2012-11-02 19:01:48 +0100143 },
144};
145
Maxime Ripard1fe42742013-01-25 09:54:07 +0100146static struct fb_videomode cfa10049_video_modes[] = {
147 {
148 .name = "Himax HX8357-B",
149 .refresh = 60,
150 .xres = 320,
151 .yres = 480,
152 .pixclock = 108506, /* picosecond (9.216 MHz) */
153 .left_margin = 2,
154 .right_margin = 2,
155 .upper_margin = 2,
156 .lower_margin = 2,
157 .hsync_len = 15,
158 .vsync_len = 15,
Maxime Ripard1fe42742013-01-25 09:54:07 +0100159 },
160};
161
Shawn Guoab2815c2012-06-25 21:21:46 +0800162static struct mxsfb_platform_data mxsfb_pdata __initdata;
163
Shawn Guo44ffb782012-08-06 22:00:45 +0800164/*
165 * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers
166 */
167#define MX28EVK_FLEXCAN_SWITCH MXS_GPIO_NR(2, 13)
168
169static int flexcan0_en, flexcan1_en;
170
171static void mx28evk_flexcan_switch(void)
172{
173 if (flexcan0_en || flexcan1_en)
174 gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1);
175 else
176 gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0);
177}
178
179static void mx28evk_flexcan0_switch(int enable)
180{
181 flexcan0_en = enable;
182 mx28evk_flexcan_switch();
183}
184
185static void mx28evk_flexcan1_switch(int enable)
186{
187 flexcan1_en = enable;
188 mx28evk_flexcan_switch();
189}
190
191static struct flexcan_platform_data flexcan_pdata[2];
192
Shawn Guoab2815c2012-06-25 21:21:46 +0800193static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = {
194 OF_DEV_AUXDATA("fsl,imx23-lcdif", 0x80030000, NULL, &mxsfb_pdata),
195 OF_DEV_AUXDATA("fsl,imx28-lcdif", 0x80030000, NULL, &mxsfb_pdata),
Shawn Guo44ffb782012-08-06 22:00:45 +0800196 OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80032000, NULL, &flexcan_pdata[0]),
197 OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80034000, NULL, &flexcan_pdata[1]),
Shawn Guoab2815c2012-06-25 21:21:46 +0800198 { /* sentinel */ }
199};
200
Shawn Guo1bff2d72013-03-29 13:27:55 +0800201#define OCOTP_WORD_OFFSET 0x20
202#define OCOTP_WORD_COUNT 0x20
203
204#define BM_OCOTP_CTRL_BUSY (1 << 8)
205#define BM_OCOTP_CTRL_ERROR (1 << 9)
206#define BM_OCOTP_CTRL_RD_BANK_OPEN (1 << 12)
207
208static DEFINE_MUTEX(ocotp_mutex);
209static u32 ocotp_words[OCOTP_WORD_COUNT];
210
211static const u32 *mxs_get_ocotp(void)
212{
213 struct device_node *np;
214 void __iomem *ocotp_base;
215 int timeout = 0x400;
216 size_t i;
217 static int once;
218
219 if (once)
220 return ocotp_words;
221
222 np = of_find_compatible_node(NULL, NULL, "fsl,ocotp");
223 ocotp_base = of_iomap(np, 0);
224 WARN_ON(!ocotp_base);
225
226 mutex_lock(&ocotp_mutex);
227
228 /*
229 * clk_enable(hbus_clk) for ocotp can be skipped
230 * as it must be on when system is running.
231 */
232
233 /* try to clear ERROR bit */
234 __mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base);
235
236 /* check both BUSY and ERROR cleared */
237 while ((__raw_readl(ocotp_base) &
238 (BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout)
239 cpu_relax();
240
241 if (unlikely(!timeout))
242 goto error_unlock;
243
244 /* open OCOTP banks for read */
245 __mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
246
247 /* approximately wait 32 hclk cycles */
248 udelay(1);
249
250 /* poll BUSY bit becoming cleared */
251 timeout = 0x400;
252 while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
253 cpu_relax();
254
255 if (unlikely(!timeout))
256 goto error_unlock;
257
258 for (i = 0; i < OCOTP_WORD_COUNT; i++)
259 ocotp_words[i] = __raw_readl(ocotp_base + OCOTP_WORD_OFFSET +
260 i * 0x10);
261
262 /* close banks for power saving */
263 __mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
264
265 once = 1;
266
267 mutex_unlock(&ocotp_mutex);
268
269 return ocotp_words;
270
271error_unlock:
272 mutex_unlock(&ocotp_mutex);
273 pr_err("%s: timeout in reading OCOTP\n", __func__);
274 return NULL;
275}
276
Shawn Guo5653acc2012-06-19 22:38:14 +0800277enum mac_oui {
278 OUI_FSL,
279 OUI_DENX,
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800280 OUI_CRYSTALFONTZ,
Shawn Guo5653acc2012-06-19 22:38:14 +0800281};
282
283static void __init update_fec_mac_prop(enum mac_oui oui)
284{
285 struct device_node *np, *from = NULL;
Shawn Guofa7c8652012-07-13 14:13:55 +0800286 struct property *newmac;
Shawn Guo5653acc2012-06-19 22:38:14 +0800287 const u32 *ocotp = mxs_get_ocotp();
288 u8 *macaddr;
289 u32 val;
290 int i;
291
292 for (i = 0; i < 2; i++) {
293 np = of_find_compatible_node(from, NULL, "fsl,imx28-fec");
294 if (!np)
295 return;
Marek Vasut16d47702012-09-25 13:32:18 +0200296
Shawn Guo5653acc2012-06-19 22:38:14 +0800297 from = np;
298
Marek Vasut16d47702012-09-25 13:32:18 +0200299 if (of_get_property(np, "local-mac-address", NULL))
300 continue;
301
Shawn Guo5653acc2012-06-19 22:38:14 +0800302 newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
303 if (!newmac)
304 return;
305 newmac->value = newmac + 1;
306 newmac->length = 6;
307
308 newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
309 if (!newmac->name) {
310 kfree(newmac);
311 return;
312 }
313
314 /*
315 * OCOTP only stores the last 4 octets for each mac address,
316 * so hard-code OUI here.
317 */
318 macaddr = newmac->value;
319 switch (oui) {
320 case OUI_FSL:
321 macaddr[0] = 0x00;
322 macaddr[1] = 0x04;
323 macaddr[2] = 0x9f;
324 break;
325 case OUI_DENX:
326 macaddr[0] = 0xc0;
327 macaddr[1] = 0xe5;
328 macaddr[2] = 0x4e;
329 break;
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800330 case OUI_CRYSTALFONTZ:
331 macaddr[0] = 0x58;
332 macaddr[1] = 0xb9;
333 macaddr[2] = 0xe1;
334 break;
Shawn Guo5653acc2012-06-19 22:38:14 +0800335 }
336 val = ocotp[i];
337 macaddr[3] = (val >> 16) & 0xff;
338 macaddr[4] = (val >> 8) & 0xff;
339 macaddr[5] = (val >> 0) & 0xff;
340
Nathan Fontenot79d1c712012-10-02 16:58:46 +0000341 of_update_property(np, newmac);
Shawn Guo5653acc2012-06-19 22:38:14 +0800342 }
343}
344
Shawn Guoab2815c2012-06-25 21:21:46 +0800345static void __init imx23_evk_init(void)
346{
347 mxsfb_pdata.mode_list = mx23evk_video_modes;
348 mxsfb_pdata.mode_count = ARRAY_SIZE(mx23evk_video_modes);
349 mxsfb_pdata.default_bpp = 32;
350 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100351 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
352 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Shawn Guoab2815c2012-06-25 21:21:46 +0800353}
354
Marek Vasut8fa62e12012-07-07 21:21:38 +0800355static inline void enable_clk_enet_out(void)
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800356{
Marek Vasut8fa62e12012-07-07 21:21:38 +0800357 struct clk *clk = clk_get_sys("enet_out", NULL);
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800358
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800359 if (!IS_ERR(clk))
360 clk_prepare_enable(clk);
Marek Vasut8fa62e12012-07-07 21:21:38 +0800361}
Shawn Guo5653acc2012-06-19 22:38:14 +0800362
Marek Vasut8fa62e12012-07-07 21:21:38 +0800363static void __init imx28_evk_init(void)
364{
365 enable_clk_enet_out();
Shawn Guo5653acc2012-06-19 22:38:14 +0800366 update_fec_mac_prop(OUI_FSL);
Shawn Guoab2815c2012-06-25 21:21:46 +0800367
368 mxsfb_pdata.mode_list = mx28evk_video_modes;
369 mxsfb_pdata.mode_count = ARRAY_SIZE(mx28evk_video_modes);
370 mxsfb_pdata.default_bpp = 32;
371 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100372 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
373 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Dong Aishenge3173172012-08-01 11:20:16 +0800374
375 mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0);
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800376}
377
Shawn Guo44ffb782012-08-06 22:00:45 +0800378static void __init imx28_evk_post_init(void)
379{
380 if (!gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT,
381 "flexcan-switch")) {
382 flexcan_pdata[0].transceiver_switch = mx28evk_flexcan0_switch;
383 flexcan_pdata[1].transceiver_switch = mx28evk_flexcan1_switch;
384 }
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800385}
386
Marek Vasut8fa62e12012-07-07 21:21:38 +0800387static void __init m28evk_init(void)
388{
Marek Vasut8fa62e12012-07-07 21:21:38 +0800389 mxsfb_pdata.mode_list = m28evk_video_modes;
390 mxsfb_pdata.mode_count = ARRAY_SIZE(m28evk_video_modes);
391 mxsfb_pdata.default_bpp = 16;
392 mxsfb_pdata.ld_intf_width = STMLCDIF_18BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100393 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT;
Marek Vasut8fa62e12012-07-07 21:21:38 +0800394}
395
Marek Vasut160d5f22012-11-18 22:08:29 +0100396static void __init sc_sps1_init(void)
397{
398 enable_clk_enet_out();
399}
400
Shawn Guo3143bbb2012-07-07 23:12:03 +0800401static int apx4devkit_phy_fixup(struct phy_device *phy)
402{
403 phy->dev_flags |= MICREL_PHY_50MHZ_CLK;
404 return 0;
405}
406
407static void __init apx4devkit_init(void)
408{
409 enable_clk_enet_out();
410
411 if (IS_BUILTIN(CONFIG_PHYLIB))
Marek Vasut510d5732012-09-23 16:58:50 +0000412 phy_register_fixup_for_uid(PHY_ID_KSZ8051, MICREL_PHY_ID_MASK,
Shawn Guo3143bbb2012-07-07 23:12:03 +0800413 apx4devkit_phy_fixup);
Lauri Hintsalad8bb8232012-07-10 10:08:08 +0300414
415 mxsfb_pdata.mode_list = apx4devkit_video_modes;
416 mxsfb_pdata.mode_count = ARRAY_SIZE(apx4devkit_video_modes);
417 mxsfb_pdata.default_bpp = 32;
418 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100419 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
420 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Shawn Guo3143bbb2012-07-07 23:12:03 +0800421}
422
Shawn Guo2c7c2c12012-07-13 14:15:34 +0800423#define ENET0_MDC__GPIO_4_0 MXS_GPIO_NR(4, 0)
424#define ENET0_MDIO__GPIO_4_1 MXS_GPIO_NR(4, 1)
425#define ENET0_RX_EN__GPIO_4_2 MXS_GPIO_NR(4, 2)
426#define ENET0_RXD0__GPIO_4_3 MXS_GPIO_NR(4, 3)
427#define ENET0_RXD1__GPIO_4_4 MXS_GPIO_NR(4, 4)
428#define ENET0_TX_EN__GPIO_4_6 MXS_GPIO_NR(4, 6)
429#define ENET0_TXD0__GPIO_4_7 MXS_GPIO_NR(4, 7)
430#define ENET0_TXD1__GPIO_4_8 MXS_GPIO_NR(4, 8)
431#define ENET_CLK__GPIO_4_16 MXS_GPIO_NR(4, 16)
432
433#define TX28_FEC_PHY_POWER MXS_GPIO_NR(3, 29)
434#define TX28_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
435#define TX28_FEC_nINT MXS_GPIO_NR(4, 5)
436
437static const struct gpio tx28_gpios[] __initconst = {
438 { ENET0_MDC__GPIO_4_0, GPIOF_OUT_INIT_LOW, "GPIO_4_0" },
439 { ENET0_MDIO__GPIO_4_1, GPIOF_OUT_INIT_LOW, "GPIO_4_1" },
440 { ENET0_RX_EN__GPIO_4_2, GPIOF_OUT_INIT_LOW, "GPIO_4_2" },
441 { ENET0_RXD0__GPIO_4_3, GPIOF_OUT_INIT_LOW, "GPIO_4_3" },
442 { ENET0_RXD1__GPIO_4_4, GPIOF_OUT_INIT_LOW, "GPIO_4_4" },
443 { ENET0_TX_EN__GPIO_4_6, GPIOF_OUT_INIT_LOW, "GPIO_4_6" },
444 { ENET0_TXD0__GPIO_4_7, GPIOF_OUT_INIT_LOW, "GPIO_4_7" },
445 { ENET0_TXD1__GPIO_4_8, GPIOF_OUT_INIT_LOW, "GPIO_4_8" },
446 { ENET_CLK__GPIO_4_16, GPIOF_OUT_INIT_LOW, "GPIO_4_16" },
447 { TX28_FEC_PHY_POWER, GPIOF_OUT_INIT_LOW, "fec-phy-power" },
448 { TX28_FEC_PHY_RESET, GPIOF_OUT_INIT_LOW, "fec-phy-reset" },
449 { TX28_FEC_nINT, GPIOF_DIR_IN, "fec-int" },
450};
451
452static void __init tx28_post_init(void)
453{
454 struct device_node *np;
455 struct platform_device *pdev;
456 struct pinctrl *pctl;
457 int ret;
458
459 enable_clk_enet_out();
460
461 np = of_find_compatible_node(NULL, NULL, "fsl,imx28-fec");
462 pdev = of_find_device_by_node(np);
463 if (!pdev) {
464 pr_err("%s: failed to find fec device\n", __func__);
465 return;
466 }
467
468 pctl = pinctrl_get_select(&pdev->dev, "gpio_mode");
469 if (IS_ERR(pctl)) {
470 pr_err("%s: failed to get pinctrl state\n", __func__);
471 return;
472 }
473
474 ret = gpio_request_array(tx28_gpios, ARRAY_SIZE(tx28_gpios));
475 if (ret) {
476 pr_err("%s: failed to request gpios: %d\n", __func__, ret);
477 return;
478 }
479
480 /* Power up fec phy */
481 gpio_set_value(TX28_FEC_PHY_POWER, 1);
482 msleep(26); /* 25ms according to data sheet */
483
484 /* Mode strap pins */
485 gpio_set_value(ENET0_RX_EN__GPIO_4_2, 1);
486 gpio_set_value(ENET0_RXD0__GPIO_4_3, 1);
487 gpio_set_value(ENET0_RXD1__GPIO_4_4, 1);
488
489 udelay(100); /* minimum assertion time for nRST */
490
491 /* Deasserting FEC PHY RESET */
492 gpio_set_value(TX28_FEC_PHY_RESET, 1);
493
494 pinctrl_put(pctl);
495}
496
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800497static void __init cfa10049_init(void)
498{
499 enable_clk_enet_out();
500 update_fec_mac_prop(OUI_CRYSTALFONTZ);
Maxime Ripard4a38a852013-03-05 16:13:35 +0100501
502 mxsfb_pdata.mode_list = cfa10049_video_modes;
503 mxsfb_pdata.mode_count = ARRAY_SIZE(cfa10049_video_modes);
504 mxsfb_pdata.default_bpp = 32;
505 mxsfb_pdata.ld_intf_width = STMLCDIF_18BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100506 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT;
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800507}
508
Maxime Riparde0f7d902013-01-26 13:40:37 +0800509static void __init cfa10037_init(void)
510{
511 enable_clk_enet_out();
512 update_fec_mac_prop(OUI_CRYSTALFONTZ);
513}
514
Julien Boibessota957fdc2012-10-18 11:50:26 +0200515static void __init apf28_init(void)
516{
517 enable_clk_enet_out();
Gwenhael Goavec-Meroua4dabca2012-11-02 19:01:48 +0100518
519 mxsfb_pdata.mode_list = apf28dev_video_modes;
520 mxsfb_pdata.mode_count = ARRAY_SIZE(apf28dev_video_modes);
521 mxsfb_pdata.default_bpp = 16;
522 mxsfb_pdata.ld_intf_width = STMLCDIF_16BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100523 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
524 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Julien Boibessota957fdc2012-10-18 11:50:26 +0200525}
526
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800527static void __init mxs_machine_init(void)
528{
529 if (of_machine_is_compatible("fsl,imx28-evk"))
530 imx28_evk_init();
Shawn Guoab2815c2012-06-25 21:21:46 +0800531 else if (of_machine_is_compatible("fsl,imx23-evk"))
532 imx23_evk_init();
Marek Vasut8fa62e12012-07-07 21:21:38 +0800533 else if (of_machine_is_compatible("denx,m28evk"))
534 m28evk_init();
Shawn Guo3143bbb2012-07-07 23:12:03 +0800535 else if (of_machine_is_compatible("bluegiga,apx4devkit"))
536 apx4devkit_init();
Maxime Riparde0f7d902013-01-26 13:40:37 +0800537 else if (of_machine_is_compatible("crystalfontz,cfa10037"))
538 cfa10037_init();
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800539 else if (of_machine_is_compatible("crystalfontz,cfa10049"))
540 cfa10049_init();
Julien Boibessota957fdc2012-10-18 11:50:26 +0200541 else if (of_machine_is_compatible("armadeus,imx28-apf28"))
542 apf28_init();
Marek Vasut160d5f22012-11-18 22:08:29 +0100543 else if (of_machine_is_compatible("schulercontrol,imx28-sps1"))
544 sc_sps1_init();
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800545
546 of_platform_populate(NULL, of_default_bus_match_table,
Shawn Guoab2815c2012-06-25 21:21:46 +0800547 mxs_auxdata_lookup, NULL);
Shawn Guo2c7c2c12012-07-13 14:15:34 +0800548
549 if (of_machine_is_compatible("karo,tx28"))
550 tx28_post_init();
Shawn Guo44ffb782012-08-06 22:00:45 +0800551
552 if (of_machine_is_compatible("fsl,imx28-evk"))
553 imx28_evk_post_init();
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800554}
555
Shawn Guo974a9af2013-03-29 09:45:31 +0800556#define MX23_CLKCTRL_RESET_OFFSET 0x120
557#define MX28_CLKCTRL_RESET_OFFSET 0x1e0
558#define MXS_CLKCTRL_RESET_CHIP (1 << 1)
559
560/*
561 * Reset the system. It is called by machine_restart().
562 */
563static void mxs_restart(char mode, const char *cmd)
564{
565 struct device_node *np;
566 void __iomem *reset_addr;
567
568 np = of_find_compatible_node(NULL, NULL, "fsl,clkctrl");
569 reset_addr = of_iomap(np, 0);
570 if (!reset_addr)
571 goto soft;
572
573 if (of_device_is_compatible(np, "fsl,imx23-clkctrl"))
574 reset_addr += MX23_CLKCTRL_RESET_OFFSET;
575 else
576 reset_addr += MX28_CLKCTRL_RESET_OFFSET;
577
578 /* reset the chip */
579 __mxs_setl(MXS_CLKCTRL_RESET_CHIP, reset_addr);
580
581 pr_err("Failed to assert the chip reset\n");
582
583 /* Delay to allow the serial port to show the message */
584 mdelay(50);
585
586soft:
587 /* We'll take a jump through zero as a poor second */
588 soft_restart(0);
589}
590
Shawn Guo39490ab2013-03-29 14:04:07 +0800591static void __init mxs_timer_init(void)
592{
593 if (of_machine_is_compatible("fsl,imx23"))
594 mx23_clocks_init();
595 else
596 mx28_clocks_init();
597 clocksource_of_init();
598}
599
600static const char *mxs_dt_compat[] __initdata = {
601 "fsl,imx28",
Shawn Guo2954ff32012-05-04 21:33:42 +0800602 "fsl,imx23",
603 NULL,
604};
605
Shawn Guo39490ab2013-03-29 14:04:07 +0800606DT_MACHINE_START(MXS, "Freescale MXS (Device Tree)")
Shawn Guo1f629562013-03-29 13:07:34 +0800607 .map_io = debug_ll_io_init,
Shawn Guo6a8e95b2013-03-25 21:34:51 +0800608 .init_irq = irqchip_init,
Shawn Guo4e0a1b82012-08-20 10:14:56 +0800609 .handle_irq = icoll_handle_irq,
Shawn Guo39490ab2013-03-29 14:04:07 +0800610 .init_time = mxs_timer_init,
Shawn Guo2954ff32012-05-04 21:33:42 +0800611 .init_machine = mxs_machine_init,
Shawn Guo45680992013-03-29 14:41:27 +0800612 .init_late = mxs_pm_init,
Shawn Guo39490ab2013-03-29 14:04:07 +0800613 .dt_compat = mxs_dt_compat,
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800614 .restart = mxs_restart,
615MACHINE_END