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>
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
;
37 struct mpsc_shared_pdata pdata
;
39 struct device_node
*mpscrouting
, *mpscintr
;
42 ph
= of_get_property(np
, "mpscrouting", NULL
);
43 mpscrouting
= of_find_node_by_phandle(*ph
);
47 err
= of_address_to_resource(mpscrouting
, 0, &r
[0]);
48 of_node_put(mpscrouting
);
52 ph
= of_get_property(np
, "mpscintr", NULL
);
53 mpscintr
= of_find_node_by_phandle(*ph
);
57 err
= of_address_to_resource(mpscintr
, 0, &r
[1]);
58 of_node_put(mpscintr
);
62 memset(&pdata
, 0, sizeof(pdata
));
64 pdev
= platform_device_alloc(MPSC_SHARED_NAME
, 0);
68 err
= platform_device_add_resources(pdev
, r
, 2);
72 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
76 err
= platform_device_add(pdev
);
83 platform_device_put(pdev
);
88 static int __init
mv64x60_mpsc_device_setup(struct device_node
*np
, int id
)
91 struct mpsc_pdata pdata
;
92 struct platform_device
*pdev
;
93 const unsigned int *prop
;
95 struct device_node
*sdma
, *brg
;
99 /* only register the shared platform device the first time through */
100 if (id
== 0 && (err
= mv64x60_mpsc_register_shared_pdev(np
)))
103 memset(r
, 0, sizeof(r
));
105 err
= of_address_to_resource(np
, 0, &r
[0]);
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
);
116 of_irq_to_resource(sdma
, 0, &r
[3]);
117 err
= of_address_to_resource(sdma
, 0, &r
[1]);
122 ph
= of_get_property(np
, "brg", NULL
);
123 brg
= of_find_node_by_phandle(*ph
);
127 err
= of_address_to_resource(brg
, 0, &r
[2]);
132 prop
= of_get_property(np
, "cell-index", NULL
);
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
);
144 pdata
.max_idle
= *prop
;
146 prop
= of_get_property(brg
, "current-speed", NULL
);
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
);
157 pdata
.chr_1_val
= *prop
;
159 prop
= of_get_property(np
, "chr_2", NULL
);
161 pdata
.chr_2_val
= *prop
;
163 prop
= of_get_property(np
, "chr_10", NULL
);
165 pdata
.chr_10_val
= *prop
;
167 prop
= of_get_property(np
, "mpcr", NULL
);
169 pdata
.mpcr_val
= *prop
;
171 prop
= of_get_property(brg
, "bcr", NULL
);
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
);
179 pdata
.brg_clk_src
= *prop
;
181 prop
= of_get_property(brg
, "clock-frequency", NULL
);
183 pdata
.brg_clk_freq
= *prop
;
185 pdev
= platform_device_alloc(MPSC_CTLR_NAME
, port_number
);
188 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
190 err
= platform_device_add_resources(pdev
, r
, 5);
194 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
198 err
= platform_device_add(pdev
);
205 platform_device_put(pdev
);
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];
219 err
= of_address_to_resource(np
, 0, &r
[0]);
223 pdev
= platform_device_register_simple(MV643XX_ETH_SHARED_NAME
, id
,
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
;
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
);
250 pdata
.port_number
= *prop
;
252 mac_addr
= of_get_mac_address(np
);
254 memcpy(pdata
.mac_addr
, mac_addr
, 6);
256 prop
= of_get_property(np
, "speed", NULL
);
260 prop
= of_get_property(np
, "tx_queue_size", NULL
);
262 pdata
.tx_queue_size
= *prop
;
264 prop
= of_get_property(np
, "rx_queue_size", NULL
);
266 pdata
.rx_queue_size
= *prop
;
268 prop
= of_get_property(np
, "tx_sram_addr", NULL
);
270 pdata
.tx_sram_addr
= *prop
;
272 prop
= of_get_property(np
, "tx_sram_size", NULL
);
274 pdata
.tx_sram_size
= *prop
;
276 prop
= of_get_property(np
, "rx_sram_addr", NULL
);
278 pdata
.rx_sram_addr
= *prop
;
280 prop
= of_get_property(np
, "rx_sram_size", NULL
);
282 pdata
.rx_sram_size
= *prop
;
284 ph
= of_get_property(np
, "phy", NULL
);
288 phy
= of_find_node_by_phandle(*ph
);
292 prop
= of_get_property(phy
, "reg", NULL
);
294 pdata
.phy_addr
= MV643XX_ETH_PHY_ADDR(*prop
);
298 pdev
= platform_device_alloc(MV643XX_ETH_NAME
, id
);
302 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
303 err
= platform_device_add_resources(pdev
, r
, 1);
307 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
311 err
= platform_device_add(pdev
);
318 platform_device_put(pdev
);
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
;
333 memset(r
, 0, sizeof(r
));
335 err
= of_address_to_resource(np
, 0, &r
[0]);
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
);
346 pdata
.freq_m
= *prop
;
348 pdata
.freq_m
= 3; /* default */
349 prop
= of_get_property(np
, "freq_n", NULL
);
351 pdata
.freq_n
= *prop
;
353 pdata
.timeout
= 1000; /* default: 1 second */
355 pdev
= platform_device_alloc(MV64XXX_I2C_CTLR_NAME
, id
);
359 err
= platform_device_add_resources(pdev
, r
, 2);
363 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
367 err
= platform_device_add(pdev
);
374 platform_device_put(pdev
);
379 * Create mv64x60_wdt platform devices
381 static int __init
mv64x60_wdt_device_setup(struct device_node
*np
, int id
)
384 struct platform_device
*pdev
;
385 struct mv64x60_wdt_pdata pdata
;
386 const unsigned int *prop
;
389 err
= of_address_to_resource(np
, 0, &r
);
393 memset(&pdata
, 0, sizeof(pdata
));
395 pdata
.timeout
= 10; /* Default: 10 seconds */
397 np
= of_get_parent(np
);
401 prop
= of_get_property(np
, "clock-frequency", NULL
);
405 pdata
.bus_clk
= *prop
/ 1000000; /* wdt driver wants freq in MHz */
407 pdev
= platform_device_alloc(MV64x60_WDT_NAME
, id
);
411 err
= platform_device_add_resources(pdev
, &r
, 1);
415 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
419 err
= platform_device_add(pdev
);
426 platform_device_put(pdev
);
430 static int __init
mv64x60_device_setup(void)
432 struct device_node
*np
, *np2
;
433 struct platform_device
*pdev
;
438 for_each_compatible_node(np
, "serial", "marvell,mv64360-mpsc") {
439 err
= mv64x60_mpsc_device_setup(np
, id
++);
441 printk(KERN_ERR
"Failed to initialize MV64x60 "
442 "serial device %s: error %d.\n",
448 for_each_compatible_node(np
, NULL
, "marvell,mv64360-eth-group") {
449 pdev
= mv64x60_eth_register_shared_pdev(np
, id
++);
452 printk(KERN_ERR
"Failed to initialize MV64x60 "
453 "network block %s: error %d.\n",
457 for_each_child_of_node(np
, np2
) {
458 if (!of_device_is_compatible(np2
,
459 "marvell,mv64360-eth"))
461 err
= mv64x60_eth_device_setup(np2
, id2
++, pdev
);
463 printk(KERN_ERR
"Failed to initialize "
464 "MV64x60 network device %s: "
466 np2
->full_name
, err
);
471 for_each_compatible_node(np
, "i2c", "marvell,mv64360-i2c") {
472 err
= mv64x60_i2c_device_setup(np
, id
++);
474 printk(KERN_ERR
"Failed to initialize MV64x60 I2C "
475 "bus %s: error %d.\n",
479 /* support up to one watchdog timer */
480 np
= of_find_compatible_node(np
, NULL
, "marvell,mv64360-wdt");
482 if ((err
= mv64x60_wdt_device_setup(np
, id
)))
483 printk(KERN_ERR
"Failed to initialize MV64x60 "
484 "Watchdog %s: error %d.\n",
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
);
495 arch_initcall(mv64x60_device_setup
);
497 static int __init
mv64x60_add_mpsc_console(void)
499 struct device_node
*np
= NULL
;
502 prop
= of_get_property(of_chosen
, "linux,stdout-path", NULL
);
506 np
= of_find_node_by_path(prop
);
510 if (!of_device_is_compatible(np
, "marvell,mv64360-mpsc"))
513 prop
= of_get_property(np
, "cell-index", NULL
);
517 add_preferred_console("ttyMM", *(int *)prop
, NULL
);
522 console_initcall(mv64x60_add_mpsc_console
);