From nobody Fri Oct 10 13:46:57 2025 Received: from TWMBX01.aspeed.com (mail.aspeedtech.com [211.20.114.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF3DE264608; Sun, 15 Jun 2025 03:58:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.20.114.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749959913; cv=none; b=e3vj0luoGXvReqYKlk9fq/eGI2VHnNNa+qbHckdykp5oDH3tCwUsS601YqoSxrRDXJifwXcvhIy8m8hu64spS7L47oln3Sfc5yOanHeXcIcwRlGky63KSj5tSXSSaqDfyqfPcDX+ourdeWpHJqJVnuspFARDpLStSXuIra1mPMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749959913; c=relaxed/simple; bh=bHUS/Tk9LMBg9lQIuPHoyB6SeTAcyZ0KY8ozl+YM+RE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Eo+8XUk3vvwwKnOft3OdPE98YIq0UjBMPLLpXpvldzmtCTrV7njTWerEbNijRWMvKAgFjHOZoZE4HDnqaGfXw3wqcn9hCvLSyCSKcCpRc03vKKk2DHaGK6EoIVS5ofMNci/Ba1t8r+w8lnQebaPsnEjJFl6bzVT+MTt7tfiBQu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aspeedtech.com; spf=pass smtp.mailfrom=aspeedtech.com; arc=none smtp.client-ip=211.20.114.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aspeedtech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aspeedtech.com Received: from TWMBX01.aspeed.com (192.168.0.62) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Sun, 15 Jun 2025 11:58:04 +0800 Received: from mail.aspeedtech.com (192.168.10.13) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server id 15.2.1748.10 via Frontend Transport; Sun, 15 Jun 2025 11:58:04 +0800 From: Cool Lee To: , , , , , , , , , Subject: [PATCH 6/8] mmc: sdhci-of-aspeed: Add output timing phase tuning Date: Sun, 15 Jun 2025 11:58:01 +0800 Message-ID: <20250615035803.3752235-7-cool_lee@aspeedtech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250615035803.3752235-1-cool_lee@aspeedtech.com> References: <20250615035803.3752235-1-cool_lee@aspeedtech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enhance auto tuning with input and output calibration. Signed-off-by: Cool Lee --- drivers/mmc/host/sdhci-of-aspeed.c | 48 ++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-aspeed.c b/drivers/mmc/host/sdhci-of= -aspeed.c index 22dde915e51b..92687fc30d1d 100644 --- a/drivers/mmc/host/sdhci-of-aspeed.c +++ b/drivers/mmc/host/sdhci-of-aspeed.c @@ -25,6 +25,7 @@ #define ASPEED_SDC_S1_PHASE_IN GENMASK(25, 21) #define ASPEED_SDC_S0_PHASE_IN GENMASK(20, 16) #define ASPEED_SDC_S0_PHASE_IN_SHIFT 16 +#define ASPEED_SDC_S0_PHASE_OUT_SHIFT 3 #define ASPEED_SDC_S1_PHASE_OUT GENMASK(15, 11) #define ASPEED_SDC_S1_PHASE_IN_EN BIT(10) #define ASPEED_SDC_S1_PHASE_OUT_EN GENMASK(9, 8) @@ -422,7 +423,7 @@ static int aspeed_sdhci_execute_tuning(struct sdhci_hos= t *host, u32 opcode) } =20 window =3D right - left; - dev_info(dev, "tuning window =3D %d\n", window); + dev_dbg(dev, "tuning window[%d][%d~%d] =3D %d\n", edge, left, right, win= dow); =20 if (window > oldwindow) { oldwindow =3D window; @@ -433,7 +434,50 @@ static int aspeed_sdhci_execute_tuning(struct sdhci_ho= st *host, u32 opcode) val =3D (out_phase | enable_mask | (center << ASPEED_SDC_S0_PHASE_IN_SHIF= T)); writel(val, sdc->regs + ASPEED_SDC_PHASE); =20 - dev_info(dev, "tuning result=3D%x\n", val); + dev_dbg(dev, "input tuning result=3D%x\n", val); + + inverted =3D 0; + out_phase =3D val & ~ASPEED_SDC_S0_PHASE_OUT; + in_phase =3D out_phase; + oldwindow =3D 0; + + for (edge =3D 0; edge < 2; edge++) { + if (edge =3D=3D 1) + inverted =3D ASPEED_SDHCI_TAP_PARAM_INVERT_CLK; + + val =3D (in_phase | enable_mask | (inverted << ASPEED_SDC_S0_PHASE_OUT_S= HIFT)); + + /* find the left boundary */ + for (left =3D 0; left < ASPEED_SDHCI_NR_TAPS + 1; left++) { + out_phase =3D val | (left << ASPEED_SDC_S0_PHASE_OUT_SHIFT); + writel(out_phase, sdc->regs + ASPEED_SDC_PHASE); + + if (!mmc_send_tuning(host->mmc, opcode, NULL)) + break; + } + + /* find the right boundary */ + for (right =3D left + 1; right < ASPEED_SDHCI_NR_TAPS + 1; right++) { + out_phase =3D val | (right << ASPEED_SDC_S0_PHASE_OUT_SHIFT); + writel(out_phase, sdc->regs + ASPEED_SDC_PHASE); + + if (mmc_send_tuning(host->mmc, opcode, NULL)) + break; + } + + window =3D right - left; + dev_info(dev, "tuning window[%d][%d~%d] =3D %d\n", edge, left, right, wi= ndow); + + if (window > oldwindow) { + oldwindow =3D window; + center =3D (((right - 1) + left) / 2) | inverted; + } + } + + val =3D (in_phase | enable_mask | (center << ASPEED_SDC_S0_PHASE_OUT_SHIF= T)); + writel(val, sdc->regs + ASPEED_SDC_PHASE); + + dev_dbg(dev, "output tuning result=3D%x\n", val); =20 return mmc_send_tuning(host->mmc, opcode, NULL); } --=20 2.34.1