Commit | Line | Data |
---|---|---|
bc3a59c1 DA |
1 | /* |
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> | |
ab2815c3 | 19 | #include <linux/mxsfb.h> |
bc3a59c1 DA |
20 | #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 | ||
ab2815c3 SG |
26 | static 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 | ||
44 | static 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 | ||
62 | static struct mxsfb_platform_data mxsfb_pdata __initdata; | |
63 | ||
64 | static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = { | |
65 | OF_DEV_AUXDATA("fsl,imx23-lcdif", 0x80030000, NULL, &mxsfb_pdata), | |
66 | OF_DEV_AUXDATA("fsl,imx28-lcdif", 0x80030000, NULL, &mxsfb_pdata), | |
67 | { /* sentinel */ } | |
68 | }; | |
69 | ||
bc3a59c1 DA |
70 | static int __init mxs_icoll_add_irq_domain(struct device_node *np, |
71 | struct device_node *interrupt_parent) | |
72 | { | |
73 | irq_domain_add_legacy(np, 128, 0, 0, &irq_domain_simple_ops, NULL); | |
74 | ||
75 | return 0; | |
76 | } | |
77 | ||
ce4c6f9b SG |
78 | static int __init mxs_gpio_add_irq_domain(struct device_node *np, |
79 | struct device_node *interrupt_parent) | |
80 | { | |
81 | static int gpio_irq_base = MXS_GPIO_IRQ_START; | |
82 | ||
83 | irq_domain_add_legacy(np, 32, gpio_irq_base, 0, &irq_domain_simple_ops, NULL); | |
84 | gpio_irq_base += 32; | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
bc3a59c1 DA |
89 | static const struct of_device_id mxs_irq_match[] __initconst = { |
90 | { .compatible = "fsl,mxs-icoll", .data = mxs_icoll_add_irq_domain, }, | |
ce4c6f9b | 91 | { .compatible = "fsl,mxs-gpio", .data = mxs_gpio_add_irq_domain, }, |
bc3a59c1 DA |
92 | { /* sentinel */ } |
93 | }; | |
94 | ||
95 | static void __init mxs_dt_init_irq(void) | |
96 | { | |
97 | icoll_init_irq(); | |
98 | of_irq_init(mxs_irq_match); | |
99 | } | |
100 | ||
2954ff39 SG |
101 | static void __init imx23_timer_init(void) |
102 | { | |
103 | mx23_clocks_init(); | |
104 | } | |
105 | ||
106 | static struct sys_timer imx23_timer = { | |
107 | .init = imx23_timer_init, | |
108 | }; | |
109 | ||
bc3a59c1 DA |
110 | static void __init imx28_timer_init(void) |
111 | { | |
112 | mx28_clocks_init(); | |
113 | } | |
114 | ||
115 | static struct sys_timer imx28_timer = { | |
116 | .init = imx28_timer_init, | |
117 | }; | |
118 | ||
5653acc2 SG |
119 | enum mac_oui { |
120 | OUI_FSL, | |
121 | OUI_DENX, | |
122 | }; | |
123 | ||
124 | static void __init update_fec_mac_prop(enum mac_oui oui) | |
125 | { | |
126 | struct device_node *np, *from = NULL; | |
127 | struct property *oldmac, *newmac; | |
128 | const u32 *ocotp = mxs_get_ocotp(); | |
129 | u8 *macaddr; | |
130 | u32 val; | |
131 | int i; | |
132 | ||
133 | for (i = 0; i < 2; i++) { | |
134 | np = of_find_compatible_node(from, NULL, "fsl,imx28-fec"); | |
135 | if (!np) | |
136 | return; | |
137 | from = np; | |
138 | ||
139 | newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL); | |
140 | if (!newmac) | |
141 | return; | |
142 | newmac->value = newmac + 1; | |
143 | newmac->length = 6; | |
144 | ||
145 | newmac->name = kstrdup("local-mac-address", GFP_KERNEL); | |
146 | if (!newmac->name) { | |
147 | kfree(newmac); | |
148 | return; | |
149 | } | |
150 | ||
151 | /* | |
152 | * OCOTP only stores the last 4 octets for each mac address, | |
153 | * so hard-code OUI here. | |
154 | */ | |
155 | macaddr = newmac->value; | |
156 | switch (oui) { | |
157 | case OUI_FSL: | |
158 | macaddr[0] = 0x00; | |
159 | macaddr[1] = 0x04; | |
160 | macaddr[2] = 0x9f; | |
161 | break; | |
162 | case OUI_DENX: | |
163 | macaddr[0] = 0xc0; | |
164 | macaddr[1] = 0xe5; | |
165 | macaddr[2] = 0x4e; | |
166 | break; | |
167 | } | |
168 | val = ocotp[i]; | |
169 | macaddr[3] = (val >> 16) & 0xff; | |
170 | macaddr[4] = (val >> 8) & 0xff; | |
171 | macaddr[5] = (val >> 0) & 0xff; | |
172 | ||
173 | oldmac = of_find_property(np, newmac->name, NULL); | |
174 | if (oldmac) | |
175 | prom_update_property(np, newmac, oldmac); | |
176 | else | |
177 | prom_add_property(np, newmac); | |
178 | } | |
179 | } | |
180 | ||
ab2815c3 SG |
181 | static void __init imx23_evk_init(void) |
182 | { | |
183 | mxsfb_pdata.mode_list = mx23evk_video_modes; | |
184 | mxsfb_pdata.mode_count = ARRAY_SIZE(mx23evk_video_modes); | |
185 | mxsfb_pdata.default_bpp = 32; | |
186 | mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT; | |
187 | } | |
188 | ||
bc3a59c1 DA |
189 | static void __init imx28_evk_init(void) |
190 | { | |
191 | struct clk *clk; | |
192 | ||
193 | /* Enable fec phy clock */ | |
194 | clk = clk_get_sys("enet_out", NULL); | |
195 | if (!IS_ERR(clk)) | |
196 | clk_prepare_enable(clk); | |
5653acc2 SG |
197 | |
198 | update_fec_mac_prop(OUI_FSL); | |
ab2815c3 SG |
199 | |
200 | mxsfb_pdata.mode_list = mx28evk_video_modes; | |
201 | mxsfb_pdata.mode_count = ARRAY_SIZE(mx28evk_video_modes); | |
202 | mxsfb_pdata.default_bpp = 32; | |
203 | mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT; | |
bc3a59c1 DA |
204 | } |
205 | ||
206 | static void __init mxs_machine_init(void) | |
207 | { | |
208 | if (of_machine_is_compatible("fsl,imx28-evk")) | |
209 | imx28_evk_init(); | |
ab2815c3 SG |
210 | else if (of_machine_is_compatible("fsl,imx23-evk")) |
211 | imx23_evk_init(); | |
bc3a59c1 DA |
212 | |
213 | of_platform_populate(NULL, of_default_bus_match_table, | |
ab2815c3 | 214 | mxs_auxdata_lookup, NULL); |
bc3a59c1 DA |
215 | } |
216 | ||
2954ff39 SG |
217 | static const char *imx23_dt_compat[] __initdata = { |
218 | "fsl,imx23-evk", | |
b9df4491 | 219 | "olimex,imx23-olinuxino", |
2954ff39 SG |
220 | "fsl,imx23", |
221 | NULL, | |
222 | }; | |
223 | ||
bc3a59c1 | 224 | static const char *imx28_dt_compat[] __initdata = { |
330eaaf9 | 225 | "crystalfontz,cfa10036", |
bc3a59c1 DA |
226 | "fsl,imx28-evk", |
227 | "fsl,imx28", | |
228 | NULL, | |
229 | }; | |
230 | ||
2954ff39 SG |
231 | DT_MACHINE_START(IMX23, "Freescale i.MX23 (Device Tree)") |
232 | .map_io = mx23_map_io, | |
233 | .init_irq = mxs_dt_init_irq, | |
234 | .timer = &imx23_timer, | |
235 | .init_machine = mxs_machine_init, | |
236 | .dt_compat = imx23_dt_compat, | |
237 | .restart = mxs_restart, | |
238 | MACHINE_END | |
239 | ||
bc3a59c1 DA |
240 | DT_MACHINE_START(IMX28, "Freescale i.MX28 (Device Tree)") |
241 | .map_io = mx28_map_io, | |
242 | .init_irq = mxs_dt_init_irq, | |
243 | .timer = &imx28_timer, | |
244 | .init_machine = mxs_machine_init, | |
245 | .dt_compat = imx28_dt_compat, | |
246 | .restart = mxs_restart, | |
247 | MACHINE_END |