blob: 3581416905eaca520485af0cdd13e5b8b7c6935d [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
Anton Vorontsov59a0ea52008-01-24 18:40:03 +030078#if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
Vitaly Bordugfba43662006-09-21 17:26:34 +040079
80static u32 brgfreq = -1;
81
82u32 get_brgfreq(void)
83{
84 struct device_node *node;
Scott Wood6d817aa2007-08-29 15:08:40 -050085 const unsigned int *prop;
86 int size;
Vitaly Bordugfba43662006-09-21 17:26:34 +040087
88 if (brgfreq != -1)
89 return brgfreq;
90
Scott Wood6d817aa2007-08-29 15:08:40 -050091 node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
Vitaly Bordugfba43662006-09-21 17:26:34 +040092 if (node) {
Scott Wood6d817aa2007-08-29 15:08:40 -050093 prop = of_get_property(node, "clock-frequency", &size);
94 if (prop && size == 4)
95 brgfreq = *prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +040096
Scott Wood6d817aa2007-08-29 15:08:40 -050097 of_node_put(node);
98 return brgfreq;
99 }
100
101 /* Legacy device binding -- will go away when no users are left. */
102 node = of_find_node_by_type(NULL, "cpm");
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300103 if (!node)
104 node = of_find_compatible_node(NULL, NULL, "fsl,qe");
105 if (!node)
106 node = of_find_node_by_type(NULL, "qe");
107
Scott Wood6d817aa2007-08-29 15:08:40 -0500108 if (node) {
109 prop = of_get_property(node, "brg-frequency", &size);
Scott Woodf9234732007-08-20 11:38:12 -0500110 if (prop && size == 4)
Vitaly Bordugfba43662006-09-21 17:26:34 +0400111 brgfreq = *prop;
Scott Woodf9234732007-08-20 11:38:12 -0500112
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300113 if (brgfreq == -1 || brgfreq == 0) {
114 prop = of_get_property(node, "bus-frequency", &size);
115 if (prop && size == 4)
116 brgfreq = *prop / 2;
117 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400118 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500119 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400120
121 return brgfreq;
122}
123
124EXPORT_SYMBOL(get_brgfreq);
125
126static u32 fs_baudrate = -1;
127
128u32 get_baudrate(void)
129{
130 struct device_node *node;
131
132 if (fs_baudrate != -1)
133 return fs_baudrate;
134
135 node = of_find_node_by_type(NULL, "serial");
136 if (node) {
Scott Woodf9234732007-08-20 11:38:12 -0500137 int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000138 const unsigned int *prop = of_get_property(node,
139 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400140
141 if (prop)
142 fs_baudrate = *prop;
143 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500144 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400145
146 return fs_baudrate;
147}
148
149EXPORT_SYMBOL(get_baudrate);
150#endif /* CONFIG_CPM2 */
151
Vitaly Borduga21e2822007-12-07 01:51:31 +0300152#ifdef CONFIG_FIXED_PHY
153static int __init of_add_fixed_phys(void)
154{
155 int ret;
156 struct device_node *np;
157 u32 *fixed_link;
158 struct fixed_phy_status status = {};
159
160 for_each_node_by_name(np, "ethernet") {
161 fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
162 if (!fixed_link)
163 continue;
164
165 status.link = 1;
166 status.duplex = fixed_link[1];
167 status.speed = fixed_link[2];
168 status.pause = fixed_link[3];
169 status.asym_pause = fixed_link[4];
170
171 ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
172 if (ret) {
173 of_node_put(np);
174 return ret;
175 }
176 }
177
178 return 0;
179}
180arch_initcall(of_add_fixed_phys);
181#endif /* CONFIG_FIXED_PHY */
182
Kumar Gala2fb07d72006-01-23 16:58:04 -0600183static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600184{
Kumar Galae77b28e2007-12-12 00:28:35 -0600185 struct device_node *np = NULL;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600186 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600187 struct resource res;
188 int ret;
189
Kumar Galae77b28e2007-12-12 00:28:35 -0600190 np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
191
192 /* try the deprecated version */
193 if (!np)
194 np = of_find_compatible_node(np, "mdio", "gianfar");
195
196 if (np) {
Kumar Galaeed32002006-01-13 11:19:13 -0600197 int k;
198 struct device_node *child = NULL;
199 struct gianfar_mdio_data mdio_data;
200
201 memset(&res, 0, sizeof(res));
202 memset(&mdio_data, 0, sizeof(mdio_data));
203
204 ret = of_address_to_resource(np, 0, &res);
205 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600206 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600207
Kumar Gala2fb07d72006-01-23 16:58:04 -0600208 mdio_dev =
209 platform_device_register_simple("fsl-gianfar_mdio",
210 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600211 if (IS_ERR(mdio_dev)) {
212 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600213 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600214 }
215
216 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500217 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600218
219 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400220 int irq = irq_of_parse_and_map(child, 0);
221 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000222 const u32 *id = of_get_property(child,
223 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400224 mdio_data.irq[*id] = irq;
225 }
Kumar Galaeed32002006-01-13 11:19:13 -0600226 }
227
Kumar Gala2fb07d72006-01-23 16:58:04 -0600228 ret =
229 platform_device_add_data(mdio_dev, &mdio_data,
230 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600231 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600232 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600233 }
234
Kumar Galae77b28e2007-12-12 00:28:35 -0600235 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600236 return 0;
237
238unreg:
239 platform_device_unregister(mdio_dev);
240err:
Kumar Galae77b28e2007-12-12 00:28:35 -0600241 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600242 return ret;
243}
244
245arch_initcall(gfar_mdio_of_init);
246
247static const char *gfar_tx_intr = "tx";
248static const char *gfar_rx_intr = "rx";
249static const char *gfar_err_intr = "error";
250
251static int __init gfar_of_init(void)
252{
253 struct device_node *np;
254 unsigned int i;
255 struct platform_device *gfar_dev;
256 struct resource res;
257 int ret;
258
259 for (np = NULL, i = 0;
260 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
261 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600262 struct resource r[4];
263 struct device_node *phy, *mdio;
264 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000265 const unsigned int *id;
266 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500267 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000268 const void *mac_addr;
269 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400270 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600271
272 memset(r, 0, sizeof(r));
273 memset(&gfar_data, 0, sizeof(gfar_data));
274
275 ret = of_address_to_resource(np, 0, &r[0]);
276 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600277 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600278
Andy Fleminga9b14972006-10-19 19:52:26 -0500279 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600280
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000281 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600282
283 /* If we aren't the FEC we have multiple interrupts */
284 if (model && strcasecmp(model, "FEC")) {
285 r[1].name = gfar_tx_intr;
286
287 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500288 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600289
290 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500291 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500292
293 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600294 }
295
Kumar Gala2fb07d72006-01-23 16:58:04 -0600296 gfar_dev =
297 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400298 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600299
300 if (IS_ERR(gfar_dev)) {
301 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600302 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600303 }
304
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600305 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500306 if (mac_addr)
307 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600308
309 if (model && !strcasecmp(model, "TSEC"))
310 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600311 FSL_GIANFAR_DEV_HAS_GIGABIT |
312 FSL_GIANFAR_DEV_HAS_COALESCE |
313 FSL_GIANFAR_DEV_HAS_RMON |
314 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600315 if (model && !strcasecmp(model, "eTSEC"))
316 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600317 FSL_GIANFAR_DEV_HAS_GIGABIT |
318 FSL_GIANFAR_DEV_HAS_COALESCE |
319 FSL_GIANFAR_DEV_HAS_RMON |
320 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
321 FSL_GIANFAR_DEV_HAS_CSUM |
322 FSL_GIANFAR_DEV_HAS_VLAN |
323 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600324
Andy Fleming7132ab72007-07-11 11:43:07 -0500325 ctype = of_get_property(np, "phy-connection-type", NULL);
326
327 /* We only care about rgmii-id. The rest are autodetected */
328 if (ctype && !strcmp(ctype, "rgmii-id"))
329 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
330 else
331 gfar_data.interface = PHY_INTERFACE_MODE_MII;
332
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000333 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300334 if (ph == NULL) {
335 u32 *fixed_link;
Kumar Galaeed32002006-01-13 11:19:13 -0600336
Vitaly Borduga21e2822007-12-07 01:51:31 +0300337 fixed_link = (u32 *)of_get_property(np, "fixed-link",
338 NULL);
339 if (!fixed_link) {
340 ret = -ENODEV;
341 goto unreg;
342 }
Kumar Galaeed32002006-01-13 11:19:13 -0600343
Andy Fleming9d9326d2008-04-09 19:38:13 -0500344 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
Vitaly Borduga21e2822007-12-07 01:51:31 +0300345 gfar_data.phy_id = fixed_link[0];
346 } else {
347 phy = of_find_node_by_phandle(*ph);
Kumar Galaeed32002006-01-13 11:19:13 -0600348
Vitaly Borduga21e2822007-12-07 01:51:31 +0300349 if (phy == NULL) {
350 ret = -ENODEV;
351 goto unreg;
352 }
353
354 mdio = of_get_parent(phy);
355
356 id = of_get_property(phy, "reg", NULL);
357 ret = of_address_to_resource(mdio, 0, &res);
358 if (ret) {
359 of_node_put(phy);
360 of_node_put(mdio);
361 goto unreg;
362 }
363
364 gfar_data.phy_id = *id;
Andy Fleming9d9326d2008-04-09 19:38:13 -0500365 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%x",
366 res.start);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300367
Kumar Galaeed32002006-01-13 11:19:13 -0600368 of_node_put(phy);
369 of_node_put(mdio);
Kumar Galaeed32002006-01-13 11:19:13 -0600370 }
371
Kumar Gala2fb07d72006-01-23 16:58:04 -0600372 ret =
373 platform_device_add_data(gfar_dev, &gfar_data,
374 sizeof(struct
375 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600376 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600377 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600378 }
379
380 return 0;
381
Kumar Gala2fb07d72006-01-23 16:58:04 -0600382unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600383 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600384err:
Kumar Galaeed32002006-01-13 11:19:13 -0600385 return ret;
386}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600387
Kumar Galaeed32002006-01-13 11:19:13 -0600388arch_initcall(gfar_of_init);
389
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000390#ifdef CONFIG_I2C_BOARDINFO
391#include <linux/i2c.h>
392struct i2c_driver_device {
393 char *of_device;
394 char *i2c_driver;
395 char *i2c_type;
396};
397
398static struct i2c_driver_device i2c_devices[] __initdata = {
399 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
400 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
401 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
402 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
Peter Korsgaard0438c282007-09-20 12:42:13 +0200403 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
404 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
405 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
406 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
407 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
408 {"stm,m41t00", "rtc-ds1307", "m41t00"},
Anton Vorontsovc0e4eb22007-10-02 17:47:43 +0400409 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000410};
411
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000412static int __init of_find_i2c_driver(struct device_node *node,
413 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000414{
415 int i;
416
417 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
418 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
419 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000420 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
421 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
422 strlcpy(info->type, i2c_devices[i].i2c_type,
423 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
424 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000425 return 0;
426 }
427 return -ENODEV;
428}
429
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000430static void __init of_register_i2c_devices(struct device_node *adap_node,
431 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000432{
433 struct device_node *node = NULL;
434
435 while ((node = of_get_next_child(adap_node, node))) {
Anton Vorontsovda1bb3a2007-10-02 17:47:40 +0400436 struct i2c_board_info info = {};
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000437 const u32 *addr;
438 int len;
439
440 addr = of_get_property(node, "reg", &len);
441 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
Peter Korsgaard210805e2007-09-20 12:42:12 +0200442 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000443 continue;
444 }
445
446 info.irq = irq_of_parse_and_map(node, 0);
447 if (info.irq == NO_IRQ)
448 info.irq = -1;
449
450 if (of_find_i2c_driver(node, &info) < 0)
451 continue;
452
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000453 info.addr = *addr;
454
455 i2c_register_board_info(bus_num, &info, 1);
456 }
457}
458
Kumar Galaeed32002006-01-13 11:19:13 -0600459static int __init fsl_i2c_of_init(void)
460{
461 struct device_node *np;
Kumar Galaec9686c2007-12-11 23:17:24 -0600462 unsigned int i = 0;
Kumar Galaeed32002006-01-13 11:19:13 -0600463 struct platform_device *i2c_dev;
464 int ret;
465
Kumar Galaec9686c2007-12-11 23:17:24 -0600466 for_each_compatible_node(np, NULL, "fsl-i2c") {
Kumar Galaeed32002006-01-13 11:19:13 -0600467 struct resource r[2];
468 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000469 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600470
471 memset(&r, 0, sizeof(r));
472 memset(&i2c_data, 0, sizeof(i2c_data));
473
474 ret = of_address_to_resource(np, 0, &r[0]);
475 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600476 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600477
Andy Fleminga9b14972006-10-19 19:52:26 -0500478 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600479
480 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
481 if (IS_ERR(i2c_dev)) {
482 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600483 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600484 }
485
486 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000487 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600488 if (flags)
489 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
490
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000491 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600492 if (flags)
493 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
494
Kumar Gala2fb07d72006-01-23 16:58:04 -0600495 ret =
496 platform_device_add_data(i2c_dev, &i2c_data,
497 sizeof(struct
498 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600499 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600500 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000501
Kumar Galaec9686c2007-12-11 23:17:24 -0600502 of_register_i2c_devices(np, i++);
Kumar Galaeed32002006-01-13 11:19:13 -0600503 }
504
505 return 0;
506
Kumar Gala2fb07d72006-01-23 16:58:04 -0600507unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600508 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600509err:
Kumar Galaeed32002006-01-13 11:19:13 -0600510 return ret;
511}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600512
Kumar Galaeed32002006-01-13 11:19:13 -0600513arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000514#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600515
516#ifdef CONFIG_PPC_83xx
517static int __init mpc83xx_wdt_init(void)
518{
519 struct resource r;
520 struct device_node *soc, *np;
521 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000522 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600523 int ret;
524
525 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
526
527 if (!np) {
528 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600529 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600530 }
531
532 soc = of_find_node_by_type(NULL, "soc");
533
534 if (!soc) {
535 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600536 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600537 }
538
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000539 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600540 if (!freq) {
541 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600542 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600543 }
544
545 memset(&r, 0, sizeof(r));
546
547 ret = of_address_to_resource(np, 0, &r);
548 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600549 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600550
551 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
552 if (IS_ERR(dev)) {
553 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600554 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600555 }
556
557 ret = platform_device_add_data(dev, freq, sizeof(int));
558 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600559 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600560
561 of_node_put(soc);
562 of_node_put(np);
563
564 return 0;
565
Kumar Gala2fb07d72006-01-23 16:58:04 -0600566unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600567 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600568err:
Kumar Galaeed32002006-01-13 11:19:13 -0600569 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600570nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600571 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600572nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600573 return ret;
574}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600575
Kumar Galaeed32002006-01-13 11:19:13 -0600576arch_initcall(mpc83xx_wdt_init);
577#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600578
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000579static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600580{
581 if (!phy_type)
582 return FSL_USB2_PHY_NONE;
583 if (!strcasecmp(phy_type, "ulpi"))
584 return FSL_USB2_PHY_ULPI;
585 if (!strcasecmp(phy_type, "utmi"))
586 return FSL_USB2_PHY_UTMI;
587 if (!strcasecmp(phy_type, "utmi_wide"))
588 return FSL_USB2_PHY_UTMI_WIDE;
589 if (!strcasecmp(phy_type, "serial"))
590 return FSL_USB2_PHY_SERIAL;
591
592 return FSL_USB2_PHY_NONE;
593}
594
595static int __init fsl_usb_of_init(void)
596{
597 struct device_node *np;
Li Yang866b6dd2008-01-08 15:18:46 +0800598 unsigned int i = 0;
Li Yang97c5a202007-02-07 13:49:24 +0800599 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
600 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600601 int ret;
602
Li Yang866b6dd2008-01-08 15:18:46 +0800603 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600604 struct resource r[2];
605 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000606 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600607
608 memset(&r, 0, sizeof(r));
609 memset(&usb_data, 0, sizeof(usb_data));
610
611 ret = of_address_to_resource(np, 0, &r[0]);
612 if (ret)
613 goto err;
614
Andy Fleminga9b14972006-10-19 19:52:26 -0500615 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600616
Kumar Gala01cced22006-04-11 10:07:16 -0500617 usb_dev_mph =
618 platform_device_register_simple("fsl-ehci", i, r, 2);
619 if (IS_ERR(usb_dev_mph)) {
620 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600621 goto err;
622 }
623
Kumar Gala01cced22006-04-11 10:07:16 -0500624 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
625 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600626
627 usb_data.operating_mode = FSL_USB2_MPH_HOST;
628
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000629 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600630 if (prop)
631 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
632
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000633 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600634 if (prop)
635 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
636
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000637 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600638 usb_data.phy_mode = determine_usb_phy(prop);
639
640 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500641 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600642 sizeof(struct
643 fsl_usb2_platform_data));
644 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500645 goto unreg_mph;
Li Yang866b6dd2008-01-08 15:18:46 +0800646 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600647 }
648
Li Yang866b6dd2008-01-08 15:18:46 +0800649 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600650 struct resource r[2];
651 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000652 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600653
654 memset(&r, 0, sizeof(r));
655 memset(&usb_data, 0, sizeof(usb_data));
656
657 ret = of_address_to_resource(np, 0, &r[0]);
658 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500659 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600660
Andy Fleminga9b14972006-10-19 19:52:26 -0500661 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600662
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000663 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800664
665 if (!prop || !strcmp(prop, "host")) {
666 usb_data.operating_mode = FSL_USB2_DR_HOST;
667 usb_dev_dr_host = platform_device_register_simple(
668 "fsl-ehci", i, r, 2);
669 if (IS_ERR(usb_dev_dr_host)) {
670 ret = PTR_ERR(usb_dev_dr_host);
671 goto err;
672 }
673 } else if (prop && !strcmp(prop, "peripheral")) {
674 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
675 usb_dev_dr_client = platform_device_register_simple(
676 "fsl-usb2-udc", i, r, 2);
677 if (IS_ERR(usb_dev_dr_client)) {
678 ret = PTR_ERR(usb_dev_dr_client);
679 goto err;
680 }
681 } else if (prop && !strcmp(prop, "otg")) {
682 usb_data.operating_mode = FSL_USB2_DR_OTG;
683 usb_dev_dr_host = platform_device_register_simple(
684 "fsl-ehci", i, r, 2);
685 if (IS_ERR(usb_dev_dr_host)) {
686 ret = PTR_ERR(usb_dev_dr_host);
687 goto err;
688 }
689 usb_dev_dr_client = platform_device_register_simple(
690 "fsl-usb2-udc", i, r, 2);
691 if (IS_ERR(usb_dev_dr_client)) {
692 ret = PTR_ERR(usb_dev_dr_client);
693 goto err;
694 }
695 } else {
696 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600697 goto err;
698 }
699
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000700 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600701 usb_data.phy_mode = determine_usb_phy(prop);
702
Li Yang97c5a202007-02-07 13:49:24 +0800703 if (usb_dev_dr_host) {
704 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
705 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
706 dev.coherent_dma_mask;
707 if ((ret = platform_device_add_data(usb_dev_dr_host,
708 &usb_data, sizeof(struct
709 fsl_usb2_platform_data))))
710 goto unreg_dr;
711 }
712 if (usb_dev_dr_client) {
713 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
714 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
715 dev.coherent_dma_mask;
716 if ((ret = platform_device_add_data(usb_dev_dr_client,
717 &usb_data, sizeof(struct
718 fsl_usb2_platform_data))))
719 goto unreg_dr;
720 }
Li Yang866b6dd2008-01-08 15:18:46 +0800721 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600722 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600723 return 0;
724
Kumar Gala01cced22006-04-11 10:07:16 -0500725unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800726 if (usb_dev_dr_host)
727 platform_device_unregister(usb_dev_dr_host);
728 if (usb_dev_dr_client)
729 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500730unreg_mph:
731 if (usb_dev_mph)
732 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600733err:
734 return ret;
735}
736
Kumar Gala01cced22006-04-11 10:07:16 -0500737arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400738
Scott Woode631ae32007-09-14 13:04:54 -0500739#ifndef CONFIG_PPC_CPM_NEW_BINDING
Vitaly Bordugfba43662006-09-21 17:26:34 +0400740#ifdef CONFIG_CPM2
741
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300742extern void init_scc_ioports(struct fs_uart_platform_info*);
743
Vitaly Bordugfba43662006-09-21 17:26:34 +0400744static const char fcc_regs[] = "fcc_regs";
745static const char fcc_regs_c[] = "fcc_regs_c";
746static const char fcc_pram[] = "fcc_pram";
747static char bus_id[9][BUS_ID_SIZE];
748
749static int __init fs_enet_of_init(void)
750{
751 struct device_node *np;
752 unsigned int i;
753 struct platform_device *fs_enet_dev;
754 struct resource res;
755 int ret;
756
757 for (np = NULL, i = 0;
758 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
759 i++) {
760 struct resource r[4];
761 struct device_node *phy, *mdio;
762 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500763 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400764 const void *mac_addr;
765 const phandle *ph;
766 const char *model;
767
768 memset(r, 0, sizeof(r));
769 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
770
771 ret = of_address_to_resource(np, 0, &r[0]);
772 if (ret)
773 goto err;
774 r[0].name = fcc_regs;
775
776 ret = of_address_to_resource(np, 1, &r[1]);
777 if (ret)
778 goto err;
779 r[1].name = fcc_pram;
780
781 ret = of_address_to_resource(np, 2, &r[2]);
782 if (ret)
783 goto err;
784 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400785 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400786
Andy Fleminga9b14972006-10-19 19:52:26 -0500787 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400788
789 fs_enet_dev =
790 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
791
792 if (IS_ERR(fs_enet_dev)) {
793 ret = PTR_ERR(fs_enet_dev);
794 goto err;
795 }
796
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000797 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400798 if (model == NULL) {
799 ret = -ENODEV;
800 goto unreg;
801 }
802
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600803 mac_addr = of_get_mac_address(np);
804 if (mac_addr)
805 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400806
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000807 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400808 phy = of_find_node_by_phandle(*ph);
809
810 if (phy == NULL) {
811 ret = -ENODEV;
812 goto unreg;
813 }
814
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000815 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400816 fs_enet_data.phy_addr = *phy_addr;
817
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000818 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400819
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000820 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400821 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400822 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400823
824 mdio = of_get_parent(phy);
825 ret = of_address_to_resource(mdio, 0, &res);
826 if (ret) {
827 of_node_put(phy);
828 of_node_put(mdio);
829 goto unreg;
830 }
831
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000832 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
833 "rx-clock", NULL));
834 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
835 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400836
Vitaly Bordugfba43662006-09-21 17:26:34 +0400837 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400838 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500839 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400840
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400841 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400842 fs_enet_data.rx_ring = 32;
843 fs_enet_data.tx_ring = 32;
844 fs_enet_data.rx_copybreak = 240;
845 fs_enet_data.use_napi = 0;
846 fs_enet_data.napi_weight = 17;
847 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
848 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
849 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
850
851 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
852 (u32)res.start, fs_enet_data.phy_addr);
853 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400854 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400855
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000856 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400857 if (mdio_bb_prop) {
858 struct platform_device *fs_enet_mdio_bb_dev;
859 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400860
Vitaly Borduged943c12006-10-02 22:41:50 +0400861 fs_enet_mdio_bb_dev =
862 platform_device_register_simple("fsl-bb-mdio",
863 i, NULL, 0);
864 memset(&fs_enet_mdio_bb_data, 0,
865 sizeof(struct fs_mii_bb_platform_info));
866 fs_enet_mdio_bb_data.mdio_dat.bit =
867 mdio_bb_prop[0];
868 fs_enet_mdio_bb_data.mdio_dir.bit =
869 mdio_bb_prop[1];
870 fs_enet_mdio_bb_data.mdc_dat.bit =
871 mdio_bb_prop[2];
872 fs_enet_mdio_bb_data.mdio_port =
873 mdio_bb_prop[3];
874 fs_enet_mdio_bb_data.mdc_port =
875 mdio_bb_prop[4];
876 fs_enet_mdio_bb_data.delay =
877 mdio_bb_prop[5];
878
879 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
880 fs_enet_mdio_bb_data.irq[1] = -1;
881 fs_enet_mdio_bb_data.irq[2] = -1;
882 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
883 fs_enet_mdio_bb_data.irq[31] = -1;
884
885 fs_enet_mdio_bb_data.mdio_dat.offset =
886 (u32)&cpm2_immr->im_ioport.iop_pdatc;
887 fs_enet_mdio_bb_data.mdio_dir.offset =
888 (u32)&cpm2_immr->im_ioport.iop_pdirc;
889 fs_enet_mdio_bb_data.mdc_dat.offset =
890 (u32)&cpm2_immr->im_ioport.iop_pdatc;
891
892 ret = platform_device_add_data(
893 fs_enet_mdio_bb_dev,
894 &fs_enet_mdio_bb_data,
895 sizeof(struct fs_mii_bb_platform_info));
896 if (ret)
897 goto unreg;
898 }
Li Yang97c5a202007-02-07 13:49:24 +0800899
Vitaly Borduged943c12006-10-02 22:41:50 +0400900 of_node_put(phy);
901 of_node_put(mdio);
902
903 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
904 sizeof(struct
905 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500906 if (ret)
907 goto unreg;
908 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400909 }
910 return 0;
911
912unreg:
913 platform_device_unregister(fs_enet_dev);
914err:
915 return ret;
916}
917
918arch_initcall(fs_enet_of_init);
919
920static const char scc_regs[] = "regs";
921static const char scc_pram[] = "pram";
922
923static int __init cpm_uart_of_init(void)
924{
925 struct device_node *np;
926 unsigned int i;
927 struct platform_device *cpm_uart_dev;
928 int ret;
929
930 for (np = NULL, i = 0;
931 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
932 i++) {
933 struct resource r[3];
934 struct fs_uart_platform_info cpm_uart_data;
935 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400936 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400937
938 memset(r, 0, sizeof(r));
939 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
940
941 ret = of_address_to_resource(np, 0, &r[0]);
942 if (ret)
943 goto err;
944
945 r[0].name = scc_regs;
946
947 ret = of_address_to_resource(np, 1, &r[1]);
948 if (ret)
949 goto err;
950 r[1].name = scc_pram;
951
Andy Fleminga9b14972006-10-19 19:52:26 -0500952 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400953
954 cpm_uart_dev =
955 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
956
957 if (IS_ERR(cpm_uart_dev)) {
958 ret = PTR_ERR(cpm_uart_dev);
959 goto err;
960 }
961
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000962 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400963 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400964
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000965 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400966 strcpy(cpm_uart_data.fs_type, model);
967
Vitaly Bordugfba43662006-09-21 17:26:34 +0400968 cpm_uart_data.uart_clk = ppc_proc_freq;
969
970 cpm_uart_data.tx_num_fifo = 4;
971 cpm_uart_data.tx_buf_size = 32;
972 cpm_uart_data.rx_num_fifo = 4;
973 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000974 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
975 "rx-clock", NULL));
976 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
977 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400978
979 ret =
980 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
981 sizeof(struct
982 fs_uart_platform_info));
983 if (ret)
984 goto unreg;
985 }
986
987 return 0;
988
989unreg:
990 platform_device_unregister(cpm_uart_dev);
991err:
992 return ret;
993}
994
995arch_initcall(cpm_uart_of_init);
996#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300997
998#ifdef CONFIG_8xx
999
1000extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001001extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001002
1003static int __init fs_enet_mdio_of_init(void)
1004{
1005 struct device_node *np;
1006 unsigned int i;
1007 struct platform_device *mdio_dev;
1008 struct resource res;
1009 int ret;
1010
1011 for (np = NULL, i = 0;
1012 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
1013 i++) {
1014 struct fs_mii_fec_platform_info mdio_data;
1015
1016 memset(&res, 0, sizeof(res));
1017 memset(&mdio_data, 0, sizeof(mdio_data));
1018
1019 ret = of_address_to_resource(np, 0, &res);
1020 if (ret)
1021 goto err;
1022
1023 mdio_dev =
1024 platform_device_register_simple("fsl-cpm-fec-mdio",
1025 res.start, &res, 1);
1026 if (IS_ERR(mdio_dev)) {
1027 ret = PTR_ERR(mdio_dev);
1028 goto err;
1029 }
1030
1031 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
1032
1033 ret =
1034 platform_device_add_data(mdio_dev, &mdio_data,
1035 sizeof(struct fs_mii_fec_platform_info));
1036 if (ret)
1037 goto unreg;
1038 }
1039 return 0;
1040
1041unreg:
1042 platform_device_unregister(mdio_dev);
1043err:
1044 return ret;
1045}
1046
1047arch_initcall(fs_enet_mdio_of_init);
1048
1049static const char *enet_regs = "regs";
1050static const char *enet_pram = "pram";
1051static const char *enet_irq = "interrupt";
1052static char bus_id[9][BUS_ID_SIZE];
1053
1054static int __init fs_enet_of_init(void)
1055{
1056 struct device_node *np;
1057 unsigned int i;
1058 struct platform_device *fs_enet_dev = NULL;
1059 struct resource res;
1060 int ret;
1061
1062 for (np = NULL, i = 0;
1063 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
1064 i++) {
1065 struct resource r[4];
1066 struct device_node *phy = NULL, *mdio = NULL;
1067 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001068 const unsigned int *id;
1069 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +10001070 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001071 const phandle *ph;
1072 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001073
1074 memset(r, 0, sizeof(r));
1075 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1076
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001077 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001078 if (model == NULL) {
1079 ret = -ENODEV;
1080 goto unreg;
1081 }
1082
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001083 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001084 fs_enet_data.fs_no = *id;
1085
1086 if (platform_device_skip(model, *id))
1087 continue;
1088
1089 ret = of_address_to_resource(np, 0, &r[0]);
1090 if (ret)
1091 goto err;
1092 r[0].name = enet_regs;
1093
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001094 mac_addr = of_get_mac_address(np);
1095 if (mac_addr)
1096 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001097
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001098 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001099 if (ph != NULL)
1100 phy = of_find_node_by_phandle(*ph);
1101
1102 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001103 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001104 fs_enet_data.phy_addr = *phy_addr;
1105 fs_enet_data.has_phy = 1;
1106
1107 mdio = of_get_parent(phy);
1108 ret = of_address_to_resource(mdio, 0, &res);
1109 if (ret) {
1110 of_node_put(phy);
1111 of_node_put(mdio);
1112 goto unreg;
1113 }
1114 }
1115
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001116 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001117 strcpy(fs_enet_data.fs_type, model);
1118
1119 if (strstr(model, "FEC")) {
1120 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1121 r[1].flags = IORESOURCE_IRQ;
1122 r[1].name = enet_irq;
1123
1124 fs_enet_dev =
1125 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1126
1127 if (IS_ERR(fs_enet_dev)) {
1128 ret = PTR_ERR(fs_enet_dev);
1129 goto err;
1130 }
1131
1132 fs_enet_data.rx_ring = 128;
1133 fs_enet_data.tx_ring = 16;
1134 fs_enet_data.rx_copybreak = 240;
1135 fs_enet_data.use_napi = 1;
1136 fs_enet_data.napi_weight = 17;
1137
1138 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1139 (u32)res.start, fs_enet_data.phy_addr);
1140 fs_enet_data.bus_id = (char*)&bus_id[i];
1141 fs_enet_data.init_ioports = init_fec_ioports;
1142 }
1143 if (strstr(model, "SCC")) {
1144 ret = of_address_to_resource(np, 1, &r[1]);
1145 if (ret)
1146 goto err;
1147 r[1].name = enet_pram;
1148
1149 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1150 r[2].flags = IORESOURCE_IRQ;
1151 r[2].name = enet_irq;
1152
1153 fs_enet_dev =
1154 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1155
1156 if (IS_ERR(fs_enet_dev)) {
1157 ret = PTR_ERR(fs_enet_dev);
1158 goto err;
1159 }
1160
1161 fs_enet_data.rx_ring = 64;
1162 fs_enet_data.tx_ring = 8;
1163 fs_enet_data.rx_copybreak = 240;
1164 fs_enet_data.use_napi = 1;
1165 fs_enet_data.napi_weight = 17;
1166
1167 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1168 fs_enet_data.bus_id = (char*)&bus_id[i];
1169 fs_enet_data.init_ioports = init_scc_ioports;
1170 }
1171
1172 of_node_put(phy);
1173 of_node_put(mdio);
1174
1175 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1176 sizeof(struct
1177 fs_platform_info));
1178 if (ret)
1179 goto unreg;
1180 }
1181 return 0;
1182
1183unreg:
1184 platform_device_unregister(fs_enet_dev);
1185err:
1186 return ret;
1187}
1188
1189arch_initcall(fs_enet_of_init);
1190
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001191static int __init fsl_pcmcia_of_init(void)
1192{
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +11001193 struct device_node *np;
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001194 /*
1195 * Register all the devices which type is "pcmcia"
1196 */
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +11001197 for_each_compatible_node(np, "pcmcia", "fsl,pq-pcmcia")
1198 of_platform_device_create(np, "m8xx-pcmcia", NULL);
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001199 return 0;
1200}
1201
1202arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001203
1204static const char *smc_regs = "regs";
1205static const char *smc_pram = "pram";
1206
1207static int __init cpm_smc_uart_of_init(void)
1208{
1209 struct device_node *np;
1210 unsigned int i;
1211 struct platform_device *cpm_uart_dev;
1212 int ret;
1213
1214 for (np = NULL, i = 0;
1215 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1216 i++) {
1217 struct resource r[3];
1218 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001219 const int *id;
1220 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001221
1222 memset(r, 0, sizeof(r));
1223 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1224
1225 ret = of_address_to_resource(np, 0, &r[0]);
1226 if (ret)
1227 goto err;
1228
1229 r[0].name = smc_regs;
1230
1231 ret = of_address_to_resource(np, 1, &r[1]);
1232 if (ret)
1233 goto err;
1234 r[1].name = smc_pram;
1235
1236 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1237 r[2].flags = IORESOURCE_IRQ;
1238
1239 cpm_uart_dev =
1240 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1241
1242 if (IS_ERR(cpm_uart_dev)) {
1243 ret = PTR_ERR(cpm_uart_dev);
1244 goto err;
1245 }
1246
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001247 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001248 strcpy(cpm_uart_data.fs_type, model);
1249
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001250 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001251 cpm_uart_data.fs_no = *id;
1252 cpm_uart_data.uart_clk = ppc_proc_freq;
1253
1254 cpm_uart_data.tx_num_fifo = 4;
1255 cpm_uart_data.tx_buf_size = 32;
1256 cpm_uart_data.rx_num_fifo = 4;
1257 cpm_uart_data.rx_buf_size = 32;
1258
1259 ret =
1260 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1261 sizeof(struct
1262 fs_uart_platform_info));
1263 if (ret)
1264 goto unreg;
1265 }
1266
1267 return 0;
1268
1269unreg:
1270 platform_device_unregister(cpm_uart_dev);
1271err:
1272 return ret;
1273}
1274
1275arch_initcall(cpm_smc_uart_of_init);
1276
1277#endif /* CONFIG_8xx */
Scott Woode631ae32007-09-14 13:04:54 -05001278#endif /* CONFIG_PPC_CPM_NEW_BINDING */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001279
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001280static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
1281 struct spi_board_info *board_infos,
1282 unsigned int num_board_infos,
1283 void (*activate_cs)(u8 cs, u8 polarity),
1284 void (*deactivate_cs)(u8 cs, u8 polarity))
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001285{
1286 struct device_node *np;
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001287 unsigned int i = 0;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001288
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001289 for_each_compatible_node(np, type, compatible) {
1290 int ret;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001291 unsigned int j;
1292 const void *prop;
1293 struct resource res[2];
1294 struct platform_device *pdev;
1295 struct fsl_spi_platform_data pdata = {
1296 .activate_cs = activate_cs,
1297 .deactivate_cs = deactivate_cs,
1298 };
1299
1300 memset(res, 0, sizeof(res));
1301
Anton Vorontsov59a0ea52008-01-24 18:40:03 +03001302 pdata.sysclk = sysclk;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001303
1304 prop = of_get_property(np, "reg", NULL);
1305 if (!prop)
1306 goto err;
1307 pdata.bus_num = *(u32 *)prop;
1308
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001309 prop = of_get_property(np, "cell-index", NULL);
1310 if (prop)
1311 i = *(u32 *)prop;
1312
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001313 prop = of_get_property(np, "mode", NULL);
1314 if (prop && !strcmp(prop, "cpu-qe"))
1315 pdata.qe_mode = 1;
1316
1317 for (j = 0; j < num_board_infos; j++) {
1318 if (board_infos[j].bus_num == pdata.bus_num)
1319 pdata.max_chipselect++;
1320 }
1321
1322 if (!pdata.max_chipselect)
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001323 continue;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001324
1325 ret = of_address_to_resource(np, 0, &res[0]);
1326 if (ret)
1327 goto err;
1328
1329 ret = of_irq_to_resource(np, 0, &res[1]);
1330 if (ret == NO_IRQ)
1331 goto err;
1332
1333 pdev = platform_device_alloc("mpc83xx_spi", i);
1334 if (!pdev)
1335 goto err;
1336
1337 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1338 if (ret)
1339 goto unreg;
1340
1341 ret = platform_device_add_resources(pdev, res,
1342 ARRAY_SIZE(res));
1343 if (ret)
1344 goto unreg;
1345
Kim Phillipsdc4e4202008-02-01 18:09:58 -06001346 ret = platform_device_add(pdev);
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001347 if (ret)
1348 goto unreg;
1349
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001350 goto next;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001351unreg:
1352 platform_device_del(pdev);
1353err:
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001354 pr_err("%s: registration failed\n", np->full_name);
1355next:
1356 i++;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001357 }
1358
Anton Vorontsovf3a2b292008-01-24 18:40:07 +03001359 return i;
1360}
1361
1362int __init fsl_spi_init(struct spi_board_info *board_infos,
1363 unsigned int num_board_infos,
1364 void (*activate_cs)(u8 cs, u8 polarity),
1365 void (*deactivate_cs)(u8 cs, u8 polarity))
1366{
1367 u32 sysclk = -1;
1368 int ret;
1369
1370#ifdef CONFIG_QUICC_ENGINE
1371 /* SPI controller is either clocked from QE or SoC clock */
1372 sysclk = get_brgfreq();
1373#endif
1374 if (sysclk == -1) {
1375 struct device_node *np;
1376 const u32 *freq;
1377 int size;
1378
1379 np = of_find_node_by_type(NULL, "soc");
1380 if (!np)
1381 return -ENODEV;
1382
1383 freq = of_get_property(np, "clock-frequency", &size);
1384 if (!freq || size != sizeof(*freq) || *freq == 0) {
1385 freq = of_get_property(np, "bus-frequency", &size);
1386 if (!freq || size != sizeof(*freq) || *freq == 0) {
1387 of_node_put(np);
1388 return -ENODEV;
1389 }
1390 }
1391
1392 sysclk = *freq;
1393 of_node_put(np);
1394 }
1395
1396 ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
1397 num_board_infos, activate_cs, deactivate_cs);
1398 if (!ret)
1399 of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
1400 num_board_infos, activate_cs, deactivate_cs);
1401
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001402 return spi_register_board_info(board_infos, num_board_infos);
1403}
Kumar Galae1c15752007-10-04 01:04:57 -05001404
1405#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1406static __be32 __iomem *rstcr;
1407
1408static int __init setup_rstcr(void)
1409{
1410 struct device_node *np;
1411 np = of_find_node_by_name(NULL, "global-utilities");
1412 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
1413 const u32 *prop = of_get_property(np, "reg", NULL);
1414 if (prop) {
1415 /* map reset control register
1416 * 0xE00B0 is offset of reset control register
1417 */
1418 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
1419 if (!rstcr)
1420 printk (KERN_EMERG "Error: reset control "
1421 "register not mapped!\n");
1422 }
1423 } else
1424 printk (KERN_INFO "rstcr compatible register does not exist!\n");
1425 if (np)
1426 of_node_put(np);
1427 return 0;
1428}
1429
1430arch_initcall(setup_rstcr);
1431
1432void fsl_rstcr_restart(char *cmd)
1433{
1434 local_irq_disable();
1435 if (rstcr)
1436 /* set reset control register */
1437 out_be32(rstcr, 0x2); /* HRESET_REQ */
1438
1439 while (1) ;
1440}
1441#endif