Blame view
arch/powerpc/sysdev/mv64x60_dev.c
11.1 KB
52d3aff90 [POWERPC] Create ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * Platform device setup for Marvell mv64360/mv64460 host bridges (Discovery) * * Author: Dale Farnsworth <dale@farnsworth.org> * * 2007 (c) MontaVista, Software, Inc. This file is licensed under * the terms of the GNU General Public License version 2. This program * is licensed "as is" without any warranty of any kind, whether express * or implied. */ #include <linux/stddef.h> #include <linux/kernel.h> #include <linux/init.h> |
542c98c06 [POWERPC] Call ad... |
15 |
#include <linux/console.h> |
52d3aff90 [POWERPC] Create ... |
16 17 |
#include <linux/mv643xx.h> #include <linux/platform_device.h> |
683307da0 [POWERPC] Create ... |
18 |
#include <linux/of_platform.h> |
4b6ba8aac of/net: Move of_g... |
19 |
#include <linux/of_net.h> |
e0508b151 powerpc: Add cohe... |
20 |
#include <linux/dma-mapping.h> |
52d3aff90 [POWERPC] Create ... |
21 22 |
#include <asm/prom.h> |
eca393016 of: Merge of_plat... |
23 |
/* These functions provide the necessary setup for the mv64x60 drivers. */ |
52d3aff90 [POWERPC] Create ... |
24 |
|
683307da0 [POWERPC] Create ... |
25 26 27 28 |
static struct of_device_id __initdata of_mv64x60_devices[] = { { .compatible = "marvell,mv64306-devctrl", }, {} }; |
52d3aff90 [POWERPC] Create ... |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
/* * Create MPSC platform devices */ static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np) { struct platform_device *pdev; struct resource r[2]; struct mpsc_shared_pdata pdata; const phandle *ph; struct device_node *mpscrouting, *mpscintr; int err; ph = of_get_property(np, "mpscrouting", NULL); mpscrouting = of_find_node_by_phandle(*ph); if (!mpscrouting) return -ENODEV; err = of_address_to_resource(mpscrouting, 0, &r[0]); of_node_put(mpscrouting); if (err) return err; ph = of_get_property(np, "mpscintr", NULL); mpscintr = of_find_node_by_phandle(*ph); if (!mpscintr) return -ENODEV; err = of_address_to_resource(mpscintr, 0, &r[1]); of_node_put(mpscintr); if (err) return err; memset(&pdata, 0, sizeof(pdata)); pdev = platform_device_alloc(MPSC_SHARED_NAME, 0); if (!pdev) return -ENOMEM; err = platform_device_add_resources(pdev, r, 2); if (err) goto error; err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (err) goto error; err = platform_device_add(pdev); if (err) goto error; return 0; error: platform_device_put(pdev); return err; } static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id) { struct resource r[5]; struct mpsc_pdata pdata; struct platform_device *pdev; const unsigned int *prop; const phandle *ph; struct device_node *sdma, *brg; int err; int port_number; /* only register the shared platform device the first time through */ if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np))) return err; memset(r, 0, sizeof(r)); err = of_address_to_resource(np, 0, &r[0]); if (err) return err; of_irq_to_resource(np, 0, &r[4]); ph = of_get_property(np, "sdma", NULL); sdma = of_find_node_by_phandle(*ph); if (!sdma) return -ENODEV; of_irq_to_resource(sdma, 0, &r[3]); err = of_address_to_resource(sdma, 0, &r[1]); of_node_put(sdma); if (err) return err; ph = of_get_property(np, "brg", NULL); brg = of_find_node_by_phandle(*ph); if (!brg) return -ENODEV; err = of_address_to_resource(brg, 0, &r[2]); of_node_put(brg); if (err) return err; |
1791f91bc [POWERPC] prpmc28... |
130 |
prop = of_get_property(np, "cell-index", NULL); |
52d3aff90 [POWERPC] Create ... |
131 132 133 134 135 136 137 |
if (!prop) return -ENODEV; port_number = *(int *)prop; memset(&pdata, 0, sizeof(pdata)); pdata.cache_mgmt = 1; /* All current revs need this set */ |
1791f91bc [POWERPC] prpmc28... |
138 |
pdata.max_idle = 40; /* default */ |
52d3aff90 [POWERPC] Create ... |
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
prop = of_get_property(np, "max_idle", NULL); if (prop) pdata.max_idle = *prop; prop = of_get_property(brg, "current-speed", NULL); if (prop) pdata.default_baud = *prop; /* Default is 8 bits, no parity, no flow control */ pdata.default_bits = 8; pdata.default_parity = 'n'; pdata.default_flow = 'n'; prop = of_get_property(np, "chr_1", NULL); if (prop) pdata.chr_1_val = *prop; prop = of_get_property(np, "chr_2", NULL); if (prop) pdata.chr_2_val = *prop; prop = of_get_property(np, "chr_10", NULL); if (prop) pdata.chr_10_val = *prop; prop = of_get_property(np, "mpcr", NULL); if (prop) pdata.mpcr_val = *prop; prop = of_get_property(brg, "bcr", NULL); if (prop) pdata.bcr_val = *prop; pdata.brg_can_tune = 1; /* All current revs need this set */ prop = of_get_property(brg, "clock-src", NULL); if (prop) pdata.brg_clk_src = *prop; prop = of_get_property(brg, "clock-frequency", NULL); if (prop) pdata.brg_clk_freq = *prop; pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number); if (!pdev) return -ENOMEM; |
e0508b151 powerpc: Add cohe... |
185 |
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
52d3aff90 [POWERPC] Create ... |
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
err = platform_device_add_resources(pdev, r, 5); if (err) goto error; err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (err) goto error; err = platform_device_add(pdev); if (err) goto error; return 0; error: platform_device_put(pdev); return err; } |
649c8e028 [POWERPC] Create ... |
205 206 207 |
/* * Create mv64x60_eth platform devices */ |
a0916bd64 [POWERPC] mv643xx... |
208 209 |
static struct platform_device * __init mv64x60_eth_register_shared_pdev( struct device_node *np, int id) |
649c8e028 [POWERPC] Create ... |
210 211 212 213 |
{ struct platform_device *pdev; struct resource r[1]; int err; |
649c8e028 [POWERPC] Create ... |
214 |
err = of_address_to_resource(np, 0, &r[0]); |
649c8e028 [POWERPC] Create ... |
215 |
if (err) |
a0916bd64 [POWERPC] mv643xx... |
216 |
return ERR_PTR(err); |
649c8e028 [POWERPC] Create ... |
217 |
|
a0916bd64 [POWERPC] mv643xx... |
218 |
pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, id, |
649c8e028 [POWERPC] Create ... |
219 |
r, 1); |
a0916bd64 [POWERPC] mv643xx... |
220 |
return pdev; |
649c8e028 [POWERPC] Create ... |
221 |
} |
a0916bd64 [POWERPC] mv643xx... |
222 223 |
static int __init mv64x60_eth_device_setup(struct device_node *np, int id, struct platform_device *shared_pdev) |
649c8e028 [POWERPC] Create ... |
224 225 226 227 228 229 230 231 232 |
{ struct resource r[1]; struct mv643xx_eth_platform_data pdata; struct platform_device *pdev; struct device_node *phy; const u8 *mac_addr; const int *prop; const phandle *ph; int err; |
649c8e028 [POWERPC] Create ... |
233 234 235 236 |
memset(r, 0, sizeof(r)); of_irq_to_resource(np, 0, &r[0]); memset(&pdata, 0, sizeof(pdata)); |
fa3959f45 mv643xx_eth: get ... |
237 |
pdata.shared = shared_pdev; |
a0916bd64 [POWERPC] mv643xx... |
238 |
prop = of_get_property(np, "reg", NULL); |
649c8e028 [POWERPC] Create ... |
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
if (!prop) return -ENODEV; pdata.port_number = *prop; mac_addr = of_get_mac_address(np); if (mac_addr) memcpy(pdata.mac_addr, mac_addr, 6); prop = of_get_property(np, "speed", NULL); if (prop) pdata.speed = *prop; prop = of_get_property(np, "tx_queue_size", NULL); if (prop) pdata.tx_queue_size = *prop; prop = of_get_property(np, "rx_queue_size", NULL); if (prop) pdata.rx_queue_size = *prop; prop = of_get_property(np, "tx_sram_addr", NULL); if (prop) pdata.tx_sram_addr = *prop; prop = of_get_property(np, "tx_sram_size", NULL); if (prop) pdata.tx_sram_size = *prop; prop = of_get_property(np, "rx_sram_addr", NULL); if (prop) pdata.rx_sram_addr = *prop; prop = of_get_property(np, "rx_sram_size", NULL); if (prop) pdata.rx_sram_size = *prop; ph = of_get_property(np, "phy", NULL); if (!ph) return -ENODEV; phy = of_find_node_by_phandle(*ph); if (phy == NULL) return -ENODEV; prop = of_get_property(phy, "reg", NULL); |
ac840605f mv643xx_eth: remo... |
284 285 |
if (prop) pdata.phy_addr = MV643XX_ETH_PHY_ADDR(*prop); |
649c8e028 [POWERPC] Create ... |
286 287 |
of_node_put(phy); |
a0916bd64 [POWERPC] mv643xx... |
288 |
pdev = platform_device_alloc(MV643XX_ETH_NAME, id); |
649c8e028 [POWERPC] Create ... |
289 290 |
if (!pdev) return -ENOMEM; |
e0508b151 powerpc: Add cohe... |
291 |
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
649c8e028 [POWERPC] Create ... |
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
err = platform_device_add_resources(pdev, r, 1); if (err) goto error; err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (err) goto error; err = platform_device_add(pdev); if (err) goto error; return 0; error: platform_device_put(pdev); return err; } |
01f0e78e1 [POWERPC] Create ... |
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
/* * Create mv64x60_i2c platform devices */ static int __init mv64x60_i2c_device_setup(struct device_node *np, int id) { struct resource r[2]; struct platform_device *pdev; struct mv64xxx_i2c_pdata pdata; const unsigned int *prop; int err; memset(r, 0, sizeof(r)); err = of_address_to_resource(np, 0, &r[0]); if (err) return err; of_irq_to_resource(np, 0, &r[1]); memset(&pdata, 0, sizeof(pdata)); |
1791f91bc [POWERPC] prpmc28... |
330 |
pdata.freq_m = 8; /* default */ |
01f0e78e1 [POWERPC] Create ... |
331 |
prop = of_get_property(np, "freq_m", NULL); |
21dbfd291 [POWERPC] Use def... |
332 333 |
if (prop) pdata.freq_m = *prop; |
01f0e78e1 [POWERPC] Create ... |
334 |
|
ae39573a1 powerpc/mv64x60: ... |
335 |
pdata.freq_n = 3; /* default */ |
01f0e78e1 [POWERPC] Create ... |
336 |
prop = of_get_property(np, "freq_n", NULL); |
21dbfd291 [POWERPC] Use def... |
337 338 |
if (prop) pdata.freq_n = *prop; |
01f0e78e1 [POWERPC] Create ... |
339 |
|
1791f91bc [POWERPC] prpmc28... |
340 |
pdata.timeout = 1000; /* default: 1 second */ |
01f0e78e1 [POWERPC] Create ... |
341 |
|
01f0e78e1 [POWERPC] Create ... |
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id); if (!pdev) return -ENOMEM; err = platform_device_add_resources(pdev, r, 2); if (err) goto error; err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (err) goto error; err = platform_device_add(pdev); if (err) goto error; return 0; error: platform_device_put(pdev); return err; } |
7e07a1591 [WATCHDOG] mv64x6... |
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
/* * Create mv64x60_wdt platform devices */ static int __init mv64x60_wdt_device_setup(struct device_node *np, int id) { struct resource r; struct platform_device *pdev; struct mv64x60_wdt_pdata pdata; const unsigned int *prop; int err; err = of_address_to_resource(np, 0, &r); if (err) return err; memset(&pdata, 0, sizeof(pdata)); |
1791f91bc [POWERPC] prpmc28... |
380 |
pdata.timeout = 10; /* Default: 10 seconds */ |
7e07a1591 [WATCHDOG] mv64x6... |
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
np = of_get_parent(np); if (!np) return -ENODEV; prop = of_get_property(np, "clock-frequency", NULL); of_node_put(np); if (!prop) return -ENODEV; pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */ pdev = platform_device_alloc(MV64x60_WDT_NAME, id); if (!pdev) return -ENOMEM; err = platform_device_add_resources(pdev, &r, 1); if (err) goto error; err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (err) goto error; err = platform_device_add(pdev); if (err) goto error; return 0; error: platform_device_put(pdev); return err; } |
52d3aff90 [POWERPC] Create ... |
414 415 |
static int __init mv64x60_device_setup(void) { |
a0916bd64 [POWERPC] mv643xx... |
416 417 418 |
struct device_node *np, *np2; struct platform_device *pdev; int id, id2; |
52d3aff90 [POWERPC] Create ... |
419 |
int err; |
26cb7d8bb [POWERPC] Use for... |
420 |
id = 0; |
ff114b669 [POWERPC] Initial... |
421 422 423 424 425 426 427 428 |
for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc") { err = mv64x60_mpsc_device_setup(np, id++); if (err) printk(KERN_ERR "Failed to initialize MV64x60 " "serial device %s: error %d. ", np->full_name, err); } |
52d3aff90 [POWERPC] Create ... |
429 |
|
26cb7d8bb [POWERPC] Use for... |
430 |
id = 0; |
a0916bd64 [POWERPC] mv643xx... |
431 432 433 434 435 |
id2 = 0; for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") { pdev = mv64x60_eth_register_shared_pdev(np, id++); if (IS_ERR(pdev)) { err = PTR_ERR(pdev); |
ff114b669 [POWERPC] Initial... |
436 437 438 439 440 |
printk(KERN_ERR "Failed to initialize MV64x60 " "network block %s: error %d. ", np->full_name, err); continue; |
a0916bd64 [POWERPC] mv643xx... |
441 442 443 444 445 446 |
} for_each_child_of_node(np, np2) { if (!of_device_is_compatible(np2, "marvell,mv64360-eth")) continue; err = mv64x60_eth_device_setup(np2, id2++, pdev); |
ff114b669 [POWERPC] Initial... |
447 448 449 450 451 452 |
if (err) printk(KERN_ERR "Failed to initialize " "MV64x60 network device %s: " "error %d. ", np2->full_name, err); |
a0916bd64 [POWERPC] mv643xx... |
453 454 |
} } |
649c8e028 [POWERPC] Create ... |
455 |
|
26cb7d8bb [POWERPC] Use for... |
456 |
id = 0; |
ff114b669 [POWERPC] Initial... |
457 458 459 460 461 462 463 464 |
for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c") { err = mv64x60_i2c_device_setup(np, id++); if (err) printk(KERN_ERR "Failed to initialize MV64x60 I2C " "bus %s: error %d. ", np->full_name, err); } |
01f0e78e1 [POWERPC] Create ... |
465 |
|
7e07a1591 [WATCHDOG] mv64x6... |
466 |
/* support up to one watchdog timer */ |
a1810b44c [POWERPC] mv64x60... |
467 |
np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt"); |
7e07a1591 [WATCHDOG] mv64x6... |
468 469 |
if (np) { if ((err = mv64x60_wdt_device_setup(np, id))) |
ff114b669 [POWERPC] Initial... |
470 471 472 473 |
printk(KERN_ERR "Failed to initialize MV64x60 " "Watchdog %s: error %d. ", np->full_name, err); |
7e07a1591 [WATCHDOG] mv64x6... |
474 475 |
of_node_put(np); } |
683307da0 [POWERPC] Create ... |
476 477 478 |
/* Now add every node that is on the device bus */ for_each_compatible_node(np, NULL, "marvell,mv64360") of_platform_bus_probe(np, of_mv64x60_devices, NULL); |
52d3aff90 [POWERPC] Create ... |
479 |
return 0; |
52d3aff90 [POWERPC] Create ... |
480 481 |
} arch_initcall(mv64x60_device_setup); |
542c98c06 [POWERPC] Call ad... |
482 483 484 485 486 487 488 489 490 491 492 493 494 |
static int __init mv64x60_add_mpsc_console(void) { struct device_node *np = NULL; const char *prop; prop = of_get_property(of_chosen, "linux,stdout-path", NULL); if (prop == NULL) goto not_mpsc; np = of_find_node_by_path(prop); if (!np) goto not_mpsc; |
a1810b44c [POWERPC] mv64x60... |
495 |
if (!of_device_is_compatible(np, "marvell,mv64360-mpsc")) |
542c98c06 [POWERPC] Call ad... |
496 |
goto not_mpsc; |
1791f91bc [POWERPC] prpmc28... |
497 |
prop = of_get_property(np, "cell-index", NULL); |
542c98c06 [POWERPC] Call ad... |
498 499 500 501 502 503 504 505 506 |
if (!prop) goto not_mpsc; add_preferred_console("ttyMM", *(int *)prop, NULL); not_mpsc: return 0; } console_initcall(mv64x60_add_mpsc_console); |