blob: ad31e56e892ba32b6e97314c17f2fb66bfa7f316 [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>
Andy Fleminga9b14972006-10-19 19:52:26 -050025#include <linux/phy.h>
Kumar Galaeed32002006-01-13 11:19:13 -060026#include <linux/fsl_devices.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040027#include <linux/fs_enet_pd.h>
28#include <linux/fs_uart_pd.h>
Kumar Galaeed32002006-01-13 11:19:13 -060029
30#include <asm/system.h>
31#include <asm/atomic.h>
32#include <asm/io.h>
33#include <asm/irq.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040034#include <asm/time.h>
Kumar Galaeed32002006-01-13 11:19:13 -060035#include <asm/prom.h>
36#include <sysdev/fsl_soc.h>
37#include <mm/mmu_decl.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040038#include <asm/cpm2.h>
Kumar Galaeed32002006-01-13 11:19:13 -060039
Vitaly Bordugd3465c92006-09-21 22:38:05 +040040extern void init_fcc_ioports(struct fs_platform_info*);
Vitaly Borduged943c12006-10-02 22:41:50 +040041extern void init_scc_ioports(struct fs_uart_platform_info*);
Kumar Galaeed32002006-01-13 11:19:13 -060042static phys_addr_t immrbase = -1;
43
44phys_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");
Kumar Gala2fb07d72006-01-23 16:58:04 -060052 if (soc) {
Kumar Galaeed32002006-01-13 11:19:13 -060053 unsigned int size;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100054 const void *prop = get_property(soc, "reg", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040055
56 if (prop)
57 immrbase = of_translate_address(soc, prop);
Kumar Galaeed32002006-01-13 11:19:13 -060058 of_node_put(soc);
59 };
60
61 return immrbase;
62}
Kumar Gala2fb07d72006-01-23 16:58:04 -060063
Kumar Galaeed32002006-01-13 11:19:13 -060064EXPORT_SYMBOL(get_immrbase);
65
Vitaly Bordugfba43662006-09-21 17:26:34 +040066#ifdef CONFIG_CPM2
67
68static u32 brgfreq = -1;
69
70u32 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
91EXPORT_SYMBOL(get_brgfreq);
92
93static u32 fs_baudrate = -1;
94
95u32 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
116EXPORT_SYMBOL(get_baudrate);
117#endif /* CONFIG_CPM2 */
118
Kumar Gala2fb07d72006-01-23 16:58:04 -0600119static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600120{
121 struct device_node *np;
122 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600123 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600124 struct resource res;
125 int ret;
126
Kumar Gala2fb07d72006-01-23 16:58:04 -0600127 for (np = NULL, i = 0;
128 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
129 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600130 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)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600139 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600140
Kumar Gala2fb07d72006-01-23 16:58:04 -0600141 mdio_dev =
142 platform_device_register_simple("fsl-gianfar_mdio",
143 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600144 if (IS_ERR(mdio_dev)) {
145 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600146 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600147 }
148
149 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500150 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600151
152 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400153 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 }
Kumar Galaeed32002006-01-13 11:19:13 -0600158 }
159
Kumar Gala2fb07d72006-01-23 16:58:04 -0600160 ret =
161 platform_device_add_data(mdio_dev, &mdio_data,
162 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600163 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600164 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600165 }
166
Kumar Gala2fb07d72006-01-23 16:58:04 -0600167 return 0;
168
169unreg:
170 platform_device_unregister(mdio_dev);
171err:
172 return ret;
173}
174
175arch_initcall(gfar_mdio_of_init);
176
177static const char *gfar_tx_intr = "tx";
178static const char *gfar_rx_intr = "rx";
179static const char *gfar_err_intr = "error";
180
Andy Fleminga9b14972006-10-19 19:52:26 -0500181
Kumar Gala2fb07d72006-01-23 16:58:04 -0600182static 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++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600193 struct resource r[4];
194 struct device_node *phy, *mdio;
195 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000196 const unsigned int *id;
197 const char *model;
198 const void *mac_addr;
199 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400200 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600201
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)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600207 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600208
Andy Fleminga9b14972006-10-19 19:52:26 -0500209 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600210
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;
Andy Fleminga9b14972006-10-19 19:52:26 -0500218 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600219
220 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500221 of_irq_to_resource(np, 2, &r[3]);
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
Andy Fleminga9b14972006-10-19 19:52:26 -0500325 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600326
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
Andy Fleminga9b14972006-10-19 19:52:26 -0500460 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600461
Kumar Gala01cced22006-04-11 10:07:16 -0500462 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);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600466 goto err;
467 }
468
Kumar Gala01cced22006-04-11 10:07:16 -0500469 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
470 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600471
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 =
Kumar Gala01cced22006-04-11 10:07:16 -0500486 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600487 sizeof(struct
488 fsl_usb2_platform_data));
489 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500490 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600491 }
492
Kumar Gala01cced22006-04-11 10:07:16 -0500493 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600494 (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;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000498 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600499
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)
Kumar Gala01cced22006-04-11 10:07:16 -0500505 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600506
Andy Fleminga9b14972006-10-19 19:52:26 -0500507 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600508
Kumar Gala01cced22006-04-11 10:07:16 -0500509 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);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600513 goto err;
514 }
515
Kumar Gala01cced22006-04-11 10:07:16 -0500516 usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
517 usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600518
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 =
Kumar Gala01cced22006-04-11 10:07:16 -0500525 platform_device_add_data(usb_dev_dr, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600526 sizeof(struct
527 fsl_usb2_platform_data));
528 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500529 goto unreg_dr;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600530 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600531 return 0;
532
Kumar Gala01cced22006-04-11 10:07:16 -0500533unreg_dr:
534 if (usb_dev_dr)
535 platform_device_unregister(usb_dev_dr);
536unreg_mph:
537 if (usb_dev_mph)
538 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600539err:
540 return ret;
541}
542
Kumar Gala01cced22006-04-11 10:07:16 -0500543arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400544
545#ifdef CONFIG_CPM2
546
547static const char fcc_regs[] = "fcc_regs";
548static const char fcc_regs_c[] = "fcc_regs_c";
549static const char fcc_pram[] = "fcc_pram";
550static char bus_id[9][BUS_ID_SIZE];
551
552static 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;
Olof Johansson2b00b252006-10-05 21:16:48 -0500566 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400567 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;
Vitaly Borduged943c12006-10-02 22:41:50 +0400588 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400589
Andy Fleminga9b14972006-10-19 19:52:26 -0500590 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400591
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
Vitaly Borduged943c12006-10-02 22:41:50 +0400620 phy_irq = get_property(phy, "interrupts", NULL);
621
Vitaly Bordugfba43662006-09-21 17:26:34 +0400622 id = get_property(np, "device-id", NULL);
623 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400624 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400625
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
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400634 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
Vitaly Bordugfba43662006-09-21 17:26:34 +0400637 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400638 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500639 const unsigned char *mdio_bb_prop;
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
Vitaly Borduged943c12006-10-02 22:41:50 +0400656 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;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400660
Vitaly Borduged943c12006-10-02 22:41:50 +0400661 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);
702
703 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
704 sizeof(struct
705 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500706 if (ret)
707 goto unreg;
708 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400709 }
710 return 0;
711
712unreg:
713 platform_device_unregister(fs_enet_dev);
714err:
715 return ret;
716}
717
718arch_initcall(fs_enet_of_init);
719
720static const char scc_regs[] = "regs";
721static const char scc_pram[] = "pram";
722
723static 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;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400736 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400737
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
Andy Fleminga9b14972006-10-19 19:52:26 -0500752 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400753
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;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400764
765 model = (char*)get_property(np, "model", NULL);
766 strcpy(cpm_uart_data.fs_type, model);
767
Vitaly Bordugfba43662006-09-21 17:26:34 +0400768 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;
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400774 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));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400776
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
787unreg:
788 platform_device_unregister(cpm_uart_dev);
789err:
790 return ret;
791}
792
793arch_initcall(cpm_uart_of_init);
794#endif /* CONFIG_CPM2 */