blob: d028e8da027b1e479e6b6c151befb63499ff8aa9 [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;
76
77 if (brgfreq != -1)
78 return brgfreq;
79
Scott Woodf9234732007-08-20 11:38:12 -050080 node = of_find_compatible_node(NULL, NULL, "fsl,cpm1");
81 if (!node)
82 node = of_find_compatible_node(NULL, NULL, "fsl,cpm2");
83 if (!node)
84 node = of_find_node_by_type(NULL, "cpm");
Vitaly Bordugfba43662006-09-21 17:26:34 +040085 if (node) {
Scott Woodf9234732007-08-20 11:38:12 -050086 int size;
87 const unsigned int *prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +040088
Scott Woodf9234732007-08-20 11:38:12 -050089 prop = of_get_property(node, "fsl,brg-frequency", &size);
90 if (!prop)
91 prop = of_get_property(node, "brg-frequency", &size);
92 if (prop && size == 4)
Vitaly Bordugfba43662006-09-21 17:26:34 +040093 brgfreq = *prop;
Scott Woodf9234732007-08-20 11:38:12 -050094
Vitaly Bordugfba43662006-09-21 17:26:34 +040095 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -050096 }
Vitaly Bordugfba43662006-09-21 17:26:34 +040097
98 return brgfreq;
99}
100
101EXPORT_SYMBOL(get_brgfreq);
102
103static u32 fs_baudrate = -1;
104
105u32 get_baudrate(void)
106{
107 struct device_node *node;
108
109 if (fs_baudrate != -1)
110 return fs_baudrate;
111
112 node = of_find_node_by_type(NULL, "serial");
113 if (node) {
Scott Woodf9234732007-08-20 11:38:12 -0500114 int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000115 const unsigned int *prop = of_get_property(node,
116 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400117
118 if (prop)
119 fs_baudrate = *prop;
120 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500121 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400122
123 return fs_baudrate;
124}
125
126EXPORT_SYMBOL(get_baudrate);
127#endif /* CONFIG_CPM2 */
128
Kumar Gala2fb07d72006-01-23 16:58:04 -0600129static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600130{
131 struct device_node *np;
132 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600133 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600134 struct resource res;
135 int ret;
136
Kumar Gala2fb07d72006-01-23 16:58:04 -0600137 for (np = NULL, i = 0;
138 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
139 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600140 int k;
141 struct device_node *child = NULL;
142 struct gianfar_mdio_data mdio_data;
143
144 memset(&res, 0, sizeof(res));
145 memset(&mdio_data, 0, sizeof(mdio_data));
146
147 ret = of_address_to_resource(np, 0, &res);
148 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600149 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600150
Kumar Gala2fb07d72006-01-23 16:58:04 -0600151 mdio_dev =
152 platform_device_register_simple("fsl-gianfar_mdio",
153 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600154 if (IS_ERR(mdio_dev)) {
155 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600156 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600157 }
158
159 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500160 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600161
162 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400163 int irq = irq_of_parse_and_map(child, 0);
164 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000165 const u32 *id = of_get_property(child,
166 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400167 mdio_data.irq[*id] = irq;
168 }
Kumar Galaeed32002006-01-13 11:19:13 -0600169 }
170
Kumar Gala2fb07d72006-01-23 16:58:04 -0600171 ret =
172 platform_device_add_data(mdio_dev, &mdio_data,
173 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600174 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600175 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600176 }
177
Kumar Gala2fb07d72006-01-23 16:58:04 -0600178 return 0;
179
180unreg:
181 platform_device_unregister(mdio_dev);
182err:
183 return ret;
184}
185
186arch_initcall(gfar_mdio_of_init);
187
188static const char *gfar_tx_intr = "tx";
189static const char *gfar_rx_intr = "rx";
190static const char *gfar_err_intr = "error";
191
Andy Fleminga9b14972006-10-19 19:52:26 -0500192
Kumar Gala2fb07d72006-01-23 16:58:04 -0600193static int __init gfar_of_init(void)
194{
195 struct device_node *np;
196 unsigned int i;
197 struct platform_device *gfar_dev;
198 struct resource res;
199 int ret;
200
201 for (np = NULL, i = 0;
202 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
203 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600204 struct resource r[4];
205 struct device_node *phy, *mdio;
206 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000207 const unsigned int *id;
208 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500209 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000210 const void *mac_addr;
211 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400212 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600213
214 memset(r, 0, sizeof(r));
215 memset(&gfar_data, 0, sizeof(gfar_data));
216
217 ret = of_address_to_resource(np, 0, &r[0]);
218 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600219 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600220
Andy Fleminga9b14972006-10-19 19:52:26 -0500221 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600222
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000223 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600224
225 /* If we aren't the FEC we have multiple interrupts */
226 if (model && strcasecmp(model, "FEC")) {
227 r[1].name = gfar_tx_intr;
228
229 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500230 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600231
232 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500233 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500234
235 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600236 }
237
Kumar Gala2fb07d72006-01-23 16:58:04 -0600238 gfar_dev =
239 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400240 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600241
242 if (IS_ERR(gfar_dev)) {
243 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600244 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600245 }
246
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600247 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500248 if (mac_addr)
249 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600250
251 if (model && !strcasecmp(model, "TSEC"))
252 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600253 FSL_GIANFAR_DEV_HAS_GIGABIT |
254 FSL_GIANFAR_DEV_HAS_COALESCE |
255 FSL_GIANFAR_DEV_HAS_RMON |
256 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600257 if (model && !strcasecmp(model, "eTSEC"))
258 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600259 FSL_GIANFAR_DEV_HAS_GIGABIT |
260 FSL_GIANFAR_DEV_HAS_COALESCE |
261 FSL_GIANFAR_DEV_HAS_RMON |
262 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
263 FSL_GIANFAR_DEV_HAS_CSUM |
264 FSL_GIANFAR_DEV_HAS_VLAN |
265 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600266
Andy Fleming7132ab72007-07-11 11:43:07 -0500267 ctype = of_get_property(np, "phy-connection-type", NULL);
268
269 /* We only care about rgmii-id. The rest are autodetected */
270 if (ctype && !strcmp(ctype, "rgmii-id"))
271 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
272 else
273 gfar_data.interface = PHY_INTERFACE_MODE_MII;
274
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000275 ph = of_get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600276 phy = of_find_node_by_phandle(*ph);
277
278 if (phy == NULL) {
279 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600280 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600281 }
282
283 mdio = of_get_parent(phy);
284
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000285 id = of_get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600286 ret = of_address_to_resource(mdio, 0, &res);
287 if (ret) {
288 of_node_put(phy);
289 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600290 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600291 }
292
293 gfar_data.phy_id = *id;
294 gfar_data.bus_id = res.start;
295
296 of_node_put(phy);
297 of_node_put(mdio);
298
Kumar Gala2fb07d72006-01-23 16:58:04 -0600299 ret =
300 platform_device_add_data(gfar_dev, &gfar_data,
301 sizeof(struct
302 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600303 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600304 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600305 }
306
307 return 0;
308
Kumar Gala2fb07d72006-01-23 16:58:04 -0600309unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600310 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600311err:
Kumar Galaeed32002006-01-13 11:19:13 -0600312 return ret;
313}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600314
Kumar Galaeed32002006-01-13 11:19:13 -0600315arch_initcall(gfar_of_init);
316
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000317#ifdef CONFIG_I2C_BOARDINFO
318#include <linux/i2c.h>
319struct i2c_driver_device {
320 char *of_device;
321 char *i2c_driver;
322 char *i2c_type;
323};
324
325static struct i2c_driver_device i2c_devices[] __initdata = {
326 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
327 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
328 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
329 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
330};
331
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000332static int __init of_find_i2c_driver(struct device_node *node,
333 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000334{
335 int i;
336
337 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
338 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
339 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000340 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
341 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
342 strlcpy(info->type, i2c_devices[i].i2c_type,
343 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
344 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000345 return 0;
346 }
347 return -ENODEV;
348}
349
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000350static void __init of_register_i2c_devices(struct device_node *adap_node,
351 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000352{
353 struct device_node *node = NULL;
354
355 while ((node = of_get_next_child(adap_node, node))) {
356 struct i2c_board_info info;
357 const u32 *addr;
358 int len;
359
360 addr = of_get_property(node, "reg", &len);
361 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
362 printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n");
363 continue;
364 }
365
366 info.irq = irq_of_parse_and_map(node, 0);
367 if (info.irq == NO_IRQ)
368 info.irq = -1;
369
370 if (of_find_i2c_driver(node, &info) < 0)
371 continue;
372
373 info.platform_data = NULL;
374 info.addr = *addr;
375
376 i2c_register_board_info(bus_num, &info, 1);
377 }
378}
379
Kumar Galaeed32002006-01-13 11:19:13 -0600380static int __init fsl_i2c_of_init(void)
381{
382 struct device_node *np;
383 unsigned int i;
384 struct platform_device *i2c_dev;
385 int ret;
386
Kumar Gala2fb07d72006-01-23 16:58:04 -0600387 for (np = NULL, i = 0;
388 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
389 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600390 struct resource r[2];
391 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000392 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600393
394 memset(&r, 0, sizeof(r));
395 memset(&i2c_data, 0, sizeof(i2c_data));
396
397 ret = of_address_to_resource(np, 0, &r[0]);
398 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600399 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600400
Andy Fleminga9b14972006-10-19 19:52:26 -0500401 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600402
403 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
404 if (IS_ERR(i2c_dev)) {
405 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600406 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600407 }
408
409 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000410 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600411 if (flags)
412 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
413
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000414 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600415 if (flags)
416 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
417
Kumar Gala2fb07d72006-01-23 16:58:04 -0600418 ret =
419 platform_device_add_data(i2c_dev, &i2c_data,
420 sizeof(struct
421 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600422 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600423 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000424
425 of_register_i2c_devices(np, i);
Kumar Galaeed32002006-01-13 11:19:13 -0600426 }
427
428 return 0;
429
Kumar Gala2fb07d72006-01-23 16:58:04 -0600430unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600431 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600432err:
Kumar Galaeed32002006-01-13 11:19:13 -0600433 return ret;
434}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600435
Kumar Galaeed32002006-01-13 11:19:13 -0600436arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000437#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600438
439#ifdef CONFIG_PPC_83xx
440static int __init mpc83xx_wdt_init(void)
441{
442 struct resource r;
443 struct device_node *soc, *np;
444 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000445 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600446 int ret;
447
448 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
449
450 if (!np) {
451 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600452 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600453 }
454
455 soc = of_find_node_by_type(NULL, "soc");
456
457 if (!soc) {
458 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600459 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600460 }
461
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000462 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600463 if (!freq) {
464 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600465 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600466 }
467
468 memset(&r, 0, sizeof(r));
469
470 ret = of_address_to_resource(np, 0, &r);
471 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600472 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600473
474 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
475 if (IS_ERR(dev)) {
476 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600477 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600478 }
479
480 ret = platform_device_add_data(dev, freq, sizeof(int));
481 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600482 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600483
484 of_node_put(soc);
485 of_node_put(np);
486
487 return 0;
488
Kumar Gala2fb07d72006-01-23 16:58:04 -0600489unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600490 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600491err:
Kumar Galaeed32002006-01-13 11:19:13 -0600492 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600493nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600494 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600495nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600496 return ret;
497}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600498
Kumar Galaeed32002006-01-13 11:19:13 -0600499arch_initcall(mpc83xx_wdt_init);
500#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600501
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000502static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600503{
504 if (!phy_type)
505 return FSL_USB2_PHY_NONE;
506 if (!strcasecmp(phy_type, "ulpi"))
507 return FSL_USB2_PHY_ULPI;
508 if (!strcasecmp(phy_type, "utmi"))
509 return FSL_USB2_PHY_UTMI;
510 if (!strcasecmp(phy_type, "utmi_wide"))
511 return FSL_USB2_PHY_UTMI_WIDE;
512 if (!strcasecmp(phy_type, "serial"))
513 return FSL_USB2_PHY_SERIAL;
514
515 return FSL_USB2_PHY_NONE;
516}
517
518static int __init fsl_usb_of_init(void)
519{
520 struct device_node *np;
521 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800522 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
523 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600524 int ret;
525
526 for (np = NULL, i = 0;
527 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
528 i++) {
529 struct resource r[2];
530 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000531 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600532
533 memset(&r, 0, sizeof(r));
534 memset(&usb_data, 0, sizeof(usb_data));
535
536 ret = of_address_to_resource(np, 0, &r[0]);
537 if (ret)
538 goto err;
539
Andy Fleminga9b14972006-10-19 19:52:26 -0500540 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600541
Kumar Gala01cced22006-04-11 10:07:16 -0500542 usb_dev_mph =
543 platform_device_register_simple("fsl-ehci", i, r, 2);
544 if (IS_ERR(usb_dev_mph)) {
545 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600546 goto err;
547 }
548
Kumar Gala01cced22006-04-11 10:07:16 -0500549 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
550 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600551
552 usb_data.operating_mode = FSL_USB2_MPH_HOST;
553
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000554 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600555 if (prop)
556 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
557
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000558 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600559 if (prop)
560 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
561
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000562 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600563 usb_data.phy_mode = determine_usb_phy(prop);
564
565 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500566 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600567 sizeof(struct
568 fsl_usb2_platform_data));
569 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500570 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600571 }
572
Kumar Gala01cced22006-04-11 10:07:16 -0500573 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600574 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
575 i++) {
576 struct resource r[2];
577 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000578 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600579
580 memset(&r, 0, sizeof(r));
581 memset(&usb_data, 0, sizeof(usb_data));
582
583 ret = of_address_to_resource(np, 0, &r[0]);
584 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500585 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600586
Andy Fleminga9b14972006-10-19 19:52:26 -0500587 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600588
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000589 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800590
591 if (!prop || !strcmp(prop, "host")) {
592 usb_data.operating_mode = FSL_USB2_DR_HOST;
593 usb_dev_dr_host = platform_device_register_simple(
594 "fsl-ehci", i, r, 2);
595 if (IS_ERR(usb_dev_dr_host)) {
596 ret = PTR_ERR(usb_dev_dr_host);
597 goto err;
598 }
599 } else if (prop && !strcmp(prop, "peripheral")) {
600 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
601 usb_dev_dr_client = platform_device_register_simple(
602 "fsl-usb2-udc", i, r, 2);
603 if (IS_ERR(usb_dev_dr_client)) {
604 ret = PTR_ERR(usb_dev_dr_client);
605 goto err;
606 }
607 } else if (prop && !strcmp(prop, "otg")) {
608 usb_data.operating_mode = FSL_USB2_DR_OTG;
609 usb_dev_dr_host = platform_device_register_simple(
610 "fsl-ehci", i, r, 2);
611 if (IS_ERR(usb_dev_dr_host)) {
612 ret = PTR_ERR(usb_dev_dr_host);
613 goto err;
614 }
615 usb_dev_dr_client = platform_device_register_simple(
616 "fsl-usb2-udc", i, r, 2);
617 if (IS_ERR(usb_dev_dr_client)) {
618 ret = PTR_ERR(usb_dev_dr_client);
619 goto err;
620 }
621 } else {
622 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600623 goto err;
624 }
625
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000626 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600627 usb_data.phy_mode = determine_usb_phy(prop);
628
Li Yang97c5a202007-02-07 13:49:24 +0800629 if (usb_dev_dr_host) {
630 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
631 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
632 dev.coherent_dma_mask;
633 if ((ret = platform_device_add_data(usb_dev_dr_host,
634 &usb_data, sizeof(struct
635 fsl_usb2_platform_data))))
636 goto unreg_dr;
637 }
638 if (usb_dev_dr_client) {
639 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
640 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
641 dev.coherent_dma_mask;
642 if ((ret = platform_device_add_data(usb_dev_dr_client,
643 &usb_data, sizeof(struct
644 fsl_usb2_platform_data))))
645 goto unreg_dr;
646 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600647 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600648 return 0;
649
Kumar Gala01cced22006-04-11 10:07:16 -0500650unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800651 if (usb_dev_dr_host)
652 platform_device_unregister(usb_dev_dr_host);
653 if (usb_dev_dr_client)
654 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500655unreg_mph:
656 if (usb_dev_mph)
657 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600658err:
659 return ret;
660}
661
Kumar Gala01cced22006-04-11 10:07:16 -0500662arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400663
664#ifdef CONFIG_CPM2
665
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300666extern void init_scc_ioports(struct fs_uart_platform_info*);
667
Vitaly Bordugfba43662006-09-21 17:26:34 +0400668static const char fcc_regs[] = "fcc_regs";
669static const char fcc_regs_c[] = "fcc_regs_c";
670static const char fcc_pram[] = "fcc_pram";
671static char bus_id[9][BUS_ID_SIZE];
672
673static int __init fs_enet_of_init(void)
674{
675 struct device_node *np;
676 unsigned int i;
677 struct platform_device *fs_enet_dev;
678 struct resource res;
679 int ret;
680
681 for (np = NULL, i = 0;
682 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
683 i++) {
684 struct resource r[4];
685 struct device_node *phy, *mdio;
686 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500687 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400688 const void *mac_addr;
689 const phandle *ph;
690 const char *model;
691
692 memset(r, 0, sizeof(r));
693 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
694
695 ret = of_address_to_resource(np, 0, &r[0]);
696 if (ret)
697 goto err;
698 r[0].name = fcc_regs;
699
700 ret = of_address_to_resource(np, 1, &r[1]);
701 if (ret)
702 goto err;
703 r[1].name = fcc_pram;
704
705 ret = of_address_to_resource(np, 2, &r[2]);
706 if (ret)
707 goto err;
708 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400709 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400710
Andy Fleminga9b14972006-10-19 19:52:26 -0500711 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400712
713 fs_enet_dev =
714 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
715
716 if (IS_ERR(fs_enet_dev)) {
717 ret = PTR_ERR(fs_enet_dev);
718 goto err;
719 }
720
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000721 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400722 if (model == NULL) {
723 ret = -ENODEV;
724 goto unreg;
725 }
726
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600727 mac_addr = of_get_mac_address(np);
728 if (mac_addr)
729 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400730
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000731 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400732 phy = of_find_node_by_phandle(*ph);
733
734 if (phy == NULL) {
735 ret = -ENODEV;
736 goto unreg;
737 }
738
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000739 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400740 fs_enet_data.phy_addr = *phy_addr;
741
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000742 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400743
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000744 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400745 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400746 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400747
748 mdio = of_get_parent(phy);
749 ret = of_address_to_resource(mdio, 0, &res);
750 if (ret) {
751 of_node_put(phy);
752 of_node_put(mdio);
753 goto unreg;
754 }
755
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000756 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
757 "rx-clock", NULL));
758 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
759 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400760
Vitaly Bordugfba43662006-09-21 17:26:34 +0400761 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400762 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500763 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400764
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400765 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400766 fs_enet_data.rx_ring = 32;
767 fs_enet_data.tx_ring = 32;
768 fs_enet_data.rx_copybreak = 240;
769 fs_enet_data.use_napi = 0;
770 fs_enet_data.napi_weight = 17;
771 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
772 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
773 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
774
775 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
776 (u32)res.start, fs_enet_data.phy_addr);
777 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400778 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400779
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000780 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400781 if (mdio_bb_prop) {
782 struct platform_device *fs_enet_mdio_bb_dev;
783 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400784
Vitaly Borduged943c12006-10-02 22:41:50 +0400785 fs_enet_mdio_bb_dev =
786 platform_device_register_simple("fsl-bb-mdio",
787 i, NULL, 0);
788 memset(&fs_enet_mdio_bb_data, 0,
789 sizeof(struct fs_mii_bb_platform_info));
790 fs_enet_mdio_bb_data.mdio_dat.bit =
791 mdio_bb_prop[0];
792 fs_enet_mdio_bb_data.mdio_dir.bit =
793 mdio_bb_prop[1];
794 fs_enet_mdio_bb_data.mdc_dat.bit =
795 mdio_bb_prop[2];
796 fs_enet_mdio_bb_data.mdio_port =
797 mdio_bb_prop[3];
798 fs_enet_mdio_bb_data.mdc_port =
799 mdio_bb_prop[4];
800 fs_enet_mdio_bb_data.delay =
801 mdio_bb_prop[5];
802
803 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
804 fs_enet_mdio_bb_data.irq[1] = -1;
805 fs_enet_mdio_bb_data.irq[2] = -1;
806 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
807 fs_enet_mdio_bb_data.irq[31] = -1;
808
809 fs_enet_mdio_bb_data.mdio_dat.offset =
810 (u32)&cpm2_immr->im_ioport.iop_pdatc;
811 fs_enet_mdio_bb_data.mdio_dir.offset =
812 (u32)&cpm2_immr->im_ioport.iop_pdirc;
813 fs_enet_mdio_bb_data.mdc_dat.offset =
814 (u32)&cpm2_immr->im_ioport.iop_pdatc;
815
816 ret = platform_device_add_data(
817 fs_enet_mdio_bb_dev,
818 &fs_enet_mdio_bb_data,
819 sizeof(struct fs_mii_bb_platform_info));
820 if (ret)
821 goto unreg;
822 }
Li Yang97c5a202007-02-07 13:49:24 +0800823
Vitaly Borduged943c12006-10-02 22:41:50 +0400824 of_node_put(phy);
825 of_node_put(mdio);
826
827 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
828 sizeof(struct
829 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500830 if (ret)
831 goto unreg;
832 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400833 }
834 return 0;
835
836unreg:
837 platform_device_unregister(fs_enet_dev);
838err:
839 return ret;
840}
841
842arch_initcall(fs_enet_of_init);
843
844static const char scc_regs[] = "regs";
845static const char scc_pram[] = "pram";
846
847static int __init cpm_uart_of_init(void)
848{
849 struct device_node *np;
850 unsigned int i;
851 struct platform_device *cpm_uart_dev;
852 int ret;
853
854 for (np = NULL, i = 0;
855 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
856 i++) {
857 struct resource r[3];
858 struct fs_uart_platform_info cpm_uart_data;
859 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400860 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400861
862 memset(r, 0, sizeof(r));
863 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
864
865 ret = of_address_to_resource(np, 0, &r[0]);
866 if (ret)
867 goto err;
868
869 r[0].name = scc_regs;
870
871 ret = of_address_to_resource(np, 1, &r[1]);
872 if (ret)
873 goto err;
874 r[1].name = scc_pram;
875
Andy Fleminga9b14972006-10-19 19:52:26 -0500876 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400877
878 cpm_uart_dev =
879 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
880
881 if (IS_ERR(cpm_uart_dev)) {
882 ret = PTR_ERR(cpm_uart_dev);
883 goto err;
884 }
885
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000886 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400887 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400888
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000889 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400890 strcpy(cpm_uart_data.fs_type, model);
891
Vitaly Bordugfba43662006-09-21 17:26:34 +0400892 cpm_uart_data.uart_clk = ppc_proc_freq;
893
894 cpm_uart_data.tx_num_fifo = 4;
895 cpm_uart_data.tx_buf_size = 32;
896 cpm_uart_data.rx_num_fifo = 4;
897 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000898 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
899 "rx-clock", NULL));
900 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
901 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400902
903 ret =
904 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
905 sizeof(struct
906 fs_uart_platform_info));
907 if (ret)
908 goto unreg;
909 }
910
911 return 0;
912
913unreg:
914 platform_device_unregister(cpm_uart_dev);
915err:
916 return ret;
917}
918
919arch_initcall(cpm_uart_of_init);
920#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300921
922#ifdef CONFIG_8xx
923
924extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000925extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300926
927static int __init fs_enet_mdio_of_init(void)
928{
929 struct device_node *np;
930 unsigned int i;
931 struct platform_device *mdio_dev;
932 struct resource res;
933 int ret;
934
935 for (np = NULL, i = 0;
936 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
937 i++) {
938 struct fs_mii_fec_platform_info mdio_data;
939
940 memset(&res, 0, sizeof(res));
941 memset(&mdio_data, 0, sizeof(mdio_data));
942
943 ret = of_address_to_resource(np, 0, &res);
944 if (ret)
945 goto err;
946
947 mdio_dev =
948 platform_device_register_simple("fsl-cpm-fec-mdio",
949 res.start, &res, 1);
950 if (IS_ERR(mdio_dev)) {
951 ret = PTR_ERR(mdio_dev);
952 goto err;
953 }
954
955 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
956
957 ret =
958 platform_device_add_data(mdio_dev, &mdio_data,
959 sizeof(struct fs_mii_fec_platform_info));
960 if (ret)
961 goto unreg;
962 }
963 return 0;
964
965unreg:
966 platform_device_unregister(mdio_dev);
967err:
968 return ret;
969}
970
971arch_initcall(fs_enet_mdio_of_init);
972
973static const char *enet_regs = "regs";
974static const char *enet_pram = "pram";
975static const char *enet_irq = "interrupt";
976static char bus_id[9][BUS_ID_SIZE];
977
978static int __init fs_enet_of_init(void)
979{
980 struct device_node *np;
981 unsigned int i;
982 struct platform_device *fs_enet_dev = NULL;
983 struct resource res;
984 int ret;
985
986 for (np = NULL, i = 0;
987 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
988 i++) {
989 struct resource r[4];
990 struct device_node *phy = NULL, *mdio = NULL;
991 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000992 const unsigned int *id;
993 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +1000994 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000995 const phandle *ph;
996 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300997
998 memset(r, 0, sizeof(r));
999 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1000
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001001 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001002 if (model == NULL) {
1003 ret = -ENODEV;
1004 goto unreg;
1005 }
1006
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001007 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001008 fs_enet_data.fs_no = *id;
1009
1010 if (platform_device_skip(model, *id))
1011 continue;
1012
1013 ret = of_address_to_resource(np, 0, &r[0]);
1014 if (ret)
1015 goto err;
1016 r[0].name = enet_regs;
1017
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001018 mac_addr = of_get_mac_address(np);
1019 if (mac_addr)
1020 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001021
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001022 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001023 if (ph != NULL)
1024 phy = of_find_node_by_phandle(*ph);
1025
1026 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001027 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001028 fs_enet_data.phy_addr = *phy_addr;
1029 fs_enet_data.has_phy = 1;
1030
1031 mdio = of_get_parent(phy);
1032 ret = of_address_to_resource(mdio, 0, &res);
1033 if (ret) {
1034 of_node_put(phy);
1035 of_node_put(mdio);
1036 goto unreg;
1037 }
1038 }
1039
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001040 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001041 strcpy(fs_enet_data.fs_type, model);
1042
1043 if (strstr(model, "FEC")) {
1044 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1045 r[1].flags = IORESOURCE_IRQ;
1046 r[1].name = enet_irq;
1047
1048 fs_enet_dev =
1049 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1050
1051 if (IS_ERR(fs_enet_dev)) {
1052 ret = PTR_ERR(fs_enet_dev);
1053 goto err;
1054 }
1055
1056 fs_enet_data.rx_ring = 128;
1057 fs_enet_data.tx_ring = 16;
1058 fs_enet_data.rx_copybreak = 240;
1059 fs_enet_data.use_napi = 1;
1060 fs_enet_data.napi_weight = 17;
1061
1062 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1063 (u32)res.start, fs_enet_data.phy_addr);
1064 fs_enet_data.bus_id = (char*)&bus_id[i];
1065 fs_enet_data.init_ioports = init_fec_ioports;
1066 }
1067 if (strstr(model, "SCC")) {
1068 ret = of_address_to_resource(np, 1, &r[1]);
1069 if (ret)
1070 goto err;
1071 r[1].name = enet_pram;
1072
1073 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1074 r[2].flags = IORESOURCE_IRQ;
1075 r[2].name = enet_irq;
1076
1077 fs_enet_dev =
1078 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1079
1080 if (IS_ERR(fs_enet_dev)) {
1081 ret = PTR_ERR(fs_enet_dev);
1082 goto err;
1083 }
1084
1085 fs_enet_data.rx_ring = 64;
1086 fs_enet_data.tx_ring = 8;
1087 fs_enet_data.rx_copybreak = 240;
1088 fs_enet_data.use_napi = 1;
1089 fs_enet_data.napi_weight = 17;
1090
1091 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1092 fs_enet_data.bus_id = (char*)&bus_id[i];
1093 fs_enet_data.init_ioports = init_scc_ioports;
1094 }
1095
1096 of_node_put(phy);
1097 of_node_put(mdio);
1098
1099 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1100 sizeof(struct
1101 fs_platform_info));
1102 if (ret)
1103 goto unreg;
1104 }
1105 return 0;
1106
1107unreg:
1108 platform_device_unregister(fs_enet_dev);
1109err:
1110 return ret;
1111}
1112
1113arch_initcall(fs_enet_of_init);
1114
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001115static int __init fsl_pcmcia_of_init(void)
1116{
1117 struct device_node *np = NULL;
1118 /*
1119 * Register all the devices which type is "pcmcia"
1120 */
1121 while ((np = of_find_compatible_node(np,
1122 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1123 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1124 return 0;
1125}
1126
1127arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001128
1129static const char *smc_regs = "regs";
1130static const char *smc_pram = "pram";
1131
1132static int __init cpm_smc_uart_of_init(void)
1133{
1134 struct device_node *np;
1135 unsigned int i;
1136 struct platform_device *cpm_uart_dev;
1137 int ret;
1138
1139 for (np = NULL, i = 0;
1140 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1141 i++) {
1142 struct resource r[3];
1143 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001144 const int *id;
1145 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001146
1147 memset(r, 0, sizeof(r));
1148 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1149
1150 ret = of_address_to_resource(np, 0, &r[0]);
1151 if (ret)
1152 goto err;
1153
1154 r[0].name = smc_regs;
1155
1156 ret = of_address_to_resource(np, 1, &r[1]);
1157 if (ret)
1158 goto err;
1159 r[1].name = smc_pram;
1160
1161 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1162 r[2].flags = IORESOURCE_IRQ;
1163
1164 cpm_uart_dev =
1165 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1166
1167 if (IS_ERR(cpm_uart_dev)) {
1168 ret = PTR_ERR(cpm_uart_dev);
1169 goto err;
1170 }
1171
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001172 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001173 strcpy(cpm_uart_data.fs_type, model);
1174
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001175 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001176 cpm_uart_data.fs_no = *id;
1177 cpm_uart_data.uart_clk = ppc_proc_freq;
1178
1179 cpm_uart_data.tx_num_fifo = 4;
1180 cpm_uart_data.tx_buf_size = 32;
1181 cpm_uart_data.rx_num_fifo = 4;
1182 cpm_uart_data.rx_buf_size = 32;
1183
1184 ret =
1185 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1186 sizeof(struct
1187 fs_uart_platform_info));
1188 if (ret)
1189 goto unreg;
1190 }
1191
1192 return 0;
1193
1194unreg:
1195 platform_device_unregister(cpm_uart_dev);
1196err:
1197 return ret;
1198}
1199
1200arch_initcall(cpm_smc_uart_of_init);
1201
1202#endif /* CONFIG_8xx */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001203
1204int __init fsl_spi_init(struct spi_board_info *board_infos,
1205 unsigned int num_board_infos,
1206 void (*activate_cs)(u8 cs, u8 polarity),
1207 void (*deactivate_cs)(u8 cs, u8 polarity))
1208{
1209 struct device_node *np;
1210 unsigned int i;
1211 const u32 *sysclk;
1212
1213 np = of_find_node_by_type(NULL, "qe");
1214 if (!np)
1215 return -ENODEV;
1216
1217 sysclk = of_get_property(np, "bus-frequency", NULL);
1218 if (!sysclk)
1219 return -ENODEV;
1220
1221 for (np = NULL, i = 1;
1222 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1223 i++) {
1224 int ret = 0;
1225 unsigned int j;
1226 const void *prop;
1227 struct resource res[2];
1228 struct platform_device *pdev;
1229 struct fsl_spi_platform_data pdata = {
1230 .activate_cs = activate_cs,
1231 .deactivate_cs = deactivate_cs,
1232 };
1233
1234 memset(res, 0, sizeof(res));
1235
1236 pdata.sysclk = *sysclk;
1237
1238 prop = of_get_property(np, "reg", NULL);
1239 if (!prop)
1240 goto err;
1241 pdata.bus_num = *(u32 *)prop;
1242
1243 prop = of_get_property(np, "mode", NULL);
1244 if (prop && !strcmp(prop, "cpu-qe"))
1245 pdata.qe_mode = 1;
1246
1247 for (j = 0; j < num_board_infos; j++) {
1248 if (board_infos[j].bus_num == pdata.bus_num)
1249 pdata.max_chipselect++;
1250 }
1251
1252 if (!pdata.max_chipselect)
1253 goto err;
1254
1255 ret = of_address_to_resource(np, 0, &res[0]);
1256 if (ret)
1257 goto err;
1258
1259 ret = of_irq_to_resource(np, 0, &res[1]);
1260 if (ret == NO_IRQ)
1261 goto err;
1262
1263 pdev = platform_device_alloc("mpc83xx_spi", i);
1264 if (!pdev)
1265 goto err;
1266
1267 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1268 if (ret)
1269 goto unreg;
1270
1271 ret = platform_device_add_resources(pdev, res,
1272 ARRAY_SIZE(res));
1273 if (ret)
1274 goto unreg;
1275
1276 ret = platform_device_register(pdev);
1277 if (ret)
1278 goto unreg;
1279
1280 continue;
1281unreg:
1282 platform_device_del(pdev);
1283err:
1284 continue;
1285 }
1286
1287 return spi_register_board_info(board_infos, num_board_infos);
1288}