Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756675AbcC2KCq (ORCPT ); Tue, 29 Mar 2016 06:02:46 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:47081 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932163AbcC2KCm (ORCPT ); Tue, 29 Mar 2016 06:02:42 -0400 X-AuditID: cbfee68d-f79e86d0000012da-b6-56fa52be0a06 Message-id: <56FA52BE.30401@samsung.com> Date: Tue, 29 Mar 2016 19:02:38 +0900 From: Jaehoon Chung User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-version: 1.0 To: Adrian Hunter , Krzysztof Kozlowski , Jisheng Zhang Cc: Ulf Hansson , ludovic.desroches@atmel.com, "Ivan T. Ivanov" , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: Re: [PATCH V3] mmc: sdhci: Fix regression setting power on Trats2 board References: <20160324155840.50474b98@xhacker> <56F3A0B7.4050509@samsung.com> <20160324162449.29c9cf78@xhacker> <56F3A88F.50603@samsung.com> <56F3E77D.7030201@intel.com> <56F3E9EB.3090207@intel.com> <56F8CA0C.2080908@samsung.com> <56FA4D66.3030109@intel.com> <56FA4EC7.8090004@intel.com> In-reply-to: <56FA4EC7.8090004@intel.com> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsWyRsSkQHdf0K8wgwOzNC1OPlnDZnF5/kx2 i3fHd7NYvH5haHF51xw2iyP/+xktZpzfx2RxaGayxfG14Q6cHgt+bWXxWLznJZPHnWt72Dwm L7zI7NG3ZRWjx+dNcgFsUVw2Kak5mWWpRfp2CVwZn5f3shUccKo4+3UbSwPjbbMuRk4OCQET iZnnVrNA2GISF+6tZ+ti5OIQEljBKNG/6iE7TNGPV0eZIBJLGS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I IBGBZkaJhj/zWEEcZoELjBKvL5wBmyosECCx+9FDqHXvmSSuXvkINopTQFOi/f9moHUcQB16 EvcvaoGEmQXkJTavecs8gVFgFpIlsxCqZiGpWsDIvIpRIrUguaA4KT3XKC+1XK84Mbe4NC9d Lzk/dxMjOO6fSe9gPLzL/RCjAAejEg8vw4KfYUKsiWXFlbmHGCU4mJVEeHUCf4UJ8aYkVlal FuXHF5XmpBYfYjQFhsJEZinR5HxgSsoriTc0NjEzsjQyN7QwMjZXEud9/H9dmJBAemJJanZq akFqEUwfEwenVANj5jXWC2v8Klb9v3Xj7t2bRdklMkU+nPc4T+tfPvW7LeHhfZb0oyvLZ+77 fFCFiTEx6onx5J91y9afmH3U5Lu/8dNFofX7Wcyt1NmWhxgv+/4pRvx5dcKXyduvrIvmFfE3 k9czkm1eFvXgxdnOSVPuRZebR6Y6d2oFPFm0QPiwkV7A46BLzmcslFiKMxINtZiLihMBpPdR SxEDAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8292 Lines: 218 On 03/29/2016 06:45 PM, Adrian Hunter wrote: > Several commits relating to setting power have been introducing > problems by putting driver-specific rules into generic SDHCI code. > > Krzysztof Kozlowski reported that after commit 918f4cbd4340 ("mmc: > sdhci: restore behavior when setting VDD via external regulator") > on Trats2 board there are warnings for invalid VDD value (2.8V): > > [ 3.119656] ------------[ cut here ]------------ > [ 3.119666] WARNING: CPU: 3 PID: 90 at > ../drivers/mmc/host/sdhci.c:1234 sdhci_do_set_ios+0x4cc/0x5e0 > [ 3.119669] mmc0: Invalid vdd 0x10 > [ 3.119673] Modules linked in: > [ 3.119679] CPU: 3 PID: 90 Comm: kworker/3:1 Tainted: G W > 4.5.0-next-20160324 #23 > [ 3.119681] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) > [ 3.119690] Workqueue: events_freezable mmc_rescan > [ 3.119708] [] (unwind_backtrace) from [] > (show_stack+0x10/0x14) > [ 3.119719] [] (show_stack) from [] > (dump_stack+0x88/0x9c) > [ 3.119728] [] (dump_stack) from [] (__warn+0xe8/0x100) > [ 3.119734] [] (__warn) from [] > (warn_slowpath_fmt+0x38/0x48) > [ 3.119740] [] (warn_slowpath_fmt) from [] > (sdhci_do_set_ios+0x4cc/0x5e0) > [ 3.119748] [] (sdhci_do_set_ios) from [] > (sdhci_runtime_resume_host+0x60/0x114) > [ 3.119758] [] (sdhci_runtime_resume_host) from > [] (__rpm_callback+0x2c/0x60) > [ 3.119767] [] (__rpm_callback) from [] > (rpm_callback+0x20/0x80) > [ 3.119773] [] (rpm_callback) from [] > (rpm_resume+0x36c/0x558) > [ 3.119780] [] (rpm_resume) from [] > (__pm_runtime_resume+0x4c/0x64) > [ 3.119788] [] (__pm_runtime_resume) from [] > (__mmc_claim_host+0x170/0x1b0) > [ 3.119795] [] (__mmc_claim_host) from [] > (mmc_rescan+0x54/0x348) > [ 3.119807] [] (mmc_rescan) from [] > (process_one_work+0x120/0x3f4) > [ 3.119815] [] (process_one_work) from [] > (worker_thread+0x38/0x554) > [ 3.119823] [] (worker_thread) from [] > (kthread+0xdc/0xf4) > [ 3.119831] [] (kthread) from [] > (ret_from_fork+0x14/0x3c) > [ 3.119834] ---[ end trace a22d652aa3276886 ]--- > > Fix by adding a 'set_power' callback and restoring the default > behaviour prior to commit 918f4cbd4340 ("mmc: sdhci: restore > behavior when setting VDD via external regulator"). The desired > behaviour of that commit is gotten by having sdhci-pxav3 provide > its own set_power callback. > > Reported-by: Krzysztof Kozlowski > Link: http://lkml.kernel.org/r/CAJKOXPcGDnPm-Ykh6wHqV1YxfTaov5E8iVqBoBn4OJc7BnhgEQ@mail.gmail.com > Fixes: 918f4cbd4340 ("mmc: sdhci: restore behavior when setting VDD...) > Tested-by: Krzysztof Kozlowski > Tested-by: Ludovic Desroches > Signed-off-by: Adrian Hunter > Cc: stable@vger.kernel.org # v4.5+ > --- > Tested-by: Jaehoon Chung With trats2 board. > > Changes in V3: > > Expanded commit message. > > Removed redundant vdd = 0 from sdhci_set_power() > > Make pxav3_set_power() check the regulator was created successfully > before using it, and ensure vdd is 0 when pwr is 0. > > > drivers/mmc/host/sdhci-pxav3.c | 22 ++++++++++++++++++++++ > drivers/mmc/host/sdhci.c | 39 ++++++++++++++++++++++++++++++--------- > drivers/mmc/host/sdhci.h | 4 ++++ > 3 files changed, 56 insertions(+), 9 deletions(-) > > diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c > index f5edf9d3a18a..0535827b02ee 100644 > --- a/drivers/mmc/host/sdhci-pxav3.c > +++ b/drivers/mmc/host/sdhci-pxav3.c > @@ -307,8 +307,30 @@ static void pxav3_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs) > __func__, uhs, ctrl_2); > } > > +static void pxav3_set_power(struct sdhci_host *host, unsigned char mode, > + unsigned short vdd) > +{ > + struct mmc_host *mmc = host->mmc; > + u8 pwr = host->pwr; > + > + sdhci_set_power(host, mode, vdd); > + > + if (host->pwr == pwr) > + return; > + > + if (host->pwr == 0) > + vdd = 0; > + > + if (!IS_ERR(mmc->supply.vmmc)) { > + spin_unlock_irq(&host->lock); > + mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); > + spin_lock_irq(&host->lock); > + } > +} > + > static const struct sdhci_ops pxav3_sdhci_ops = { > .set_clock = sdhci_set_clock, > + .set_power = pxav3_set_power, > .platform_send_init_74_clocks = pxav3_gen_init_74_clocks, > .get_max_clock = sdhci_pltfm_clk_get_max_clock, > .set_bus_width = sdhci_set_bus_width, > diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c > index add9fdfd1d8f..f5b52b4308cc 100644 > --- a/drivers/mmc/host/sdhci.c > +++ b/drivers/mmc/host/sdhci.c > @@ -1269,10 +1269,24 @@ clock_set: > } > EXPORT_SYMBOL_GPL(sdhci_set_clock); > > -static void sdhci_set_power(struct sdhci_host *host, unsigned char mode, > - unsigned short vdd) > +static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode, > + unsigned short vdd) > { > struct mmc_host *mmc = host->mmc; > + > + spin_unlock_irq(&host->lock); > + mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); > + spin_lock_irq(&host->lock); > + > + if (mode != MMC_POWER_OFF) > + sdhci_writeb(host, SDHCI_POWER_ON, SDHCI_POWER_CONTROL); > + else > + sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); > +} > + > +void sdhci_set_power(struct sdhci_host *host, unsigned char mode, > + unsigned short vdd) > +{ > u8 pwr = 0; > > if (mode != MMC_POWER_OFF) { > @@ -1304,7 +1318,6 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned char mode, > sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); > if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) > sdhci_runtime_pm_bus_off(host); > - vdd = 0; > } else { > /* > * Spec says that we should clear the power reg before setting > @@ -1335,12 +1348,20 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned char mode, > if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER) > mdelay(10); > } > +} > +EXPORT_SYMBOL_GPL(sdhci_set_power); > > - if (!IS_ERR(mmc->supply.vmmc)) { > - spin_unlock_irq(&host->lock); > - mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); > - spin_lock_irq(&host->lock); > - } > +static void __sdhci_set_power(struct sdhci_host *host, unsigned char mode, > + unsigned short vdd) > +{ > + struct mmc_host *mmc = host->mmc; > + > + if (host->ops->set_power) > + host->ops->set_power(host, mode, vdd); > + else if (!IS_ERR(mmc->supply.vmmc)) > + sdhci_set_power_reg(host, mode, vdd); > + else > + sdhci_set_power(host, mode, vdd); > } > > /*****************************************************************************\ > @@ -1490,7 +1511,7 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios) > } > } > > - sdhci_set_power(host, ios->power_mode, ios->vdd); > + __sdhci_set_power(host, ios->power_mode, ios->vdd); > > if (host->ops->platform_send_init_74_clocks) > host->ops->platform_send_init_74_clocks(host, ios->power_mode); > diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h > index 0115e9907bf8..033d72b5bbd5 100644 > --- a/drivers/mmc/host/sdhci.h > +++ b/drivers/mmc/host/sdhci.h > @@ -529,6 +529,8 @@ struct sdhci_ops { > #endif > > void (*set_clock)(struct sdhci_host *host, unsigned int clock); > + void (*set_power)(struct sdhci_host *host, unsigned char mode, > + unsigned short vdd); > > int (*enable_dma)(struct sdhci_host *host); > unsigned int (*get_max_clock)(struct sdhci_host *host); > @@ -660,6 +662,8 @@ static inline bool sdhci_sdio_irq_enabled(struct sdhci_host *host) > } > > void sdhci_set_clock(struct sdhci_host *host, unsigned int clock); > +void sdhci_set_power(struct sdhci_host *host, unsigned char mode, > + unsigned short vdd); > void sdhci_set_bus_width(struct sdhci_host *host, int width); > void sdhci_reset(struct sdhci_host *host, u8 mask); > void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing); >