blob: 022ed275ea6890c2084ee34c8d21d82c5163d06a [file] [log] [blame]
Kumar Galaeed32002006-01-13 11:19:13 -06001/*
2 * FSL SoC setup code
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5 *
Vitaly Bordugfba43662006-09-21 17:26:34 +04006 * 2006 (c) MontaVista Software, Inc.
7 * Vitaly Bordug <vbordug@ru.mvista.com>
8 *
Kumar Galaeed32002006-01-13 11:19:13 -06009 * 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
Kumar Galaeed32002006-01-13 11:19:13 -060015#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>
25#include <linux/fsl_devices.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040026#include <linux/fs_enet_pd.h>
27#include <linux/fs_uart_pd.h>
Kumar Galaeed32002006-01-13 11:19:13 -060028
29#include <asm/system.h>
30#include <asm/atomic.h>
31#include <asm/io.h>
32#include <asm/irq.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040033#include <asm/time.h>
Kumar Galaeed32002006-01-13 11:19:13 -060034#include <asm/prom.h>
35#include <sysdev/fsl_soc.h>
36#include <mm/mmu_decl.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040037#include <asm/cpm2.h>
Kumar Galaeed32002006-01-13 11:19:13 -060038
Vitaly Bordugd3465c92006-09-21 22:38:05 +040039extern void init_fcc_ioports(struct fs_platform_info*);
Kumar Galaeed32002006-01-13 11:19:13 -060040static phys_addr_t immrbase = -1;
41
42phys_addr_t get_immrbase(void)
43{
44 struct device_node *soc;
45
46 if (immrbase != -1)
47 return immrbase;
48
49 soc = of_find_node_by_type(NULL, "soc");
Kumar Gala2fb07d72006-01-23 16:58:04 -060050 if (soc) {
Kumar Galaeed32002006-01-13 11:19:13 -060051 unsigned int size;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100052 const void *prop = get_property(soc, "reg", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040053
54 if (prop)
55 immrbase = of_translate_address(soc, prop);
Kumar Galaeed32002006-01-13 11:19:13 -060056 of_node_put(soc);
57 };
58
59 return immrbase;
60}
Kumar Gala2fb07d72006-01-23 16:58:04 -060061
Kumar Galaeed32002006-01-13 11:19:13 -060062EXPORT_SYMBOL(get_immrbase);
63
Vitaly Bordugfba43662006-09-21 17:26:34 +040064#ifdef CONFIG_CPM2
65
66static u32 brgfreq = -1;
67
68u32 get_brgfreq(void)
69{
70 struct device_node *node;
71
72 if (brgfreq != -1)
73 return brgfreq;
74
75 node = of_find_node_by_type(NULL, "cpm");
76 if (node) {
77 unsigned int size;
78 const unsigned int *prop = get_property(node, "brg-frequency",
79 &size);
80
81 if (prop)
82 brgfreq = *prop;
83 of_node_put(node);
84 };
85
86 return brgfreq;
87}
88
89EXPORT_SYMBOL(get_brgfreq);
90
91static u32 fs_baudrate = -1;
92
93u32 get_baudrate(void)
94{
95 struct device_node *node;
96
97 if (fs_baudrate != -1)
98 return fs_baudrate;
99
100 node = of_find_node_by_type(NULL, "serial");
101 if (node) {
102 unsigned int size;
103 const unsigned int *prop = get_property(node, "current-speed",
104 &size);
105
106 if (prop)
107 fs_baudrate = *prop;
108 of_node_put(node);
109 };
110
111 return fs_baudrate;
112}
113
114EXPORT_SYMBOL(get_baudrate);
115#endif /* CONFIG_CPM2 */
116
Kumar Gala2fb07d72006-01-23 16:58:04 -0600117static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600118{
119 struct device_node *np;
120 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600121 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600122 struct resource res;
123 int ret;
124
Kumar Gala2fb07d72006-01-23 16:58:04 -0600125 for (np = NULL, i = 0;
126 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
127 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600128 int k;
129 struct device_node *child = NULL;
130 struct gianfar_mdio_data mdio_data;
131
132 memset(&res, 0, sizeof(res));
133 memset(&mdio_data, 0, sizeof(mdio_data));
134
135 ret = of_address_to_resource(np, 0, &res);
136 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600137 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600138
Kumar Gala2fb07d72006-01-23 16:58:04 -0600139 mdio_dev =
140 platform_device_register_simple("fsl-gianfar_mdio",
141 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600142 if (IS_ERR(mdio_dev)) {
143 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600144 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600145 }
146
147 for (k = 0; k < 32; k++)
148 mdio_data.irq[k] = -1;
149
150 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400151 int irq = irq_of_parse_and_map(child, 0);
152 if (irq != NO_IRQ) {
153 const u32 *id = get_property(child, "reg", NULL);
154 mdio_data.irq[*id] = irq;
155 }
Kumar Galaeed32002006-01-13 11:19:13 -0600156 }
157
Kumar Gala2fb07d72006-01-23 16:58:04 -0600158 ret =
159 platform_device_add_data(mdio_dev, &mdio_data,
160 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600161 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600162 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600163 }
164
Kumar Gala2fb07d72006-01-23 16:58:04 -0600165 return 0;
166
167unreg:
168 platform_device_unregister(mdio_dev);
169err:
170 return ret;
171}
172
173arch_initcall(gfar_mdio_of_init);
174
175static const char *gfar_tx_intr = "tx";
176static const char *gfar_rx_intr = "rx";
177static const char *gfar_err_intr = "error";
178
179static int __init gfar_of_init(void)
180{
181 struct device_node *np;
182 unsigned int i;
183 struct platform_device *gfar_dev;
184 struct resource res;
185 int ret;
186
187 for (np = NULL, i = 0;
188 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
189 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600190 struct resource r[4];
191 struct device_node *phy, *mdio;
192 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000193 const unsigned int *id;
194 const char *model;
195 const void *mac_addr;
196 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400197 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600198
199 memset(r, 0, sizeof(r));
200 memset(&gfar_data, 0, sizeof(gfar_data));
201
202 ret = of_address_to_resource(np, 0, &r[0]);
203 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600204 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600205
Jon Loeliger919fede2006-07-31 15:35:41 -0500206 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Galaeed32002006-01-13 11:19:13 -0600207 r[1].flags = IORESOURCE_IRQ;
208
209 model = get_property(np, "model", NULL);
210
211 /* If we aren't the FEC we have multiple interrupts */
212 if (model && strcasecmp(model, "FEC")) {
213 r[1].name = gfar_tx_intr;
214
215 r[2].name = gfar_rx_intr;
Jon Loeliger919fede2006-07-31 15:35:41 -0500216 r[2].start = r[2].end = irq_of_parse_and_map(np, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600217 r[2].flags = IORESOURCE_IRQ;
218
219 r[3].name = gfar_err_intr;
Jon Loeliger919fede2006-07-31 15:35:41 -0500220 r[3].start = r[3].end = irq_of_parse_and_map(np, 2);
Kumar Galaeed32002006-01-13 11:19:13 -0600221 r[3].flags = IORESOURCE_IRQ;
Jon Loeliger919fede2006-07-31 15:35:41 -0500222
223 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600224 }
225
Kumar Gala2fb07d72006-01-23 16:58:04 -0600226 gfar_dev =
227 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400228 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600229
230 if (IS_ERR(gfar_dev)) {
231 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600232 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600233 }
234
Jon Loeligerf5831652006-08-17 08:42:35 -0500235 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);
Kumar Galaeed32002006-01-13 11:19:13 -0600245
246 if (model && !strcasecmp(model, "TSEC"))
247 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600248 FSL_GIANFAR_DEV_HAS_GIGABIT |
249 FSL_GIANFAR_DEV_HAS_COALESCE |
250 FSL_GIANFAR_DEV_HAS_RMON |
251 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600252 if (model && !strcasecmp(model, "eTSEC"))
253 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600254 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;
Kumar Galaeed32002006-01-13 11:19:13 -0600261
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000262 ph = get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600263 phy = of_find_node_by_phandle(*ph);
264
265 if (phy == NULL) {
266 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600267 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600268 }
269
270 mdio = of_get_parent(phy);
271
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000272 id = get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600273 ret = of_address_to_resource(mdio, 0, &res);
274 if (ret) {
275 of_node_put(phy);
276 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600277 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600278 }
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
Kumar Gala2fb07d72006-01-23 16:58:04 -0600286 ret =
287 platform_device_add_data(gfar_dev, &gfar_data,
288 sizeof(struct
289 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600290 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600291 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600292 }
293
294 return 0;
295
Kumar Gala2fb07d72006-01-23 16:58:04 -0600296unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600297 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600298err:
Kumar Galaeed32002006-01-13 11:19:13 -0600299 return ret;
300}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600301
Kumar Galaeed32002006-01-13 11:19:13 -0600302arch_initcall(gfar_of_init);
303
304static 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
Kumar Gala2fb07d72006-01-23 16:58:04 -0600311 for (np = NULL, i = 0;
312 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
313 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600314 struct resource r[2];
315 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000316 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600317
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)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600323 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600324
Jon Loeliger919fede2006-07-31 15:35:41 -0500325 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Galaeed32002006-01-13 11:19:13 -0600326 r[1].flags = IORESOURCE_IRQ;
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);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600331 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600332 }
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
Kumar Gala2fb07d72006-01-23 16:58:04 -0600343 ret =
344 platform_device_add_data(i2c_dev, &i2c_data,
345 sizeof(struct
346 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600347 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600348 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600349 }
350
351 return 0;
352
Kumar Gala2fb07d72006-01-23 16:58:04 -0600353unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600354 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600355err:
Kumar Galaeed32002006-01-13 11:19:13 -0600356 return ret;
357}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600358
Kumar Galaeed32002006-01-13 11:19:13 -0600359arch_initcall(fsl_i2c_of_init);
360
361#ifdef CONFIG_PPC_83xx
362static int __init mpc83xx_wdt_init(void)
363{
364 struct resource r;
365 struct device_node *soc, *np;
366 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000367 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600368 int ret;
369
370 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
371
372 if (!np) {
373 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600374 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600375 }
376
377 soc = of_find_node_by_type(NULL, "soc");
378
379 if (!soc) {
380 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600381 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600382 }
383
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000384 freq = get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600385 if (!freq) {
386 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600387 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600388 }
389
390 memset(&r, 0, sizeof(r));
391
392 ret = of_address_to_resource(np, 0, &r);
393 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600394 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600395
396 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
397 if (IS_ERR(dev)) {
398 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600399 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600400 }
401
402 ret = platform_device_add_data(dev, freq, sizeof(int));
403 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600404 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600405
406 of_node_put(soc);
407 of_node_put(np);
408
409 return 0;
410
Kumar Gala2fb07d72006-01-23 16:58:04 -0600411unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600412 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600413err:
Kumar Galaeed32002006-01-13 11:19:13 -0600414 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600415nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600416 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600417nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600418 return ret;
419}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600420
Kumar Galaeed32002006-01-13 11:19:13 -0600421arch_initcall(mpc83xx_wdt_init);
422#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600423
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000424static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600425{
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
440static int __init fsl_usb_of_init(void)
441{
442 struct device_node *np;
443 unsigned int i;
Kumar Gala01cced22006-04-11 10:07:16 -0500444 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600445 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;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000452 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600453
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
Jon Loeliger919fede2006-07-31 15:35:41 -0500461 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600462 r[1].flags = IORESOURCE_IRQ;
463
Kumar Gala01cced22006-04-11 10:07:16 -0500464 usb_dev_mph =
465 platform_device_register_simple("fsl-ehci", i, r, 2);
466 if (IS_ERR(usb_dev_mph)) {
467 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600468 goto err;
469 }
470
Kumar Gala01cced22006-04-11 10:07:16 -0500471 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
472 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600473
474 usb_data.operating_mode = FSL_USB2_MPH_HOST;
475
476 prop = get_property(np, "port0", NULL);
477 if (prop)
478 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
479
480 prop = get_property(np, "port1", NULL);
481 if (prop)
482 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
483
484 prop = get_property(np, "phy_type", NULL);
485 usb_data.phy_mode = determine_usb_phy(prop);
486
487 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500488 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600489 sizeof(struct
490 fsl_usb2_platform_data));
491 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500492 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600493 }
494
Kumar Gala01cced22006-04-11 10:07:16 -0500495 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600496 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
497 i++) {
498 struct resource r[2];
499 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000500 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600501
502 memset(&r, 0, sizeof(r));
503 memset(&usb_data, 0, sizeof(usb_data));
504
505 ret = of_address_to_resource(np, 0, &r[0]);
506 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500507 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600508
Jon Loeliger919fede2006-07-31 15:35:41 -0500509 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600510 r[1].flags = IORESOURCE_IRQ;
511
Kumar Gala01cced22006-04-11 10:07:16 -0500512 usb_dev_dr =
513 platform_device_register_simple("fsl-ehci", i, r, 2);
514 if (IS_ERR(usb_dev_dr)) {
515 ret = PTR_ERR(usb_dev_dr);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600516 goto err;
517 }
518
Kumar Gala01cced22006-04-11 10:07:16 -0500519 usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
520 usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600521
522 usb_data.operating_mode = FSL_USB2_DR_HOST;
523
524 prop = get_property(np, "phy_type", NULL);
525 usb_data.phy_mode = determine_usb_phy(prop);
526
527 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500528 platform_device_add_data(usb_dev_dr, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600529 sizeof(struct
530 fsl_usb2_platform_data));
531 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500532 goto unreg_dr;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600533 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600534 return 0;
535
Kumar Gala01cced22006-04-11 10:07:16 -0500536unreg_dr:
537 if (usb_dev_dr)
538 platform_device_unregister(usb_dev_dr);
539unreg_mph:
540 if (usb_dev_mph)
541 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600542err:
543 return ret;
544}
545
Kumar Gala01cced22006-04-11 10:07:16 -0500546arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400547
548#ifdef CONFIG_CPM2
549
550static const char fcc_regs[] = "fcc_regs";
551static const char fcc_regs_c[] = "fcc_regs_c";
552static const char fcc_pram[] = "fcc_pram";
553static char bus_id[9][BUS_ID_SIZE];
554
555static 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;
569 const unsigned int *id, *phy_addr;
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;
591
592 r[3].start = r[3].end = irq_of_parse_and_map(np, 0);
593 r[3].flags = IORESOURCE_IRQ;
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
623 id = get_property(np, "device-id", NULL);
624 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400625 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400626
627 mdio = of_get_parent(phy);
628 ret = of_address_to_resource(mdio, 0, &res);
629 if (ret) {
630 of_node_put(phy);
631 of_node_put(mdio);
632 goto unreg;
633 }
634
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400635 fs_enet_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL));
636 fs_enet_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL));
637
Vitaly Bordugfba43662006-09-21 17:26:34 +0400638 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400639 int fcc_index = *id - 1;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400640
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400641 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400642 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)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400654 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400655 }
656
657 of_node_put(phy);
658 of_node_put(mdio);
659
660 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
661 sizeof(struct
662 fs_platform_info));
663 if (ret)
664 goto unreg;
665 }
666 return 0;
667
668unreg:
669 platform_device_unregister(fs_enet_dev);
670err:
671 return ret;
672}
673
674arch_initcall(fs_enet_of_init);
675
676static const char scc_regs[] = "regs";
677static const char scc_pram[] = "pram";
678
679static int __init cpm_uart_of_init(void)
680{
681 struct device_node *np;
682 unsigned int i;
683 struct platform_device *cpm_uart_dev;
684 int ret;
685
686 for (np = NULL, i = 0;
687 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
688 i++) {
689 struct resource r[3];
690 struct fs_uart_platform_info cpm_uart_data;
691 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400692 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400693
694 memset(r, 0, sizeof(r));
695 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
696
697 ret = of_address_to_resource(np, 0, &r[0]);
698 if (ret)
699 goto err;
700
701 r[0].name = scc_regs;
702
703 ret = of_address_to_resource(np, 1, &r[1]);
704 if (ret)
705 goto err;
706 r[1].name = scc_pram;
707
708 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
709 r[2].flags = IORESOURCE_IRQ;
710
711 cpm_uart_dev =
712 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
713
714 if (IS_ERR(cpm_uart_dev)) {
715 ret = PTR_ERR(cpm_uart_dev);
716 goto err;
717 }
718
719 id = get_property(np, "device-id", NULL);
720 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400721
722 model = (char*)get_property(np, "model", NULL);
723 strcpy(cpm_uart_data.fs_type, model);
724
Vitaly Bordugfba43662006-09-21 17:26:34 +0400725 cpm_uart_data.uart_clk = ppc_proc_freq;
726
727 cpm_uart_data.tx_num_fifo = 4;
728 cpm_uart_data.tx_buf_size = 32;
729 cpm_uart_data.rx_num_fifo = 4;
730 cpm_uart_data.rx_buf_size = 32;
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400731 cpm_uart_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL));
732 cpm_uart_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400733
734 ret =
735 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
736 sizeof(struct
737 fs_uart_platform_info));
738 if (ret)
739 goto unreg;
740 }
741
742 return 0;
743
744unreg:
745 platform_device_unregister(cpm_uart_dev);
746err:
747 return ret;
748}
749
750arch_initcall(cpm_uart_of_init);
751#endif /* CONFIG_CPM2 */