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
[2];
220 err
= of_address_to_resource(np
, 0, &r
[0]);
224 /* register an orion mdio bus driver */
225 r
[1].start
= r
[0].start
+ 0x4;
226 r
[1].end
= r
[0].start
+ 0x84 - 1;
227 r
[1].flags
= IORESOURCE_MEM
;
230 pdev
= platform_device_register_simple("orion-mdio", -1, &r
[1], 1);
235 pdev
= platform_device_register_simple(MV643XX_ETH_SHARED_NAME
, id
,
241 static int __init
mv64x60_eth_device_setup(struct device_node
*np
, int id
,
242 struct platform_device
*shared_pdev
)
244 struct resource r
[1];
245 struct mv643xx_eth_platform_data pdata
;
246 struct platform_device
*pdev
;
247 struct device_node
*phy
;
253 memset(r
, 0, sizeof(r
));
254 of_irq_to_resource(np
, 0, &r
[0]);
256 memset(&pdata
, 0, sizeof(pdata
));
258 pdata
.shared
= shared_pdev
;
260 prop
= of_get_property(np
, "reg", NULL
);
263 pdata
.port_number
= *prop
;
265 mac_addr
= of_get_mac_address(np
);
267 memcpy(pdata
.mac_addr
, mac_addr
, 6);
269 prop
= of_get_property(np
, "speed", NULL
);
273 prop
= of_get_property(np
, "tx_queue_size", NULL
);
275 pdata
.tx_queue_size
= *prop
;
277 prop
= of_get_property(np
, "rx_queue_size", NULL
);
279 pdata
.rx_queue_size
= *prop
;
281 prop
= of_get_property(np
, "tx_sram_addr", NULL
);
283 pdata
.tx_sram_addr
= *prop
;
285 prop
= of_get_property(np
, "tx_sram_size", NULL
);
287 pdata
.tx_sram_size
= *prop
;
289 prop
= of_get_property(np
, "rx_sram_addr", NULL
);
291 pdata
.rx_sram_addr
= *prop
;
293 prop
= of_get_property(np
, "rx_sram_size", NULL
);
295 pdata
.rx_sram_size
= *prop
;
297 ph
= of_get_property(np
, "phy", NULL
);
301 phy
= of_find_node_by_phandle(*ph
);
305 prop
= of_get_property(phy
, "reg", NULL
);
307 pdata
.phy_addr
= MV643XX_ETH_PHY_ADDR(*prop
);
311 pdev
= platform_device_alloc(MV643XX_ETH_NAME
, id
);
315 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
316 err
= platform_device_add_resources(pdev
, r
, 1);
320 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
324 err
= platform_device_add(pdev
);
331 platform_device_put(pdev
);
336 * Create mv64x60_i2c platform devices
338 static int __init
mv64x60_i2c_device_setup(struct device_node
*np
, int id
)
340 struct resource r
[2];
341 struct platform_device
*pdev
;
342 struct mv64xxx_i2c_pdata pdata
;
343 const unsigned int *prop
;
346 memset(r
, 0, sizeof(r
));
348 err
= of_address_to_resource(np
, 0, &r
[0]);
352 of_irq_to_resource(np
, 0, &r
[1]);
354 memset(&pdata
, 0, sizeof(pdata
));
356 pdata
.freq_m
= 8; /* default */
357 prop
= of_get_property(np
, "freq_m", NULL
);
359 pdata
.freq_m
= *prop
;
361 pdata
.freq_n
= 3; /* default */
362 prop
= of_get_property(np
, "freq_n", NULL
);
364 pdata
.freq_n
= *prop
;
366 pdata
.timeout
= 1000; /* default: 1 second */
368 pdev
= platform_device_alloc(MV64XXX_I2C_CTLR_NAME
, id
);
372 err
= platform_device_add_resources(pdev
, r
, 2);
376 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
380 err
= platform_device_add(pdev
);
387 platform_device_put(pdev
);
392 * Create mv64x60_wdt platform devices
394 static int __init
mv64x60_wdt_device_setup(struct device_node
*np
, int id
)
397 struct platform_device
*pdev
;
398 struct mv64x60_wdt_pdata pdata
;
399 const unsigned int *prop
;
402 err
= of_address_to_resource(np
, 0, &r
);
406 memset(&pdata
, 0, sizeof(pdata
));
408 pdata
.timeout
= 10; /* Default: 10 seconds */
410 np
= of_get_parent(np
);
414 prop
= of_get_property(np
, "clock-frequency", NULL
);
418 pdata
.bus_clk
= *prop
/ 1000000; /* wdt driver wants freq in MHz */
420 pdev
= platform_device_alloc(MV64x60_WDT_NAME
, id
);
424 err
= platform_device_add_resources(pdev
, &r
, 1);
428 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
432 err
= platform_device_add(pdev
);
439 platform_device_put(pdev
);
443 static int __init
mv64x60_device_setup(void)
445 struct device_node
*np
, *np2
;
446 struct platform_device
*pdev
;
451 for_each_compatible_node(np
, "serial", "marvell,mv64360-mpsc") {
452 err
= mv64x60_mpsc_device_setup(np
, id
++);
454 printk(KERN_ERR
"Failed to initialize MV64x60 "
455 "serial device %s: error %d.\n",
461 for_each_compatible_node(np
, NULL
, "marvell,mv64360-eth-group") {
462 pdev
= mv64x60_eth_register_shared_pdev(np
, id
++);
465 printk(KERN_ERR
"Failed to initialize MV64x60 "
466 "network block %s: error %d.\n",
470 for_each_child_of_node(np
, np2
) {
471 if (!of_device_is_compatible(np2
,
472 "marvell,mv64360-eth"))
474 err
= mv64x60_eth_device_setup(np2
, id2
++, pdev
);
476 printk(KERN_ERR
"Failed to initialize "
477 "MV64x60 network device %s: "
479 np2
->full_name
, err
);
484 for_each_compatible_node(np
, "i2c", "marvell,mv64360-i2c") {
485 err
= mv64x60_i2c_device_setup(np
, id
++);
487 printk(KERN_ERR
"Failed to initialize MV64x60 I2C "
488 "bus %s: error %d.\n",
492 /* support up to one watchdog timer */
493 np
= of_find_compatible_node(np
, NULL
, "marvell,mv64360-wdt");
495 if ((err
= mv64x60_wdt_device_setup(np
, id
)))
496 printk(KERN_ERR
"Failed to initialize MV64x60 "
497 "Watchdog %s: error %d.\n",
502 /* Now add every node that is on the device bus */
503 for_each_compatible_node(np
, NULL
, "marvell,mv64360")
504 of_platform_bus_probe(np
, of_mv64x60_devices
, NULL
);
508 arch_initcall(mv64x60_device_setup
);
510 static int __init
mv64x60_add_mpsc_console(void)
512 struct device_node
*np
= NULL
;
515 prop
= of_get_property(of_chosen
, "linux,stdout-path", NULL
);
519 np
= of_find_node_by_path(prop
);
523 if (!of_device_is_compatible(np
, "marvell,mv64360-mpsc"))
526 prop
= of_get_property(np
, "cell-index", NULL
);
530 add_preferred_console("ttyMM", *(int *)prop
, NULL
);
535 console_initcall(mv64x60_add_mpsc_console
);