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>
22 * These functions provide the necessary setup for the mv64x60 drivers.
23 * These drivers are unusual in that they work on both the MIPS and PowerPC
24 * architectures. Because of that, the drivers do not support the normal
25 * PowerPC of_platform_bus_type. They support platform_bus_type instead.
29 * Create MPSC platform devices
31 static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
33 struct platform_device *pdev;
35 struct mpsc_shared_pdata pdata;
37 struct device_node *mpscrouting, *mpscintr;
40 ph = of_get_property(np, "mpscrouting", NULL);
41 mpscrouting = of_find_node_by_phandle(*ph);
45 err = of_address_to_resource(mpscrouting, 0, &r[0]);
46 of_node_put(mpscrouting);
50 ph = of_get_property(np, "mpscintr", NULL);
51 mpscintr = of_find_node_by_phandle(*ph);
55 err = of_address_to_resource(mpscintr, 0, &r[1]);
56 of_node_put(mpscintr);
60 memset(&pdata, 0, sizeof(pdata));
62 pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
66 err = platform_device_add_resources(pdev, r, 2);
70 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
74 err = platform_device_add(pdev);
81 platform_device_put(pdev);
86 static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
89 struct mpsc_pdata pdata;
90 struct platform_device *pdev;
91 const unsigned int *prop;
93 struct device_node *sdma, *brg;
97 /* only register the shared platform device the first time through */
98 if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
101 memset(r, 0, sizeof(r));
103 err = of_address_to_resource(np, 0, &r[0]);
107 of_irq_to_resource(np, 0, &r[4]);
109 ph = of_get_property(np, "sdma", NULL);
110 sdma = of_find_node_by_phandle(*ph);
114 of_irq_to_resource(sdma, 0, &r[3]);
115 err = of_address_to_resource(sdma, 0, &r[1]);
120 ph = of_get_property(np, "brg", NULL);
121 brg = of_find_node_by_phandle(*ph);
125 err = of_address_to_resource(brg, 0, &r[2]);
130 prop = of_get_property(np, "cell-index", NULL);
133 port_number = *(int *)prop;
135 memset(&pdata, 0, sizeof(pdata));
137 pdata.cache_mgmt = 1; /* All current revs need this set */
139 pdata.max_idle = 40; /* default */
140 prop = of_get_property(np, "max_idle", NULL);
142 pdata.max_idle = *prop;
144 prop = of_get_property(brg, "current-speed", NULL);
146 pdata.default_baud = *prop;
148 /* Default is 8 bits, no parity, no flow control */
149 pdata.default_bits = 8;
150 pdata.default_parity = 'n';
151 pdata.default_flow = 'n';
153 prop = of_get_property(np, "chr_1", NULL);
155 pdata.chr_1_val = *prop;
157 prop = of_get_property(np, "chr_2", NULL);
159 pdata.chr_2_val = *prop;
161 prop = of_get_property(np, "chr_10", NULL);
163 pdata.chr_10_val = *prop;
165 prop = of_get_property(np, "mpcr", NULL);
167 pdata.mpcr_val = *prop;
169 prop = of_get_property(brg, "bcr", NULL);
171 pdata.bcr_val = *prop;
173 pdata.brg_can_tune = 1; /* All current revs need this set */
175 prop = of_get_property(brg, "clock-src", NULL);
177 pdata.brg_clk_src = *prop;
179 prop = of_get_property(brg, "clock-frequency", NULL);
181 pdata.brg_clk_freq = *prop;
183 pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
187 err = platform_device_add_resources(pdev, r, 5);
191 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
195 err = platform_device_add(pdev);
202 platform_device_put(pdev);
207 * Create mv64x60_eth platform devices
209 static int __init eth_register_shared_pdev(struct device_node *np)
211 struct platform_device *pdev;
212 struct resource r[1];
215 np = of_get_parent(np);
219 err = of_address_to_resource(np, 0, &r[0]);
224 pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, 0,
227 return PTR_ERR(pdev);
232 static int __init mv64x60_eth_device_setup(struct device_node *np, int id)
234 struct resource r[1];
235 struct mv643xx_eth_platform_data pdata;
236 struct platform_device *pdev;
237 struct device_node *phy;
243 /* only register the shared platform device the first time through */
244 if (id == 0 && (err = eth_register_shared_pdev(np)))
247 memset(r, 0, sizeof(r));
248 of_irq_to_resource(np, 0, &r[0]);
250 memset(&pdata, 0, sizeof(pdata));
252 prop = of_get_property(np, "block-index", 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.force_phy_addr = 1;
300 pdata.phy_addr = *prop;
305 pdev = platform_device_alloc(MV643XX_ETH_NAME, pdata.port_number);
309 err = platform_device_add_resources(pdev, r, 1);
313 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
317 err = platform_device_add(pdev);
324 platform_device_put(pdev);
329 * Create mv64x60_i2c platform devices
331 static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
333 struct resource r[2];
334 struct platform_device *pdev;
335 struct mv64xxx_i2c_pdata pdata;
336 const unsigned int *prop;
339 memset(r, 0, sizeof(r));
341 err = of_address_to_resource(np, 0, &r[0]);
345 of_irq_to_resource(np, 0, &r[1]);
347 memset(&pdata, 0, sizeof(pdata));
349 pdata.freq_m = 8; /* default */
350 prop = of_get_property(np, "freq_m", NULL);
353 pdata.freq_m = *prop;
355 pdata.freq_m = 3; /* default */
356 prop = of_get_property(np, "freq_n", NULL);
359 pdata.freq_n = *prop;
361 pdata.timeout = 1000; /* default: 1 second */
363 pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
367 err = platform_device_add_resources(pdev, r, 2);
371 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
375 err = platform_device_add(pdev);
382 platform_device_put(pdev);
387 * Create mv64x60_wdt platform devices
389 static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
392 struct platform_device *pdev;
393 struct mv64x60_wdt_pdata pdata;
394 const unsigned int *prop;
397 err = of_address_to_resource(np, 0, &r);
401 memset(&pdata, 0, sizeof(pdata));
403 pdata.timeout = 10; /* Default: 10 seconds */
405 np = of_get_parent(np);
409 prop = of_get_property(np, "clock-frequency", NULL);
413 pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
415 pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
419 err = platform_device_add_resources(pdev, &r, 1);
423 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
427 err = platform_device_add(pdev);
434 platform_device_put(pdev);
438 static int __init mv64x60_device_setup(void)
440 struct device_node *np = NULL;
445 for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc")
446 if ((err = mv64x60_mpsc_device_setup(np, id++)))
450 for_each_compatible_node(np, "network", "marvell,mv64360-eth")
451 if ((err = mv64x60_eth_device_setup(np, id++)))
455 for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c")
456 if ((err = mv64x60_i2c_device_setup(np, id++)))
459 /* support up to one watchdog timer */
460 np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
462 if ((err = mv64x60_wdt_device_setup(np, id)))
473 arch_initcall(mv64x60_device_setup);
475 static int __init mv64x60_add_mpsc_console(void)
477 struct device_node *np = NULL;
480 prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
484 np = of_find_node_by_path(prop);
488 if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
491 prop = of_get_property(np, "cell-index", NULL);
495 add_preferred_console("ttyMM", *(int *)prop, NULL);
500 console_initcall(mv64x60_add_mpsc_console);