From patchwork Thu Jun 4 11:20:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 11587793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FC8D14E3 for ; Thu, 4 Jun 2020 11:20:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D67D2075B for ; Thu, 4 Jun 2020 11:20:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="u13yUz49" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbgFDLUx (ORCPT ); Thu, 4 Jun 2020 07:20:53 -0400 Received: from www.zeus03.de ([194.117.254.33]:58166 "EHLO mail.zeus03.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbgFDLUx (ORCPT ); Thu, 4 Jun 2020 07:20:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=sang-engineering.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=k1; bh=fy0N5v6dMpnuMO xPYW0BamAucP2Gatl8R92TW/mjjgs=; b=u13yUz494e1+srkMiGdtJSW+sRd8dS t3GK2hPoFdKaCahOLt6VlS6JEyOzVaNmmw3yMuQ+qQwRIczVNoH18/Ixt0pWwaQm U63qknRKtatUpWQRN27YVQ8x2wlX5a0flgGwhCSkSh+ZKL1TBgFu0AF1EimLZmQX X9tEI867k5rwI= Received: (qmail 1656146 invoked from network); 4 Jun 2020 13:20:51 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 4 Jun 2020 13:20:51 +0200 X-UD-Smtp-Session: l3s3148p1@+g9OVkCncOUgAwDPXw1XANux7yWtmp4Z From: Wolfram Sang To: linux-mmc@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda , Wolfram Sang Subject: [PATCH 1/2] mmc: core: when downgrading HS400, callback into drivers earlier Date: Thu, 4 Jun 2020 13:20:39 +0200 Message-Id: <20200604112040.22144-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200604112040.22144-1-wsa+renesas@sang-engineering.com> References: <20200604112040.22144-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The driver specific downgrade function makes more sense if we run it before we switch anything, not after we already switched. Otherwise some non-HS400 communication has already happened. No need to convert users. There is only one currenty which needs this change in a later patchset. Signed-off-by: Wolfram Sang --- drivers/mmc/core/mmc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 4203303f946a..f97994eace3b 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1156,6 +1156,10 @@ static int mmc_select_hs400(struct mmc_card *card) host->ios.bus_width == MMC_BUS_WIDTH_8)) return 0; + /* Prepare host to downgrade to HS timing */ + if (host->ops->hs400_downgrade) + host->ops->hs400_downgrade(host); + /* Switch card to HS mode */ val = EXT_CSD_TIMING_HS; err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, @@ -1171,10 +1175,6 @@ static int mmc_select_hs400(struct mmc_card *card) /* Set host controller to HS timing */ mmc_set_timing(card->host, MMC_TIMING_MMC_HS); - /* Prepare host to downgrade to HS timing */ - if (host->ops->hs400_downgrade) - host->ops->hs400_downgrade(host); - /* Reduce frequency to HS frequency */ max_dtr = card->ext_csd.hs_max_dtr; mmc_set_clock(host, max_dtr); @@ -1241,6 +1241,9 @@ int mmc_hs400_to_hs200(struct mmc_card *card) int err; u8 val; + if (host->ops->hs400_downgrade) + host->ops->hs400_downgrade(host); + /* Reduce frequency to HS */ max_dtr = card->ext_csd.hs_max_dtr; mmc_set_clock(host, max_dtr); @@ -1268,9 +1271,6 @@ int mmc_hs400_to_hs200(struct mmc_card *card) mmc_set_timing(host, MMC_TIMING_MMC_HS); - if (host->ops->hs400_downgrade) - host->ops->hs400_downgrade(host); - err = mmc_switch_status(card, true); if (err) goto out_err; From patchwork Thu Jun 4 11:20:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 11587797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5D79175A for ; Thu, 4 Jun 2020 11:20:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE6E02075B for ; Thu, 4 Jun 2020 11:20:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="JSE4mkCT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727038AbgFDLUx (ORCPT ); Thu, 4 Jun 2020 07:20:53 -0400 Received: from www.zeus03.de ([194.117.254.33]:58172 "EHLO mail.zeus03.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727046AbgFDLUx (ORCPT ); Thu, 4 Jun 2020 07:20:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=sang-engineering.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=k1; bh=Z93EQCVx29m/J8 oT4GzMC5ngz7xne9z1CvWsn7xKrXw=; b=JSE4mkCT9EjQg3BHj/YbjjCvCI18vK KrYSQOOSL3FjfrpbrnSs3mXJsIXSuIaX8OhJbZ53sms94krE4jBbtPw7uEd55RUD Wlxh3TDzmXNBtYNTG0uexK0KakmlUIj2ySTBFfNTDy6AhWVZI12Pj92N5S/ILKVV 0qq/PADIgLqpY= Received: (qmail 1656181 invoked from network); 4 Jun 2020 13:20:51 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 4 Jun 2020 13:20:51 +0200 X-UD-Smtp-Session: l3s3148p1@ZA5UVkCncuUgAwDPXw1XANux7yWtmp4Z From: Wolfram Sang To: linux-mmc@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda , Wolfram Sang Subject: [PATCH 2/2] mmc: renesas_sdhi: keep SCC clock active when tuning Date: Thu, 4 Jun 2020 13:20:40 +0200 Message-Id: <20200604112040.22144-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200604112040.22144-1-wsa+renesas@sang-engineering.com> References: <20200604112040.22144-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Tuning procedure switches to lower frequencies but that will turn the SCC off and accessing its register then will hang. So, flag when we are tuning and keep the current setup of the external clock if we are doing so. Note that we still switch to the lower frequency because of the internal divider. We just make sure to not modify the external clock. This patch depends on a MMC core patch calling the downgrade function earlier. Signed-off-by: Wolfram Sang --- drivers/mmc/host/renesas_sdhi.h | 1 + drivers/mmc/host/renesas_sdhi_core.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/renesas_sdhi.h b/drivers/mmc/host/renesas_sdhi.h index 14c64caefc64..58a8c9133ba4 100644 --- a/drivers/mmc/host/renesas_sdhi.h +++ b/drivers/mmc/host/renesas_sdhi.h @@ -59,6 +59,7 @@ struct renesas_sdhi { u32 scc_tappos; u32 scc_tappos_hs400; bool doing_tune; + bool keep_scc_freq; /* Tuning values: 1 for success, 0 for failure */ DECLARE_BITMAP(taps, BITS_PER_LONG); diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c index 15e21894bd44..589a59fb70eb 100644 --- a/drivers/mmc/host/renesas_sdhi_core.c +++ b/drivers/mmc/host/renesas_sdhi_core.c @@ -117,8 +117,12 @@ static unsigned int renesas_sdhi_clk_update(struct tmio_mmc_host *host, unsigned int freq, diff, best_freq = 0, diff_min = ~0; int i; - /* tested only on R-Car Gen2+ currently; may work for others */ - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) + /* + * We simply return the current rate if a) we are not on a R-Car Gen2+ + * SoC (may work for others, but untested) or b) if the SCC needs its + * clock during tuning, so we don't change the external clock setup. + */ + if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2) || priv->keep_scc_freq) return clk_get_rate(priv->clk); /* @@ -323,6 +327,9 @@ static void renesas_sdhi_hs400_complete(struct mmc_host *mmc) u32 bad_taps = priv->quirks ? priv->quirks->hs400_bad_taps : 0; bool use_4tap = priv->quirks && priv->quirks->hs400_4taps; + /* Tuning done, no special handling for SCC clock needed anymore */ + priv->keep_scc_freq = false; + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); @@ -401,6 +408,14 @@ static void renesas_sdhi_disable_scc(struct mmc_host *mmc) sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + + /* + * During retune, we still access SCC registers, so keep clock on. + * We have it here again because for retuning it is too late when we + * only enable this flag when HS400 tuning gets initialized. + */ + if (mmc_doing_retune(mmc)) + priv->keep_scc_freq = true; } static void renesas_sdhi_reset_hs400_mode(struct tmio_mmc_host *host, @@ -427,8 +442,12 @@ static void renesas_sdhi_reset_hs400_mode(struct tmio_mmc_host *host, static int renesas_sdhi_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios) { struct tmio_mmc_host *host = mmc_priv(mmc); + struct renesas_sdhi *priv = host_to_priv(host); + + /* During tuning, we still access SCC registers, so keep clock on */ + priv->keep_scc_freq = true; + renesas_sdhi_reset_hs400_mode(host, priv); - renesas_sdhi_reset_hs400_mode(host, host_to_priv(host)); return 0; }