blob: 16870bf853b8f4e748bed10affea8f7a478f0797 [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
35/* MXS DIGCTL SAIF CLKMUX */
36#define MXS_DIGCTL_SAIF_CLKMUX_DIRECT 0x0
37#define MXS_DIGCTL_SAIF_CLKMUX_CROSSINPUT 0x1
38#define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0 0x2
39#define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR1 0x3
40
41#define MXS_GPIO_NR(bank, nr) ((bank) * 32 + (nr))
42
43#define MXS_SET_ADDR 0x4
44#define MXS_CLR_ADDR 0x8
45#define MXS_TOG_ADDR 0xc
46
47static inline void __mxs_setl(u32 mask, void __iomem *reg)
48{
49 __raw_writel(mask, reg + MXS_SET_ADDR);
50}
51
52static inline void __mxs_clrl(u32 mask, void __iomem *reg)
53{
54 __raw_writel(mask, reg + MXS_CLR_ADDR);
55}
56
57static inline void __mxs_togl(u32 mask, void __iomem *reg)
58{
59 __raw_writel(mask, reg + MXS_TOG_ADDR);
60}
Dong Aishengbc3a59c2012-03-31 21:26:57 +080061
Shawn Guoab2815c2012-06-25 21:21:46 +080062static struct fb_videomode mx23evk_video_modes[] = {
63 {
64 .name = "Samsung-LMS430HF02",
65 .refresh = 60,
66 .xres = 480,
67 .yres = 272,
68 .pixclock = 108096, /* picosecond (9.2 MHz) */
69 .left_margin = 15,
70 .right_margin = 8,
71 .upper_margin = 12,
72 .lower_margin = 4,
73 .hsync_len = 1,
74 .vsync_len = 1,
Shawn Guoab2815c2012-06-25 21:21:46 +080075 },
76};
77
78static struct fb_videomode mx28evk_video_modes[] = {
79 {
80 .name = "Seiko-43WVF1G",
81 .refresh = 60,
82 .xres = 800,
83 .yres = 480,
84 .pixclock = 29851, /* picosecond (33.5 MHz) */
85 .left_margin = 89,
86 .right_margin = 164,
87 .upper_margin = 23,
88 .lower_margin = 10,
89 .hsync_len = 10,
90 .vsync_len = 10,
Shawn Guoab2815c2012-06-25 21:21:46 +080091 },
92};
93
Marek Vasut8fa62e12012-07-07 21:21:38 +080094static struct fb_videomode m28evk_video_modes[] = {
95 {
96 .name = "Ampire AM-800480R2TMQW-T01H",
97 .refresh = 60,
98 .xres = 800,
99 .yres = 480,
100 .pixclock = 30066, /* picosecond (33.26 MHz) */
101 .left_margin = 0,
102 .right_margin = 256,
103 .upper_margin = 0,
104 .lower_margin = 45,
105 .hsync_len = 1,
106 .vsync_len = 1,
Marek Vasut8fa62e12012-07-07 21:21:38 +0800107 },
108};
109
Lauri Hintsalad8bb8232012-07-10 10:08:08 +0300110static struct fb_videomode apx4devkit_video_modes[] = {
111 {
112 .name = "HannStar PJ70112A",
113 .refresh = 60,
114 .xres = 800,
115 .yres = 480,
116 .pixclock = 33333, /* picosecond (30.00 MHz) */
117 .left_margin = 88,
118 .right_margin = 40,
119 .upper_margin = 32,
120 .lower_margin = 13,
121 .hsync_len = 48,
122 .vsync_len = 3,
Marek Vasut6a150752013-03-18 19:24:02 +0100123 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Lauri Hintsalad8bb8232012-07-10 10:08:08 +0300124 },
125};
126
Gwenhael Goavec-Meroua4dabca2012-11-02 19:01:48 +0100127static struct fb_videomode apf28dev_video_modes[] = {
128 {
129 .name = "LW700",
130 .refresh = 60,
131 .xres = 800,
132 .yres = 480,
133 .pixclock = 30303, /* picosecond */
134 .left_margin = 96,
135 .right_margin = 96, /* at least 3 & 1 */
136 .upper_margin = 0x14,
137 .lower_margin = 0x15,
138 .hsync_len = 64,
139 .vsync_len = 4,
Marek Vasut6a150752013-03-18 19:24:02 +0100140 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Gwenhael Goavec-Meroua4dabca2012-11-02 19:01:48 +0100141 },
142};
143
Maxime Ripard1fe42742013-01-25 09:54:07 +0100144static struct fb_videomode cfa10049_video_modes[] = {
145 {
146 .name = "Himax HX8357-B",
147 .refresh = 60,
148 .xres = 320,
149 .yres = 480,
150 .pixclock = 108506, /* picosecond (9.216 MHz) */
151 .left_margin = 2,
152 .right_margin = 2,
153 .upper_margin = 2,
154 .lower_margin = 2,
155 .hsync_len = 15,
156 .vsync_len = 15,
Maxime Ripard1fe42742013-01-25 09:54:07 +0100157 },
158};
159
Shawn Guoab2815c2012-06-25 21:21:46 +0800160static struct mxsfb_platform_data mxsfb_pdata __initdata;
161
Shawn Guo44ffb782012-08-06 22:00:45 +0800162/*
163 * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers
164 */
165#define MX28EVK_FLEXCAN_SWITCH MXS_GPIO_NR(2, 13)
166
167static int flexcan0_en, flexcan1_en;
168
169static void mx28evk_flexcan_switch(void)
170{
171 if (flexcan0_en || flexcan1_en)
172 gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1);
173 else
174 gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0);
175}
176
177static void mx28evk_flexcan0_switch(int enable)
178{
179 flexcan0_en = enable;
180 mx28evk_flexcan_switch();
181}
182
183static void mx28evk_flexcan1_switch(int enable)
184{
185 flexcan1_en = enable;
186 mx28evk_flexcan_switch();
187}
188
189static struct flexcan_platform_data flexcan_pdata[2];
190
Shawn Guoab2815c2012-06-25 21:21:46 +0800191static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = {
192 OF_DEV_AUXDATA("fsl,imx23-lcdif", 0x80030000, NULL, &mxsfb_pdata),
193 OF_DEV_AUXDATA("fsl,imx28-lcdif", 0x80030000, NULL, &mxsfb_pdata),
Shawn Guo44ffb782012-08-06 22:00:45 +0800194 OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80032000, NULL, &flexcan_pdata[0]),
195 OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80034000, NULL, &flexcan_pdata[1]),
Shawn Guoab2815c2012-06-25 21:21:46 +0800196 { /* sentinel */ }
197};
198
Shawn Guo1bff2d72013-03-29 13:27:55 +0800199#define OCOTP_WORD_OFFSET 0x20
200#define OCOTP_WORD_COUNT 0x20
201
202#define BM_OCOTP_CTRL_BUSY (1 << 8)
203#define BM_OCOTP_CTRL_ERROR (1 << 9)
204#define BM_OCOTP_CTRL_RD_BANK_OPEN (1 << 12)
205
206static DEFINE_MUTEX(ocotp_mutex);
207static u32 ocotp_words[OCOTP_WORD_COUNT];
208
209static const u32 *mxs_get_ocotp(void)
210{
211 struct device_node *np;
212 void __iomem *ocotp_base;
213 int timeout = 0x400;
214 size_t i;
215 static int once;
216
217 if (once)
218 return ocotp_words;
219
220 np = of_find_compatible_node(NULL, NULL, "fsl,ocotp");
221 ocotp_base = of_iomap(np, 0);
222 WARN_ON(!ocotp_base);
223
224 mutex_lock(&ocotp_mutex);
225
226 /*
227 * clk_enable(hbus_clk) for ocotp can be skipped
228 * as it must be on when system is running.
229 */
230
231 /* try to clear ERROR bit */
232 __mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base);
233
234 /* check both BUSY and ERROR cleared */
235 while ((__raw_readl(ocotp_base) &
236 (BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout)
237 cpu_relax();
238
239 if (unlikely(!timeout))
240 goto error_unlock;
241
242 /* open OCOTP banks for read */
243 __mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
244
245 /* approximately wait 32 hclk cycles */
246 udelay(1);
247
248 /* poll BUSY bit becoming cleared */
249 timeout = 0x400;
250 while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
251 cpu_relax();
252
253 if (unlikely(!timeout))
254 goto error_unlock;
255
256 for (i = 0; i < OCOTP_WORD_COUNT; i++)
257 ocotp_words[i] = __raw_readl(ocotp_base + OCOTP_WORD_OFFSET +
258 i * 0x10);
259
260 /* close banks for power saving */
261 __mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
262
263 once = 1;
264
265 mutex_unlock(&ocotp_mutex);
266
267 return ocotp_words;
268
269error_unlock:
270 mutex_unlock(&ocotp_mutex);
271 pr_err("%s: timeout in reading OCOTP\n", __func__);
272 return NULL;
273}
274
Shawn Guo5653acc2012-06-19 22:38:14 +0800275enum mac_oui {
276 OUI_FSL,
277 OUI_DENX,
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800278 OUI_CRYSTALFONTZ,
Shawn Guo5653acc2012-06-19 22:38:14 +0800279};
280
281static void __init update_fec_mac_prop(enum mac_oui oui)
282{
283 struct device_node *np, *from = NULL;
Shawn Guofa7c8652012-07-13 14:13:55 +0800284 struct property *newmac;
Shawn Guo5653acc2012-06-19 22:38:14 +0800285 const u32 *ocotp = mxs_get_ocotp();
286 u8 *macaddr;
287 u32 val;
288 int i;
289
290 for (i = 0; i < 2; i++) {
291 np = of_find_compatible_node(from, NULL, "fsl,imx28-fec");
292 if (!np)
293 return;
Marek Vasut16d47702012-09-25 13:32:18 +0200294
Shawn Guo5653acc2012-06-19 22:38:14 +0800295 from = np;
296
Marek Vasut16d47702012-09-25 13:32:18 +0200297 if (of_get_property(np, "local-mac-address", NULL))
298 continue;
299
Shawn Guo5653acc2012-06-19 22:38:14 +0800300 newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
301 if (!newmac)
302 return;
303 newmac->value = newmac + 1;
304 newmac->length = 6;
305
306 newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
307 if (!newmac->name) {
308 kfree(newmac);
309 return;
310 }
311
312 /*
313 * OCOTP only stores the last 4 octets for each mac address,
314 * so hard-code OUI here.
315 */
316 macaddr = newmac->value;
317 switch (oui) {
318 case OUI_FSL:
319 macaddr[0] = 0x00;
320 macaddr[1] = 0x04;
321 macaddr[2] = 0x9f;
322 break;
323 case OUI_DENX:
324 macaddr[0] = 0xc0;
325 macaddr[1] = 0xe5;
326 macaddr[2] = 0x4e;
327 break;
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800328 case OUI_CRYSTALFONTZ:
329 macaddr[0] = 0x58;
330 macaddr[1] = 0xb9;
331 macaddr[2] = 0xe1;
332 break;
Shawn Guo5653acc2012-06-19 22:38:14 +0800333 }
334 val = ocotp[i];
335 macaddr[3] = (val >> 16) & 0xff;
336 macaddr[4] = (val >> 8) & 0xff;
337 macaddr[5] = (val >> 0) & 0xff;
338
Nathan Fontenot79d1c712012-10-02 16:58:46 +0000339 of_update_property(np, newmac);
Shawn Guo5653acc2012-06-19 22:38:14 +0800340 }
341}
342
Shawn Guoab2815c2012-06-25 21:21:46 +0800343static void __init imx23_evk_init(void)
344{
345 mxsfb_pdata.mode_list = mx23evk_video_modes;
346 mxsfb_pdata.mode_count = ARRAY_SIZE(mx23evk_video_modes);
347 mxsfb_pdata.default_bpp = 32;
348 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100349 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
350 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Shawn Guoab2815c2012-06-25 21:21:46 +0800351}
352
Marek Vasut8fa62e12012-07-07 21:21:38 +0800353static inline void enable_clk_enet_out(void)
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800354{
Marek Vasut8fa62e12012-07-07 21:21:38 +0800355 struct clk *clk = clk_get_sys("enet_out", NULL);
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800356
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800357 if (!IS_ERR(clk))
358 clk_prepare_enable(clk);
Marek Vasut8fa62e12012-07-07 21:21:38 +0800359}
Shawn Guo5653acc2012-06-19 22:38:14 +0800360
Marek Vasut8fa62e12012-07-07 21:21:38 +0800361static void __init imx28_evk_init(void)
362{
363 enable_clk_enet_out();
Shawn Guo5653acc2012-06-19 22:38:14 +0800364 update_fec_mac_prop(OUI_FSL);
Shawn Guoab2815c2012-06-25 21:21:46 +0800365
366 mxsfb_pdata.mode_list = mx28evk_video_modes;
367 mxsfb_pdata.mode_count = ARRAY_SIZE(mx28evk_video_modes);
368 mxsfb_pdata.default_bpp = 32;
369 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100370 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
371 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Dong Aishenge3173172012-08-01 11:20:16 +0800372
373 mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0);
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800374}
375
Shawn Guo44ffb782012-08-06 22:00:45 +0800376static void __init imx28_evk_post_init(void)
377{
378 if (!gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT,
379 "flexcan-switch")) {
380 flexcan_pdata[0].transceiver_switch = mx28evk_flexcan0_switch;
381 flexcan_pdata[1].transceiver_switch = mx28evk_flexcan1_switch;
382 }
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800383}
384
Marek Vasut8fa62e12012-07-07 21:21:38 +0800385static void __init m28evk_init(void)
386{
Marek Vasut8fa62e12012-07-07 21:21:38 +0800387 mxsfb_pdata.mode_list = m28evk_video_modes;
388 mxsfb_pdata.mode_count = ARRAY_SIZE(m28evk_video_modes);
389 mxsfb_pdata.default_bpp = 16;
390 mxsfb_pdata.ld_intf_width = STMLCDIF_18BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100391 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT;
Marek Vasut8fa62e12012-07-07 21:21:38 +0800392}
393
Marek Vasut160d5f22012-11-18 22:08:29 +0100394static void __init sc_sps1_init(void)
395{
396 enable_clk_enet_out();
397}
398
Shawn Guo3143bbb2012-07-07 23:12:03 +0800399static int apx4devkit_phy_fixup(struct phy_device *phy)
400{
401 phy->dev_flags |= MICREL_PHY_50MHZ_CLK;
402 return 0;
403}
404
405static void __init apx4devkit_init(void)
406{
407 enable_clk_enet_out();
408
409 if (IS_BUILTIN(CONFIG_PHYLIB))
Marek Vasut510d5732012-09-23 16:58:50 +0000410 phy_register_fixup_for_uid(PHY_ID_KSZ8051, MICREL_PHY_ID_MASK,
Shawn Guo3143bbb2012-07-07 23:12:03 +0800411 apx4devkit_phy_fixup);
Lauri Hintsalad8bb8232012-07-10 10:08:08 +0300412
413 mxsfb_pdata.mode_list = apx4devkit_video_modes;
414 mxsfb_pdata.mode_count = ARRAY_SIZE(apx4devkit_video_modes);
415 mxsfb_pdata.default_bpp = 32;
416 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100417 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
418 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Shawn Guo3143bbb2012-07-07 23:12:03 +0800419}
420
Shawn Guo2c7c2c12012-07-13 14:15:34 +0800421#define ENET0_MDC__GPIO_4_0 MXS_GPIO_NR(4, 0)
422#define ENET0_MDIO__GPIO_4_1 MXS_GPIO_NR(4, 1)
423#define ENET0_RX_EN__GPIO_4_2 MXS_GPIO_NR(4, 2)
424#define ENET0_RXD0__GPIO_4_3 MXS_GPIO_NR(4, 3)
425#define ENET0_RXD1__GPIO_4_4 MXS_GPIO_NR(4, 4)
426#define ENET0_TX_EN__GPIO_4_6 MXS_GPIO_NR(4, 6)
427#define ENET0_TXD0__GPIO_4_7 MXS_GPIO_NR(4, 7)
428#define ENET0_TXD1__GPIO_4_8 MXS_GPIO_NR(4, 8)
429#define ENET_CLK__GPIO_4_16 MXS_GPIO_NR(4, 16)
430
431#define TX28_FEC_PHY_POWER MXS_GPIO_NR(3, 29)
432#define TX28_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
433#define TX28_FEC_nINT MXS_GPIO_NR(4, 5)
434
435static const struct gpio tx28_gpios[] __initconst = {
436 { ENET0_MDC__GPIO_4_0, GPIOF_OUT_INIT_LOW, "GPIO_4_0" },
437 { ENET0_MDIO__GPIO_4_1, GPIOF_OUT_INIT_LOW, "GPIO_4_1" },
438 { ENET0_RX_EN__GPIO_4_2, GPIOF_OUT_INIT_LOW, "GPIO_4_2" },
439 { ENET0_RXD0__GPIO_4_3, GPIOF_OUT_INIT_LOW, "GPIO_4_3" },
440 { ENET0_RXD1__GPIO_4_4, GPIOF_OUT_INIT_LOW, "GPIO_4_4" },
441 { ENET0_TX_EN__GPIO_4_6, GPIOF_OUT_INIT_LOW, "GPIO_4_6" },
442 { ENET0_TXD0__GPIO_4_7, GPIOF_OUT_INIT_LOW, "GPIO_4_7" },
443 { ENET0_TXD1__GPIO_4_8, GPIOF_OUT_INIT_LOW, "GPIO_4_8" },
444 { ENET_CLK__GPIO_4_16, GPIOF_OUT_INIT_LOW, "GPIO_4_16" },
445 { TX28_FEC_PHY_POWER, GPIOF_OUT_INIT_LOW, "fec-phy-power" },
446 { TX28_FEC_PHY_RESET, GPIOF_OUT_INIT_LOW, "fec-phy-reset" },
447 { TX28_FEC_nINT, GPIOF_DIR_IN, "fec-int" },
448};
449
450static void __init tx28_post_init(void)
451{
452 struct device_node *np;
453 struct platform_device *pdev;
454 struct pinctrl *pctl;
455 int ret;
456
457 enable_clk_enet_out();
458
459 np = of_find_compatible_node(NULL, NULL, "fsl,imx28-fec");
460 pdev = of_find_device_by_node(np);
461 if (!pdev) {
462 pr_err("%s: failed to find fec device\n", __func__);
463 return;
464 }
465
466 pctl = pinctrl_get_select(&pdev->dev, "gpio_mode");
467 if (IS_ERR(pctl)) {
468 pr_err("%s: failed to get pinctrl state\n", __func__);
469 return;
470 }
471
472 ret = gpio_request_array(tx28_gpios, ARRAY_SIZE(tx28_gpios));
473 if (ret) {
474 pr_err("%s: failed to request gpios: %d\n", __func__, ret);
475 return;
476 }
477
478 /* Power up fec phy */
479 gpio_set_value(TX28_FEC_PHY_POWER, 1);
480 msleep(26); /* 25ms according to data sheet */
481
482 /* Mode strap pins */
483 gpio_set_value(ENET0_RX_EN__GPIO_4_2, 1);
484 gpio_set_value(ENET0_RXD0__GPIO_4_3, 1);
485 gpio_set_value(ENET0_RXD1__GPIO_4_4, 1);
486
487 udelay(100); /* minimum assertion time for nRST */
488
489 /* Deasserting FEC PHY RESET */
490 gpio_set_value(TX28_FEC_PHY_RESET, 1);
491
492 pinctrl_put(pctl);
493}
494
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800495static void __init cfa10049_init(void)
496{
497 enable_clk_enet_out();
498 update_fec_mac_prop(OUI_CRYSTALFONTZ);
Maxime Ripard4a38a852013-03-05 16:13:35 +0100499
500 mxsfb_pdata.mode_list = cfa10049_video_modes;
501 mxsfb_pdata.mode_count = ARRAY_SIZE(cfa10049_video_modes);
502 mxsfb_pdata.default_bpp = 32;
503 mxsfb_pdata.ld_intf_width = STMLCDIF_18BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100504 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT;
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800505}
506
Maxime Riparde0f7d902013-01-26 13:40:37 +0800507static void __init cfa10037_init(void)
508{
509 enable_clk_enet_out();
510 update_fec_mac_prop(OUI_CRYSTALFONTZ);
511}
512
Julien Boibessota957fdc2012-10-18 11:50:26 +0200513static void __init apf28_init(void)
514{
515 enable_clk_enet_out();
Gwenhael Goavec-Meroua4dabca2012-11-02 19:01:48 +0100516
517 mxsfb_pdata.mode_list = apf28dev_video_modes;
518 mxsfb_pdata.mode_count = ARRAY_SIZE(apf28dev_video_modes);
519 mxsfb_pdata.default_bpp = 16;
520 mxsfb_pdata.ld_intf_width = STMLCDIF_16BIT;
Marek Vasut6a150752013-03-18 19:24:02 +0100521 mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT |
522 MXSFB_SYNC_DOTCLK_FAILING_ACT;
Julien Boibessota957fdc2012-10-18 11:50:26 +0200523}
524
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800525static void __init mxs_machine_init(void)
526{
527 if (of_machine_is_compatible("fsl,imx28-evk"))
528 imx28_evk_init();
Shawn Guoab2815c2012-06-25 21:21:46 +0800529 else if (of_machine_is_compatible("fsl,imx23-evk"))
530 imx23_evk_init();
Marek Vasut8fa62e12012-07-07 21:21:38 +0800531 else if (of_machine_is_compatible("denx,m28evk"))
532 m28evk_init();
Shawn Guo3143bbb2012-07-07 23:12:03 +0800533 else if (of_machine_is_compatible("bluegiga,apx4devkit"))
534 apx4devkit_init();
Maxime Riparde0f7d902013-01-26 13:40:37 +0800535 else if (of_machine_is_compatible("crystalfontz,cfa10037"))
536 cfa10037_init();
Maxime Ripard8eec4b32012-10-07 10:36:28 +0800537 else if (of_machine_is_compatible("crystalfontz,cfa10049"))
538 cfa10049_init();
Julien Boibessota957fdc2012-10-18 11:50:26 +0200539 else if (of_machine_is_compatible("armadeus,imx28-apf28"))
540 apf28_init();
Marek Vasut160d5f22012-11-18 22:08:29 +0100541 else if (of_machine_is_compatible("schulercontrol,imx28-sps1"))
542 sc_sps1_init();
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800543
544 of_platform_populate(NULL, of_default_bus_match_table,
Shawn Guoab2815c2012-06-25 21:21:46 +0800545 mxs_auxdata_lookup, NULL);
Shawn Guo2c7c2c12012-07-13 14:15:34 +0800546
547 if (of_machine_is_compatible("karo,tx28"))
548 tx28_post_init();
Shawn Guo44ffb782012-08-06 22:00:45 +0800549
550 if (of_machine_is_compatible("fsl,imx28-evk"))
551 imx28_evk_post_init();
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800552}
553
Shawn Guo974a9af2013-03-29 09:45:31 +0800554#define MX23_CLKCTRL_RESET_OFFSET 0x120
555#define MX28_CLKCTRL_RESET_OFFSET 0x1e0
556#define MXS_CLKCTRL_RESET_CHIP (1 << 1)
557
558/*
559 * Reset the system. It is called by machine_restart().
560 */
561static void mxs_restart(char mode, const char *cmd)
562{
563 struct device_node *np;
564 void __iomem *reset_addr;
565
566 np = of_find_compatible_node(NULL, NULL, "fsl,clkctrl");
567 reset_addr = of_iomap(np, 0);
568 if (!reset_addr)
569 goto soft;
570
571 if (of_device_is_compatible(np, "fsl,imx23-clkctrl"))
572 reset_addr += MX23_CLKCTRL_RESET_OFFSET;
573 else
574 reset_addr += MX28_CLKCTRL_RESET_OFFSET;
575
576 /* reset the chip */
577 __mxs_setl(MXS_CLKCTRL_RESET_CHIP, reset_addr);
578
579 pr_err("Failed to assert the chip reset\n");
580
581 /* Delay to allow the serial port to show the message */
582 mdelay(50);
583
584soft:
585 /* We'll take a jump through zero as a poor second */
586 soft_restart(0);
587}
588
Shawn Guo39490ab2013-03-29 14:04:07 +0800589static void __init mxs_timer_init(void)
590{
591 if (of_machine_is_compatible("fsl,imx23"))
592 mx23_clocks_init();
593 else
594 mx28_clocks_init();
595 clocksource_of_init();
596}
597
598static const char *mxs_dt_compat[] __initdata = {
599 "fsl,imx28",
Shawn Guo2954ff32012-05-04 21:33:42 +0800600 "fsl,imx23",
601 NULL,
602};
603
Shawn Guo39490ab2013-03-29 14:04:07 +0800604DT_MACHINE_START(MXS, "Freescale MXS (Device Tree)")
Shawn Guo1f629562013-03-29 13:07:34 +0800605 .map_io = debug_ll_io_init,
Shawn Guo6a8e95b2013-03-25 21:34:51 +0800606 .init_irq = irqchip_init,
Shawn Guo4e0a1b82012-08-20 10:14:56 +0800607 .handle_irq = icoll_handle_irq,
Shawn Guo39490ab2013-03-29 14:04:07 +0800608 .init_time = mxs_timer_init,
Shawn Guo2954ff32012-05-04 21:33:42 +0800609 .init_machine = mxs_machine_init,
Shawn Guo39490ab2013-03-29 14:04:07 +0800610 .dt_compat = mxs_dt_compat,
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800611 .restart = mxs_restart,
612MACHINE_END