blob: 81af4bdf252aaa61054c433215b46a87377ab5b7 [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"},
Anton Vorontsovc0e4eb22007-10-02 17:47:43 +0400340 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000341};
342
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000343static int __init of_find_i2c_driver(struct device_node *node,
344 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000345{
346 int i;
347
348 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
349 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
350 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000351 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
352 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
353 strlcpy(info->type, i2c_devices[i].i2c_type,
354 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
355 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000356 return 0;
357 }
358 return -ENODEV;
359}
360
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000361static void __init of_register_i2c_devices(struct device_node *adap_node,
362 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000363{
364 struct device_node *node = NULL;
365
366 while ((node = of_get_next_child(adap_node, node))) {
Anton Vorontsovda1bb3a2007-10-02 17:47:40 +0400367 struct i2c_board_info info = {};
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000368 const u32 *addr;
369 int len;
370
371 addr = of_get_property(node, "reg", &len);
372 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
Peter Korsgaard210805e2007-09-20 12:42:12 +0200373 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000374 continue;
375 }
376
377 info.irq = irq_of_parse_and_map(node, 0);
378 if (info.irq == NO_IRQ)
379 info.irq = -1;
380
381 if (of_find_i2c_driver(node, &info) < 0)
382 continue;
383
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000384 info.addr = *addr;
385
386 i2c_register_board_info(bus_num, &info, 1);
387 }
388}
389
Kumar Galaeed32002006-01-13 11:19:13 -0600390static int __init fsl_i2c_of_init(void)
391{
392 struct device_node *np;
Kumar Galaec9686c2007-12-11 23:17:24 -0600393 unsigned int i = 0;
Kumar Galaeed32002006-01-13 11:19:13 -0600394 struct platform_device *i2c_dev;
395 int ret;
396
Kumar Galaec9686c2007-12-11 23:17:24 -0600397 for_each_compatible_node(np, NULL, "fsl-i2c") {
Kumar Galaeed32002006-01-13 11:19:13 -0600398 struct resource r[2];
399 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000400 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600401
402 memset(&r, 0, sizeof(r));
403 memset(&i2c_data, 0, sizeof(i2c_data));
404
405 ret = of_address_to_resource(np, 0, &r[0]);
406 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600407 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600408
Andy Fleminga9b14972006-10-19 19:52:26 -0500409 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600410
411 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
412 if (IS_ERR(i2c_dev)) {
413 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600414 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600415 }
416
417 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000418 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600419 if (flags)
420 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
421
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000422 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600423 if (flags)
424 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
425
Kumar Gala2fb07d72006-01-23 16:58:04 -0600426 ret =
427 platform_device_add_data(i2c_dev, &i2c_data,
428 sizeof(struct
429 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600430 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600431 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000432
Kumar Galaec9686c2007-12-11 23:17:24 -0600433 of_register_i2c_devices(np, i++);
Kumar Galaeed32002006-01-13 11:19:13 -0600434 }
435
436 return 0;
437
Kumar Gala2fb07d72006-01-23 16:58:04 -0600438unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600439 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600440err:
Kumar Galaeed32002006-01-13 11:19:13 -0600441 return ret;
442}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600443
Kumar Galaeed32002006-01-13 11:19:13 -0600444arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000445#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600446
447#ifdef CONFIG_PPC_83xx
448static int __init mpc83xx_wdt_init(void)
449{
450 struct resource r;
451 struct device_node *soc, *np;
452 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000453 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600454 int ret;
455
456 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
457
458 if (!np) {
459 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600460 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600461 }
462
463 soc = of_find_node_by_type(NULL, "soc");
464
465 if (!soc) {
466 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600467 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600468 }
469
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000470 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600471 if (!freq) {
472 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600473 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600474 }
475
476 memset(&r, 0, sizeof(r));
477
478 ret = of_address_to_resource(np, 0, &r);
479 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600480 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600481
482 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
483 if (IS_ERR(dev)) {
484 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600485 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600486 }
487
488 ret = platform_device_add_data(dev, freq, sizeof(int));
489 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600490 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600491
492 of_node_put(soc);
493 of_node_put(np);
494
495 return 0;
496
Kumar Gala2fb07d72006-01-23 16:58:04 -0600497unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600498 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600499err:
Kumar Galaeed32002006-01-13 11:19:13 -0600500 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600501nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600502 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600503nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600504 return ret;
505}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600506
Kumar Galaeed32002006-01-13 11:19:13 -0600507arch_initcall(mpc83xx_wdt_init);
508#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600509
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000510static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600511{
512 if (!phy_type)
513 return FSL_USB2_PHY_NONE;
514 if (!strcasecmp(phy_type, "ulpi"))
515 return FSL_USB2_PHY_ULPI;
516 if (!strcasecmp(phy_type, "utmi"))
517 return FSL_USB2_PHY_UTMI;
518 if (!strcasecmp(phy_type, "utmi_wide"))
519 return FSL_USB2_PHY_UTMI_WIDE;
520 if (!strcasecmp(phy_type, "serial"))
521 return FSL_USB2_PHY_SERIAL;
522
523 return FSL_USB2_PHY_NONE;
524}
525
526static int __init fsl_usb_of_init(void)
527{
528 struct device_node *np;
529 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800530 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
531 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600532 int ret;
533
534 for (np = NULL, i = 0;
535 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
536 i++) {
537 struct resource r[2];
538 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000539 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600540
541 memset(&r, 0, sizeof(r));
542 memset(&usb_data, 0, sizeof(usb_data));
543
544 ret = of_address_to_resource(np, 0, &r[0]);
545 if (ret)
546 goto err;
547
Andy Fleminga9b14972006-10-19 19:52:26 -0500548 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600549
Kumar Gala01cced22006-04-11 10:07:16 -0500550 usb_dev_mph =
551 platform_device_register_simple("fsl-ehci", i, r, 2);
552 if (IS_ERR(usb_dev_mph)) {
553 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600554 goto err;
555 }
556
Kumar Gala01cced22006-04-11 10:07:16 -0500557 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
558 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600559
560 usb_data.operating_mode = FSL_USB2_MPH_HOST;
561
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000562 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600563 if (prop)
564 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
565
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000566 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600567 if (prop)
568 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
569
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000570 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600571 usb_data.phy_mode = determine_usb_phy(prop);
572
573 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500574 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600575 sizeof(struct
576 fsl_usb2_platform_data));
577 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500578 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600579 }
580
Kumar Gala01cced22006-04-11 10:07:16 -0500581 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600582 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
583 i++) {
584 struct resource r[2];
585 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000586 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600587
588 memset(&r, 0, sizeof(r));
589 memset(&usb_data, 0, sizeof(usb_data));
590
591 ret = of_address_to_resource(np, 0, &r[0]);
592 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500593 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600594
Andy Fleminga9b14972006-10-19 19:52:26 -0500595 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600596
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000597 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800598
599 if (!prop || !strcmp(prop, "host")) {
600 usb_data.operating_mode = FSL_USB2_DR_HOST;
601 usb_dev_dr_host = platform_device_register_simple(
602 "fsl-ehci", i, r, 2);
603 if (IS_ERR(usb_dev_dr_host)) {
604 ret = PTR_ERR(usb_dev_dr_host);
605 goto err;
606 }
607 } else if (prop && !strcmp(prop, "peripheral")) {
608 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
609 usb_dev_dr_client = platform_device_register_simple(
610 "fsl-usb2-udc", i, r, 2);
611 if (IS_ERR(usb_dev_dr_client)) {
612 ret = PTR_ERR(usb_dev_dr_client);
613 goto err;
614 }
615 } else if (prop && !strcmp(prop, "otg")) {
616 usb_data.operating_mode = FSL_USB2_DR_OTG;
617 usb_dev_dr_host = platform_device_register_simple(
618 "fsl-ehci", i, r, 2);
619 if (IS_ERR(usb_dev_dr_host)) {
620 ret = PTR_ERR(usb_dev_dr_host);
621 goto err;
622 }
623 usb_dev_dr_client = platform_device_register_simple(
624 "fsl-usb2-udc", i, r, 2);
625 if (IS_ERR(usb_dev_dr_client)) {
626 ret = PTR_ERR(usb_dev_dr_client);
627 goto err;
628 }
629 } else {
630 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600631 goto err;
632 }
633
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000634 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600635 usb_data.phy_mode = determine_usb_phy(prop);
636
Li Yang97c5a202007-02-07 13:49:24 +0800637 if (usb_dev_dr_host) {
638 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
639 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
640 dev.coherent_dma_mask;
641 if ((ret = platform_device_add_data(usb_dev_dr_host,
642 &usb_data, sizeof(struct
643 fsl_usb2_platform_data))))
644 goto unreg_dr;
645 }
646 if (usb_dev_dr_client) {
647 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
648 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
649 dev.coherent_dma_mask;
650 if ((ret = platform_device_add_data(usb_dev_dr_client,
651 &usb_data, sizeof(struct
652 fsl_usb2_platform_data))))
653 goto unreg_dr;
654 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600655 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600656 return 0;
657
Kumar Gala01cced22006-04-11 10:07:16 -0500658unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800659 if (usb_dev_dr_host)
660 platform_device_unregister(usb_dev_dr_host);
661 if (usb_dev_dr_client)
662 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500663unreg_mph:
664 if (usb_dev_mph)
665 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600666err:
667 return ret;
668}
669
Kumar Gala01cced22006-04-11 10:07:16 -0500670arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400671
Scott Woode631ae32007-09-14 13:04:54 -0500672#ifndef CONFIG_PPC_CPM_NEW_BINDING
Vitaly Bordugfba43662006-09-21 17:26:34 +0400673#ifdef CONFIG_CPM2
674
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300675extern void init_scc_ioports(struct fs_uart_platform_info*);
676
Vitaly Bordugfba43662006-09-21 17:26:34 +0400677static const char fcc_regs[] = "fcc_regs";
678static const char fcc_regs_c[] = "fcc_regs_c";
679static const char fcc_pram[] = "fcc_pram";
680static char bus_id[9][BUS_ID_SIZE];
681
682static int __init fs_enet_of_init(void)
683{
684 struct device_node *np;
685 unsigned int i;
686 struct platform_device *fs_enet_dev;
687 struct resource res;
688 int ret;
689
690 for (np = NULL, i = 0;
691 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
692 i++) {
693 struct resource r[4];
694 struct device_node *phy, *mdio;
695 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500696 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400697 const void *mac_addr;
698 const phandle *ph;
699 const char *model;
700
701 memset(r, 0, sizeof(r));
702 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
703
704 ret = of_address_to_resource(np, 0, &r[0]);
705 if (ret)
706 goto err;
707 r[0].name = fcc_regs;
708
709 ret = of_address_to_resource(np, 1, &r[1]);
710 if (ret)
711 goto err;
712 r[1].name = fcc_pram;
713
714 ret = of_address_to_resource(np, 2, &r[2]);
715 if (ret)
716 goto err;
717 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400718 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400719
Andy Fleminga9b14972006-10-19 19:52:26 -0500720 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400721
722 fs_enet_dev =
723 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
724
725 if (IS_ERR(fs_enet_dev)) {
726 ret = PTR_ERR(fs_enet_dev);
727 goto err;
728 }
729
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000730 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400731 if (model == NULL) {
732 ret = -ENODEV;
733 goto unreg;
734 }
735
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600736 mac_addr = of_get_mac_address(np);
737 if (mac_addr)
738 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400739
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000740 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400741 phy = of_find_node_by_phandle(*ph);
742
743 if (phy == NULL) {
744 ret = -ENODEV;
745 goto unreg;
746 }
747
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000748 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400749 fs_enet_data.phy_addr = *phy_addr;
750
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000751 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400752
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000753 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400754 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400755 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400756
757 mdio = of_get_parent(phy);
758 ret = of_address_to_resource(mdio, 0, &res);
759 if (ret) {
760 of_node_put(phy);
761 of_node_put(mdio);
762 goto unreg;
763 }
764
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000765 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
766 "rx-clock", NULL));
767 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
768 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400769
Vitaly Bordugfba43662006-09-21 17:26:34 +0400770 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400771 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500772 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400773
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400774 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400775 fs_enet_data.rx_ring = 32;
776 fs_enet_data.tx_ring = 32;
777 fs_enet_data.rx_copybreak = 240;
778 fs_enet_data.use_napi = 0;
779 fs_enet_data.napi_weight = 17;
780 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
781 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
782 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
783
784 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
785 (u32)res.start, fs_enet_data.phy_addr);
786 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400787 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400788
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000789 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400790 if (mdio_bb_prop) {
791 struct platform_device *fs_enet_mdio_bb_dev;
792 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400793
Vitaly Borduged943c12006-10-02 22:41:50 +0400794 fs_enet_mdio_bb_dev =
795 platform_device_register_simple("fsl-bb-mdio",
796 i, NULL, 0);
797 memset(&fs_enet_mdio_bb_data, 0,
798 sizeof(struct fs_mii_bb_platform_info));
799 fs_enet_mdio_bb_data.mdio_dat.bit =
800 mdio_bb_prop[0];
801 fs_enet_mdio_bb_data.mdio_dir.bit =
802 mdio_bb_prop[1];
803 fs_enet_mdio_bb_data.mdc_dat.bit =
804 mdio_bb_prop[2];
805 fs_enet_mdio_bb_data.mdio_port =
806 mdio_bb_prop[3];
807 fs_enet_mdio_bb_data.mdc_port =
808 mdio_bb_prop[4];
809 fs_enet_mdio_bb_data.delay =
810 mdio_bb_prop[5];
811
812 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
813 fs_enet_mdio_bb_data.irq[1] = -1;
814 fs_enet_mdio_bb_data.irq[2] = -1;
815 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
816 fs_enet_mdio_bb_data.irq[31] = -1;
817
818 fs_enet_mdio_bb_data.mdio_dat.offset =
819 (u32)&cpm2_immr->im_ioport.iop_pdatc;
820 fs_enet_mdio_bb_data.mdio_dir.offset =
821 (u32)&cpm2_immr->im_ioport.iop_pdirc;
822 fs_enet_mdio_bb_data.mdc_dat.offset =
823 (u32)&cpm2_immr->im_ioport.iop_pdatc;
824
825 ret = platform_device_add_data(
826 fs_enet_mdio_bb_dev,
827 &fs_enet_mdio_bb_data,
828 sizeof(struct fs_mii_bb_platform_info));
829 if (ret)
830 goto unreg;
831 }
Li Yang97c5a202007-02-07 13:49:24 +0800832
Vitaly Borduged943c12006-10-02 22:41:50 +0400833 of_node_put(phy);
834 of_node_put(mdio);
835
836 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
837 sizeof(struct
838 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500839 if (ret)
840 goto unreg;
841 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400842 }
843 return 0;
844
845unreg:
846 platform_device_unregister(fs_enet_dev);
847err:
848 return ret;
849}
850
851arch_initcall(fs_enet_of_init);
852
853static const char scc_regs[] = "regs";
854static const char scc_pram[] = "pram";
855
856static int __init cpm_uart_of_init(void)
857{
858 struct device_node *np;
859 unsigned int i;
860 struct platform_device *cpm_uart_dev;
861 int ret;
862
863 for (np = NULL, i = 0;
864 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
865 i++) {
866 struct resource r[3];
867 struct fs_uart_platform_info cpm_uart_data;
868 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400869 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400870
871 memset(r, 0, sizeof(r));
872 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
873
874 ret = of_address_to_resource(np, 0, &r[0]);
875 if (ret)
876 goto err;
877
878 r[0].name = scc_regs;
879
880 ret = of_address_to_resource(np, 1, &r[1]);
881 if (ret)
882 goto err;
883 r[1].name = scc_pram;
884
Andy Fleminga9b14972006-10-19 19:52:26 -0500885 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400886
887 cpm_uart_dev =
888 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
889
890 if (IS_ERR(cpm_uart_dev)) {
891 ret = PTR_ERR(cpm_uart_dev);
892 goto err;
893 }
894
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000895 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400896 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400897
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000898 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400899 strcpy(cpm_uart_data.fs_type, model);
900
Vitaly Bordugfba43662006-09-21 17:26:34 +0400901 cpm_uart_data.uart_clk = ppc_proc_freq;
902
903 cpm_uart_data.tx_num_fifo = 4;
904 cpm_uart_data.tx_buf_size = 32;
905 cpm_uart_data.rx_num_fifo = 4;
906 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000907 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
908 "rx-clock", NULL));
909 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
910 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400911
912 ret =
913 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
914 sizeof(struct
915 fs_uart_platform_info));
916 if (ret)
917 goto unreg;
918 }
919
920 return 0;
921
922unreg:
923 platform_device_unregister(cpm_uart_dev);
924err:
925 return ret;
926}
927
928arch_initcall(cpm_uart_of_init);
929#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300930
931#ifdef CONFIG_8xx
932
933extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000934extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300935
936static int __init fs_enet_mdio_of_init(void)
937{
938 struct device_node *np;
939 unsigned int i;
940 struct platform_device *mdio_dev;
941 struct resource res;
942 int ret;
943
944 for (np = NULL, i = 0;
945 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
946 i++) {
947 struct fs_mii_fec_platform_info mdio_data;
948
949 memset(&res, 0, sizeof(res));
950 memset(&mdio_data, 0, sizeof(mdio_data));
951
952 ret = of_address_to_resource(np, 0, &res);
953 if (ret)
954 goto err;
955
956 mdio_dev =
957 platform_device_register_simple("fsl-cpm-fec-mdio",
958 res.start, &res, 1);
959 if (IS_ERR(mdio_dev)) {
960 ret = PTR_ERR(mdio_dev);
961 goto err;
962 }
963
964 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
965
966 ret =
967 platform_device_add_data(mdio_dev, &mdio_data,
968 sizeof(struct fs_mii_fec_platform_info));
969 if (ret)
970 goto unreg;
971 }
972 return 0;
973
974unreg:
975 platform_device_unregister(mdio_dev);
976err:
977 return ret;
978}
979
980arch_initcall(fs_enet_mdio_of_init);
981
982static const char *enet_regs = "regs";
983static const char *enet_pram = "pram";
984static const char *enet_irq = "interrupt";
985static char bus_id[9][BUS_ID_SIZE];
986
987static int __init fs_enet_of_init(void)
988{
989 struct device_node *np;
990 unsigned int i;
991 struct platform_device *fs_enet_dev = NULL;
992 struct resource res;
993 int ret;
994
995 for (np = NULL, i = 0;
996 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
997 i++) {
998 struct resource r[4];
999 struct device_node *phy = NULL, *mdio = NULL;
1000 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001001 const unsigned int *id;
1002 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +10001003 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001004 const phandle *ph;
1005 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001006
1007 memset(r, 0, sizeof(r));
1008 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1009
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001010 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001011 if (model == NULL) {
1012 ret = -ENODEV;
1013 goto unreg;
1014 }
1015
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001016 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001017 fs_enet_data.fs_no = *id;
1018
1019 if (platform_device_skip(model, *id))
1020 continue;
1021
1022 ret = of_address_to_resource(np, 0, &r[0]);
1023 if (ret)
1024 goto err;
1025 r[0].name = enet_regs;
1026
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001027 mac_addr = of_get_mac_address(np);
1028 if (mac_addr)
1029 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001030
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001031 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001032 if (ph != NULL)
1033 phy = of_find_node_by_phandle(*ph);
1034
1035 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001036 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001037 fs_enet_data.phy_addr = *phy_addr;
1038 fs_enet_data.has_phy = 1;
1039
1040 mdio = of_get_parent(phy);
1041 ret = of_address_to_resource(mdio, 0, &res);
1042 if (ret) {
1043 of_node_put(phy);
1044 of_node_put(mdio);
1045 goto unreg;
1046 }
1047 }
1048
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001049 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001050 strcpy(fs_enet_data.fs_type, model);
1051
1052 if (strstr(model, "FEC")) {
1053 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1054 r[1].flags = IORESOURCE_IRQ;
1055 r[1].name = enet_irq;
1056
1057 fs_enet_dev =
1058 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1059
1060 if (IS_ERR(fs_enet_dev)) {
1061 ret = PTR_ERR(fs_enet_dev);
1062 goto err;
1063 }
1064
1065 fs_enet_data.rx_ring = 128;
1066 fs_enet_data.tx_ring = 16;
1067 fs_enet_data.rx_copybreak = 240;
1068 fs_enet_data.use_napi = 1;
1069 fs_enet_data.napi_weight = 17;
1070
1071 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1072 (u32)res.start, fs_enet_data.phy_addr);
1073 fs_enet_data.bus_id = (char*)&bus_id[i];
1074 fs_enet_data.init_ioports = init_fec_ioports;
1075 }
1076 if (strstr(model, "SCC")) {
1077 ret = of_address_to_resource(np, 1, &r[1]);
1078 if (ret)
1079 goto err;
1080 r[1].name = enet_pram;
1081
1082 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1083 r[2].flags = IORESOURCE_IRQ;
1084 r[2].name = enet_irq;
1085
1086 fs_enet_dev =
1087 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1088
1089 if (IS_ERR(fs_enet_dev)) {
1090 ret = PTR_ERR(fs_enet_dev);
1091 goto err;
1092 }
1093
1094 fs_enet_data.rx_ring = 64;
1095 fs_enet_data.tx_ring = 8;
1096 fs_enet_data.rx_copybreak = 240;
1097 fs_enet_data.use_napi = 1;
1098 fs_enet_data.napi_weight = 17;
1099
1100 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1101 fs_enet_data.bus_id = (char*)&bus_id[i];
1102 fs_enet_data.init_ioports = init_scc_ioports;
1103 }
1104
1105 of_node_put(phy);
1106 of_node_put(mdio);
1107
1108 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1109 sizeof(struct
1110 fs_platform_info));
1111 if (ret)
1112 goto unreg;
1113 }
1114 return 0;
1115
1116unreg:
1117 platform_device_unregister(fs_enet_dev);
1118err:
1119 return ret;
1120}
1121
1122arch_initcall(fs_enet_of_init);
1123
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001124static int __init fsl_pcmcia_of_init(void)
1125{
1126 struct device_node *np = NULL;
1127 /*
1128 * Register all the devices which type is "pcmcia"
1129 */
1130 while ((np = of_find_compatible_node(np,
1131 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1132 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1133 return 0;
1134}
1135
1136arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001137
1138static const char *smc_regs = "regs";
1139static const char *smc_pram = "pram";
1140
1141static int __init cpm_smc_uart_of_init(void)
1142{
1143 struct device_node *np;
1144 unsigned int i;
1145 struct platform_device *cpm_uart_dev;
1146 int ret;
1147
1148 for (np = NULL, i = 0;
1149 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1150 i++) {
1151 struct resource r[3];
1152 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001153 const int *id;
1154 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001155
1156 memset(r, 0, sizeof(r));
1157 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1158
1159 ret = of_address_to_resource(np, 0, &r[0]);
1160 if (ret)
1161 goto err;
1162
1163 r[0].name = smc_regs;
1164
1165 ret = of_address_to_resource(np, 1, &r[1]);
1166 if (ret)
1167 goto err;
1168 r[1].name = smc_pram;
1169
1170 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1171 r[2].flags = IORESOURCE_IRQ;
1172
1173 cpm_uart_dev =
1174 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1175
1176 if (IS_ERR(cpm_uart_dev)) {
1177 ret = PTR_ERR(cpm_uart_dev);
1178 goto err;
1179 }
1180
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001181 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001182 strcpy(cpm_uart_data.fs_type, model);
1183
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001184 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001185 cpm_uart_data.fs_no = *id;
1186 cpm_uart_data.uart_clk = ppc_proc_freq;
1187
1188 cpm_uart_data.tx_num_fifo = 4;
1189 cpm_uart_data.tx_buf_size = 32;
1190 cpm_uart_data.rx_num_fifo = 4;
1191 cpm_uart_data.rx_buf_size = 32;
1192
1193 ret =
1194 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1195 sizeof(struct
1196 fs_uart_platform_info));
1197 if (ret)
1198 goto unreg;
1199 }
1200
1201 return 0;
1202
1203unreg:
1204 platform_device_unregister(cpm_uart_dev);
1205err:
1206 return ret;
1207}
1208
1209arch_initcall(cpm_smc_uart_of_init);
1210
1211#endif /* CONFIG_8xx */
Scott Woode631ae32007-09-14 13:04:54 -05001212#endif /* CONFIG_PPC_CPM_NEW_BINDING */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001213
1214int __init fsl_spi_init(struct spi_board_info *board_infos,
1215 unsigned int num_board_infos,
1216 void (*activate_cs)(u8 cs, u8 polarity),
1217 void (*deactivate_cs)(u8 cs, u8 polarity))
1218{
1219 struct device_node *np;
1220 unsigned int i;
1221 const u32 *sysclk;
1222
Peter Korsgaard082ea862007-10-06 22:06:40 +02001223 /* SPI controller is either clocked from QE or SoC clock */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001224 np = of_find_node_by_type(NULL, "qe");
1225 if (!np)
Peter Korsgaard082ea862007-10-06 22:06:40 +02001226 np = of_find_node_by_type(NULL, "soc");
1227
1228 if (!np)
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001229 return -ENODEV;
1230
1231 sysclk = of_get_property(np, "bus-frequency", NULL);
1232 if (!sysclk)
1233 return -ENODEV;
1234
1235 for (np = NULL, i = 1;
1236 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1237 i++) {
1238 int ret = 0;
1239 unsigned int j;
1240 const void *prop;
1241 struct resource res[2];
1242 struct platform_device *pdev;
1243 struct fsl_spi_platform_data pdata = {
1244 .activate_cs = activate_cs,
1245 .deactivate_cs = deactivate_cs,
1246 };
1247
1248 memset(res, 0, sizeof(res));
1249
1250 pdata.sysclk = *sysclk;
1251
1252 prop = of_get_property(np, "reg", NULL);
1253 if (!prop)
1254 goto err;
1255 pdata.bus_num = *(u32 *)prop;
1256
1257 prop = of_get_property(np, "mode", NULL);
1258 if (prop && !strcmp(prop, "cpu-qe"))
1259 pdata.qe_mode = 1;
1260
1261 for (j = 0; j < num_board_infos; j++) {
1262 if (board_infos[j].bus_num == pdata.bus_num)
1263 pdata.max_chipselect++;
1264 }
1265
1266 if (!pdata.max_chipselect)
1267 goto err;
1268
1269 ret = of_address_to_resource(np, 0, &res[0]);
1270 if (ret)
1271 goto err;
1272
1273 ret = of_irq_to_resource(np, 0, &res[1]);
1274 if (ret == NO_IRQ)
1275 goto err;
1276
1277 pdev = platform_device_alloc("mpc83xx_spi", i);
1278 if (!pdev)
1279 goto err;
1280
1281 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1282 if (ret)
1283 goto unreg;
1284
1285 ret = platform_device_add_resources(pdev, res,
1286 ARRAY_SIZE(res));
1287 if (ret)
1288 goto unreg;
1289
1290 ret = platform_device_register(pdev);
1291 if (ret)
1292 goto unreg;
1293
1294 continue;
1295unreg:
1296 platform_device_del(pdev);
1297err:
1298 continue;
1299 }
1300
1301 return spi_register_board_info(board_infos, num_board_infos);
1302}
Kumar Galae1c15752007-10-04 01:04:57 -05001303
1304#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1305static __be32 __iomem *rstcr;
1306
1307static int __init setup_rstcr(void)
1308{
1309 struct device_node *np;
1310 np = of_find_node_by_name(NULL, "global-utilities");
1311 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
1312 const u32 *prop = of_get_property(np, "reg", NULL);
1313 if (prop) {
1314 /* map reset control register
1315 * 0xE00B0 is offset of reset control register
1316 */
1317 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
1318 if (!rstcr)
1319 printk (KERN_EMERG "Error: reset control "
1320 "register not mapped!\n");
1321 }
1322 } else
1323 printk (KERN_INFO "rstcr compatible register does not exist!\n");
1324 if (np)
1325 of_node_put(np);
1326 return 0;
1327}
1328
1329arch_initcall(setup_rstcr);
1330
1331void fsl_rstcr_restart(char *cmd)
1332{
1333 local_irq_disable();
1334 if (rstcr)
1335 /* set reset control register */
1336 out_be32(rstcr, 0x2); /* HRESET_REQ */
1337
1338 while (1) ;
1339}
1340#endif