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
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>
24 * These functions provide the necessary setup for the mv64x60 drivers.
25 * These drivers are unusual in that they work on both the MIPS and PowerPC
26 * architectures. Because of that, the drivers do not support the normal
27 * PowerPC of_platform_bus_type. They support platform_bus_type instead.
30 static struct of_device_id __initdata of_mv64x60_devices[] = {
31 { .compatible = "marvell,mv64306-devctrl", },
36 * Create MPSC platform devices
38 static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
40 struct platform_device *pdev;
42 struct mpsc_shared_pdata pdata;
44 struct device_node *mpscrouting, *mpscintr;
47 ph = of_get_property(np, "mpscrouting", NULL);
48 mpscrouting = of_find_node_by_phandle(*ph);
52 err = of_address_to_resource(mpscrouting, 0, &r[0]);
53 of_node_put(mpscrouting);
57 ph = of_get_property(np, "mpscintr", NULL);
58 mpscintr = of_find_node_by_phandle(*ph);
62 err = of_address_to_resource(mpscintr, 0, &r[1]);
63 of_node_put(mpscintr);
67 memset(&pdata, 0, sizeof(pdata));
69 pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
73 err = platform_device_add_resources(pdev, r, 2);
77 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
81 err = platform_device_add(pdev);
88 platform_device_put(pdev);
93 static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
96 struct mpsc_pdata pdata;
97 struct platform_device *pdev;
98 const unsigned int *prop;
100 struct device_node *sdma, *brg;
104 /* only register the shared platform device the first time through */
105 if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
108 memset(r, 0, sizeof(r));
110 err = of_address_to_resource(np, 0, &r[0]);
114 of_irq_to_resource(np, 0, &r[4]);
116 ph = of_get_property(np, "sdma", NULL);
117 sdma = of_find_node_by_phandle(*ph);
121 of_irq_to_resource(sdma, 0, &r[3]);
122 err = of_address_to_resource(sdma, 0, &r[1]);
127 ph = of_get_property(np, "brg", NULL);
128 brg = of_find_node_by_phandle(*ph);
132 err = of_address_to_resource(brg, 0, &r[2]);
137 prop = of_get_property(np, "cell-index", NULL);
140 port_number = *(int *)prop;
142 memset(&pdata, 0, sizeof(pdata));
144 pdata.cache_mgmt = 1; /* All current revs need this set */
146 pdata.max_idle = 40; /* default */
147 prop = of_get_property(np, "max_idle", NULL);
149 pdata.max_idle = *prop;
151 prop = of_get_property(brg, "current-speed", NULL);
153 pdata.default_baud = *prop;
155 /* Default is 8 bits, no parity, no flow control */
156 pdata.default_bits = 8;
157 pdata.default_parity = 'n';
158 pdata.default_flow = 'n';
160 prop = of_get_property(np, "chr_1", NULL);
162 pdata.chr_1_val = *prop;
164 prop = of_get_property(np, "chr_2", NULL);
166 pdata.chr_2_val = *prop;
168 prop = of_get_property(np, "chr_10", NULL);
170 pdata.chr_10_val = *prop;
172 prop = of_get_property(np, "mpcr", NULL);
174 pdata.mpcr_val = *prop;
176 prop = of_get_property(brg, "bcr", NULL);
178 pdata.bcr_val = *prop;
180 pdata.brg_can_tune = 1; /* All current revs need this set */
182 prop = of_get_property(brg, "clock-src", NULL);
184 pdata.brg_clk_src = *prop;
186 prop = of_get_property(brg, "clock-frequency", NULL);
188 pdata.brg_clk_freq = *prop;
190 pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
193 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
195 err = platform_device_add_resources(pdev, r, 5);
199 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
203 err = platform_device_add(pdev);
210 platform_device_put(pdev);
215 * Create mv64x60_eth platform devices
217 static struct platform_device * __init mv64x60_eth_register_shared_pdev(
218 struct device_node *np, int id)
220 struct platform_device *pdev;
221 struct resource r[1];
224 err = of_address_to_resource(np, 0, &r[0]);
228 pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, id,
233 static int __init mv64x60_eth_device_setup(struct device_node *np, int id,
234 struct platform_device *shared_pdev)
236 struct resource r[1];
237 struct mv643xx_eth_platform_data pdata;
238 struct platform_device *pdev;
239 struct device_node *phy;
245 memset(r, 0, sizeof(r));
246 of_irq_to_resource(np, 0, &r[0]);
248 memset(&pdata, 0, sizeof(pdata));
250 pdata.shared = shared_pdev;
252 prop = of_get_property(np, "reg", NULL);
255 pdata.port_number = *prop;
257 mac_addr = of_get_mac_address(np);
259 memcpy(pdata.mac_addr, mac_addr, 6);
261 prop = of_get_property(np, "speed", NULL);
265 prop = of_get_property(np, "tx_queue_size", NULL);
267 pdata.tx_queue_size = *prop;
269 prop = of_get_property(np, "rx_queue_size", NULL);
271 pdata.rx_queue_size = *prop;
273 prop = of_get_property(np, "tx_sram_addr", NULL);
275 pdata.tx_sram_addr = *prop;
277 prop = of_get_property(np, "tx_sram_size", NULL);
279 pdata.tx_sram_size = *prop;
281 prop = of_get_property(np, "rx_sram_addr", NULL);
283 pdata.rx_sram_addr = *prop;
285 prop = of_get_property(np, "rx_sram_size", NULL);
287 pdata.rx_sram_size = *prop;
289 ph = of_get_property(np, "phy", NULL);
293 phy = of_find_node_by_phandle(*ph);
297 prop = of_get_property(phy, "reg", NULL);
299 pdata.phy_addr = MV643XX_ETH_PHY_ADDR(*prop);
303 pdev = platform_device_alloc(MV643XX_ETH_NAME, id);
307 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
308 err = platform_device_add_resources(pdev, r, 1);
312 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
316 err = platform_device_add(pdev);
323 platform_device_put(pdev);
328 * Create mv64x60_i2c platform devices
330 static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
332 struct resource r[2];
333 struct platform_device *pdev;
334 struct mv64xxx_i2c_pdata pdata;
335 const unsigned int *prop;
338 memset(r, 0, sizeof(r));
340 err = of_address_to_resource(np, 0, &r[0]);
344 of_irq_to_resource(np, 0, &r[1]);
346 memset(&pdata, 0, sizeof(pdata));
348 pdata.freq_m = 8; /* default */
349 prop = of_get_property(np, "freq_m", NULL);
351 pdata.freq_m = *prop;
353 pdata.freq_m = 3; /* default */
354 prop = of_get_property(np, "freq_n", NULL);
356 pdata.freq_n = *prop;
358 pdata.timeout = 1000; /* default: 1 second */
360 pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
364 err = platform_device_add_resources(pdev, r, 2);
368 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
372 err = platform_device_add(pdev);
379 platform_device_put(pdev);
384 * Create mv64x60_wdt platform devices
386 static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
389 struct platform_device *pdev;
390 struct mv64x60_wdt_pdata pdata;
391 const unsigned int *prop;
394 err = of_address_to_resource(np, 0, &r);
398 memset(&pdata, 0, sizeof(pdata));
400 pdata.timeout = 10; /* Default: 10 seconds */
402 np = of_get_parent(np);
406 prop = of_get_property(np, "clock-frequency", NULL);
410 pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
412 pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
416 err = platform_device_add_resources(pdev, &r, 1);
420 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
424 err = platform_device_add(pdev);
431 platform_device_put(pdev);
435 static int __init mv64x60_device_setup(void)
437 struct device_node *np, *np2;
438 struct platform_device *pdev;
443 for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc") {
444 err = mv64x60_mpsc_device_setup(np, id++);
446 printk(KERN_ERR "Failed to initialize MV64x60 "
447 "serial device %s: error %d.\n",
453 for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") {
454 pdev = mv64x60_eth_register_shared_pdev(np, id++);
457 printk(KERN_ERR "Failed to initialize MV64x60 "
458 "network block %s: error %d.\n",
462 for_each_child_of_node(np, np2) {
463 if (!of_device_is_compatible(np2,
464 "marvell,mv64360-eth"))
466 err = mv64x60_eth_device_setup(np2, id2++, pdev);
468 printk(KERN_ERR "Failed to initialize "
469 "MV64x60 network device %s: "
471 np2->full_name, err);
476 for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c") {
477 err = mv64x60_i2c_device_setup(np, id++);
479 printk(KERN_ERR "Failed to initialize MV64x60 I2C "
480 "bus %s: error %d.\n",
484 /* support up to one watchdog timer */
485 np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
487 if ((err = mv64x60_wdt_device_setup(np, id)))
488 printk(KERN_ERR "Failed to initialize MV64x60 "
489 "Watchdog %s: error %d.\n",
494 /* Now add every node that is on the device bus */
495 for_each_compatible_node(np, NULL, "marvell,mv64360")
496 of_platform_bus_probe(np, of_mv64x60_devices, NULL);
500 arch_initcall(mv64x60_device_setup);
502 static int __init mv64x60_add_mpsc_console(void)
504 struct device_node *np = NULL;
507 prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
511 np = of_find_node_by_path(prop);
515 if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
518 prop = of_get_property(np, "cell-index", NULL);
522 add_preferred_console("ttyMM", *(int *)prop, NULL);
527 console_initcall(mv64x60_add_mpsc_console);