]>
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*); |
88bdc6f0 VB |
41 | extern void init_fec_ioports(struct fs_platform_info*); |
42 | extern void init_smc_ioports(struct fs_uart_platform_info*); | |
eed32001 KG |
43 | static phys_addr_t immrbase = -1; |
44 | ||
45 | phys_addr_t get_immrbase(void) | |
46 | { | |
47 | struct device_node *soc; | |
48 | ||
49 | if (immrbase != -1) | |
50 | return immrbase; | |
51 | ||
52 | soc = of_find_node_by_type(NULL, "soc"); | |
2fb07d77 | 53 | if (soc) { |
eed32001 | 54 | unsigned int size; |
a7f67bdf | 55 | const void *prop = get_property(soc, "reg", &size); |
fba43665 VB |
56 | |
57 | if (prop) | |
58 | immrbase = of_translate_address(soc, prop); | |
eed32001 KG |
59 | of_node_put(soc); |
60 | }; | |
61 | ||
62 | return immrbase; | |
63 | } | |
eed32001 | 64 | |
2fb07d77 | 65 | EXPORT_SYMBOL(get_immrbase); |
eed32001 | 66 | |
88bdc6f0 | 67 | #if defined(CONFIG_CPM2) || defined(CONFIG_8xx) |
fba43665 VB |
68 | |
69 | static u32 brgfreq = -1; | |
70 | ||
71 | u32 get_brgfreq(void) | |
72 | { | |
73 | struct device_node *node; | |
74 | ||
75 | if (brgfreq != -1) | |
76 | return brgfreq; | |
77 | ||
78 | node = of_find_node_by_type(NULL, "cpm"); | |
79 | if (node) { | |
80 | unsigned int size; | |
81 | const unsigned int *prop = get_property(node, "brg-frequency", | |
82 | &size); | |
83 | ||
84 | if (prop) | |
85 | brgfreq = *prop; | |
86 | of_node_put(node); | |
87 | }; | |
88 | ||
89 | return brgfreq; | |
90 | } | |
91 | ||
92 | EXPORT_SYMBOL(get_brgfreq); | |
93 | ||
94 | static u32 fs_baudrate = -1; | |
95 | ||
96 | u32 get_baudrate(void) | |
97 | { | |
98 | struct device_node *node; | |
99 | ||
100 | if (fs_baudrate != -1) | |
101 | return fs_baudrate; | |
102 | ||
103 | node = of_find_node_by_type(NULL, "serial"); | |
104 | if (node) { | |
105 | unsigned int size; | |
106 | const unsigned int *prop = get_property(node, "current-speed", | |
107 | &size); | |
108 | ||
109 | if (prop) | |
110 | fs_baudrate = *prop; | |
111 | of_node_put(node); | |
112 | }; | |
113 | ||
114 | return fs_baudrate; | |
115 | } | |
116 | ||
117 | EXPORT_SYMBOL(get_baudrate); | |
118 | #endif /* CONFIG_CPM2 */ | |
119 | ||
2fb07d77 | 120 | static int __init gfar_mdio_of_init(void) |
eed32001 KG |
121 | { |
122 | struct device_node *np; | |
123 | unsigned int i; | |
2fb07d77 | 124 | struct platform_device *mdio_dev; |
eed32001 KG |
125 | struct resource res; |
126 | int ret; | |
127 | ||
2fb07d77 KG |
128 | for (np = NULL, i = 0; |
129 | (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; | |
130 | i++) { | |
eed32001 KG |
131 | int k; |
132 | struct device_node *child = NULL; | |
133 | struct gianfar_mdio_data mdio_data; | |
134 | ||
135 | memset(&res, 0, sizeof(res)); | |
136 | memset(&mdio_data, 0, sizeof(mdio_data)); | |
137 | ||
138 | ret = of_address_to_resource(np, 0, &res); | |
139 | if (ret) | |
2fb07d77 | 140 | goto err; |
eed32001 | 141 | |
2fb07d77 KG |
142 | mdio_dev = |
143 | platform_device_register_simple("fsl-gianfar_mdio", | |
144 | res.start, &res, 1); | |
eed32001 KG |
145 | if (IS_ERR(mdio_dev)) { |
146 | ret = PTR_ERR(mdio_dev); | |
2fb07d77 | 147 | goto err; |
eed32001 KG |
148 | } |
149 | ||
150 | for (k = 0; k < 32; k++) | |
a9b14973 | 151 | mdio_data.irq[k] = PHY_POLL; |
eed32001 KG |
152 | |
153 | while ((child = of_get_next_child(np, child)) != NULL) { | |
fba43665 VB |
154 | int irq = irq_of_parse_and_map(child, 0); |
155 | if (irq != NO_IRQ) { | |
156 | const u32 *id = get_property(child, "reg", NULL); | |
157 | mdio_data.irq[*id] = irq; | |
158 | } | |
eed32001 KG |
159 | } |
160 | ||
2fb07d77 KG |
161 | ret = |
162 | platform_device_add_data(mdio_dev, &mdio_data, | |
163 | sizeof(struct gianfar_mdio_data)); | |
eed32001 | 164 | if (ret) |
2fb07d77 | 165 | goto unreg; |
eed32001 KG |
166 | } |
167 | ||
2fb07d77 KG |
168 | return 0; |
169 | ||
170 | unreg: | |
171 | platform_device_unregister(mdio_dev); | |
172 | err: | |
173 | return ret; | |
174 | } | |
175 | ||
176 | arch_initcall(gfar_mdio_of_init); | |
177 | ||
178 | static const char *gfar_tx_intr = "tx"; | |
179 | static const char *gfar_rx_intr = "rx"; | |
180 | static const char *gfar_err_intr = "error"; | |
181 | ||
a9b14973 | 182 | |
2fb07d77 KG |
183 | static int __init gfar_of_init(void) |
184 | { | |
185 | struct device_node *np; | |
186 | unsigned int i; | |
187 | struct platform_device *gfar_dev; | |
188 | struct resource res; | |
189 | int ret; | |
190 | ||
191 | for (np = NULL, i = 0; | |
192 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; | |
193 | i++) { | |
eed32001 KG |
194 | struct resource r[4]; |
195 | struct device_node *phy, *mdio; | |
196 | struct gianfar_platform_data gfar_data; | |
a7f67bdf JK |
197 | const unsigned int *id; |
198 | const char *model; | |
199 | const void *mac_addr; | |
200 | const phandle *ph; | |
fba43665 | 201 | int n_res = 2; |
eed32001 KG |
202 | |
203 | memset(r, 0, sizeof(r)); | |
204 | memset(&gfar_data, 0, sizeof(gfar_data)); | |
205 | ||
206 | ret = of_address_to_resource(np, 0, &r[0]); | |
207 | if (ret) | |
2fb07d77 | 208 | goto err; |
eed32001 | 209 | |
a9b14973 | 210 | of_irq_to_resource(np, 0, &r[1]); |
eed32001 KG |
211 | |
212 | model = get_property(np, "model", NULL); | |
213 | ||
214 | /* If we aren't the FEC we have multiple interrupts */ | |
215 | if (model && strcasecmp(model, "FEC")) { | |
216 | r[1].name = gfar_tx_intr; | |
217 | ||
218 | r[2].name = gfar_rx_intr; | |
a9b14973 | 219 | of_irq_to_resource(np, 1, &r[2]); |
eed32001 KG |
220 | |
221 | r[3].name = gfar_err_intr; | |
a9b14973 | 222 | of_irq_to_resource(np, 2, &r[3]); |
919fede6 JL |
223 | |
224 | n_res += 2; | |
eed32001 KG |
225 | } |
226 | ||
2fb07d77 KG |
227 | gfar_dev = |
228 | platform_device_register_simple("fsl-gianfar", i, &r[0], | |
fba43665 | 229 | n_res); |
eed32001 KG |
230 | |
231 | if (IS_ERR(gfar_dev)) { | |
232 | ret = PTR_ERR(gfar_dev); | |
2fb07d77 | 233 | goto err; |
eed32001 KG |
234 | } |
235 | ||
f583165f JL |
236 | mac_addr = get_property(np, "local-mac-address", NULL); |
237 | if (mac_addr == NULL) | |
238 | mac_addr = get_property(np, "mac-address", NULL); | |
239 | if (mac_addr == NULL) { | |
240 | /* Obsolete */ | |
241 | mac_addr = get_property(np, "address", NULL); | |
242 | } | |
243 | ||
244 | if (mac_addr) | |
245 | memcpy(gfar_data.mac_addr, mac_addr, 6); | |
eed32001 KG |
246 | |
247 | if (model && !strcasecmp(model, "TSEC")) | |
248 | gfar_data.device_flags = | |
2fb07d77 KG |
249 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
250 | FSL_GIANFAR_DEV_HAS_COALESCE | | |
251 | FSL_GIANFAR_DEV_HAS_RMON | | |
252 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; | |
eed32001 KG |
253 | if (model && !strcasecmp(model, "eTSEC")) |
254 | gfar_data.device_flags = | |
2fb07d77 KG |
255 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
256 | FSL_GIANFAR_DEV_HAS_COALESCE | | |
257 | FSL_GIANFAR_DEV_HAS_RMON | | |
258 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | | |
259 | FSL_GIANFAR_DEV_HAS_CSUM | | |
260 | FSL_GIANFAR_DEV_HAS_VLAN | | |
261 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; | |
eed32001 | 262 | |
a7f67bdf | 263 | ph = get_property(np, "phy-handle", NULL); |
eed32001 KG |
264 | phy = of_find_node_by_phandle(*ph); |
265 | ||
266 | if (phy == NULL) { | |
267 | ret = -ENODEV; | |
2fb07d77 | 268 | goto unreg; |
eed32001 KG |
269 | } |
270 | ||
271 | mdio = of_get_parent(phy); | |
272 | ||
a7f67bdf | 273 | id = get_property(phy, "reg", NULL); |
eed32001 KG |
274 | ret = of_address_to_resource(mdio, 0, &res); |
275 | if (ret) { | |
276 | of_node_put(phy); | |
277 | of_node_put(mdio); | |
2fb07d77 | 278 | goto unreg; |
eed32001 KG |
279 | } |
280 | ||
281 | gfar_data.phy_id = *id; | |
282 | gfar_data.bus_id = res.start; | |
283 | ||
284 | of_node_put(phy); | |
285 | of_node_put(mdio); | |
286 | ||
2fb07d77 KG |
287 | ret = |
288 | platform_device_add_data(gfar_dev, &gfar_data, | |
289 | sizeof(struct | |
290 | gianfar_platform_data)); | |
eed32001 | 291 | if (ret) |
2fb07d77 | 292 | goto unreg; |
eed32001 KG |
293 | } |
294 | ||
295 | return 0; | |
296 | ||
2fb07d77 | 297 | unreg: |
eed32001 | 298 | platform_device_unregister(gfar_dev); |
2fb07d77 | 299 | err: |
eed32001 KG |
300 | return ret; |
301 | } | |
2fb07d77 | 302 | |
eed32001 KG |
303 | arch_initcall(gfar_of_init); |
304 | ||
305 | static int __init fsl_i2c_of_init(void) | |
306 | { | |
307 | struct device_node *np; | |
308 | unsigned int i; | |
309 | struct platform_device *i2c_dev; | |
310 | int ret; | |
311 | ||
2fb07d77 KG |
312 | for (np = NULL, i = 0; |
313 | (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; | |
314 | i++) { | |
eed32001 KG |
315 | struct resource r[2]; |
316 | struct fsl_i2c_platform_data i2c_data; | |
a7f67bdf | 317 | const unsigned char *flags = NULL; |
eed32001 KG |
318 | |
319 | memset(&r, 0, sizeof(r)); | |
320 | memset(&i2c_data, 0, sizeof(i2c_data)); | |
321 | ||
322 | ret = of_address_to_resource(np, 0, &r[0]); | |
323 | if (ret) | |
2fb07d77 | 324 | goto err; |
eed32001 | 325 | |
a9b14973 | 326 | of_irq_to_resource(np, 0, &r[1]); |
eed32001 KG |
327 | |
328 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); | |
329 | if (IS_ERR(i2c_dev)) { | |
330 | ret = PTR_ERR(i2c_dev); | |
2fb07d77 | 331 | goto err; |
eed32001 KG |
332 | } |
333 | ||
334 | i2c_data.device_flags = 0; | |
335 | flags = get_property(np, "dfsrr", NULL); | |
336 | if (flags) | |
337 | i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR; | |
338 | ||
339 | flags = get_property(np, "fsl5200-clocking", NULL); | |
340 | if (flags) | |
341 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; | |
342 | ||
2fb07d77 KG |
343 | ret = |
344 | platform_device_add_data(i2c_dev, &i2c_data, | |
345 | sizeof(struct | |
346 | fsl_i2c_platform_data)); | |
eed32001 | 347 | if (ret) |
2fb07d77 | 348 | goto unreg; |
eed32001 KG |
349 | } |
350 | ||
351 | return 0; | |
352 | ||
2fb07d77 | 353 | unreg: |
eed32001 | 354 | platform_device_unregister(i2c_dev); |
2fb07d77 | 355 | err: |
eed32001 KG |
356 | return ret; |
357 | } | |
2fb07d77 | 358 | |
eed32001 KG |
359 | arch_initcall(fsl_i2c_of_init); |
360 | ||
361 | #ifdef CONFIG_PPC_83xx | |
362 | static int __init mpc83xx_wdt_init(void) | |
363 | { | |
364 | struct resource r; | |
365 | struct device_node *soc, *np; | |
366 | struct platform_device *dev; | |
a7f67bdf | 367 | const unsigned int *freq; |
eed32001 KG |
368 | int ret; |
369 | ||
370 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); | |
371 | ||
372 | if (!np) { | |
373 | ret = -ENODEV; | |
2fb07d77 | 374 | goto nodev; |
eed32001 KG |
375 | } |
376 | ||
377 | soc = of_find_node_by_type(NULL, "soc"); | |
378 | ||
379 | if (!soc) { | |
380 | ret = -ENODEV; | |
2fb07d77 | 381 | goto nosoc; |
eed32001 KG |
382 | } |
383 | ||
a7f67bdf | 384 | freq = get_property(soc, "bus-frequency", NULL); |
eed32001 KG |
385 | if (!freq) { |
386 | ret = -ENODEV; | |
2fb07d77 | 387 | goto err; |
eed32001 KG |
388 | } |
389 | ||
390 | memset(&r, 0, sizeof(r)); | |
391 | ||
392 | ret = of_address_to_resource(np, 0, &r); | |
393 | if (ret) | |
2fb07d77 | 394 | goto err; |
eed32001 KG |
395 | |
396 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); | |
397 | if (IS_ERR(dev)) { | |
398 | ret = PTR_ERR(dev); | |
2fb07d77 | 399 | goto err; |
eed32001 KG |
400 | } |
401 | ||
402 | ret = platform_device_add_data(dev, freq, sizeof(int)); | |
403 | if (ret) | |
2fb07d77 | 404 | goto unreg; |
eed32001 KG |
405 | |
406 | of_node_put(soc); | |
407 | of_node_put(np); | |
408 | ||
409 | return 0; | |
410 | ||
2fb07d77 | 411 | unreg: |
eed32001 | 412 | platform_device_unregister(dev); |
2fb07d77 | 413 | err: |
eed32001 | 414 | of_node_put(soc); |
2fb07d77 | 415 | nosoc: |
eed32001 | 416 | of_node_put(np); |
2fb07d77 | 417 | nodev: |
eed32001 KG |
418 | return ret; |
419 | } | |
2fb07d77 | 420 | |
eed32001 KG |
421 | arch_initcall(mpc83xx_wdt_init); |
422 | #endif | |
4b10cfd4 | 423 | |
a7f67bdf | 424 | static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type) |
4b10cfd4 KG |
425 | { |
426 | if (!phy_type) | |
427 | return FSL_USB2_PHY_NONE; | |
428 | if (!strcasecmp(phy_type, "ulpi")) | |
429 | return FSL_USB2_PHY_ULPI; | |
430 | if (!strcasecmp(phy_type, "utmi")) | |
431 | return FSL_USB2_PHY_UTMI; | |
432 | if (!strcasecmp(phy_type, "utmi_wide")) | |
433 | return FSL_USB2_PHY_UTMI_WIDE; | |
434 | if (!strcasecmp(phy_type, "serial")) | |
435 | return FSL_USB2_PHY_SERIAL; | |
436 | ||
437 | return FSL_USB2_PHY_NONE; | |
438 | } | |
439 | ||
440 | static int __init fsl_usb_of_init(void) | |
441 | { | |
442 | struct device_node *np; | |
443 | unsigned int i; | |
01cced25 | 444 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL; |
4b10cfd4 KG |
445 | int ret; |
446 | ||
447 | for (np = NULL, i = 0; | |
448 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL; | |
449 | i++) { | |
450 | struct resource r[2]; | |
451 | struct fsl_usb2_platform_data usb_data; | |
a7f67bdf | 452 | const unsigned char *prop = NULL; |
4b10cfd4 KG |
453 | |
454 | memset(&r, 0, sizeof(r)); | |
455 | memset(&usb_data, 0, sizeof(usb_data)); | |
456 | ||
457 | ret = of_address_to_resource(np, 0, &r[0]); | |
458 | if (ret) | |
459 | goto err; | |
460 | ||
a9b14973 | 461 | of_irq_to_resource(np, 0, &r[1]); |
4b10cfd4 | 462 | |
01cced25 KG |
463 | usb_dev_mph = |
464 | platform_device_register_simple("fsl-ehci", i, r, 2); | |
465 | if (IS_ERR(usb_dev_mph)) { | |
466 | ret = PTR_ERR(usb_dev_mph); | |
4b10cfd4 KG |
467 | goto err; |
468 | } | |
469 | ||
01cced25 KG |
470 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; |
471 | usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask; | |
4b10cfd4 KG |
472 | |
473 | usb_data.operating_mode = FSL_USB2_MPH_HOST; | |
474 | ||
475 | prop = get_property(np, "port0", NULL); | |
476 | if (prop) | |
477 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; | |
478 | ||
479 | prop = get_property(np, "port1", NULL); | |
480 | if (prop) | |
481 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; | |
482 | ||
483 | prop = get_property(np, "phy_type", NULL); | |
484 | usb_data.phy_mode = determine_usb_phy(prop); | |
485 | ||
486 | ret = | |
01cced25 | 487 | platform_device_add_data(usb_dev_mph, &usb_data, |
4b10cfd4 KG |
488 | sizeof(struct |
489 | fsl_usb2_platform_data)); | |
490 | if (ret) | |
01cced25 | 491 | goto unreg_mph; |
4b10cfd4 KG |
492 | } |
493 | ||
01cced25 | 494 | for (np = NULL; |
4b10cfd4 KG |
495 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL; |
496 | i++) { | |
497 | struct resource r[2]; | |
498 | struct fsl_usb2_platform_data usb_data; | |
a7f67bdf | 499 | const unsigned char *prop = NULL; |
4b10cfd4 KG |
500 | |
501 | memset(&r, 0, sizeof(r)); | |
502 | memset(&usb_data, 0, sizeof(usb_data)); | |
503 | ||
504 | ret = of_address_to_resource(np, 0, &r[0]); | |
505 | if (ret) | |
01cced25 | 506 | goto unreg_mph; |
4b10cfd4 | 507 | |
a9b14973 | 508 | of_irq_to_resource(np, 0, &r[1]); |
4b10cfd4 | 509 | |
01cced25 KG |
510 | usb_dev_dr = |
511 | platform_device_register_simple("fsl-ehci", i, r, 2); | |
512 | if (IS_ERR(usb_dev_dr)) { | |
513 | ret = PTR_ERR(usb_dev_dr); | |
4b10cfd4 KG |
514 | goto err; |
515 | } | |
516 | ||
01cced25 KG |
517 | usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL; |
518 | usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask; | |
4b10cfd4 KG |
519 | |
520 | usb_data.operating_mode = FSL_USB2_DR_HOST; | |
521 | ||
522 | prop = get_property(np, "phy_type", NULL); | |
523 | usb_data.phy_mode = determine_usb_phy(prop); | |
524 | ||
525 | ret = | |
01cced25 | 526 | platform_device_add_data(usb_dev_dr, &usb_data, |
4b10cfd4 KG |
527 | sizeof(struct |
528 | fsl_usb2_platform_data)); | |
529 | if (ret) | |
01cced25 | 530 | goto unreg_dr; |
4b10cfd4 | 531 | } |
4b10cfd4 KG |
532 | return 0; |
533 | ||
01cced25 KG |
534 | unreg_dr: |
535 | if (usb_dev_dr) | |
536 | platform_device_unregister(usb_dev_dr); | |
537 | unreg_mph: | |
538 | if (usb_dev_mph) | |
539 | platform_device_unregister(usb_dev_mph); | |
4b10cfd4 KG |
540 | err: |
541 | return ret; | |
542 | } | |
543 | ||
01cced25 | 544 | arch_initcall(fsl_usb_of_init); |
fba43665 VB |
545 | |
546 | #ifdef CONFIG_CPM2 | |
547 | ||
88bdc6f0 VB |
548 | extern void init_scc_ioports(struct fs_uart_platform_info*); |
549 | ||
fba43665 VB |
550 | static const char fcc_regs[] = "fcc_regs"; |
551 | static const char fcc_regs_c[] = "fcc_regs_c"; | |
552 | static const char fcc_pram[] = "fcc_pram"; | |
553 | static char bus_id[9][BUS_ID_SIZE]; | |
554 | ||
555 | static int __init fs_enet_of_init(void) | |
556 | { | |
557 | struct device_node *np; | |
558 | unsigned int i; | |
559 | struct platform_device *fs_enet_dev; | |
560 | struct resource res; | |
561 | int ret; | |
562 | ||
563 | for (np = NULL, i = 0; | |
564 | (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; | |
565 | i++) { | |
566 | struct resource r[4]; | |
567 | struct device_node *phy, *mdio; | |
568 | struct fs_platform_info fs_enet_data; | |
2b00b254 | 569 | const unsigned int *id, *phy_addr, *phy_irq; |
fba43665 VB |
570 | const void *mac_addr; |
571 | const phandle *ph; | |
572 | const char *model; | |
573 | ||
574 | memset(r, 0, sizeof(r)); | |
575 | memset(&fs_enet_data, 0, sizeof(fs_enet_data)); | |
576 | ||
577 | ret = of_address_to_resource(np, 0, &r[0]); | |
578 | if (ret) | |
579 | goto err; | |
580 | r[0].name = fcc_regs; | |
581 | ||
582 | ret = of_address_to_resource(np, 1, &r[1]); | |
583 | if (ret) | |
584 | goto err; | |
585 | r[1].name = fcc_pram; | |
586 | ||
587 | ret = of_address_to_resource(np, 2, &r[2]); | |
588 | if (ret) | |
589 | goto err; | |
590 | r[2].name = fcc_regs_c; | |
ed943c1f | 591 | fs_enet_data.fcc_regs_c = r[2].start; |
fba43665 | 592 | |
a9b14973 | 593 | of_irq_to_resource(np, 0, &r[3]); |
fba43665 VB |
594 | |
595 | fs_enet_dev = | |
596 | platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4); | |
597 | ||
598 | if (IS_ERR(fs_enet_dev)) { | |
599 | ret = PTR_ERR(fs_enet_dev); | |
600 | goto err; | |
601 | } | |
602 | ||
603 | model = get_property(np, "model", NULL); | |
604 | if (model == NULL) { | |
605 | ret = -ENODEV; | |
606 | goto unreg; | |
607 | } | |
608 | ||
609 | mac_addr = get_property(np, "mac-address", NULL); | |
610 | memcpy(fs_enet_data.macaddr, mac_addr, 6); | |
611 | ||
612 | ph = get_property(np, "phy-handle", NULL); | |
613 | phy = of_find_node_by_phandle(*ph); | |
614 | ||
615 | if (phy == NULL) { | |
616 | ret = -ENODEV; | |
617 | goto unreg; | |
618 | } | |
619 | ||
620 | phy_addr = get_property(phy, "reg", NULL); | |
621 | fs_enet_data.phy_addr = *phy_addr; | |
622 | ||
ed943c1f VB |
623 | phy_irq = get_property(phy, "interrupts", NULL); |
624 | ||
fba43665 VB |
625 | id = get_property(np, "device-id", NULL); |
626 | fs_enet_data.fs_no = *id; | |
611a15af | 627 | strcpy(fs_enet_data.fs_type, model); |
fba43665 VB |
628 | |
629 | mdio = of_get_parent(phy); | |
630 | ret = of_address_to_resource(mdio, 0, &res); | |
631 | if (ret) { | |
632 | of_node_put(phy); | |
633 | of_node_put(mdio); | |
634 | goto unreg; | |
635 | } | |
636 | ||
d3465c92 VB |
637 | fs_enet_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL)); |
638 | fs_enet_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL)); | |
639 | ||
fba43665 | 640 | if (strstr(model, "FCC")) { |
611a15af | 641 | int fcc_index = *id - 1; |
2b00b254 | 642 | const unsigned char *mdio_bb_prop; |
fba43665 | 643 | |
fc8e50e3 | 644 | fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0); |
fba43665 VB |
645 | fs_enet_data.rx_ring = 32; |
646 | fs_enet_data.tx_ring = 32; | |
647 | fs_enet_data.rx_copybreak = 240; | |
648 | fs_enet_data.use_napi = 0; | |
649 | fs_enet_data.napi_weight = 17; | |
650 | fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index); | |
651 | fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index); | |
652 | fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index); | |
653 | ||
654 | snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x", | |
655 | (u32)res.start, fs_enet_data.phy_addr); | |
656 | fs_enet_data.bus_id = (char*)&bus_id[(*id)]; | |
d3465c92 | 657 | fs_enet_data.init_ioports = init_fcc_ioports; |
fba43665 | 658 | |
ed943c1f VB |
659 | mdio_bb_prop = get_property(phy, "bitbang", NULL); |
660 | if (mdio_bb_prop) { | |
661 | struct platform_device *fs_enet_mdio_bb_dev; | |
662 | struct fs_mii_bb_platform_info fs_enet_mdio_bb_data; | |
663 | ||
664 | fs_enet_mdio_bb_dev = | |
665 | platform_device_register_simple("fsl-bb-mdio", | |
666 | i, NULL, 0); | |
667 | memset(&fs_enet_mdio_bb_data, 0, | |
668 | sizeof(struct fs_mii_bb_platform_info)); | |
669 | fs_enet_mdio_bb_data.mdio_dat.bit = | |
670 | mdio_bb_prop[0]; | |
671 | fs_enet_mdio_bb_data.mdio_dir.bit = | |
672 | mdio_bb_prop[1]; | |
673 | fs_enet_mdio_bb_data.mdc_dat.bit = | |
674 | mdio_bb_prop[2]; | |
675 | fs_enet_mdio_bb_data.mdio_port = | |
676 | mdio_bb_prop[3]; | |
677 | fs_enet_mdio_bb_data.mdc_port = | |
678 | mdio_bb_prop[4]; | |
679 | fs_enet_mdio_bb_data.delay = | |
680 | mdio_bb_prop[5]; | |
681 | ||
682 | fs_enet_mdio_bb_data.irq[0] = phy_irq[0]; | |
683 | fs_enet_mdio_bb_data.irq[1] = -1; | |
684 | fs_enet_mdio_bb_data.irq[2] = -1; | |
685 | fs_enet_mdio_bb_data.irq[3] = phy_irq[0]; | |
686 | fs_enet_mdio_bb_data.irq[31] = -1; | |
687 | ||
688 | fs_enet_mdio_bb_data.mdio_dat.offset = | |
689 | (u32)&cpm2_immr->im_ioport.iop_pdatc; | |
690 | fs_enet_mdio_bb_data.mdio_dir.offset = | |
691 | (u32)&cpm2_immr->im_ioport.iop_pdirc; | |
692 | fs_enet_mdio_bb_data.mdc_dat.offset = | |
693 | (u32)&cpm2_immr->im_ioport.iop_pdatc; | |
694 | ||
695 | ret = platform_device_add_data( | |
696 | fs_enet_mdio_bb_dev, | |
697 | &fs_enet_mdio_bb_data, | |
698 | sizeof(struct fs_mii_bb_platform_info)); | |
699 | if (ret) | |
700 | goto unreg; | |
701 | } | |
702 | ||
703 | of_node_put(phy); | |
704 | of_node_put(mdio); | |
fba43665 | 705 | |
ed943c1f VB |
706 | ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, |
707 | sizeof(struct | |
708 | fs_platform_info)); | |
2b00b254 OJ |
709 | if (ret) |
710 | goto unreg; | |
711 | } | |
fba43665 VB |
712 | } |
713 | return 0; | |
714 | ||
715 | unreg: | |
716 | platform_device_unregister(fs_enet_dev); | |
717 | err: | |
718 | return ret; | |
719 | } | |
720 | ||
721 | arch_initcall(fs_enet_of_init); | |
722 | ||
723 | static const char scc_regs[] = "regs"; | |
724 | static const char scc_pram[] = "pram"; | |
725 | ||
726 | static int __init cpm_uart_of_init(void) | |
727 | { | |
728 | struct device_node *np; | |
729 | unsigned int i; | |
730 | struct platform_device *cpm_uart_dev; | |
731 | int ret; | |
732 | ||
733 | for (np = NULL, i = 0; | |
734 | (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; | |
735 | i++) { | |
736 | struct resource r[3]; | |
737 | struct fs_uart_platform_info cpm_uart_data; | |
738 | const int *id; | |
611a15af | 739 | const char *model; |
fba43665 VB |
740 | |
741 | memset(r, 0, sizeof(r)); | |
742 | memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); | |
743 | ||
744 | ret = of_address_to_resource(np, 0, &r[0]); | |
745 | if (ret) | |
746 | goto err; | |
747 | ||
748 | r[0].name = scc_regs; | |
749 | ||
750 | ret = of_address_to_resource(np, 1, &r[1]); | |
751 | if (ret) | |
752 | goto err; | |
753 | r[1].name = scc_pram; | |
754 | ||
a9b14973 | 755 | of_irq_to_resource(np, 0, &r[2]); |
fba43665 VB |
756 | |
757 | cpm_uart_dev = | |
758 | platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3); | |
759 | ||
760 | if (IS_ERR(cpm_uart_dev)) { | |
761 | ret = PTR_ERR(cpm_uart_dev); | |
762 | goto err; | |
763 | } | |
764 | ||
765 | id = get_property(np, "device-id", NULL); | |
766 | cpm_uart_data.fs_no = *id; | |
611a15af VB |
767 | |
768 | model = (char*)get_property(np, "model", NULL); | |
769 | strcpy(cpm_uart_data.fs_type, model); | |
770 | ||
fba43665 VB |
771 | cpm_uart_data.uart_clk = ppc_proc_freq; |
772 | ||
773 | cpm_uart_data.tx_num_fifo = 4; | |
774 | cpm_uart_data.tx_buf_size = 32; | |
775 | cpm_uart_data.rx_num_fifo = 4; | |
776 | cpm_uart_data.rx_buf_size = 32; | |
d3465c92 VB |
777 | cpm_uart_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL)); |
778 | cpm_uart_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL)); | |
fba43665 VB |
779 | |
780 | ret = | |
781 | platform_device_add_data(cpm_uart_dev, &cpm_uart_data, | |
782 | sizeof(struct | |
783 | fs_uart_platform_info)); | |
784 | if (ret) | |
785 | goto unreg; | |
786 | } | |
787 | ||
788 | return 0; | |
789 | ||
790 | unreg: | |
791 | platform_device_unregister(cpm_uart_dev); | |
792 | err: | |
793 | return ret; | |
794 | } | |
795 | ||
796 | arch_initcall(cpm_uart_of_init); | |
797 | #endif /* CONFIG_CPM2 */ | |
88bdc6f0 VB |
798 | |
799 | #ifdef CONFIG_8xx | |
800 | ||
801 | extern void init_scc_ioports(struct fs_platform_info*); | |
802 | extern int platform_device_skip(char *model, int id); | |
803 | ||
804 | static int __init fs_enet_mdio_of_init(void) | |
805 | { | |
806 | struct device_node *np; | |
807 | unsigned int i; | |
808 | struct platform_device *mdio_dev; | |
809 | struct resource res; | |
810 | int ret; | |
811 | ||
812 | for (np = NULL, i = 0; | |
813 | (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL; | |
814 | i++) { | |
815 | struct fs_mii_fec_platform_info mdio_data; | |
816 | ||
817 | memset(&res, 0, sizeof(res)); | |
818 | memset(&mdio_data, 0, sizeof(mdio_data)); | |
819 | ||
820 | ret = of_address_to_resource(np, 0, &res); | |
821 | if (ret) | |
822 | goto err; | |
823 | ||
824 | mdio_dev = | |
825 | platform_device_register_simple("fsl-cpm-fec-mdio", | |
826 | res.start, &res, 1); | |
827 | if (IS_ERR(mdio_dev)) { | |
828 | ret = PTR_ERR(mdio_dev); | |
829 | goto err; | |
830 | } | |
831 | ||
832 | mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1; | |
833 | ||
834 | ret = | |
835 | platform_device_add_data(mdio_dev, &mdio_data, | |
836 | sizeof(struct fs_mii_fec_platform_info)); | |
837 | if (ret) | |
838 | goto unreg; | |
839 | } | |
840 | return 0; | |
841 | ||
842 | unreg: | |
843 | platform_device_unregister(mdio_dev); | |
844 | err: | |
845 | return ret; | |
846 | } | |
847 | ||
848 | arch_initcall(fs_enet_mdio_of_init); | |
849 | ||
850 | static const char *enet_regs = "regs"; | |
851 | static const char *enet_pram = "pram"; | |
852 | static const char *enet_irq = "interrupt"; | |
853 | static char bus_id[9][BUS_ID_SIZE]; | |
854 | ||
855 | static int __init fs_enet_of_init(void) | |
856 | { | |
857 | struct device_node *np; | |
858 | unsigned int i; | |
859 | struct platform_device *fs_enet_dev = NULL; | |
860 | struct resource res; | |
861 | int ret; | |
862 | ||
863 | for (np = NULL, i = 0; | |
864 | (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; | |
865 | i++) { | |
866 | struct resource r[4]; | |
867 | struct device_node *phy = NULL, *mdio = NULL; | |
868 | struct fs_platform_info fs_enet_data; | |
869 | unsigned int *id, *phy_addr; | |
870 | void *mac_addr; | |
871 | phandle *ph; | |
872 | char *model; | |
873 | ||
874 | memset(r, 0, sizeof(r)); | |
875 | memset(&fs_enet_data, 0, sizeof(fs_enet_data)); | |
876 | ||
877 | model = (char *)get_property(np, "model", NULL); | |
878 | if (model == NULL) { | |
879 | ret = -ENODEV; | |
880 | goto unreg; | |
881 | } | |
882 | ||
883 | id = (u32 *) get_property(np, "device-id", NULL); | |
884 | fs_enet_data.fs_no = *id; | |
885 | ||
886 | if (platform_device_skip(model, *id)) | |
887 | continue; | |
888 | ||
889 | ret = of_address_to_resource(np, 0, &r[0]); | |
890 | if (ret) | |
891 | goto err; | |
892 | r[0].name = enet_regs; | |
893 | ||
894 | mac_addr = (void *)get_property(np, "mac-address", NULL); | |
895 | memcpy(fs_enet_data.macaddr, mac_addr, 6); | |
896 | ||
897 | ph = (phandle *) get_property(np, "phy-handle", NULL); | |
898 | if (ph != NULL) | |
899 | phy = of_find_node_by_phandle(*ph); | |
900 | ||
901 | if (phy != NULL) { | |
902 | phy_addr = (u32 *) get_property(phy, "reg", NULL); | |
903 | fs_enet_data.phy_addr = *phy_addr; | |
904 | fs_enet_data.has_phy = 1; | |
905 | ||
906 | mdio = of_get_parent(phy); | |
907 | ret = of_address_to_resource(mdio, 0, &res); | |
908 | if (ret) { | |
909 | of_node_put(phy); | |
910 | of_node_put(mdio); | |
911 | goto unreg; | |
912 | } | |
913 | } | |
914 | ||
915 | model = (char*)get_property(np, "model", NULL); | |
916 | strcpy(fs_enet_data.fs_type, model); | |
917 | ||
918 | if (strstr(model, "FEC")) { | |
919 | r[1].start = r[1].end = irq_of_parse_and_map(np, 0); | |
920 | r[1].flags = IORESOURCE_IRQ; | |
921 | r[1].name = enet_irq; | |
922 | ||
923 | fs_enet_dev = | |
924 | platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2); | |
925 | ||
926 | if (IS_ERR(fs_enet_dev)) { | |
927 | ret = PTR_ERR(fs_enet_dev); | |
928 | goto err; | |
929 | } | |
930 | ||
931 | fs_enet_data.rx_ring = 128; | |
932 | fs_enet_data.tx_ring = 16; | |
933 | fs_enet_data.rx_copybreak = 240; | |
934 | fs_enet_data.use_napi = 1; | |
935 | fs_enet_data.napi_weight = 17; | |
936 | ||
937 | snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x", | |
938 | (u32)res.start, fs_enet_data.phy_addr); | |
939 | fs_enet_data.bus_id = (char*)&bus_id[i]; | |
940 | fs_enet_data.init_ioports = init_fec_ioports; | |
941 | } | |
942 | if (strstr(model, "SCC")) { | |
943 | ret = of_address_to_resource(np, 1, &r[1]); | |
944 | if (ret) | |
945 | goto err; | |
946 | r[1].name = enet_pram; | |
947 | ||
948 | r[2].start = r[2].end = irq_of_parse_and_map(np, 0); | |
949 | r[2].flags = IORESOURCE_IRQ; | |
950 | r[2].name = enet_irq; | |
951 | ||
952 | fs_enet_dev = | |
953 | platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3); | |
954 | ||
955 | if (IS_ERR(fs_enet_dev)) { | |
956 | ret = PTR_ERR(fs_enet_dev); | |
957 | goto err; | |
958 | } | |
959 | ||
960 | fs_enet_data.rx_ring = 64; | |
961 | fs_enet_data.tx_ring = 8; | |
962 | fs_enet_data.rx_copybreak = 240; | |
963 | fs_enet_data.use_napi = 1; | |
964 | fs_enet_data.napi_weight = 17; | |
965 | ||
966 | snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1"); | |
967 | fs_enet_data.bus_id = (char*)&bus_id[i]; | |
968 | fs_enet_data.init_ioports = init_scc_ioports; | |
969 | } | |
970 | ||
971 | of_node_put(phy); | |
972 | of_node_put(mdio); | |
973 | ||
974 | ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, | |
975 | sizeof(struct | |
976 | fs_platform_info)); | |
977 | if (ret) | |
978 | goto unreg; | |
979 | } | |
980 | return 0; | |
981 | ||
982 | unreg: | |
983 | platform_device_unregister(fs_enet_dev); | |
984 | err: | |
985 | return ret; | |
986 | } | |
987 | ||
988 | arch_initcall(fs_enet_of_init); | |
989 | ||
990 | ||
991 | static const char *smc_regs = "regs"; | |
992 | static const char *smc_pram = "pram"; | |
993 | ||
994 | static int __init cpm_smc_uart_of_init(void) | |
995 | { | |
996 | struct device_node *np; | |
997 | unsigned int i; | |
998 | struct platform_device *cpm_uart_dev; | |
999 | int ret; | |
1000 | ||
1001 | for (np = NULL, i = 0; | |
1002 | (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; | |
1003 | i++) { | |
1004 | struct resource r[3]; | |
1005 | struct fs_uart_platform_info cpm_uart_data; | |
1006 | int *id; | |
1007 | char *model; | |
1008 | ||
1009 | memset(r, 0, sizeof(r)); | |
1010 | memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); | |
1011 | ||
1012 | ret = of_address_to_resource(np, 0, &r[0]); | |
1013 | if (ret) | |
1014 | goto err; | |
1015 | ||
1016 | r[0].name = smc_regs; | |
1017 | ||
1018 | ret = of_address_to_resource(np, 1, &r[1]); | |
1019 | if (ret) | |
1020 | goto err; | |
1021 | r[1].name = smc_pram; | |
1022 | ||
1023 | r[2].start = r[2].end = irq_of_parse_and_map(np, 0); | |
1024 | r[2].flags = IORESOURCE_IRQ; | |
1025 | ||
1026 | cpm_uart_dev = | |
1027 | platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3); | |
1028 | ||
1029 | if (IS_ERR(cpm_uart_dev)) { | |
1030 | ret = PTR_ERR(cpm_uart_dev); | |
1031 | goto err; | |
1032 | } | |
1033 | ||
1034 | model = (char*)get_property(np, "model", NULL); | |
1035 | strcpy(cpm_uart_data.fs_type, model); | |
1036 | ||
1037 | id = (int*)get_property(np, "device-id", NULL); | |
1038 | cpm_uart_data.fs_no = *id; | |
1039 | cpm_uart_data.uart_clk = ppc_proc_freq; | |
1040 | ||
1041 | cpm_uart_data.tx_num_fifo = 4; | |
1042 | cpm_uart_data.tx_buf_size = 32; | |
1043 | cpm_uart_data.rx_num_fifo = 4; | |
1044 | cpm_uart_data.rx_buf_size = 32; | |
1045 | ||
1046 | ret = | |
1047 | platform_device_add_data(cpm_uart_dev, &cpm_uart_data, | |
1048 | sizeof(struct | |
1049 | fs_uart_platform_info)); | |
1050 | if (ret) | |
1051 | goto unreg; | |
1052 | } | |
1053 | ||
1054 | return 0; | |
1055 | ||
1056 | unreg: | |
1057 | platform_device_unregister(cpm_uart_dev); | |
1058 | err: | |
1059 | return ret; | |
1060 | } | |
1061 | ||
1062 | arch_initcall(cpm_smc_uart_of_init); | |
1063 | ||
1064 | #endif /* CONFIG_8xx */ |