From patchwork Thu Apr 19 12:41:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Girish K S X-Patchwork-Id: 7946 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 78C8A23E13 for ; Thu, 19 Apr 2012 12:41:27 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 1EF87A18E59 for ; Thu, 19 Apr 2012 12:41:27 +0000 (UTC) Received: by iage36 with SMTP id e36so16243183iag.11 for ; Thu, 19 Apr 2012 05:41:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=Lle8+jDMHCj6SkUb2EPOFN3ljK1c+GA+pX3aj0m/wag=; b=Z+lu3+XjSzwIsbvXBWTsVYul+ZOxepDwfPHG2Qux0PfdvaRG+wOEagG7wYSrf6bHWY ejvLImRX2AVGUFlGsUP58c38918R+JPU+b59JJdSIUCpuf70N5BaQ2rSxYg8P/CCzSd9 r2lTWjeG6EzAkOX1uec/5b1Rbugp7VtVdY9hsiqLH4Cw0y9a3HHFD1sWV924FESsKl3C QM2LQvMQbZnmuoEuz2YU8L0QuFC7ltj0NwFT4K2uXai8mQNJg3kn98mrZ+G/8m6ryEGo lgawPnqIFaTGyC7ixF+CSlsQnG28XCuJykTgXL7NI/588aKQ2N3u5xJEjq2p7cxpPSSN hECw== Received: by 10.50.17.201 with SMTP id q9mr1917361igd.19.1334839286535; Thu, 19 Apr 2012 05:41:26 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp287092ibt; Thu, 19 Apr 2012 05:41:25 -0700 (PDT) Received: by 10.68.218.72 with SMTP id pe8mr4662555pbc.45.1334839284580; Thu, 19 Apr 2012 05:41:24 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id pz5si2547995pbb.246.2012.04.19.05.41.24 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Apr 2012 05:41:24 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of girish.shivananjappa@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of girish.shivananjappa@linaro.org) smtp.mail=girish.shivananjappa@linaro.org Received: by pbcxa12 with SMTP id xa12so12069114pbc.37 for ; Thu, 19 Apr 2012 05:41:24 -0700 (PDT) Received: by 10.68.226.8 with SMTP id ro8mr4606215pbc.72.1334839283998; Thu, 19 Apr 2012 05:41:23 -0700 (PDT) Received: from girishks ([115.113.119.130]) by mx.google.com with ESMTPS id sx2sm2169990pbc.26.2012.04.19.05.41.19 (version=SSLv3 cipher=OTHER); Thu, 19 Apr 2012 05:41:22 -0700 (PDT) From: Girish K S To: linux-mmc@vger.kernel.org Cc: patches@linaro.org, ulf.hansson@stericsson.com, saugata.das@linaro.org, girish.shivananjappa@linaro.org Subject: [PATCH] MMC-4.5 Power OFF Notify rework Date: Thu, 19 Apr 2012 18:11:29 +0530 Message-Id: <1334839289-22620-1-git-send-email-girish.shivananjappa@linaro.org> X-Mailer: git-send-email 1.7.1 X-Gm-Message-State: ALoCoQl+qF/8Ns1Js9rG5qwZnAunZbYKvALE62BBKI8Q/Dloht3SmkX2ET6rGroIG00B70njKkxi This is a rework of the existing POWER OFF NOTIFY patch. The current problem with the patch comes from the ambiguity on the usage of POWER OFF NOTIFY together with SLEEP and misunderstanding on the usage of MMC_POWER_OFF power_mode from mmc_set_ios in different host controller drivers. This new patch works around this problem by adding a new host CAP, MMC_CAP2_POWER_OFF_VCCQ_DURING_SUSPEND, which when set sends a POWER OFF NOTIFY from mmc_suspend instead of SLEEP. It is expected that host controller drivers will set this CAP, if they switch off both Vcc and Vccq from MMC_POWER_OFF condition within mmc_set_ios. However, note that there is no harm in sending MMC_POWER_NOTIFY even if Vccq is not switched off. This patch also sends POWER OFF NOTIFY from power management routines (e.g. mmc_power_save_host, mmc_pm_notify/PM_SUSPEND_PREPARE, mmc_stop_host), which does reinitialization of the eMMC on the return path of the power management routines (e.g. mmc_power_restore_host, mmc_pm_notify/PM_POST_RESTORE, mmc_start_host). This patch sets POWER_OFF_NOTIFICATION to POWER_OFF_SHORT if it is sent from the suspend sequence. If it is sent from shutdown sequence then it is set to POWER_OFF_LONG. Previuos implementation of PowerOff Notify as a core function is replaced as a device's bus operation. Signed-off-by: Saugata Das Signed-off-by: Girish K S --- drivers/mmc/core/core.c | 83 ++++++++++----------------------------------- drivers/mmc/core/core.h | 1 + drivers/mmc/core/mmc.c | 75 +++++++++++++++++++++++++++++++++++------- include/linux/mmc/host.h | 1 + 4 files changed, 84 insertions(+), 76 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index e541efb..4b8b2c1 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1100,48 +1100,6 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type) mmc_host_clk_release(host); } -static void mmc_poweroff_notify(struct mmc_host *host) -{ - struct mmc_card *card; - unsigned int timeout; - unsigned int notify_type = EXT_CSD_NO_POWER_NOTIFICATION; - int err = 0; - - card = host->card; - mmc_claim_host(host); - - /* - * Send power notify command only if card - * is mmc and notify state is powered ON - */ - if (card && mmc_card_mmc(card) && - (card->poweroff_notify_state == MMC_POWERED_ON)) { - - if (host->power_notify_type == MMC_HOST_PW_NOTIFY_SHORT) { - notify_type = EXT_CSD_POWER_OFF_SHORT; - timeout = card->ext_csd.generic_cmd6_time; - card->poweroff_notify_state = MMC_POWEROFF_SHORT; - } else { - notify_type = EXT_CSD_POWER_OFF_LONG; - timeout = card->ext_csd.power_off_longtime; - card->poweroff_notify_state = MMC_POWEROFF_LONG; - } - - err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, - EXT_CSD_POWER_OFF_NOTIFICATION, - notify_type, timeout); - - if (err && err != -EBADMSG) - pr_err("Device failed to respond within %d poweroff " - "time. Forcefully powering down the device\n", - timeout); - - /* Set the card state to no notification after the poweroff */ - card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION; - } - mmc_release_host(host); -} - /* * Apply power to the MMC stack. This is a two-stage process. * First, we enable power to the card without the clock running. @@ -1198,30 +1156,12 @@ static void mmc_power_up(struct mmc_host *host) void mmc_power_off(struct mmc_host *host) { - int err = 0; mmc_host_clk_hold(host); host->ios.clock = 0; host->ios.vdd = 0; /* - * For eMMC 4.5 device send AWAKE command before - * POWER_OFF_NOTIFY command, because in sleep state - * eMMC 4.5 devices respond to only RESET and AWAKE cmd - */ - if (host->card && mmc_card_is_sleep(host->card) && - host->bus_ops->resume) { - err = host->bus_ops->resume(host); - - if (!err) - mmc_poweroff_notify(host); - else - pr_warning("%s: error %d during resume " - "(continue with poweroff sequence)\n", - mmc_hostname(host), err); - } - - /* * Reset ocr mask to be the highest possible voltage supported for * this mmc host. This value will be used at next power up. */ @@ -2084,6 +2024,9 @@ void mmc_stop_host(struct mmc_host *host) mmc_bus_get(host); if (host->bus_ops && !host->bus_dead) { + if (host->bus_ops->poweroff_notify) + host->bus_ops->poweroff_notify(host); + /* Calling bus_ops->remove() with a claimed host can deadlock */ if (host->bus_ops->remove) host->bus_ops->remove(host); @@ -2093,6 +2036,7 @@ void mmc_stop_host(struct mmc_host *host) mmc_power_off(host); mmc_release_host(host); mmc_bus_put(host); + return; } mmc_bus_put(host); @@ -2119,7 +2063,9 @@ int mmc_power_save_host(struct mmc_host *host) if (host->bus_ops->power_save) ret = host->bus_ops->power_save(host); - + host->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT; + if (host->bus_ops->poweroff_notify) + host->bus_ops->poweroff_notify(host); mmc_bus_put(host); mmc_power_off(host); @@ -2142,7 +2088,7 @@ int mmc_power_restore_host(struct mmc_host *host) mmc_bus_put(host); return -EINVAL; } - + host->power_notify_type = MMC_HOST_PW_NOTIFY_LONG; mmc_power_up(host); ret = host->bus_ops->power_restore(host); @@ -2161,8 +2107,11 @@ int mmc_card_awake(struct mmc_host *host) mmc_bus_get(host); - if (host->bus_ops && !host->bus_dead && host->bus_ops->awake) + if (host->bus_ops && !host->bus_dead && host->bus_ops->awake) { err = host->bus_ops->awake(host); + if (!err) + mmc_card_clr_sleep(host->card); + } mmc_bus_put(host); @@ -2179,8 +2128,11 @@ int mmc_card_sleep(struct mmc_host *host) mmc_bus_get(host); - if (host->bus_ops && !host->bus_dead && host->bus_ops->sleep) + if (host->bus_ops && !host->bus_dead && host->bus_ops->sleep) { err = host->bus_ops->sleep(host); + if (!err) + mmc_card_set_sleep(host->card); + } mmc_bus_put(host); @@ -2394,6 +2346,8 @@ int mmc_pm_notify(struct notifier_block *notify_block, if (!host->bus_ops || host->bus_ops->suspend) break; + if (host->bus_ops->poweroff_notify) + host->bus_ops->poweroff_notify(host); /* Calling bus_ops->remove() with a claimed host can deadlock */ if (host->bus_ops->remove) @@ -2403,6 +2357,7 @@ int mmc_pm_notify(struct notifier_block *notify_block, mmc_detach_bus(host); mmc_power_off(host); mmc_release_host(host); + host->pm_flags = 0; break; diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 3bdafbc..351cbbe 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -25,6 +25,7 @@ struct mmc_bus_ops { int (*power_save)(struct mmc_host *); int (*power_restore)(struct mmc_host *); int (*alive)(struct mmc_host *); + int (*poweroff_notify)(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 54df5ad..62bdee6 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1282,6 +1282,50 @@ err: return err; } +static int mmc_poweroff_notify(struct mmc_host *host) +{ + struct mmc_card *card; + unsigned int timeout; + unsigned int notify_type = EXT_CSD_NO_POWER_NOTIFICATION; + int err = -EINVAL; + + card = host->card; + mmc_claim_host(host); + + /* + * Send power notify command only if card + * is mmc and notify state is powered ON + */ + if (card && mmc_card_mmc(card) && + (card->poweroff_notify_state == MMC_POWERED_ON)) { + + if (host->power_notify_type == MMC_HOST_PW_NOTIFY_SHORT) { + notify_type = EXT_CSD_POWER_OFF_SHORT; + timeout = card->ext_csd.generic_cmd6_time; + card->poweroff_notify_state = MMC_POWEROFF_SHORT; + } else { + notify_type = EXT_CSD_POWER_OFF_LONG; + timeout = card->ext_csd.power_off_longtime; + card->poweroff_notify_state = MMC_POWEROFF_LONG; + } + + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_POWER_OFF_NOTIFICATION, + notify_type, timeout); + + if (err && err != -EBADMSG) + pr_err("%s: Device failed to respond within %d " + "poweroff time. Forcefully powering down " + "the device\n", mmc_hostname(host), timeout); + + /* Set the card state to no notification after the poweroff */ + card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION; + } + mmc_release_host(host); + + return err; +} + /* * Host is being removed. Free up the current card. */ @@ -1341,15 +1385,20 @@ static int mmc_suspend(struct mmc_host *host) BUG_ON(!host); BUG_ON(!host->card); - mmc_claim_host(host); - if (mmc_card_can_sleep(host)) { - err = mmc_card_sleep(host); - if (!err) - mmc_card_set_sleep(host->card); - } else if (!mmc_host_is_spi(host)) - mmc_deselect_cards(host); - host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); - mmc_release_host(host); + if (host->caps2 & MMC_CAP2_POWER_OFF_VCCQ_DURING_SUSPEND) { + err = mmc_poweroff_notify(host); + } else { + mmc_claim_host(host); + if (mmc_card_can_sleep(host)) + err = mmc_card_sleep(host); + else if (!mmc_host_is_spi(host)) + mmc_deselect_cards(host); + mmc_release_host(host); + } + + if (!err) + host->card->state &= + ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); return err; } @@ -1368,11 +1417,11 @@ static int mmc_resume(struct mmc_host *host) BUG_ON(!host->card); mmc_claim_host(host); - if (mmc_card_is_sleep(host->card)) { + if (mmc_card_is_sleep(host->card)) err = mmc_card_awake(host); - mmc_card_clr_sleep(host->card); - } else + else err = mmc_init_card(host, host->ocr, host->card); + mmc_release_host(host); return err; @@ -1430,6 +1479,7 @@ static const struct mmc_bus_ops mmc_ops = { .resume = NULL, .power_restore = mmc_power_restore, .alive = mmc_alive, + .poweroff_notify = NULL, }; static const struct mmc_bus_ops mmc_ops_unsafe = { @@ -1441,6 +1491,7 @@ static const struct mmc_bus_ops mmc_ops_unsafe = { .resume = mmc_resume, .power_restore = mmc_power_restore, .alive = mmc_alive, + .poweroff_notify = mmc_poweroff_notify, }; static void mmc_attach_bus_ops(struct mmc_host *host) diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index cbde4b7..cf44a6f 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -238,6 +238,7 @@ struct mmc_host { #define MMC_CAP2_BROKEN_VOLTAGE (1 << 7) /* Use the broken voltage */ #define MMC_CAP2_DETECT_ON_ERR (1 << 8) /* On I/O err check card removal */ #define MMC_CAP2_HC_ERASE_SZ (1 << 9) /* High-capacity erase size */ +#define MMC_CAP2_POWER_OFF_VCCQ_DURING_SUSPEND (1 << 10) mmc_pm_flag_t pm_caps; /* supported pm features */ unsigned int power_notify_type;