blob: 217bcc2e8f8664f5af07ef8a871f499d5300c50e [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{
Kumar Galae77b28e2007-12-12 00:28:35 -0600135 struct device_node *np = NULL;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600136 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600137 struct resource res;
138 int ret;
139
Kumar Galae77b28e2007-12-12 00:28:35 -0600140 np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
141
142 /* try the deprecated version */
143 if (!np)
144 np = of_find_compatible_node(np, "mdio", "gianfar");
145
146 if (np) {
Kumar Galaeed32002006-01-13 11:19:13 -0600147 int k;
148 struct device_node *child = NULL;
149 struct gianfar_mdio_data mdio_data;
150
151 memset(&res, 0, sizeof(res));
152 memset(&mdio_data, 0, sizeof(mdio_data));
153
154 ret = of_address_to_resource(np, 0, &res);
155 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600156 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600157
Kumar Gala2fb07d72006-01-23 16:58:04 -0600158 mdio_dev =
159 platform_device_register_simple("fsl-gianfar_mdio",
160 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600161 if (IS_ERR(mdio_dev)) {
162 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600163 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600164 }
165
166 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500167 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600168
169 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400170 int irq = irq_of_parse_and_map(child, 0);
171 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000172 const u32 *id = of_get_property(child,
173 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400174 mdio_data.irq[*id] = irq;
175 }
Kumar Galaeed32002006-01-13 11:19:13 -0600176 }
177
Kumar Gala2fb07d72006-01-23 16:58:04 -0600178 ret =
179 platform_device_add_data(mdio_dev, &mdio_data,
180 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600181 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600182 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600183 }
184
Kumar Galae77b28e2007-12-12 00:28:35 -0600185 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600186 return 0;
187
188unreg:
189 platform_device_unregister(mdio_dev);
190err:
Kumar Galae77b28e2007-12-12 00:28:35 -0600191 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600192 return ret;
193}
194
195arch_initcall(gfar_mdio_of_init);
196
197static const char *gfar_tx_intr = "tx";
198static const char *gfar_rx_intr = "rx";
199static const char *gfar_err_intr = "error";
200
Andy Fleminga9b14972006-10-19 19:52:26 -0500201
Kumar Gala2fb07d72006-01-23 16:58:04 -0600202static int __init gfar_of_init(void)
203{
204 struct device_node *np;
205 unsigned int i;
206 struct platform_device *gfar_dev;
207 struct resource res;
208 int ret;
209
210 for (np = NULL, i = 0;
211 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
212 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600213 struct resource r[4];
214 struct device_node *phy, *mdio;
215 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000216 const unsigned int *id;
217 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500218 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000219 const void *mac_addr;
220 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400221 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600222
223 memset(r, 0, sizeof(r));
224 memset(&gfar_data, 0, sizeof(gfar_data));
225
226 ret = of_address_to_resource(np, 0, &r[0]);
227 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600228 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600229
Andy Fleminga9b14972006-10-19 19:52:26 -0500230 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600231
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000232 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600233
234 /* If we aren't the FEC we have multiple interrupts */
235 if (model && strcasecmp(model, "FEC")) {
236 r[1].name = gfar_tx_intr;
237
238 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500239 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600240
241 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500242 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500243
244 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600245 }
246
Kumar Gala2fb07d72006-01-23 16:58:04 -0600247 gfar_dev =
248 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400249 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600250
251 if (IS_ERR(gfar_dev)) {
252 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600253 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600254 }
255
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600256 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500257 if (mac_addr)
258 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600259
260 if (model && !strcasecmp(model, "TSEC"))
261 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600262 FSL_GIANFAR_DEV_HAS_GIGABIT |
263 FSL_GIANFAR_DEV_HAS_COALESCE |
264 FSL_GIANFAR_DEV_HAS_RMON |
265 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600266 if (model && !strcasecmp(model, "eTSEC"))
267 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600268 FSL_GIANFAR_DEV_HAS_GIGABIT |
269 FSL_GIANFAR_DEV_HAS_COALESCE |
270 FSL_GIANFAR_DEV_HAS_RMON |
271 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
272 FSL_GIANFAR_DEV_HAS_CSUM |
273 FSL_GIANFAR_DEV_HAS_VLAN |
274 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600275
Andy Fleming7132ab72007-07-11 11:43:07 -0500276 ctype = of_get_property(np, "phy-connection-type", NULL);
277
278 /* We only care about rgmii-id. The rest are autodetected */
279 if (ctype && !strcmp(ctype, "rgmii-id"))
280 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
281 else
282 gfar_data.interface = PHY_INTERFACE_MODE_MII;
283
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000284 ph = of_get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600285 phy = of_find_node_by_phandle(*ph);
286
287 if (phy == NULL) {
288 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600289 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600290 }
291
292 mdio = of_get_parent(phy);
293
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000294 id = of_get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600295 ret = of_address_to_resource(mdio, 0, &res);
296 if (ret) {
297 of_node_put(phy);
298 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600299 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600300 }
301
302 gfar_data.phy_id = *id;
303 gfar_data.bus_id = res.start;
304
305 of_node_put(phy);
306 of_node_put(mdio);
307
Kumar Gala2fb07d72006-01-23 16:58:04 -0600308 ret =
309 platform_device_add_data(gfar_dev, &gfar_data,
310 sizeof(struct
311 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600312 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600313 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600314 }
315
316 return 0;
317
Kumar Gala2fb07d72006-01-23 16:58:04 -0600318unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600319 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600320err:
Kumar Galaeed32002006-01-13 11:19:13 -0600321 return ret;
322}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600323
Kumar Galaeed32002006-01-13 11:19:13 -0600324arch_initcall(gfar_of_init);
325
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000326#ifdef CONFIG_I2C_BOARDINFO
327#include <linux/i2c.h>
328struct i2c_driver_device {
329 char *of_device;
330 char *i2c_driver;
331 char *i2c_type;
332};
333
334static struct i2c_driver_device i2c_devices[] __initdata = {
335 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
336 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
337 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
338 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
Peter Korsgaard0438c282007-09-20 12:42:13 +0200339 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
340 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
341 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
342 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
343 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
344 {"stm,m41t00", "rtc-ds1307", "m41t00"},
Anton Vorontsovc0e4eb22007-10-02 17:47:43 +0400345 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000346};
347
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000348static int __init of_find_i2c_driver(struct device_node *node,
349 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000350{
351 int i;
352
353 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
354 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
355 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000356 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
357 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
358 strlcpy(info->type, i2c_devices[i].i2c_type,
359 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
360 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000361 return 0;
362 }
363 return -ENODEV;
364}
365
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000366static void __init of_register_i2c_devices(struct device_node *adap_node,
367 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000368{
369 struct device_node *node = NULL;
370
371 while ((node = of_get_next_child(adap_node, node))) {
Anton Vorontsovda1bb3a2007-10-02 17:47:40 +0400372 struct i2c_board_info info = {};
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000373 const u32 *addr;
374 int len;
375
376 addr = of_get_property(node, "reg", &len);
377 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
Peter Korsgaard210805e2007-09-20 12:42:12 +0200378 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000379 continue;
380 }
381
382 info.irq = irq_of_parse_and_map(node, 0);
383 if (info.irq == NO_IRQ)
384 info.irq = -1;
385
386 if (of_find_i2c_driver(node, &info) < 0)
387 continue;
388
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000389 info.addr = *addr;
390
391 i2c_register_board_info(bus_num, &info, 1);
392 }
393}
394
Kumar Galaeed32002006-01-13 11:19:13 -0600395static int __init fsl_i2c_of_init(void)
396{
397 struct device_node *np;
Kumar Galaec9686c2007-12-11 23:17:24 -0600398 unsigned int i = 0;
Kumar Galaeed32002006-01-13 11:19:13 -0600399 struct platform_device *i2c_dev;
400 int ret;
401
Kumar Galaec9686c2007-12-11 23:17:24 -0600402 for_each_compatible_node(np, NULL, "fsl-i2c") {
Kumar Galaeed32002006-01-13 11:19:13 -0600403 struct resource r[2];
404 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000405 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600406
407 memset(&r, 0, sizeof(r));
408 memset(&i2c_data, 0, sizeof(i2c_data));
409
410 ret = of_address_to_resource(np, 0, &r[0]);
411 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600412 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600413
Andy Fleminga9b14972006-10-19 19:52:26 -0500414 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600415
416 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
417 if (IS_ERR(i2c_dev)) {
418 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600419 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600420 }
421
422 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000423 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600424 if (flags)
425 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
426
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000427 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600428 if (flags)
429 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
430
Kumar Gala2fb07d72006-01-23 16:58:04 -0600431 ret =
432 platform_device_add_data(i2c_dev, &i2c_data,
433 sizeof(struct
434 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600435 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600436 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000437
Kumar Galaec9686c2007-12-11 23:17:24 -0600438 of_register_i2c_devices(np, i++);
Kumar Galaeed32002006-01-13 11:19:13 -0600439 }
440
441 return 0;
442
Kumar Gala2fb07d72006-01-23 16:58:04 -0600443unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600444 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600445err:
Kumar Galaeed32002006-01-13 11:19:13 -0600446 return ret;
447}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600448
Kumar Galaeed32002006-01-13 11:19:13 -0600449arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000450#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600451
452#ifdef CONFIG_PPC_83xx
453static int __init mpc83xx_wdt_init(void)
454{
455 struct resource r;
456 struct device_node *soc, *np;
457 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000458 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600459 int ret;
460
461 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
462
463 if (!np) {
464 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600465 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600466 }
467
468 soc = of_find_node_by_type(NULL, "soc");
469
470 if (!soc) {
471 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600472 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600473 }
474
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000475 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600476 if (!freq) {
477 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600478 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600479 }
480
481 memset(&r, 0, sizeof(r));
482
483 ret = of_address_to_resource(np, 0, &r);
484 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600485 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600486
487 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
488 if (IS_ERR(dev)) {
489 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600490 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600491 }
492
493 ret = platform_device_add_data(dev, freq, sizeof(int));
494 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600495 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600496
497 of_node_put(soc);
498 of_node_put(np);
499
500 return 0;
501
Kumar Gala2fb07d72006-01-23 16:58:04 -0600502unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600503 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600504err:
Kumar Galaeed32002006-01-13 11:19:13 -0600505 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600506nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600507 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600508nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600509 return ret;
510}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600511
Kumar Galaeed32002006-01-13 11:19:13 -0600512arch_initcall(mpc83xx_wdt_init);
513#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600514
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000515static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600516{
517 if (!phy_type)
518 return FSL_USB2_PHY_NONE;
519 if (!strcasecmp(phy_type, "ulpi"))
520 return FSL_USB2_PHY_ULPI;
521 if (!strcasecmp(phy_type, "utmi"))
522 return FSL_USB2_PHY_UTMI;
523 if (!strcasecmp(phy_type, "utmi_wide"))
524 return FSL_USB2_PHY_UTMI_WIDE;
525 if (!strcasecmp(phy_type, "serial"))
526 return FSL_USB2_PHY_SERIAL;
527
528 return FSL_USB2_PHY_NONE;
529}
530
531static int __init fsl_usb_of_init(void)
532{
533 struct device_node *np;
534 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800535 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
536 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600537 int ret;
538
539 for (np = NULL, i = 0;
540 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
541 i++) {
542 struct resource r[2];
543 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000544 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600545
546 memset(&r, 0, sizeof(r));
547 memset(&usb_data, 0, sizeof(usb_data));
548
549 ret = of_address_to_resource(np, 0, &r[0]);
550 if (ret)
551 goto err;
552
Andy Fleminga9b14972006-10-19 19:52:26 -0500553 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600554
Kumar Gala01cced22006-04-11 10:07:16 -0500555 usb_dev_mph =
556 platform_device_register_simple("fsl-ehci", i, r, 2);
557 if (IS_ERR(usb_dev_mph)) {
558 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600559 goto err;
560 }
561
Kumar Gala01cced22006-04-11 10:07:16 -0500562 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
563 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600564
565 usb_data.operating_mode = FSL_USB2_MPH_HOST;
566
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000567 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600568 if (prop)
569 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
570
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000571 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600572 if (prop)
573 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
574
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000575 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600576 usb_data.phy_mode = determine_usb_phy(prop);
577
578 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500579 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600580 sizeof(struct
581 fsl_usb2_platform_data));
582 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500583 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600584 }
585
Kumar Gala01cced22006-04-11 10:07:16 -0500586 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600587 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
588 i++) {
589 struct resource r[2];
590 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000591 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600592
593 memset(&r, 0, sizeof(r));
594 memset(&usb_data, 0, sizeof(usb_data));
595
596 ret = of_address_to_resource(np, 0, &r[0]);
597 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500598 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600599
Andy Fleminga9b14972006-10-19 19:52:26 -0500600 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600601
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000602 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800603
604 if (!prop || !strcmp(prop, "host")) {
605 usb_data.operating_mode = FSL_USB2_DR_HOST;
606 usb_dev_dr_host = platform_device_register_simple(
607 "fsl-ehci", i, r, 2);
608 if (IS_ERR(usb_dev_dr_host)) {
609 ret = PTR_ERR(usb_dev_dr_host);
610 goto err;
611 }
612 } else if (prop && !strcmp(prop, "peripheral")) {
613 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
614 usb_dev_dr_client = platform_device_register_simple(
615 "fsl-usb2-udc", i, r, 2);
616 if (IS_ERR(usb_dev_dr_client)) {
617 ret = PTR_ERR(usb_dev_dr_client);
618 goto err;
619 }
620 } else if (prop && !strcmp(prop, "otg")) {
621 usb_data.operating_mode = FSL_USB2_DR_OTG;
622 usb_dev_dr_host = platform_device_register_simple(
623 "fsl-ehci", i, r, 2);
624 if (IS_ERR(usb_dev_dr_host)) {
625 ret = PTR_ERR(usb_dev_dr_host);
626 goto err;
627 }
628 usb_dev_dr_client = platform_device_register_simple(
629 "fsl-usb2-udc", i, r, 2);
630 if (IS_ERR(usb_dev_dr_client)) {
631 ret = PTR_ERR(usb_dev_dr_client);
632 goto err;
633 }
634 } else {
635 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600636 goto err;
637 }
638
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000639 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600640 usb_data.phy_mode = determine_usb_phy(prop);
641
Li Yang97c5a202007-02-07 13:49:24 +0800642 if (usb_dev_dr_host) {
643 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
644 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
645 dev.coherent_dma_mask;
646 if ((ret = platform_device_add_data(usb_dev_dr_host,
647 &usb_data, sizeof(struct
648 fsl_usb2_platform_data))))
649 goto unreg_dr;
650 }
651 if (usb_dev_dr_client) {
652 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
653 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
654 dev.coherent_dma_mask;
655 if ((ret = platform_device_add_data(usb_dev_dr_client,
656 &usb_data, sizeof(struct
657 fsl_usb2_platform_data))))
658 goto unreg_dr;
659 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600660 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600661 return 0;
662
Kumar Gala01cced22006-04-11 10:07:16 -0500663unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800664 if (usb_dev_dr_host)
665 platform_device_unregister(usb_dev_dr_host);
666 if (usb_dev_dr_client)
667 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500668unreg_mph:
669 if (usb_dev_mph)
670 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600671err:
672 return ret;
673}
674
Kumar Gala01cced22006-04-11 10:07:16 -0500675arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400676
Scott Woode631ae32007-09-14 13:04:54 -0500677#ifndef CONFIG_PPC_CPM_NEW_BINDING
Vitaly Bordugfba43662006-09-21 17:26:34 +0400678#ifdef CONFIG_CPM2
679
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300680extern void init_scc_ioports(struct fs_uart_platform_info*);
681
Vitaly Bordugfba43662006-09-21 17:26:34 +0400682static const char fcc_regs[] = "fcc_regs";
683static const char fcc_regs_c[] = "fcc_regs_c";
684static const char fcc_pram[] = "fcc_pram";
685static char bus_id[9][BUS_ID_SIZE];
686
687static int __init fs_enet_of_init(void)
688{
689 struct device_node *np;
690 unsigned int i;
691 struct platform_device *fs_enet_dev;
692 struct resource res;
693 int ret;
694
695 for (np = NULL, i = 0;
696 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
697 i++) {
698 struct resource r[4];
699 struct device_node *phy, *mdio;
700 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500701 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400702 const void *mac_addr;
703 const phandle *ph;
704 const char *model;
705
706 memset(r, 0, sizeof(r));
707 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
708
709 ret = of_address_to_resource(np, 0, &r[0]);
710 if (ret)
711 goto err;
712 r[0].name = fcc_regs;
713
714 ret = of_address_to_resource(np, 1, &r[1]);
715 if (ret)
716 goto err;
717 r[1].name = fcc_pram;
718
719 ret = of_address_to_resource(np, 2, &r[2]);
720 if (ret)
721 goto err;
722 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400723 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400724
Andy Fleminga9b14972006-10-19 19:52:26 -0500725 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400726
727 fs_enet_dev =
728 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
729
730 if (IS_ERR(fs_enet_dev)) {
731 ret = PTR_ERR(fs_enet_dev);
732 goto err;
733 }
734
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000735 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400736 if (model == NULL) {
737 ret = -ENODEV;
738 goto unreg;
739 }
740
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600741 mac_addr = of_get_mac_address(np);
742 if (mac_addr)
743 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400744
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000745 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400746 phy = of_find_node_by_phandle(*ph);
747
748 if (phy == NULL) {
749 ret = -ENODEV;
750 goto unreg;
751 }
752
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000753 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400754 fs_enet_data.phy_addr = *phy_addr;
755
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000756 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400757
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000758 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400759 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400760 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400761
762 mdio = of_get_parent(phy);
763 ret = of_address_to_resource(mdio, 0, &res);
764 if (ret) {
765 of_node_put(phy);
766 of_node_put(mdio);
767 goto unreg;
768 }
769
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000770 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
771 "rx-clock", NULL));
772 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
773 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400774
Vitaly Bordugfba43662006-09-21 17:26:34 +0400775 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400776 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500777 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400778
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400779 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400780 fs_enet_data.rx_ring = 32;
781 fs_enet_data.tx_ring = 32;
782 fs_enet_data.rx_copybreak = 240;
783 fs_enet_data.use_napi = 0;
784 fs_enet_data.napi_weight = 17;
785 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
786 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
787 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
788
789 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
790 (u32)res.start, fs_enet_data.phy_addr);
791 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400792 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400793
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000794 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400795 if (mdio_bb_prop) {
796 struct platform_device *fs_enet_mdio_bb_dev;
797 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400798
Vitaly Borduged943c12006-10-02 22:41:50 +0400799 fs_enet_mdio_bb_dev =
800 platform_device_register_simple("fsl-bb-mdio",
801 i, NULL, 0);
802 memset(&fs_enet_mdio_bb_data, 0,
803 sizeof(struct fs_mii_bb_platform_info));
804 fs_enet_mdio_bb_data.mdio_dat.bit =
805 mdio_bb_prop[0];
806 fs_enet_mdio_bb_data.mdio_dir.bit =
807 mdio_bb_prop[1];
808 fs_enet_mdio_bb_data.mdc_dat.bit =
809 mdio_bb_prop[2];
810 fs_enet_mdio_bb_data.mdio_port =
811 mdio_bb_prop[3];
812 fs_enet_mdio_bb_data.mdc_port =
813 mdio_bb_prop[4];
814 fs_enet_mdio_bb_data.delay =
815 mdio_bb_prop[5];
816
817 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
818 fs_enet_mdio_bb_data.irq[1] = -1;
819 fs_enet_mdio_bb_data.irq[2] = -1;
820 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
821 fs_enet_mdio_bb_data.irq[31] = -1;
822
823 fs_enet_mdio_bb_data.mdio_dat.offset =
824 (u32)&cpm2_immr->im_ioport.iop_pdatc;
825 fs_enet_mdio_bb_data.mdio_dir.offset =
826 (u32)&cpm2_immr->im_ioport.iop_pdirc;
827 fs_enet_mdio_bb_data.mdc_dat.offset =
828 (u32)&cpm2_immr->im_ioport.iop_pdatc;
829
830 ret = platform_device_add_data(
831 fs_enet_mdio_bb_dev,
832 &fs_enet_mdio_bb_data,
833 sizeof(struct fs_mii_bb_platform_info));
834 if (ret)
835 goto unreg;
836 }
Li Yang97c5a202007-02-07 13:49:24 +0800837
Vitaly Borduged943c12006-10-02 22:41:50 +0400838 of_node_put(phy);
839 of_node_put(mdio);
840
841 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
842 sizeof(struct
843 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500844 if (ret)
845 goto unreg;
846 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400847 }
848 return 0;
849
850unreg:
851 platform_device_unregister(fs_enet_dev);
852err:
853 return ret;
854}
855
856arch_initcall(fs_enet_of_init);
857
858static const char scc_regs[] = "regs";
859static const char scc_pram[] = "pram";
860
861static int __init cpm_uart_of_init(void)
862{
863 struct device_node *np;
864 unsigned int i;
865 struct platform_device *cpm_uart_dev;
866 int ret;
867
868 for (np = NULL, i = 0;
869 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
870 i++) {
871 struct resource r[3];
872 struct fs_uart_platform_info cpm_uart_data;
873 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400874 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400875
876 memset(r, 0, sizeof(r));
877 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
878
879 ret = of_address_to_resource(np, 0, &r[0]);
880 if (ret)
881 goto err;
882
883 r[0].name = scc_regs;
884
885 ret = of_address_to_resource(np, 1, &r[1]);
886 if (ret)
887 goto err;
888 r[1].name = scc_pram;
889
Andy Fleminga9b14972006-10-19 19:52:26 -0500890 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400891
892 cpm_uart_dev =
893 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
894
895 if (IS_ERR(cpm_uart_dev)) {
896 ret = PTR_ERR(cpm_uart_dev);
897 goto err;
898 }
899
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000900 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400901 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400902
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000903 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400904 strcpy(cpm_uart_data.fs_type, model);
905
Vitaly Bordugfba43662006-09-21 17:26:34 +0400906 cpm_uart_data.uart_clk = ppc_proc_freq;
907
908 cpm_uart_data.tx_num_fifo = 4;
909 cpm_uart_data.tx_buf_size = 32;
910 cpm_uart_data.rx_num_fifo = 4;
911 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000912 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
913 "rx-clock", NULL));
914 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
915 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400916
917 ret =
918 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
919 sizeof(struct
920 fs_uart_platform_info));
921 if (ret)
922 goto unreg;
923 }
924
925 return 0;
926
927unreg:
928 platform_device_unregister(cpm_uart_dev);
929err:
930 return ret;
931}
932
933arch_initcall(cpm_uart_of_init);
934#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300935
936#ifdef CONFIG_8xx
937
938extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000939extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300940
941static int __init fs_enet_mdio_of_init(void)
942{
943 struct device_node *np;
944 unsigned int i;
945 struct platform_device *mdio_dev;
946 struct resource res;
947 int ret;
948
949 for (np = NULL, i = 0;
950 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
951 i++) {
952 struct fs_mii_fec_platform_info mdio_data;
953
954 memset(&res, 0, sizeof(res));
955 memset(&mdio_data, 0, sizeof(mdio_data));
956
957 ret = of_address_to_resource(np, 0, &res);
958 if (ret)
959 goto err;
960
961 mdio_dev =
962 platform_device_register_simple("fsl-cpm-fec-mdio",
963 res.start, &res, 1);
964 if (IS_ERR(mdio_dev)) {
965 ret = PTR_ERR(mdio_dev);
966 goto err;
967 }
968
969 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
970
971 ret =
972 platform_device_add_data(mdio_dev, &mdio_data,
973 sizeof(struct fs_mii_fec_platform_info));
974 if (ret)
975 goto unreg;
976 }
977 return 0;
978
979unreg:
980 platform_device_unregister(mdio_dev);
981err:
982 return ret;
983}
984
985arch_initcall(fs_enet_mdio_of_init);
986
987static const char *enet_regs = "regs";
988static const char *enet_pram = "pram";
989static const char *enet_irq = "interrupt";
990static char bus_id[9][BUS_ID_SIZE];
991
992static int __init fs_enet_of_init(void)
993{
994 struct device_node *np;
995 unsigned int i;
996 struct platform_device *fs_enet_dev = NULL;
997 struct resource res;
998 int ret;
999
1000 for (np = NULL, i = 0;
1001 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
1002 i++) {
1003 struct resource r[4];
1004 struct device_node *phy = NULL, *mdio = NULL;
1005 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001006 const unsigned int *id;
1007 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +10001008 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001009 const phandle *ph;
1010 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001011
1012 memset(r, 0, sizeof(r));
1013 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1014
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001015 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001016 if (model == NULL) {
1017 ret = -ENODEV;
1018 goto unreg;
1019 }
1020
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001021 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001022 fs_enet_data.fs_no = *id;
1023
1024 if (platform_device_skip(model, *id))
1025 continue;
1026
1027 ret = of_address_to_resource(np, 0, &r[0]);
1028 if (ret)
1029 goto err;
1030 r[0].name = enet_regs;
1031
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001032 mac_addr = of_get_mac_address(np);
1033 if (mac_addr)
1034 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001035
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001036 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001037 if (ph != NULL)
1038 phy = of_find_node_by_phandle(*ph);
1039
1040 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001041 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001042 fs_enet_data.phy_addr = *phy_addr;
1043 fs_enet_data.has_phy = 1;
1044
1045 mdio = of_get_parent(phy);
1046 ret = of_address_to_resource(mdio, 0, &res);
1047 if (ret) {
1048 of_node_put(phy);
1049 of_node_put(mdio);
1050 goto unreg;
1051 }
1052 }
1053
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001054 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001055 strcpy(fs_enet_data.fs_type, model);
1056
1057 if (strstr(model, "FEC")) {
1058 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1059 r[1].flags = IORESOURCE_IRQ;
1060 r[1].name = enet_irq;
1061
1062 fs_enet_dev =
1063 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1064
1065 if (IS_ERR(fs_enet_dev)) {
1066 ret = PTR_ERR(fs_enet_dev);
1067 goto err;
1068 }
1069
1070 fs_enet_data.rx_ring = 128;
1071 fs_enet_data.tx_ring = 16;
1072 fs_enet_data.rx_copybreak = 240;
1073 fs_enet_data.use_napi = 1;
1074 fs_enet_data.napi_weight = 17;
1075
1076 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1077 (u32)res.start, fs_enet_data.phy_addr);
1078 fs_enet_data.bus_id = (char*)&bus_id[i];
1079 fs_enet_data.init_ioports = init_fec_ioports;
1080 }
1081 if (strstr(model, "SCC")) {
1082 ret = of_address_to_resource(np, 1, &r[1]);
1083 if (ret)
1084 goto err;
1085 r[1].name = enet_pram;
1086
1087 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1088 r[2].flags = IORESOURCE_IRQ;
1089 r[2].name = enet_irq;
1090
1091 fs_enet_dev =
1092 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1093
1094 if (IS_ERR(fs_enet_dev)) {
1095 ret = PTR_ERR(fs_enet_dev);
1096 goto err;
1097 }
1098
1099 fs_enet_data.rx_ring = 64;
1100 fs_enet_data.tx_ring = 8;
1101 fs_enet_data.rx_copybreak = 240;
1102 fs_enet_data.use_napi = 1;
1103 fs_enet_data.napi_weight = 17;
1104
1105 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1106 fs_enet_data.bus_id = (char*)&bus_id[i];
1107 fs_enet_data.init_ioports = init_scc_ioports;
1108 }
1109
1110 of_node_put(phy);
1111 of_node_put(mdio);
1112
1113 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1114 sizeof(struct
1115 fs_platform_info));
1116 if (ret)
1117 goto unreg;
1118 }
1119 return 0;
1120
1121unreg:
1122 platform_device_unregister(fs_enet_dev);
1123err:
1124 return ret;
1125}
1126
1127arch_initcall(fs_enet_of_init);
1128
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001129static int __init fsl_pcmcia_of_init(void)
1130{
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +11001131 struct device_node *np;
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001132 /*
1133 * Register all the devices which type is "pcmcia"
1134 */
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +11001135 for_each_compatible_node(np, "pcmcia", "fsl,pq-pcmcia")
1136 of_platform_device_create(np, "m8xx-pcmcia", NULL);
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001137 return 0;
1138}
1139
1140arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001141
1142static const char *smc_regs = "regs";
1143static const char *smc_pram = "pram";
1144
1145static int __init cpm_smc_uart_of_init(void)
1146{
1147 struct device_node *np;
1148 unsigned int i;
1149 struct platform_device *cpm_uart_dev;
1150 int ret;
1151
1152 for (np = NULL, i = 0;
1153 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1154 i++) {
1155 struct resource r[3];
1156 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001157 const int *id;
1158 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001159
1160 memset(r, 0, sizeof(r));
1161 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1162
1163 ret = of_address_to_resource(np, 0, &r[0]);
1164 if (ret)
1165 goto err;
1166
1167 r[0].name = smc_regs;
1168
1169 ret = of_address_to_resource(np, 1, &r[1]);
1170 if (ret)
1171 goto err;
1172 r[1].name = smc_pram;
1173
1174 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1175 r[2].flags = IORESOURCE_IRQ;
1176
1177 cpm_uart_dev =
1178 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1179
1180 if (IS_ERR(cpm_uart_dev)) {
1181 ret = PTR_ERR(cpm_uart_dev);
1182 goto err;
1183 }
1184
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001185 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001186 strcpy(cpm_uart_data.fs_type, model);
1187
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001188 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001189 cpm_uart_data.fs_no = *id;
1190 cpm_uart_data.uart_clk = ppc_proc_freq;
1191
1192 cpm_uart_data.tx_num_fifo = 4;
1193 cpm_uart_data.tx_buf_size = 32;
1194 cpm_uart_data.rx_num_fifo = 4;
1195 cpm_uart_data.rx_buf_size = 32;
1196
1197 ret =
1198 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1199 sizeof(struct
1200 fs_uart_platform_info));
1201 if (ret)
1202 goto unreg;
1203 }
1204
1205 return 0;
1206
1207unreg:
1208 platform_device_unregister(cpm_uart_dev);
1209err:
1210 return ret;
1211}
1212
1213arch_initcall(cpm_smc_uart_of_init);
1214
1215#endif /* CONFIG_8xx */
Scott Woode631ae32007-09-14 13:04:54 -05001216#endif /* CONFIG_PPC_CPM_NEW_BINDING */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001217
1218int __init fsl_spi_init(struct spi_board_info *board_infos,
1219 unsigned int num_board_infos,
1220 void (*activate_cs)(u8 cs, u8 polarity),
1221 void (*deactivate_cs)(u8 cs, u8 polarity))
1222{
1223 struct device_node *np;
1224 unsigned int i;
1225 const u32 *sysclk;
1226
Peter Korsgaard082ea862007-10-06 22:06:40 +02001227 /* SPI controller is either clocked from QE or SoC clock */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001228 np = of_find_node_by_type(NULL, "qe");
1229 if (!np)
Peter Korsgaard082ea862007-10-06 22:06:40 +02001230 np = of_find_node_by_type(NULL, "soc");
1231
1232 if (!np)
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001233 return -ENODEV;
1234
1235 sysclk = of_get_property(np, "bus-frequency", NULL);
1236 if (!sysclk)
1237 return -ENODEV;
1238
1239 for (np = NULL, i = 1;
1240 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1241 i++) {
1242 int ret = 0;
1243 unsigned int j;
1244 const void *prop;
1245 struct resource res[2];
1246 struct platform_device *pdev;
1247 struct fsl_spi_platform_data pdata = {
1248 .activate_cs = activate_cs,
1249 .deactivate_cs = deactivate_cs,
1250 };
1251
1252 memset(res, 0, sizeof(res));
1253
1254 pdata.sysclk = *sysclk;
1255
1256 prop = of_get_property(np, "reg", NULL);
1257 if (!prop)
1258 goto err;
1259 pdata.bus_num = *(u32 *)prop;
1260
1261 prop = of_get_property(np, "mode", NULL);
1262 if (prop && !strcmp(prop, "cpu-qe"))
1263 pdata.qe_mode = 1;
1264
1265 for (j = 0; j < num_board_infos; j++) {
1266 if (board_infos[j].bus_num == pdata.bus_num)
1267 pdata.max_chipselect++;
1268 }
1269
1270 if (!pdata.max_chipselect)
1271 goto err;
1272
1273 ret = of_address_to_resource(np, 0, &res[0]);
1274 if (ret)
1275 goto err;
1276
1277 ret = of_irq_to_resource(np, 0, &res[1]);
1278 if (ret == NO_IRQ)
1279 goto err;
1280
1281 pdev = platform_device_alloc("mpc83xx_spi", i);
1282 if (!pdev)
1283 goto err;
1284
1285 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1286 if (ret)
1287 goto unreg;
1288
1289 ret = platform_device_add_resources(pdev, res,
1290 ARRAY_SIZE(res));
1291 if (ret)
1292 goto unreg;
1293
1294 ret = platform_device_register(pdev);
1295 if (ret)
1296 goto unreg;
1297
1298 continue;
1299unreg:
1300 platform_device_del(pdev);
1301err:
1302 continue;
1303 }
1304
1305 return spi_register_board_info(board_infos, num_board_infos);
1306}
Kumar Galae1c15752007-10-04 01:04:57 -05001307
1308#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1309static __be32 __iomem *rstcr;
1310
1311static int __init setup_rstcr(void)
1312{
1313 struct device_node *np;
1314 np = of_find_node_by_name(NULL, "global-utilities");
1315 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
1316 const u32 *prop = of_get_property(np, "reg", NULL);
1317 if (prop) {
1318 /* map reset control register
1319 * 0xE00B0 is offset of reset control register
1320 */
1321 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
1322 if (!rstcr)
1323 printk (KERN_EMERG "Error: reset control "
1324 "register not mapped!\n");
1325 }
1326 } else
1327 printk (KERN_INFO "rstcr compatible register does not exist!\n");
1328 if (np)
1329 of_node_put(np);
1330 return 0;
1331}
1332
1333arch_initcall(setup_rstcr);
1334
1335void fsl_rstcr_restart(char *cmd)
1336{
1337 local_irq_disable();
1338 if (rstcr)
1339 /* set reset control register */
1340 out_be32(rstcr, 0x2); /* HRESET_REQ */
1341
1342 while (1) ;
1343}
1344#endif