[POWERPC] fsl: Add CS4270 i2c data to fsl_soc.c
[linux-block.git] / arch / powerpc / sysdev / fsl_soc.c
CommitLineData
eed32001
KG
1/*
2 * FSL SoC setup code
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5 *
fba43665
VB
6 * 2006 (c) MontaVista Software, Inc.
7 * Vitaly Bordug <vbordug@ru.mvista.com>
8 *
eed32001
KG
9 * 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
eed32001
KG
15#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>
0af666fa 25#include <linux/of_platform.h>
a9b14973 26#include <linux/phy.h>
a21e282a 27#include <linux/phy_fixed.h>
26f6cb99 28#include <linux/spi/spi.h>
eed32001 29#include <linux/fsl_devices.h>
fba43665
VB
30#include <linux/fs_enet_pd.h>
31#include <linux/fs_uart_pd.h>
eed32001
KG
32
33#include <asm/system.h>
34#include <asm/atomic.h>
35#include <asm/io.h>
36#include <asm/irq.h>
fba43665 37#include <asm/time.h>
eed32001
KG
38#include <asm/prom.h>
39#include <sysdev/fsl_soc.h>
40#include <mm/mmu_decl.h>
fba43665 41#include <asm/cpm2.h>
eed32001 42
d3465c92 43extern void init_fcc_ioports(struct fs_platform_info*);
88bdc6f0
VB
44extern void init_fec_ioports(struct fs_platform_info*);
45extern void init_smc_ioports(struct fs_uart_platform_info*);
eed32001
KG
46static phys_addr_t immrbase = -1;
47
48phys_addr_t get_immrbase(void)
49{
50 struct device_node *soc;
51
52 if (immrbase != -1)
53 return immrbase;
54
55 soc = of_find_node_by_type(NULL, "soc");
2fb07d77 56 if (soc) {
f9234736 57 int size;
6c7e072b
SW
58 u32 naddr;
59 const u32 *prop = of_get_property(soc, "#address-cells", &size);
fba43665 60
6c7e072b
SW
61 if (prop && size == 4)
62 naddr = *prop;
63 else
64 naddr = 2;
65
66 prop = of_get_property(soc, "ranges", &size);
fba43665 67 if (prop)
6c7e072b
SW
68 immrbase = of_translate_address(soc, prop + naddr);
69
eed32001 70 of_node_put(soc);
f9234736 71 }
eed32001
KG
72
73 return immrbase;
74}
eed32001 75
2fb07d77 76EXPORT_SYMBOL(get_immrbase);
eed32001 77
38664095
SW
78static u32 sysfreq = -1;
79
80u32 fsl_get_sys_freq(void)
81{
82 struct device_node *soc;
83 const u32 *prop;
84 int size;
85
86 if (sysfreq != -1)
87 return sysfreq;
88
89 soc = of_find_node_by_type(NULL, "soc");
90 if (!soc)
91 return -1;
92
93 prop = of_get_property(soc, "clock-frequency", &size);
94 if (!prop || size != sizeof(*prop) || *prop == 0)
95 prop = of_get_property(soc, "bus-frequency", &size);
96
97 if (prop && size == sizeof(*prop))
98 sysfreq = *prop;
99
100 of_node_put(soc);
101 return sysfreq;
102}
103EXPORT_SYMBOL(fsl_get_sys_freq);
104
59a0ea50 105#if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
fba43665
VB
106
107static u32 brgfreq = -1;
108
109u32 get_brgfreq(void)
110{
111 struct device_node *node;
6d817aa7
SW
112 const unsigned int *prop;
113 int size;
fba43665
VB
114
115 if (brgfreq != -1)
116 return brgfreq;
117
6d817aa7 118 node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
fba43665 119 if (node) {
6d817aa7
SW
120 prop = of_get_property(node, "clock-frequency", &size);
121 if (prop && size == 4)
122 brgfreq = *prop;
123
124 of_node_put(node);
125 return brgfreq;
126 }
fba43665 127
6d817aa7
SW
128 /* Legacy device binding -- will go away when no users are left. */
129 node = of_find_node_by_type(NULL, "cpm");
59a0ea50
AV
130 if (!node)
131 node = of_find_compatible_node(NULL, NULL, "fsl,qe");
132 if (!node)
133 node = of_find_node_by_type(NULL, "qe");
134
6d817aa7
SW
135 if (node) {
136 prop = of_get_property(node, "brg-frequency", &size);
f9234736 137 if (prop && size == 4)
fba43665 138 brgfreq = *prop;
f9234736 139
59a0ea50
AV
140 if (brgfreq == -1 || brgfreq == 0) {
141 prop = of_get_property(node, "bus-frequency", &size);
142 if (prop && size == 4)
143 brgfreq = *prop / 2;
144 }
fba43665 145 of_node_put(node);
f9234736 146 }
fba43665
VB
147
148 return brgfreq;
149}
150
151EXPORT_SYMBOL(get_brgfreq);
152
153static u32 fs_baudrate = -1;
154
155u32 get_baudrate(void)
156{
157 struct device_node *node;
158
159 if (fs_baudrate != -1)
160 return fs_baudrate;
161
162 node = of_find_node_by_type(NULL, "serial");
163 if (node) {
f9234736 164 int size;
e2eb6392
SR
165 const unsigned int *prop = of_get_property(node,
166 "current-speed", &size);
fba43665
VB
167
168 if (prop)
169 fs_baudrate = *prop;
170 of_node_put(node);
f9234736 171 }
fba43665
VB
172
173 return fs_baudrate;
174}
175
176EXPORT_SYMBOL(get_baudrate);
177#endif /* CONFIG_CPM2 */
178
a21e282a
VB
179#ifdef CONFIG_FIXED_PHY
180static int __init of_add_fixed_phys(void)
181{
182 int ret;
183 struct device_node *np;
184 u32 *fixed_link;
185 struct fixed_phy_status status = {};
186
187 for_each_node_by_name(np, "ethernet") {
188 fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
189 if (!fixed_link)
190 continue;
191
192 status.link = 1;
193 status.duplex = fixed_link[1];
194 status.speed = fixed_link[2];
195 status.pause = fixed_link[3];
196 status.asym_pause = fixed_link[4];
197
198 ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
199 if (ret) {
200 of_node_put(np);
201 return ret;
202 }
203 }
204
205 return 0;
206}
207arch_initcall(of_add_fixed_phys);
208#endif /* CONFIG_FIXED_PHY */
209
2fb07d77 210static int __init gfar_mdio_of_init(void)
eed32001 211{
e77b28eb 212 struct device_node *np = NULL;
2fb07d77 213 struct platform_device *mdio_dev;
eed32001
KG
214 struct resource res;
215 int ret;
216
e77b28eb
KG
217 np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
218
219 /* try the deprecated version */
220 if (!np)
221 np = of_find_compatible_node(np, "mdio", "gianfar");
222
223 if (np) {
eed32001
KG
224 int k;
225 struct device_node *child = NULL;
226 struct gianfar_mdio_data mdio_data;
227
228 memset(&res, 0, sizeof(res));
229 memset(&mdio_data, 0, sizeof(mdio_data));
230
231 ret = of_address_to_resource(np, 0, &res);
232 if (ret)
2fb07d77 233 goto err;
eed32001 234
2fb07d77
KG
235 mdio_dev =
236 platform_device_register_simple("fsl-gianfar_mdio",
237 res.start, &res, 1);
eed32001
KG
238 if (IS_ERR(mdio_dev)) {
239 ret = PTR_ERR(mdio_dev);
2fb07d77 240 goto err;
eed32001
KG
241 }
242
243 for (k = 0; k < 32; k++)
a9b14973 244 mdio_data.irq[k] = PHY_POLL;
eed32001
KG
245
246 while ((child = of_get_next_child(np, child)) != NULL) {
fba43665
VB
247 int irq = irq_of_parse_and_map(child, 0);
248 if (irq != NO_IRQ) {
e2eb6392
SR
249 const u32 *id = of_get_property(child,
250 "reg", NULL);
fba43665
VB
251 mdio_data.irq[*id] = irq;
252 }
eed32001
KG
253 }
254
2fb07d77
KG
255 ret =
256 platform_device_add_data(mdio_dev, &mdio_data,
257 sizeof(struct gianfar_mdio_data));
eed32001 258 if (ret)
2fb07d77 259 goto unreg;
eed32001
KG
260 }
261
e77b28eb 262 of_node_put(np);
2fb07d77
KG
263 return 0;
264
265unreg:
266 platform_device_unregister(mdio_dev);
267err:
e77b28eb 268 of_node_put(np);
2fb07d77
KG
269 return ret;
270}
271
272arch_initcall(gfar_mdio_of_init);
273
274static const char *gfar_tx_intr = "tx";
275static const char *gfar_rx_intr = "rx";
276static const char *gfar_err_intr = "error";
277
278static int __init gfar_of_init(void)
279{
280 struct device_node *np;
281 unsigned int i;
282 struct platform_device *gfar_dev;
283 struct resource res;
284 int ret;
285
286 for (np = NULL, i = 0;
287 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
288 i++) {
eed32001
KG
289 struct resource r[4];
290 struct device_node *phy, *mdio;
291 struct gianfar_platform_data gfar_data;
a7f67bdf
JK
292 const unsigned int *id;
293 const char *model;
7132ab7f 294 const char *ctype;
a7f67bdf
JK
295 const void *mac_addr;
296 const phandle *ph;
fba43665 297 int n_res = 2;
eed32001
KG
298
299 memset(r, 0, sizeof(r));
300 memset(&gfar_data, 0, sizeof(gfar_data));
301
302 ret = of_address_to_resource(np, 0, &r[0]);
303 if (ret)
2fb07d77 304 goto err;
eed32001 305
a9b14973 306 of_irq_to_resource(np, 0, &r[1]);
eed32001 307
e2eb6392 308 model = of_get_property(np, "model", NULL);
eed32001
KG
309
310 /* If we aren't the FEC we have multiple interrupts */
311 if (model && strcasecmp(model, "FEC")) {
312 r[1].name = gfar_tx_intr;
313
314 r[2].name = gfar_rx_intr;
a9b14973 315 of_irq_to_resource(np, 1, &r[2]);
eed32001
KG
316
317 r[3].name = gfar_err_intr;
a9b14973 318 of_irq_to_resource(np, 2, &r[3]);
919fede6
JL
319
320 n_res += 2;
eed32001
KG
321 }
322
2fb07d77
KG
323 gfar_dev =
324 platform_device_register_simple("fsl-gianfar", i, &r[0],
fba43665 325 n_res);
eed32001
KG
326
327 if (IS_ERR(gfar_dev)) {
328 ret = PTR_ERR(gfar_dev);
2fb07d77 329 goto err;
eed32001
KG
330 }
331
29cfe6f4 332 mac_addr = of_get_mac_address(np);
f583165f
JL
333 if (mac_addr)
334 memcpy(gfar_data.mac_addr, mac_addr, 6);
eed32001
KG
335
336 if (model && !strcasecmp(model, "TSEC"))
337 gfar_data.device_flags =
2fb07d77
KG
338 FSL_GIANFAR_DEV_HAS_GIGABIT |
339 FSL_GIANFAR_DEV_HAS_COALESCE |
340 FSL_GIANFAR_DEV_HAS_RMON |
341 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
eed32001
KG
342 if (model && !strcasecmp(model, "eTSEC"))
343 gfar_data.device_flags =
2fb07d77
KG
344 FSL_GIANFAR_DEV_HAS_GIGABIT |
345 FSL_GIANFAR_DEV_HAS_COALESCE |
346 FSL_GIANFAR_DEV_HAS_RMON |
347 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
348 FSL_GIANFAR_DEV_HAS_CSUM |
349 FSL_GIANFAR_DEV_HAS_VLAN |
350 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
eed32001 351
7132ab7f
AF
352 ctype = of_get_property(np, "phy-connection-type", NULL);
353
354 /* We only care about rgmii-id. The rest are autodetected */
355 if (ctype && !strcmp(ctype, "rgmii-id"))
356 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
357 else
358 gfar_data.interface = PHY_INTERFACE_MODE_MII;
359
e2eb6392 360 ph = of_get_property(np, "phy-handle", NULL);
a21e282a
VB
361 if (ph == NULL) {
362 u32 *fixed_link;
363
364 fixed_link = (u32 *)of_get_property(np, "fixed-link",
365 NULL);
366 if (!fixed_link) {
367 ret = -ENODEV;
368 goto unreg;
369 }
eed32001 370
9d9326d3 371 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
a21e282a
VB
372 gfar_data.phy_id = fixed_link[0];
373 } else {
374 phy = of_find_node_by_phandle(*ph);
eed32001 375
a21e282a
VB
376 if (phy == NULL) {
377 ret = -ENODEV;
378 goto unreg;
379 }
380
381 mdio = of_get_parent(phy);
382
383 id = of_get_property(phy, "reg", NULL);
384 ret = of_address_to_resource(mdio, 0, &res);
385 if (ret) {
386 of_node_put(phy);
387 of_node_put(mdio);
388 goto unreg;
389 }
390
391 gfar_data.phy_id = *id;
128cf7f2
BB
392 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx",
393 (unsigned long long)res.start);
eed32001 394
eed32001
KG
395 of_node_put(phy);
396 of_node_put(mdio);
eed32001
KG
397 }
398
2fb07d77
KG
399 ret =
400 platform_device_add_data(gfar_dev, &gfar_data,
401 sizeof(struct
402 gianfar_platform_data));
eed32001 403 if (ret)
2fb07d77 404 goto unreg;
eed32001
KG
405 }
406
407 return 0;
408
2fb07d77 409unreg:
eed32001 410 platform_device_unregister(gfar_dev);
2fb07d77 411err:
eed32001
KG
412 return ret;
413}
2fb07d77 414
eed32001
KG
415arch_initcall(gfar_of_init);
416
d13ae862
GL
417#ifdef CONFIG_I2C_BOARDINFO
418#include <linux/i2c.h>
419struct i2c_driver_device {
420 char *of_device;
d13ae862
GL
421 char *i2c_type;
422};
423
424static struct i2c_driver_device i2c_devices[] __initdata = {
3760f736
JD
425 {"ricoh,rs5c372a", "rs5c372a"},
426 {"ricoh,rs5c372b", "rs5c372b"},
427 {"ricoh,rv5c386", "rv5c386"},
428 {"ricoh,rv5c387a", "rv5c387a"},
429 {"dallas,ds1307", "ds1307"},
430 {"dallas,ds1337", "ds1337"},
431 {"dallas,ds1338", "ds1338"},
432 {"dallas,ds1339", "ds1339"},
433 {"dallas,ds1340", "ds1340"},
434 {"stm,m41t00", "m41t00"},
435 {"dallas,ds1374", "rtc-ds1374"},
64f9b5ee 436 {"cirrus,cs4270", "cs4270"},
d13ae862
GL
437};
438
e78bb5dc
GL
439static int __init of_find_i2c_driver(struct device_node *node,
440 struct i2c_board_info *info)
d13ae862
GL
441{
442 int i;
443
444 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
445 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
446 continue;
3760f736 447 if (strlcpy(info->type, i2c_devices[i].i2c_type,
e78bb5dc
GL
448 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
449 return -ENOMEM;
d13ae862
GL
450 return 0;
451 }
22fb7d9b
TT
452
453 pr_warning("fsl_soc.c: unrecognized i2c node %s\n",
454 (const char *) of_get_property(node, "compatible", NULL));
455
d13ae862
GL
456 return -ENODEV;
457}
458
e78bb5dc
GL
459static void __init of_register_i2c_devices(struct device_node *adap_node,
460 int bus_num)
d13ae862
GL
461{
462 struct device_node *node = NULL;
463
464 while ((node = of_get_next_child(adap_node, node))) {
da1bb3a0 465 struct i2c_board_info info = {};
d13ae862
GL
466 const u32 *addr;
467 int len;
468
469 addr = of_get_property(node, "reg", &len);
470 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
210805e2 471 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
d13ae862
GL
472 continue;
473 }
474
475 info.irq = irq_of_parse_and_map(node, 0);
476 if (info.irq == NO_IRQ)
477 info.irq = -1;
478
479 if (of_find_i2c_driver(node, &info) < 0)
480 continue;
481
d13ae862
GL
482 info.addr = *addr;
483
484 i2c_register_board_info(bus_num, &info, 1);
485 }
486}
487
eed32001
KG
488static int __init fsl_i2c_of_init(void)
489{
490 struct device_node *np;
ec9686c4 491 unsigned int i = 0;
eed32001
KG
492 struct platform_device *i2c_dev;
493 int ret;
494
ec9686c4 495 for_each_compatible_node(np, NULL, "fsl-i2c") {
eed32001
KG
496 struct resource r[2];
497 struct fsl_i2c_platform_data i2c_data;
a7f67bdf 498 const unsigned char *flags = NULL;
eed32001
KG
499
500 memset(&r, 0, sizeof(r));
501 memset(&i2c_data, 0, sizeof(i2c_data));
502
503 ret = of_address_to_resource(np, 0, &r[0]);
504 if (ret)
2fb07d77 505 goto err;
eed32001 506
a9b14973 507 of_irq_to_resource(np, 0, &r[1]);
eed32001
KG
508
509 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
510 if (IS_ERR(i2c_dev)) {
511 ret = PTR_ERR(i2c_dev);
2fb07d77 512 goto err;
eed32001
KG
513 }
514
515 i2c_data.device_flags = 0;
e2eb6392 516 flags = of_get_property(np, "dfsrr", NULL);
eed32001
KG
517 if (flags)
518 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
519
e2eb6392 520 flags = of_get_property(np, "fsl5200-clocking", NULL);
eed32001
KG
521 if (flags)
522 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
523
2fb07d77
KG
524 ret =
525 platform_device_add_data(i2c_dev, &i2c_data,
526 sizeof(struct
527 fsl_i2c_platform_data));
eed32001 528 if (ret)
2fb07d77 529 goto unreg;
d13ae862 530
ec9686c4 531 of_register_i2c_devices(np, i++);
eed32001
KG
532 }
533
534 return 0;
535
2fb07d77 536unreg:
eed32001 537 platform_device_unregister(i2c_dev);
2fb07d77 538err:
eed32001
KG
539 return ret;
540}
2fb07d77 541
eed32001 542arch_initcall(fsl_i2c_of_init);
d13ae862 543#endif
eed32001
KG
544
545#ifdef CONFIG_PPC_83xx
546static int __init mpc83xx_wdt_init(void)
547{
548 struct resource r;
38664095 549 struct device_node *np;
eed32001 550 struct platform_device *dev;
38664095 551 u32 freq = fsl_get_sys_freq();
eed32001
KG
552 int ret;
553
554 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
555
556 if (!np) {
557 ret = -ENODEV;
2fb07d77 558 goto nodev;
eed32001
KG
559 }
560
eed32001
KG
561 memset(&r, 0, sizeof(r));
562
563 ret = of_address_to_resource(np, 0, &r);
564 if (ret)
2fb07d77 565 goto err;
eed32001
KG
566
567 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
568 if (IS_ERR(dev)) {
569 ret = PTR_ERR(dev);
2fb07d77 570 goto err;
eed32001
KG
571 }
572
38664095 573 ret = platform_device_add_data(dev, &freq, sizeof(freq));
eed32001 574 if (ret)
2fb07d77 575 goto unreg;
eed32001 576
eed32001 577 of_node_put(np);
eed32001
KG
578 return 0;
579
2fb07d77 580unreg:
eed32001 581 platform_device_unregister(dev);
2fb07d77 582err:
eed32001 583 of_node_put(np);
2fb07d77 584nodev:
eed32001
KG
585 return ret;
586}
2fb07d77 587
eed32001
KG
588arch_initcall(mpc83xx_wdt_init);
589#endif
4b10cfd4 590
a7f67bdf 591static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
4b10cfd4
KG
592{
593 if (!phy_type)
594 return FSL_USB2_PHY_NONE;
595 if (!strcasecmp(phy_type, "ulpi"))
596 return FSL_USB2_PHY_ULPI;
597 if (!strcasecmp(phy_type, "utmi"))
598 return FSL_USB2_PHY_UTMI;
599 if (!strcasecmp(phy_type, "utmi_wide"))
600 return FSL_USB2_PHY_UTMI_WIDE;
601 if (!strcasecmp(phy_type, "serial"))
602 return FSL_USB2_PHY_SERIAL;
603
604 return FSL_USB2_PHY_NONE;
605}
606
607static int __init fsl_usb_of_init(void)
608{
609 struct device_node *np;
866b6ddd 610 unsigned int i = 0;
97c5a20a
LY
611 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
612 *usb_dev_dr_client = NULL;
4b10cfd4
KG
613 int ret;
614
866b6ddd 615 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
4b10cfd4
KG
616 struct resource r[2];
617 struct fsl_usb2_platform_data usb_data;
a7f67bdf 618 const unsigned char *prop = NULL;
4b10cfd4
KG
619
620 memset(&r, 0, sizeof(r));
621 memset(&usb_data, 0, sizeof(usb_data));
622
623 ret = of_address_to_resource(np, 0, &r[0]);
624 if (ret)
625 goto err;
626
a9b14973 627 of_irq_to_resource(np, 0, &r[1]);
4b10cfd4 628
01cced25
KG
629 usb_dev_mph =
630 platform_device_register_simple("fsl-ehci", i, r, 2);
631 if (IS_ERR(usb_dev_mph)) {
632 ret = PTR_ERR(usb_dev_mph);
4b10cfd4
KG
633 goto err;
634 }
635
01cced25
KG
636 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
637 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
4b10cfd4
KG
638
639 usb_data.operating_mode = FSL_USB2_MPH_HOST;
640
e2eb6392 641 prop = of_get_property(np, "port0", NULL);
4b10cfd4
KG
642 if (prop)
643 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
644
e2eb6392 645 prop = of_get_property(np, "port1", NULL);
4b10cfd4
KG
646 if (prop)
647 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
648
e2eb6392 649 prop = of_get_property(np, "phy_type", NULL);
4b10cfd4
KG
650 usb_data.phy_mode = determine_usb_phy(prop);
651
652 ret =
01cced25 653 platform_device_add_data(usb_dev_mph, &usb_data,
4b10cfd4
KG
654 sizeof(struct
655 fsl_usb2_platform_data));
656 if (ret)
01cced25 657 goto unreg_mph;
866b6ddd 658 i++;
4b10cfd4
KG
659 }
660
866b6ddd 661 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
4b10cfd4
KG
662 struct resource r[2];
663 struct fsl_usb2_platform_data usb_data;
a7f67bdf 664 const unsigned char *prop = NULL;
4b10cfd4
KG
665
666 memset(&r, 0, sizeof(r));
667 memset(&usb_data, 0, sizeof(usb_data));
668
669 ret = of_address_to_resource(np, 0, &r[0]);
670 if (ret)
01cced25 671 goto unreg_mph;
4b10cfd4 672
a9b14973 673 of_irq_to_resource(np, 0, &r[1]);
4b10cfd4 674
e2eb6392 675 prop = of_get_property(np, "dr_mode", NULL);
97c5a20a
LY
676
677 if (!prop || !strcmp(prop, "host")) {
678 usb_data.operating_mode = FSL_USB2_DR_HOST;
679 usb_dev_dr_host = platform_device_register_simple(
680 "fsl-ehci", i, r, 2);
681 if (IS_ERR(usb_dev_dr_host)) {
682 ret = PTR_ERR(usb_dev_dr_host);
683 goto err;
684 }
685 } else if (prop && !strcmp(prop, "peripheral")) {
686 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
687 usb_dev_dr_client = platform_device_register_simple(
688 "fsl-usb2-udc", i, r, 2);
689 if (IS_ERR(usb_dev_dr_client)) {
690 ret = PTR_ERR(usb_dev_dr_client);
691 goto err;
692 }
693 } else if (prop && !strcmp(prop, "otg")) {
694 usb_data.operating_mode = FSL_USB2_DR_OTG;
695 usb_dev_dr_host = platform_device_register_simple(
696 "fsl-ehci", i, r, 2);
697 if (IS_ERR(usb_dev_dr_host)) {
698 ret = PTR_ERR(usb_dev_dr_host);
699 goto err;
700 }
701 usb_dev_dr_client = platform_device_register_simple(
702 "fsl-usb2-udc", i, r, 2);
703 if (IS_ERR(usb_dev_dr_client)) {
704 ret = PTR_ERR(usb_dev_dr_client);
705 goto err;
706 }
707 } else {
708 ret = -EINVAL;
4b10cfd4
KG
709 goto err;
710 }
711
e2eb6392 712 prop = of_get_property(np, "phy_type", NULL);
4b10cfd4
KG
713 usb_data.phy_mode = determine_usb_phy(prop);
714
97c5a20a
LY
715 if (usb_dev_dr_host) {
716 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
717 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
718 dev.coherent_dma_mask;
719 if ((ret = platform_device_add_data(usb_dev_dr_host,
720 &usb_data, sizeof(struct
721 fsl_usb2_platform_data))))
722 goto unreg_dr;
723 }
724 if (usb_dev_dr_client) {
725 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
726 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
727 dev.coherent_dma_mask;
728 if ((ret = platform_device_add_data(usb_dev_dr_client,
729 &usb_data, sizeof(struct
730 fsl_usb2_platform_data))))
731 goto unreg_dr;
732 }
866b6ddd 733 i++;
4b10cfd4 734 }
4b10cfd4
KG
735 return 0;
736
01cced25 737unreg_dr:
97c5a20a
LY
738 if (usb_dev_dr_host)
739 platform_device_unregister(usb_dev_dr_host);
740 if (usb_dev_dr_client)
741 platform_device_unregister(usb_dev_dr_client);
01cced25
KG
742unreg_mph:
743 if (usb_dev_mph)
744 platform_device_unregister(usb_dev_mph);
4b10cfd4
KG
745err:
746 return ret;
747}
748
01cced25 749arch_initcall(fsl_usb_of_init);
fba43665 750
f3a2b29d
AV
751static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
752 struct spi_board_info *board_infos,
753 unsigned int num_board_infos,
754 void (*activate_cs)(u8 cs, u8 polarity),
755 void (*deactivate_cs)(u8 cs, u8 polarity))
26f6cb99
AV
756{
757 struct device_node *np;
f3a2b29d 758 unsigned int i = 0;
26f6cb99 759
f3a2b29d
AV
760 for_each_compatible_node(np, type, compatible) {
761 int ret;
26f6cb99
AV
762 unsigned int j;
763 const void *prop;
764 struct resource res[2];
765 struct platform_device *pdev;
766 struct fsl_spi_platform_data pdata = {
767 .activate_cs = activate_cs,
768 .deactivate_cs = deactivate_cs,
769 };
770
771 memset(res, 0, sizeof(res));
772
59a0ea50 773 pdata.sysclk = sysclk;
26f6cb99
AV
774
775 prop = of_get_property(np, "reg", NULL);
776 if (!prop)
777 goto err;
778 pdata.bus_num = *(u32 *)prop;
779
f3a2b29d
AV
780 prop = of_get_property(np, "cell-index", NULL);
781 if (prop)
782 i = *(u32 *)prop;
783
26f6cb99
AV
784 prop = of_get_property(np, "mode", NULL);
785 if (prop && !strcmp(prop, "cpu-qe"))
786 pdata.qe_mode = 1;
787
788 for (j = 0; j < num_board_infos; j++) {
789 if (board_infos[j].bus_num == pdata.bus_num)
790 pdata.max_chipselect++;
791 }
792
793 if (!pdata.max_chipselect)
f3a2b29d 794 continue;
26f6cb99
AV
795
796 ret = of_address_to_resource(np, 0, &res[0]);
797 if (ret)
798 goto err;
799
800 ret = of_irq_to_resource(np, 0, &res[1]);
801 if (ret == NO_IRQ)
802 goto err;
803
804 pdev = platform_device_alloc("mpc83xx_spi", i);
805 if (!pdev)
806 goto err;
807
808 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
809 if (ret)
810 goto unreg;
811
812 ret = platform_device_add_resources(pdev, res,
813 ARRAY_SIZE(res));
814 if (ret)
815 goto unreg;
816
dc4e4207 817 ret = platform_device_add(pdev);
26f6cb99
AV
818 if (ret)
819 goto unreg;
820
f3a2b29d 821 goto next;
26f6cb99
AV
822unreg:
823 platform_device_del(pdev);
824err:
f3a2b29d
AV
825 pr_err("%s: registration failed\n", np->full_name);
826next:
827 i++;
26f6cb99
AV
828 }
829
f3a2b29d
AV
830 return i;
831}
832
833int __init fsl_spi_init(struct spi_board_info *board_infos,
834 unsigned int num_board_infos,
835 void (*activate_cs)(u8 cs, u8 polarity),
836 void (*deactivate_cs)(u8 cs, u8 polarity))
837{
838 u32 sysclk = -1;
839 int ret;
840
841#ifdef CONFIG_QUICC_ENGINE
842 /* SPI controller is either clocked from QE or SoC clock */
843 sysclk = get_brgfreq();
844#endif
845 if (sysclk == -1) {
38664095
SW
846 sysclk = fsl_get_sys_freq();
847 if (sysclk == -1)
f3a2b29d 848 return -ENODEV;
f3a2b29d
AV
849 }
850
851 ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
852 num_board_infos, activate_cs, deactivate_cs);
853 if (!ret)
854 of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
855 num_board_infos, activate_cs, deactivate_cs);
856
26f6cb99
AV
857 return spi_register_board_info(board_infos, num_board_infos);
858}
e1c1575f
KG
859
860#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
861static __be32 __iomem *rstcr;
862
863static int __init setup_rstcr(void)
864{
865 struct device_node *np;
866 np = of_find_node_by_name(NULL, "global-utilities");
867 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
868 const u32 *prop = of_get_property(np, "reg", NULL);
869 if (prop) {
870 /* map reset control register
871 * 0xE00B0 is offset of reset control register
872 */
873 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
874 if (!rstcr)
875 printk (KERN_EMERG "Error: reset control "
876 "register not mapped!\n");
877 }
878 } else
879 printk (KERN_INFO "rstcr compatible register does not exist!\n");
880 if (np)
881 of_node_put(np);
882 return 0;
883}
884
885arch_initcall(setup_rstcr);
886
887void fsl_rstcr_restart(char *cmd)
888{
889 local_irq_disable();
890 if (rstcr)
891 /* set reset control register */
892 out_be32(rstcr, 0x2); /* HRESET_REQ */
893
894 while (1) ;
895}
896#endif
6f90a8bd
YS
897
898#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
899struct platform_diu_data_ops diu_ops = {
900 .diu_size = 1280 * 1024 * 4, /* default one 1280x1024 buffer */
901};
902EXPORT_SYMBOL(diu_ops);
903
904int __init preallocate_diu_videomemory(void)
905{
906 pr_debug("diu_size=%lu\n", diu_ops.diu_size);
907
908 diu_ops.diu_mem = __alloc_bootmem(diu_ops.diu_size, 8, 0);
909 if (!diu_ops.diu_mem) {
910 printk(KERN_ERR "fsl-diu: cannot allocate %lu bytes\n",
911 diu_ops.diu_size);
912 return -ENOMEM;
913 }
914
915 pr_debug("diu_mem=%p\n", diu_ops.diu_mem);
916
917 rh_init(&diu_ops.diu_rh_info, 4096, ARRAY_SIZE(diu_ops.diu_rh_block),
918 diu_ops.diu_rh_block);
919 return rh_attach_region(&diu_ops.diu_rh_info,
920 (unsigned long) diu_ops.diu_mem,
921 diu_ops.diu_size);
922}
923
924static int __init early_parse_diufb(char *p)
925{
926 if (!p)
927 return 1;
928
929 diu_ops.diu_size = _ALIGN_UP(memparse(p, &p), 8);
930
931 pr_debug("diu_size=%lu\n", diu_ops.diu_size);
932
933 return 0;
934}
935early_param("diufb", early_parse_diufb);
936
937#endif