>From c3bb01f8806c5aec26967ae17ada27bc3d79ff86 Mon Sep 17 00:00:00 2001
From: Chuanxiao Dong <[email protected]>
Date: Sat, 13 Nov 2010 19:03:54 +0800
Subject: [PATCH 3/3] mmc: add acquire_ownership and release_ownership in core 
layer

Since SCU will use host controller and may change the status of
host controller and card, after IA get the ownership, IA need to
reinit sdhci host controller and card.
Hos controller reinit work was been done in acquire_ownership
callback.
Added a reinit callback in mmc_bus_ops to implement the eMMC
card reinit work.

Signed-off-by: Yunpeng Gao <[email protected]>
Signed-off-by: Chuanxiao Dong <[email protected]>
---
 drivers/mmc/core/core.c |   22 +++++++++++++++++++++-
 drivers/mmc/core/core.h |    1 +
 drivers/mmc/core/mmc.c  |   18 ++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index d464252..ff05314 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -475,7 +475,7 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 {
        DECLARE_WAITQUEUE(wait, current);
        unsigned long flags;
-       int stop;
+       int stop, ret;
 
        might_sleep();
 
@@ -499,6 +499,23 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t 
*abort)
                wake_up(&host->wq);
        spin_unlock_irqrestore(&host->lock, flags);
        remove_wait_queue(&host->wq, &wait);
+
+       if (host->ops->acquire_ownership) {
+               ret = host->ops->acquire_ownership(host);
+               if (ret == -EBUSY) {
+                       pr_warn("SCU did release host in negotiated"
+                                       " time, ignore this and keep on using"
+                                       " host controller\n");
+               } else if (ret == 1 && host->bus_ops &&
+                               host->bus_ops->reinit) {
+                       /* struggled the host controller from SCU,
+                        * IA need to re-init eMMC card as SCU FW does
+                        * */
+                       if (host->card)
+                               host->bus_ops->reinit(host);
+               }
+       }
+
        if (!stop)
                mmc_host_enable(host);
        return stop;
@@ -602,6 +619,9 @@ void mmc_release_host(struct mmc_host *host)
        mmc_host_lazy_disable(host);
 
        mmc_do_release_host(host);
+
+       if (host->ops->release_ownership)
+               host->ops->release_ownership(host);
 }
 
 EXPORT_SYMBOL(mmc_release_host);
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 77240cd..232a3d9 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -24,6 +24,7 @@ struct mmc_bus_ops {
        int (*resume)(struct mmc_host *);
        int (*power_save)(struct mmc_host *);
        int (*power_restore)(struct mmc_host *);
+       int (*reinit)(struct mmc_host *);
 };
 
 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 91c35fd..7e337ac 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -727,6 +727,23 @@ static int mmc_awake(struct mmc_host *host)
        return err;
 }
 
+static int mmc_reinit_card(struct mmc_host *host)
+{
+       int err;
+
+       BUG_ON(!host);
+       BUG_ON(!host->card);
+
+       host->ios.clock = host->f_init;
+       mmc_set_clock(host, host->ios.clock);
+
+       err = mmc_init_card(host, host->ocr, host->card);
+       if (err)
+               printk(KERN_ERR "%s: err %d\n", __func__, err);
+
+       return err;
+}
+
 static const struct mmc_bus_ops mmc_ops = {
        .awake = mmc_awake,
        .sleep = mmc_sleep,
@@ -735,6 +752,7 @@ static const struct mmc_bus_ops mmc_ops = {
        .suspend = NULL,
        .resume = NULL,
        .power_restore = mmc_power_restore,
+       .reinit = mmc_reinit_card,
 };
 
 static const struct mmc_bus_ops mmc_ops_unsafe = {
-- 
1.6.6.1

_______________________________________________
MeeGo-kernel mailing list
[email protected]
http://lists.meego.com/listinfo/meego-kernel

Reply via email to