blob: d3fc8ba9d759de5a7f07ba91a6d8d94d0ee075f9 [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>
14#include <linux/clkdev.h>
15#include <linux/err.h>
16#include <linux/init.h>
17#include <linux/init.h>
18#include <linux/irqdomain.h>
Shawn Guoab2815c2012-06-25 21:21:46 +080019#include <linux/mxsfb.h>
Dong Aishengbc3a59c2012-03-31 21:26:57 +080020#include <linux/of_irq.h>
21#include <linux/of_platform.h>
22#include <asm/mach/arch.h>
23#include <asm/mach/time.h>
24#include <mach/common.h>
25
Shawn Guoab2815c2012-06-25 21:21:46 +080026static struct fb_videomode mx23evk_video_modes[] = {
27 {
28 .name = "Samsung-LMS430HF02",
29 .refresh = 60,
30 .xres = 480,
31 .yres = 272,
32 .pixclock = 108096, /* picosecond (9.2 MHz) */
33 .left_margin = 15,
34 .right_margin = 8,
35 .upper_margin = 12,
36 .lower_margin = 4,
37 .hsync_len = 1,
38 .vsync_len = 1,
39 .sync = FB_SYNC_DATA_ENABLE_HIGH_ACT |
40 FB_SYNC_DOTCLK_FAILING_ACT,
41 },
42};
43
44static struct fb_videomode mx28evk_video_modes[] = {
45 {
46 .name = "Seiko-43WVF1G",
47 .refresh = 60,
48 .xres = 800,
49 .yres = 480,
50 .pixclock = 29851, /* picosecond (33.5 MHz) */
51 .left_margin = 89,
52 .right_margin = 164,
53 .upper_margin = 23,
54 .lower_margin = 10,
55 .hsync_len = 10,
56 .vsync_len = 10,
57 .sync = FB_SYNC_DATA_ENABLE_HIGH_ACT |
58 FB_SYNC_DOTCLK_FAILING_ACT,
59 },
60};
61
Marek Vasut8fa62e12012-07-07 21:21:38 +080062static struct fb_videomode m28evk_video_modes[] = {
63 {
64 .name = "Ampire AM-800480R2TMQW-T01H",
65 .refresh = 60,
66 .xres = 800,
67 .yres = 480,
68 .pixclock = 30066, /* picosecond (33.26 MHz) */
69 .left_margin = 0,
70 .right_margin = 256,
71 .upper_margin = 0,
72 .lower_margin = 45,
73 .hsync_len = 1,
74 .vsync_len = 1,
75 .sync = FB_SYNC_DATA_ENABLE_HIGH_ACT,
76 },
77};
78
Shawn Guoab2815c2012-06-25 21:21:46 +080079static struct mxsfb_platform_data mxsfb_pdata __initdata;
80
81static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = {
82 OF_DEV_AUXDATA("fsl,imx23-lcdif", 0x80030000, NULL, &mxsfb_pdata),
83 OF_DEV_AUXDATA("fsl,imx28-lcdif", 0x80030000, NULL, &mxsfb_pdata),
84 { /* sentinel */ }
85};
86
Dong Aishengbc3a59c2012-03-31 21:26:57 +080087static int __init mxs_icoll_add_irq_domain(struct device_node *np,
88 struct device_node *interrupt_parent)
89{
90 irq_domain_add_legacy(np, 128, 0, 0, &irq_domain_simple_ops, NULL);
91
92 return 0;
93}
94
Shawn Guoce4c6f92012-05-04 14:32:35 +080095static int __init mxs_gpio_add_irq_domain(struct device_node *np,
96 struct device_node *interrupt_parent)
97{
98 static int gpio_irq_base = MXS_GPIO_IRQ_START;
99
100 irq_domain_add_legacy(np, 32, gpio_irq_base, 0, &irq_domain_simple_ops, NULL);
101 gpio_irq_base += 32;
102
103 return 0;
104}
105
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800106static const struct of_device_id mxs_irq_match[] __initconst = {
107 { .compatible = "fsl,mxs-icoll", .data = mxs_icoll_add_irq_domain, },
Shawn Guoce4c6f92012-05-04 14:32:35 +0800108 { .compatible = "fsl,mxs-gpio", .data = mxs_gpio_add_irq_domain, },
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800109 { /* sentinel */ }
110};
111
112static void __init mxs_dt_init_irq(void)
113{
114 icoll_init_irq();
115 of_irq_init(mxs_irq_match);
116}
117
Shawn Guo2954ff32012-05-04 21:33:42 +0800118static void __init imx23_timer_init(void)
119{
120 mx23_clocks_init();
121}
122
123static struct sys_timer imx23_timer = {
124 .init = imx23_timer_init,
125};
126
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800127static void __init imx28_timer_init(void)
128{
129 mx28_clocks_init();
130}
131
132static struct sys_timer imx28_timer = {
133 .init = imx28_timer_init,
134};
135
Shawn Guo5653acc2012-06-19 22:38:14 +0800136enum mac_oui {
137 OUI_FSL,
138 OUI_DENX,
139};
140
141static void __init update_fec_mac_prop(enum mac_oui oui)
142{
143 struct device_node *np, *from = NULL;
144 struct property *oldmac, *newmac;
145 const u32 *ocotp = mxs_get_ocotp();
146 u8 *macaddr;
147 u32 val;
148 int i;
149
150 for (i = 0; i < 2; i++) {
151 np = of_find_compatible_node(from, NULL, "fsl,imx28-fec");
152 if (!np)
153 return;
154 from = np;
155
156 newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
157 if (!newmac)
158 return;
159 newmac->value = newmac + 1;
160 newmac->length = 6;
161
162 newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
163 if (!newmac->name) {
164 kfree(newmac);
165 return;
166 }
167
168 /*
169 * OCOTP only stores the last 4 octets for each mac address,
170 * so hard-code OUI here.
171 */
172 macaddr = newmac->value;
173 switch (oui) {
174 case OUI_FSL:
175 macaddr[0] = 0x00;
176 macaddr[1] = 0x04;
177 macaddr[2] = 0x9f;
178 break;
179 case OUI_DENX:
180 macaddr[0] = 0xc0;
181 macaddr[1] = 0xe5;
182 macaddr[2] = 0x4e;
183 break;
184 }
185 val = ocotp[i];
186 macaddr[3] = (val >> 16) & 0xff;
187 macaddr[4] = (val >> 8) & 0xff;
188 macaddr[5] = (val >> 0) & 0xff;
189
190 oldmac = of_find_property(np, newmac->name, NULL);
191 if (oldmac)
192 prom_update_property(np, newmac, oldmac);
193 else
194 prom_add_property(np, newmac);
195 }
196}
197
Shawn Guoab2815c2012-06-25 21:21:46 +0800198static void __init imx23_evk_init(void)
199{
200 mxsfb_pdata.mode_list = mx23evk_video_modes;
201 mxsfb_pdata.mode_count = ARRAY_SIZE(mx23evk_video_modes);
202 mxsfb_pdata.default_bpp = 32;
203 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
204}
205
Marek Vasut8fa62e12012-07-07 21:21:38 +0800206static inline void enable_clk_enet_out(void)
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800207{
Marek Vasut8fa62e12012-07-07 21:21:38 +0800208 struct clk *clk = clk_get_sys("enet_out", NULL);
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800209
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800210 if (!IS_ERR(clk))
211 clk_prepare_enable(clk);
Marek Vasut8fa62e12012-07-07 21:21:38 +0800212}
Shawn Guo5653acc2012-06-19 22:38:14 +0800213
Marek Vasut8fa62e12012-07-07 21:21:38 +0800214static void __init imx28_evk_init(void)
215{
216 enable_clk_enet_out();
Shawn Guo5653acc2012-06-19 22:38:14 +0800217 update_fec_mac_prop(OUI_FSL);
Shawn Guoab2815c2012-06-25 21:21:46 +0800218
219 mxsfb_pdata.mode_list = mx28evk_video_modes;
220 mxsfb_pdata.mode_count = ARRAY_SIZE(mx28evk_video_modes);
221 mxsfb_pdata.default_bpp = 32;
222 mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800223}
224
Marek Vasut8fa62e12012-07-07 21:21:38 +0800225static void __init m28evk_init(void)
226{
227 enable_clk_enet_out();
228 update_fec_mac_prop(OUI_DENX);
229
230 mxsfb_pdata.mode_list = m28evk_video_modes;
231 mxsfb_pdata.mode_count = ARRAY_SIZE(m28evk_video_modes);
232 mxsfb_pdata.default_bpp = 16;
233 mxsfb_pdata.ld_intf_width = STMLCDIF_18BIT;
234}
235
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800236static void __init mxs_machine_init(void)
237{
238 if (of_machine_is_compatible("fsl,imx28-evk"))
239 imx28_evk_init();
Shawn Guoab2815c2012-06-25 21:21:46 +0800240 else if (of_machine_is_compatible("fsl,imx23-evk"))
241 imx23_evk_init();
Marek Vasut8fa62e12012-07-07 21:21:38 +0800242 else if (of_machine_is_compatible("denx,m28evk"))
243 m28evk_init();
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800244
245 of_platform_populate(NULL, of_default_bus_match_table,
Shawn Guoab2815c2012-06-25 21:21:46 +0800246 mxs_auxdata_lookup, NULL);
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800247}
248
Shawn Guo2954ff32012-05-04 21:33:42 +0800249static const char *imx23_dt_compat[] __initdata = {
250 "fsl,imx23-evk",
Fabio Estevamb9df4492012-07-04 13:22:53 -0300251 "olimex,imx23-olinuxino",
Shawn Guo2954ff32012-05-04 21:33:42 +0800252 "fsl,imx23",
253 NULL,
254};
255
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800256static const char *imx28_dt_compat[] __initdata = {
Maxime Ripard330eaaf2012-06-27 10:18:12 +0200257 "crystalfontz,cfa10036",
Marek Vasut8fa62e12012-07-07 21:21:38 +0800258 "denx,m28evk",
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800259 "fsl,imx28-evk",
260 "fsl,imx28",
261 NULL,
262};
263
Shawn Guo2954ff32012-05-04 21:33:42 +0800264DT_MACHINE_START(IMX23, "Freescale i.MX23 (Device Tree)")
265 .map_io = mx23_map_io,
266 .init_irq = mxs_dt_init_irq,
267 .timer = &imx23_timer,
268 .init_machine = mxs_machine_init,
269 .dt_compat = imx23_dt_compat,
270 .restart = mxs_restart,
271MACHINE_END
272
Dong Aishengbc3a59c2012-03-31 21:26:57 +0800273DT_MACHINE_START(IMX28, "Freescale i.MX28 (Device Tree)")
274 .map_io = mx28_map_io,
275 .init_irq = mxs_dt_init_irq,
276 .timer = &imx28_timer,
277 .init_machine = mxs_machine_init,
278 .dt_compat = imx28_dt_compat,
279 .restart = mxs_restart,
280MACHINE_END