From patchwork Thu Jun 6 14:35:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 2681251 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 606F7DF23A for ; Thu, 6 Jun 2013 14:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752211Ab3FFOfz (ORCPT ); Thu, 6 Jun 2013 10:35:55 -0400 Received: from moutng.kundenserver.de ([212.227.126.171]:62307 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752084Ab3FFOfy (ORCPT ); Thu, 6 Jun 2013 10:35:54 -0400 Received: from axis700.grange (dslb-088-077-167-013.pools.arcor-ip.net [88.77.167.13]) by mrelayeu.kundenserver.de (node=mrbap0) with ESMTP (Nemesis) id 0MdXMC-1V18c10LT2-00PNRQ; Thu, 06 Jun 2013 16:35:45 +0200 Received: by axis700.grange (Postfix, from userid 1000) id 6D89940BB4; Thu, 6 Jun 2013 16:35:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 6A82040BB3; Thu, 6 Jun 2013 16:35:44 +0200 (CEST) Date: Thu, 6 Jun 2013 16:35:44 +0200 (CEST) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Chris Ball cc: linux-mmc@vger.kernel.org, linux-sh@vger.kernel.org Subject: [PATCH v3 1/2] mmc: tmio: fix unbalanced power-on calls with clock-gating enabled In-Reply-To: <871u8f8nxb.fsf@octavius.laptop.org> Message-ID: References: <871u8f8nxb.fsf@octavius.laptop.org> MIME-Version: 1.0 X-Provags-ID: V02:K0:vgM839VkYSAJOHAjamrmC+DSYfuhkKrzEbs+c9cT1n/ oTnXJz0NP2ITd9wlRPA2yFRxmujFJOjIAz+oPc6esPi1QIZrin Kj3N8IPaDKEjwmE3DEBBt9/QIwzEy80rWe04B9ovZCCUXZ8lUD es1wYGvXp84iwSm6+VuweGYj4aQ9Cd3a+0plcGuQiUgo3YP9TU d9R8oFp5BOF916Z8xGsgRhVLMDscLWsz0N+WeVAv5xGoZAPBAs 2oeBHH3yqedE4wUEofZ/XFQ3/gDIY1PHe/KUhAAQGNSuYkFLG/ wgl1Na6iyuHCVwFXCdGGXjVRyah9JN0pbOupXQ1/J8abnMqsT1 ACTe15fytbAMXrdekW04vjBtFZUOvwKifmR/S9xgQ9fVrYSPfg pj7eb1ub4S38w== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org With MMC clock gating enabled the MMC core currently calls MMC host driver's .set_ios() method with .power_mode == MMC_POWER_ON and the clock value set either to 0 or to the target rate. The tmio MMC driver then wrongly translates the latter calls to card slot power-on requests, even when the slot already was on. This patch fixes the driver to avoid needlessly incrementing power-supplying regulator's use count. Signed-off-by: Guennadi Liakhovetski Tested-by: Laurent Pinchart --- v3: rebased on top of current mmc-next / 3.10-rc drivers/mmc/host/tmio_mmc.h | 20 ++++++++++++++++++-- drivers/mmc/host/tmio_mmc_pio.c | 27 +++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h index 759d8f4..86fd21e 100644 --- a/drivers/mmc/host/tmio_mmc.h +++ b/drivers/mmc/host/tmio_mmc.h @@ -40,6 +40,22 @@ struct tmio_mmc_data; +/* + * We differentiate between the following 3 power states: + * 1. card slot powered off, controller stopped. This is used, when either there + * is no card in the slot, or the card really has to be powered down. + * 2. card slot powered on, controller stopped. This is used, when a card is in + * the slot, but no activity is currently taking place. This is a power- + * saving mode with card-state preserved. This state can be entered, e.g. + * when MMC clock-gating is used. + * 3. card slot powered on, controller running. This is the actual active state. + */ +enum tmio_mmc_power { + TMIO_MMC_OFF_STOP, /* card power off, controller stopped */ + TMIO_MMC_ON_STOP, /* card power on, controller stopped */ + TMIO_MMC_ON_RUN, /* card power on, controller running */ +}; + struct tmio_mmc_host { void __iomem *ctl; unsigned long bus_shift; @@ -48,8 +64,8 @@ struct tmio_mmc_host { struct mmc_data *data; struct mmc_host *mmc; - /* Controller power state */ - bool power; + /* Controller and card power state */ + enum tmio_mmc_power power; /* Callbacks for clock / power control */ void (*set_pwr)(struct platform_device *host, int state); diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c index 435cc4d..67d9642 100644 --- a/drivers/mmc/host/tmio_mmc_pio.c +++ b/drivers/mmc/host/tmio_mmc_pio.c @@ -859,7 +859,7 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) * is kept positive, so no suspending actually takes place. */ if (ios->power_mode == MMC_POWER_ON && ios->clock) { - if (!host->power) { + if (host->power != TMIO_MMC_ON_RUN) { tmio_mmc_clk_update(mmc); pm_runtime_get_sync(dev); if (host->resuming) { @@ -868,27 +868,34 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) } } tmio_mmc_set_clock(host, ios->clock); - if (!host->power) { + if (host->power == TMIO_MMC_OFF_STOP) /* power up SD card and the bus */ tmio_mmc_power_on(host, ios->vdd); - host->power = true; - } + host->power = TMIO_MMC_ON_RUN; /* start bus clock */ tmio_mmc_clk_start(host); } else if (ios->power_mode != MMC_POWER_UP) { - if (host->power) { - struct tmio_mmc_data *pdata = host->pdata; - if (ios->power_mode == MMC_POWER_OFF) + struct tmio_mmc_data *pdata = host->pdata; + unsigned int old_power = host->power; + + if (old_power != TMIO_MMC_OFF_STOP) { + if (ios->power_mode == MMC_POWER_OFF) { tmio_mmc_power_off(host); + host->power = TMIO_MMC_OFF_STOP; + } else { + host->power = TMIO_MMC_ON_STOP; + } + } + + if (old_power == TMIO_MMC_ON_RUN) { tmio_mmc_clk_stop(host); - host->power = false; pm_runtime_put(dev); if (pdata->clk_disable) pdata->clk_disable(host->pdev); } } - if (host->power) { + if (host->power != TMIO_MMC_OFF_STOP) { switch (ios->bus_width) { case MMC_BUS_WIDTH_1: sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0); @@ -1029,7 +1036,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host **host, mmc->caps & MMC_CAP_NONREMOVABLE || mmc->slot.cd_irq >= 0); - _host->power = false; + _host->power = TMIO_MMC_OFF_STOP; pm_runtime_enable(&pdev->dev); ret = pm_runtime_resume(&pdev->dev); if (ret < 0)