blob: ca180a93bca1e1f3c12074db96e3be5af6184e75 [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>
Kumar Gala0af666f2007-08-17 08:23:06 -050025#include <linux/of_platform.h>
Andy Fleminga9b14972006-10-19 19:52:26 -050026#include <linux/phy.h>
Vitaly Borduga21e2822007-12-07 01:51:31 +030027#include <linux/phy_fixed.h>
Anton Vorontsov26f6cb92007-08-23 15:35:56 +040028#include <linux/spi/spi.h>
Kumar Galaeed32002006-01-13 11:19:13 -060029#include <linux/fsl_devices.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040030#include <linux/fs_enet_pd.h>
31#include <linux/fs_uart_pd.h>
Kumar Galaeed32002006-01-13 11:19:13 -060032
33#include <asm/system.h>
34#include <asm/atomic.h>
35#include <asm/io.h>
36#include <asm/irq.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040037#include <asm/time.h>
Kumar Galaeed32002006-01-13 11:19:13 -060038#include <asm/prom.h>
39#include <sysdev/fsl_soc.h>
40#include <mm/mmu_decl.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040041#include <asm/cpm2.h>
Kumar Galaeed32002006-01-13 11:19:13 -060042
Vitaly Bordugd3465c92006-09-21 22:38:05 +040043extern void init_fcc_ioports(struct fs_platform_info*);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030044extern void init_fec_ioports(struct fs_platform_info*);
45extern void init_smc_ioports(struct fs_uart_platform_info*);
Kumar Galaeed32002006-01-13 11:19:13 -060046static 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");
Kumar Gala2fb07d72006-01-23 16:58:04 -060056 if (soc) {
Scott Woodf9234732007-08-20 11:38:12 -050057 int size;
Scott Wood6c7e0722008-01-14 10:29:35 -060058 u32 naddr;
59 const u32 *prop = of_get_property(soc, "#address-cells", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040060
Scott Wood6c7e0722008-01-14 10:29:35 -060061 if (prop && size == 4)
62 naddr = *prop;
63 else
64 naddr = 2;
65
66 prop = of_get_property(soc, "ranges", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040067 if (prop)
Scott Wood6c7e0722008-01-14 10:29:35 -060068 immrbase = of_translate_address(soc, prop + naddr);
69
Kumar Galaeed32002006-01-13 11:19:13 -060070 of_node_put(soc);
Scott Woodf9234732007-08-20 11:38:12 -050071 }
Kumar Galaeed32002006-01-13 11:19:13 -060072
73 return immrbase;
74}
Kumar Gala2fb07d72006-01-23 16:58:04 -060075
Kumar Galaeed32002006-01-13 11:19:13 -060076EXPORT_SYMBOL(get_immrbase);
77
Scott Wood38664092008-04-15 13:52:34 -050078static 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
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300105#if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
Vitaly Bordugfba43662006-09-21 17:26:34 +0400106
107static u32 brgfreq = -1;
108
109u32 get_brgfreq(void)
110{
111 struct device_node *node;
Scott Wood6d817aa2007-08-29 15:08:40 -0500112 const unsigned int *prop;
113 int size;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400114
115 if (brgfreq != -1)
116 return brgfreq;
117
Scott Wood6d817aa2007-08-29 15:08:40 -0500118 node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
Vitaly Bordugfba43662006-09-21 17:26:34 +0400119 if (node) {
Scott Wood6d817aa2007-08-29 15:08:40 -0500120 prop = of_get_property(node, "clock-frequency", &size);
121 if (prop && size == 4)
122 brgfreq = *prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400123
Scott Wood6d817aa2007-08-29 15:08:40 -0500124 of_node_put(node);
125 return brgfreq;
126 }
127
128 /* Legacy device binding -- will go away when no users are left. */
129 node = of_find_node_by_type(NULL, "cpm");
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300130 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
Scott Wood6d817aa2007-08-29 15:08:40 -0500135 if (node) {
136 prop = of_get_property(node, "brg-frequency", &size);
Scott Woodf9234732007-08-20 11:38:12 -0500137 if (prop && size == 4)
Vitaly Bordugfba43662006-09-21 17:26:34 +0400138 brgfreq = *prop;
Scott Woodf9234732007-08-20 11:38:12 -0500139
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300140 if (brgfreq == -1 || brgfreq == 0) {
141 prop = of_get_property(node, "bus-frequency", &size);
142 if (prop && size == 4)
143 brgfreq = *prop / 2;
144 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400145 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500146 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400147
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) {
Scott Woodf9234732007-08-20 11:38:12 -0500164 int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000165 const unsigned int *prop = of_get_property(node,
166 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400167
168 if (prop)
169 fs_baudrate = *prop;
170 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500171 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400172
173 return fs_baudrate;
174}
175
176EXPORT_SYMBOL(get_baudrate);
177#endif /* CONFIG_CPM2 */
178
Vitaly Borduga21e2822007-12-07 01:51:31 +0300179#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
Kumar Gala2fb07d72006-01-23 16:58:04 -0600210static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600211{
Kumar Galae77b28e2007-12-12 00:28:35 -0600212 struct device_node *np = NULL;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600213 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600214 struct resource res;
215 int ret;
216
Kumar Galae77b28e2007-12-12 00:28:35 -0600217 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) {
Kumar Galaeed32002006-01-13 11:19:13 -0600224 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)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600233 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600234
Kumar Gala2fb07d72006-01-23 16:58:04 -0600235 mdio_dev =
236 platform_device_register_simple("fsl-gianfar_mdio",
237 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600238 if (IS_ERR(mdio_dev)) {
239 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600240 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600241 }
242
243 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500244 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600245
246 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400247 int irq = irq_of_parse_and_map(child, 0);
248 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000249 const u32 *id = of_get_property(child,
250 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400251 mdio_data.irq[*id] = irq;
252 }
Kumar Galaeed32002006-01-13 11:19:13 -0600253 }
254
Kumar Gala2fb07d72006-01-23 16:58:04 -0600255 ret =
256 platform_device_add_data(mdio_dev, &mdio_data,
257 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600258 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600259 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600260 }
261
Kumar Galae77b28e2007-12-12 00:28:35 -0600262 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600263 return 0;
264
265unreg:
266 platform_device_unregister(mdio_dev);
267err:
Kumar Galae77b28e2007-12-12 00:28:35 -0600268 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600269 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++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600289 struct resource r[4];
290 struct device_node *phy, *mdio;
291 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000292 const unsigned int *id;
293 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500294 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000295 const void *mac_addr;
296 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400297 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600298
Anton Vorontsov69ad7e72008-07-08 21:36:40 +0400299 if (!of_device_is_available(np))
300 continue;
301
Kumar Galaeed32002006-01-13 11:19:13 -0600302 memset(r, 0, sizeof(r));
303 memset(&gfar_data, 0, sizeof(gfar_data));
304
305 ret = of_address_to_resource(np, 0, &r[0]);
306 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600307 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600308
Andy Fleminga9b14972006-10-19 19:52:26 -0500309 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600310
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000311 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600312
313 /* If we aren't the FEC we have multiple interrupts */
314 if (model && strcasecmp(model, "FEC")) {
315 r[1].name = gfar_tx_intr;
316
317 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500318 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600319
320 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500321 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500322
323 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600324 }
325
Kumar Gala2fb07d72006-01-23 16:58:04 -0600326 gfar_dev =
327 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400328 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600329
330 if (IS_ERR(gfar_dev)) {
331 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600332 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600333 }
334
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600335 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500336 if (mac_addr)
337 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600338
339 if (model && !strcasecmp(model, "TSEC"))
340 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600341 FSL_GIANFAR_DEV_HAS_GIGABIT |
342 FSL_GIANFAR_DEV_HAS_COALESCE |
343 FSL_GIANFAR_DEV_HAS_RMON |
344 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600345 if (model && !strcasecmp(model, "eTSEC"))
346 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600347 FSL_GIANFAR_DEV_HAS_GIGABIT |
348 FSL_GIANFAR_DEV_HAS_COALESCE |
349 FSL_GIANFAR_DEV_HAS_RMON |
350 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
351 FSL_GIANFAR_DEV_HAS_CSUM |
352 FSL_GIANFAR_DEV_HAS_VLAN |
353 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600354
Andy Fleming7132ab72007-07-11 11:43:07 -0500355 ctype = of_get_property(np, "phy-connection-type", NULL);
356
357 /* We only care about rgmii-id. The rest are autodetected */
358 if (ctype && !strcmp(ctype, "rgmii-id"))
359 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
360 else
361 gfar_data.interface = PHY_INTERFACE_MODE_MII;
362
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000363 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300364 if (ph == NULL) {
365 u32 *fixed_link;
Kumar Galaeed32002006-01-13 11:19:13 -0600366
Vitaly Borduga21e2822007-12-07 01:51:31 +0300367 fixed_link = (u32 *)of_get_property(np, "fixed-link",
368 NULL);
369 if (!fixed_link) {
370 ret = -ENODEV;
371 goto unreg;
372 }
Kumar Galaeed32002006-01-13 11:19:13 -0600373
Andy Fleming9d9326d2008-04-09 19:38:13 -0500374 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
Vitaly Borduga21e2822007-12-07 01:51:31 +0300375 gfar_data.phy_id = fixed_link[0];
376 } else {
377 phy = of_find_node_by_phandle(*ph);
Kumar Galaeed32002006-01-13 11:19:13 -0600378
Vitaly Borduga21e2822007-12-07 01:51:31 +0300379 if (phy == NULL) {
380 ret = -ENODEV;
381 goto unreg;
382 }
383
384 mdio = of_get_parent(phy);
385
386 id = of_get_property(phy, "reg", NULL);
387 ret = of_address_to_resource(mdio, 0, &res);
388 if (ret) {
389 of_node_put(phy);
390 of_node_put(mdio);
391 goto unreg;
392 }
393
394 gfar_data.phy_id = *id;
Becky Bruce128cf7f2008-05-01 18:15:45 -0500395 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx",
396 (unsigned long long)res.start);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300397
Kumar Galaeed32002006-01-13 11:19:13 -0600398 of_node_put(phy);
399 of_node_put(mdio);
Kumar Galaeed32002006-01-13 11:19:13 -0600400 }
401
Kumar Gala2fb07d72006-01-23 16:58:04 -0600402 ret =
403 platform_device_add_data(gfar_dev, &gfar_data,
404 sizeof(struct
405 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600406 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600407 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600408 }
409
410 return 0;
411
Kumar Gala2fb07d72006-01-23 16:58:04 -0600412unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600413 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600414err:
Kumar Galaeed32002006-01-13 11:19:13 -0600415 return ret;
416}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600417
Kumar Galaeed32002006-01-13 11:19:13 -0600418arch_initcall(gfar_of_init);
419
Kumar Galaeed32002006-01-13 11:19:13 -0600420
421#ifdef CONFIG_PPC_83xx
422static int __init mpc83xx_wdt_init(void)
423{
424 struct resource r;
Scott Wood38664092008-04-15 13:52:34 -0500425 struct device_node *np;
Kumar Galaeed32002006-01-13 11:19:13 -0600426 struct platform_device *dev;
Scott Wood38664092008-04-15 13:52:34 -0500427 u32 freq = fsl_get_sys_freq();
Kumar Galaeed32002006-01-13 11:19:13 -0600428 int ret;
429
430 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
431
432 if (!np) {
433 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600434 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600435 }
436
Kumar Galaeed32002006-01-13 11:19:13 -0600437 memset(&r, 0, sizeof(r));
438
439 ret = of_address_to_resource(np, 0, &r);
440 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600441 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600442
443 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
444 if (IS_ERR(dev)) {
445 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600446 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600447 }
448
Scott Wood38664092008-04-15 13:52:34 -0500449 ret = platform_device_add_data(dev, &freq, sizeof(freq));
Kumar Galaeed32002006-01-13 11:19:13 -0600450 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600451 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600452
Kumar Galaeed32002006-01-13 11:19:13 -0600453 of_node_put(np);
Kumar Galaeed32002006-01-13 11:19:13 -0600454 return 0;
455
Kumar Gala2fb07d72006-01-23 16:58:04 -0600456unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600457 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600458err:
Kumar Galaeed32002006-01-13 11:19:13 -0600459 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600460nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600461 return ret;
462}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600463
Kumar Galaeed32002006-01-13 11:19:13 -0600464arch_initcall(mpc83xx_wdt_init);
465#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600466
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000467static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600468{
469 if (!phy_type)
470 return FSL_USB2_PHY_NONE;
471 if (!strcasecmp(phy_type, "ulpi"))
472 return FSL_USB2_PHY_ULPI;
473 if (!strcasecmp(phy_type, "utmi"))
474 return FSL_USB2_PHY_UTMI;
475 if (!strcasecmp(phy_type, "utmi_wide"))
476 return FSL_USB2_PHY_UTMI_WIDE;
477 if (!strcasecmp(phy_type, "serial"))
478 return FSL_USB2_PHY_SERIAL;
479
480 return FSL_USB2_PHY_NONE;
481}
482
483static int __init fsl_usb_of_init(void)
484{
485 struct device_node *np;
Li Yang866b6dd2008-01-08 15:18:46 +0800486 unsigned int i = 0;
Li Yang97c5a202007-02-07 13:49:24 +0800487 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
488 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600489 int ret;
490
Li Yang866b6dd2008-01-08 15:18:46 +0800491 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600492 struct resource r[2];
493 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000494 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600495
496 memset(&r, 0, sizeof(r));
497 memset(&usb_data, 0, sizeof(usb_data));
498
499 ret = of_address_to_resource(np, 0, &r[0]);
500 if (ret)
501 goto err;
502
Andy Fleminga9b14972006-10-19 19:52:26 -0500503 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600504
Kumar Gala01cced22006-04-11 10:07:16 -0500505 usb_dev_mph =
506 platform_device_register_simple("fsl-ehci", i, r, 2);
507 if (IS_ERR(usb_dev_mph)) {
508 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600509 goto err;
510 }
511
Kumar Gala01cced22006-04-11 10:07:16 -0500512 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
513 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600514
515 usb_data.operating_mode = FSL_USB2_MPH_HOST;
516
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000517 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600518 if (prop)
519 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
520
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000521 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600522 if (prop)
523 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
524
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000525 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600526 usb_data.phy_mode = determine_usb_phy(prop);
527
528 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500529 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600530 sizeof(struct
531 fsl_usb2_platform_data));
532 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500533 goto unreg_mph;
Li Yang866b6dd2008-01-08 15:18:46 +0800534 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600535 }
536
Li Yang866b6dd2008-01-08 15:18:46 +0800537 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600538 struct resource r[2];
539 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000540 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600541
542 memset(&r, 0, sizeof(r));
543 memset(&usb_data, 0, sizeof(usb_data));
544
545 ret = of_address_to_resource(np, 0, &r[0]);
546 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500547 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600548
Andy Fleminga9b14972006-10-19 19:52:26 -0500549 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600550
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000551 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800552
553 if (!prop || !strcmp(prop, "host")) {
554 usb_data.operating_mode = FSL_USB2_DR_HOST;
555 usb_dev_dr_host = platform_device_register_simple(
556 "fsl-ehci", i, r, 2);
557 if (IS_ERR(usb_dev_dr_host)) {
558 ret = PTR_ERR(usb_dev_dr_host);
559 goto err;
560 }
561 } else if (prop && !strcmp(prop, "peripheral")) {
562 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
563 usb_dev_dr_client = platform_device_register_simple(
564 "fsl-usb2-udc", i, r, 2);
565 if (IS_ERR(usb_dev_dr_client)) {
566 ret = PTR_ERR(usb_dev_dr_client);
567 goto err;
568 }
569 } else if (prop && !strcmp(prop, "otg")) {
570 usb_data.operating_mode = FSL_USB2_DR_OTG;
571 usb_dev_dr_host = platform_device_register_simple(
572 "fsl-ehci", i, r, 2);
573 if (IS_ERR(usb_dev_dr_host)) {
574 ret = PTR_ERR(usb_dev_dr_host);
575 goto err;
576 }
577 usb_dev_dr_client = platform_device_register_simple(
578 "fsl-usb2-udc", i, r, 2);
579 if (IS_ERR(usb_dev_dr_client)) {
580 ret = PTR_ERR(usb_dev_dr_client);
581 goto err;
582 }
583 } else {
584 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600585 goto err;
586 }
587
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000588 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600589 usb_data.phy_mode = determine_usb_phy(prop);
590
Li Yang97c5a202007-02-07 13:49:24 +0800591 if (usb_dev_dr_host) {
592 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
593 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
594 dev.coherent_dma_mask;
595 if ((ret = platform_device_add_data(usb_dev_dr_host,
596 &usb_data, sizeof(struct
597 fsl_usb2_platform_data))))
598 goto unreg_dr;
599 }
600 if (usb_dev_dr_client) {
601 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
602 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
603 dev.coherent_dma_mask;
604 if ((ret = platform_device_add_data(usb_dev_dr_client,
605 &usb_data, sizeof(struct
606 fsl_usb2_platform_data))))
607 goto unreg_dr;
608 }
Li Yang866b6dd2008-01-08 15:18:46 +0800609 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600610 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600611 return 0;
612
Kumar Gala01cced22006-04-11 10:07:16 -0500613unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800614 if (usb_dev_dr_host)
615 platform_device_unregister(usb_dev_dr_host);
616 if (usb_dev_dr_client)
617 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500618unreg_mph:
619 if (usb_dev_mph)
620 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600621err:
622 return ret;
623}
624
Kumar Gala01cced22006-04-11 10:07:16 -0500625arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400626
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300627static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
628 struct spi_board_info *board_infos,
629 unsigned int num_board_infos,
630 void (*activate_cs)(u8 cs, u8 polarity),
631 void (*deactivate_cs)(u8 cs, u8 polarity))
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400632{
633 struct device_node *np;
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300634 unsigned int i = 0;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400635
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300636 for_each_compatible_node(np, type, compatible) {
637 int ret;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400638 unsigned int j;
639 const void *prop;
640 struct resource res[2];
641 struct platform_device *pdev;
642 struct fsl_spi_platform_data pdata = {
643 .activate_cs = activate_cs,
644 .deactivate_cs = deactivate_cs,
645 };
646
647 memset(res, 0, sizeof(res));
648
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300649 pdata.sysclk = sysclk;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400650
651 prop = of_get_property(np, "reg", NULL);
652 if (!prop)
653 goto err;
654 pdata.bus_num = *(u32 *)prop;
655
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300656 prop = of_get_property(np, "cell-index", NULL);
657 if (prop)
658 i = *(u32 *)prop;
659
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400660 prop = of_get_property(np, "mode", NULL);
661 if (prop && !strcmp(prop, "cpu-qe"))
662 pdata.qe_mode = 1;
663
664 for (j = 0; j < num_board_infos; j++) {
665 if (board_infos[j].bus_num == pdata.bus_num)
666 pdata.max_chipselect++;
667 }
668
669 if (!pdata.max_chipselect)
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300670 continue;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400671
672 ret = of_address_to_resource(np, 0, &res[0]);
673 if (ret)
674 goto err;
675
676 ret = of_irq_to_resource(np, 0, &res[1]);
677 if (ret == NO_IRQ)
678 goto err;
679
680 pdev = platform_device_alloc("mpc83xx_spi", i);
681 if (!pdev)
682 goto err;
683
684 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
685 if (ret)
686 goto unreg;
687
688 ret = platform_device_add_resources(pdev, res,
689 ARRAY_SIZE(res));
690 if (ret)
691 goto unreg;
692
Kim Phillipsdc4e4202008-02-01 18:09:58 -0600693 ret = platform_device_add(pdev);
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400694 if (ret)
695 goto unreg;
696
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300697 goto next;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400698unreg:
699 platform_device_del(pdev);
700err:
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300701 pr_err("%s: registration failed\n", np->full_name);
702next:
703 i++;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400704 }
705
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300706 return i;
707}
708
709int __init fsl_spi_init(struct spi_board_info *board_infos,
710 unsigned int num_board_infos,
711 void (*activate_cs)(u8 cs, u8 polarity),
712 void (*deactivate_cs)(u8 cs, u8 polarity))
713{
714 u32 sysclk = -1;
715 int ret;
716
717#ifdef CONFIG_QUICC_ENGINE
718 /* SPI controller is either clocked from QE or SoC clock */
719 sysclk = get_brgfreq();
720#endif
721 if (sysclk == -1) {
Scott Wood38664092008-04-15 13:52:34 -0500722 sysclk = fsl_get_sys_freq();
723 if (sysclk == -1)
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300724 return -ENODEV;
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300725 }
726
727 ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
728 num_board_infos, activate_cs, deactivate_cs);
729 if (!ret)
730 of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
731 num_board_infos, activate_cs, deactivate_cs);
732
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400733 return spi_register_board_info(board_infos, num_board_infos);
734}
Kumar Galae1c15752007-10-04 01:04:57 -0500735
736#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
737static __be32 __iomem *rstcr;
738
739static int __init setup_rstcr(void)
740{
741 struct device_node *np;
742 np = of_find_node_by_name(NULL, "global-utilities");
743 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
744 const u32 *prop = of_get_property(np, "reg", NULL);
745 if (prop) {
746 /* map reset control register
747 * 0xE00B0 is offset of reset control register
748 */
749 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
750 if (!rstcr)
751 printk (KERN_EMERG "Error: reset control "
752 "register not mapped!\n");
753 }
754 } else
755 printk (KERN_INFO "rstcr compatible register does not exist!\n");
756 if (np)
757 of_node_put(np);
758 return 0;
759}
760
761arch_initcall(setup_rstcr);
762
763void fsl_rstcr_restart(char *cmd)
764{
765 local_irq_disable();
766 if (rstcr)
767 /* set reset control register */
768 out_be32(rstcr, 0x2); /* HRESET_REQ */
769
770 while (1) ;
771}
772#endif
York Sun6f90a8bd2008-04-28 02:15:36 -0700773
774#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
775struct platform_diu_data_ops diu_ops = {
776 .diu_size = 1280 * 1024 * 4, /* default one 1280x1024 buffer */
777};
778EXPORT_SYMBOL(diu_ops);
779
780int __init preallocate_diu_videomemory(void)
781{
782 pr_debug("diu_size=%lu\n", diu_ops.diu_size);
783
784 diu_ops.diu_mem = __alloc_bootmem(diu_ops.diu_size, 8, 0);
785 if (!diu_ops.diu_mem) {
786 printk(KERN_ERR "fsl-diu: cannot allocate %lu bytes\n",
787 diu_ops.diu_size);
788 return -ENOMEM;
789 }
790
791 pr_debug("diu_mem=%p\n", diu_ops.diu_mem);
792
793 rh_init(&diu_ops.diu_rh_info, 4096, ARRAY_SIZE(diu_ops.diu_rh_block),
794 diu_ops.diu_rh_block);
795 return rh_attach_region(&diu_ops.diu_rh_info,
796 (unsigned long) diu_ops.diu_mem,
797 diu_ops.diu_size);
798}
799
800static int __init early_parse_diufb(char *p)
801{
802 if (!p)
803 return 1;
804
805 diu_ops.diu_size = _ALIGN_UP(memparse(p, &p), 8);
806
807 pr_debug("diu_size=%lu\n", diu_ops.diu_size);
808
809 return 0;
810}
811early_param("diufb", early_parse_diufb);
812
813#endif