blob: 26f7d83c4be548c9e379f87d75f528468c0c93dc [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>
Vitaly Borduga21e2822007-12-07 01:51:31 +030027#include <linux/phy_fixed.h>
Anton Vorontsov26f6cb92007-08-23 15:35:56 +040028#include <linux/spi/spi.h>
Kumar Galaeed32002006-01-13 11:19:13 -060029#include <linux/fsl_devices.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040030#include <linux/fs_enet_pd.h>
31#include <linux/fs_uart_pd.h>
Kumar Galaeed32002006-01-13 11:19:13 -060032
33#include <asm/system.h>
34#include <asm/atomic.h>
35#include <asm/io.h>
36#include <asm/irq.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040037#include <asm/time.h>
Kumar Galaeed32002006-01-13 11:19:13 -060038#include <asm/prom.h>
39#include <sysdev/fsl_soc.h>
40#include <mm/mmu_decl.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040041#include <asm/cpm2.h>
Kumar Galaeed32002006-01-13 11:19:13 -060042
Vitaly Bordugd3465c92006-09-21 22:38:05 +040043extern void init_fcc_ioports(struct fs_platform_info*);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030044extern void init_fec_ioports(struct fs_platform_info*);
45extern void init_smc_ioports(struct fs_uart_platform_info*);
Kumar Galaeed32002006-01-13 11:19:13 -060046static phys_addr_t immrbase = -1;
47
48phys_addr_t get_immrbase(void)
49{
50 struct device_node *soc;
51
52 if (immrbase != -1)
53 return immrbase;
54
55 soc = of_find_node_by_type(NULL, "soc");
Kumar Gala2fb07d72006-01-23 16:58:04 -060056 if (soc) {
Scott Woodf9234732007-08-20 11:38:12 -050057 int size;
Scott Wood6c7e0722008-01-14 10:29:35 -060058 u32 naddr;
59 const u32 *prop = of_get_property(soc, "#address-cells", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040060
Scott Wood6c7e0722008-01-14 10:29:35 -060061 if (prop && size == 4)
62 naddr = *prop;
63 else
64 naddr = 2;
65
66 prop = of_get_property(soc, "ranges", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040067 if (prop)
Scott Wood6c7e0722008-01-14 10:29:35 -060068 immrbase = of_translate_address(soc, prop + naddr);
69
Kumar Galaeed32002006-01-13 11:19:13 -060070 of_node_put(soc);
Scott Woodf9234732007-08-20 11:38:12 -050071 }
Kumar Galaeed32002006-01-13 11:19:13 -060072
73 return immrbase;
74}
Kumar Gala2fb07d72006-01-23 16:58:04 -060075
Kumar Galaeed32002006-01-13 11:19:13 -060076EXPORT_SYMBOL(get_immrbase);
77
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030078#if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
Vitaly Bordugfba43662006-09-21 17:26:34 +040079
80static u32 brgfreq = -1;
81
82u32 get_brgfreq(void)
83{
84 struct device_node *node;
Scott Wood6d817aa2007-08-29 15:08:40 -050085 const unsigned int *prop;
86 int size;
Vitaly Bordugfba43662006-09-21 17:26:34 +040087
88 if (brgfreq != -1)
89 return brgfreq;
90
Scott Wood6d817aa2007-08-29 15:08:40 -050091 node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
Vitaly Bordugfba43662006-09-21 17:26:34 +040092 if (node) {
Scott Wood6d817aa2007-08-29 15:08:40 -050093 prop = of_get_property(node, "clock-frequency", &size);
94 if (prop && size == 4)
95 brgfreq = *prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +040096
Scott Wood6d817aa2007-08-29 15:08:40 -050097 of_node_put(node);
98 return brgfreq;
99 }
100
101 /* Legacy device binding -- will go away when no users are left. */
102 node = of_find_node_by_type(NULL, "cpm");
103 if (node) {
104 prop = of_get_property(node, "brg-frequency", &size);
Scott Woodf9234732007-08-20 11:38:12 -0500105 if (prop && size == 4)
Vitaly Bordugfba43662006-09-21 17:26:34 +0400106 brgfreq = *prop;
Scott Woodf9234732007-08-20 11:38:12 -0500107
Vitaly Bordugfba43662006-09-21 17:26:34 +0400108 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500109 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400110
111 return brgfreq;
112}
113
114EXPORT_SYMBOL(get_brgfreq);
115
116static u32 fs_baudrate = -1;
117
118u32 get_baudrate(void)
119{
120 struct device_node *node;
121
122 if (fs_baudrate != -1)
123 return fs_baudrate;
124
125 node = of_find_node_by_type(NULL, "serial");
126 if (node) {
Scott Woodf9234732007-08-20 11:38:12 -0500127 int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000128 const unsigned int *prop = of_get_property(node,
129 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400130
131 if (prop)
132 fs_baudrate = *prop;
133 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500134 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400135
136 return fs_baudrate;
137}
138
139EXPORT_SYMBOL(get_baudrate);
140#endif /* CONFIG_CPM2 */
141
Vitaly Borduga21e2822007-12-07 01:51:31 +0300142#ifdef CONFIG_FIXED_PHY
143static int __init of_add_fixed_phys(void)
144{
145 int ret;
146 struct device_node *np;
147 u32 *fixed_link;
148 struct fixed_phy_status status = {};
149
150 for_each_node_by_name(np, "ethernet") {
151 fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
152 if (!fixed_link)
153 continue;
154
155 status.link = 1;
156 status.duplex = fixed_link[1];
157 status.speed = fixed_link[2];
158 status.pause = fixed_link[3];
159 status.asym_pause = fixed_link[4];
160
161 ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
162 if (ret) {
163 of_node_put(np);
164 return ret;
165 }
166 }
167
168 return 0;
169}
170arch_initcall(of_add_fixed_phys);
171#endif /* CONFIG_FIXED_PHY */
172
Kumar Gala2fb07d72006-01-23 16:58:04 -0600173static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600174{
Kumar Galae77b28e2007-12-12 00:28:35 -0600175 struct device_node *np = NULL;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600176 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600177 struct resource res;
178 int ret;
179
Kumar Galae77b28e2007-12-12 00:28:35 -0600180 np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
181
182 /* try the deprecated version */
183 if (!np)
184 np = of_find_compatible_node(np, "mdio", "gianfar");
185
186 if (np) {
Kumar Galaeed32002006-01-13 11:19:13 -0600187 int k;
188 struct device_node *child = NULL;
189 struct gianfar_mdio_data mdio_data;
190
191 memset(&res, 0, sizeof(res));
192 memset(&mdio_data, 0, sizeof(mdio_data));
193
194 ret = of_address_to_resource(np, 0, &res);
195 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600196 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600197
Kumar Gala2fb07d72006-01-23 16:58:04 -0600198 mdio_dev =
199 platform_device_register_simple("fsl-gianfar_mdio",
200 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600201 if (IS_ERR(mdio_dev)) {
202 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600203 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600204 }
205
206 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500207 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600208
209 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400210 int irq = irq_of_parse_and_map(child, 0);
211 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000212 const u32 *id = of_get_property(child,
213 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400214 mdio_data.irq[*id] = irq;
215 }
Kumar Galaeed32002006-01-13 11:19:13 -0600216 }
217
Kumar Gala2fb07d72006-01-23 16:58:04 -0600218 ret =
219 platform_device_add_data(mdio_dev, &mdio_data,
220 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600221 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600222 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600223 }
224
Kumar Galae77b28e2007-12-12 00:28:35 -0600225 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600226 return 0;
227
228unreg:
229 platform_device_unregister(mdio_dev);
230err:
Kumar Galae77b28e2007-12-12 00:28:35 -0600231 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600232 return ret;
233}
234
235arch_initcall(gfar_mdio_of_init);
236
237static const char *gfar_tx_intr = "tx";
238static const char *gfar_rx_intr = "rx";
239static const char *gfar_err_intr = "error";
240
241static int __init gfar_of_init(void)
242{
243 struct device_node *np;
244 unsigned int i;
245 struct platform_device *gfar_dev;
246 struct resource res;
247 int ret;
248
249 for (np = NULL, i = 0;
250 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
251 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600252 struct resource r[4];
253 struct device_node *phy, *mdio;
254 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000255 const unsigned int *id;
256 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500257 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000258 const void *mac_addr;
259 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400260 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600261
262 memset(r, 0, sizeof(r));
263 memset(&gfar_data, 0, sizeof(gfar_data));
264
265 ret = of_address_to_resource(np, 0, &r[0]);
266 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600267 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600268
Andy Fleminga9b14972006-10-19 19:52:26 -0500269 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600270
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000271 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600272
273 /* If we aren't the FEC we have multiple interrupts */
274 if (model && strcasecmp(model, "FEC")) {
275 r[1].name = gfar_tx_intr;
276
277 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500278 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600279
280 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500281 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500282
283 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600284 }
285
Kumar Gala2fb07d72006-01-23 16:58:04 -0600286 gfar_dev =
287 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400288 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600289
290 if (IS_ERR(gfar_dev)) {
291 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600292 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600293 }
294
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600295 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500296 if (mac_addr)
297 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600298
299 if (model && !strcasecmp(model, "TSEC"))
300 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600301 FSL_GIANFAR_DEV_HAS_GIGABIT |
302 FSL_GIANFAR_DEV_HAS_COALESCE |
303 FSL_GIANFAR_DEV_HAS_RMON |
304 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600305 if (model && !strcasecmp(model, "eTSEC"))
306 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600307 FSL_GIANFAR_DEV_HAS_GIGABIT |
308 FSL_GIANFAR_DEV_HAS_COALESCE |
309 FSL_GIANFAR_DEV_HAS_RMON |
310 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
311 FSL_GIANFAR_DEV_HAS_CSUM |
312 FSL_GIANFAR_DEV_HAS_VLAN |
313 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600314
Andy Fleming7132ab72007-07-11 11:43:07 -0500315 ctype = of_get_property(np, "phy-connection-type", NULL);
316
317 /* We only care about rgmii-id. The rest are autodetected */
318 if (ctype && !strcmp(ctype, "rgmii-id"))
319 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
320 else
321 gfar_data.interface = PHY_INTERFACE_MODE_MII;
322
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000323 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300324 if (ph == NULL) {
325 u32 *fixed_link;
Kumar Galaeed32002006-01-13 11:19:13 -0600326
Vitaly Borduga21e2822007-12-07 01:51:31 +0300327 fixed_link = (u32 *)of_get_property(np, "fixed-link",
328 NULL);
329 if (!fixed_link) {
330 ret = -ENODEV;
331 goto unreg;
332 }
Kumar Galaeed32002006-01-13 11:19:13 -0600333
Vitaly Borduga21e2822007-12-07 01:51:31 +0300334 gfar_data.bus_id = 0;
335 gfar_data.phy_id = fixed_link[0];
336 } else {
337 phy = of_find_node_by_phandle(*ph);
Kumar Galaeed32002006-01-13 11:19:13 -0600338
Vitaly Borduga21e2822007-12-07 01:51:31 +0300339 if (phy == NULL) {
340 ret = -ENODEV;
341 goto unreg;
342 }
343
344 mdio = of_get_parent(phy);
345
346 id = of_get_property(phy, "reg", NULL);
347 ret = of_address_to_resource(mdio, 0, &res);
348 if (ret) {
349 of_node_put(phy);
350 of_node_put(mdio);
351 goto unreg;
352 }
353
354 gfar_data.phy_id = *id;
355 gfar_data.bus_id = res.start;
356
Kumar Galaeed32002006-01-13 11:19:13 -0600357 of_node_put(phy);
358 of_node_put(mdio);
Kumar Galaeed32002006-01-13 11:19:13 -0600359 }
360
Kumar Gala2fb07d72006-01-23 16:58:04 -0600361 ret =
362 platform_device_add_data(gfar_dev, &gfar_data,
363 sizeof(struct
364 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600365 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600366 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600367 }
368
369 return 0;
370
Kumar Gala2fb07d72006-01-23 16:58:04 -0600371unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600372 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600373err:
Kumar Galaeed32002006-01-13 11:19:13 -0600374 return ret;
375}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600376
Kumar Galaeed32002006-01-13 11:19:13 -0600377arch_initcall(gfar_of_init);
378
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000379#ifdef CONFIG_I2C_BOARDINFO
380#include <linux/i2c.h>
381struct i2c_driver_device {
382 char *of_device;
383 char *i2c_driver;
384 char *i2c_type;
385};
386
387static struct i2c_driver_device i2c_devices[] __initdata = {
388 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
389 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
390 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
391 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
Peter Korsgaard0438c282007-09-20 12:42:13 +0200392 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
393 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
394 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
395 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
396 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
397 {"stm,m41t00", "rtc-ds1307", "m41t00"},
Anton Vorontsovc0e4eb22007-10-02 17:47:43 +0400398 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000399};
400
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000401static int __init of_find_i2c_driver(struct device_node *node,
402 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000403{
404 int i;
405
406 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
407 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
408 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000409 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
410 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
411 strlcpy(info->type, i2c_devices[i].i2c_type,
412 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
413 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000414 return 0;
415 }
416 return -ENODEV;
417}
418
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000419static void __init of_register_i2c_devices(struct device_node *adap_node,
420 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000421{
422 struct device_node *node = NULL;
423
424 while ((node = of_get_next_child(adap_node, node))) {
Anton Vorontsovda1bb3a2007-10-02 17:47:40 +0400425 struct i2c_board_info info = {};
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000426 const u32 *addr;
427 int len;
428
429 addr = of_get_property(node, "reg", &len);
430 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
Peter Korsgaard210805e2007-09-20 12:42:12 +0200431 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000432 continue;
433 }
434
435 info.irq = irq_of_parse_and_map(node, 0);
436 if (info.irq == NO_IRQ)
437 info.irq = -1;
438
439 if (of_find_i2c_driver(node, &info) < 0)
440 continue;
441
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000442 info.addr = *addr;
443
444 i2c_register_board_info(bus_num, &info, 1);
445 }
446}
447
Kumar Galaeed32002006-01-13 11:19:13 -0600448static int __init fsl_i2c_of_init(void)
449{
450 struct device_node *np;
Kumar Galaec9686c2007-12-11 23:17:24 -0600451 unsigned int i = 0;
Kumar Galaeed32002006-01-13 11:19:13 -0600452 struct platform_device *i2c_dev;
453 int ret;
454
Kumar Galaec9686c2007-12-11 23:17:24 -0600455 for_each_compatible_node(np, NULL, "fsl-i2c") {
Kumar Galaeed32002006-01-13 11:19:13 -0600456 struct resource r[2];
457 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000458 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600459
460 memset(&r, 0, sizeof(r));
461 memset(&i2c_data, 0, sizeof(i2c_data));
462
463 ret = of_address_to_resource(np, 0, &r[0]);
464 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600465 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600466
Andy Fleminga9b14972006-10-19 19:52:26 -0500467 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600468
469 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
470 if (IS_ERR(i2c_dev)) {
471 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600472 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600473 }
474
475 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000476 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600477 if (flags)
478 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
479
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000480 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600481 if (flags)
482 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
483
Kumar Gala2fb07d72006-01-23 16:58:04 -0600484 ret =
485 platform_device_add_data(i2c_dev, &i2c_data,
486 sizeof(struct
487 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600488 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600489 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000490
Kumar Galaec9686c2007-12-11 23:17:24 -0600491 of_register_i2c_devices(np, i++);
Kumar Galaeed32002006-01-13 11:19:13 -0600492 }
493
494 return 0;
495
Kumar Gala2fb07d72006-01-23 16:58:04 -0600496unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600497 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600498err:
Kumar Galaeed32002006-01-13 11:19:13 -0600499 return ret;
500}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600501
Kumar Galaeed32002006-01-13 11:19:13 -0600502arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000503#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600504
505#ifdef CONFIG_PPC_83xx
506static int __init mpc83xx_wdt_init(void)
507{
508 struct resource r;
509 struct device_node *soc, *np;
510 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000511 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600512 int ret;
513
514 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
515
516 if (!np) {
517 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600518 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600519 }
520
521 soc = of_find_node_by_type(NULL, "soc");
522
523 if (!soc) {
524 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600525 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600526 }
527
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000528 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600529 if (!freq) {
530 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600531 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600532 }
533
534 memset(&r, 0, sizeof(r));
535
536 ret = of_address_to_resource(np, 0, &r);
537 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600538 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600539
540 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
541 if (IS_ERR(dev)) {
542 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600543 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600544 }
545
546 ret = platform_device_add_data(dev, freq, sizeof(int));
547 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600548 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600549
550 of_node_put(soc);
551 of_node_put(np);
552
553 return 0;
554
Kumar Gala2fb07d72006-01-23 16:58:04 -0600555unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600556 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600557err:
Kumar Galaeed32002006-01-13 11:19:13 -0600558 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600559nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600560 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600561nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600562 return ret;
563}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600564
Kumar Galaeed32002006-01-13 11:19:13 -0600565arch_initcall(mpc83xx_wdt_init);
566#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600567
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000568static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600569{
570 if (!phy_type)
571 return FSL_USB2_PHY_NONE;
572 if (!strcasecmp(phy_type, "ulpi"))
573 return FSL_USB2_PHY_ULPI;
574 if (!strcasecmp(phy_type, "utmi"))
575 return FSL_USB2_PHY_UTMI;
576 if (!strcasecmp(phy_type, "utmi_wide"))
577 return FSL_USB2_PHY_UTMI_WIDE;
578 if (!strcasecmp(phy_type, "serial"))
579 return FSL_USB2_PHY_SERIAL;
580
581 return FSL_USB2_PHY_NONE;
582}
583
584static int __init fsl_usb_of_init(void)
585{
586 struct device_node *np;
Li Yang866b6dd2008-01-08 15:18:46 +0800587 unsigned int i = 0;
Li Yang97c5a202007-02-07 13:49:24 +0800588 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
589 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600590 int ret;
591
Li Yang866b6dd2008-01-08 15:18:46 +0800592 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600593 struct resource r[2];
594 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000595 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600596
597 memset(&r, 0, sizeof(r));
598 memset(&usb_data, 0, sizeof(usb_data));
599
600 ret = of_address_to_resource(np, 0, &r[0]);
601 if (ret)
602 goto err;
603
Andy Fleminga9b14972006-10-19 19:52:26 -0500604 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600605
Kumar Gala01cced22006-04-11 10:07:16 -0500606 usb_dev_mph =
607 platform_device_register_simple("fsl-ehci", i, r, 2);
608 if (IS_ERR(usb_dev_mph)) {
609 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600610 goto err;
611 }
612
Kumar Gala01cced22006-04-11 10:07:16 -0500613 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
614 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600615
616 usb_data.operating_mode = FSL_USB2_MPH_HOST;
617
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000618 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600619 if (prop)
620 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
621
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000622 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600623 if (prop)
624 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
625
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000626 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600627 usb_data.phy_mode = determine_usb_phy(prop);
628
629 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500630 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600631 sizeof(struct
632 fsl_usb2_platform_data));
633 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500634 goto unreg_mph;
Li Yang866b6dd2008-01-08 15:18:46 +0800635 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600636 }
637
Li Yang866b6dd2008-01-08 15:18:46 +0800638 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600639 struct resource r[2];
640 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000641 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600642
643 memset(&r, 0, sizeof(r));
644 memset(&usb_data, 0, sizeof(usb_data));
645
646 ret = of_address_to_resource(np, 0, &r[0]);
647 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500648 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600649
Andy Fleminga9b14972006-10-19 19:52:26 -0500650 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600651
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000652 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800653
654 if (!prop || !strcmp(prop, "host")) {
655 usb_data.operating_mode = FSL_USB2_DR_HOST;
656 usb_dev_dr_host = platform_device_register_simple(
657 "fsl-ehci", i, r, 2);
658 if (IS_ERR(usb_dev_dr_host)) {
659 ret = PTR_ERR(usb_dev_dr_host);
660 goto err;
661 }
662 } else if (prop && !strcmp(prop, "peripheral")) {
663 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
664 usb_dev_dr_client = platform_device_register_simple(
665 "fsl-usb2-udc", i, r, 2);
666 if (IS_ERR(usb_dev_dr_client)) {
667 ret = PTR_ERR(usb_dev_dr_client);
668 goto err;
669 }
670 } else if (prop && !strcmp(prop, "otg")) {
671 usb_data.operating_mode = FSL_USB2_DR_OTG;
672 usb_dev_dr_host = platform_device_register_simple(
673 "fsl-ehci", i, r, 2);
674 if (IS_ERR(usb_dev_dr_host)) {
675 ret = PTR_ERR(usb_dev_dr_host);
676 goto err;
677 }
678 usb_dev_dr_client = platform_device_register_simple(
679 "fsl-usb2-udc", i, r, 2);
680 if (IS_ERR(usb_dev_dr_client)) {
681 ret = PTR_ERR(usb_dev_dr_client);
682 goto err;
683 }
684 } else {
685 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600686 goto err;
687 }
688
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000689 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600690 usb_data.phy_mode = determine_usb_phy(prop);
691
Li Yang97c5a202007-02-07 13:49:24 +0800692 if (usb_dev_dr_host) {
693 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
694 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
695 dev.coherent_dma_mask;
696 if ((ret = platform_device_add_data(usb_dev_dr_host,
697 &usb_data, sizeof(struct
698 fsl_usb2_platform_data))))
699 goto unreg_dr;
700 }
701 if (usb_dev_dr_client) {
702 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
703 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
704 dev.coherent_dma_mask;
705 if ((ret = platform_device_add_data(usb_dev_dr_client,
706 &usb_data, sizeof(struct
707 fsl_usb2_platform_data))))
708 goto unreg_dr;
709 }
Li Yang866b6dd2008-01-08 15:18:46 +0800710 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600711 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600712 return 0;
713
Kumar Gala01cced22006-04-11 10:07:16 -0500714unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800715 if (usb_dev_dr_host)
716 platform_device_unregister(usb_dev_dr_host);
717 if (usb_dev_dr_client)
718 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500719unreg_mph:
720 if (usb_dev_mph)
721 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600722err:
723 return ret;
724}
725
Kumar Gala01cced22006-04-11 10:07:16 -0500726arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400727
Scott Woode631ae32007-09-14 13:04:54 -0500728#ifndef CONFIG_PPC_CPM_NEW_BINDING
Vitaly Bordugfba43662006-09-21 17:26:34 +0400729#ifdef CONFIG_CPM2
730
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300731extern void init_scc_ioports(struct fs_uart_platform_info*);
732
Vitaly Bordugfba43662006-09-21 17:26:34 +0400733static const char fcc_regs[] = "fcc_regs";
734static const char fcc_regs_c[] = "fcc_regs_c";
735static const char fcc_pram[] = "fcc_pram";
736static char bus_id[9][BUS_ID_SIZE];
737
738static int __init fs_enet_of_init(void)
739{
740 struct device_node *np;
741 unsigned int i;
742 struct platform_device *fs_enet_dev;
743 struct resource res;
744 int ret;
745
746 for (np = NULL, i = 0;
747 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
748 i++) {
749 struct resource r[4];
750 struct device_node *phy, *mdio;
751 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500752 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400753 const void *mac_addr;
754 const phandle *ph;
755 const char *model;
756
757 memset(r, 0, sizeof(r));
758 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
759
760 ret = of_address_to_resource(np, 0, &r[0]);
761 if (ret)
762 goto err;
763 r[0].name = fcc_regs;
764
765 ret = of_address_to_resource(np, 1, &r[1]);
766 if (ret)
767 goto err;
768 r[1].name = fcc_pram;
769
770 ret = of_address_to_resource(np, 2, &r[2]);
771 if (ret)
772 goto err;
773 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400774 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400775
Andy Fleminga9b14972006-10-19 19:52:26 -0500776 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400777
778 fs_enet_dev =
779 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
780
781 if (IS_ERR(fs_enet_dev)) {
782 ret = PTR_ERR(fs_enet_dev);
783 goto err;
784 }
785
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000786 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400787 if (model == NULL) {
788 ret = -ENODEV;
789 goto unreg;
790 }
791
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600792 mac_addr = of_get_mac_address(np);
793 if (mac_addr)
794 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400795
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000796 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400797 phy = of_find_node_by_phandle(*ph);
798
799 if (phy == NULL) {
800 ret = -ENODEV;
801 goto unreg;
802 }
803
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000804 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400805 fs_enet_data.phy_addr = *phy_addr;
806
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000807 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400808
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000809 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400810 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400811 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400812
813 mdio = of_get_parent(phy);
814 ret = of_address_to_resource(mdio, 0, &res);
815 if (ret) {
816 of_node_put(phy);
817 of_node_put(mdio);
818 goto unreg;
819 }
820
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000821 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
822 "rx-clock", NULL));
823 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
824 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400825
Vitaly Bordugfba43662006-09-21 17:26:34 +0400826 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400827 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500828 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400829
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400830 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400831 fs_enet_data.rx_ring = 32;
832 fs_enet_data.tx_ring = 32;
833 fs_enet_data.rx_copybreak = 240;
834 fs_enet_data.use_napi = 0;
835 fs_enet_data.napi_weight = 17;
836 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
837 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
838 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
839
840 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
841 (u32)res.start, fs_enet_data.phy_addr);
842 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400843 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400844
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000845 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400846 if (mdio_bb_prop) {
847 struct platform_device *fs_enet_mdio_bb_dev;
848 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400849
Vitaly Borduged943c12006-10-02 22:41:50 +0400850 fs_enet_mdio_bb_dev =
851 platform_device_register_simple("fsl-bb-mdio",
852 i, NULL, 0);
853 memset(&fs_enet_mdio_bb_data, 0,
854 sizeof(struct fs_mii_bb_platform_info));
855 fs_enet_mdio_bb_data.mdio_dat.bit =
856 mdio_bb_prop[0];
857 fs_enet_mdio_bb_data.mdio_dir.bit =
858 mdio_bb_prop[1];
859 fs_enet_mdio_bb_data.mdc_dat.bit =
860 mdio_bb_prop[2];
861 fs_enet_mdio_bb_data.mdio_port =
862 mdio_bb_prop[3];
863 fs_enet_mdio_bb_data.mdc_port =
864 mdio_bb_prop[4];
865 fs_enet_mdio_bb_data.delay =
866 mdio_bb_prop[5];
867
868 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
869 fs_enet_mdio_bb_data.irq[1] = -1;
870 fs_enet_mdio_bb_data.irq[2] = -1;
871 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
872 fs_enet_mdio_bb_data.irq[31] = -1;
873
874 fs_enet_mdio_bb_data.mdio_dat.offset =
875 (u32)&cpm2_immr->im_ioport.iop_pdatc;
876 fs_enet_mdio_bb_data.mdio_dir.offset =
877 (u32)&cpm2_immr->im_ioport.iop_pdirc;
878 fs_enet_mdio_bb_data.mdc_dat.offset =
879 (u32)&cpm2_immr->im_ioport.iop_pdatc;
880
881 ret = platform_device_add_data(
882 fs_enet_mdio_bb_dev,
883 &fs_enet_mdio_bb_data,
884 sizeof(struct fs_mii_bb_platform_info));
885 if (ret)
886 goto unreg;
887 }
Li Yang97c5a202007-02-07 13:49:24 +0800888
Vitaly Borduged943c12006-10-02 22:41:50 +0400889 of_node_put(phy);
890 of_node_put(mdio);
891
892 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
893 sizeof(struct
894 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500895 if (ret)
896 goto unreg;
897 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400898 }
899 return 0;
900
901unreg:
902 platform_device_unregister(fs_enet_dev);
903err:
904 return ret;
905}
906
907arch_initcall(fs_enet_of_init);
908
909static const char scc_regs[] = "regs";
910static const char scc_pram[] = "pram";
911
912static int __init cpm_uart_of_init(void)
913{
914 struct device_node *np;
915 unsigned int i;
916 struct platform_device *cpm_uart_dev;
917 int ret;
918
919 for (np = NULL, i = 0;
920 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
921 i++) {
922 struct resource r[3];
923 struct fs_uart_platform_info cpm_uart_data;
924 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400925 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400926
927 memset(r, 0, sizeof(r));
928 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
929
930 ret = of_address_to_resource(np, 0, &r[0]);
931 if (ret)
932 goto err;
933
934 r[0].name = scc_regs;
935
936 ret = of_address_to_resource(np, 1, &r[1]);
937 if (ret)
938 goto err;
939 r[1].name = scc_pram;
940
Andy Fleminga9b14972006-10-19 19:52:26 -0500941 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400942
943 cpm_uart_dev =
944 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
945
946 if (IS_ERR(cpm_uart_dev)) {
947 ret = PTR_ERR(cpm_uart_dev);
948 goto err;
949 }
950
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000951 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400952 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400953
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000954 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400955 strcpy(cpm_uart_data.fs_type, model);
956
Vitaly Bordugfba43662006-09-21 17:26:34 +0400957 cpm_uart_data.uart_clk = ppc_proc_freq;
958
959 cpm_uart_data.tx_num_fifo = 4;
960 cpm_uart_data.tx_buf_size = 32;
961 cpm_uart_data.rx_num_fifo = 4;
962 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000963 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
964 "rx-clock", NULL));
965 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
966 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400967
968 ret =
969 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
970 sizeof(struct
971 fs_uart_platform_info));
972 if (ret)
973 goto unreg;
974 }
975
976 return 0;
977
978unreg:
979 platform_device_unregister(cpm_uart_dev);
980err:
981 return ret;
982}
983
984arch_initcall(cpm_uart_of_init);
985#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300986
987#ifdef CONFIG_8xx
988
989extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000990extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300991
992static int __init fs_enet_mdio_of_init(void)
993{
994 struct device_node *np;
995 unsigned int i;
996 struct platform_device *mdio_dev;
997 struct resource res;
998 int ret;
999
1000 for (np = NULL, i = 0;
1001 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
1002 i++) {
1003 struct fs_mii_fec_platform_info mdio_data;
1004
1005 memset(&res, 0, sizeof(res));
1006 memset(&mdio_data, 0, sizeof(mdio_data));
1007
1008 ret = of_address_to_resource(np, 0, &res);
1009 if (ret)
1010 goto err;
1011
1012 mdio_dev =
1013 platform_device_register_simple("fsl-cpm-fec-mdio",
1014 res.start, &res, 1);
1015 if (IS_ERR(mdio_dev)) {
1016 ret = PTR_ERR(mdio_dev);
1017 goto err;
1018 }
1019
1020 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
1021
1022 ret =
1023 platform_device_add_data(mdio_dev, &mdio_data,
1024 sizeof(struct fs_mii_fec_platform_info));
1025 if (ret)
1026 goto unreg;
1027 }
1028 return 0;
1029
1030unreg:
1031 platform_device_unregister(mdio_dev);
1032err:
1033 return ret;
1034}
1035
1036arch_initcall(fs_enet_mdio_of_init);
1037
1038static const char *enet_regs = "regs";
1039static const char *enet_pram = "pram";
1040static const char *enet_irq = "interrupt";
1041static char bus_id[9][BUS_ID_SIZE];
1042
1043static int __init fs_enet_of_init(void)
1044{
1045 struct device_node *np;
1046 unsigned int i;
1047 struct platform_device *fs_enet_dev = NULL;
1048 struct resource res;
1049 int ret;
1050
1051 for (np = NULL, i = 0;
1052 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
1053 i++) {
1054 struct resource r[4];
1055 struct device_node *phy = NULL, *mdio = NULL;
1056 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001057 const unsigned int *id;
1058 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +10001059 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001060 const phandle *ph;
1061 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001062
1063 memset(r, 0, sizeof(r));
1064 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1065
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001066 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001067 if (model == NULL) {
1068 ret = -ENODEV;
1069 goto unreg;
1070 }
1071
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001072 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001073 fs_enet_data.fs_no = *id;
1074
1075 if (platform_device_skip(model, *id))
1076 continue;
1077
1078 ret = of_address_to_resource(np, 0, &r[0]);
1079 if (ret)
1080 goto err;
1081 r[0].name = enet_regs;
1082
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001083 mac_addr = of_get_mac_address(np);
1084 if (mac_addr)
1085 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001086
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001087 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001088 if (ph != NULL)
1089 phy = of_find_node_by_phandle(*ph);
1090
1091 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001092 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001093 fs_enet_data.phy_addr = *phy_addr;
1094 fs_enet_data.has_phy = 1;
1095
1096 mdio = of_get_parent(phy);
1097 ret = of_address_to_resource(mdio, 0, &res);
1098 if (ret) {
1099 of_node_put(phy);
1100 of_node_put(mdio);
1101 goto unreg;
1102 }
1103 }
1104
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001105 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001106 strcpy(fs_enet_data.fs_type, model);
1107
1108 if (strstr(model, "FEC")) {
1109 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1110 r[1].flags = IORESOURCE_IRQ;
1111 r[1].name = enet_irq;
1112
1113 fs_enet_dev =
1114 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1115
1116 if (IS_ERR(fs_enet_dev)) {
1117 ret = PTR_ERR(fs_enet_dev);
1118 goto err;
1119 }
1120
1121 fs_enet_data.rx_ring = 128;
1122 fs_enet_data.tx_ring = 16;
1123 fs_enet_data.rx_copybreak = 240;
1124 fs_enet_data.use_napi = 1;
1125 fs_enet_data.napi_weight = 17;
1126
1127 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1128 (u32)res.start, fs_enet_data.phy_addr);
1129 fs_enet_data.bus_id = (char*)&bus_id[i];
1130 fs_enet_data.init_ioports = init_fec_ioports;
1131 }
1132 if (strstr(model, "SCC")) {
1133 ret = of_address_to_resource(np, 1, &r[1]);
1134 if (ret)
1135 goto err;
1136 r[1].name = enet_pram;
1137
1138 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1139 r[2].flags = IORESOURCE_IRQ;
1140 r[2].name = enet_irq;
1141
1142 fs_enet_dev =
1143 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1144
1145 if (IS_ERR(fs_enet_dev)) {
1146 ret = PTR_ERR(fs_enet_dev);
1147 goto err;
1148 }
1149
1150 fs_enet_data.rx_ring = 64;
1151 fs_enet_data.tx_ring = 8;
1152 fs_enet_data.rx_copybreak = 240;
1153 fs_enet_data.use_napi = 1;
1154 fs_enet_data.napi_weight = 17;
1155
1156 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1157 fs_enet_data.bus_id = (char*)&bus_id[i];
1158 fs_enet_data.init_ioports = init_scc_ioports;
1159 }
1160
1161 of_node_put(phy);
1162 of_node_put(mdio);
1163
1164 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1165 sizeof(struct
1166 fs_platform_info));
1167 if (ret)
1168 goto unreg;
1169 }
1170 return 0;
1171
1172unreg:
1173 platform_device_unregister(fs_enet_dev);
1174err:
1175 return ret;
1176}
1177
1178arch_initcall(fs_enet_of_init);
1179
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001180static int __init fsl_pcmcia_of_init(void)
1181{
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +11001182 struct device_node *np;
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001183 /*
1184 * Register all the devices which type is "pcmcia"
1185 */
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +11001186 for_each_compatible_node(np, "pcmcia", "fsl,pq-pcmcia")
1187 of_platform_device_create(np, "m8xx-pcmcia", NULL);
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001188 return 0;
1189}
1190
1191arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001192
1193static const char *smc_regs = "regs";
1194static const char *smc_pram = "pram";
1195
1196static int __init cpm_smc_uart_of_init(void)
1197{
1198 struct device_node *np;
1199 unsigned int i;
1200 struct platform_device *cpm_uart_dev;
1201 int ret;
1202
1203 for (np = NULL, i = 0;
1204 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1205 i++) {
1206 struct resource r[3];
1207 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001208 const int *id;
1209 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001210
1211 memset(r, 0, sizeof(r));
1212 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1213
1214 ret = of_address_to_resource(np, 0, &r[0]);
1215 if (ret)
1216 goto err;
1217
1218 r[0].name = smc_regs;
1219
1220 ret = of_address_to_resource(np, 1, &r[1]);
1221 if (ret)
1222 goto err;
1223 r[1].name = smc_pram;
1224
1225 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1226 r[2].flags = IORESOURCE_IRQ;
1227
1228 cpm_uart_dev =
1229 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1230
1231 if (IS_ERR(cpm_uart_dev)) {
1232 ret = PTR_ERR(cpm_uart_dev);
1233 goto err;
1234 }
1235
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001236 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001237 strcpy(cpm_uart_data.fs_type, model);
1238
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001239 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001240 cpm_uart_data.fs_no = *id;
1241 cpm_uart_data.uart_clk = ppc_proc_freq;
1242
1243 cpm_uart_data.tx_num_fifo = 4;
1244 cpm_uart_data.tx_buf_size = 32;
1245 cpm_uart_data.rx_num_fifo = 4;
1246 cpm_uart_data.rx_buf_size = 32;
1247
1248 ret =
1249 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1250 sizeof(struct
1251 fs_uart_platform_info));
1252 if (ret)
1253 goto unreg;
1254 }
1255
1256 return 0;
1257
1258unreg:
1259 platform_device_unregister(cpm_uart_dev);
1260err:
1261 return ret;
1262}
1263
1264arch_initcall(cpm_smc_uart_of_init);
1265
1266#endif /* CONFIG_8xx */
Scott Woode631ae32007-09-14 13:04:54 -05001267#endif /* CONFIG_PPC_CPM_NEW_BINDING */
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001268
1269int __init fsl_spi_init(struct spi_board_info *board_infos,
1270 unsigned int num_board_infos,
1271 void (*activate_cs)(u8 cs, u8 polarity),
1272 void (*deactivate_cs)(u8 cs, u8 polarity))
1273{
1274 struct device_node *np;
1275 unsigned int i;
1276 const u32 *sysclk;
1277
Peter Korsgaard082ea862007-10-06 22:06:40 +02001278 /* SPI controller is either clocked from QE or SoC clock */
Anton Vorontsova2dd70a2008-01-24 18:39:59 +03001279 np = of_find_compatible_node(NULL, NULL, "fsl,qe");
1280 if (!np)
1281 np = of_find_node_by_type(NULL, "qe");
1282
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001283 if (!np)
Peter Korsgaard082ea862007-10-06 22:06:40 +02001284 np = of_find_node_by_type(NULL, "soc");
1285
1286 if (!np)
Anton Vorontsov26f6cb92007-08-23 15:35:56 +04001287 return -ENODEV;
1288
1289 sysclk = of_get_property(np, "bus-frequency", NULL);
1290 if (!sysclk)
1291 return -ENODEV;
1292
1293 for (np = NULL, i = 1;
1294 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1295 i++) {
1296 int ret = 0;
1297 unsigned int j;
1298 const void *prop;
1299 struct resource res[2];
1300 struct platform_device *pdev;
1301 struct fsl_spi_platform_data pdata = {
1302 .activate_cs = activate_cs,
1303 .deactivate_cs = deactivate_cs,
1304 };
1305
1306 memset(res, 0, sizeof(res));
1307
1308 pdata.sysclk = *sysclk;
1309
1310 prop = of_get_property(np, "reg", NULL);
1311 if (!prop)
1312 goto err;
1313 pdata.bus_num = *(u32 *)prop;
1314
1315 prop = of_get_property(np, "mode", NULL);
1316 if (prop && !strcmp(prop, "cpu-qe"))
1317 pdata.qe_mode = 1;
1318
1319 for (j = 0; j < num_board_infos; j++) {
1320 if (board_infos[j].bus_num == pdata.bus_num)
1321 pdata.max_chipselect++;
1322 }
1323
1324 if (!pdata.max_chipselect)
1325 goto err;
1326
1327 ret = of_address_to_resource(np, 0, &res[0]);
1328 if (ret)
1329 goto err;
1330
1331 ret = of_irq_to_resource(np, 0, &res[1]);
1332 if (ret == NO_IRQ)
1333 goto err;
1334
1335 pdev = platform_device_alloc("mpc83xx_spi", i);
1336 if (!pdev)
1337 goto err;
1338
1339 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1340 if (ret)
1341 goto unreg;
1342
1343 ret = platform_device_add_resources(pdev, res,
1344 ARRAY_SIZE(res));
1345 if (ret)
1346 goto unreg;
1347
1348 ret = platform_device_register(pdev);
1349 if (ret)
1350 goto unreg;
1351
1352 continue;
1353unreg:
1354 platform_device_del(pdev);
1355err:
1356 continue;
1357 }
1358
1359 return spi_register_board_info(board_infos, num_board_infos);
1360}
Kumar Galae1c15752007-10-04 01:04:57 -05001361
1362#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1363static __be32 __iomem *rstcr;
1364
1365static int __init setup_rstcr(void)
1366{
1367 struct device_node *np;
1368 np = of_find_node_by_name(NULL, "global-utilities");
1369 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
1370 const u32 *prop = of_get_property(np, "reg", NULL);
1371 if (prop) {
1372 /* map reset control register
1373 * 0xE00B0 is offset of reset control register
1374 */
1375 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
1376 if (!rstcr)
1377 printk (KERN_EMERG "Error: reset control "
1378 "register not mapped!\n");
1379 }
1380 } else
1381 printk (KERN_INFO "rstcr compatible register does not exist!\n");
1382 if (np)
1383 of_node_put(np);
1384 return 0;
1385}
1386
1387arch_initcall(setup_rstcr);
1388
1389void fsl_rstcr_restart(char *cmd)
1390{
1391 local_irq_disable();
1392 if (rstcr)
1393 /* set reset control register */
1394 out_be32(rstcr, 0x2); /* HRESET_REQ */
1395
1396 while (1) ;
1397}
1398#endif