GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / powerpc / sysdev / mv64x60_dev.c
blob1398bc454999b2b10fae54972e5e92c69689b3eb
1 /*
2 * Platform device setup for Marvell mv64360/mv64460 host bridges (Discovery)
4 * Author: Dale Farnsworth <dale@farnsworth.org>
6 * 2007 (c) MontaVista, Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
12 #include <linux/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/console.h>
16 #include <linux/mv643xx.h>
17 #include <linux/platform_device.h>
18 #include <linux/of_platform.h>
19 #include <linux/dma-mapping.h>
21 #include <asm/prom.h>
23 /* These functions provide the necessary setup for the mv64x60 drivers. */
25 static struct of_device_id __initdata of_mv64x60_devices[] = {
26 { .compatible = "marvell,mv64306-devctrl", },
31 * Create MPSC platform devices
33 static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
35 struct platform_device *pdev;
36 struct resource r[2];
37 struct mpsc_shared_pdata pdata;
38 const phandle *ph;
39 struct device_node *mpscrouting, *mpscintr;
40 int err;
42 ph = of_get_property(np, "mpscrouting", NULL);
43 mpscrouting = of_find_node_by_phandle(*ph);
44 if (!mpscrouting)
45 return -ENODEV;
47 err = of_address_to_resource(mpscrouting, 0, &r[0]);
48 of_node_put(mpscrouting);
49 if (err)
50 return err;
52 ph = of_get_property(np, "mpscintr", NULL);
53 mpscintr = of_find_node_by_phandle(*ph);
54 if (!mpscintr)
55 return -ENODEV;
57 err = of_address_to_resource(mpscintr, 0, &r[1]);
58 of_node_put(mpscintr);
59 if (err)
60 return err;
62 memset(&pdata, 0, sizeof(pdata));
64 pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
65 if (!pdev)
66 return -ENOMEM;
68 err = platform_device_add_resources(pdev, r, 2);
69 if (err)
70 goto error;
72 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
73 if (err)
74 goto error;
76 err = platform_device_add(pdev);
77 if (err)
78 goto error;
80 return 0;
82 error:
83 platform_device_put(pdev);
84 return err;
88 static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
90 struct resource r[5];
91 struct mpsc_pdata pdata;
92 struct platform_device *pdev;
93 const unsigned int *prop;
94 const phandle *ph;
95 struct device_node *sdma, *brg;
96 int err;
97 int port_number;
99 /* only register the shared platform device the first time through */
100 if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
101 return err;
103 memset(r, 0, sizeof(r));
105 err = of_address_to_resource(np, 0, &r[0]);
106 if (err)
107 return err;
109 of_irq_to_resource(np, 0, &r[4]);
111 ph = of_get_property(np, "sdma", NULL);
112 sdma = of_find_node_by_phandle(*ph);
113 if (!sdma)
114 return -ENODEV;
116 of_irq_to_resource(sdma, 0, &r[3]);
117 err = of_address_to_resource(sdma, 0, &r[1]);
118 of_node_put(sdma);
119 if (err)
120 return err;
122 ph = of_get_property(np, "brg", NULL);
123 brg = of_find_node_by_phandle(*ph);
124 if (!brg)
125 return -ENODEV;
127 err = of_address_to_resource(brg, 0, &r[2]);
128 of_node_put(brg);
129 if (err)
130 return err;
132 prop = of_get_property(np, "cell-index", NULL);
133 if (!prop)
134 return -ENODEV;
135 port_number = *(int *)prop;
137 memset(&pdata, 0, sizeof(pdata));
139 pdata.cache_mgmt = 1; /* All current revs need this set */
141 pdata.max_idle = 40; /* default */
142 prop = of_get_property(np, "max_idle", NULL);
143 if (prop)
144 pdata.max_idle = *prop;
146 prop = of_get_property(brg, "current-speed", NULL);
147 if (prop)
148 pdata.default_baud = *prop;
150 /* Default is 8 bits, no parity, no flow control */
151 pdata.default_bits = 8;
152 pdata.default_parity = 'n';
153 pdata.default_flow = 'n';
155 prop = of_get_property(np, "chr_1", NULL);
156 if (prop)
157 pdata.chr_1_val = *prop;
159 prop = of_get_property(np, "chr_2", NULL);
160 if (prop)
161 pdata.chr_2_val = *prop;
163 prop = of_get_property(np, "chr_10", NULL);
164 if (prop)
165 pdata.chr_10_val = *prop;
167 prop = of_get_property(np, "mpcr", NULL);
168 if (prop)
169 pdata.mpcr_val = *prop;
171 prop = of_get_property(brg, "bcr", NULL);
172 if (prop)
173 pdata.bcr_val = *prop;
175 pdata.brg_can_tune = 1; /* All current revs need this set */
177 prop = of_get_property(brg, "clock-src", NULL);
178 if (prop)
179 pdata.brg_clk_src = *prop;
181 prop = of_get_property(brg, "clock-frequency", NULL);
182 if (prop)
183 pdata.brg_clk_freq = *prop;
185 pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
186 if (!pdev)
187 return -ENOMEM;
188 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
190 err = platform_device_add_resources(pdev, r, 5);
191 if (err)
192 goto error;
194 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
195 if (err)
196 goto error;
198 err = platform_device_add(pdev);
199 if (err)
200 goto error;
202 return 0;
204 error:
205 platform_device_put(pdev);
206 return err;
210 * Create mv64x60_eth platform devices
212 static struct platform_device * __init mv64x60_eth_register_shared_pdev(
213 struct device_node *np, int id)
215 struct platform_device *pdev;
216 struct resource r[1];
217 int err;
219 err = of_address_to_resource(np, 0, &r[0]);
220 if (err)
221 return ERR_PTR(err);
223 pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, id,
224 r, 1);
225 return pdev;
228 static int __init mv64x60_eth_device_setup(struct device_node *np, int id,
229 struct platform_device *shared_pdev)
231 struct resource r[1];
232 struct mv643xx_eth_platform_data pdata;
233 struct platform_device *pdev;
234 struct device_node *phy;
235 const u8 *mac_addr;
236 const int *prop;
237 const phandle *ph;
238 int err;
240 memset(r, 0, sizeof(r));
241 of_irq_to_resource(np, 0, &r[0]);
243 memset(&pdata, 0, sizeof(pdata));
245 pdata.shared = shared_pdev;
247 prop = of_get_property(np, "reg", NULL);
248 if (!prop)
249 return -ENODEV;
250 pdata.port_number = *prop;
252 mac_addr = of_get_mac_address(np);
253 if (mac_addr)
254 memcpy(pdata.mac_addr, mac_addr, 6);
256 prop = of_get_property(np, "speed", NULL);
257 if (prop)
258 pdata.speed = *prop;
260 prop = of_get_property(np, "tx_queue_size", NULL);
261 if (prop)
262 pdata.tx_queue_size = *prop;
264 prop = of_get_property(np, "rx_queue_size", NULL);
265 if (prop)
266 pdata.rx_queue_size = *prop;
268 prop = of_get_property(np, "tx_sram_addr", NULL);
269 if (prop)
270 pdata.tx_sram_addr = *prop;
272 prop = of_get_property(np, "tx_sram_size", NULL);
273 if (prop)
274 pdata.tx_sram_size = *prop;
276 prop = of_get_property(np, "rx_sram_addr", NULL);
277 if (prop)
278 pdata.rx_sram_addr = *prop;
280 prop = of_get_property(np, "rx_sram_size", NULL);
281 if (prop)
282 pdata.rx_sram_size = *prop;
284 ph = of_get_property(np, "phy", NULL);
285 if (!ph)
286 return -ENODEV;
288 phy = of_find_node_by_phandle(*ph);
289 if (phy == NULL)
290 return -ENODEV;
292 prop = of_get_property(phy, "reg", NULL);
293 if (prop)
294 pdata.phy_addr = MV643XX_ETH_PHY_ADDR(*prop);
296 of_node_put(phy);
298 pdev = platform_device_alloc(MV643XX_ETH_NAME, id);
299 if (!pdev)
300 return -ENOMEM;
302 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
303 err = platform_device_add_resources(pdev, r, 1);
304 if (err)
305 goto error;
307 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
308 if (err)
309 goto error;
311 err = platform_device_add(pdev);
312 if (err)
313 goto error;
315 return 0;
317 error:
318 platform_device_put(pdev);
319 return err;
323 * Create mv64x60_i2c platform devices
325 static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
327 struct resource r[2];
328 struct platform_device *pdev;
329 struct mv64xxx_i2c_pdata pdata;
330 const unsigned int *prop;
331 int err;
333 memset(r, 0, sizeof(r));
335 err = of_address_to_resource(np, 0, &r[0]);
336 if (err)
337 return err;
339 of_irq_to_resource(np, 0, &r[1]);
341 memset(&pdata, 0, sizeof(pdata));
343 pdata.freq_m = 8; /* default */
344 prop = of_get_property(np, "freq_m", NULL);
345 if (prop)
346 pdata.freq_m = *prop;
348 pdata.freq_m = 3; /* default */
349 prop = of_get_property(np, "freq_n", NULL);
350 if (prop)
351 pdata.freq_n = *prop;
353 pdata.timeout = 1000; /* default: 1 second */
355 pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
356 if (!pdev)
357 return -ENOMEM;
359 err = platform_device_add_resources(pdev, r, 2);
360 if (err)
361 goto error;
363 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
364 if (err)
365 goto error;
367 err = platform_device_add(pdev);
368 if (err)
369 goto error;
371 return 0;
373 error:
374 platform_device_put(pdev);
375 return err;
379 * Create mv64x60_wdt platform devices
381 static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
383 struct resource r;
384 struct platform_device *pdev;
385 struct mv64x60_wdt_pdata pdata;
386 const unsigned int *prop;
387 int err;
389 err = of_address_to_resource(np, 0, &r);
390 if (err)
391 return err;
393 memset(&pdata, 0, sizeof(pdata));
395 pdata.timeout = 10; /* Default: 10 seconds */
397 np = of_get_parent(np);
398 if (!np)
399 return -ENODEV;
401 prop = of_get_property(np, "clock-frequency", NULL);
402 of_node_put(np);
403 if (!prop)
404 return -ENODEV;
405 pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
407 pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
408 if (!pdev)
409 return -ENOMEM;
411 err = platform_device_add_resources(pdev, &r, 1);
412 if (err)
413 goto error;
415 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
416 if (err)
417 goto error;
419 err = platform_device_add(pdev);
420 if (err)
421 goto error;
423 return 0;
425 error:
426 platform_device_put(pdev);
427 return err;
430 static int __init mv64x60_device_setup(void)
432 struct device_node *np, *np2;
433 struct platform_device *pdev;
434 int id, id2;
435 int err;
437 id = 0;
438 for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc") {
439 err = mv64x60_mpsc_device_setup(np, id++);
440 if (err)
441 printk(KERN_ERR "Failed to initialize MV64x60 "
442 "serial device %s: error %d.\n",
443 np->full_name, err);
446 id = 0;
447 id2 = 0;
448 for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") {
449 pdev = mv64x60_eth_register_shared_pdev(np, id++);
450 if (IS_ERR(pdev)) {
451 err = PTR_ERR(pdev);
452 printk(KERN_ERR "Failed to initialize MV64x60 "
453 "network block %s: error %d.\n",
454 np->full_name, err);
455 continue;
457 for_each_child_of_node(np, np2) {
458 if (!of_device_is_compatible(np2,
459 "marvell,mv64360-eth"))
460 continue;
461 err = mv64x60_eth_device_setup(np2, id2++, pdev);
462 if (err)
463 printk(KERN_ERR "Failed to initialize "
464 "MV64x60 network device %s: "
465 "error %d.\n",
466 np2->full_name, err);
470 id = 0;
471 for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c") {
472 err = mv64x60_i2c_device_setup(np, id++);
473 if (err)
474 printk(KERN_ERR "Failed to initialize MV64x60 I2C "
475 "bus %s: error %d.\n",
476 np->full_name, err);
479 /* support up to one watchdog timer */
480 np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
481 if (np) {
482 if ((err = mv64x60_wdt_device_setup(np, id)))
483 printk(KERN_ERR "Failed to initialize MV64x60 "
484 "Watchdog %s: error %d.\n",
485 np->full_name, err);
486 of_node_put(np);
489 /* Now add every node that is on the device bus */
490 for_each_compatible_node(np, NULL, "marvell,mv64360")
491 of_platform_bus_probe(np, of_mv64x60_devices, NULL);
493 return 0;
495 arch_initcall(mv64x60_device_setup);
497 static int __init mv64x60_add_mpsc_console(void)
499 struct device_node *np = NULL;
500 const char *prop;
502 prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
503 if (prop == NULL)
504 goto not_mpsc;
506 np = of_find_node_by_path(prop);
507 if (!np)
508 goto not_mpsc;
510 if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
511 goto not_mpsc;
513 prop = of_get_property(np, "cell-index", NULL);
514 if (!prop)
515 goto not_mpsc;
517 add_preferred_console("ttyMM", *(int *)prop, NULL);
519 not_mpsc:
520 return 0;
522 console_initcall(mv64x60_add_mpsc_console);