blob: 07c47e8309edacb0a904e55702d717e393a73029 [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;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100044 const void *prop = get_property(soc, "reg", &size);
Kumar Galaeed32002006-01-13 11:19:13 -060045 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) {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100089 const u32 *id =
90 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;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000130 const unsigned int *id;
131 const char *model;
132 const void *mac_addr;
133 const phandle *ph;
Kumar Galaeed32002006-01-13 11:19:13 -0600134
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
172 mac_addr = get_property(np, "address", NULL);
173 memcpy(gfar_data.mac_addr, mac_addr, 6);
174
175 if (model && !strcasecmp(model, "TSEC"))
176 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600177 FSL_GIANFAR_DEV_HAS_GIGABIT |
178 FSL_GIANFAR_DEV_HAS_COALESCE |
179 FSL_GIANFAR_DEV_HAS_RMON |
180 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600181 if (model && !strcasecmp(model, "eTSEC"))
182 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600183 FSL_GIANFAR_DEV_HAS_GIGABIT |
184 FSL_GIANFAR_DEV_HAS_COALESCE |
185 FSL_GIANFAR_DEV_HAS_RMON |
186 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
187 FSL_GIANFAR_DEV_HAS_CSUM |
188 FSL_GIANFAR_DEV_HAS_VLAN |
189 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600190
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000191 ph = get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600192 phy = of_find_node_by_phandle(*ph);
193
194 if (phy == NULL) {
195 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600196 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600197 }
198
199 mdio = of_get_parent(phy);
200
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000201 id = get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600202 ret = of_address_to_resource(mdio, 0, &res);
203 if (ret) {
204 of_node_put(phy);
205 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600206 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600207 }
208
209 gfar_data.phy_id = *id;
210 gfar_data.bus_id = res.start;
211
212 of_node_put(phy);
213 of_node_put(mdio);
214
Kumar Gala2fb07d72006-01-23 16:58:04 -0600215 ret =
216 platform_device_add_data(gfar_dev, &gfar_data,
217 sizeof(struct
218 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600219 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600220 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600221 }
222
223 return 0;
224
Kumar Gala2fb07d72006-01-23 16:58:04 -0600225unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600226 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600227err:
Kumar Galaeed32002006-01-13 11:19:13 -0600228 return ret;
229}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600230
Kumar Galaeed32002006-01-13 11:19:13 -0600231arch_initcall(gfar_of_init);
232
233static int __init fsl_i2c_of_init(void)
234{
235 struct device_node *np;
236 unsigned int i;
237 struct platform_device *i2c_dev;
238 int ret;
239
Kumar Gala2fb07d72006-01-23 16:58:04 -0600240 for (np = NULL, i = 0;
241 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
242 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600243 struct resource r[2];
244 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000245 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600246
247 memset(&r, 0, sizeof(r));
248 memset(&i2c_data, 0, sizeof(i2c_data));
249
250 ret = of_address_to_resource(np, 0, &r[0]);
251 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600252 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600253
254 r[1].start = np->intrs[0].line;
255 r[1].end = np->intrs[0].line;
256 r[1].flags = IORESOURCE_IRQ;
257
258 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
259 if (IS_ERR(i2c_dev)) {
260 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600261 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600262 }
263
264 i2c_data.device_flags = 0;
265 flags = get_property(np, "dfsrr", NULL);
266 if (flags)
267 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
268
269 flags = get_property(np, "fsl5200-clocking", NULL);
270 if (flags)
271 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
272
Kumar Gala2fb07d72006-01-23 16:58:04 -0600273 ret =
274 platform_device_add_data(i2c_dev, &i2c_data,
275 sizeof(struct
276 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600277 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600278 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600279 }
280
281 return 0;
282
Kumar Gala2fb07d72006-01-23 16:58:04 -0600283unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600284 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600285err:
Kumar Galaeed32002006-01-13 11:19:13 -0600286 return ret;
287}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600288
Kumar Galaeed32002006-01-13 11:19:13 -0600289arch_initcall(fsl_i2c_of_init);
290
291#ifdef CONFIG_PPC_83xx
292static int __init mpc83xx_wdt_init(void)
293{
294 struct resource r;
295 struct device_node *soc, *np;
296 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000297 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600298 int ret;
299
300 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
301
302 if (!np) {
303 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600304 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600305 }
306
307 soc = of_find_node_by_type(NULL, "soc");
308
309 if (!soc) {
310 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600311 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600312 }
313
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000314 freq = get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600315 if (!freq) {
316 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600317 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600318 }
319
320 memset(&r, 0, sizeof(r));
321
322 ret = of_address_to_resource(np, 0, &r);
323 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600324 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600325
326 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
327 if (IS_ERR(dev)) {
328 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600329 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600330 }
331
332 ret = platform_device_add_data(dev, freq, sizeof(int));
333 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600334 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600335
336 of_node_put(soc);
337 of_node_put(np);
338
339 return 0;
340
Kumar Gala2fb07d72006-01-23 16:58:04 -0600341unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600342 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600343err:
Kumar Galaeed32002006-01-13 11:19:13 -0600344 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600345nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600346 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600347nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600348 return ret;
349}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600350
Kumar Galaeed32002006-01-13 11:19:13 -0600351arch_initcall(mpc83xx_wdt_init);
352#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600353
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000354static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600355{
356 if (!phy_type)
357 return FSL_USB2_PHY_NONE;
358 if (!strcasecmp(phy_type, "ulpi"))
359 return FSL_USB2_PHY_ULPI;
360 if (!strcasecmp(phy_type, "utmi"))
361 return FSL_USB2_PHY_UTMI;
362 if (!strcasecmp(phy_type, "utmi_wide"))
363 return FSL_USB2_PHY_UTMI_WIDE;
364 if (!strcasecmp(phy_type, "serial"))
365 return FSL_USB2_PHY_SERIAL;
366
367 return FSL_USB2_PHY_NONE;
368}
369
370static int __init fsl_usb_of_init(void)
371{
372 struct device_node *np;
373 unsigned int i;
Kumar Gala01cced22006-04-11 10:07:16 -0500374 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600375 int ret;
376
377 for (np = NULL, i = 0;
378 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
379 i++) {
380 struct resource r[2];
381 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000382 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600383
384 memset(&r, 0, sizeof(r));
385 memset(&usb_data, 0, sizeof(usb_data));
386
387 ret = of_address_to_resource(np, 0, &r[0]);
388 if (ret)
389 goto err;
390
391 r[1].start = np->intrs[0].line;
392 r[1].end = np->intrs[0].line;
393 r[1].flags = IORESOURCE_IRQ;
394
Kumar Gala01cced22006-04-11 10:07:16 -0500395 usb_dev_mph =
396 platform_device_register_simple("fsl-ehci", i, r, 2);
397 if (IS_ERR(usb_dev_mph)) {
398 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600399 goto err;
400 }
401
Kumar Gala01cced22006-04-11 10:07:16 -0500402 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
403 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600404
405 usb_data.operating_mode = FSL_USB2_MPH_HOST;
406
407 prop = get_property(np, "port0", NULL);
408 if (prop)
409 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
410
411 prop = get_property(np, "port1", NULL);
412 if (prop)
413 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
414
415 prop = get_property(np, "phy_type", NULL);
416 usb_data.phy_mode = determine_usb_phy(prop);
417
418 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500419 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600420 sizeof(struct
421 fsl_usb2_platform_data));
422 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500423 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600424 }
425
Kumar Gala01cced22006-04-11 10:07:16 -0500426 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600427 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
428 i++) {
429 struct resource r[2];
430 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000431 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600432
433 memset(&r, 0, sizeof(r));
434 memset(&usb_data, 0, sizeof(usb_data));
435
436 ret = of_address_to_resource(np, 0, &r[0]);
437 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500438 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600439
440 r[1].start = np->intrs[0].line;
441 r[1].end = np->intrs[0].line;
442 r[1].flags = IORESOURCE_IRQ;
443
Kumar Gala01cced22006-04-11 10:07:16 -0500444 usb_dev_dr =
445 platform_device_register_simple("fsl-ehci", i, r, 2);
446 if (IS_ERR(usb_dev_dr)) {
447 ret = PTR_ERR(usb_dev_dr);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600448 goto err;
449 }
450
Kumar Gala01cced22006-04-11 10:07:16 -0500451 usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
452 usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600453
454 usb_data.operating_mode = FSL_USB2_DR_HOST;
455
456 prop = get_property(np, "phy_type", NULL);
457 usb_data.phy_mode = determine_usb_phy(prop);
458
459 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500460 platform_device_add_data(usb_dev_dr, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600461 sizeof(struct
462 fsl_usb2_platform_data));
463 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500464 goto unreg_dr;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600465 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600466 return 0;
467
Kumar Gala01cced22006-04-11 10:07:16 -0500468unreg_dr:
469 if (usb_dev_dr)
470 platform_device_unregister(usb_dev_dr);
471unreg_mph:
472 if (usb_dev_mph)
473 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600474err:
475 return ret;
476}
477
Kumar Gala01cced22006-04-11 10:07:16 -0500478arch_initcall(fsl_usb_of_init);