From patchwork Wed Apr 17 20:43:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 162424 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp5955435jan; Wed, 17 Apr 2019 13:44:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMO/zki9yRhJy2TUDb+jLmLVBDF0JEbouuARsL2b1e+L3NDgsK0vkorXO8hnUTZ3ZDKysq X-Received: by 2002:a17:902:e70c:: with SMTP id co12mr1927455plb.339.1555533860048; Wed, 17 Apr 2019 13:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555533860; cv=none; d=google.com; s=arc-20160816; b=VJWAbgRw9pEH/yZ6dbYGqP3yHqBVvNtX4YaFe90e6RdSeJc13CRL+s3A1zJvCiJWrf j1ts6VnZxKG94SQomFjiWty5bhA5a4vAWQvD5/LGzFoHKwSxWtPEbitKjM1HrbN2j3M2 l2ac9iokHNa6ls9NTk4VqDj2A829L+vpQjN6l2nXiQIJ9sbRkwCk+Cn+GUvinpZXUUOV ci0BTyjnCAdHfqUqoTt/gCSzoYSi9toWa6fywRcgKFUADofhge3Qo/auqfbHw3hcb9GE 2b6KhV5fc1OmW+wntU+aqGHb1kQ4dxsKSseDvgcs9OB5zfwCcD2qdWXwnyghYujPjWms 79+w== 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=2PG4RVUDpV3B0qjRGkkQWtaaCze4HgvXH3Z70Qm9O/U=; b=aGBaG9cyxShfFveSU7iZbbvHhR3ykO1fCgd2g///OCTXH6t3KJiig/RxRQOe61d8vH Zy2ZDFgcdAuXDZtEMoIoK2ExBCc/dpP022nJcy7sSm6R/IXfLbcQ98ezyXfEUxj7ERez C5KRLmvV2ug2yoj5W8GaQNXHBMYo7gqZr+YUyB+2DpEW/iiKDod4zBRUkBuo05H43s7Z 4hdcdkYcNOrcWmCCj1C/kggjyjnP6p1MNacsSemRuTH+YG2yJ4GZATwlhTe8V923HgI4 XdlyX5EI+6s9QNDIxfAeJdY4Br8J5UH70mW8CUiYjN+BN8/dTIiW1Fe5PEdQyRqpeend Zlzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=warLkyBW; 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 94si53475299plc.298.2019.04.17.13.44.19; Wed, 17 Apr 2019 13:44:20 -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=warLkyBW; 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 S1733134AbfDQUoS (ORCPT + 5 others); Wed, 17 Apr 2019 16:44:18 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45066 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733147AbfDQUoR (ORCPT ); Wed, 17 Apr 2019 16:44:17 -0400 Received: by mail-wr1-f65.google.com with SMTP id s15so54601wra.12 for ; Wed, 17 Apr 2019 13:44:15 -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=2PG4RVUDpV3B0qjRGkkQWtaaCze4HgvXH3Z70Qm9O/U=; b=warLkyBWdpYp4KCSIryoCoiZ8g33ebunoaq+b324HnCWykVlBGG9uLeJFnplM4RNvu MQgIbQM/u8eXQjMn8bmy825OKBYcmspvxnC1G0Uc0DEd6vCKR/yfpdXyDdQpaHdYjx62 otT8hh2K210mgQItR8iQwaLCqKrhOrgLezEZGM5Gr6Maz38CSwoi1q5R91LiYXKqIm2b pBy8P6l+FveatazYFV/RkNtmPF7GLssnnVDowUjoTuiIpJM/er/KRT7aJYfSSEKU/tV0 /uV3DgSs0ckqP9ndEejdlFA0iBDq7mmNzZ2J5ZCIGQhvOt39cecFNBFFklIjdqR3qXRP qMsQ== 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=2PG4RVUDpV3B0qjRGkkQWtaaCze4HgvXH3Z70Qm9O/U=; b=Vh0G55B5jHeqgClJylhtb0DmYyFu16JpYT+zC9DQR862Mg9krMe31l+rbpRWEGyWGk sR+PjcswI+GeIjVycuGDq4yUGPWEQsDZxHkS6zmGuDVfPanNzTKM1RWbW0gD2cov/aKi Ts25wW17QwKlU3p4auLMqG17xzmuq7D/w6oseGgRN4zZ2I+Qkzoa9xyzM228speYcW9d n55iA1TkoNY6xHNw6irpyY6IuYHuvvzzbuh7ElKZ8RmmO29K5hKPjQY9/zKLKdPdZwVL 8CXGUvGng15vQbi1aWaOLalIKfl5M0j6cMIlWDTBOw3SVC+Si7E1G0RnUTELmdlqYJoT OAiA== X-Gm-Message-State: APjAAAWE40d9eqT4YNBmIQP6UUMLsmLvKzaxkAyB9BWrTkucGHzSWNm6 I/ft/q99taOP0OeZc/RCSTOiBA== X-Received: by 2002:adf:ed8f:: with SMTP id c15mr35201960wro.144.1555533855185; Wed, 17 Apr 2019 13:44:15 -0700 (PDT) Received: from boomer.lan (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id c20sm98716866wre.28.2019.04.17.13.44.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 13:44:14 -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 7/7] mmc: meson-gx: add signal resampling tuning Date: Wed, 17 Apr 2019 22:43:55 +0200 Message-Id: <20190417204355.469-8-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190417204355.469-1-jbrunet@baylibre.com> References: <20190417204355.469-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 diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 50b03c167435..207c65b3ddf1 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: @@ -573,6 +638,7 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) val &= ~CFG_BUS_WIDTH_MASK; val |= FIELD_PREP(CFG_BUS_WIDTH_MASK, bus_width); + 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); @@ -962,6 +1028,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, };