From patchwork Thu Feb 11 12:59:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 61755 Delivered-To: patches@linaro.org Received: by 10.112.43.199 with SMTP id y7csp175049lbl; Thu, 11 Feb 2016 05:00:13 -0800 (PST) X-Received: by 10.25.218.148 with SMTP id r142mr9195803lfg.154.1455195612234; Thu, 11 Feb 2016 05:00:12 -0800 (PST) Return-Path: Received: from mail-lf0-x22f.google.com (mail-lf0-x22f.google.com. [2a00:1450:4010:c07::22f]) by mx.google.com with ESMTPS id a1si4217332lbg.155.2016.02.11.05.00.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Feb 2016 05:00:12 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22f as permitted sender) client-ip=2a00:1450:4010:c07::22f; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22f as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-lf0-x22f.google.com with SMTP id l143so31048636lfe.2 for ; Thu, 11 Feb 2016 05:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mss/JxWAfDNwKD9CbMOWIBqAw488ADr+cLshHDapyxY=; b=k2DzQKWy3wIj++JDpz89vljKEgivV7z5d88nqkdtW/qFVweRiwvD6PigG1EiJL1zir Ck6YN+vmlPqmKAqNwUz9nLm9nTs4P730jDd3xK15Nd/IG6q0XVNX7nqgv49Rz5bzaogx uFYE3J3KZd7MJtQy5bgC/V1saMmb9da3EplVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mss/JxWAfDNwKD9CbMOWIBqAw488ADr+cLshHDapyxY=; b=PRT2zcQebXYDkzX6WWlJ1tgui7K2Ze5lZwmkHKY8jQ8JQiArmdRUR4o+7lmvn3/T1+ DeIziE4KLAT43/huEt33+UwIGVPXvrLc8+k6b4GZad1+0nNetX0BZ2y5xKPS0x3IHLAZ vP1aHI8j3hafPEpBf4Z6HGKvbEF4pAKaJ/7fEx4Cs9uqGWMAKyWc2cEVJKAbxXT8Kqsm ixCsJV51CNL4PAoxVy7P7pLR+wLfTMQlwqJNYiqnCD19cuXhNv1GCLBa9xedCdmKBHxg GB5ZQkxpg4N58y+vfIicyiysFCGHjWfc63aFVE0jYyDz9VDnNcDzyVhkWazW7+WCHlpl nnfw== X-Gm-Message-State: AG10YOT2cOH101Y+m7KalCsePGBNChkt372EVUi9TwVqmtFA44211WN+KtDRSuqTxghv7SNlIAk= X-Received: by 10.25.91.20 with SMTP id p20mr5113225lfb.79.1455195612091; Thu, 11 Feb 2016 05:00:12 -0800 (PST) Return-Path: Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id dm7sm1179635lbc.32.2016.02.11.05.00.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 11 Feb 2016 05:00:11 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Kuninori Morimoto , Geert Uytterhoeven , Nguyen Viet Dung , Magnus Damm , Simon Horman , Laurent Pinchart Subject: [PATCH 2/3] mmc: sh_mmcif: Restructure ->set_ios() Date: Thu, 11 Feb 2016 13:59:54 +0100 Message-Id: <1455195595-5121-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455195595-5121-1-git-send-email-ulf.hansson@linaro.org> References: <1455195595-5121-1-git-send-email-ulf.hansson@linaro.org> Both from a runtime PM and clock management point of view, the ->set_ios() code is unnecessary complex. A suboptimal path is also executed when the mmc core requests a clock rate of zero. As that happens during the card initialization phase, trying to save power by decreasing the runtime PM usage count and gating the clock via clk_disable_unprepare() is just superfluous. Moreover, from a runtime PM point of view the core will anyway keep the device active during the entire card initialization phase. Restructure the code to rely on the ios->power_mode to understand when the runtime PM usage count needs to be increased. Let's also deal with clock rate changes by simply applying the rate. Signed-off-by: Ulf Hansson --- drivers/mmc/host/sh_mmcif.c | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) -- 1.9.1 diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c index c6c2a08..1c84c62 100644 --- a/drivers/mmc/host/sh_mmcif.c +++ b/drivers/mmc/host/sh_mmcif.c @@ -248,7 +248,6 @@ struct sh_mmcif_host { int sg_idx; int sg_blkidx; bool power; - bool card_present; bool ccs_enable; /* Command Completion Signal support */ bool clk_ctrl2_enable; struct mutex thread_lock; @@ -1091,42 +1090,30 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) host->state = STATE_IOS; spin_unlock_irqrestore(&host->lock, flags); - if (ios->power_mode == MMC_POWER_UP) { - if (!host->card_present) { - /* See if we also get DMA */ + switch (ios->power_mode) { + case MMC_POWER_UP: + sh_mmcif_set_power(host, ios); + if (!host->power) { + clk_prepare_enable(host->clk); + pm_runtime_get_sync(dev); + sh_mmcif_sync_reset(host); sh_mmcif_request_dma(host); - host->card_present = true; + host->power = true; } + break; + case MMC_POWER_OFF: sh_mmcif_set_power(host, ios); - } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) { - /* clock stop */ - sh_mmcif_clock_control(host, 0); - if (ios->power_mode == MMC_POWER_OFF) { - if (host->card_present) { - sh_mmcif_release_dma(host); - host->card_present = false; - } - } if (host->power) { - pm_runtime_put_sync(dev); + sh_mmcif_clock_control(host, 0); + sh_mmcif_release_dma(host); + pm_runtime_put(dev); clk_disable_unprepare(host->clk); host->power = false; - if (ios->power_mode == MMC_POWER_OFF) - sh_mmcif_set_power(host, ios); - } - host->state = STATE_IDLE; - return; - } - - if (ios->clock) { - if (!host->power) { - clk_prepare_enable(host->clk); - - pm_runtime_get_sync(dev); - host->power = true; - sh_mmcif_sync_reset(host); } + break; + case MMC_POWER_ON: sh_mmcif_clock_control(host, ios->clock); + break; } host->timing = ios->timing;