From patchwork Mon May 13 13:47:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 16882 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CBDF225E14 for ; Mon, 13 May 2013 13:48:55 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id hi5sf1486663wib.10 for ; Mon, 13 May 2013 06:48:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-beenthere:x-received:received-spf:x-received :x-forwarded-to:x-forwarded-for:delivered-to:x-received:received-spf :from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=VGK3FQdSYECUGaZePf2i20umXYqlwpEknQb/z/mqQMc=; b=g32vB+6/9aToTdZcXJdDWFsVTq1lI8moAWw5eggV5xbyqKp3hwOXnRX5U0d3e1lV5u kpWa/koswnpdPNO2wW4/K1l+8mOGJt/qUNWPh1bX8OGY0DdCgzJLhL3S14z00D0FeErb +fWcP110lDHd865R81IYrifIqa1n+3j4SfcxLE/oYiyDAhtCBFkQ9sCVy+vWNXbGmxvA m/hwb/+bf9fxn+I7EQKOV+hWjm72wWbfQFvYk7/FvcWFz+5UMVK9uwiJBAfWvsUPh+dC EI+DmPsKHETxQf48SIB8wwPXU3eIZwXNtdhzOiqSD8dCuNFtLcJYcbHONKs3LB7smr0k cKLA== X-Received: by 10.180.210.161 with SMTP id mv1mr1813497wic.1.1368452902466; Mon, 13 May 2013 06:48:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.180.211.201 with SMTP id ne9ls783102wic.51.gmail; Mon, 13 May 2013 06:48:22 -0700 (PDT) X-Received: by 10.194.90.202 with SMTP id by10mr40573676wjb.11.1368452902331; Mon, 13 May 2013 06:48:22 -0700 (PDT) Received: from mail-ve0-x233.google.com (mail-ve0-x233.google.com [2607:f8b0:400c:c01::233]) by mx.google.com with ESMTPS id b7si3774088wjf.126.2013.05.13.06.48.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 May 2013 06:48:22 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::233 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::233; Received: by mail-ve0-f179.google.com with SMTP id oz11so5823745veb.10 for ; Mon, 13 May 2013 06:48:21 -0700 (PDT) X-Received: by 10.52.36.115 with SMTP id p19mr1533933vdj.8.1368452901138; Mon, 13 May 2013 06:48:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.217.15 with SMTP id hk15csp19576vcb; Mon, 13 May 2013 06:48:20 -0700 (PDT) X-Received: by 10.15.95.74 with SMTP id bc50mr78546806eeb.36.1368452898082; Mon, 13 May 2013 06:48:18 -0700 (PDT) Received: from eu1sys200aog114.obsmtp.com (eu1sys200aog114.obsmtp.com [207.126.144.137]) by mx.google.com with SMTP id k4si22835802eey.198.2013.05.13.06.47.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 13 May 2013 06:48:18 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.137 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.137; Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob114.postini.com ([207.126.147.11]) with SMTP ID DSNKUZDu/YdeptH5Es0+qBbvuYeE3HKt5jUW@postini.com; Mon, 13 May 2013 13:48:17 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id B0D91C9; Mon, 13 May 2013 13:47:38 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 2387A3FD; Mon, 13 May 2013 13:47:38 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id C28D7A8072; Mon, 13 May 2013 15:47:31 +0200 (CEST) Received: from steludxu1397.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.279.5; Mon, 13 May 2013 15:47:37 +0200 From: Ulf Hansson To: , Russell King Cc: , Chris Ball , Daniel Lezcano , Linus Walleij , Rickard Andersson , Ulf Hansson Subject: [PATCH 3/3] mmc: mmci: Save and restore register context Date: Mon, 13 May 2013 15:47:17 +0200 Message-ID: <1368452837-31458-4-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1368452837-31458-1-git-send-email-ulf.hansson@stericsson.com> References: <1368452837-31458-1-git-send-email-ulf.hansson@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlHaA83lSMlDLhn5sIIB/hM79o7gKd8fTItksM/sVM8npZfMIMSZ3j9vRmkjsMvwTXFUhiz X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::233 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Ulf Hansson If a corresponding power domain exists for the device and it manages to cut the domain regulator while the device is runtime suspended, the IP loses it's registers context. We restore the context in the .runtime_resume callback from the existing register caches to adapt to this siutuation. We also want to make sure the registers are in a known state while restoring context in the case when the power domain did not drop the power, since there are restrictions for the order of writing to these registers. To handle this, we clear the registers in the .runtime_suspend callback. Signed-off-by: Ulf Hansson --- drivers/mmc/host/mmci.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 7815816..790d744 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -61,6 +61,7 @@ static unsigned int fmax = 515633; * @pwrreg_powerup: power up value for MMCIPOWER register * @signal_direction: input/out direction of bus signals can be indicated * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock + * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply */ struct variant_data { unsigned int clkreg; @@ -74,6 +75,7 @@ struct variant_data { u32 pwrreg_powerup; bool signal_direction; bool pwrreg_clkgate; + bool pwrreg_nopower; }; static struct variant_data variant_arm = { @@ -107,6 +109,7 @@ static struct variant_data variant_u300 = { .pwrreg_powerup = MCI_PWR_ON, .signal_direction = true, .pwrreg_clkgate = true, + .pwrreg_nopower = true, }; static struct variant_data variant_nomadik = { @@ -119,6 +122,7 @@ static struct variant_data variant_nomadik = { .pwrreg_powerup = MCI_PWR_ON, .signal_direction = true, .pwrreg_clkgate = true, + .pwrreg_nopower = true, }; static struct variant_data variant_ux500 = { @@ -132,6 +136,7 @@ static struct variant_data variant_ux500 = { .pwrreg_powerup = MCI_PWR_ON, .signal_direction = true, .pwrreg_clkgate = true, + .pwrreg_nopower = true, }; static struct variant_data variant_ux500v2 = { @@ -146,6 +151,7 @@ static struct variant_data variant_ux500v2 = { .pwrreg_powerup = MCI_PWR_ON, .signal_direction = true, .pwrreg_clkgate = true, + .pwrreg_nopower = true, }; /* @@ -1695,6 +1701,39 @@ static int mmci_resume(struct device *dev) #endif #ifdef CONFIG_PM_RUNTIME +static void mmci_save(struct mmci_host *host) +{ + unsigned long flags; + + if (host->variant->pwrreg_nopower) { + spin_lock_irqsave(&host->lock, flags); + + writel(0, host->base + MMCIMASK0); + writel(0, host->base + MMCIPOWER); + writel(0, host->base + MMCICLOCK); + mmci_reg_delay(host); + + spin_unlock_irqrestore(&host->lock, flags); + } + +} + +static void mmci_restore(struct mmci_host *host) +{ + unsigned long flags; + + if (host->variant->pwrreg_nopower) { + spin_lock_irqsave(&host->lock, flags); + + writel(host->clk_reg, host->base + MMCICLOCK); + writel(host->pwr_reg, host->base + MMCIPOWER); + writel(MCI_IRQENABLE, host->base + MMCIMASK0); + mmci_reg_delay(host); + + spin_unlock_irqrestore(&host->lock, flags); + } +} + static int mmci_runtime_suspend(struct device *dev) { struct amba_device *adev = to_amba_device(dev); @@ -1707,6 +1746,7 @@ static int mmci_runtime_suspend(struct device *dev) if (!IS_ERR(host->pins_sleep)) pinctrl_select_state(host->pinctrl, host->pins_sleep); + mmci_save(host); clk_disable_unprepare(host->clk); } @@ -1722,6 +1762,7 @@ static int mmci_runtime_resume(struct device *dev) struct mmci_host *host = mmc_priv(mmc); clk_prepare_enable(host->clk); + mmci_restore(host); /* Optionally enable pins to be muxed in and configured */ if (!IS_ERR(host->pins_default))