2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright 2012 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/can/platform/flexcan.h>
16 #include <linux/delay.h>
17 #include <linux/err.h>
18 #include <linux/gpio.h>
19 #include <linux/init.h>
20 #include <linux/micrel_phy.h>
21 #include <linux/mxsfb.h>
22 #include <linux/of_platform.h>
23 #include <linux/phy.h>
24 #include <linux/pinctrl/consumer.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/time.h>
27 #include <mach/common.h>
28 #include <mach/digctl.h>
31 static struct fb_videomode mx23evk_video_modes
[] = {
33 .name
= "Samsung-LMS430HF02",
37 .pixclock
= 108096, /* picosecond (9.2 MHz) */
44 .sync
= FB_SYNC_DATA_ENABLE_HIGH_ACT
|
45 FB_SYNC_DOTCLK_FAILING_ACT
,
49 static struct fb_videomode mx28evk_video_modes
[] = {
51 .name
= "Seiko-43WVF1G",
55 .pixclock
= 29851, /* picosecond (33.5 MHz) */
62 .sync
= FB_SYNC_DATA_ENABLE_HIGH_ACT
|
63 FB_SYNC_DOTCLK_FAILING_ACT
,
67 static struct fb_videomode m28evk_video_modes
[] = {
69 .name
= "Ampire AM-800480R2TMQW-T01H",
73 .pixclock
= 30066, /* picosecond (33.26 MHz) */
80 .sync
= FB_SYNC_DATA_ENABLE_HIGH_ACT
,
84 static struct fb_videomode apx4devkit_video_modes
[] = {
86 .name
= "HannStar PJ70112A",
90 .pixclock
= 33333, /* picosecond (30.00 MHz) */
97 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
|
98 FB_SYNC_DATA_ENABLE_HIGH_ACT
|
99 FB_SYNC_DOTCLK_FAILING_ACT
,
103 static struct fb_videomode apf28dev_video_modes
[] = {
109 .pixclock
= 30303, /* picosecond */
111 .right_margin
= 96, /* at least 3 & 1 */
112 .upper_margin
= 0x14,
113 .lower_margin
= 0x15,
116 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
|
117 FB_SYNC_DATA_ENABLE_HIGH_ACT
|
118 FB_SYNC_DOTCLK_FAILING_ACT
,
122 static struct mxsfb_platform_data mxsfb_pdata __initdata
;
125 * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers
127 #define MX28EVK_FLEXCAN_SWITCH MXS_GPIO_NR(2, 13)
129 static int flexcan0_en
, flexcan1_en
;
131 static void mx28evk_flexcan_switch(void)
133 if (flexcan0_en
|| flexcan1_en
)
134 gpio_set_value(MX28EVK_FLEXCAN_SWITCH
, 1);
136 gpio_set_value(MX28EVK_FLEXCAN_SWITCH
, 0);
139 static void mx28evk_flexcan0_switch(int enable
)
141 flexcan0_en
= enable
;
142 mx28evk_flexcan_switch();
145 static void mx28evk_flexcan1_switch(int enable
)
147 flexcan1_en
= enable
;
148 mx28evk_flexcan_switch();
151 static struct flexcan_platform_data flexcan_pdata
[2];
153 static struct of_dev_auxdata mxs_auxdata_lookup
[] __initdata
= {
154 OF_DEV_AUXDATA("fsl,imx23-lcdif", 0x80030000, NULL
, &mxsfb_pdata
),
155 OF_DEV_AUXDATA("fsl,imx28-lcdif", 0x80030000, NULL
, &mxsfb_pdata
),
156 OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80032000, NULL
, &flexcan_pdata
[0]),
157 OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80034000, NULL
, &flexcan_pdata
[1]),
161 static void __init
imx23_timer_init(void)
166 static struct sys_timer imx23_timer
= {
167 .init
= imx23_timer_init
,
170 static void __init
imx28_timer_init(void)
175 static struct sys_timer imx28_timer
= {
176 .init
= imx28_timer_init
,
185 static void __init
update_fec_mac_prop(enum mac_oui oui
)
187 struct device_node
*np
, *from
= NULL
;
188 struct property
*newmac
;
189 const u32
*ocotp
= mxs_get_ocotp();
194 for (i
= 0; i
< 2; i
++) {
195 np
= of_find_compatible_node(from
, NULL
, "fsl,imx28-fec");
201 if (of_get_property(np
, "local-mac-address", NULL
))
204 newmac
= kzalloc(sizeof(*newmac
) + 6, GFP_KERNEL
);
207 newmac
->value
= newmac
+ 1;
210 newmac
->name
= kstrdup("local-mac-address", GFP_KERNEL
);
217 * OCOTP only stores the last 4 octets for each mac address,
218 * so hard-code OUI here.
220 macaddr
= newmac
->value
;
232 case OUI_CRYSTALFONTZ
:
239 macaddr
[3] = (val
>> 16) & 0xff;
240 macaddr
[4] = (val
>> 8) & 0xff;
241 macaddr
[5] = (val
>> 0) & 0xff;
243 of_update_property(np
, newmac
);
247 static void __init
imx23_evk_init(void)
249 mxsfb_pdata
.mode_list
= mx23evk_video_modes
;
250 mxsfb_pdata
.mode_count
= ARRAY_SIZE(mx23evk_video_modes
);
251 mxsfb_pdata
.default_bpp
= 32;
252 mxsfb_pdata
.ld_intf_width
= STMLCDIF_24BIT
;
255 static inline void enable_clk_enet_out(void)
257 struct clk
*clk
= clk_get_sys("enet_out", NULL
);
260 clk_prepare_enable(clk
);
263 static void __init
imx28_evk_init(void)
265 enable_clk_enet_out();
266 update_fec_mac_prop(OUI_FSL
);
268 mxsfb_pdata
.mode_list
= mx28evk_video_modes
;
269 mxsfb_pdata
.mode_count
= ARRAY_SIZE(mx28evk_video_modes
);
270 mxsfb_pdata
.default_bpp
= 32;
271 mxsfb_pdata
.ld_intf_width
= STMLCDIF_24BIT
;
273 mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0
);
276 static void __init
imx28_evk_post_init(void)
278 if (!gpio_request_one(MX28EVK_FLEXCAN_SWITCH
, GPIOF_DIR_OUT
,
280 flexcan_pdata
[0].transceiver_switch
= mx28evk_flexcan0_switch
;
281 flexcan_pdata
[1].transceiver_switch
= mx28evk_flexcan1_switch
;
285 static void __init
m28evk_init(void)
287 mxsfb_pdata
.mode_list
= m28evk_video_modes
;
288 mxsfb_pdata
.mode_count
= ARRAY_SIZE(m28evk_video_modes
);
289 mxsfb_pdata
.default_bpp
= 16;
290 mxsfb_pdata
.ld_intf_width
= STMLCDIF_18BIT
;
293 static void __init
sc_sps1_init(void)
295 enable_clk_enet_out();
298 static int apx4devkit_phy_fixup(struct phy_device
*phy
)
300 phy
->dev_flags
|= MICREL_PHY_50MHZ_CLK
;
304 static void __init
apx4devkit_init(void)
306 enable_clk_enet_out();
308 if (IS_BUILTIN(CONFIG_PHYLIB
))
309 phy_register_fixup_for_uid(PHY_ID_KSZ8051
, MICREL_PHY_ID_MASK
,
310 apx4devkit_phy_fixup
);
312 mxsfb_pdata
.mode_list
= apx4devkit_video_modes
;
313 mxsfb_pdata
.mode_count
= ARRAY_SIZE(apx4devkit_video_modes
);
314 mxsfb_pdata
.default_bpp
= 32;
315 mxsfb_pdata
.ld_intf_width
= STMLCDIF_24BIT
;
318 #define ENET0_MDC__GPIO_4_0 MXS_GPIO_NR(4, 0)
319 #define ENET0_MDIO__GPIO_4_1 MXS_GPIO_NR(4, 1)
320 #define ENET0_RX_EN__GPIO_4_2 MXS_GPIO_NR(4, 2)
321 #define ENET0_RXD0__GPIO_4_3 MXS_GPIO_NR(4, 3)
322 #define ENET0_RXD1__GPIO_4_4 MXS_GPIO_NR(4, 4)
323 #define ENET0_TX_EN__GPIO_4_6 MXS_GPIO_NR(4, 6)
324 #define ENET0_TXD0__GPIO_4_7 MXS_GPIO_NR(4, 7)
325 #define ENET0_TXD1__GPIO_4_8 MXS_GPIO_NR(4, 8)
326 #define ENET_CLK__GPIO_4_16 MXS_GPIO_NR(4, 16)
328 #define TX28_FEC_PHY_POWER MXS_GPIO_NR(3, 29)
329 #define TX28_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
330 #define TX28_FEC_nINT MXS_GPIO_NR(4, 5)
332 static const struct gpio tx28_gpios
[] __initconst
= {
333 { ENET0_MDC__GPIO_4_0
, GPIOF_OUT_INIT_LOW
, "GPIO_4_0" },
334 { ENET0_MDIO__GPIO_4_1
, GPIOF_OUT_INIT_LOW
, "GPIO_4_1" },
335 { ENET0_RX_EN__GPIO_4_2
, GPIOF_OUT_INIT_LOW
, "GPIO_4_2" },
336 { ENET0_RXD0__GPIO_4_3
, GPIOF_OUT_INIT_LOW
, "GPIO_4_3" },
337 { ENET0_RXD1__GPIO_4_4
, GPIOF_OUT_INIT_LOW
, "GPIO_4_4" },
338 { ENET0_TX_EN__GPIO_4_6
, GPIOF_OUT_INIT_LOW
, "GPIO_4_6" },
339 { ENET0_TXD0__GPIO_4_7
, GPIOF_OUT_INIT_LOW
, "GPIO_4_7" },
340 { ENET0_TXD1__GPIO_4_8
, GPIOF_OUT_INIT_LOW
, "GPIO_4_8" },
341 { ENET_CLK__GPIO_4_16
, GPIOF_OUT_INIT_LOW
, "GPIO_4_16" },
342 { TX28_FEC_PHY_POWER
, GPIOF_OUT_INIT_LOW
, "fec-phy-power" },
343 { TX28_FEC_PHY_RESET
, GPIOF_OUT_INIT_LOW
, "fec-phy-reset" },
344 { TX28_FEC_nINT
, GPIOF_DIR_IN
, "fec-int" },
347 static void __init
tx28_post_init(void)
349 struct device_node
*np
;
350 struct platform_device
*pdev
;
351 struct pinctrl
*pctl
;
354 enable_clk_enet_out();
356 np
= of_find_compatible_node(NULL
, NULL
, "fsl,imx28-fec");
357 pdev
= of_find_device_by_node(np
);
359 pr_err("%s: failed to find fec device\n", __func__
);
363 pctl
= pinctrl_get_select(&pdev
->dev
, "gpio_mode");
365 pr_err("%s: failed to get pinctrl state\n", __func__
);
369 ret
= gpio_request_array(tx28_gpios
, ARRAY_SIZE(tx28_gpios
));
371 pr_err("%s: failed to request gpios: %d\n", __func__
, ret
);
375 /* Power up fec phy */
376 gpio_set_value(TX28_FEC_PHY_POWER
, 1);
377 msleep(26); /* 25ms according to data sheet */
379 /* Mode strap pins */
380 gpio_set_value(ENET0_RX_EN__GPIO_4_2
, 1);
381 gpio_set_value(ENET0_RXD0__GPIO_4_3
, 1);
382 gpio_set_value(ENET0_RXD1__GPIO_4_4
, 1);
384 udelay(100); /* minimum assertion time for nRST */
386 /* Deasserting FEC PHY RESET */
387 gpio_set_value(TX28_FEC_PHY_RESET
, 1);
392 static void __init
cfa10049_init(void)
394 enable_clk_enet_out();
395 update_fec_mac_prop(OUI_CRYSTALFONTZ
);
398 static void __init
apf28_init(void)
400 enable_clk_enet_out();
402 mxsfb_pdata
.mode_list
= apf28dev_video_modes
;
403 mxsfb_pdata
.mode_count
= ARRAY_SIZE(apf28dev_video_modes
);
404 mxsfb_pdata
.default_bpp
= 16;
405 mxsfb_pdata
.ld_intf_width
= STMLCDIF_16BIT
;
408 static void __init
mxs_machine_init(void)
410 if (of_machine_is_compatible("fsl,imx28-evk"))
412 else if (of_machine_is_compatible("fsl,imx23-evk"))
414 else if (of_machine_is_compatible("denx,m28evk"))
416 else if (of_machine_is_compatible("bluegiga,apx4devkit"))
418 else if (of_machine_is_compatible("crystalfontz,cfa10049"))
420 else if (of_machine_is_compatible("armadeus,imx28-apf28"))
422 else if (of_machine_is_compatible("schulercontrol,imx28-sps1"))
425 of_platform_populate(NULL
, of_default_bus_match_table
,
426 mxs_auxdata_lookup
, NULL
);
428 if (of_machine_is_compatible("karo,tx28"))
431 if (of_machine_is_compatible("fsl,imx28-evk"))
432 imx28_evk_post_init();
435 static const char *imx23_dt_compat
[] __initdata
= {
440 static const char *imx28_dt_compat
[] __initdata
= {
445 DT_MACHINE_START(IMX23
, "Freescale i.MX23 (Device Tree)")
446 .map_io
= mx23_map_io
,
447 .init_irq
= icoll_init_irq
,
448 .handle_irq
= icoll_handle_irq
,
449 .timer
= &imx23_timer
,
450 .init_machine
= mxs_machine_init
,
451 .dt_compat
= imx23_dt_compat
,
452 .restart
= mxs_restart
,
455 DT_MACHINE_START(IMX28
, "Freescale i.MX28 (Device Tree)")
456 .map_io
= mx28_map_io
,
457 .init_irq
= icoll_init_irq
,
458 .handle_irq
= icoll_handle_irq
,
459 .timer
= &imx28_timer
,
460 .init_machine
= mxs_machine_init
,
461 .dt_compat
= imx28_dt_compat
,
462 .restart
= mxs_restart
,