Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp636911rdb; Thu, 31 Aug 2023 22:37:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlH0UBOm24DxKSUR9i/h9W3bLTBLcHqv1PFSGDvVsaBMItm5E5dp+vlZ6lWN2oQYCP42Ef X-Received: by 2002:a9d:621a:0:b0:6b9:c4b1:7a86 with SMTP id g26-20020a9d621a000000b006b9c4b17a86mr1562673otj.3.1693546677378; Thu, 31 Aug 2023 22:37:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693546677; cv=none; d=google.com; s=arc-20160816; b=GAuCMV7rqrjTRPfm4SPX8/Q8pL57S+CHwdiGkWsSbscBMDq850K3YUypBrGLHD6xUM x+sg7hclT27OX3HwLsH7AiNluiHuXYR1oSSHiOdd177Ks5pEVP+8PuarQkQJOlvH+Qhp bfk91q+ympVW/7rV6be5dUGuDa5E7lf6Bmx2ZLkX6bQGvtwltaJ1e3cq94rtu3VYQagf cWtFOdMv1YRw6jUsNl6K1LhBHSgTQOUPsvMqiZIHndePzR+I4MB/fXFCBWHAZd5YAgKj 6ZTN0Oj9DphZHunzmcSsTZJ3vwh7aDHWuQ3oFcGkrhyvEWKOyMqAVy3UlmlrsWiRTbBR noGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=4k22SRoHZGD+2p3NocS2qnAVPQhucv00xEo4RPTgLWM=; fh=sg912lgnEohcL0JUMzfWGx0t9YAJPMA7HYUUJgLnAoc=; b=ArCE1fJ3NHOzRtLmNkzMFLb0jQL4CDpWTVWvfPdvHHTRmKdZV2cwJzgQV/jbt5V9Ah RlZte38w6v2krRBTsCYNAsMmAioETNcH9qpukTAw35E1jFfbMXZUwmpj53rv3LV14f1M DYBswWABNpX241+hQxkdQ3h2wboSOUgI5RDUtrL8MV3sVudJ8lToJUOfwsTzgsEFYXMU 9AWm7FG5O0ppZj4gp58ZgzVJNR5tQ5YA0PV5Q2DhAk/RQil6HPtZ+3BrJoExw1oN0Pg1 cz8EBBfDECCNj7Ncjgd7I1KG+aNmoCZT4PIUcai3sF+Ah49SFiCsPmV3CtgsK8+jn5Fq w87A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a63724f000000b0056601c94983si2409580pgn.25.2023.08.31.22.37.43; Thu, 31 Aug 2023 22:37:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344484AbjIACk4 (ORCPT + 99 others); Thu, 31 Aug 2023 22:40:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234785AbjIACkz (ORCPT ); Thu, 31 Aug 2023 22:40:55 -0400 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E626E72; Thu, 31 Aug 2023 19:40:51 -0700 (PDT) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id 7F82C80C4; Fri, 1 Sep 2023 10:40:43 +0800 (CST) Received: from EXMBX168.cuchost.com (172.16.6.78) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 1 Sep 2023 10:40:44 +0800 Received: from [192.168.120.76] (171.223.208.138) by EXMBX168.cuchost.com (172.16.6.78) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 1 Sep 2023 10:40:42 +0800 Message-ID: Date: Fri, 1 Sep 2023 10:40:41 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH v1 2/3] mmc: starfive: Change tuning implementation Content-Language: en-US To: Emil Renner Berthing CC: , , , , "Emil Renner Berthing" , Rob Herring , Jaehoon Chung , Ulf Hansson , "Krzysztof Kozlowski" , Conor Dooley , Paul Walmsley , "Palmer Dabbelt" , Albert Ou References: <20230830031846.127957-1-william.qiu@starfivetech.com> <20230830031846.127957-3-william.qiu@starfivetech.com> From: William Qiu In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [171.223.208.138] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) To EXMBX168.cuchost.com (172.16.6.78) X-YovoleRuleAgent: yovoleflag X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/8/30 18:28, Emil Renner Berthing wrote: > On Wed, 30 Aug 2023 at 05:21, William Qiu wrote: >> >> Before, we used syscon to achieve tuning, but the actual measurement >> showed little effect, so the tuning implementation was modified here, >> and it was realized by reading and writing the UHS_REG_EXT register. >> >> Signed-off-by: William Qiu >> --- >> drivers/mmc/host/dw_mmc-starfive.c | 131 ++++++++--------------------- >> 1 file changed, 37 insertions(+), 94 deletions(-) >> >> diff --git a/drivers/mmc/host/dw_mmc-starfive.c b/drivers/mmc/host/dw_mmc-starfive.c >> index fd05a648a8bb..593c995e49f5 100644 >> --- a/drivers/mmc/host/dw_mmc-starfive.c >> +++ b/drivers/mmc/host/dw_mmc-starfive.c >> @@ -20,14 +20,6 @@ >> #define ALL_INT_CLR 0x1ffff >> #define MAX_DELAY_CHAIN 32 >> >> -struct starfive_priv { >> - struct device *dev; >> - struct regmap *reg_syscon; >> - u32 syscon_offset; >> - u32 syscon_shift; >> - u32 syscon_mask; >> -}; >> - >> static void dw_mci_starfive_set_ios(struct dw_mci *host, struct mmc_ios *ios) >> { >> int ret; >> @@ -44,117 +36,68 @@ static void dw_mci_starfive_set_ios(struct dw_mci *host, struct mmc_ios *ios) >> } >> } >> >> +static void dw_mci_starfive_hs_set_bits(struct dw_mci *host, u32 smpl_phase) > > "set bits" is very generic. Maybe dw_mci_starfive_set_sample_phase() > or something more descriptive. > Will update. >> +{ >> + /* change driver phase and sample phase */ >> + u32 mask = 0x1f; >> + u32 reg_value; >> + >> + reg_value = mci_readl(host, UHS_REG_EXT); >> + >> + /* In UHS_REG_EXT, only 5 bits valid in DRV_PHASE and SMPL_PHASE */ >> + reg_value &= ~(mask << 16); >> + reg_value |= (smpl_phase << 16); >> + mci_writel(host, UHS_REG_EXT, reg_value); >> + >> + /* We should delay 1ms wait for timing setting finished. */ >> + mdelay(1); >> +} > > This implementation could use some cleanup. Eg. why do we need the > mask variable? > How about something like this: > > #define STARFIVE_SMPL_PHASE GENMASK(20, 16) > > u32 reg_value = mci_read(host, UHS_REG_EXT); > reg_value &= ~STARFIVE_SMPL_PHASE; > reg_value |= FIELD_PREP(STARFIVE_SMPL_PHASE, smpl_phase); > mci_writel(host, UHS_REG_EXT, reg_value); > ... > I'll try it. >> static int dw_mci_starfive_execute_tuning(struct dw_mci_slot *slot, >> u32 opcode) >> { >> static const int grade = MAX_DELAY_CHAIN; >> struct dw_mci *host = slot->host; >> - struct starfive_priv *priv = host->priv; >> - int rise_point = -1, fall_point = -1; >> - int err, prev_err = 0; >> + int err = -1; > > This variable is always set later so doesn't need initialization and > is better called 'ret' as it's the return value of the function, and > not necessarily an error. Will update. > >> + int smpl_phase, smpl_raise = -1, smpl_fall = -1; >> int i; >> - bool found = 0; >> - u32 regval; >> - >> - /* >> - * Use grade as the max delay chain, and use the rise_point and >> - * fall_point to ensure the best sampling point of a data input >> - * signals. >> - */ >> + >> for (i = 0; i < grade; i++) { >> - regval = i << priv->syscon_shift; >> - err = regmap_update_bits(priv->reg_syscon, priv->syscon_offset, >> - priv->syscon_mask, regval); >> - if (err) >> - return err; >> + smpl_phase = i; > > This can now be written > > for (sampl_phase = 0; sampl_phase < grade; sampl_phase++) > Will update. >> + dw_mci_starfive_hs_set_bits(host, smpl_phase); >> mci_writel(host, RINTSTS, ALL_INT_CLR); >> >> err = mmc_send_tuning(slot->mmc, opcode, NULL); >> - if (!err) >> - found = 1; >> - >> - if (i > 0) { >> - if (err && !prev_err) >> - fall_point = i - 1; >> - if (!err && prev_err) >> - rise_point = i; >> - } >> >> - if (rise_point != -1 && fall_point != -1) >> - goto tuning_out; >> - >> - prev_err = err; >> - err = 0; >> - } >> - >> -tuning_out: >> - if (found) { >> - if (rise_point == -1) >> - rise_point = 0; >> - if (fall_point == -1) >> - fall_point = grade - 1; >> - if (fall_point < rise_point) { >> - if ((rise_point + fall_point) > >> - (grade - 1)) >> - i = fall_point / 2; >> - else >> - i = (rise_point + grade - 1) / 2; >> - } else { >> - i = (rise_point + fall_point) / 2; >> + if (!err && smpl_raise < 0) { >> + smpl_raise = i; >> + } else if (err && smpl_raise >= 0) { >> + smpl_fall = i - 1; >> + break; >> } >> + } >> >> - regval = i << priv->syscon_shift; >> - err = regmap_update_bits(priv->reg_syscon, priv->syscon_offset, >> - priv->syscon_mask, regval); >> - if (err) >> - return err; >> - mci_writel(host, RINTSTS, ALL_INT_CLR); >> + if (i >= grade && smpl_raise >= 0) >> + smpl_fall = grade - 1; >> >> - dev_info(host->dev, "Found valid delay chain! use it [delay=%d]\n", i); >> - } else { >> + if (smpl_raise < 0) { >> dev_err(host->dev, "No valid delay chain! use default\n"); >> + dw_mci_starfive_hs_set_bits(host, 0); >> err = -EINVAL; >> + } else { >> + smpl_phase = (smpl_raise + smpl_fall) / 2; >> + dw_mci_starfive_hs_set_bits(host, smpl_phase); >> + dev_dbg(host->dev, "Found valid delay chain! use it [delay=%d]\n", smpl_phase); >> + err = 0; >> } > > Maybe something like: > > if (smpl_raise < 0) { > smpl_phase = 0; > dev_err(host->dev, "No valid delay chain, using default\n"); > ret = -EINVAL; > goto out; > } > > smpl_phase = (smpl_raise + smpl_fall) / 2; > dev_dbg(...); > ret = 0; > > out: > dw_mci_starfive_hs_set_bits(host, smpl_phase); > mci_writel(host, RINTSTS, ALL_INT_CLR); > return ret; >> } >> I'll try it. Thanks for taking time to review this patch series and giving so much helpful suggestions. Best regards, William >> -static int dw_mci_starfive_parse_dt(struct dw_mci *host) >> -{ >> - struct of_phandle_args args; >> - struct starfive_priv *priv; >> - int ret; >> - >> - priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); >> - if (!priv) >> - return -ENOMEM; >> - >> - ret = of_parse_phandle_with_fixed_args(host->dev->of_node, >> - "starfive,sysreg", 3, 0, &args); >> - if (ret) { >> - dev_err(host->dev, "Failed to parse starfive,sysreg\n"); >> - return -EINVAL; >> - } >> - >> - priv->reg_syscon = syscon_node_to_regmap(args.np); >> - of_node_put(args.np); >> - if (IS_ERR(priv->reg_syscon)) >> - return PTR_ERR(priv->reg_syscon); >> - >> - priv->syscon_offset = args.args[0]; >> - priv->syscon_shift = args.args[1]; >> - priv->syscon_mask = args.args[2]; >> - >> - host->priv = priv; >> - >> - return 0; >> -} >> - >> static const struct dw_mci_drv_data starfive_data = { >> .common_caps = MMC_CAP_CMD23, >> .set_ios = dw_mci_starfive_set_ios, >> - .parse_dt = dw_mci_starfive_parse_dt, >> .execute_tuning = dw_mci_starfive_execute_tuning, >> }; >> >> -- >> 2.34.1 >> >> >> _______________________________________________ >> linux-riscv mailing list >> linux-riscv@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-riscv