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>
23 * These functions provide the necessary setup for the mv64x60 drivers.
24 * These drivers are unusual in that they work on both the MIPS and PowerPC
25 * architectures. Because of that, the drivers do not support the normal
26 * PowerPC of_platform_bus_type. They support platform_bus_type instead.
29 static struct of_device_id __initdata of_mv64x60_devices
[] = {
30 { .compatible
= "marvell,mv64306-devctrl", },
35 * Create MPSC platform devices
37 static int __init
mv64x60_mpsc_register_shared_pdev(struct device_node
*np
)
39 struct platform_device
*pdev
;
41 struct mpsc_shared_pdata pdata
;
43 struct device_node
*mpscrouting
, *mpscintr
;
46 ph
= of_get_property(np
, "mpscrouting", NULL
);
47 mpscrouting
= of_find_node_by_phandle(*ph
);
51 err
= of_address_to_resource(mpscrouting
, 0, &r
[0]);
52 of_node_put(mpscrouting
);
56 ph
= of_get_property(np
, "mpscintr", NULL
);
57 mpscintr
= of_find_node_by_phandle(*ph
);
61 err
= of_address_to_resource(mpscintr
, 0, &r
[1]);
62 of_node_put(mpscintr
);
66 memset(&pdata
, 0, sizeof(pdata
));
68 pdev
= platform_device_alloc(MPSC_SHARED_NAME
, 0);
72 err
= platform_device_add_resources(pdev
, r
, 2);
76 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
80 err
= platform_device_add(pdev
);
87 platform_device_put(pdev
);
92 static int __init
mv64x60_mpsc_device_setup(struct device_node
*np
, int id
)
95 struct mpsc_pdata pdata
;
96 struct platform_device
*pdev
;
97 const unsigned int *prop
;
99 struct device_node
*sdma
, *brg
;
103 /* only register the shared platform device the first time through */
104 if (id
== 0 && (err
= mv64x60_mpsc_register_shared_pdev(np
)))
107 memset(r
, 0, sizeof(r
));
109 err
= of_address_to_resource(np
, 0, &r
[0]);
113 of_irq_to_resource(np
, 0, &r
[4]);
115 ph
= of_get_property(np
, "sdma", NULL
);
116 sdma
= of_find_node_by_phandle(*ph
);
120 of_irq_to_resource(sdma
, 0, &r
[3]);
121 err
= of_address_to_resource(sdma
, 0, &r
[1]);
126 ph
= of_get_property(np
, "brg", NULL
);
127 brg
= of_find_node_by_phandle(*ph
);
131 err
= of_address_to_resource(brg
, 0, &r
[2]);
136 prop
= of_get_property(np
, "cell-index", NULL
);
139 port_number
= *(int *)prop
;
141 memset(&pdata
, 0, sizeof(pdata
));
143 pdata
.cache_mgmt
= 1; /* All current revs need this set */
145 pdata
.max_idle
= 40; /* default */
146 prop
= of_get_property(np
, "max_idle", NULL
);
148 pdata
.max_idle
= *prop
;
150 prop
= of_get_property(brg
, "current-speed", NULL
);
152 pdata
.default_baud
= *prop
;
154 /* Default is 8 bits, no parity, no flow control */
155 pdata
.default_bits
= 8;
156 pdata
.default_parity
= 'n';
157 pdata
.default_flow
= 'n';
159 prop
= of_get_property(np
, "chr_1", NULL
);
161 pdata
.chr_1_val
= *prop
;
163 prop
= of_get_property(np
, "chr_2", NULL
);
165 pdata
.chr_2_val
= *prop
;
167 prop
= of_get_property(np
, "chr_10", NULL
);
169 pdata
.chr_10_val
= *prop
;
171 prop
= of_get_property(np
, "mpcr", NULL
);
173 pdata
.mpcr_val
= *prop
;
175 prop
= of_get_property(brg
, "bcr", NULL
);
177 pdata
.bcr_val
= *prop
;
179 pdata
.brg_can_tune
= 1; /* All current revs need this set */
181 prop
= of_get_property(brg
, "clock-src", NULL
);
183 pdata
.brg_clk_src
= *prop
;
185 prop
= of_get_property(brg
, "clock-frequency", NULL
);
187 pdata
.brg_clk_freq
= *prop
;
189 pdev
= platform_device_alloc(MPSC_CTLR_NAME
, port_number
);
193 err
= platform_device_add_resources(pdev
, r
, 5);
197 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
201 err
= platform_device_add(pdev
);
208 platform_device_put(pdev
);
213 * Create mv64x60_eth platform devices
215 static struct platform_device
* __init
mv64x60_eth_register_shared_pdev(
216 struct device_node
*np
, int id
)
218 struct platform_device
*pdev
;
219 struct resource r
[1];
222 err
= of_address_to_resource(np
, 0, &r
[0]);
226 pdev
= platform_device_register_simple(MV643XX_ETH_SHARED_NAME
, id
,
231 static int __init
mv64x60_eth_device_setup(struct device_node
*np
, int id
,
232 struct platform_device
*shared_pdev
)
234 struct resource r
[1];
235 struct mv643xx_eth_platform_data pdata
;
236 struct platform_device
*pdev
;
237 struct device_node
*phy
;
243 memset(r
, 0, sizeof(r
));
244 of_irq_to_resource(np
, 0, &r
[0]);
246 memset(&pdata
, 0, sizeof(pdata
));
248 pdata
.shared
= shared_pdev
;
250 prop
= of_get_property(np
, "reg", NULL
);
253 pdata
.port_number
= *prop
;
255 mac_addr
= of_get_mac_address(np
);
257 memcpy(pdata
.mac_addr
, mac_addr
, 6);
259 prop
= of_get_property(np
, "speed", NULL
);
263 prop
= of_get_property(np
, "tx_queue_size", NULL
);
265 pdata
.tx_queue_size
= *prop
;
267 prop
= of_get_property(np
, "rx_queue_size", NULL
);
269 pdata
.rx_queue_size
= *prop
;
271 prop
= of_get_property(np
, "tx_sram_addr", NULL
);
273 pdata
.tx_sram_addr
= *prop
;
275 prop
= of_get_property(np
, "tx_sram_size", NULL
);
277 pdata
.tx_sram_size
= *prop
;
279 prop
= of_get_property(np
, "rx_sram_addr", NULL
);
281 pdata
.rx_sram_addr
= *prop
;
283 prop
= of_get_property(np
, "rx_sram_size", NULL
);
285 pdata
.rx_sram_size
= *prop
;
287 ph
= of_get_property(np
, "phy", NULL
);
291 phy
= of_find_node_by_phandle(*ph
);
295 prop
= of_get_property(phy
, "reg", NULL
);
297 pdata
.phy_addr
= MV643XX_ETH_PHY_ADDR(*prop
);
301 pdev
= platform_device_alloc(MV643XX_ETH_NAME
, id
);
305 err
= platform_device_add_resources(pdev
, r
, 1);
309 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
313 err
= platform_device_add(pdev
);
320 platform_device_put(pdev
);
325 * Create mv64x60_i2c platform devices
327 static int __init
mv64x60_i2c_device_setup(struct device_node
*np
, int id
)
329 struct resource r
[2];
330 struct platform_device
*pdev
;
331 struct mv64xxx_i2c_pdata pdata
;
332 const unsigned int *prop
;
335 memset(r
, 0, sizeof(r
));
337 err
= of_address_to_resource(np
, 0, &r
[0]);
341 of_irq_to_resource(np
, 0, &r
[1]);
343 memset(&pdata
, 0, sizeof(pdata
));
345 pdata
.freq_m
= 8; /* default */
346 prop
= of_get_property(np
, "freq_m", NULL
);
348 pdata
.freq_m
= *prop
;
350 pdata
.freq_m
= 3; /* default */
351 prop
= of_get_property(np
, "freq_n", NULL
);
353 pdata
.freq_n
= *prop
;
355 pdata
.timeout
= 1000; /* default: 1 second */
357 pdev
= platform_device_alloc(MV64XXX_I2C_CTLR_NAME
, id
);
361 err
= platform_device_add_resources(pdev
, r
, 2);
365 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
369 err
= platform_device_add(pdev
);
376 platform_device_put(pdev
);
381 * Create mv64x60_wdt platform devices
383 static int __init
mv64x60_wdt_device_setup(struct device_node
*np
, int id
)
386 struct platform_device
*pdev
;
387 struct mv64x60_wdt_pdata pdata
;
388 const unsigned int *prop
;
391 err
= of_address_to_resource(np
, 0, &r
);
395 memset(&pdata
, 0, sizeof(pdata
));
397 pdata
.timeout
= 10; /* Default: 10 seconds */
399 np
= of_get_parent(np
);
403 prop
= of_get_property(np
, "clock-frequency", NULL
);
407 pdata
.bus_clk
= *prop
/ 1000000; /* wdt driver wants freq in MHz */
409 pdev
= platform_device_alloc(MV64x60_WDT_NAME
, id
);
413 err
= platform_device_add_resources(pdev
, &r
, 1);
417 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
421 err
= platform_device_add(pdev
);
428 platform_device_put(pdev
);
432 static int __init
mv64x60_device_setup(void)
434 struct device_node
*np
, *np2
;
435 struct platform_device
*pdev
;
440 for_each_compatible_node(np
, "serial", "marvell,mv64360-mpsc") {
441 err
= mv64x60_mpsc_device_setup(np
, id
++);
443 printk(KERN_ERR
"Failed to initialize MV64x60 "
444 "serial device %s: error %d.\n",
450 for_each_compatible_node(np
, NULL
, "marvell,mv64360-eth-group") {
451 pdev
= mv64x60_eth_register_shared_pdev(np
, id
++);
454 printk(KERN_ERR
"Failed to initialize MV64x60 "
455 "network block %s: error %d.\n",
459 for_each_child_of_node(np
, np2
) {
460 if (!of_device_is_compatible(np2
,
461 "marvell,mv64360-eth"))
463 err
= mv64x60_eth_device_setup(np2
, id2
++, pdev
);
465 printk(KERN_ERR
"Failed to initialize "
466 "MV64x60 network device %s: "
468 np2
->full_name
, err
);
473 for_each_compatible_node(np
, "i2c", "marvell,mv64360-i2c") {
474 err
= mv64x60_i2c_device_setup(np
, id
++);
476 printk(KERN_ERR
"Failed to initialize MV64x60 I2C "
477 "bus %s: error %d.\n",
481 /* support up to one watchdog timer */
482 np
= of_find_compatible_node(np
, NULL
, "marvell,mv64360-wdt");
484 if ((err
= mv64x60_wdt_device_setup(np
, id
)))
485 printk(KERN_ERR
"Failed to initialize MV64x60 "
486 "Watchdog %s: error %d.\n",
491 /* Now add every node that is on the device bus */
492 for_each_compatible_node(np
, NULL
, "marvell,mv64360")
493 of_platform_bus_probe(np
, of_mv64x60_devices
, NULL
);
497 arch_initcall(mv64x60_device_setup
);
499 static int __init
mv64x60_add_mpsc_console(void)
501 struct device_node
*np
= NULL
;
504 prop
= of_get_property(of_chosen
, "linux,stdout-path", NULL
);
508 np
= of_find_node_by_path(prop
);
512 if (!of_device_is_compatible(np
, "marvell,mv64360-mpsc"))
515 prop
= of_get_property(np
, "cell-index", NULL
);
519 add_preferred_console("ttyMM", *(int *)prop
, NULL
);
524 console_initcall(mv64x60_add_mpsc_console
);