From patchwork Fri Aug 4 17:43:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9881867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A4A4B602B8 for ; Fri, 4 Aug 2017 17:48:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91E712891B for ; Fri, 4 Aug 2017 17:48:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86AA128964; Fri, 4 Aug 2017 17:48:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 228AF2891B for ; Fri, 4 Aug 2017 17:48:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=jF8kL5TAnsQ2465Ld08SwkHkmqXlJz3af1g8eDOow/s=; b=eGFBoijIcl/FD0HwPBtsezpxUr sGYKi1qICVhxo/KD1+KyrJFweC2/3RBXSIJxNVt+jnrK5/PGhbgfBWShPa4gy+2WPAB8f8g8mS8Rc FXCWnaYf/sCjkq8JWNxI03zyfbkzZ5fbgj1jhdW/+hFMTMtBEmTYLj0H8gt97jCYj1mvq73Xm4bBk m3W2wrL90+1NCM8ivU+5OybvW8at4A6mObzyL3s2fvv2huYM1EACYFaw0il31WBXBSyQ2lk20i4ji TM19kjdAd1qfc7pZ3wgkT6CdFyJ2Vtx8G8f3v2Ed1ygSqaxAGisPIQA23+tkhHZJksGpUux7BNtlR mhkN+H4g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ddgiL-0002Ld-My; Fri, 04 Aug 2017 17:48:45 +0000 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ddgeN-0006EX-H1 for linux-arm-kernel@lists.infradead.org; Fri, 04 Aug 2017 17:45:27 +0000 Received: by mail-wr0-x22f.google.com with SMTP id y43so19271626wrd.3 for ; Fri, 04 Aug 2017 10:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aXSsxtzj86v1KcEcxpTUl3XG7ximZhw4N1xAHRIzeiY=; b=BtquizK8tYjasMgXia1WkvmsUNDYhR5DX3iu5t/qIXfjX1aWaG+o4YXBWEJxhlDoZo wPvy5tvT0vGXtnkdgEVBBxcRn2OiBd7qM3EVsLX1DnPzbigh1Lqs43+FQUT8AHZ4Z19c CTFV0bgWp9Wg89pSicXR+6yQCDupzijN54ck76yBbmr0j3NIqPneUYxUxp1ybYz3k6bt IckaQxlU1cBvdDut0Jp9mQQnLIY/v9gN9cEIWrEB4/zgoO5MKnOgpyjkG0APOqHjYKoY 9EAun9VLkg+gI8W2J5cWIfJ7afGIOP2DBYXay+b0XzywZDNWxkZDcBMIqugwSffpnTWP IpvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aXSsxtzj86v1KcEcxpTUl3XG7ximZhw4N1xAHRIzeiY=; b=KleThEi5WGRX9UvOrbosmUl0KjdOxF3tYiuUznqsrW0HgT/L4iQVkJ2FSA4BRa/h7A +F/+YcxcQm4nKshMjQz8YpNPbHefNAJUc2whB3hfeE01zbXa6H37fYyXZ59wArDjBpzX SSkNuFxAWP5ctTuJqVaY1pqwDKsDfyiLJ9HK4pKaZuFuEAbyHLRe0VQU2MT0ME8MZuTp p+fGlfhcksolV7JqHqR2R7xrko1X+w2k/tjaQQUp5uXJAIIz2TPXxGwLfef53myNG+wl sZCBX2vbkN220AvKGsZThnGFqOjuLdE78lWaCU0348+C8JbiQc5/9Ir5L90PsES2FZXW vRvg== X-Gm-Message-State: AIVw111vpHkp1KyP/zb/92Z6oTsTSiTsdOuKoS5SOq/3UphiSOeCLVfY bTtpLf9Zk0Dgif6q X-Received: by 10.223.139.216 with SMTP id w24mr2255177wra.206.1501868657761; Fri, 04 Aug 2017 10:44:17 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id p17sm996082wma.45.2017.08.04.10.44.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Aug 2017 10:44:17 -0700 (PDT) From: Jerome Brunet To: Ulf Hansson , Kevin Hilman , Carlo Caione Subject: [PATCH 13/14] mmc: meson-gx: work around clk-stop issue Date: Fri, 4 Aug 2017 19:43:52 +0200 Message-Id: <20170804174353.16486-14-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170804174353.16486-1-jbrunet@baylibre.com> References: <20170804174353.16486-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170804_104440_372637_C2CAB996 X-CRM114-Status: GOOD ( 19.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jerome Brunet MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP It seems that the signal clock is also used and required, somehow, by the controller it self. It is shown during init, when writing to CFG while the divider is set to 0 will crash the SoC. During voltage switch, the controller may crash and the card may then fail to exit busy state if the clock is stopped. To avoid this, it is best to keep the clock running for the controller, except during rate change. However, we still need to be able to gate the clock out of the SoC. Let's use the pinmux for this, and fallback to gpio mode (pulled-down) when we need to gate the clock Signed-off-by: Jerome Brunet Reviewed-by: Kevin Hilman --- drivers/mmc/host/meson-gx-mmc.c | 74 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index f973278a3f8d..e991c9e452ab 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -145,6 +145,10 @@ struct meson_host { struct clk *signal_clk; unsigned long req_rate; + struct pinctrl *pinctrl; + struct pinctrl_state *pins_default; + struct pinctrl_state *pins_clk_gate; + unsigned int bounce_buf_size; void *bounce_buf; dma_addr_t bounce_dma_addr; @@ -308,6 +312,42 @@ static bool meson_mmc_timing_is_ddr(struct mmc_ios *ios) return false; } +/* + * Gating the clock on this controller is tricky. It seems the signal clock + * is also used by the controller. It may crash during some operation if the + * clock is stopped. The safest thing to do, whenever possible, is to keep + * clock running at stop it at the pad using the pinmux. + */ +static void meson_mmc_clk_gate(struct meson_host *host) +{ + u32 cfg; + + if (host->pins_clk_gate) { + pinctrl_select_state(host->pinctrl, host->pins_clk_gate); + } else { + /* + * If the pinmux is not provided - default to the classic and + * unsafe method + */ + cfg = readl(host->regs + SD_EMMC_CFG); + cfg |= CFG_STOP_CLOCK; + writel(cfg, host->regs + SD_EMMC_CFG); + } +} + +static void meson_mmc_clk_ungate(struct meson_host *host) +{ + u32 cfg; + + if (host->pins_clk_gate) + pinctrl_select_state(host->pinctrl, host->pins_default); + + /* Make sure the clock is not stopped in the controller */ + cfg = readl(host->regs + SD_EMMC_CFG); + cfg &= ~CFG_STOP_CLOCK; + writel(cfg, host->regs + SD_EMMC_CFG); +} + static int meson_mmc_clk_set(struct meson_host *host, struct mmc_ios *ios) { struct mmc_host *mmc = host->mmc; @@ -324,9 +364,7 @@ static int meson_mmc_clk_set(struct meson_host *host, struct mmc_ios *ios) return 0; /* stop clock */ - cfg = readl(host->regs + SD_EMMC_CFG); - cfg |= CFG_STOP_CLOCK; - writel(cfg, host->regs + SD_EMMC_CFG); + meson_mmc_clk_gate(host); host->req_rate = 0; if (!rate) { @@ -335,6 +373,11 @@ static int meson_mmc_clk_set(struct meson_host *host, struct mmc_ios *ios) return 0; } + /* Stop the clock during rate change to avoid glitches */ + cfg = readl(host->regs + SD_EMMC_CFG); + cfg |= CFG_STOP_CLOCK; + writel(cfg, host->regs + SD_EMMC_CFG); + ret = clk_set_rate(host->signal_clk, rate); if (ret) { dev_err(host->dev, "Unable to set cfg_div_clk to %lu. ret=%d\n", @@ -354,9 +397,7 @@ static int meson_mmc_clk_set(struct meson_host *host, struct mmc_ios *ios) dev_dbg(host->dev, "requested rate was %u\n", ios->clock); /* (re)start clock */ - cfg = readl(host->regs + SD_EMMC_CFG); - cfg &= ~CFG_STOP_CLOCK; - writel(cfg, host->regs + SD_EMMC_CFG); + meson_mmc_clk_ungate(host); return 0; } @@ -1037,6 +1078,27 @@ static int meson_mmc_probe(struct platform_device *pdev) goto free_host; } + host->pinctrl = devm_pinctrl_get(&pdev->dev); + if (IS_ERR(host->pinctrl)) { + ret = PTR_ERR(host->pinctrl); + goto free_host; + } + + host->pins_default = pinctrl_lookup_state(host->pinctrl, + PINCTRL_STATE_DEFAULT); + if (IS_ERR(host->pins_default)) { + ret = PTR_ERR(host->pins_default); + goto free_host; + } + + host->pins_clk_gate = pinctrl_lookup_state(host->pinctrl, + "clk-gate"); + if (IS_ERR(host->pins_clk_gate)) { + dev_warn(&pdev->dev, + "can't get clk-gate pinctrl, using clk_stop bit\n"); + host->pins_clk_gate = NULL; + } + host->core_clk = devm_clk_get(&pdev->dev, "core"); if (IS_ERR(host->core_clk)) { ret = PTR_ERR(host->core_clk);