blob: 12b65609c072cd801acb8f469a6b2e667f2147a3 [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 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
Kumar Galaeed32002006-01-13 11:19:13 -060012#include <linux/stddef.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/major.h>
17#include <linux/delay.h>
18#include <linux/irq.h>
19#include <linux/module.h>
20#include <linux/device.h>
21#include <linux/platform_device.h>
22#include <linux/fsl_devices.h>
23
24#include <asm/system.h>
25#include <asm/atomic.h>
26#include <asm/io.h>
27#include <asm/irq.h>
28#include <asm/prom.h>
29#include <sysdev/fsl_soc.h>
30#include <mm/mmu_decl.h>
31
32static phys_addr_t immrbase = -1;
33
34phys_addr_t get_immrbase(void)
35{
36 struct device_node *soc;
37
38 if (immrbase != -1)
39 return immrbase;
40
41 soc = of_find_node_by_type(NULL, "soc");
Kumar Gala2fb07d72006-01-23 16:58:04 -060042 if (soc) {
Kumar Galaeed32002006-01-13 11:19:13 -060043 unsigned int size;
44 void *prop = get_property(soc, "reg", &size);
45 immrbase = of_translate_address(soc, prop);
46 of_node_put(soc);
47 };
48
49 return immrbase;
50}
Kumar Gala2fb07d72006-01-23 16:58:04 -060051
Kumar Galaeed32002006-01-13 11:19:13 -060052EXPORT_SYMBOL(get_immrbase);
53
Kumar Gala2fb07d72006-01-23 16:58:04 -060054static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -060055{
56 struct device_node *np;
57 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -060058 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -060059 struct resource res;
60 int ret;
61
Kumar Gala2fb07d72006-01-23 16:58:04 -060062 for (np = NULL, i = 0;
63 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
64 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -060065 int k;
66 struct device_node *child = NULL;
67 struct gianfar_mdio_data mdio_data;
68
69 memset(&res, 0, sizeof(res));
70 memset(&mdio_data, 0, sizeof(mdio_data));
71
72 ret = of_address_to_resource(np, 0, &res);
73 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -060074 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -060075
Kumar Gala2fb07d72006-01-23 16:58:04 -060076 mdio_dev =
77 platform_device_register_simple("fsl-gianfar_mdio",
78 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -060079 if (IS_ERR(mdio_dev)) {
80 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -060081 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -060082 }
83
84 for (k = 0; k < 32; k++)
85 mdio_data.irq[k] = -1;
86
87 while ((child = of_get_next_child(np, child)) != NULL) {
88 if (child->n_intrs) {
Kumar Gala2fb07d72006-01-23 16:58:04 -060089 u32 *id =
90 (u32 *) get_property(child, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -060091 mdio_data.irq[*id] = child->intrs[0].line;
92 }
93 }
94
Kumar Gala2fb07d72006-01-23 16:58:04 -060095 ret =
96 platform_device_add_data(mdio_dev, &mdio_data,
97 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -060098 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -060099 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600100 }
101
Kumar Gala2fb07d72006-01-23 16:58:04 -0600102 return 0;
103
104unreg:
105 platform_device_unregister(mdio_dev);
106err:
107 return ret;
108}
109
110arch_initcall(gfar_mdio_of_init);
111
112static const char *gfar_tx_intr = "tx";
113static const char *gfar_rx_intr = "rx";
114static const char *gfar_err_intr = "error";
115
116static int __init gfar_of_init(void)
117{
118 struct device_node *np;
119 unsigned int i;
120 struct platform_device *gfar_dev;
121 struct resource res;
122 int ret;
123
124 for (np = NULL, i = 0;
125 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
126 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600127 struct resource r[4];
128 struct device_node *phy, *mdio;
129 struct gianfar_platform_data gfar_data;
130 unsigned int *id;
131 char *model;
132 void *mac_addr;
133 phandle *ph;
134
135 memset(r, 0, sizeof(r));
136 memset(&gfar_data, 0, sizeof(gfar_data));
137
138 ret = of_address_to_resource(np, 0, &r[0]);
139 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600140 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600141
142 r[1].start = np->intrs[0].line;
143 r[1].end = np->intrs[0].line;
144 r[1].flags = IORESOURCE_IRQ;
145
146 model = get_property(np, "model", NULL);
147
148 /* If we aren't the FEC we have multiple interrupts */
149 if (model && strcasecmp(model, "FEC")) {
150 r[1].name = gfar_tx_intr;
151
152 r[2].name = gfar_rx_intr;
153 r[2].start = np->intrs[1].line;
154 r[2].end = np->intrs[1].line;
155 r[2].flags = IORESOURCE_IRQ;
156
157 r[3].name = gfar_err_intr;
158 r[3].start = np->intrs[2].line;
159 r[3].end = np->intrs[2].line;
160 r[3].flags = IORESOURCE_IRQ;
161 }
162
Kumar Gala2fb07d72006-01-23 16:58:04 -0600163 gfar_dev =
164 platform_device_register_simple("fsl-gianfar", i, &r[0],
165 np->n_intrs + 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600166
167 if (IS_ERR(gfar_dev)) {
168 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600169 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600170 }
171
Jon Loeligerf5831652006-08-17 08:42:35 -0500172 mac_addr = get_property(np, "local-mac-address", NULL);
173 if (mac_addr == NULL)
174 mac_addr = get_property(np, "mac-address", NULL);
175 if (mac_addr == NULL) {
176 /* Obsolete */
177 mac_addr = get_property(np, "address", NULL);
178 }
179
180 if (mac_addr)
181 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600182
183 if (model && !strcasecmp(model, "TSEC"))
184 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600185 FSL_GIANFAR_DEV_HAS_GIGABIT |
186 FSL_GIANFAR_DEV_HAS_COALESCE |
187 FSL_GIANFAR_DEV_HAS_RMON |
188 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600189 if (model && !strcasecmp(model, "eTSEC"))
190 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600191 FSL_GIANFAR_DEV_HAS_GIGABIT |
192 FSL_GIANFAR_DEV_HAS_COALESCE |
193 FSL_GIANFAR_DEV_HAS_RMON |
194 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
195 FSL_GIANFAR_DEV_HAS_CSUM |
196 FSL_GIANFAR_DEV_HAS_VLAN |
197 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600198
199 ph = (phandle *) get_property(np, "phy-handle", NULL);
200 phy = of_find_node_by_phandle(*ph);
201
202 if (phy == NULL) {
203 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600204 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600205 }
206
207 mdio = of_get_parent(phy);
208
209 id = (u32 *) get_property(phy, "reg", NULL);
210 ret = of_address_to_resource(mdio, 0, &res);
211 if (ret) {
212 of_node_put(phy);
213 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600214 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600215 }
216
217 gfar_data.phy_id = *id;
218 gfar_data.bus_id = res.start;
219
220 of_node_put(phy);
221 of_node_put(mdio);
222
Kumar Gala2fb07d72006-01-23 16:58:04 -0600223 ret =
224 platform_device_add_data(gfar_dev, &gfar_data,
225 sizeof(struct
226 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600227 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600228 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600229 }
230
231 return 0;
232
Kumar Gala2fb07d72006-01-23 16:58:04 -0600233unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600234 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600235err:
Kumar Galaeed32002006-01-13 11:19:13 -0600236 return ret;
237}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600238
Kumar Galaeed32002006-01-13 11:19:13 -0600239arch_initcall(gfar_of_init);
240
241static int __init fsl_i2c_of_init(void)
242{
243 struct device_node *np;
244 unsigned int i;
245 struct platform_device *i2c_dev;
246 int ret;
247
Kumar Gala2fb07d72006-01-23 16:58:04 -0600248 for (np = NULL, i = 0;
249 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
250 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600251 struct resource r[2];
252 struct fsl_i2c_platform_data i2c_data;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600253 unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600254
255 memset(&r, 0, sizeof(r));
256 memset(&i2c_data, 0, sizeof(i2c_data));
257
258 ret = of_address_to_resource(np, 0, &r[0]);
259 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600260 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600261
262 r[1].start = np->intrs[0].line;
263 r[1].end = np->intrs[0].line;
264 r[1].flags = IORESOURCE_IRQ;
265
266 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
267 if (IS_ERR(i2c_dev)) {
268 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600269 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600270 }
271
272 i2c_data.device_flags = 0;
273 flags = get_property(np, "dfsrr", NULL);
274 if (flags)
275 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
276
277 flags = get_property(np, "fsl5200-clocking", NULL);
278 if (flags)
279 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
280
Kumar Gala2fb07d72006-01-23 16:58:04 -0600281 ret =
282 platform_device_add_data(i2c_dev, &i2c_data,
283 sizeof(struct
284 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600285 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600286 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600287 }
288
289 return 0;
290
Kumar Gala2fb07d72006-01-23 16:58:04 -0600291unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600292 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600293err:
Kumar Galaeed32002006-01-13 11:19:13 -0600294 return ret;
295}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600296
Kumar Galaeed32002006-01-13 11:19:13 -0600297arch_initcall(fsl_i2c_of_init);
298
299#ifdef CONFIG_PPC_83xx
300static int __init mpc83xx_wdt_init(void)
301{
302 struct resource r;
303 struct device_node *soc, *np;
304 struct platform_device *dev;
305 unsigned int *freq;
306 int ret;
307
308 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
309
310 if (!np) {
311 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600312 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600313 }
314
315 soc = of_find_node_by_type(NULL, "soc");
316
317 if (!soc) {
318 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600319 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600320 }
321
322 freq = (unsigned int *)get_property(soc, "bus-frequency", NULL);
323 if (!freq) {
324 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600325 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600326 }
327
328 memset(&r, 0, sizeof(r));
329
330 ret = of_address_to_resource(np, 0, &r);
331 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600332 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600333
334 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
335 if (IS_ERR(dev)) {
336 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600337 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600338 }
339
340 ret = platform_device_add_data(dev, freq, sizeof(int));
341 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600342 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600343
344 of_node_put(soc);
345 of_node_put(np);
346
347 return 0;
348
Kumar Gala2fb07d72006-01-23 16:58:04 -0600349unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600350 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600351err:
Kumar Galaeed32002006-01-13 11:19:13 -0600352 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600353nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600354 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600355nodev:
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(mpc83xx_wdt_init);
360#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600361
362static enum fsl_usb2_phy_modes determine_usb_phy(char * phy_type)
363{
364 if (!phy_type)
365 return FSL_USB2_PHY_NONE;
366 if (!strcasecmp(phy_type, "ulpi"))
367 return FSL_USB2_PHY_ULPI;
368 if (!strcasecmp(phy_type, "utmi"))
369 return FSL_USB2_PHY_UTMI;
370 if (!strcasecmp(phy_type, "utmi_wide"))
371 return FSL_USB2_PHY_UTMI_WIDE;
372 if (!strcasecmp(phy_type, "serial"))
373 return FSL_USB2_PHY_SERIAL;
374
375 return FSL_USB2_PHY_NONE;
376}
377
378static int __init fsl_usb_of_init(void)
379{
380 struct device_node *np;
381 unsigned int i;
Kumar Gala01cced22006-04-11 10:07:16 -0500382 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600383 int ret;
384
385 for (np = NULL, i = 0;
386 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
387 i++) {
388 struct resource r[2];
389 struct fsl_usb2_platform_data usb_data;
390 unsigned char *prop = NULL;
391
392 memset(&r, 0, sizeof(r));
393 memset(&usb_data, 0, sizeof(usb_data));
394
395 ret = of_address_to_resource(np, 0, &r[0]);
396 if (ret)
397 goto err;
398
399 r[1].start = np->intrs[0].line;
400 r[1].end = np->intrs[0].line;
401 r[1].flags = IORESOURCE_IRQ;
402
Kumar Gala01cced22006-04-11 10:07:16 -0500403 usb_dev_mph =
404 platform_device_register_simple("fsl-ehci", i, r, 2);
405 if (IS_ERR(usb_dev_mph)) {
406 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600407 goto err;
408 }
409
Kumar Gala01cced22006-04-11 10:07:16 -0500410 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
411 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600412
413 usb_data.operating_mode = FSL_USB2_MPH_HOST;
414
415 prop = get_property(np, "port0", NULL);
416 if (prop)
417 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
418
419 prop = get_property(np, "port1", NULL);
420 if (prop)
421 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
422
423 prop = get_property(np, "phy_type", NULL);
424 usb_data.phy_mode = determine_usb_phy(prop);
425
426 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500427 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600428 sizeof(struct
429 fsl_usb2_platform_data));
430 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500431 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600432 }
433
Kumar Gala01cced22006-04-11 10:07:16 -0500434 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600435 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
436 i++) {
437 struct resource r[2];
438 struct fsl_usb2_platform_data usb_data;
439 unsigned char *prop = NULL;
440
441 memset(&r, 0, sizeof(r));
442 memset(&usb_data, 0, sizeof(usb_data));
443
444 ret = of_address_to_resource(np, 0, &r[0]);
445 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500446 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600447
448 r[1].start = np->intrs[0].line;
449 r[1].end = np->intrs[0].line;
450 r[1].flags = IORESOURCE_IRQ;
451
Kumar Gala01cced22006-04-11 10:07:16 -0500452 usb_dev_dr =
453 platform_device_register_simple("fsl-ehci", i, r, 2);
454 if (IS_ERR(usb_dev_dr)) {
455 ret = PTR_ERR(usb_dev_dr);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600456 goto err;
457 }
458
Kumar Gala01cced22006-04-11 10:07:16 -0500459 usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
460 usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600461
462 usb_data.operating_mode = FSL_USB2_DR_HOST;
463
464 prop = get_property(np, "phy_type", NULL);
465 usb_data.phy_mode = determine_usb_phy(prop);
466
467 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500468 platform_device_add_data(usb_dev_dr, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600469 sizeof(struct
470 fsl_usb2_platform_data));
471 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500472 goto unreg_dr;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600473 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600474 return 0;
475
Kumar Gala01cced22006-04-11 10:07:16 -0500476unreg_dr:
477 if (usb_dev_dr)
478 platform_device_unregister(usb_dev_dr);
479unreg_mph:
480 if (usb_dev_mph)
481 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600482err:
483 return ret;
484}
485
Kumar Gala01cced22006-04-11 10:07:16 -0500486arch_initcall(fsl_usb_of_init);