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/of_net.h>
20 #include <linux/dma-mapping.h>
24 /* These functions provide the necessary setup for the mv64x60 drivers. */
26 static struct of_device_id __initdata of_mv64x60_devices[] = {
27 { .compatible = "marvell,mv64306-devctrl", },
32 * Create MPSC platform devices
34 static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
36 struct platform_device *pdev;
38 struct mpsc_shared_pdata pdata;
40 struct device_node *mpscrouting, *mpscintr;
43 ph = of_get_property(np, "mpscrouting", NULL);
44 mpscrouting = of_find_node_by_phandle(*ph);
48 err = of_address_to_resource(mpscrouting, 0, &r[0]);
49 of_node_put(mpscrouting);
53 ph = of_get_property(np, "mpscintr", NULL);
54 mpscintr = of_find_node_by_phandle(*ph);
58 err = of_address_to_resource(mpscintr, 0, &r[1]);
59 of_node_put(mpscintr);
63 memset(&pdata, 0, sizeof(pdata));
65 pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
69 err = platform_device_add_resources(pdev, r, 2);
73 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
77 err = platform_device_add(pdev);
84 platform_device_put(pdev);
89 static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
92 struct mpsc_pdata pdata;
93 struct platform_device *pdev;
94 const unsigned int *prop;
96 struct device_node *sdma, *brg;
100 /* only register the shared platform device the first time through */
101 if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
104 memset(r, 0, sizeof(r));
106 err = of_address_to_resource(np, 0, &r[0]);
110 of_irq_to_resource(np, 0, &r[4]);
112 ph = of_get_property(np, "sdma", NULL);
113 sdma = of_find_node_by_phandle(*ph);
117 of_irq_to_resource(sdma, 0, &r[3]);
118 err = of_address_to_resource(sdma, 0, &r[1]);
123 ph = of_get_property(np, "brg", NULL);
124 brg = of_find_node_by_phandle(*ph);
128 err = of_address_to_resource(brg, 0, &r[2]);
133 prop = of_get_property(np, "cell-index", NULL);
136 port_number = *(int *)prop;
138 memset(&pdata, 0, sizeof(pdata));
140 pdata.cache_mgmt = 1; /* All current revs need this set */
142 pdata.max_idle = 40; /* default */
143 prop = of_get_property(np, "max_idle", NULL);
145 pdata.max_idle = *prop;
147 prop = of_get_property(brg, "current-speed", NULL);
149 pdata.default_baud = *prop;
151 /* Default is 8 bits, no parity, no flow control */
152 pdata.default_bits = 8;
153 pdata.default_parity = 'n';
154 pdata.default_flow = 'n';
156 prop = of_get_property(np, "chr_1", NULL);
158 pdata.chr_1_val = *prop;
160 prop = of_get_property(np, "chr_2", NULL);
162 pdata.chr_2_val = *prop;
164 prop = of_get_property(np, "chr_10", NULL);
166 pdata.chr_10_val = *prop;
168 prop = of_get_property(np, "mpcr", NULL);
170 pdata.mpcr_val = *prop;
172 prop = of_get_property(brg, "bcr", NULL);
174 pdata.bcr_val = *prop;
176 pdata.brg_can_tune = 1; /* All current revs need this set */
178 prop = of_get_property(brg, "clock-src", NULL);
180 pdata.brg_clk_src = *prop;
182 prop = of_get_property(brg, "clock-frequency", NULL);
184 pdata.brg_clk_freq = *prop;
186 pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
189 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
191 err = platform_device_add_resources(pdev, r, 5);
195 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
199 err = platform_device_add(pdev);
206 platform_device_put(pdev);
211 * Create mv64x60_eth platform devices
213 static struct platform_device * __init mv64x60_eth_register_shared_pdev(
214 struct device_node *np, int id)
216 struct platform_device *pdev;
217 struct resource r[1];
220 err = of_address_to_resource(np, 0, &r[0]);
224 pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, id,
229 static int __init mv64x60_eth_device_setup(struct device_node *np, int id,
230 struct platform_device *shared_pdev)
232 struct resource r[1];
233 struct mv643xx_eth_platform_data pdata;
234 struct platform_device *pdev;
235 struct device_node *phy;
241 memset(r, 0, sizeof(r));
242 of_irq_to_resource(np, 0, &r[0]);
244 memset(&pdata, 0, sizeof(pdata));
246 pdata.shared = shared_pdev;
248 prop = of_get_property(np, "reg", NULL);
251 pdata.port_number = *prop;
253 mac_addr = of_get_mac_address(np);
255 memcpy(pdata.mac_addr, mac_addr, 6);
257 prop = of_get_property(np, "speed", NULL);
261 prop = of_get_property(np, "tx_queue_size", NULL);
263 pdata.tx_queue_size = *prop;
265 prop = of_get_property(np, "rx_queue_size", NULL);
267 pdata.rx_queue_size = *prop;
269 prop = of_get_property(np, "tx_sram_addr", NULL);
271 pdata.tx_sram_addr = *prop;
273 prop = of_get_property(np, "tx_sram_size", NULL);
275 pdata.tx_sram_size = *prop;
277 prop = of_get_property(np, "rx_sram_addr", NULL);
279 pdata.rx_sram_addr = *prop;
281 prop = of_get_property(np, "rx_sram_size", NULL);
283 pdata.rx_sram_size = *prop;
285 ph = of_get_property(np, "phy", NULL);
289 phy = of_find_node_by_phandle(*ph);
293 prop = of_get_property(phy, "reg", NULL);
295 pdata.phy_addr = MV643XX_ETH_PHY_ADDR(*prop);
299 pdev = platform_device_alloc(MV643XX_ETH_NAME, id);
303 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
304 err = platform_device_add_resources(pdev, r, 1);
308 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
312 err = platform_device_add(pdev);
319 platform_device_put(pdev);
324 * Create mv64x60_i2c platform devices
326 static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
328 struct resource r[2];
329 struct platform_device *pdev;
330 struct mv64xxx_i2c_pdata pdata;
331 const unsigned int *prop;
334 memset(r, 0, sizeof(r));
336 err = of_address_to_resource(np, 0, &r[0]);
340 of_irq_to_resource(np, 0, &r[1]);
342 memset(&pdata, 0, sizeof(pdata));
344 pdata.freq_m = 8; /* default */
345 prop = of_get_property(np, "freq_m", NULL);
347 pdata.freq_m = *prop;
349 pdata.freq_n = 3; /* default */
350 prop = of_get_property(np, "freq_n", NULL);
352 pdata.freq_n = *prop;
354 pdata.timeout = 1000; /* default: 1 second */
356 pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
360 err = platform_device_add_resources(pdev, r, 2);
364 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
368 err = platform_device_add(pdev);
375 platform_device_put(pdev);
380 * Create mv64x60_wdt platform devices
382 static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
385 struct platform_device *pdev;
386 struct mv64x60_wdt_pdata pdata;
387 const unsigned int *prop;
390 err = of_address_to_resource(np, 0, &r);
394 memset(&pdata, 0, sizeof(pdata));
396 pdata.timeout = 10; /* Default: 10 seconds */
398 np = of_get_parent(np);
402 prop = of_get_property(np, "clock-frequency", NULL);
406 pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
408 pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
412 err = platform_device_add_resources(pdev, &r, 1);
416 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
420 err = platform_device_add(pdev);
427 platform_device_put(pdev);
431 static int __init mv64x60_device_setup(void)
433 struct device_node *np, *np2;
434 struct platform_device *pdev;
439 for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc") {
440 err = mv64x60_mpsc_device_setup(np, id++);
442 printk(KERN_ERR "Failed to initialize MV64x60 "
443 "serial device %s: error %d.\n",
449 for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") {
450 pdev = mv64x60_eth_register_shared_pdev(np, id++);
453 printk(KERN_ERR "Failed to initialize MV64x60 "
454 "network block %s: error %d.\n",
458 for_each_child_of_node(np, np2) {
459 if (!of_device_is_compatible(np2,
460 "marvell,mv64360-eth"))
462 err = mv64x60_eth_device_setup(np2, id2++, pdev);
464 printk(KERN_ERR "Failed to initialize "
465 "MV64x60 network device %s: "
467 np2->full_name, err);
472 for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c") {
473 err = mv64x60_i2c_device_setup(np, id++);
475 printk(KERN_ERR "Failed to initialize MV64x60 I2C "
476 "bus %s: error %d.\n",
480 /* support up to one watchdog timer */
481 np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
483 if ((err = mv64x60_wdt_device_setup(np, id)))
484 printk(KERN_ERR "Failed to initialize MV64x60 "
485 "Watchdog %s: error %d.\n",
490 /* Now add every node that is on the device bus */
491 for_each_compatible_node(np, NULL, "marvell,mv64360")
492 of_platform_bus_probe(np, of_mv64x60_devices, NULL);
496 arch_initcall(mv64x60_device_setup);
498 static int __init mv64x60_add_mpsc_console(void)
500 struct device_node *np = NULL;
503 prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
507 np = of_find_node_by_path(prop);
511 if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
514 prop = of_get_property(np, "cell-index", NULL);
518 add_preferred_console("ttyMM", *(int *)prop, NULL);
523 console_initcall(mv64x60_add_mpsc_console);