diff options
author | Tony Lindgren <tony@atomide.com> | 2012-02-20 12:43:29 -0500 |
---|---|---|
committer | Tony Lindgren <tony@atomide.com> | 2012-02-20 13:00:39 -0500 |
commit | 3b972bf06c22f5abfa6586a8baf50321cd825965 (patch) | |
tree | 666fd47675069dae78337f648670a550c4f9f85b /arch/arm/mach-omap2/hsmmc.c | |
parent | 993e4fbd7822cdf874fcf9f1b054a323d67ccf97 (diff) |
ARM: OMAP2+: Split omap2_hsmmc_init() to properly support I2C GPIO pins
Otherwise omap_device_build() and omap_mux related functions
can't be marked as __init when twl is build as a module.
If a board is using GPIO pins or regulators configured by an
external chip, such as TWL PMIC on I2C bus, the board must
mark those MMC controllers as deferred. Additionally both
omap_hsmmc_init() and omap_hsmmc_late_init() must be called
by the board.
For MMC controllers using internal GPIO pins for card
detect and regulators the slots don't need to be marked
deferred. In this case calling omap_hsmmc_init() is sufficient.
Only mark the MMC slots using gpio_cd or gpio_wd as deferred
as noted by Igor Grinberg <grinberg@compulab.co.il>.
Note that this patch does not change the behaviour for
board-4430sdp.c board-omap4panda.c. These boards wrongly
rely on the omap_hsmmc.c init function callback to configure
the PMIC GPIO interrupt lines on external chip. If the PMIC
interrupt lines are not configured during init, they will
fail.
Reported-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Rajendra Nayak <rnayak@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'arch/arm/mach-omap2/hsmmc.c')
-rw-r--r-- | arch/arm/mach-omap2/hsmmc.c | 119 |
1 files changed, 92 insertions, 27 deletions
diff --git a/arch/arm/mach-omap2/hsmmc.c b/arch/arm/mach-omap2/hsmmc.c index 19dd1657245c..efb2fcbf9b3f 100644 --- a/arch/arm/mach-omap2/hsmmc.c +++ b/arch/arm/mach-omap2/hsmmc.c | |||
@@ -429,66 +429,131 @@ static int omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c, | |||
429 | } | 429 | } |
430 | 430 | ||
431 | static int omap_hsmmc_done; | 431 | static int omap_hsmmc_done; |
432 | |||
433 | void omap_hsmmc_late_init(struct omap2_hsmmc_info *c) | ||
434 | { | ||
435 | struct platform_device *pdev; | ||
436 | struct omap_mmc_platform_data *mmc_pdata; | ||
437 | int res; | ||
438 | |||
439 | if (omap_hsmmc_done != 1) | ||
440 | return; | ||
441 | |||
442 | omap_hsmmc_done++; | ||
443 | |||
444 | for (; c->mmc; c++) { | ||
445 | if (!c->deferred) | ||
446 | continue; | ||
447 | |||
448 | pdev = c->pdev; | ||
449 | if (!pdev) | ||
450 | continue; | ||
451 | |||
452 | mmc_pdata = pdev->dev.platform_data; | ||
453 | if (!mmc_pdata) | ||
454 | continue; | ||
455 | |||
456 | mmc_pdata->slots[0].switch_pin = c->gpio_cd; | ||
457 | mmc_pdata->slots[0].gpio_wp = c->gpio_wp; | ||
458 | |||
459 | res = omap_device_register(pdev); | ||
460 | if (res) | ||
461 | pr_err("Could not late init MMC %s\n", | ||
462 | c->name); | ||
463 | } | ||
464 | } | ||
465 | |||
432 | #define MAX_OMAP_MMC_HWMOD_NAME_LEN 16 | 466 | #define MAX_OMAP_MMC_HWMOD_NAME_LEN 16 |
433 | 467 | ||
434 | void omap_init_hsmmc(struct omap2_hsmmc_info *hsmmcinfo, int ctrl_nr) | 468 | static void omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo, |
469 | int ctrl_nr) | ||
435 | { | 470 | { |
436 | struct omap_hwmod *oh; | 471 | struct omap_hwmod *oh; |
472 | struct omap_hwmod *ohs[1]; | ||
473 | struct omap_device *od; | ||
437 | struct platform_device *pdev; | 474 | struct platform_device *pdev; |
438 | char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN]; | 475 | char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN]; |
439 | struct omap_mmc_platform_data *mmc_data; | 476 | struct omap_mmc_platform_data *mmc_data; |
440 | struct omap_mmc_dev_attr *mmc_dev_attr; | 477 | struct omap_mmc_dev_attr *mmc_dev_attr; |
441 | char *name; | 478 | char *name; |
442 | int l; | 479 | int res; |
443 | 480 | ||
444 | mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL); | 481 | mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL); |
445 | if (!mmc_data) { | 482 | if (!mmc_data) { |
446 | pr_err("Cannot allocate memory for mmc device!\n"); | 483 | pr_err("Cannot allocate memory for mmc device!\n"); |
447 | goto done; | 484 | return; |
448 | } | 485 | } |
449 | 486 | ||
450 | if (omap_hsmmc_pdata_init(hsmmcinfo, mmc_data) < 0) { | 487 | res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data); |
451 | pr_err("%s fails!\n", __func__); | 488 | if (res < 0) |
452 | goto done; | 489 | goto free_mmc; |
453 | } | 490 | |
454 | omap_hsmmc_mux(mmc_data, (ctrl_nr - 1)); | 491 | omap_hsmmc_mux(mmc_data, (ctrl_nr - 1)); |
455 | 492 | ||
456 | name = "omap_hsmmc"; | 493 | name = "omap_hsmmc"; |
457 | 494 | res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN, | |
458 | l = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN, | ||
459 | "mmc%d", ctrl_nr); | 495 | "mmc%d", ctrl_nr); |
460 | WARN(l >= MAX_OMAP_MMC_HWMOD_NAME_LEN, | 496 | WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN, |
461 | "String buffer overflow in MMC%d device setup\n", ctrl_nr); | 497 | "String buffer overflow in MMC%d device setup\n", ctrl_nr); |
498 | |||
462 | oh = omap_hwmod_lookup(oh_name); | 499 | oh = omap_hwmod_lookup(oh_name); |
463 | if (!oh) { | 500 | if (!oh) { |
464 | pr_err("Could not look up %s\n", oh_name); | 501 | pr_err("Could not look up %s\n", oh_name); |
465 | kfree(mmc_data->slots[0].name); | 502 | goto free_name; |
466 | goto done; | ||
467 | } | 503 | } |
468 | 504 | ohs[0] = oh; | |
469 | if (oh->dev_attr != NULL) { | 505 | if (oh->dev_attr != NULL) { |
470 | mmc_dev_attr = oh->dev_attr; | 506 | mmc_dev_attr = oh->dev_attr; |
471 | mmc_data->controller_flags = mmc_dev_attr->flags; | 507 | mmc_data->controller_flags = mmc_dev_attr->flags; |
472 | } | 508 | } |
473 | 509 | ||
474 | pdev = omap_device_build(name, ctrl_nr - 1, oh, mmc_data, | 510 | pdev = platform_device_alloc(name, ctrl_nr - 1); |
475 | sizeof(struct omap_mmc_platform_data), NULL, 0, false); | 511 | if (!pdev) { |
476 | if (IS_ERR(pdev)) { | 512 | pr_err("Could not allocate pdev for %s\n", name); |
477 | WARN(1, "Can't build omap_device for %s:%s.\n", name, oh->name); | 513 | goto free_name; |
478 | kfree(mmc_data->slots[0].name); | ||
479 | goto done; | ||
480 | } | 514 | } |
481 | /* | 515 | dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id); |
482 | * return device handle to board setup code | 516 | |
483 | * required to populate for regulator framework structure | 517 | od = omap_device_alloc(pdev, ohs, 1, NULL, 0); |
484 | */ | 518 | if (!od) { |
485 | hsmmcinfo->dev = &pdev->dev; | 519 | pr_err("Could not allocate od for %s\n", name); |
520 | goto put_pdev; | ||
521 | } | ||
522 | |||
523 | res = platform_device_add_data(pdev, mmc_data, | ||
524 | sizeof(struct omap_mmc_platform_data)); | ||
525 | if (res) { | ||
526 | pr_err("Could not add pdata for %s\n", name); | ||
527 | goto put_pdev; | ||
528 | } | ||
529 | |||
530 | hsmmcinfo->pdev = pdev; | ||
531 | |||
532 | if (hsmmcinfo->deferred) | ||
533 | goto free_mmc; | ||
534 | |||
535 | res = omap_device_register(pdev); | ||
536 | if (res) { | ||
537 | pr_err("Could not register od for %s\n", name); | ||
538 | goto free_od; | ||
539 | } | ||
540 | |||
541 | goto free_mmc; | ||
542 | |||
543 | free_od: | ||
544 | omap_device_delete(od); | ||
545 | |||
546 | put_pdev: | ||
547 | platform_device_put(pdev); | ||
548 | |||
549 | free_name: | ||
550 | kfree(mmc_data->slots[0].name); | ||
486 | 551 | ||
487 | done: | 552 | free_mmc: |
488 | kfree(mmc_data); | 553 | kfree(mmc_data); |
489 | } | 554 | } |
490 | 555 | ||
491 | void omap2_hsmmc_init(struct omap2_hsmmc_info *controllers) | 556 | void omap_hsmmc_init(struct omap2_hsmmc_info *controllers) |
492 | { | 557 | { |
493 | u32 reg; | 558 | u32 reg; |
494 | 559 | ||
@@ -521,7 +586,7 @@ void omap2_hsmmc_init(struct omap2_hsmmc_info *controllers) | |||
521 | } | 586 | } |
522 | 587 | ||
523 | for (; controllers->mmc; controllers++) | 588 | for (; controllers->mmc; controllers++) |
524 | omap_init_hsmmc(controllers, controllers->mmc); | 589 | omap_hsmmc_init_one(controllers, controllers->mmc); |
525 | 590 | ||
526 | } | 591 | } |
527 | 592 | ||