blob: ef880cb54c1dce0bc7e1d0c3a62795b68ec0e3fd [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>
Anton Vorontsov26f6cb92007-08-23 15:35:56 +040027#include <linux/spi/spi.h>
Kumar Galaeed32002006-01-13 11:19:13 -060028#include <linux/fsl_devices.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040029#include <linux/fs_enet_pd.h>
30#include <linux/fs_uart_pd.h>
Kumar Galaeed32002006-01-13 11:19:13 -060031
32#include <asm/system.h>
33#include <asm/atomic.h>
34#include <asm/io.h>
35#include <asm/irq.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040036#include <asm/time.h>
Kumar Galaeed32002006-01-13 11:19:13 -060037#include <asm/prom.h>
38#include <sysdev/fsl_soc.h>
39#include <mm/mmu_decl.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040040#include <asm/cpm2.h>
Kumar Galaeed32002006-01-13 11:19:13 -060041
Vitaly Bordugd3465c92006-09-21 22:38:05 +040042extern void init_fcc_ioports(struct fs_platform_info*);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030043extern void init_fec_ioports(struct fs_platform_info*);
44extern void init_smc_ioports(struct fs_uart_platform_info*);
Kumar Galaeed32002006-01-13 11:19:13 -060045static phys_addr_t immrbase = -1;
46
47phys_addr_t get_immrbase(void)
48{
49 struct device_node *soc;
50
51 if (immrbase != -1)
52 return immrbase;
53
54 soc = of_find_node_by_type(NULL, "soc");
Kumar Gala2fb07d72006-01-23 16:58:04 -060055 if (soc) {
Scott Woodf9234732007-08-20 11:38:12 -050056 int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100057 const void *prop = of_get_property(soc, "reg", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040058
59 if (prop)
60 immrbase = of_translate_address(soc, prop);
Kumar Galaeed32002006-01-13 11:19:13 -060061 of_node_put(soc);
Scott Woodf9234732007-08-20 11:38:12 -050062 }
Kumar Galaeed32002006-01-13 11:19:13 -060063
64 return immrbase;
65}
Kumar Gala2fb07d72006-01-23 16:58:04 -060066
Kumar Galaeed32002006-01-13 11:19:13 -060067EXPORT_SYMBOL(get_immrbase);
68
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030069#if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
Vitaly Bordugfba43662006-09-21 17:26:34 +040070
71static u32 brgfreq = -1;
72
73u32 get_brgfreq(void)
74{
75 struct device_node *node;
Scott Wood6d817aa2007-08-29 15:08:40 -050076 const unsigned int *prop;
77 int size;
Vitaly Bordugfba43662006-09-21 17:26:34 +040078
79 if (brgfreq != -1)
80 return brgfreq;
81
Scott Wood6d817aa2007-08-29 15:08:40 -050082 node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
Vitaly Bordugfba43662006-09-21 17:26:34 +040083 if (node) {
Scott Wood6d817aa2007-08-29 15:08:40 -050084 prop = of_get_property(node, "clock-frequency", &size);
85 if (prop && size == 4)
86 brgfreq = *prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +040087
Scott Wood6d817aa2007-08-29 15:08:40 -050088 of_node_put(node);
89 return brgfreq;
90 }
91
92 /* Legacy device binding -- will go away when no users are left. */
93 node = of_find_node_by_type(NULL, "cpm");
94 if (node) {
95 prop = of_get_property(node, "brg-frequency", &size);
Scott Woodf9234732007-08-20 11:38:12 -050096 if (prop && size == 4)
Vitaly Bordugfba43662006-09-21 17:26:34 +040097 brgfreq = *prop;
Scott Woodf9234732007-08-20 11:38:12 -050098
Vitaly Bordugfba43662006-09-21 17:26:34 +040099 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500100 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400101
102 return brgfreq;
103}
104
105EXPORT_SYMBOL(get_brgfreq);
106
107static u32 fs_baudrate = -1;
108
109u32 get_baudrate(void)
110{
111 struct device_node *node;
112
113 if (fs_baudrate != -1)
114 return fs_baudrate;
115
116 node = of_find_node_by_type(NULL, "serial");
117 if (node) {
Scott Woodf9234732007-08-20 11:38:12 -0500118 int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000119 const unsigned int *prop = of_get_property(node,
120 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400121
122 if (prop)
123 fs_baudrate = *prop;
124 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500125 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400126
127 return fs_baudrate;
128}
129
130EXPORT_SYMBOL(get_baudrate);
131#endif /* CONFIG_CPM2 */
132
Kumar Gala2fb07d72006-01-23 16:58:04 -0600133static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600134{
135 struct device_node *np;
136 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600137 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600138 struct resource res;
139 int ret;
140
Kumar Gala2fb07d72006-01-23 16:58:04 -0600141 for (np = NULL, i = 0;
142 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
143 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600144 int k;
145 struct device_node *child = NULL;
146 struct gianfar_mdio_data mdio_data;
147
148 memset(&res, 0, sizeof(res));
149 memset(&mdio_data, 0, sizeof(mdio_data));
150
151 ret = of_address_to_resource(np, 0, &res);
152 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600153 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600154
Kumar Gala2fb07d72006-01-23 16:58:04 -0600155 mdio_dev =
156 platform_device_register_simple("fsl-gianfar_mdio",
157 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600158 if (IS_ERR(mdio_dev)) {
159 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600160 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600161 }
162
163 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500164 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600165
166 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400167 int irq = irq_of_parse_and_map(child, 0);
168 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000169 const u32 *id = of_get_property(child,
170 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400171 mdio_data.irq[*id] = irq;
172 }
Kumar Galaeed32002006-01-13 11:19:13 -0600173 }
174
Kumar Gala2fb07d72006-01-23 16:58:04 -0600175 ret =
176 platform_device_add_data(mdio_dev, &mdio_data,
177 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600178 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600179 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600180 }
181
Kumar Gala2fb07d72006-01-23 16:58:04 -0600182 return 0;
183
184unreg:
185 platform_device_unregister(mdio_dev);
186err:
187 return ret;
188}
189
190arch_initcall(gfar_mdio_of_init);
191
192static const char *gfar_tx_intr = "tx";
193static const char *gfar_rx_intr = "rx";
194static const char *gfar_err_intr = "error";
195
Andy Fleminga9b14972006-10-19 19:52:26 -0500196
Kumar Gala2fb07d72006-01-23 16:58:04 -0600197static int __init gfar_of_init(void)
198{
199 struct device_node *np;
200 unsigned int i;
201 struct platform_device *gfar_dev;
202 struct resource res;
203 int ret;
204
205 for (np = NULL, i = 0;
206 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
207 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600208 struct resource r[4];
209 struct device_node *phy, *mdio;
210 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000211 const unsigned int *id;
212 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500213 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000214 const void *mac_addr;
215 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400216 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600217
218 memset(r, 0, sizeof(r));
219 memset(&gfar_data, 0, sizeof(gfar_data));
220
221 ret = of_address_to_resource(np, 0, &r[0]);
222 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600223 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600224
Andy Fleminga9b14972006-10-19 19:52:26 -0500225 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600226
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000227 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600228
229 /* If we aren't the FEC we have multiple interrupts */
230 if (model && strcasecmp(model, "FEC")) {
231 r[1].name = gfar_tx_intr;
232
233 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500234 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600235
236 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500237 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500238
239 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600240 }
241
Kumar Gala2fb07d72006-01-23 16:58:04 -0600242 gfar_dev =
243 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400244 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600245
246 if (IS_ERR(gfar_dev)) {
247 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600248 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600249 }
250
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600251 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500252 if (mac_addr)
253 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600254
255 if (model && !strcasecmp(model, "TSEC"))
256 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600257 FSL_GIANFAR_DEV_HAS_GIGABIT |
258 FSL_GIANFAR_DEV_HAS_COALESCE |
259 FSL_GIANFAR_DEV_HAS_RMON |
260 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600261 if (model && !strcasecmp(model, "eTSEC"))
262 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600263 FSL_GIANFAR_DEV_HAS_GIGABIT |
264 FSL_GIANFAR_DEV_HAS_COALESCE |
265 FSL_GIANFAR_DEV_HAS_RMON |
266 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
267 FSL_GIANFAR_DEV_HAS_CSUM |
268 FSL_GIANFAR_DEV_HAS_VLAN |
269 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600270
Andy Fleming7132ab72007-07-11 11:43:07 -0500271 ctype = of_get_property(np, "phy-connection-type", NULL);
272
273 /* We only care about rgmii-id. The rest are autodetected */
274 if (ctype && !strcmp(ctype, "rgmii-id"))
275 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
276 else
277 gfar_data.interface = PHY_INTERFACE_MODE_MII;
278
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000279 ph = of_get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600280 phy = of_find_node_by_phandle(*ph);
281
282 if (phy == NULL) {
283 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600284 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600285 }
286
287 mdio = of_get_parent(phy);
288
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000289 id = of_get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600290 ret = of_address_to_resource(mdio, 0, &res);
291 if (ret) {
292 of_node_put(phy);
293 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600294 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600295 }
296
297 gfar_data.phy_id = *id;
298 gfar_data.bus_id = res.start;
299
300 of_node_put(phy);
301 of_node_put(mdio);
302
Kumar Gala2fb07d72006-01-23 16:58:04 -0600303 ret =
304 platform_device_add_data(gfar_dev, &gfar_data,
305 sizeof(struct
306 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600307 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600308 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600309 }
310
311 return 0;
312
Kumar Gala2fb07d72006-01-23 16:58:04 -0600313unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600314 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600315err:
Kumar Galaeed32002006-01-13 11:19:13 -0600316 return ret;
317}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600318
Kumar Galaeed32002006-01-13 11:19:13 -0600319arch_initcall(gfar_of_init);
320
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000321#ifdef CONFIG_I2C_BOARDINFO
322#include <linux/i2c.h>
323struct i2c_driver_device {
324 char *of_device;
325 char *i2c_driver;
326 char *i2c_type;
327};
328
329static struct i2c_driver_device i2c_devices[] __initdata = {
330 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
331 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
332 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
333 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
334};
335
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000336static int __init of_find_i2c_driver(struct device_node *node,
337 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000338{
339 int i;
340
341 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
342 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
343 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000344 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
345 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
346 strlcpy(info->type, i2c_devices[i].i2c_type,
347 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
348 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000349 return 0;
350 }
351 return -ENODEV;
352}
353
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000354static void __init of_register_i2c_devices(struct device_node *adap_node,
355 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000356{
357 struct device_node *node = NULL;
358
359 while ((node = of_get_next_child(adap_node, node))) {
360 struct i2c_board_info info;
361 const u32 *addr;
362 int len;
363
364 addr = of_get_property(node, "reg", &len);
365 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
Peter Korsgaard210805e2007-09-20 12:42:12 +0200366 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000367 continue;
368 }
369
370 info.irq = irq_of_parse_and_map(node, 0);
371 if (info.irq == NO_IRQ)
372 info.irq = -1;
373
374 if (of_find_i2c_driver(node, &info) < 0)
375 continue;
376
377 info.platform_data = NULL;
378 info.addr = *addr;
379
380 i2c_register_board_info(bus_num, &info, 1);
381 }
382}
383
Kumar Galaeed32002006-01-13 11:19:13 -0600384static int __init fsl_i2c_of_init(void)
385{
386 struct device_node *np;
387 unsigned int i;
388 struct platform_device *i2c_dev;
389 int ret;
390
Kumar Gala2fb07d72006-01-23 16:58:04 -0600391 for (np = NULL, i = 0;
392 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
393 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600394 struct resource r[2];
395 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000396 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600397
398 memset(&r, 0, sizeof(r));
399 memset(&i2c_data, 0, sizeof(i2c_data));
400
401 ret = of_address_to_resource(np, 0, &r[0]);
402 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600403 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600404
Andy Fleminga9b14972006-10-19 19:52:26 -0500405 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600406
407 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
408 if (IS_ERR(i2c_dev)) {
409 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600410 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600411 }
412
413 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000414 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600415 if (flags)
416 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
417
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000418 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600419 if (flags)
420 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
421
Kumar Gala2fb07d72006-01-23 16:58:04 -0600422 ret =
423 platform_device_add_data(i2c_dev, &i2c_data,
424 sizeof(struct
425 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600426 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600427 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000428
429 of_register_i2c_devices(np, i);
Kumar Galaeed32002006-01-13 11:19:13 -0600430 }
431
432 return 0;
433
Kumar Gala2fb07d72006-01-23 16:58:04 -0600434unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600435 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600436err:
Kumar Galaeed32002006-01-13 11:19:13 -0600437 return ret;
438}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600439
Kumar Galaeed32002006-01-13 11:19:13 -0600440arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000441#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600442
443#ifdef CONFIG_PPC_83xx
444static int __init mpc83xx_wdt_init(void)
445{
446 struct resource r;
447 struct device_node *soc, *np;
448 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000449 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600450 int ret;
451
452 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
453
454 if (!np) {
455 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600456 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600457 }
458
459 soc = of_find_node_by_type(NULL, "soc");
460
461 if (!soc) {
462 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600463 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600464 }
465
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000466 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600467 if (!freq) {
468 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600469 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600470 }
471
472 memset(&r, 0, sizeof(r));
473
474 ret = of_address_to_resource(np, 0, &r);
475 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600476 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600477
478 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
479 if (IS_ERR(dev)) {
480 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600481 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600482 }
483
484 ret = platform_device_add_data(dev, freq, sizeof(int));
485 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600486 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600487
488 of_node_put(soc);
489 of_node_put(np);
490
491 return 0;
492
Kumar Gala2fb07d72006-01-23 16:58:04 -0600493unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600494 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600495err:
Kumar Galaeed32002006-01-13 11:19:13 -0600496 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600497nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600498 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600499nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600500 return ret;
501}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600502
Kumar Galaeed32002006-01-13 11:19:13 -0600503arch_initcall(mpc83xx_wdt_init);
504#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600505
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000506static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600507{
508 if (!phy_type)
509 return FSL_USB2_PHY_NONE;
510 if (!strcasecmp(phy_type, "ulpi"))
511 return FSL_USB2_PHY_ULPI;
512 if (!strcasecmp(phy_type, "utmi"))
513 return FSL_USB2_PHY_UTMI;
514 if (!strcasecmp(phy_type, "utmi_wide"))
515 return FSL_USB2_PHY_UTMI_WIDE;
516 if (!strcasecmp(phy_type, "serial"))
517 return FSL_USB2_PHY_SERIAL;
518
519 return FSL_USB2_PHY_NONE;
520}
521
522static int __init fsl_usb_of_init(void)
523{
524 struct device_node *np;
525 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800526 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
527 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600528 int ret;
529
530 for (np = NULL, i = 0;
531 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
532 i++) {
533 struct resource r[2];
534 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000535 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600536
537 memset(&r, 0, sizeof(r));
538 memset(&usb_data, 0, sizeof(usb_data));
539
540 ret = of_address_to_resource(np, 0, &r[0]);
541 if (ret)
542 goto err;
543
Andy Fleminga9b14972006-10-19 19:52:26 -0500544 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600545
Kumar Gala01cced22006-04-11 10:07:16 -0500546 usb_dev_mph =
547 platform_device_register_simple("fsl-ehci", i, r, 2);
548 if (IS_ERR(usb_dev_mph)) {
549 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600550 goto err;
551 }
552
Kumar Gala01cced22006-04-11 10:07:16 -0500553 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
554 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600555
556 usb_data.operating_mode = FSL_USB2_MPH_HOST;
557
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000558 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600559 if (prop)
560 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
561
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000562 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600563 if (prop)
564 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
565
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000566 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600567 usb_data.phy_mode = determine_usb_phy(prop);
568
569 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500570 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600571 sizeof(struct
572 fsl_usb2_platform_data));
573 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500574 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600575 }
576
Kumar Gala01cced22006-04-11 10:07:16 -0500577 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600578 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
579 i++) {
580 struct resource r[2];
581 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000582 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600583
584 memset(&r, 0, sizeof(r));
585 memset(&usb_data, 0, sizeof(usb_data));
586
587 ret = of_address_to_resource(np, 0, &r[0]);
588 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500589 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600590
Andy Fleminga9b14972006-10-19 19:52:26 -0500591 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600592
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000593 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800594
595 if (!prop || !strcmp(prop, "host")) {
596 usb_data.operating_mode = FSL_USB2_DR_HOST;
597 usb_dev_dr_host = platform_device_register_simple(
598 "fsl-ehci", i, r, 2);
599 if (IS_ERR(usb_dev_dr_host)) {
600 ret = PTR_ERR(usb_dev_dr_host);
601 goto err;
602 }
603 } else if (prop && !strcmp(prop, "peripheral")) {
604 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
605 usb_dev_dr_client = platform_device_register_simple(
606 "fsl-usb2-udc", i, r, 2);
607 if (IS_ERR(usb_dev_dr_client)) {
608 ret = PTR_ERR(usb_dev_dr_client);
609 goto err;
610 }
611 } else if (prop && !strcmp(prop, "otg")) {
612 usb_data.operating_mode = FSL_USB2_DR_OTG;
613 usb_dev_dr_host = platform_device_register_simple(
614 "fsl-ehci", i, r, 2);
615 if (IS_ERR(usb_dev_dr_host)) {
616 ret = PTR_ERR(usb_dev_dr_host);
617 goto err;
618 }
619 usb_dev_dr_client = platform_device_register_simple(
620 "fsl-usb2-udc", i, r, 2);
621 if (IS_ERR(usb_dev_dr_client)) {
622 ret = PTR_ERR(usb_dev_dr_client);
623 goto err;
624 }
625 } else {
626 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600627 goto err;
628 }
629
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000630 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600631 usb_data.phy_mode = determine_usb_phy(prop);
632
Li Yang97c5a202007-02-07 13:49:24 +0800633 if (usb_dev_dr_host) {
634 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
635 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
636 dev.coherent_dma_mask;
637 if ((ret = platform_device_add_data(usb_dev_dr_host,
638 &usb_data, sizeof(struct
639 fsl_usb2_platform_data))))
640 goto unreg_dr;
641 }
642 if (usb_dev_dr_client) {
643 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
644 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
645 dev.coherent_dma_mask;
646 if ((ret = platform_device_add_data(usb_dev_dr_client,
647 &usb_data, sizeof(struct
648 fsl_usb2_platform_data))))
649 goto unreg_dr;
650 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600651 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600652 return 0;
653
Kumar Gala01cced22006-04-11 10:07:16 -0500654unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800655 if (usb_dev_dr_host)
656 platform_device_unregister(usb_dev_dr_host);
657 if (usb_dev_dr_client)
658 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500659unreg_mph:
660 if (usb_dev_mph)
661 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600662err:
663 return ret;
664}
665
Kumar Gala01cced22006-04-11 10:07:16 -0500666arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400667
Scott Woode631ae32007-09-14 13:04:54 -0500668#ifndef CONFIG_PPC_CPM_NEW_BINDING
Vitaly Bordugfba43662006-09-21 17:26:34 +0400669#ifdef CONFIG_CPM2
670
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300671extern void init_scc_ioports(struct fs_uart_platform_info*);
672
Vitaly Bordugfba43662006-09-21 17:26:34 +0400673static const char fcc_regs[] = "fcc_regs";
674static const char fcc_regs_c[] = "fcc_regs_c";
675static const char fcc_pram[] = "fcc_pram";
676static char bus_id[9][BUS_ID_SIZE];
677
678static int __init fs_enet_of_init(void)
679{
680 struct device_node *np;
681 unsigned int i;
682 struct platform_device *fs_enet_dev;
683 struct resource res;
684 int ret;
685
686 for (np = NULL, i = 0;
687 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
688 i++) {
689 struct resource r[4];
690 struct device_node *phy, *mdio;
691 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500692 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400693 const void *mac_addr;
694 const phandle *ph;
695 const char *model;
696
697 memset(r, 0, sizeof(r));
698 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
699
700 ret = of_address_to_resource(np, 0, &r[0]);
701 if (ret)
702 goto err;
703 r[0].name = fcc_regs;
704
705 ret = of_address_to_resource(np, 1, &r[1]);
706 if (ret)
707 goto err;
708 r[1].name = fcc_pram;
709
710 ret = of_address_to_resource(np, 2, &r[2]);
711 if (ret)
712 goto err;
713 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400714 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400715
Andy Fleminga9b14972006-10-19 19:52:26 -0500716 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400717
718 fs_enet_dev =
719 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
720
721 if (IS_ERR(fs_enet_dev)) {
722 ret = PTR_ERR(fs_enet_dev);
723 goto err;
724 }
725
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000726 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400727 if (model == NULL) {
728 ret = -ENODEV;
729 goto unreg;
730 }
731
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600732 mac_addr = of_get_mac_address(np);
733 if (mac_addr)
734 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400735
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000736 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400737 phy = of_find_node_by_phandle(*ph);
738
739 if (phy == NULL) {
740 ret = -ENODEV;
741 goto unreg;
742 }
743
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000744 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400745 fs_enet_data.phy_addr = *phy_addr;
746
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000747 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400748
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000749 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400750 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400751 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400752
753 mdio = of_get_parent(phy);
754 ret = of_address_to_resource(mdio, 0, &res);
755 if (ret) {
756 of_node_put(phy);
757 of_node_put(mdio);
758 goto unreg;
759 }
760
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000761 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
762 "rx-clock", NULL));
763 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
764 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400765
Vitaly Bordugfba43662006-09-21 17:26:34 +0400766 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400767 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500768 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400769
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400770 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400771 fs_enet_data.rx_ring = 32;
772 fs_enet_data.tx_ring = 32;
773 fs_enet_data.rx_copybreak = 240;
774 fs_enet_data.use_napi = 0;
775 fs_enet_data.napi_weight = 17;
776 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
777 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
778 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
779
780 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
781 (u32)res.start, fs_enet_data.phy_addr);
782 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400783 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400784
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000785 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400786 if (mdio_bb_prop) {
787 struct platform_device *fs_enet_mdio_bb_dev;
788 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400789
Vitaly Borduged943c12006-10-02 22:41:50 +0400790 fs_enet_mdio_bb_dev =
791 platform_device_register_simple("fsl-bb-mdio",
792 i, NULL, 0);
793 memset(&fs_enet_mdio_bb_data, 0,
794 sizeof(struct fs_mii_bb_platform_info));
795 fs_enet_mdio_bb_data.mdio_dat.bit =
796 mdio_bb_prop[0];
797 fs_enet_mdio_bb_data.mdio_dir.bit =
798 mdio_bb_prop[1];
799 fs_enet_mdio_bb_data.mdc_dat.bit =
800 mdio_bb_prop[2];
801 fs_enet_mdio_bb_data.mdio_port =
802 mdio_bb_prop[3];
803 fs_enet_mdio_bb_data.mdc_port =
804 mdio_bb_prop[4];
805 fs_enet_mdio_bb_data.delay =
806 mdio_bb_prop[5];
807
808 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
809 fs_enet_mdio_bb_data.irq[1] = -1;
810 fs_enet_mdio_bb_data.irq[2] = -1;
811 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
812 fs_enet_mdio_bb_data.irq[31] = -1;
813
814 fs_enet_mdio_bb_data.mdio_dat.offset =
815 (u32)&cpm2_immr->im_ioport.iop_pdatc;
816 fs_enet_mdio_bb_data.mdio_dir.offset =
817 (u32)&cpm2_immr->im_ioport.iop_pdirc;
818 fs_enet_mdio_bb_data.mdc_dat.offset =
819 (u32)&cpm2_immr->im_ioport.iop_pdatc;
820
821 ret = platform_device_add_data(
822 fs_enet_mdio_bb_dev,
823 &fs_enet_mdio_bb_data,
824 sizeof(struct fs_mii_bb_platform_info));
825 if (ret)
826 goto unreg;
827 }
Li Yang97c5a202007-02-07 13:49:24 +0800828
Vitaly Borduged943c12006-10-02 22:41:50 +0400829 of_node_put(phy);
830 of_node_put(mdio);
831
832 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
833 sizeof(struct
834 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500835 if (ret)
836 goto unreg;
837 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400838 }
839 return 0;
840
841unreg:
842 platform_device_unregister(fs_enet_dev);
843err:
844 return ret;
845}
846
847arch_initcall(fs_enet_of_init);
848
849static const char scc_regs[] = "regs";
850static const char scc_pram[] = "pram";
851
852static int __init cpm_uart_of_init(void)
853{
854 struct device_node *np;
855 unsigned int i;
856 struct platform_device *cpm_uart_dev;
857 int ret;
858
859 for (np = NULL, i = 0;
860 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
861 i++) {
862 struct resource r[3];
863 struct fs_uart_platform_info cpm_uart_data;
864 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400865 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400866
867 memset(r, 0, sizeof(r));
868 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
869
870 ret = of_address_to_resource(np, 0, &r[0]);
871 if (ret)
872 goto err;
873
874 r[0].name = scc_regs;
875
876 ret = of_address_to_resource(np, 1, &r[1]);
877 if (ret)
878 goto err;
879 r[1].name = scc_pram;
880
Andy Fleminga9b14972006-10-19 19:52:26 -0500881 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400882
883 cpm_uart_dev =
884 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
885
886 if (IS_ERR(cpm_uart_dev)) {
887 ret = PTR_ERR(cpm_uart_dev);
888 goto err;
889 }
890
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000891 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400892 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400893
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000894 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400895 strcpy(cpm_uart_data.fs_type, model);
896
Vitaly Bordugfba43662006-09-21 17:26:34 +0400897 cpm_uart_data.uart_clk = ppc_proc_freq;
898
899 cpm_uart_data.tx_num_fifo = 4;
900 cpm_uart_data.tx_buf_size = 32;
901 cpm_uart_data.rx_num_fifo = 4;
902 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000903 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
904 "rx-clock", NULL));
905 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
906 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400907
908 ret =
909 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
910 sizeof(struct
911 fs_uart_platform_info));
912 if (ret)
913 goto unreg;
914 }
915
916 return 0;
917
918unreg:
919 platform_device_unregister(cpm_uart_dev);
920err:
921 return ret;
922}
923
924arch_initcall(cpm_uart_of_init);
925#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300926
927#ifdef CONFIG_8xx
928
929extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000930extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300931
932static int __init fs_enet_mdio_of_init(void)
933{
934 struct device_node *np;
935 unsigned int i;
936 struct platform_device *mdio_dev;
937 struct resource res;
938 int ret;
939
940 for (np = NULL, i = 0;
941 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
942 i++) {
943 struct fs_mii_fec_platform_info mdio_data;
944
945 memset(&res, 0, sizeof(res));
946 memset(&mdio_data, 0, sizeof(mdio_data));
947
948 ret = of_address_to_resource(np, 0, &res);
949 if (ret)
950 goto err;
951
952 mdio_dev =
953 platform_device_register_simple("fsl-cpm-fec-mdio",
954 res.start, &res, 1);
955 if (IS_ERR(mdio_dev)) {
956 ret = PTR_ERR(mdio_dev);
957 goto err;
958 }
959
960 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
961
962 ret =
963 platform_device_add_data(mdio_dev, &mdio_data,
964 sizeof(struct fs_mii_fec_platform_info));
965 if (ret)
966 goto unreg;
967 }
968 return 0;
969
970unreg:
971 platform_device_unregister(mdio_dev);
972err:
973 return ret;
974}
975
976arch_initcall(fs_enet_mdio_of_init);
977
978static const char *enet_regs = "regs";
979static const char *enet_pram = "pram";
980static const char *enet_irq = "interrupt";
981static char bus_id[9][BUS_ID_SIZE];
982
983static int __init fs_enet_of_init(void)
984{
985 struct device_node *np;
986 unsigned int i;
987 struct platform_device *fs_enet_dev = NULL;
988 struct resource res;
989 int ret;
990
991 for (np = NULL, i = 0;
992 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
993 i++) {
994 struct resource r[4];
995 struct device_node *phy = NULL, *mdio = NULL;
996 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000997 const unsigned int *id;
998 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +1000999 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001000 const phandle *ph;
1001 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001002
1003 memset(r, 0, sizeof(r));
1004 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1005
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001006 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001007 if (model == NULL) {
1008 ret = -ENODEV;
1009 goto unreg;
1010 }
1011
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001012 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001013 fs_enet_data.fs_no = *id;
1014
1015 if (platform_device_skip(model, *id))
1016 continue;
1017
1018 ret = of_address_to_resource(np, 0, &r[0]);
1019 if (ret)
1020 goto err;
1021 r[0].name = enet_regs;
1022
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001023 mac_addr = of_get_mac_address(np);
1024 if (mac_addr)
1025 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001026
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001027 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001028 if (ph != NULL)
1029 phy = of_find_node_by_phandle(*ph);
1030
1031 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001032 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001033 fs_enet_data.phy_addr = *phy_addr;
1034 fs_enet_data.has_phy = 1;
1035
1036 mdio = of_get_parent(phy);
1037 ret = of_address_to_resource(mdio, 0, &res);
1038 if (ret) {
1039 of_node_put(phy);
1040 of_node_put(mdio);
1041 goto unreg;
1042 }
1043 }
1044
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001045 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001046 strcpy(fs_enet_data.fs_type, model);
1047
1048 if (strstr(model, "FEC")) {
1049 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1050 r[1].flags = IORESOURCE_IRQ;
1051 r[1].name = enet_irq;
1052
1053 fs_enet_dev =
1054 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1055
1056 if (IS_ERR(fs_enet_dev)) {
1057 ret = PTR_ERR(fs_enet_dev);
1058 goto err;
1059 }
1060
1061 fs_enet_data.rx_ring = 128;
1062 fs_enet_data.tx_ring = 16;
1063 fs_enet_data.rx_copybreak = 240;
1064 fs_enet_data.use_napi = 1;
1065 fs_enet_data.napi_weight = 17;
1066
1067 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1068 (u32)res.start, fs_enet_data.phy_addr);
1069 fs_enet_data.bus_id = (char*)&bus_id[i];
1070 fs_enet_data.init_ioports = init_fec_ioports;
1071 }
1072 if (strstr(model, "SCC")) {
1073 ret = of_address_to_resource(np, 1, &r[1]);
1074 if (ret)
1075 goto err;
1076 r[1].name = enet_pram;
1077
1078 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1079 r[2].flags = IORESOURCE_IRQ;
1080 r[2].name = enet_irq;
1081
1082 fs_enet_dev =
1083 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1084
1085 if (IS_ERR(fs_enet_dev)) {
1086 ret = PTR_ERR(fs_enet_dev);
1087 goto err;
1088 }
1089
1090 fs_enet_data.rx_ring = 64;
1091 fs_enet_data.tx_ring = 8;
1092 fs_enet_data.rx_copybreak = 240;
1093 fs_enet_data.use_napi = 1;
1094 fs_enet_data.napi_weight = 17;
1095
1096 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1097 fs_enet_data.bus_id = (char*)&bus_id[i];
1098 fs_enet_data.init_ioports = init_scc_ioports;
1099 }
1100
1101 of_node_put(phy);
1102 of_node_put(mdio);
1103
1104 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1105 sizeof(struct
1106 fs_platform_info));
1107 if (ret)
1108 goto unreg;
1109 }
1110 return 0;
1111
1112unreg:
1113 platform_device_unregister(fs_enet_dev);
1114err:
1115 return ret;
1116}
1117
1118arch_initcall(fs_enet_of_init);
1119
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001120static int __init fsl_pcmcia_of_init(void)
1121{
1122 struct device_node *np = NULL;
1123 /*
1124 * Register all the devices which type is "pcmcia"
1125 */
1126 while ((np = of_find_compatible_node(np,
1127 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1128 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1129 return 0;
1130}
1131
1132arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001133
1134static const char *smc_regs = "regs";
1135static const char *smc_pram = "pram";
1136
1137static int __init cpm_smc_uart_of_init(void)
1138{
1139 struct device_node *np;
1140 unsigned int i;
1141 struct platform_device *cpm_uart_dev;
1142 int ret;
1143
1144 for (np = NULL, i = 0;
1145 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1146 i++) {
1147 struct resource r[3];
1148 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001149 const int *id;
1150 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001151
1152 memset(r, 0, sizeof(r));
1153 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1154
1155 ret = of_address_to_resource(np, 0, &r[0]);
1156 if (ret)
1157 goto err;
1158
1159 r[0].name = smc_regs;
1160
1161 ret = of_address_to_resource(np, 1, &r[1]);
1162 if (ret)
1163 goto err;
1164 r[1].name = smc_pram;
1165
1166 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1167 r[2].flags = IORESOURCE_IRQ;
1168
1169 cpm_uart_dev =
1170 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1171
1172 if (IS_ERR(cpm_uart_dev)) {
1173 ret = PTR_ERR(cpm_uart_dev);
1174 goto err;
1175 }
1176
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001177 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001178 strcpy(cpm_uart_data.fs_type, model);
1179
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001180 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001181 cpm_uart_data.fs_no = *id;
1182 cpm_uart_data.uart_clk = ppc_proc_freq;
1183
1184 cpm_uart_data.tx_num_fifo = 4;
1185 cpm_uart_data.tx_buf_size = 32;
1186 cpm_uart_data.rx_num_fifo = 4;
1187 cpm_uart_data.rx_buf_size = 32;
1188
1189 ret =
1190 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1191 sizeof(struct
1192 fs_uart_platform_info));
1193 if (ret)
1194 goto unreg;
1195 }
1196
1197 return 0;
1198
1199unreg:
1200 platform_device_unregister(cpm_uart_dev);
1201err:
1202 return ret;
1203}
1204
1205arch_initcall(cpm_smc_uart_of_init);
1206
1207#endif /* CONFIG_8xx */
Scott Woode631ae32007-09-14 13:04:54 -05001208#endif /* CONFIG_PPC_CPM_NEW_BINDING */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001209
1210int __init fsl_spi_init(struct spi_board_info *board_infos,
1211 unsigned int num_board_infos,
1212 void (*activate_cs)(u8 cs, u8 polarity),
1213 void (*deactivate_cs)(u8 cs, u8 polarity))
1214{
1215 struct device_node *np;
1216 unsigned int i;
1217 const u32 *sysclk;
1218
1219 np = of_find_node_by_type(NULL, "qe");
1220 if (!np)
1221 return -ENODEV;
1222
1223 sysclk = of_get_property(np, "bus-frequency", NULL);
1224 if (!sysclk)
1225 return -ENODEV;
1226
1227 for (np = NULL, i = 1;
1228 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1229 i++) {
1230 int ret = 0;
1231 unsigned int j;
1232 const void *prop;
1233 struct resource res[2];
1234 struct platform_device *pdev;
1235 struct fsl_spi_platform_data pdata = {
1236 .activate_cs = activate_cs,
1237 .deactivate_cs = deactivate_cs,
1238 };
1239
1240 memset(res, 0, sizeof(res));
1241
1242 pdata.sysclk = *sysclk;
1243
1244 prop = of_get_property(np, "reg", NULL);
1245 if (!prop)
1246 goto err;
1247 pdata.bus_num = *(u32 *)prop;
1248
1249 prop = of_get_property(np, "mode", NULL);
1250 if (prop && !strcmp(prop, "cpu-qe"))
1251 pdata.qe_mode = 1;
1252
1253 for (j = 0; j < num_board_infos; j++) {
1254 if (board_infos[j].bus_num == pdata.bus_num)
1255 pdata.max_chipselect++;
1256 }
1257
1258 if (!pdata.max_chipselect)
1259 goto err;
1260
1261 ret = of_address_to_resource(np, 0, &res[0]);
1262 if (ret)
1263 goto err;
1264
1265 ret = of_irq_to_resource(np, 0, &res[1]);
1266 if (ret == NO_IRQ)
1267 goto err;
1268
1269 pdev = platform_device_alloc("mpc83xx_spi", i);
1270 if (!pdev)
1271 goto err;
1272
1273 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1274 if (ret)
1275 goto unreg;
1276
1277 ret = platform_device_add_resources(pdev, res,
1278 ARRAY_SIZE(res));
1279 if (ret)
1280 goto unreg;
1281
1282 ret = platform_device_register(pdev);
1283 if (ret)
1284 goto unreg;
1285
1286 continue;
1287unreg:
1288 platform_device_del(pdev);
1289err:
1290 continue;
1291 }
1292
1293 return spi_register_board_info(board_infos, num_board_infos);
1294}