From patchwork Tue Apr 23 09:02:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 162669 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3541086jan; Tue, 23 Apr 2019 02:03:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwD3vHRRxzHhLZB/ahNCKV4ZcF6YGZw84nWEYU3qQA+4U1F+sIQUlEcBzIAkxXNnU3N19H0 X-Received: by 2002:a17:902:9006:: with SMTP id a6mr18447349plp.259.1556010183972; Tue, 23 Apr 2019 02:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556010183; cv=none; d=google.com; s=arc-20160816; b=q4deMwXpfAAHx7z40/VqY9XfhcD4IwsI8hrElqo4x+OO8PKDx10zu4u8Bw02bZU1ZD 8I1DMHhnB/ZYteVmvcAbdcyRdXRnDXIAuTQK4eO6EbxS0KtuOAUU2AbdM3dvmI9kvPqJ x6o22xEdmrrZcVx/29zEA9aJQfpkgzzKA05kOuZKog+m/4mqE99vNYzz7Ea+hGNW7Yiy sisDNXs8t+O6EcoSCEhQOoAy3jgYYs8b8IjdBmvNf+Kws29xNTDLjKq2lmTgnGEfGudE NfWYbcs/oUAKrVp6fnF+/EmBen/gY6x0COlgWymXu+OWM1xOT6bz3ODMF4SARoV8K+dO zEYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a2NNf2UNkHCYlSEUhojNPJKAy7RIBEN/uvTpac68Irc=; b=RG+0sgRSptoOCbV7MbzMqzgG3sHyFWl4HgA3r+ZrXwEsphnoQDzzgnSsKGeO19uoOZ O9wSY9bDqt+EU7xS+guFz8wKhv4UcT36HQJc7+HG4c6MNZYjzjiiwZqe/aetVm6byb3/ BchpNGQ/v9IkOH3HbO8/soGSmKbzQS7WoOEKpNTxO3ET+/YULtQb1AHRj6JSyQWz9u2k SuZkN6vTaaaDhIS3XyvZg0j4PmgrMZmd/iykPaINWYMp4RfoNSpd+uU4I6wqwzO5B0v1 5C4KmPURQemjaWtMNUCXFiJSWhj6PxTDENTXGDovNNb7RTuy9Fa19VPDKnadaXmZ8c1r +BXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=pZVAggBK; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si14920910plk.297.2019.04.23.02.03.03; Tue, 23 Apr 2019 02:03:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=pZVAggBK; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727031AbfDWJDC (ORCPT + 5 others); Tue, 23 Apr 2019 05:03:02 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43417 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727183AbfDWJC4 (ORCPT ); Tue, 23 Apr 2019 05:02:56 -0400 Received: by mail-wr1-f66.google.com with SMTP id k17so19128216wrx.10 for ; Tue, 23 Apr 2019 02:02:55 -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 :mime-version:content-transfer-encoding; bh=a2NNf2UNkHCYlSEUhojNPJKAy7RIBEN/uvTpac68Irc=; b=pZVAggBKomrDwwXwIFYC88tNJkpD/Elg6lpOxD5sDMZvV6+ahObnJ+VVsAxt/lwutS ljrx4Xpze05TLTBdcwoEXSm27XmhxjSYafhKfc+SDicqyvlw02SGRPGc6FORBPzvoXwY GAPcIdb3Z3b3HE7m4xr+a2HSnufoatwh86T8T6PaZRN2gMEaMEYHsgJ9jw+AsQS4er3J J5VDSCDTgNKOXWESciIjO8ozYcjg17xIx+gXKaULdRwb6rS7MeeBUQzNRICz3cJN/Vkp wD3oL65hUoxMItGoTk141UR2SEF65tzO04gxrNc2aGjmVTYaWzpnXykWMaQGAlX39xbK xaaw== 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:mime-version:content-transfer-encoding; bh=a2NNf2UNkHCYlSEUhojNPJKAy7RIBEN/uvTpac68Irc=; b=SEq4Fbel9NQbkjmJMOLNVEztzjIacwppwXjDQ86uPZRUYf9139rd3NaaCllrrHNJop neejk4SrjwQCquso3iDlFDgsmP0OS/6fUkeBiF3trFUghZKUjyPoj5Nd6QOLUAF189lT ek5ugRZdLE6WXHI45FAg+KydMQZM77LLXeiG4v+XEmBDFihbsESmfH+FvRmFdbTO1cXW 3Yc2dTSbMzq8C5GzCJPSXiPJVoq974Xbu4M1Ofao6kzJPjGpZ65QaoGFmqVVN+Gqnsr+ 1RWj4f6X3MaKA/2qqHuUcR3q5Vc0ZfzLR5owXuyjFSO0jsIEQA52Y5T9hJgu0gAVDV+f vKnw== X-Gm-Message-State: APjAAAVO2ZW3oHZkJKdeiAU6UhTOsW1yY/KxuTpGFeYl69OuB3+oc1lD 8KgGGrC7gg7/7+3phjgyaTlAbA== X-Received: by 2002:a5d:5346:: with SMTP id t6mr17432415wrv.59.1556010174449; Tue, 23 Apr 2019 02:02:54 -0700 (PDT) Received: from boomer.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id z23sm12361894wma.0.2019.04.23.02.02.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 02:02:53 -0700 (PDT) From: Jerome Brunet To: Ulf Hansson , Kevin Hilman Cc: Jerome Brunet , linux-mmc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] mmc: meson-gx: add signal resampling tuning Date: Tue, 23 Apr 2019 11:02:35 +0200 Message-Id: <20190423090235.17244-8-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190423090235.17244-1-jbrunet@baylibre.com> References: <20190423090235.17244-1-jbrunet@baylibre.com> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Use signal resampling tuning for the UHS and HS200 modes. Instead of trying to get the *best* resampling setting with complex window calculation, we just stop on the first working setting. If the tuning setting later proves unstable, we will just continue the tuning where we left it. Signed-off-by: Jerome Brunet --- drivers/mmc/host/meson-gx-mmc.c | 73 +++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) -- 2.20.1 Tested-by: Martin Blumenstingl diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index acdc5520d02c..c5a8af4ca76b 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -488,6 +488,61 @@ static int meson_mmc_clk_init(struct meson_host *host) return clk_prepare_enable(host->mmc_clk); } +static void meson_mmc_disable_resampling(struct meson_host *host) +{ + unsigned int val = readl(host->regs + host->data->adjust); + + val &= ~ADJUST_ADJ_EN; + writel(val, host->regs + host->data->adjust); +} + +static void meson_mmc_reset_resampling(struct meson_host *host) +{ + unsigned int val; + + meson_mmc_disable_resampling(host); + + val = readl(host->regs + host->data->adjust); + val &= ~ADJUST_ADJ_DELAY_MASK; + writel(val, host->regs + host->data->adjust); +} + +static int meson_mmc_resampling_tuning(struct mmc_host *mmc, u32 opcode) +{ + struct meson_host *host = mmc_priv(mmc); + unsigned int val, dly, max_dly, i; + int ret; + + /* Resampling is done using the source clock */ + max_dly = DIV_ROUND_UP(clk_get_rate(host->mux_clk), + clk_get_rate(host->mmc_clk)); + + val = readl(host->regs + host->data->adjust); + val |= ADJUST_ADJ_EN; + writel(val, host->regs + host->data->adjust); + + if (mmc->doing_retune) + dly = FIELD_GET(ADJUST_ADJ_DELAY_MASK, val) + 1; + else + dly = 0; + + for (i = 0; i < max_dly; i++) { + val &= ~ADJUST_ADJ_DELAY_MASK; + val |= FIELD_PREP(ADJUST_ADJ_DELAY_MASK, (dly + i) % max_dly); + writel(val, host->regs + host->data->adjust); + + ret = mmc_send_tuning(mmc, opcode, NULL); + if (!ret) { + dev_dbg(mmc_dev(mmc), "resampling delay: %u\n", + (dly + i) % max_dly); + return 0; + } + } + + meson_mmc_reset_resampling(host); + return -EIO; +} + static int meson_mmc_prepare_ios_clock(struct meson_host *host, struct mmc_ios *ios) { @@ -507,6 +562,19 @@ static int meson_mmc_prepare_ios_clock(struct meson_host *host, return meson_mmc_clk_set(host, ios->clock, ddr); } +static void meson_mmc_check_resampling(struct meson_host *host, + struct mmc_ios *ios) +{ + switch (ios->timing) { + case MMC_TIMING_LEGACY: + case MMC_TIMING_MMC_HS: + case MMC_TIMING_SD_HS: + case MMC_TIMING_MMC_DDR52: + meson_mmc_disable_resampling(host); + break; + } +} + static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) { struct meson_host *host = mmc_priv(mmc); @@ -533,9 +601,6 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) if (!IS_ERR(mmc->supply.vmmc)) mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd); - /* disable signal resampling */ - writel(0, host->regs + host->data->adjust); - break; case MMC_POWER_ON: @@ -574,6 +639,7 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) val |= FIELD_PREP(CFG_BUS_WIDTH_MASK, bus_width); writel(val, host->regs + SD_EMMC_CFG); + meson_mmc_check_resampling(host, ios); err = meson_mmc_prepare_ios_clock(host, ios); if (err) dev_err(host->dev, "Failed to set clock: %d\n,", err); @@ -963,6 +1029,7 @@ static const struct mmc_host_ops meson_mmc_ops = { .get_cd = meson_mmc_get_cd, .pre_req = meson_mmc_pre_req, .post_req = meson_mmc_post_req, + .execute_tuning = meson_mmc_resampling_tuning, .card_busy = meson_mmc_card_busy, .start_signal_voltage_switch = meson_mmc_voltage_switch, };