blob: 91987e000d25b1d0cfee209d929436a00ec788db [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",},
Peter Korsgaard0438c282007-09-20 12:42:13 +0200334 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
335 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
336 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
337 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
338 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
339 {"stm,m41t00", "rtc-ds1307", "m41t00"},
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000340};
341
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000342static int __init of_find_i2c_driver(struct device_node *node,
343 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000344{
345 int i;
346
347 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
348 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
349 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000350 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
351 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
352 strlcpy(info->type, i2c_devices[i].i2c_type,
353 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
354 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000355 return 0;
356 }
357 return -ENODEV;
358}
359
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000360static void __init of_register_i2c_devices(struct device_node *adap_node,
361 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000362{
363 struct device_node *node = NULL;
364
365 while ((node = of_get_next_child(adap_node, node))) {
Anton Vorontsovda1bb3a2007-10-02 17:47:40 +0400366 struct i2c_board_info info = {};
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000367 const u32 *addr;
368 int len;
369
370 addr = of_get_property(node, "reg", &len);
371 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
Peter Korsgaard210805e2007-09-20 12:42:12 +0200372 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000373 continue;
374 }
375
376 info.irq = irq_of_parse_and_map(node, 0);
377 if (info.irq == NO_IRQ)
378 info.irq = -1;
379
380 if (of_find_i2c_driver(node, &info) < 0)
381 continue;
382
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000383 info.addr = *addr;
384
385 i2c_register_board_info(bus_num, &info, 1);
386 }
387}
388
Kumar Galaeed32002006-01-13 11:19:13 -0600389static int __init fsl_i2c_of_init(void)
390{
391 struct device_node *np;
392 unsigned int i;
393 struct platform_device *i2c_dev;
394 int ret;
395
Kumar Gala2fb07d72006-01-23 16:58:04 -0600396 for (np = NULL, i = 0;
397 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
398 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600399 struct resource r[2];
400 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000401 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600402
403 memset(&r, 0, sizeof(r));
404 memset(&i2c_data, 0, sizeof(i2c_data));
405
406 ret = of_address_to_resource(np, 0, &r[0]);
407 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600408 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600409
Andy Fleminga9b14972006-10-19 19:52:26 -0500410 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600411
412 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
413 if (IS_ERR(i2c_dev)) {
414 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600415 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600416 }
417
418 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000419 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600420 if (flags)
421 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
422
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000423 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600424 if (flags)
425 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
426
Kumar Gala2fb07d72006-01-23 16:58:04 -0600427 ret =
428 platform_device_add_data(i2c_dev, &i2c_data,
429 sizeof(struct
430 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600431 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600432 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000433
434 of_register_i2c_devices(np, i);
Kumar Galaeed32002006-01-13 11:19:13 -0600435 }
436
437 return 0;
438
Kumar Gala2fb07d72006-01-23 16:58:04 -0600439unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600440 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600441err:
Kumar Galaeed32002006-01-13 11:19:13 -0600442 return ret;
443}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600444
Kumar Galaeed32002006-01-13 11:19:13 -0600445arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000446#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600447
448#ifdef CONFIG_PPC_83xx
449static int __init mpc83xx_wdt_init(void)
450{
451 struct resource r;
452 struct device_node *soc, *np;
453 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000454 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600455 int ret;
456
457 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
458
459 if (!np) {
460 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600461 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600462 }
463
464 soc = of_find_node_by_type(NULL, "soc");
465
466 if (!soc) {
467 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600468 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600469 }
470
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000471 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600472 if (!freq) {
473 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600474 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600475 }
476
477 memset(&r, 0, sizeof(r));
478
479 ret = of_address_to_resource(np, 0, &r);
480 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600481 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600482
483 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
484 if (IS_ERR(dev)) {
485 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600486 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600487 }
488
489 ret = platform_device_add_data(dev, freq, sizeof(int));
490 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600491 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600492
493 of_node_put(soc);
494 of_node_put(np);
495
496 return 0;
497
Kumar Gala2fb07d72006-01-23 16:58:04 -0600498unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600499 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600500err:
Kumar Galaeed32002006-01-13 11:19:13 -0600501 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600502nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600503 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600504nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600505 return ret;
506}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600507
Kumar Galaeed32002006-01-13 11:19:13 -0600508arch_initcall(mpc83xx_wdt_init);
509#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600510
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000511static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600512{
513 if (!phy_type)
514 return FSL_USB2_PHY_NONE;
515 if (!strcasecmp(phy_type, "ulpi"))
516 return FSL_USB2_PHY_ULPI;
517 if (!strcasecmp(phy_type, "utmi"))
518 return FSL_USB2_PHY_UTMI;
519 if (!strcasecmp(phy_type, "utmi_wide"))
520 return FSL_USB2_PHY_UTMI_WIDE;
521 if (!strcasecmp(phy_type, "serial"))
522 return FSL_USB2_PHY_SERIAL;
523
524 return FSL_USB2_PHY_NONE;
525}
526
527static int __init fsl_usb_of_init(void)
528{
529 struct device_node *np;
530 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800531 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
532 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600533 int ret;
534
535 for (np = NULL, i = 0;
536 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
537 i++) {
538 struct resource r[2];
539 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000540 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600541
542 memset(&r, 0, sizeof(r));
543 memset(&usb_data, 0, sizeof(usb_data));
544
545 ret = of_address_to_resource(np, 0, &r[0]);
546 if (ret)
547 goto err;
548
Andy Fleminga9b14972006-10-19 19:52:26 -0500549 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600550
Kumar Gala01cced22006-04-11 10:07:16 -0500551 usb_dev_mph =
552 platform_device_register_simple("fsl-ehci", i, r, 2);
553 if (IS_ERR(usb_dev_mph)) {
554 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600555 goto err;
556 }
557
Kumar Gala01cced22006-04-11 10:07:16 -0500558 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
559 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600560
561 usb_data.operating_mode = FSL_USB2_MPH_HOST;
562
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000563 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600564 if (prop)
565 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
566
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000567 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600568 if (prop)
569 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
570
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000571 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600572 usb_data.phy_mode = determine_usb_phy(prop);
573
574 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500575 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600576 sizeof(struct
577 fsl_usb2_platform_data));
578 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500579 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600580 }
581
Kumar Gala01cced22006-04-11 10:07:16 -0500582 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600583 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
584 i++) {
585 struct resource r[2];
586 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000587 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600588
589 memset(&r, 0, sizeof(r));
590 memset(&usb_data, 0, sizeof(usb_data));
591
592 ret = of_address_to_resource(np, 0, &r[0]);
593 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500594 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600595
Andy Fleminga9b14972006-10-19 19:52:26 -0500596 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600597
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000598 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800599
600 if (!prop || !strcmp(prop, "host")) {
601 usb_data.operating_mode = FSL_USB2_DR_HOST;
602 usb_dev_dr_host = platform_device_register_simple(
603 "fsl-ehci", i, r, 2);
604 if (IS_ERR(usb_dev_dr_host)) {
605 ret = PTR_ERR(usb_dev_dr_host);
606 goto err;
607 }
608 } else if (prop && !strcmp(prop, "peripheral")) {
609 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
610 usb_dev_dr_client = platform_device_register_simple(
611 "fsl-usb2-udc", i, r, 2);
612 if (IS_ERR(usb_dev_dr_client)) {
613 ret = PTR_ERR(usb_dev_dr_client);
614 goto err;
615 }
616 } else if (prop && !strcmp(prop, "otg")) {
617 usb_data.operating_mode = FSL_USB2_DR_OTG;
618 usb_dev_dr_host = platform_device_register_simple(
619 "fsl-ehci", i, r, 2);
620 if (IS_ERR(usb_dev_dr_host)) {
621 ret = PTR_ERR(usb_dev_dr_host);
622 goto err;
623 }
624 usb_dev_dr_client = platform_device_register_simple(
625 "fsl-usb2-udc", i, r, 2);
626 if (IS_ERR(usb_dev_dr_client)) {
627 ret = PTR_ERR(usb_dev_dr_client);
628 goto err;
629 }
630 } else {
631 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600632 goto err;
633 }
634
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000635 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600636 usb_data.phy_mode = determine_usb_phy(prop);
637
Li Yang97c5a202007-02-07 13:49:24 +0800638 if (usb_dev_dr_host) {
639 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
640 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
641 dev.coherent_dma_mask;
642 if ((ret = platform_device_add_data(usb_dev_dr_host,
643 &usb_data, sizeof(struct
644 fsl_usb2_platform_data))))
645 goto unreg_dr;
646 }
647 if (usb_dev_dr_client) {
648 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
649 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
650 dev.coherent_dma_mask;
651 if ((ret = platform_device_add_data(usb_dev_dr_client,
652 &usb_data, sizeof(struct
653 fsl_usb2_platform_data))))
654 goto unreg_dr;
655 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600656 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600657 return 0;
658
Kumar Gala01cced22006-04-11 10:07:16 -0500659unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800660 if (usb_dev_dr_host)
661 platform_device_unregister(usb_dev_dr_host);
662 if (usb_dev_dr_client)
663 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500664unreg_mph:
665 if (usb_dev_mph)
666 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600667err:
668 return ret;
669}
670
Kumar Gala01cced22006-04-11 10:07:16 -0500671arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400672
Scott Woode631ae32007-09-14 13:04:54 -0500673#ifndef CONFIG_PPC_CPM_NEW_BINDING
Vitaly Bordugfba43662006-09-21 17:26:34 +0400674#ifdef CONFIG_CPM2
675
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300676extern void init_scc_ioports(struct fs_uart_platform_info*);
677
Vitaly Bordugfba43662006-09-21 17:26:34 +0400678static const char fcc_regs[] = "fcc_regs";
679static const char fcc_regs_c[] = "fcc_regs_c";
680static const char fcc_pram[] = "fcc_pram";
681static char bus_id[9][BUS_ID_SIZE];
682
683static int __init fs_enet_of_init(void)
684{
685 struct device_node *np;
686 unsigned int i;
687 struct platform_device *fs_enet_dev;
688 struct resource res;
689 int ret;
690
691 for (np = NULL, i = 0;
692 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
693 i++) {
694 struct resource r[4];
695 struct device_node *phy, *mdio;
696 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500697 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400698 const void *mac_addr;
699 const phandle *ph;
700 const char *model;
701
702 memset(r, 0, sizeof(r));
703 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
704
705 ret = of_address_to_resource(np, 0, &r[0]);
706 if (ret)
707 goto err;
708 r[0].name = fcc_regs;
709
710 ret = of_address_to_resource(np, 1, &r[1]);
711 if (ret)
712 goto err;
713 r[1].name = fcc_pram;
714
715 ret = of_address_to_resource(np, 2, &r[2]);
716 if (ret)
717 goto err;
718 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400719 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400720
Andy Fleminga9b14972006-10-19 19:52:26 -0500721 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400722
723 fs_enet_dev =
724 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
725
726 if (IS_ERR(fs_enet_dev)) {
727 ret = PTR_ERR(fs_enet_dev);
728 goto err;
729 }
730
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000731 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400732 if (model == NULL) {
733 ret = -ENODEV;
734 goto unreg;
735 }
736
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600737 mac_addr = of_get_mac_address(np);
738 if (mac_addr)
739 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400740
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000741 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400742 phy = of_find_node_by_phandle(*ph);
743
744 if (phy == NULL) {
745 ret = -ENODEV;
746 goto unreg;
747 }
748
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000749 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400750 fs_enet_data.phy_addr = *phy_addr;
751
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000752 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400753
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000754 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400755 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400756 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400757
758 mdio = of_get_parent(phy);
759 ret = of_address_to_resource(mdio, 0, &res);
760 if (ret) {
761 of_node_put(phy);
762 of_node_put(mdio);
763 goto unreg;
764 }
765
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000766 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
767 "rx-clock", NULL));
768 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
769 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400770
Vitaly Bordugfba43662006-09-21 17:26:34 +0400771 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400772 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500773 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400774
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400775 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400776 fs_enet_data.rx_ring = 32;
777 fs_enet_data.tx_ring = 32;
778 fs_enet_data.rx_copybreak = 240;
779 fs_enet_data.use_napi = 0;
780 fs_enet_data.napi_weight = 17;
781 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
782 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
783 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
784
785 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
786 (u32)res.start, fs_enet_data.phy_addr);
787 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400788 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400789
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000790 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400791 if (mdio_bb_prop) {
792 struct platform_device *fs_enet_mdio_bb_dev;
793 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400794
Vitaly Borduged943c12006-10-02 22:41:50 +0400795 fs_enet_mdio_bb_dev =
796 platform_device_register_simple("fsl-bb-mdio",
797 i, NULL, 0);
798 memset(&fs_enet_mdio_bb_data, 0,
799 sizeof(struct fs_mii_bb_platform_info));
800 fs_enet_mdio_bb_data.mdio_dat.bit =
801 mdio_bb_prop[0];
802 fs_enet_mdio_bb_data.mdio_dir.bit =
803 mdio_bb_prop[1];
804 fs_enet_mdio_bb_data.mdc_dat.bit =
805 mdio_bb_prop[2];
806 fs_enet_mdio_bb_data.mdio_port =
807 mdio_bb_prop[3];
808 fs_enet_mdio_bb_data.mdc_port =
809 mdio_bb_prop[4];
810 fs_enet_mdio_bb_data.delay =
811 mdio_bb_prop[5];
812
813 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
814 fs_enet_mdio_bb_data.irq[1] = -1;
815 fs_enet_mdio_bb_data.irq[2] = -1;
816 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
817 fs_enet_mdio_bb_data.irq[31] = -1;
818
819 fs_enet_mdio_bb_data.mdio_dat.offset =
820 (u32)&cpm2_immr->im_ioport.iop_pdatc;
821 fs_enet_mdio_bb_data.mdio_dir.offset =
822 (u32)&cpm2_immr->im_ioport.iop_pdirc;
823 fs_enet_mdio_bb_data.mdc_dat.offset =
824 (u32)&cpm2_immr->im_ioport.iop_pdatc;
825
826 ret = platform_device_add_data(
827 fs_enet_mdio_bb_dev,
828 &fs_enet_mdio_bb_data,
829 sizeof(struct fs_mii_bb_platform_info));
830 if (ret)
831 goto unreg;
832 }
Li Yang97c5a202007-02-07 13:49:24 +0800833
Vitaly Borduged943c12006-10-02 22:41:50 +0400834 of_node_put(phy);
835 of_node_put(mdio);
836
837 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
838 sizeof(struct
839 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500840 if (ret)
841 goto unreg;
842 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400843 }
844 return 0;
845
846unreg:
847 platform_device_unregister(fs_enet_dev);
848err:
849 return ret;
850}
851
852arch_initcall(fs_enet_of_init);
853
854static const char scc_regs[] = "regs";
855static const char scc_pram[] = "pram";
856
857static int __init cpm_uart_of_init(void)
858{
859 struct device_node *np;
860 unsigned int i;
861 struct platform_device *cpm_uart_dev;
862 int ret;
863
864 for (np = NULL, i = 0;
865 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
866 i++) {
867 struct resource r[3];
868 struct fs_uart_platform_info cpm_uart_data;
869 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400870 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400871
872 memset(r, 0, sizeof(r));
873 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
874
875 ret = of_address_to_resource(np, 0, &r[0]);
876 if (ret)
877 goto err;
878
879 r[0].name = scc_regs;
880
881 ret = of_address_to_resource(np, 1, &r[1]);
882 if (ret)
883 goto err;
884 r[1].name = scc_pram;
885
Andy Fleminga9b14972006-10-19 19:52:26 -0500886 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400887
888 cpm_uart_dev =
889 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
890
891 if (IS_ERR(cpm_uart_dev)) {
892 ret = PTR_ERR(cpm_uart_dev);
893 goto err;
894 }
895
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000896 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400897 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400898
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000899 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400900 strcpy(cpm_uart_data.fs_type, model);
901
Vitaly Bordugfba43662006-09-21 17:26:34 +0400902 cpm_uart_data.uart_clk = ppc_proc_freq;
903
904 cpm_uart_data.tx_num_fifo = 4;
905 cpm_uart_data.tx_buf_size = 32;
906 cpm_uart_data.rx_num_fifo = 4;
907 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000908 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
909 "rx-clock", NULL));
910 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
911 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400912
913 ret =
914 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
915 sizeof(struct
916 fs_uart_platform_info));
917 if (ret)
918 goto unreg;
919 }
920
921 return 0;
922
923unreg:
924 platform_device_unregister(cpm_uart_dev);
925err:
926 return ret;
927}
928
929arch_initcall(cpm_uart_of_init);
930#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300931
932#ifdef CONFIG_8xx
933
934extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000935extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300936
937static int __init fs_enet_mdio_of_init(void)
938{
939 struct device_node *np;
940 unsigned int i;
941 struct platform_device *mdio_dev;
942 struct resource res;
943 int ret;
944
945 for (np = NULL, i = 0;
946 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
947 i++) {
948 struct fs_mii_fec_platform_info mdio_data;
949
950 memset(&res, 0, sizeof(res));
951 memset(&mdio_data, 0, sizeof(mdio_data));
952
953 ret = of_address_to_resource(np, 0, &res);
954 if (ret)
955 goto err;
956
957 mdio_dev =
958 platform_device_register_simple("fsl-cpm-fec-mdio",
959 res.start, &res, 1);
960 if (IS_ERR(mdio_dev)) {
961 ret = PTR_ERR(mdio_dev);
962 goto err;
963 }
964
965 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
966
967 ret =
968 platform_device_add_data(mdio_dev, &mdio_data,
969 sizeof(struct fs_mii_fec_platform_info));
970 if (ret)
971 goto unreg;
972 }
973 return 0;
974
975unreg:
976 platform_device_unregister(mdio_dev);
977err:
978 return ret;
979}
980
981arch_initcall(fs_enet_mdio_of_init);
982
983static const char *enet_regs = "regs";
984static const char *enet_pram = "pram";
985static const char *enet_irq = "interrupt";
986static char bus_id[9][BUS_ID_SIZE];
987
988static int __init fs_enet_of_init(void)
989{
990 struct device_node *np;
991 unsigned int i;
992 struct platform_device *fs_enet_dev = NULL;
993 struct resource res;
994 int ret;
995
996 for (np = NULL, i = 0;
997 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
998 i++) {
999 struct resource r[4];
1000 struct device_node *phy = NULL, *mdio = NULL;
1001 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001002 const unsigned int *id;
1003 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +10001004 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001005 const phandle *ph;
1006 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001007
1008 memset(r, 0, sizeof(r));
1009 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1010
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001011 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001012 if (model == NULL) {
1013 ret = -ENODEV;
1014 goto unreg;
1015 }
1016
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001017 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001018 fs_enet_data.fs_no = *id;
1019
1020 if (platform_device_skip(model, *id))
1021 continue;
1022
1023 ret = of_address_to_resource(np, 0, &r[0]);
1024 if (ret)
1025 goto err;
1026 r[0].name = enet_regs;
1027
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001028 mac_addr = of_get_mac_address(np);
1029 if (mac_addr)
1030 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001031
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001032 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001033 if (ph != NULL)
1034 phy = of_find_node_by_phandle(*ph);
1035
1036 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001037 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001038 fs_enet_data.phy_addr = *phy_addr;
1039 fs_enet_data.has_phy = 1;
1040
1041 mdio = of_get_parent(phy);
1042 ret = of_address_to_resource(mdio, 0, &res);
1043 if (ret) {
1044 of_node_put(phy);
1045 of_node_put(mdio);
1046 goto unreg;
1047 }
1048 }
1049
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001050 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001051 strcpy(fs_enet_data.fs_type, model);
1052
1053 if (strstr(model, "FEC")) {
1054 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1055 r[1].flags = IORESOURCE_IRQ;
1056 r[1].name = enet_irq;
1057
1058 fs_enet_dev =
1059 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1060
1061 if (IS_ERR(fs_enet_dev)) {
1062 ret = PTR_ERR(fs_enet_dev);
1063 goto err;
1064 }
1065
1066 fs_enet_data.rx_ring = 128;
1067 fs_enet_data.tx_ring = 16;
1068 fs_enet_data.rx_copybreak = 240;
1069 fs_enet_data.use_napi = 1;
1070 fs_enet_data.napi_weight = 17;
1071
1072 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1073 (u32)res.start, fs_enet_data.phy_addr);
1074 fs_enet_data.bus_id = (char*)&bus_id[i];
1075 fs_enet_data.init_ioports = init_fec_ioports;
1076 }
1077 if (strstr(model, "SCC")) {
1078 ret = of_address_to_resource(np, 1, &r[1]);
1079 if (ret)
1080 goto err;
1081 r[1].name = enet_pram;
1082
1083 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1084 r[2].flags = IORESOURCE_IRQ;
1085 r[2].name = enet_irq;
1086
1087 fs_enet_dev =
1088 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1089
1090 if (IS_ERR(fs_enet_dev)) {
1091 ret = PTR_ERR(fs_enet_dev);
1092 goto err;
1093 }
1094
1095 fs_enet_data.rx_ring = 64;
1096 fs_enet_data.tx_ring = 8;
1097 fs_enet_data.rx_copybreak = 240;
1098 fs_enet_data.use_napi = 1;
1099 fs_enet_data.napi_weight = 17;
1100
1101 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1102 fs_enet_data.bus_id = (char*)&bus_id[i];
1103 fs_enet_data.init_ioports = init_scc_ioports;
1104 }
1105
1106 of_node_put(phy);
1107 of_node_put(mdio);
1108
1109 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1110 sizeof(struct
1111 fs_platform_info));
1112 if (ret)
1113 goto unreg;
1114 }
1115 return 0;
1116
1117unreg:
1118 platform_device_unregister(fs_enet_dev);
1119err:
1120 return ret;
1121}
1122
1123arch_initcall(fs_enet_of_init);
1124
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001125static int __init fsl_pcmcia_of_init(void)
1126{
1127 struct device_node *np = NULL;
1128 /*
1129 * Register all the devices which type is "pcmcia"
1130 */
1131 while ((np = of_find_compatible_node(np,
1132 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1133 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1134 return 0;
1135}
1136
1137arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001138
1139static const char *smc_regs = "regs";
1140static const char *smc_pram = "pram";
1141
1142static int __init cpm_smc_uart_of_init(void)
1143{
1144 struct device_node *np;
1145 unsigned int i;
1146 struct platform_device *cpm_uart_dev;
1147 int ret;
1148
1149 for (np = NULL, i = 0;
1150 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1151 i++) {
1152 struct resource r[3];
1153 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001154 const int *id;
1155 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001156
1157 memset(r, 0, sizeof(r));
1158 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1159
1160 ret = of_address_to_resource(np, 0, &r[0]);
1161 if (ret)
1162 goto err;
1163
1164 r[0].name = smc_regs;
1165
1166 ret = of_address_to_resource(np, 1, &r[1]);
1167 if (ret)
1168 goto err;
1169 r[1].name = smc_pram;
1170
1171 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1172 r[2].flags = IORESOURCE_IRQ;
1173
1174 cpm_uart_dev =
1175 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1176
1177 if (IS_ERR(cpm_uart_dev)) {
1178 ret = PTR_ERR(cpm_uart_dev);
1179 goto err;
1180 }
1181
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001182 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001183 strcpy(cpm_uart_data.fs_type, model);
1184
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001185 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001186 cpm_uart_data.fs_no = *id;
1187 cpm_uart_data.uart_clk = ppc_proc_freq;
1188
1189 cpm_uart_data.tx_num_fifo = 4;
1190 cpm_uart_data.tx_buf_size = 32;
1191 cpm_uart_data.rx_num_fifo = 4;
1192 cpm_uart_data.rx_buf_size = 32;
1193
1194 ret =
1195 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1196 sizeof(struct
1197 fs_uart_platform_info));
1198 if (ret)
1199 goto unreg;
1200 }
1201
1202 return 0;
1203
1204unreg:
1205 platform_device_unregister(cpm_uart_dev);
1206err:
1207 return ret;
1208}
1209
1210arch_initcall(cpm_smc_uart_of_init);
1211
1212#endif /* CONFIG_8xx */
Scott Woode631ae32007-09-14 13:04:54 -05001213#endif /* CONFIG_PPC_CPM_NEW_BINDING */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001214
1215int __init fsl_spi_init(struct spi_board_info *board_infos,
1216 unsigned int num_board_infos,
1217 void (*activate_cs)(u8 cs, u8 polarity),
1218 void (*deactivate_cs)(u8 cs, u8 polarity))
1219{
1220 struct device_node *np;
1221 unsigned int i;
1222 const u32 *sysclk;
1223
1224 np = of_find_node_by_type(NULL, "qe");
1225 if (!np)
1226 return -ENODEV;
1227
1228 sysclk = of_get_property(np, "bus-frequency", NULL);
1229 if (!sysclk)
1230 return -ENODEV;
1231
1232 for (np = NULL, i = 1;
1233 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1234 i++) {
1235 int ret = 0;
1236 unsigned int j;
1237 const void *prop;
1238 struct resource res[2];
1239 struct platform_device *pdev;
1240 struct fsl_spi_platform_data pdata = {
1241 .activate_cs = activate_cs,
1242 .deactivate_cs = deactivate_cs,
1243 };
1244
1245 memset(res, 0, sizeof(res));
1246
1247 pdata.sysclk = *sysclk;
1248
1249 prop = of_get_property(np, "reg", NULL);
1250 if (!prop)
1251 goto err;
1252 pdata.bus_num = *(u32 *)prop;
1253
1254 prop = of_get_property(np, "mode", NULL);
1255 if (prop && !strcmp(prop, "cpu-qe"))
1256 pdata.qe_mode = 1;
1257
1258 for (j = 0; j < num_board_infos; j++) {
1259 if (board_infos[j].bus_num == pdata.bus_num)
1260 pdata.max_chipselect++;
1261 }
1262
1263 if (!pdata.max_chipselect)
1264 goto err;
1265
1266 ret = of_address_to_resource(np, 0, &res[0]);
1267 if (ret)
1268 goto err;
1269
1270 ret = of_irq_to_resource(np, 0, &res[1]);
1271 if (ret == NO_IRQ)
1272 goto err;
1273
1274 pdev = platform_device_alloc("mpc83xx_spi", i);
1275 if (!pdev)
1276 goto err;
1277
1278 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1279 if (ret)
1280 goto unreg;
1281
1282 ret = platform_device_add_resources(pdev, res,
1283 ARRAY_SIZE(res));
1284 if (ret)
1285 goto unreg;
1286
1287 ret = platform_device_register(pdev);
1288 if (ret)
1289 goto unreg;
1290
1291 continue;
1292unreg:
1293 platform_device_del(pdev);
1294err:
1295 continue;
1296 }
1297
1298 return spi_register_board_info(board_infos, num_board_infos);
1299}