blob: 0b8a03cc304244a6b00802c25cda60e0dcb524e2 [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
39static phys_addr_t immrbase = -1;
40
41phys_addr_t get_immrbase(void)
42{
43 struct device_node *soc;
44
45 if (immrbase != -1)
46 return immrbase;
47
48 soc = of_find_node_by_type(NULL, "soc");
Kumar Gala2fb07d72006-01-23 16:58:04 -060049 if (soc) {
Kumar Galaeed32002006-01-13 11:19:13 -060050 unsigned int size;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100051 const void *prop = get_property(soc, "reg", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040052
53 if (prop)
54 immrbase = of_translate_address(soc, prop);
Kumar Galaeed32002006-01-13 11:19:13 -060055 of_node_put(soc);
56 };
57
58 return immrbase;
59}
Kumar Gala2fb07d72006-01-23 16:58:04 -060060
Kumar Galaeed32002006-01-13 11:19:13 -060061EXPORT_SYMBOL(get_immrbase);
62
Vitaly Bordugfba43662006-09-21 17:26:34 +040063#ifdef CONFIG_CPM2
64
65static u32 brgfreq = -1;
66
67u32 get_brgfreq(void)
68{
69 struct device_node *node;
70
71 if (brgfreq != -1)
72 return brgfreq;
73
74 node = of_find_node_by_type(NULL, "cpm");
75 if (node) {
76 unsigned int size;
77 const unsigned int *prop = get_property(node, "brg-frequency",
78 &size);
79
80 if (prop)
81 brgfreq = *prop;
82 of_node_put(node);
83 };
84
85 return brgfreq;
86}
87
88EXPORT_SYMBOL(get_brgfreq);
89
90static u32 fs_baudrate = -1;
91
92u32 get_baudrate(void)
93{
94 struct device_node *node;
95
96 if (fs_baudrate != -1)
97 return fs_baudrate;
98
99 node = of_find_node_by_type(NULL, "serial");
100 if (node) {
101 unsigned int size;
102 const unsigned int *prop = get_property(node, "current-speed",
103 &size);
104
105 if (prop)
106 fs_baudrate = *prop;
107 of_node_put(node);
108 };
109
110 return fs_baudrate;
111}
112
113EXPORT_SYMBOL(get_baudrate);
114#endif /* CONFIG_CPM2 */
115
Kumar Gala2fb07d72006-01-23 16:58:04 -0600116static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600117{
118 struct device_node *np;
119 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600120 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600121 struct resource res;
122 int ret;
123
Kumar Gala2fb07d72006-01-23 16:58:04 -0600124 for (np = NULL, i = 0;
125 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
126 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600127 int k;
128 struct device_node *child = NULL;
129 struct gianfar_mdio_data mdio_data;
130
131 memset(&res, 0, sizeof(res));
132 memset(&mdio_data, 0, sizeof(mdio_data));
133
134 ret = of_address_to_resource(np, 0, &res);
135 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600136 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600137
Kumar Gala2fb07d72006-01-23 16:58:04 -0600138 mdio_dev =
139 platform_device_register_simple("fsl-gianfar_mdio",
140 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600141 if (IS_ERR(mdio_dev)) {
142 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600143 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600144 }
145
146 for (k = 0; k < 32; k++)
147 mdio_data.irq[k] = -1;
148
149 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400150 int irq = irq_of_parse_and_map(child, 0);
151 if (irq != NO_IRQ) {
152 const u32 *id = get_property(child, "reg", NULL);
153 mdio_data.irq[*id] = irq;
154 }
Kumar Galaeed32002006-01-13 11:19:13 -0600155 }
156
Kumar Gala2fb07d72006-01-23 16:58:04 -0600157 ret =
158 platform_device_add_data(mdio_dev, &mdio_data,
159 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600160 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600161 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600162 }
163
Kumar Gala2fb07d72006-01-23 16:58:04 -0600164 return 0;
165
166unreg:
167 platform_device_unregister(mdio_dev);
168err:
169 return ret;
170}
171
172arch_initcall(gfar_mdio_of_init);
173
174static const char *gfar_tx_intr = "tx";
175static const char *gfar_rx_intr = "rx";
176static const char *gfar_err_intr = "error";
177
178static int __init gfar_of_init(void)
179{
180 struct device_node *np;
181 unsigned int i;
182 struct platform_device *gfar_dev;
183 struct resource res;
184 int ret;
185
186 for (np = NULL, i = 0;
187 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
188 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600189 struct resource r[4];
190 struct device_node *phy, *mdio;
191 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000192 const unsigned int *id;
193 const char *model;
194 const void *mac_addr;
195 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400196 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600197
198 memset(r, 0, sizeof(r));
199 memset(&gfar_data, 0, sizeof(gfar_data));
200
201 ret = of_address_to_resource(np, 0, &r[0]);
202 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600203 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600204
Jon Loeliger919fede2006-07-31 15:35:41 -0500205 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Galaeed32002006-01-13 11:19:13 -0600206 r[1].flags = IORESOURCE_IRQ;
207
208 model = get_property(np, "model", NULL);
209
210 /* If we aren't the FEC we have multiple interrupts */
211 if (model && strcasecmp(model, "FEC")) {
212 r[1].name = gfar_tx_intr;
213
214 r[2].name = gfar_rx_intr;
Jon Loeliger919fede2006-07-31 15:35:41 -0500215 r[2].start = r[2].end = irq_of_parse_and_map(np, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600216 r[2].flags = IORESOURCE_IRQ;
217
218 r[3].name = gfar_err_intr;
Jon Loeliger919fede2006-07-31 15:35:41 -0500219 r[3].start = r[3].end = irq_of_parse_and_map(np, 2);
Kumar Galaeed32002006-01-13 11:19:13 -0600220 r[3].flags = IORESOURCE_IRQ;
Jon Loeliger919fede2006-07-31 15:35:41 -0500221
222 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600223 }
224
Kumar Gala2fb07d72006-01-23 16:58:04 -0600225 gfar_dev =
226 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400227 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600228
229 if (IS_ERR(gfar_dev)) {
230 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600231 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600232 }
233
Jon Loeligerf5831652006-08-17 08:42:35 -0500234 mac_addr = get_property(np, "local-mac-address", NULL);
235 if (mac_addr == NULL)
236 mac_addr = get_property(np, "mac-address", NULL);
237 if (mac_addr == NULL) {
238 /* Obsolete */
239 mac_addr = get_property(np, "address", NULL);
240 }
241
242 if (mac_addr)
243 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600244
245 if (model && !strcasecmp(model, "TSEC"))
246 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600247 FSL_GIANFAR_DEV_HAS_GIGABIT |
248 FSL_GIANFAR_DEV_HAS_COALESCE |
249 FSL_GIANFAR_DEV_HAS_RMON |
250 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600251 if (model && !strcasecmp(model, "eTSEC"))
252 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600253 FSL_GIANFAR_DEV_HAS_GIGABIT |
254 FSL_GIANFAR_DEV_HAS_COALESCE |
255 FSL_GIANFAR_DEV_HAS_RMON |
256 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
257 FSL_GIANFAR_DEV_HAS_CSUM |
258 FSL_GIANFAR_DEV_HAS_VLAN |
259 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600260
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000261 ph = get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600262 phy = of_find_node_by_phandle(*ph);
263
264 if (phy == NULL) {
265 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600266 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600267 }
268
269 mdio = of_get_parent(phy);
270
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000271 id = get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600272 ret = of_address_to_resource(mdio, 0, &res);
273 if (ret) {
274 of_node_put(phy);
275 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600276 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600277 }
278
279 gfar_data.phy_id = *id;
280 gfar_data.bus_id = res.start;
281
282 of_node_put(phy);
283 of_node_put(mdio);
284
Kumar Gala2fb07d72006-01-23 16:58:04 -0600285 ret =
286 platform_device_add_data(gfar_dev, &gfar_data,
287 sizeof(struct
288 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600289 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600290 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600291 }
292
293 return 0;
294
Kumar Gala2fb07d72006-01-23 16:58:04 -0600295unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600296 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600297err:
Kumar Galaeed32002006-01-13 11:19:13 -0600298 return ret;
299}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600300
Kumar Galaeed32002006-01-13 11:19:13 -0600301arch_initcall(gfar_of_init);
302
303static int __init fsl_i2c_of_init(void)
304{
305 struct device_node *np;
306 unsigned int i;
307 struct platform_device *i2c_dev;
308 int ret;
309
Kumar Gala2fb07d72006-01-23 16:58:04 -0600310 for (np = NULL, i = 0;
311 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
312 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600313 struct resource r[2];
314 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000315 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600316
317 memset(&r, 0, sizeof(r));
318 memset(&i2c_data, 0, sizeof(i2c_data));
319
320 ret = of_address_to_resource(np, 0, &r[0]);
321 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600322 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600323
Jon Loeliger919fede2006-07-31 15:35:41 -0500324 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Galaeed32002006-01-13 11:19:13 -0600325 r[1].flags = IORESOURCE_IRQ;
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);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600330 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600331 }
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
Kumar Gala2fb07d72006-01-23 16:58:04 -0600342 ret =
343 platform_device_add_data(i2c_dev, &i2c_data,
344 sizeof(struct
345 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600346 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600347 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600348 }
349
350 return 0;
351
Kumar Gala2fb07d72006-01-23 16:58:04 -0600352unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600353 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600354err:
Kumar Galaeed32002006-01-13 11:19:13 -0600355 return ret;
356}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600357
Kumar Galaeed32002006-01-13 11:19:13 -0600358arch_initcall(fsl_i2c_of_init);
359
360#ifdef CONFIG_PPC_83xx
361static int __init mpc83xx_wdt_init(void)
362{
363 struct resource r;
364 struct device_node *soc, *np;
365 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000366 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600367 int ret;
368
369 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
370
371 if (!np) {
372 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600373 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600374 }
375
376 soc = of_find_node_by_type(NULL, "soc");
377
378 if (!soc) {
379 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600380 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600381 }
382
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000383 freq = get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600384 if (!freq) {
385 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600386 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600387 }
388
389 memset(&r, 0, sizeof(r));
390
391 ret = of_address_to_resource(np, 0, &r);
392 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600393 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600394
395 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
396 if (IS_ERR(dev)) {
397 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600398 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600399 }
400
401 ret = platform_device_add_data(dev, freq, sizeof(int));
402 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600403 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600404
405 of_node_put(soc);
406 of_node_put(np);
407
408 return 0;
409
Kumar Gala2fb07d72006-01-23 16:58:04 -0600410unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600411 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600412err:
Kumar Galaeed32002006-01-13 11:19:13 -0600413 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600414nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600415 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600416nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600417 return ret;
418}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600419
Kumar Galaeed32002006-01-13 11:19:13 -0600420arch_initcall(mpc83xx_wdt_init);
421#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600422
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000423static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600424{
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
439static int __init fsl_usb_of_init(void)
440{
441 struct device_node *np;
442 unsigned int i;
Kumar Gala01cced22006-04-11 10:07:16 -0500443 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600444 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;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000451 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600452
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
Jon Loeliger919fede2006-07-31 15:35:41 -0500460 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600461 r[1].flags = IORESOURCE_IRQ;
462
Kumar Gala01cced22006-04-11 10:07:16 -0500463 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);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600467 goto err;
468 }
469
Kumar Gala01cced22006-04-11 10:07:16 -0500470 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
471 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600472
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 =
Kumar Gala01cced22006-04-11 10:07:16 -0500487 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600488 sizeof(struct
489 fsl_usb2_platform_data));
490 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500491 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600492 }
493
Kumar Gala01cced22006-04-11 10:07:16 -0500494 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600495 (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;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000499 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600500
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)
Kumar Gala01cced22006-04-11 10:07:16 -0500506 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600507
Jon Loeliger919fede2006-07-31 15:35:41 -0500508 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600509 r[1].flags = IORESOURCE_IRQ;
510
Kumar Gala01cced22006-04-11 10:07:16 -0500511 usb_dev_dr =
512 platform_device_register_simple("fsl-ehci", i, r, 2);
513 if (IS_ERR(usb_dev_dr)) {
514 ret = PTR_ERR(usb_dev_dr);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600515 goto err;
516 }
517
Kumar Gala01cced22006-04-11 10:07:16 -0500518 usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
519 usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600520
521 usb_data.operating_mode = FSL_USB2_DR_HOST;
522
523 prop = get_property(np, "phy_type", NULL);
524 usb_data.phy_mode = determine_usb_phy(prop);
525
526 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500527 platform_device_add_data(usb_dev_dr, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600528 sizeof(struct
529 fsl_usb2_platform_data));
530 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500531 goto unreg_dr;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600532 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600533 return 0;
534
Kumar Gala01cced22006-04-11 10:07:16 -0500535unreg_dr:
536 if (usb_dev_dr)
537 platform_device_unregister(usb_dev_dr);
538unreg_mph:
539 if (usb_dev_mph)
540 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600541err:
542 return ret;
543}
544
Kumar Gala01cced22006-04-11 10:07:16 -0500545arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400546
547#ifdef CONFIG_CPM2
548
549static const char fcc_regs[] = "fcc_regs";
550static const char fcc_regs_c[] = "fcc_regs_c";
551static const char fcc_pram[] = "fcc_pram";
552static char bus_id[9][BUS_ID_SIZE];
553
554static int __init fs_enet_of_init(void)
555{
556 struct device_node *np;
557 unsigned int i;
558 struct platform_device *fs_enet_dev;
559 struct resource res;
560 int ret;
561
562 for (np = NULL, i = 0;
563 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
564 i++) {
565 struct resource r[4];
566 struct device_node *phy, *mdio;
567 struct fs_platform_info fs_enet_data;
568 const unsigned int *id, *phy_addr;
569 const void *mac_addr;
570 const phandle *ph;
571 const char *model;
572
573 memset(r, 0, sizeof(r));
574 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
575
576 ret = of_address_to_resource(np, 0, &r[0]);
577 if (ret)
578 goto err;
579 r[0].name = fcc_regs;
580
581 ret = of_address_to_resource(np, 1, &r[1]);
582 if (ret)
583 goto err;
584 r[1].name = fcc_pram;
585
586 ret = of_address_to_resource(np, 2, &r[2]);
587 if (ret)
588 goto err;
589 r[2].name = fcc_regs_c;
590
591 r[3].start = r[3].end = irq_of_parse_and_map(np, 0);
592 r[3].flags = IORESOURCE_IRQ;
593
594 fs_enet_dev =
595 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
596
597 if (IS_ERR(fs_enet_dev)) {
598 ret = PTR_ERR(fs_enet_dev);
599 goto err;
600 }
601
602 model = get_property(np, "model", NULL);
603 if (model == NULL) {
604 ret = -ENODEV;
605 goto unreg;
606 }
607
608 mac_addr = get_property(np, "mac-address", NULL);
609 memcpy(fs_enet_data.macaddr, mac_addr, 6);
610
611 ph = get_property(np, "phy-handle", NULL);
612 phy = of_find_node_by_phandle(*ph);
613
614 if (phy == NULL) {
615 ret = -ENODEV;
616 goto unreg;
617 }
618
619 phy_addr = get_property(phy, "reg", NULL);
620 fs_enet_data.phy_addr = *phy_addr;
621
622 id = get_property(np, "device-id", NULL);
623 fs_enet_data.fs_no = *id;
624
625 mdio = of_get_parent(phy);
626 ret = of_address_to_resource(mdio, 0, &res);
627 if (ret) {
628 of_node_put(phy);
629 of_node_put(mdio);
630 goto unreg;
631 }
632
633 if (strstr(model, "FCC")) {
634 int fcc_index = fs_get_fcc_index(*id);
635
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400636 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400637 fs_enet_data.rx_ring = 32;
638 fs_enet_data.tx_ring = 32;
639 fs_enet_data.rx_copybreak = 240;
640 fs_enet_data.use_napi = 0;
641 fs_enet_data.napi_weight = 17;
642 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
643 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
644 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
645
646 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
647 (u32)res.start, fs_enet_data.phy_addr);
648 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
649 }
650
651 of_node_put(phy);
652 of_node_put(mdio);
653
654 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
655 sizeof(struct
656 fs_platform_info));
657 if (ret)
658 goto unreg;
659 }
660 return 0;
661
662unreg:
663 platform_device_unregister(fs_enet_dev);
664err:
665 return ret;
666}
667
668arch_initcall(fs_enet_of_init);
669
670static const char scc_regs[] = "regs";
671static const char scc_pram[] = "pram";
672
673static int __init cpm_uart_of_init(void)
674{
675 struct device_node *np;
676 unsigned int i;
677 struct platform_device *cpm_uart_dev;
678 int ret;
679
680 for (np = NULL, i = 0;
681 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
682 i++) {
683 struct resource r[3];
684 struct fs_uart_platform_info cpm_uart_data;
685 const int *id;
686
687 memset(r, 0, sizeof(r));
688 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
689
690 ret = of_address_to_resource(np, 0, &r[0]);
691 if (ret)
692 goto err;
693
694 r[0].name = scc_regs;
695
696 ret = of_address_to_resource(np, 1, &r[1]);
697 if (ret)
698 goto err;
699 r[1].name = scc_pram;
700
701 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
702 r[2].flags = IORESOURCE_IRQ;
703
704 cpm_uart_dev =
705 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
706
707 if (IS_ERR(cpm_uart_dev)) {
708 ret = PTR_ERR(cpm_uart_dev);
709 goto err;
710 }
711
712 id = get_property(np, "device-id", NULL);
713 cpm_uart_data.fs_no = *id;
714 cpm_uart_data.uart_clk = ppc_proc_freq;
715
716 cpm_uart_data.tx_num_fifo = 4;
717 cpm_uart_data.tx_buf_size = 32;
718 cpm_uart_data.rx_num_fifo = 4;
719 cpm_uart_data.rx_buf_size = 32;
720
721 ret =
722 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
723 sizeof(struct
724 fs_uart_platform_info));
725 if (ret)
726 goto unreg;
727 }
728
729 return 0;
730
731unreg:
732 platform_device_unregister(cpm_uart_dev);
733err:
734 return ret;
735}
736
737arch_initcall(cpm_uart_of_init);
738#endif /* CONFIG_CPM2 */