]>
Commit | Line | Data |
---|---|---|
eed32001 KG |
1 | /* |
2 | * FSL SoC setup code | |
3 | * | |
4 | * Maintained by Kumar Gala (see MAINTAINERS for contact information) | |
5 | * | |
fba43665 VB |
6 | * 2006 (c) MontaVista Software, Inc. |
7 | * Vitaly Bordug <vbordug@ru.mvista.com> | |
8 | * | |
eed32001 KG |
9 | * This program is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2 of the License, or (at your | |
12 | * option) any later version. | |
13 | */ | |
14 | ||
eed32001 KG |
15 | #include <linux/stddef.h> |
16 | #include <linux/kernel.h> | |
17 | #include <linux/init.h> | |
18 | #include <linux/errno.h> | |
19 | #include <linux/major.h> | |
20 | #include <linux/delay.h> | |
21 | #include <linux/irq.h> | |
22 | #include <linux/module.h> | |
23 | #include <linux/device.h> | |
24 | #include <linux/platform_device.h> | |
a9b14973 | 25 | #include <linux/phy.h> |
eed32001 | 26 | #include <linux/fsl_devices.h> |
fba43665 VB |
27 | #include <linux/fs_enet_pd.h> |
28 | #include <linux/fs_uart_pd.h> | |
eed32001 KG |
29 | |
30 | #include <asm/system.h> | |
31 | #include <asm/atomic.h> | |
32 | #include <asm/io.h> | |
33 | #include <asm/irq.h> | |
fba43665 | 34 | #include <asm/time.h> |
eed32001 KG |
35 | #include <asm/prom.h> |
36 | #include <sysdev/fsl_soc.h> | |
37 | #include <mm/mmu_decl.h> | |
fba43665 | 38 | #include <asm/cpm2.h> |
eed32001 | 39 | |
d3465c92 | 40 | extern void init_fcc_ioports(struct fs_platform_info*); |
ed943c1f | 41 | extern void init_scc_ioports(struct fs_uart_platform_info*); |
eed32001 KG |
42 | static phys_addr_t immrbase = -1; |
43 | ||
44 | phys_addr_t get_immrbase(void) | |
45 | { | |
46 | struct device_node *soc; | |
47 | ||
48 | if (immrbase != -1) | |
49 | return immrbase; | |
50 | ||
51 | soc = of_find_node_by_type(NULL, "soc"); | |
2fb07d77 | 52 | if (soc) { |
eed32001 | 53 | unsigned int size; |
a7f67bdf | 54 | const void *prop = get_property(soc, "reg", &size); |
fba43665 VB |
55 | |
56 | if (prop) | |
57 | immrbase = of_translate_address(soc, prop); | |
eed32001 KG |
58 | of_node_put(soc); |
59 | }; | |
60 | ||
61 | return immrbase; | |
62 | } | |
eed32001 | 63 | |
2fb07d77 | 64 | EXPORT_SYMBOL(get_immrbase); |
eed32001 | 65 | |
fba43665 VB |
66 | #ifdef CONFIG_CPM2 |
67 | ||
68 | static u32 brgfreq = -1; | |
69 | ||
70 | u32 get_brgfreq(void) | |
71 | { | |
72 | struct device_node *node; | |
73 | ||
74 | if (brgfreq != -1) | |
75 | return brgfreq; | |
76 | ||
77 | node = of_find_node_by_type(NULL, "cpm"); | |
78 | if (node) { | |
79 | unsigned int size; | |
80 | const unsigned int *prop = get_property(node, "brg-frequency", | |
81 | &size); | |
82 | ||
83 | if (prop) | |
84 | brgfreq = *prop; | |
85 | of_node_put(node); | |
86 | }; | |
87 | ||
88 | return brgfreq; | |
89 | } | |
90 | ||
91 | EXPORT_SYMBOL(get_brgfreq); | |
92 | ||
93 | static u32 fs_baudrate = -1; | |
94 | ||
95 | u32 get_baudrate(void) | |
96 | { | |
97 | struct device_node *node; | |
98 | ||
99 | if (fs_baudrate != -1) | |
100 | return fs_baudrate; | |
101 | ||
102 | node = of_find_node_by_type(NULL, "serial"); | |
103 | if (node) { | |
104 | unsigned int size; | |
105 | const unsigned int *prop = get_property(node, "current-speed", | |
106 | &size); | |
107 | ||
108 | if (prop) | |
109 | fs_baudrate = *prop; | |
110 | of_node_put(node); | |
111 | }; | |
112 | ||
113 | return fs_baudrate; | |
114 | } | |
115 | ||
116 | EXPORT_SYMBOL(get_baudrate); | |
117 | #endif /* CONFIG_CPM2 */ | |
118 | ||
2fb07d77 | 119 | static int __init gfar_mdio_of_init(void) |
eed32001 KG |
120 | { |
121 | struct device_node *np; | |
122 | unsigned int i; | |
2fb07d77 | 123 | struct platform_device *mdio_dev; |
eed32001 KG |
124 | struct resource res; |
125 | int ret; | |
126 | ||
2fb07d77 KG |
127 | for (np = NULL, i = 0; |
128 | (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; | |
129 | i++) { | |
eed32001 KG |
130 | int k; |
131 | struct device_node *child = NULL; | |
132 | struct gianfar_mdio_data mdio_data; | |
133 | ||
134 | memset(&res, 0, sizeof(res)); | |
135 | memset(&mdio_data, 0, sizeof(mdio_data)); | |
136 | ||
137 | ret = of_address_to_resource(np, 0, &res); | |
138 | if (ret) | |
2fb07d77 | 139 | goto err; |
eed32001 | 140 | |
2fb07d77 KG |
141 | mdio_dev = |
142 | platform_device_register_simple("fsl-gianfar_mdio", | |
143 | res.start, &res, 1); | |
eed32001 KG |
144 | if (IS_ERR(mdio_dev)) { |
145 | ret = PTR_ERR(mdio_dev); | |
2fb07d77 | 146 | goto err; |
eed32001 KG |
147 | } |
148 | ||
149 | for (k = 0; k < 32; k++) | |
a9b14973 | 150 | mdio_data.irq[k] = PHY_POLL; |
eed32001 KG |
151 | |
152 | while ((child = of_get_next_child(np, child)) != NULL) { | |
fba43665 VB |
153 | int irq = irq_of_parse_and_map(child, 0); |
154 | if (irq != NO_IRQ) { | |
155 | const u32 *id = get_property(child, "reg", NULL); | |
156 | mdio_data.irq[*id] = irq; | |
157 | } | |
eed32001 KG |
158 | } |
159 | ||
2fb07d77 KG |
160 | ret = |
161 | platform_device_add_data(mdio_dev, &mdio_data, | |
162 | sizeof(struct gianfar_mdio_data)); | |
eed32001 | 163 | if (ret) |
2fb07d77 | 164 | goto unreg; |
eed32001 KG |
165 | } |
166 | ||
2fb07d77 KG |
167 | return 0; |
168 | ||
169 | unreg: | |
170 | platform_device_unregister(mdio_dev); | |
171 | err: | |
172 | return ret; | |
173 | } | |
174 | ||
175 | arch_initcall(gfar_mdio_of_init); | |
176 | ||
177 | static const char *gfar_tx_intr = "tx"; | |
178 | static const char *gfar_rx_intr = "rx"; | |
179 | static const char *gfar_err_intr = "error"; | |
180 | ||
a9b14973 | 181 | |
2fb07d77 KG |
182 | static int __init gfar_of_init(void) |
183 | { | |
184 | struct device_node *np; | |
185 | unsigned int i; | |
186 | struct platform_device *gfar_dev; | |
187 | struct resource res; | |
188 | int ret; | |
189 | ||
190 | for (np = NULL, i = 0; | |
191 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; | |
192 | i++) { | |
eed32001 KG |
193 | struct resource r[4]; |
194 | struct device_node *phy, *mdio; | |
195 | struct gianfar_platform_data gfar_data; | |
a7f67bdf JK |
196 | const unsigned int *id; |
197 | const char *model; | |
198 | const void *mac_addr; | |
199 | const phandle *ph; | |
fba43665 | 200 | int n_res = 2; |
eed32001 KG |
201 | |
202 | memset(r, 0, sizeof(r)); | |
203 | memset(&gfar_data, 0, sizeof(gfar_data)); | |
204 | ||
205 | ret = of_address_to_resource(np, 0, &r[0]); | |
206 | if (ret) | |
2fb07d77 | 207 | goto err; |
eed32001 | 208 | |
a9b14973 | 209 | of_irq_to_resource(np, 0, &r[1]); |
eed32001 KG |
210 | |
211 | model = get_property(np, "model", NULL); | |
212 | ||
213 | /* If we aren't the FEC we have multiple interrupts */ | |
214 | if (model && strcasecmp(model, "FEC")) { | |
215 | r[1].name = gfar_tx_intr; | |
216 | ||
217 | r[2].name = gfar_rx_intr; | |
a9b14973 | 218 | of_irq_to_resource(np, 1, &r[2]); |
eed32001 KG |
219 | |
220 | r[3].name = gfar_err_intr; | |
a9b14973 | 221 | of_irq_to_resource(np, 2, &r[3]); |
919fede6 JL |
222 | |
223 | n_res += 2; | |
eed32001 KG |
224 | } |
225 | ||
2fb07d77 KG |
226 | gfar_dev = |
227 | platform_device_register_simple("fsl-gianfar", i, &r[0], | |
fba43665 | 228 | n_res); |
eed32001 KG |
229 | |
230 | if (IS_ERR(gfar_dev)) { | |
231 | ret = PTR_ERR(gfar_dev); | |
2fb07d77 | 232 | goto err; |
eed32001 KG |
233 | } |
234 | ||
f583165f JL |
235 | mac_addr = get_property(np, "local-mac-address", NULL); |
236 | if (mac_addr == NULL) | |
237 | mac_addr = get_property(np, "mac-address", NULL); | |
238 | if (mac_addr == NULL) { | |
239 | /* Obsolete */ | |
240 | mac_addr = get_property(np, "address", NULL); | |
241 | } | |
242 | ||
243 | if (mac_addr) | |
244 | memcpy(gfar_data.mac_addr, mac_addr, 6); | |
eed32001 KG |
245 | |
246 | if (model && !strcasecmp(model, "TSEC")) | |
247 | gfar_data.device_flags = | |
2fb07d77 KG |
248 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
249 | FSL_GIANFAR_DEV_HAS_COALESCE | | |
250 | FSL_GIANFAR_DEV_HAS_RMON | | |
251 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; | |
eed32001 KG |
252 | if (model && !strcasecmp(model, "eTSEC")) |
253 | gfar_data.device_flags = | |
2fb07d77 KG |
254 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
255 | FSL_GIANFAR_DEV_HAS_COALESCE | | |
256 | FSL_GIANFAR_DEV_HAS_RMON | | |
257 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | | |
258 | FSL_GIANFAR_DEV_HAS_CSUM | | |
259 | FSL_GIANFAR_DEV_HAS_VLAN | | |
260 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; | |
eed32001 | 261 | |
a7f67bdf | 262 | ph = get_property(np, "phy-handle", NULL); |
eed32001 KG |
263 | phy = of_find_node_by_phandle(*ph); |
264 | ||
265 | if (phy == NULL) { | |
266 | ret = -ENODEV; | |
2fb07d77 | 267 | goto unreg; |
eed32001 KG |
268 | } |
269 | ||
270 | mdio = of_get_parent(phy); | |
271 | ||
a7f67bdf | 272 | id = get_property(phy, "reg", NULL); |
eed32001 KG |
273 | ret = of_address_to_resource(mdio, 0, &res); |
274 | if (ret) { | |
275 | of_node_put(phy); | |
276 | of_node_put(mdio); | |
2fb07d77 | 277 | goto unreg; |
eed32001 KG |
278 | } |
279 | ||
280 | gfar_data.phy_id = *id; | |
281 | gfar_data.bus_id = res.start; | |
282 | ||
283 | of_node_put(phy); | |
284 | of_node_put(mdio); | |
285 | ||
2fb07d77 KG |
286 | ret = |
287 | platform_device_add_data(gfar_dev, &gfar_data, | |
288 | sizeof(struct | |
289 | gianfar_platform_data)); | |
eed32001 | 290 | if (ret) |
2fb07d77 | 291 | goto unreg; |
eed32001 KG |
292 | } |
293 | ||
294 | return 0; | |
295 | ||
2fb07d77 | 296 | unreg: |
eed32001 | 297 | platform_device_unregister(gfar_dev); |
2fb07d77 | 298 | err: |
eed32001 KG |
299 | return ret; |
300 | } | |
2fb07d77 | 301 | |
eed32001 KG |
302 | arch_initcall(gfar_of_init); |
303 | ||
304 | static int __init fsl_i2c_of_init(void) | |
305 | { | |
306 | struct device_node *np; | |
307 | unsigned int i; | |
308 | struct platform_device *i2c_dev; | |
309 | int ret; | |
310 | ||
2fb07d77 KG |
311 | for (np = NULL, i = 0; |
312 | (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; | |
313 | i++) { | |
eed32001 KG |
314 | struct resource r[2]; |
315 | struct fsl_i2c_platform_data i2c_data; | |
a7f67bdf | 316 | const unsigned char *flags = NULL; |
eed32001 KG |
317 | |
318 | memset(&r, 0, sizeof(r)); | |
319 | memset(&i2c_data, 0, sizeof(i2c_data)); | |
320 | ||
321 | ret = of_address_to_resource(np, 0, &r[0]); | |
322 | if (ret) | |
2fb07d77 | 323 | goto err; |
eed32001 | 324 | |
a9b14973 | 325 | of_irq_to_resource(np, 0, &r[1]); |
eed32001 KG |
326 | |
327 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); | |
328 | if (IS_ERR(i2c_dev)) { | |
329 | ret = PTR_ERR(i2c_dev); | |
2fb07d77 | 330 | goto err; |
eed32001 KG |
331 | } |
332 | ||
333 | i2c_data.device_flags = 0; | |
334 | flags = get_property(np, "dfsrr", NULL); | |
335 | if (flags) | |
336 | i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR; | |
337 | ||
338 | flags = get_property(np, "fsl5200-clocking", NULL); | |
339 | if (flags) | |
340 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; | |
341 | ||
2fb07d77 KG |
342 | ret = |
343 | platform_device_add_data(i2c_dev, &i2c_data, | |
344 | sizeof(struct | |
345 | fsl_i2c_platform_data)); | |
eed32001 | 346 | if (ret) |
2fb07d77 | 347 | goto unreg; |
eed32001 KG |
348 | } |
349 | ||
350 | return 0; | |
351 | ||
2fb07d77 | 352 | unreg: |
eed32001 | 353 | platform_device_unregister(i2c_dev); |
2fb07d77 | 354 | err: |
eed32001 KG |
355 | return ret; |
356 | } | |
2fb07d77 | 357 | |
eed32001 KG |
358 | arch_initcall(fsl_i2c_of_init); |
359 | ||
360 | #ifdef CONFIG_PPC_83xx | |
361 | static int __init mpc83xx_wdt_init(void) | |
362 | { | |
363 | struct resource r; | |
364 | struct device_node *soc, *np; | |
365 | struct platform_device *dev; | |
a7f67bdf | 366 | const unsigned int *freq; |
eed32001 KG |
367 | int ret; |
368 | ||
369 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); | |
370 | ||
371 | if (!np) { | |
372 | ret = -ENODEV; | |
2fb07d77 | 373 | goto nodev; |
eed32001 KG |
374 | } |
375 | ||
376 | soc = of_find_node_by_type(NULL, "soc"); | |
377 | ||
378 | if (!soc) { | |
379 | ret = -ENODEV; | |
2fb07d77 | 380 | goto nosoc; |
eed32001 KG |
381 | } |
382 | ||
a7f67bdf | 383 | freq = get_property(soc, "bus-frequency", NULL); |
eed32001 KG |
384 | if (!freq) { |
385 | ret = -ENODEV; | |
2fb07d77 | 386 | goto err; |
eed32001 KG |
387 | } |
388 | ||
389 | memset(&r, 0, sizeof(r)); | |
390 | ||
391 | ret = of_address_to_resource(np, 0, &r); | |
392 | if (ret) | |
2fb07d77 | 393 | goto err; |
eed32001 KG |
394 | |
395 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); | |
396 | if (IS_ERR(dev)) { | |
397 | ret = PTR_ERR(dev); | |
2fb07d77 | 398 | goto err; |
eed32001 KG |
399 | } |
400 | ||
401 | ret = platform_device_add_data(dev, freq, sizeof(int)); | |
402 | if (ret) | |
2fb07d77 | 403 | goto unreg; |
eed32001 KG |
404 | |
405 | of_node_put(soc); | |
406 | of_node_put(np); | |
407 | ||
408 | return 0; | |
409 | ||
2fb07d77 | 410 | unreg: |
eed32001 | 411 | platform_device_unregister(dev); |
2fb07d77 | 412 | err: |
eed32001 | 413 | of_node_put(soc); |
2fb07d77 | 414 | nosoc: |
eed32001 | 415 | of_node_put(np); |
2fb07d77 | 416 | nodev: |
eed32001 KG |
417 | return ret; |
418 | } | |
2fb07d77 | 419 | |
eed32001 KG |
420 | arch_initcall(mpc83xx_wdt_init); |
421 | #endif | |
4b10cfd4 | 422 | |
a7f67bdf | 423 | static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type) |
4b10cfd4 KG |
424 | { |
425 | if (!phy_type) | |
426 | return FSL_USB2_PHY_NONE; | |
427 | if (!strcasecmp(phy_type, "ulpi")) | |
428 | return FSL_USB2_PHY_ULPI; | |
429 | if (!strcasecmp(phy_type, "utmi")) | |
430 | return FSL_USB2_PHY_UTMI; | |
431 | if (!strcasecmp(phy_type, "utmi_wide")) | |
432 | return FSL_USB2_PHY_UTMI_WIDE; | |
433 | if (!strcasecmp(phy_type, "serial")) | |
434 | return FSL_USB2_PHY_SERIAL; | |
435 | ||
436 | return FSL_USB2_PHY_NONE; | |
437 | } | |
438 | ||
439 | static int __init fsl_usb_of_init(void) | |
440 | { | |
441 | struct device_node *np; | |
442 | unsigned int i; | |
01cced25 | 443 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL; |
4b10cfd4 KG |
444 | int ret; |
445 | ||
446 | for (np = NULL, i = 0; | |
447 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL; | |
448 | i++) { | |
449 | struct resource r[2]; | |
450 | struct fsl_usb2_platform_data usb_data; | |
a7f67bdf | 451 | const unsigned char *prop = NULL; |
4b10cfd4 KG |
452 | |
453 | memset(&r, 0, sizeof(r)); | |
454 | memset(&usb_data, 0, sizeof(usb_data)); | |
455 | ||
456 | ret = of_address_to_resource(np, 0, &r[0]); | |
457 | if (ret) | |
458 | goto err; | |
459 | ||
a9b14973 | 460 | of_irq_to_resource(np, 0, &r[1]); |
4b10cfd4 | 461 | |
01cced25 KG |
462 | usb_dev_mph = |
463 | platform_device_register_simple("fsl-ehci", i, r, 2); | |
464 | if (IS_ERR(usb_dev_mph)) { | |
465 | ret = PTR_ERR(usb_dev_mph); | |
4b10cfd4 KG |
466 | goto err; |
467 | } | |
468 | ||
01cced25 KG |
469 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; |
470 | usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask; | |
4b10cfd4 KG |
471 | |
472 | usb_data.operating_mode = FSL_USB2_MPH_HOST; | |
473 | ||
474 | prop = get_property(np, "port0", NULL); | |
475 | if (prop) | |
476 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; | |
477 | ||
478 | prop = get_property(np, "port1", NULL); | |
479 | if (prop) | |
480 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; | |
481 | ||
482 | prop = get_property(np, "phy_type", NULL); | |
483 | usb_data.phy_mode = determine_usb_phy(prop); | |
484 | ||
485 | ret = | |
01cced25 | 486 | platform_device_add_data(usb_dev_mph, &usb_data, |
4b10cfd4 KG |
487 | sizeof(struct |
488 | fsl_usb2_platform_data)); | |
489 | if (ret) | |
01cced25 | 490 | goto unreg_mph; |
4b10cfd4 KG |
491 | } |
492 | ||
01cced25 | 493 | for (np = NULL; |
4b10cfd4 KG |
494 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL; |
495 | i++) { | |
496 | struct resource r[2]; | |
497 | struct fsl_usb2_platform_data usb_data; | |
a7f67bdf | 498 | const unsigned char *prop = NULL; |
4b10cfd4 KG |
499 | |
500 | memset(&r, 0, sizeof(r)); | |
501 | memset(&usb_data, 0, sizeof(usb_data)); | |
502 | ||
503 | ret = of_address_to_resource(np, 0, &r[0]); | |
504 | if (ret) | |
01cced25 | 505 | goto unreg_mph; |
4b10cfd4 | 506 | |
a9b14973 | 507 | of_irq_to_resource(np, 0, &r[1]); |
4b10cfd4 | 508 | |
01cced25 KG |
509 | usb_dev_dr = |
510 | platform_device_register_simple("fsl-ehci", i, r, 2); | |
511 | if (IS_ERR(usb_dev_dr)) { | |
512 | ret = PTR_ERR(usb_dev_dr); | |
4b10cfd4 KG |
513 | goto err; |
514 | } | |
515 | ||
01cced25 KG |
516 | usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL; |
517 | usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask; | |
4b10cfd4 KG |
518 | |
519 | usb_data.operating_mode = FSL_USB2_DR_HOST; | |
520 | ||
521 | prop = get_property(np, "phy_type", NULL); | |
522 | usb_data.phy_mode = determine_usb_phy(prop); | |
523 | ||
524 | ret = | |
01cced25 | 525 | platform_device_add_data(usb_dev_dr, &usb_data, |
4b10cfd4 KG |
526 | sizeof(struct |
527 | fsl_usb2_platform_data)); | |
528 | if (ret) | |
01cced25 | 529 | goto unreg_dr; |
4b10cfd4 | 530 | } |
4b10cfd4 KG |
531 | return 0; |
532 | ||
01cced25 KG |
533 | unreg_dr: |
534 | if (usb_dev_dr) | |
535 | platform_device_unregister(usb_dev_dr); | |
536 | unreg_mph: | |
537 | if (usb_dev_mph) | |
538 | platform_device_unregister(usb_dev_mph); | |
4b10cfd4 KG |
539 | err: |
540 | return ret; | |
541 | } | |
542 | ||
01cced25 | 543 | arch_initcall(fsl_usb_of_init); |
fba43665 VB |
544 | |
545 | #ifdef CONFIG_CPM2 | |
546 | ||
547 | static const char fcc_regs[] = "fcc_regs"; | |
548 | static const char fcc_regs_c[] = "fcc_regs_c"; | |
549 | static const char fcc_pram[] = "fcc_pram"; | |
550 | static char bus_id[9][BUS_ID_SIZE]; | |
551 | ||
552 | static int __init fs_enet_of_init(void) | |
553 | { | |
554 | struct device_node *np; | |
555 | unsigned int i; | |
556 | struct platform_device *fs_enet_dev; | |
557 | struct resource res; | |
558 | int ret; | |
559 | ||
560 | for (np = NULL, i = 0; | |
561 | (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; | |
562 | i++) { | |
563 | struct resource r[4]; | |
564 | struct device_node *phy, *mdio; | |
565 | struct fs_platform_info fs_enet_data; | |
2b00b254 | 566 | const unsigned int *id, *phy_addr, *phy_irq; |
fba43665 VB |
567 | const void *mac_addr; |
568 | const phandle *ph; | |
569 | const char *model; | |
570 | ||
571 | memset(r, 0, sizeof(r)); | |
572 | memset(&fs_enet_data, 0, sizeof(fs_enet_data)); | |
573 | ||
574 | ret = of_address_to_resource(np, 0, &r[0]); | |
575 | if (ret) | |
576 | goto err; | |
577 | r[0].name = fcc_regs; | |
578 | ||
579 | ret = of_address_to_resource(np, 1, &r[1]); | |
580 | if (ret) | |
581 | goto err; | |
582 | r[1].name = fcc_pram; | |
583 | ||
584 | ret = of_address_to_resource(np, 2, &r[2]); | |
585 | if (ret) | |
586 | goto err; | |
587 | r[2].name = fcc_regs_c; | |
ed943c1f | 588 | fs_enet_data.fcc_regs_c = r[2].start; |
fba43665 | 589 | |
a9b14973 | 590 | of_irq_to_resource(np, 0, &r[3]); |
fba43665 VB |
591 | |
592 | fs_enet_dev = | |
593 | platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4); | |
594 | ||
595 | if (IS_ERR(fs_enet_dev)) { | |
596 | ret = PTR_ERR(fs_enet_dev); | |
597 | goto err; | |
598 | } | |
599 | ||
600 | model = get_property(np, "model", NULL); | |
601 | if (model == NULL) { | |
602 | ret = -ENODEV; | |
603 | goto unreg; | |
604 | } | |
605 | ||
606 | mac_addr = get_property(np, "mac-address", NULL); | |
607 | memcpy(fs_enet_data.macaddr, mac_addr, 6); | |
608 | ||
609 | ph = get_property(np, "phy-handle", NULL); | |
610 | phy = of_find_node_by_phandle(*ph); | |
611 | ||
612 | if (phy == NULL) { | |
613 | ret = -ENODEV; | |
614 | goto unreg; | |
615 | } | |
616 | ||
617 | phy_addr = get_property(phy, "reg", NULL); | |
618 | fs_enet_data.phy_addr = *phy_addr; | |
619 | ||
ed943c1f VB |
620 | phy_irq = get_property(phy, "interrupts", NULL); |
621 | ||
fba43665 VB |
622 | id = get_property(np, "device-id", NULL); |
623 | fs_enet_data.fs_no = *id; | |
611a15af | 624 | strcpy(fs_enet_data.fs_type, model); |
fba43665 VB |
625 | |
626 | mdio = of_get_parent(phy); | |
627 | ret = of_address_to_resource(mdio, 0, &res); | |
628 | if (ret) { | |
629 | of_node_put(phy); | |
630 | of_node_put(mdio); | |
631 | goto unreg; | |
632 | } | |
633 | ||
d3465c92 VB |
634 | fs_enet_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL)); |
635 | fs_enet_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL)); | |
636 | ||
fba43665 | 637 | if (strstr(model, "FCC")) { |
611a15af | 638 | int fcc_index = *id - 1; |
2b00b254 | 639 | const unsigned char *mdio_bb_prop; |
fba43665 | 640 | |
fc8e50e3 | 641 | fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0); |
fba43665 VB |
642 | fs_enet_data.rx_ring = 32; |
643 | fs_enet_data.tx_ring = 32; | |
644 | fs_enet_data.rx_copybreak = 240; | |
645 | fs_enet_data.use_napi = 0; | |
646 | fs_enet_data.napi_weight = 17; | |
647 | fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index); | |
648 | fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index); | |
649 | fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index); | |
650 | ||
651 | snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x", | |
652 | (u32)res.start, fs_enet_data.phy_addr); | |
653 | fs_enet_data.bus_id = (char*)&bus_id[(*id)]; | |
d3465c92 | 654 | fs_enet_data.init_ioports = init_fcc_ioports; |
fba43665 | 655 | |
ed943c1f VB |
656 | mdio_bb_prop = get_property(phy, "bitbang", NULL); |
657 | if (mdio_bb_prop) { | |
658 | struct platform_device *fs_enet_mdio_bb_dev; | |
659 | struct fs_mii_bb_platform_info fs_enet_mdio_bb_data; | |
660 | ||
661 | fs_enet_mdio_bb_dev = | |
662 | platform_device_register_simple("fsl-bb-mdio", | |
663 | i, NULL, 0); | |
664 | memset(&fs_enet_mdio_bb_data, 0, | |
665 | sizeof(struct fs_mii_bb_platform_info)); | |
666 | fs_enet_mdio_bb_data.mdio_dat.bit = | |
667 | mdio_bb_prop[0]; | |
668 | fs_enet_mdio_bb_data.mdio_dir.bit = | |
669 | mdio_bb_prop[1]; | |
670 | fs_enet_mdio_bb_data.mdc_dat.bit = | |
671 | mdio_bb_prop[2]; | |
672 | fs_enet_mdio_bb_data.mdio_port = | |
673 | mdio_bb_prop[3]; | |
674 | fs_enet_mdio_bb_data.mdc_port = | |
675 | mdio_bb_prop[4]; | |
676 | fs_enet_mdio_bb_data.delay = | |
677 | mdio_bb_prop[5]; | |
678 | ||
679 | fs_enet_mdio_bb_data.irq[0] = phy_irq[0]; | |
680 | fs_enet_mdio_bb_data.irq[1] = -1; | |
681 | fs_enet_mdio_bb_data.irq[2] = -1; | |
682 | fs_enet_mdio_bb_data.irq[3] = phy_irq[0]; | |
683 | fs_enet_mdio_bb_data.irq[31] = -1; | |
684 | ||
685 | fs_enet_mdio_bb_data.mdio_dat.offset = | |
686 | (u32)&cpm2_immr->im_ioport.iop_pdatc; | |
687 | fs_enet_mdio_bb_data.mdio_dir.offset = | |
688 | (u32)&cpm2_immr->im_ioport.iop_pdirc; | |
689 | fs_enet_mdio_bb_data.mdc_dat.offset = | |
690 | (u32)&cpm2_immr->im_ioport.iop_pdatc; | |
691 | ||
692 | ret = platform_device_add_data( | |
693 | fs_enet_mdio_bb_dev, | |
694 | &fs_enet_mdio_bb_data, | |
695 | sizeof(struct fs_mii_bb_platform_info)); | |
696 | if (ret) | |
697 | goto unreg; | |
698 | } | |
699 | ||
700 | of_node_put(phy); | |
701 | of_node_put(mdio); | |
fba43665 | 702 | |
ed943c1f VB |
703 | ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, |
704 | sizeof(struct | |
705 | fs_platform_info)); | |
2b00b254 OJ |
706 | if (ret) |
707 | goto unreg; | |
708 | } | |
fba43665 VB |
709 | } |
710 | return 0; | |
711 | ||
712 | unreg: | |
713 | platform_device_unregister(fs_enet_dev); | |
714 | err: | |
715 | return ret; | |
716 | } | |
717 | ||
718 | arch_initcall(fs_enet_of_init); | |
719 | ||
720 | static const char scc_regs[] = "regs"; | |
721 | static const char scc_pram[] = "pram"; | |
722 | ||
723 | static int __init cpm_uart_of_init(void) | |
724 | { | |
725 | struct device_node *np; | |
726 | unsigned int i; | |
727 | struct platform_device *cpm_uart_dev; | |
728 | int ret; | |
729 | ||
730 | for (np = NULL, i = 0; | |
731 | (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; | |
732 | i++) { | |
733 | struct resource r[3]; | |
734 | struct fs_uart_platform_info cpm_uart_data; | |
735 | const int *id; | |
611a15af | 736 | const char *model; |
fba43665 VB |
737 | |
738 | memset(r, 0, sizeof(r)); | |
739 | memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); | |
740 | ||
741 | ret = of_address_to_resource(np, 0, &r[0]); | |
742 | if (ret) | |
743 | goto err; | |
744 | ||
745 | r[0].name = scc_regs; | |
746 | ||
747 | ret = of_address_to_resource(np, 1, &r[1]); | |
748 | if (ret) | |
749 | goto err; | |
750 | r[1].name = scc_pram; | |
751 | ||
a9b14973 | 752 | of_irq_to_resource(np, 0, &r[2]); |
fba43665 VB |
753 | |
754 | cpm_uart_dev = | |
755 | platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3); | |
756 | ||
757 | if (IS_ERR(cpm_uart_dev)) { | |
758 | ret = PTR_ERR(cpm_uart_dev); | |
759 | goto err; | |
760 | } | |
761 | ||
762 | id = get_property(np, "device-id", NULL); | |
763 | cpm_uart_data.fs_no = *id; | |
611a15af VB |
764 | |
765 | model = (char*)get_property(np, "model", NULL); | |
766 | strcpy(cpm_uart_data.fs_type, model); | |
767 | ||
fba43665 VB |
768 | cpm_uart_data.uart_clk = ppc_proc_freq; |
769 | ||
770 | cpm_uart_data.tx_num_fifo = 4; | |
771 | cpm_uart_data.tx_buf_size = 32; | |
772 | cpm_uart_data.rx_num_fifo = 4; | |
773 | cpm_uart_data.rx_buf_size = 32; | |
d3465c92 VB |
774 | cpm_uart_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL)); |
775 | cpm_uart_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL)); | |
fba43665 VB |
776 | |
777 | ret = | |
778 | platform_device_add_data(cpm_uart_dev, &cpm_uart_data, | |
779 | sizeof(struct | |
780 | fs_uart_platform_info)); | |
781 | if (ret) | |
782 | goto unreg; | |
783 | } | |
784 | ||
785 | return 0; | |
786 | ||
787 | unreg: | |
788 | platform_device_unregister(cpm_uart_dev); | |
789 | err: | |
790 | return ret; | |
791 | } | |
792 | ||
793 | arch_initcall(cpm_uart_of_init); | |
794 | #endif /* CONFIG_CPM2 */ |