blob: b6d6bdae95f25ffdd1019ad9b844760b5f054959 [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
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)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600304 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600305
Andy Fleminga9b14972006-10-19 19:52:26 -0500306 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600307
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000308 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600309
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;
Andy Fleminga9b14972006-10-19 19:52:26 -0500315 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600316
317 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500318 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500319
320 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600321 }
322
Kumar Gala2fb07d72006-01-23 16:58:04 -0600323 gfar_dev =
324 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400325 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600326
327 if (IS_ERR(gfar_dev)) {
328 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600329 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600330 }
331
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600332 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500333 if (mac_addr)
334 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600335
336 if (model && !strcasecmp(model, "TSEC"))
337 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600338 FSL_GIANFAR_DEV_HAS_GIGABIT |
339 FSL_GIANFAR_DEV_HAS_COALESCE |
340 FSL_GIANFAR_DEV_HAS_RMON |
341 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600342 if (model && !strcasecmp(model, "eTSEC"))
343 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600344 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;
Kumar Galaeed32002006-01-13 11:19:13 -0600351
Andy Fleming7132ab72007-07-11 11:43:07 -0500352 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
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000360 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300361 if (ph == NULL) {
362 u32 *fixed_link;
Kumar Galaeed32002006-01-13 11:19:13 -0600363
Vitaly Borduga21e2822007-12-07 01:51:31 +0300364 fixed_link = (u32 *)of_get_property(np, "fixed-link",
365 NULL);
366 if (!fixed_link) {
367 ret = -ENODEV;
368 goto unreg;
369 }
Kumar Galaeed32002006-01-13 11:19:13 -0600370
Vitaly Borduga21e2822007-12-07 01:51:31 +0300371 gfar_data.bus_id = 0;
372 gfar_data.phy_id = fixed_link[0];
373 } else {
374 phy = of_find_node_by_phandle(*ph);
Kumar Galaeed32002006-01-13 11:19:13 -0600375
Vitaly Borduga21e2822007-12-07 01:51:31 +0300376 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;
392 gfar_data.bus_id = res.start;
393
Kumar Galaeed32002006-01-13 11:19:13 -0600394 of_node_put(phy);
395 of_node_put(mdio);
Kumar Galaeed32002006-01-13 11:19:13 -0600396 }
397
Kumar Gala2fb07d72006-01-23 16:58:04 -0600398 ret =
399 platform_device_add_data(gfar_dev, &gfar_data,
400 sizeof(struct
401 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600402 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600403 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600404 }
405
406 return 0;
407
Kumar Gala2fb07d72006-01-23 16:58:04 -0600408unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600409 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600410err:
Kumar Galaeed32002006-01-13 11:19:13 -0600411 return ret;
412}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600413
Kumar Galaeed32002006-01-13 11:19:13 -0600414arch_initcall(gfar_of_init);
415
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000416#ifdef CONFIG_I2C_BOARDINFO
417#include <linux/i2c.h>
418struct i2c_driver_device {
419 char *of_device;
420 char *i2c_driver;
421 char *i2c_type;
422};
423
424static struct i2c_driver_device i2c_devices[] __initdata = {
425 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
426 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
427 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
428 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
Peter Korsgaard0438c282007-09-20 12:42:13 +0200429 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
430 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
431 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
432 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
433 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
434 {"stm,m41t00", "rtc-ds1307", "m41t00"},
Anton Vorontsovc0e4eb22007-10-02 17:47:43 +0400435 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000436};
437
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000438static int __init of_find_i2c_driver(struct device_node *node,
439 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000440{
441 int i;
442
443 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
444 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
445 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000446 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
447 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
448 strlcpy(info->type, i2c_devices[i].i2c_type,
449 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
450 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000451 return 0;
452 }
453 return -ENODEV;
454}
455
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000456static void __init of_register_i2c_devices(struct device_node *adap_node,
457 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000458{
459 struct device_node *node = NULL;
460
461 while ((node = of_get_next_child(adap_node, node))) {
Anton Vorontsovda1bb3a2007-10-02 17:47:40 +0400462 struct i2c_board_info info = {};
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000463 const u32 *addr;
464 int len;
465
466 addr = of_get_property(node, "reg", &len);
467 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
Peter Korsgaard210805e2007-09-20 12:42:12 +0200468 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000469 continue;
470 }
471
472 info.irq = irq_of_parse_and_map(node, 0);
473 if (info.irq == NO_IRQ)
474 info.irq = -1;
475
476 if (of_find_i2c_driver(node, &info) < 0)
477 continue;
478
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000479 info.addr = *addr;
480
481 i2c_register_board_info(bus_num, &info, 1);
482 }
483}
484
Kumar Galaeed32002006-01-13 11:19:13 -0600485static int __init fsl_i2c_of_init(void)
486{
487 struct device_node *np;
Kumar Galaec9686c2007-12-11 23:17:24 -0600488 unsigned int i = 0;
Kumar Galaeed32002006-01-13 11:19:13 -0600489 struct platform_device *i2c_dev;
490 int ret;
491
Kumar Galaec9686c2007-12-11 23:17:24 -0600492 for_each_compatible_node(np, NULL, "fsl-i2c") {
Kumar Galaeed32002006-01-13 11:19:13 -0600493 struct resource r[2];
494 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000495 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600496
497 memset(&r, 0, sizeof(r));
498 memset(&i2c_data, 0, sizeof(i2c_data));
499
500 ret = of_address_to_resource(np, 0, &r[0]);
501 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600502 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600503
Andy Fleminga9b14972006-10-19 19:52:26 -0500504 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600505
506 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
507 if (IS_ERR(i2c_dev)) {
508 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600509 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600510 }
511
512 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000513 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600514 if (flags)
515 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
516
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000517 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600518 if (flags)
519 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
520
Kumar Gala2fb07d72006-01-23 16:58:04 -0600521 ret =
522 platform_device_add_data(i2c_dev, &i2c_data,
523 sizeof(struct
524 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600525 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600526 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000527
Kumar Galaec9686c2007-12-11 23:17:24 -0600528 of_register_i2c_devices(np, i++);
Kumar Galaeed32002006-01-13 11:19:13 -0600529 }
530
531 return 0;
532
Kumar Gala2fb07d72006-01-23 16:58:04 -0600533unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600534 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600535err:
Kumar Galaeed32002006-01-13 11:19:13 -0600536 return ret;
537}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600538
Kumar Galaeed32002006-01-13 11:19:13 -0600539arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000540#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600541
542#ifdef CONFIG_PPC_83xx
543static int __init mpc83xx_wdt_init(void)
544{
545 struct resource r;
Scott Wood38664092008-04-15 13:52:34 -0500546 struct device_node *np;
Kumar Galaeed32002006-01-13 11:19:13 -0600547 struct platform_device *dev;
Scott Wood38664092008-04-15 13:52:34 -0500548 u32 freq = fsl_get_sys_freq();
Kumar Galaeed32002006-01-13 11:19:13 -0600549 int ret;
550
551 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
552
553 if (!np) {
554 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600555 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600556 }
557
Kumar Galaeed32002006-01-13 11:19:13 -0600558 memset(&r, 0, sizeof(r));
559
560 ret = of_address_to_resource(np, 0, &r);
561 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600562 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600563
564 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
565 if (IS_ERR(dev)) {
566 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600567 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600568 }
569
Scott Wood38664092008-04-15 13:52:34 -0500570 ret = platform_device_add_data(dev, &freq, sizeof(freq));
Kumar Galaeed32002006-01-13 11:19:13 -0600571 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600572 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600573
Kumar Galaeed32002006-01-13 11:19:13 -0600574 of_node_put(np);
Kumar Galaeed32002006-01-13 11:19:13 -0600575 return 0;
576
Kumar Gala2fb07d72006-01-23 16:58:04 -0600577unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600578 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600579err:
Kumar Galaeed32002006-01-13 11:19:13 -0600580 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600581nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600582 return ret;
583}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600584
Kumar Galaeed32002006-01-13 11:19:13 -0600585arch_initcall(mpc83xx_wdt_init);
586#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600587
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000588static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600589{
590 if (!phy_type)
591 return FSL_USB2_PHY_NONE;
592 if (!strcasecmp(phy_type, "ulpi"))
593 return FSL_USB2_PHY_ULPI;
594 if (!strcasecmp(phy_type, "utmi"))
595 return FSL_USB2_PHY_UTMI;
596 if (!strcasecmp(phy_type, "utmi_wide"))
597 return FSL_USB2_PHY_UTMI_WIDE;
598 if (!strcasecmp(phy_type, "serial"))
599 return FSL_USB2_PHY_SERIAL;
600
601 return FSL_USB2_PHY_NONE;
602}
603
604static int __init fsl_usb_of_init(void)
605{
606 struct device_node *np;
Li Yang866b6dd2008-01-08 15:18:46 +0800607 unsigned int i = 0;
Li Yang97c5a202007-02-07 13:49:24 +0800608 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
609 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600610 int ret;
611
Li Yang866b6dd2008-01-08 15:18:46 +0800612 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600613 struct resource r[2];
614 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000615 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600616
617 memset(&r, 0, sizeof(r));
618 memset(&usb_data, 0, sizeof(usb_data));
619
620 ret = of_address_to_resource(np, 0, &r[0]);
621 if (ret)
622 goto err;
623
Andy Fleminga9b14972006-10-19 19:52:26 -0500624 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600625
Kumar Gala01cced22006-04-11 10:07:16 -0500626 usb_dev_mph =
627 platform_device_register_simple("fsl-ehci", i, r, 2);
628 if (IS_ERR(usb_dev_mph)) {
629 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600630 goto err;
631 }
632
Kumar Gala01cced22006-04-11 10:07:16 -0500633 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
634 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600635
636 usb_data.operating_mode = FSL_USB2_MPH_HOST;
637
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000638 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600639 if (prop)
640 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
641
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000642 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600643 if (prop)
644 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
645
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000646 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600647 usb_data.phy_mode = determine_usb_phy(prop);
648
649 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500650 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600651 sizeof(struct
652 fsl_usb2_platform_data));
653 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500654 goto unreg_mph;
Li Yang866b6dd2008-01-08 15:18:46 +0800655 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600656 }
657
Li Yang866b6dd2008-01-08 15:18:46 +0800658 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600659 struct resource r[2];
660 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000661 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600662
663 memset(&r, 0, sizeof(r));
664 memset(&usb_data, 0, sizeof(usb_data));
665
666 ret = of_address_to_resource(np, 0, &r[0]);
667 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500668 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600669
Andy Fleminga9b14972006-10-19 19:52:26 -0500670 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600671
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000672 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800673
674 if (!prop || !strcmp(prop, "host")) {
675 usb_data.operating_mode = FSL_USB2_DR_HOST;
676 usb_dev_dr_host = platform_device_register_simple(
677 "fsl-ehci", i, r, 2);
678 if (IS_ERR(usb_dev_dr_host)) {
679 ret = PTR_ERR(usb_dev_dr_host);
680 goto err;
681 }
682 } else if (prop && !strcmp(prop, "peripheral")) {
683 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
684 usb_dev_dr_client = platform_device_register_simple(
685 "fsl-usb2-udc", i, r, 2);
686 if (IS_ERR(usb_dev_dr_client)) {
687 ret = PTR_ERR(usb_dev_dr_client);
688 goto err;
689 }
690 } else if (prop && !strcmp(prop, "otg")) {
691 usb_data.operating_mode = FSL_USB2_DR_OTG;
692 usb_dev_dr_host = platform_device_register_simple(
693 "fsl-ehci", i, r, 2);
694 if (IS_ERR(usb_dev_dr_host)) {
695 ret = PTR_ERR(usb_dev_dr_host);
696 goto err;
697 }
698 usb_dev_dr_client = platform_device_register_simple(
699 "fsl-usb2-udc", i, r, 2);
700 if (IS_ERR(usb_dev_dr_client)) {
701 ret = PTR_ERR(usb_dev_dr_client);
702 goto err;
703 }
704 } else {
705 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600706 goto err;
707 }
708
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000709 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600710 usb_data.phy_mode = determine_usb_phy(prop);
711
Li Yang97c5a202007-02-07 13:49:24 +0800712 if (usb_dev_dr_host) {
713 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
714 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
715 dev.coherent_dma_mask;
716 if ((ret = platform_device_add_data(usb_dev_dr_host,
717 &usb_data, sizeof(struct
718 fsl_usb2_platform_data))))
719 goto unreg_dr;
720 }
721 if (usb_dev_dr_client) {
722 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
723 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
724 dev.coherent_dma_mask;
725 if ((ret = platform_device_add_data(usb_dev_dr_client,
726 &usb_data, sizeof(struct
727 fsl_usb2_platform_data))))
728 goto unreg_dr;
729 }
Li Yang866b6dd2008-01-08 15:18:46 +0800730 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600731 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600732 return 0;
733
Kumar Gala01cced22006-04-11 10:07:16 -0500734unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800735 if (usb_dev_dr_host)
736 platform_device_unregister(usb_dev_dr_host);
737 if (usb_dev_dr_client)
738 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500739unreg_mph:
740 if (usb_dev_mph)
741 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600742err:
743 return ret;
744}
745
Kumar Gala01cced22006-04-11 10:07:16 -0500746arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400747
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300748static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
749 struct spi_board_info *board_infos,
750 unsigned int num_board_infos,
751 void (*activate_cs)(u8 cs, u8 polarity),
752 void (*deactivate_cs)(u8 cs, u8 polarity))
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400753{
754 struct device_node *np;
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300755 unsigned int i = 0;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400756
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300757 for_each_compatible_node(np, type, compatible) {
758 int ret;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400759 unsigned int j;
760 const void *prop;
761 struct resource res[2];
762 struct platform_device *pdev;
763 struct fsl_spi_platform_data pdata = {
764 .activate_cs = activate_cs,
765 .deactivate_cs = deactivate_cs,
766 };
767
768 memset(res, 0, sizeof(res));
769
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300770 pdata.sysclk = sysclk;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400771
772 prop = of_get_property(np, "reg", NULL);
773 if (!prop)
774 goto err;
775 pdata.bus_num = *(u32 *)prop;
776
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300777 prop = of_get_property(np, "cell-index", NULL);
778 if (prop)
779 i = *(u32 *)prop;
780
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400781 prop = of_get_property(np, "mode", NULL);
782 if (prop && !strcmp(prop, "cpu-qe"))
783 pdata.qe_mode = 1;
784
785 for (j = 0; j < num_board_infos; j++) {
786 if (board_infos[j].bus_num == pdata.bus_num)
787 pdata.max_chipselect++;
788 }
789
790 if (!pdata.max_chipselect)
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300791 continue;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400792
793 ret = of_address_to_resource(np, 0, &res[0]);
794 if (ret)
795 goto err;
796
797 ret = of_irq_to_resource(np, 0, &res[1]);
798 if (ret == NO_IRQ)
799 goto err;
800
801 pdev = platform_device_alloc("mpc83xx_spi", i);
802 if (!pdev)
803 goto err;
804
805 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
806 if (ret)
807 goto unreg;
808
809 ret = platform_device_add_resources(pdev, res,
810 ARRAY_SIZE(res));
811 if (ret)
812 goto unreg;
813
Kim Phillipsdc4e4202008-02-01 18:09:58 -0600814 ret = platform_device_add(pdev);
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400815 if (ret)
816 goto unreg;
817
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300818 goto next;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400819unreg:
820 platform_device_del(pdev);
821err:
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300822 pr_err("%s: registration failed\n", np->full_name);
823next:
824 i++;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400825 }
826
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300827 return i;
828}
829
830int __init fsl_spi_init(struct spi_board_info *board_infos,
831 unsigned int num_board_infos,
832 void (*activate_cs)(u8 cs, u8 polarity),
833 void (*deactivate_cs)(u8 cs, u8 polarity))
834{
835 u32 sysclk = -1;
836 int ret;
837
838#ifdef CONFIG_QUICC_ENGINE
839 /* SPI controller is either clocked from QE or SoC clock */
840 sysclk = get_brgfreq();
841#endif
842 if (sysclk == -1) {
Scott Wood38664092008-04-15 13:52:34 -0500843 sysclk = fsl_get_sys_freq();
844 if (sysclk == -1)
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300845 return -ENODEV;
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300846 }
847
848 ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
849 num_board_infos, activate_cs, deactivate_cs);
850 if (!ret)
851 of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
852 num_board_infos, activate_cs, deactivate_cs);
853
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400854 return spi_register_board_info(board_infos, num_board_infos);
855}
Kumar Galae1c15752007-10-04 01:04:57 -0500856
857#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
858static __be32 __iomem *rstcr;
859
860static int __init setup_rstcr(void)
861{
862 struct device_node *np;
863 np = of_find_node_by_name(NULL, "global-utilities");
864 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
865 const u32 *prop = of_get_property(np, "reg", NULL);
866 if (prop) {
867 /* map reset control register
868 * 0xE00B0 is offset of reset control register
869 */
870 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
871 if (!rstcr)
872 printk (KERN_EMERG "Error: reset control "
873 "register not mapped!\n");
874 }
875 } else
876 printk (KERN_INFO "rstcr compatible register does not exist!\n");
877 if (np)
878 of_node_put(np);
879 return 0;
880}
881
882arch_initcall(setup_rstcr);
883
884void fsl_rstcr_restart(char *cmd)
885{
886 local_irq_disable();
887 if (rstcr)
888 /* set reset control register */
889 out_be32(rstcr, 0x2); /* HRESET_REQ */
890
891 while (1) ;
892}
893#endif