blob: 01b884b25696847d6c58817169156c49e49c11e0 [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
Scott Wood38664092008-04-15 13:52:34 -050078static u32 sysfreq = -1;
79
80u32 fsl_get_sys_freq(void)
81{
82 struct device_node *soc;
83 const u32 *prop;
84 int size;
85
86 if (sysfreq != -1)
87 return sysfreq;
88
89 soc = of_find_node_by_type(NULL, "soc");
90 if (!soc)
91 return -1;
92
93 prop = of_get_property(soc, "clock-frequency", &size);
94 if (!prop || size != sizeof(*prop) || *prop == 0)
95 prop = of_get_property(soc, "bus-frequency", &size);
96
97 if (prop && size == sizeof(*prop))
98 sysfreq = *prop;
99
100 of_node_put(soc);
101 return sysfreq;
102}
103EXPORT_SYMBOL(fsl_get_sys_freq);
104
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300105#if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
Vitaly Bordugfba43662006-09-21 17:26:34 +0400106
107static u32 brgfreq = -1;
108
109u32 get_brgfreq(void)
110{
111 struct device_node *node;
Scott Wood6d817aa2007-08-29 15:08:40 -0500112 const unsigned int *prop;
113 int size;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400114
115 if (brgfreq != -1)
116 return brgfreq;
117
Scott Wood6d817aa2007-08-29 15:08:40 -0500118 node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
Vitaly Bordugfba43662006-09-21 17:26:34 +0400119 if (node) {
Scott Wood6d817aa2007-08-29 15:08:40 -0500120 prop = of_get_property(node, "clock-frequency", &size);
121 if (prop && size == 4)
122 brgfreq = *prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400123
Scott Wood6d817aa2007-08-29 15:08:40 -0500124 of_node_put(node);
125 return brgfreq;
126 }
127
128 /* Legacy device binding -- will go away when no users are left. */
129 node = of_find_node_by_type(NULL, "cpm");
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300130 if (!node)
131 node = of_find_compatible_node(NULL, NULL, "fsl,qe");
132 if (!node)
133 node = of_find_node_by_type(NULL, "qe");
134
Scott Wood6d817aa2007-08-29 15:08:40 -0500135 if (node) {
136 prop = of_get_property(node, "brg-frequency", &size);
Scott Woodf9234732007-08-20 11:38:12 -0500137 if (prop && size == 4)
Vitaly Bordugfba43662006-09-21 17:26:34 +0400138 brgfreq = *prop;
Scott Woodf9234732007-08-20 11:38:12 -0500139
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300140 if (brgfreq == -1 || brgfreq == 0) {
141 prop = of_get_property(node, "bus-frequency", &size);
142 if (prop && size == 4)
143 brgfreq = *prop / 2;
144 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400145 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500146 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400147
148 return brgfreq;
149}
150
151EXPORT_SYMBOL(get_brgfreq);
152
153static u32 fs_baudrate = -1;
154
155u32 get_baudrate(void)
156{
157 struct device_node *node;
158
159 if (fs_baudrate != -1)
160 return fs_baudrate;
161
162 node = of_find_node_by_type(NULL, "serial");
163 if (node) {
Scott Woodf9234732007-08-20 11:38:12 -0500164 int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000165 const unsigned int *prop = of_get_property(node,
166 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400167
168 if (prop)
169 fs_baudrate = *prop;
170 of_node_put(node);
Scott Woodf9234732007-08-20 11:38:12 -0500171 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400172
173 return fs_baudrate;
174}
175
176EXPORT_SYMBOL(get_baudrate);
177#endif /* CONFIG_CPM2 */
178
Vitaly Borduga21e2822007-12-07 01:51:31 +0300179#ifdef CONFIG_FIXED_PHY
180static int __init of_add_fixed_phys(void)
181{
182 int ret;
183 struct device_node *np;
184 u32 *fixed_link;
185 struct fixed_phy_status status = {};
186
187 for_each_node_by_name(np, "ethernet") {
188 fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
189 if (!fixed_link)
190 continue;
191
192 status.link = 1;
193 status.duplex = fixed_link[1];
194 status.speed = fixed_link[2];
195 status.pause = fixed_link[3];
196 status.asym_pause = fixed_link[4];
197
198 ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
199 if (ret) {
200 of_node_put(np);
201 return ret;
202 }
203 }
204
205 return 0;
206}
207arch_initcall(of_add_fixed_phys);
208#endif /* CONFIG_FIXED_PHY */
209
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500210static int gfar_mdio_of_init_one(struct device_node *np)
Kumar Galaeed32002006-01-13 11:19:13 -0600211{
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500212 int k;
213 struct device_node *child = NULL;
214 struct gianfar_mdio_data mdio_data;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600215 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600216 struct resource res;
217 int ret;
218
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500219 memset(&res, 0, sizeof(res));
220 memset(&mdio_data, 0, sizeof(mdio_data));
Kumar Galae77b28e2007-12-12 00:28:35 -0600221
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500222 ret = of_address_to_resource(np, 0, &res);
223 if (ret)
224 return ret;
Kumar Galae77b28e2007-12-12 00:28:35 -0600225
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500226 mdio_dev = platform_device_register_simple("fsl-gianfar_mdio",
227 res.start&0xfffff, &res, 1);
228 if (IS_ERR(mdio_dev))
229 return PTR_ERR(mdio_dev);
Kumar Galaeed32002006-01-13 11:19:13 -0600230
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500231 for (k = 0; k < 32; k++)
232 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600233
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500234 while ((child = of_get_next_child(np, child)) != NULL) {
235 int irq = irq_of_parse_and_map(child, 0);
236 if (irq != NO_IRQ) {
237 const u32 *id = of_get_property(child, "reg", NULL);
238 mdio_data.irq[*id] = irq;
Kumar Galaeed32002006-01-13 11:19:13 -0600239 }
Kumar Galaeed32002006-01-13 11:19:13 -0600240 }
241
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500242 ret = platform_device_add_data(mdio_dev, &mdio_data,
243 sizeof(struct gianfar_mdio_data));
244 if (ret)
245 platform_device_unregister(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600246
Kumar Gala2fb07d72006-01-23 16:58:04 -0600247 return ret;
248}
249
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500250static int __init gfar_mdio_of_init(void)
251{
252 struct device_node *np = NULL;
253
254 for_each_compatible_node(np, NULL, "fsl,gianfar-mdio")
255 gfar_mdio_of_init_one(np);
256
257 /* try the deprecated version */
258 for_each_compatible_node(np, "mdio", "gianfar");
259 gfar_mdio_of_init_one(np);
260
261 return 0;
262}
263
Kumar Gala2fb07d72006-01-23 16:58:04 -0600264arch_initcall(gfar_mdio_of_init);
265
266static const char *gfar_tx_intr = "tx";
267static const char *gfar_rx_intr = "rx";
268static const char *gfar_err_intr = "error";
269
270static int __init gfar_of_init(void)
271{
272 struct device_node *np;
273 unsigned int i;
274 struct platform_device *gfar_dev;
275 struct resource res;
276 int ret;
277
278 for (np = NULL, i = 0;
279 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
280 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600281 struct resource r[4];
282 struct device_node *phy, *mdio;
283 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000284 const unsigned int *id;
285 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500286 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000287 const void *mac_addr;
288 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400289 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600290
Anton Vorontsov69ad7e72008-07-08 21:36:40 +0400291 if (!of_device_is_available(np))
292 continue;
293
Kumar Galaeed32002006-01-13 11:19:13 -0600294 memset(r, 0, sizeof(r));
295 memset(&gfar_data, 0, sizeof(gfar_data));
296
297 ret = of_address_to_resource(np, 0, &r[0]);
298 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600299 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600300
Andy Fleminga9b14972006-10-19 19:52:26 -0500301 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600302
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000303 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600304
305 /* If we aren't the FEC we have multiple interrupts */
306 if (model && strcasecmp(model, "FEC")) {
307 r[1].name = gfar_tx_intr;
308
309 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500310 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600311
312 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500313 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500314
315 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600316 }
317
Kumar Gala2fb07d72006-01-23 16:58:04 -0600318 gfar_dev =
319 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400320 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600321
322 if (IS_ERR(gfar_dev)) {
323 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600324 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600325 }
326
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600327 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500328 if (mac_addr)
329 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600330
331 if (model && !strcasecmp(model, "TSEC"))
332 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600333 FSL_GIANFAR_DEV_HAS_GIGABIT |
334 FSL_GIANFAR_DEV_HAS_COALESCE |
335 FSL_GIANFAR_DEV_HAS_RMON |
336 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600337 if (model && !strcasecmp(model, "eTSEC"))
338 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600339 FSL_GIANFAR_DEV_HAS_GIGABIT |
340 FSL_GIANFAR_DEV_HAS_COALESCE |
341 FSL_GIANFAR_DEV_HAS_RMON |
342 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
343 FSL_GIANFAR_DEV_HAS_CSUM |
344 FSL_GIANFAR_DEV_HAS_VLAN |
345 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600346
Andy Fleming7132ab72007-07-11 11:43:07 -0500347 ctype = of_get_property(np, "phy-connection-type", NULL);
348
349 /* We only care about rgmii-id. The rest are autodetected */
350 if (ctype && !strcmp(ctype, "rgmii-id"))
351 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
352 else
353 gfar_data.interface = PHY_INTERFACE_MODE_MII;
354
Scott Woodd87eb122008-07-11 18:04:45 -0500355 if (of_get_property(np, "fsl,magic-packet", NULL))
356 gfar_data.device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
357
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000358 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300359 if (ph == NULL) {
360 u32 *fixed_link;
Kumar Galaeed32002006-01-13 11:19:13 -0600361
Vitaly Borduga21e2822007-12-07 01:51:31 +0300362 fixed_link = (u32 *)of_get_property(np, "fixed-link",
363 NULL);
364 if (!fixed_link) {
365 ret = -ENODEV;
366 goto unreg;
367 }
Kumar Galaeed32002006-01-13 11:19:13 -0600368
Andy Fleming9d9326d2008-04-09 19:38:13 -0500369 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
Vitaly Borduga21e2822007-12-07 01:51:31 +0300370 gfar_data.phy_id = fixed_link[0];
371 } else {
372 phy = of_find_node_by_phandle(*ph);
Kumar Galaeed32002006-01-13 11:19:13 -0600373
Vitaly Borduga21e2822007-12-07 01:51:31 +0300374 if (phy == NULL) {
375 ret = -ENODEV;
376 goto unreg;
377 }
378
379 mdio = of_get_parent(phy);
380
381 id = of_get_property(phy, "reg", NULL);
382 ret = of_address_to_resource(mdio, 0, &res);
383 if (ret) {
384 of_node_put(phy);
385 of_node_put(mdio);
386 goto unreg;
387 }
388
389 gfar_data.phy_id = *id;
Becky Bruce128cf7f2008-05-01 18:15:45 -0500390 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx",
Andy Fleming4cd7e1c2008-05-02 13:03:50 -0500391 (unsigned long long)res.start&0xfffff);
Vitaly Borduga21e2822007-12-07 01:51:31 +0300392
Kumar Galaeed32002006-01-13 11:19:13 -0600393 of_node_put(phy);
394 of_node_put(mdio);
Kumar Galaeed32002006-01-13 11:19:13 -0600395 }
396
Kumar Gala2fb07d72006-01-23 16:58:04 -0600397 ret =
398 platform_device_add_data(gfar_dev, &gfar_data,
399 sizeof(struct
400 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600401 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600402 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600403 }
404
405 return 0;
406
Kumar Gala2fb07d72006-01-23 16:58:04 -0600407unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600408 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600409err:
Kumar Galaeed32002006-01-13 11:19:13 -0600410 return ret;
411}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600412
Kumar Galaeed32002006-01-13 11:19:13 -0600413arch_initcall(gfar_of_init);
414
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000415static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600416{
417 if (!phy_type)
418 return FSL_USB2_PHY_NONE;
419 if (!strcasecmp(phy_type, "ulpi"))
420 return FSL_USB2_PHY_ULPI;
421 if (!strcasecmp(phy_type, "utmi"))
422 return FSL_USB2_PHY_UTMI;
423 if (!strcasecmp(phy_type, "utmi_wide"))
424 return FSL_USB2_PHY_UTMI_WIDE;
425 if (!strcasecmp(phy_type, "serial"))
426 return FSL_USB2_PHY_SERIAL;
427
428 return FSL_USB2_PHY_NONE;
429}
430
431static int __init fsl_usb_of_init(void)
432{
433 struct device_node *np;
Li Yang866b6dd2008-01-08 15:18:46 +0800434 unsigned int i = 0;
Li Yang97c5a202007-02-07 13:49:24 +0800435 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
436 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600437 int ret;
438
Li Yang866b6dd2008-01-08 15:18:46 +0800439 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600440 struct resource r[2];
441 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000442 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600443
444 memset(&r, 0, sizeof(r));
445 memset(&usb_data, 0, sizeof(usb_data));
446
447 ret = of_address_to_resource(np, 0, &r[0]);
448 if (ret)
449 goto err;
450
Andy Fleminga9b14972006-10-19 19:52:26 -0500451 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600452
Kumar Gala01cced22006-04-11 10:07:16 -0500453 usb_dev_mph =
454 platform_device_register_simple("fsl-ehci", i, r, 2);
455 if (IS_ERR(usb_dev_mph)) {
456 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600457 goto err;
458 }
459
Kumar Gala01cced22006-04-11 10:07:16 -0500460 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
461 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600462
463 usb_data.operating_mode = FSL_USB2_MPH_HOST;
464
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000465 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600466 if (prop)
467 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
468
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000469 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600470 if (prop)
471 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
472
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000473 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600474 usb_data.phy_mode = determine_usb_phy(prop);
475
476 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500477 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600478 sizeof(struct
479 fsl_usb2_platform_data));
480 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500481 goto unreg_mph;
Li Yang866b6dd2008-01-08 15:18:46 +0800482 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600483 }
484
Li Yang866b6dd2008-01-08 15:18:46 +0800485 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600486 struct resource r[2];
487 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000488 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600489
490 memset(&r, 0, sizeof(r));
491 memset(&usb_data, 0, sizeof(usb_data));
492
493 ret = of_address_to_resource(np, 0, &r[0]);
494 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500495 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600496
Andy Fleminga9b14972006-10-19 19:52:26 -0500497 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600498
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000499 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800500
501 if (!prop || !strcmp(prop, "host")) {
502 usb_data.operating_mode = FSL_USB2_DR_HOST;
503 usb_dev_dr_host = platform_device_register_simple(
504 "fsl-ehci", i, r, 2);
505 if (IS_ERR(usb_dev_dr_host)) {
506 ret = PTR_ERR(usb_dev_dr_host);
507 goto err;
508 }
509 } else if (prop && !strcmp(prop, "peripheral")) {
510 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
511 usb_dev_dr_client = platform_device_register_simple(
512 "fsl-usb2-udc", i, r, 2);
513 if (IS_ERR(usb_dev_dr_client)) {
514 ret = PTR_ERR(usb_dev_dr_client);
515 goto err;
516 }
517 } else if (prop && !strcmp(prop, "otg")) {
518 usb_data.operating_mode = FSL_USB2_DR_OTG;
519 usb_dev_dr_host = platform_device_register_simple(
520 "fsl-ehci", i, r, 2);
521 if (IS_ERR(usb_dev_dr_host)) {
522 ret = PTR_ERR(usb_dev_dr_host);
523 goto err;
524 }
525 usb_dev_dr_client = platform_device_register_simple(
526 "fsl-usb2-udc", i, r, 2);
527 if (IS_ERR(usb_dev_dr_client)) {
528 ret = PTR_ERR(usb_dev_dr_client);
529 goto err;
530 }
531 } else {
532 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600533 goto err;
534 }
535
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000536 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600537 usb_data.phy_mode = determine_usb_phy(prop);
538
Li Yang97c5a202007-02-07 13:49:24 +0800539 if (usb_dev_dr_host) {
540 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
541 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
542 dev.coherent_dma_mask;
543 if ((ret = platform_device_add_data(usb_dev_dr_host,
544 &usb_data, sizeof(struct
545 fsl_usb2_platform_data))))
546 goto unreg_dr;
547 }
548 if (usb_dev_dr_client) {
549 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
550 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
551 dev.coherent_dma_mask;
552 if ((ret = platform_device_add_data(usb_dev_dr_client,
553 &usb_data, sizeof(struct
554 fsl_usb2_platform_data))))
555 goto unreg_dr;
556 }
Li Yang866b6dd2008-01-08 15:18:46 +0800557 i++;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600558 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600559 return 0;
560
Kumar Gala01cced22006-04-11 10:07:16 -0500561unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800562 if (usb_dev_dr_host)
563 platform_device_unregister(usb_dev_dr_host);
564 if (usb_dev_dr_client)
565 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500566unreg_mph:
567 if (usb_dev_mph)
568 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600569err:
570 return ret;
571}
572
Kumar Gala01cced22006-04-11 10:07:16 -0500573arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400574
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300575static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
576 struct spi_board_info *board_infos,
577 unsigned int num_board_infos,
578 void (*activate_cs)(u8 cs, u8 polarity),
579 void (*deactivate_cs)(u8 cs, u8 polarity))
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400580{
581 struct device_node *np;
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300582 unsigned int i = 0;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400583
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300584 for_each_compatible_node(np, type, compatible) {
585 int ret;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400586 unsigned int j;
587 const void *prop;
588 struct resource res[2];
589 struct platform_device *pdev;
590 struct fsl_spi_platform_data pdata = {
591 .activate_cs = activate_cs,
592 .deactivate_cs = deactivate_cs,
593 };
594
595 memset(res, 0, sizeof(res));
596
Anton Vorontsov59a0ea52008-01-24 18:40:03 +0300597 pdata.sysclk = sysclk;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400598
599 prop = of_get_property(np, "reg", NULL);
600 if (!prop)
601 goto err;
602 pdata.bus_num = *(u32 *)prop;
603
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300604 prop = of_get_property(np, "cell-index", NULL);
605 if (prop)
606 i = *(u32 *)prop;
607
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400608 prop = of_get_property(np, "mode", NULL);
609 if (prop && !strcmp(prop, "cpu-qe"))
610 pdata.qe_mode = 1;
611
612 for (j = 0; j < num_board_infos; j++) {
613 if (board_infos[j].bus_num == pdata.bus_num)
614 pdata.max_chipselect++;
615 }
616
617 if (!pdata.max_chipselect)
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300618 continue;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400619
620 ret = of_address_to_resource(np, 0, &res[0]);
621 if (ret)
622 goto err;
623
624 ret = of_irq_to_resource(np, 0, &res[1]);
625 if (ret == NO_IRQ)
626 goto err;
627
628 pdev = platform_device_alloc("mpc83xx_spi", i);
629 if (!pdev)
630 goto err;
631
632 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
633 if (ret)
634 goto unreg;
635
636 ret = platform_device_add_resources(pdev, res,
637 ARRAY_SIZE(res));
638 if (ret)
639 goto unreg;
640
Kim Phillipsdc4e4202008-02-01 18:09:58 -0600641 ret = platform_device_add(pdev);
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400642 if (ret)
643 goto unreg;
644
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300645 goto next;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400646unreg:
647 platform_device_del(pdev);
648err:
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300649 pr_err("%s: registration failed\n", np->full_name);
650next:
651 i++;
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400652 }
653
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300654 return i;
655}
656
657int __init fsl_spi_init(struct spi_board_info *board_infos,
658 unsigned int num_board_infos,
659 void (*activate_cs)(u8 cs, u8 polarity),
660 void (*deactivate_cs)(u8 cs, u8 polarity))
661{
662 u32 sysclk = -1;
663 int ret;
664
665#ifdef CONFIG_QUICC_ENGINE
666 /* SPI controller is either clocked from QE or SoC clock */
667 sysclk = get_brgfreq();
668#endif
669 if (sysclk == -1) {
Scott Wood38664092008-04-15 13:52:34 -0500670 sysclk = fsl_get_sys_freq();
671 if (sysclk == -1)
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300672 return -ENODEV;
Anton Vorontsovf3a2b292008-01-24 18:40:07 +0300673 }
674
675 ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
676 num_board_infos, activate_cs, deactivate_cs);
677 if (!ret)
678 of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
679 num_board_infos, activate_cs, deactivate_cs);
680
Anton Vorontsov26f6cb92007-08-23 15:35:56 +0400681 return spi_register_board_info(board_infos, num_board_infos);
682}
Kumar Galae1c15752007-10-04 01:04:57 -0500683
684#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
685static __be32 __iomem *rstcr;
686
687static int __init setup_rstcr(void)
688{
689 struct device_node *np;
690 np = of_find_node_by_name(NULL, "global-utilities");
691 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
692 const u32 *prop = of_get_property(np, "reg", NULL);
693 if (prop) {
694 /* map reset control register
695 * 0xE00B0 is offset of reset control register
696 */
697 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
698 if (!rstcr)
699 printk (KERN_EMERG "Error: reset control "
700 "register not mapped!\n");
701 }
702 } else
703 printk (KERN_INFO "rstcr compatible register does not exist!\n");
704 if (np)
705 of_node_put(np);
706 return 0;
707}
708
709arch_initcall(setup_rstcr);
710
711void fsl_rstcr_restart(char *cmd)
712{
713 local_irq_disable();
714 if (rstcr)
715 /* set reset control register */
716 out_be32(rstcr, 0x2); /* HRESET_REQ */
717
718 while (1) ;
719}
720#endif
York Sun6f90a8bd2008-04-28 02:15:36 -0700721
722#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
Timur Tabi43c9f432008-09-23 09:47:01 -0500723struct platform_diu_data_ops diu_ops;
York Sun6f90a8bd2008-04-28 02:15:36 -0700724EXPORT_SYMBOL(diu_ops);
York Sun6f90a8bd2008-04-28 02:15:36 -0700725#endif