Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2993943rdb; Tue, 12 Sep 2023 20:41:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiL6/HsIeAQMeT9tDWIXX+4eSv1WsUDclGDvbLNJpTLqxCfJlTmeZCEnN2tOGttFpZNRkv X-Received: by 2002:a17:902:d50b:b0:1c1:fbec:bc32 with SMTP id b11-20020a170902d50b00b001c1fbecbc32mr1665672plg.6.1694576495876; Tue, 12 Sep 2023 20:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694576495; cv=none; d=google.com; s=arc-20160816; b=H5ilk2RZxrvirtr6tejE2gNHCRm/MxlmiaPM/s9XGVRgWJYfd91+AdYId9a3nh0ibf PhDx1fKwDBIDdOjBnzyTv/cmTGmtUUuevBuwnIu3/kYe/jPyb5rGCYyTtJiZIFpJHzYx hkhwnphVjhL7WGLpVk/mkd9GF4YuifL+7hd7/1L50SsrTu7tSUfb5kuWMqLtsexsz0Li wcR3XF/Bewy2Zp5JEl6f8w6XgEFehuMICYrXSWRFFc8nUccsodhQmMWQe/AeNt2VIc14 ww6e2yIMnnuZs0JQrbW2J/NzSEZtsVH+dmT+tCPR7cyJBr68UHrIJ+taxNdrcDb95ecd 4LXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:mime-version :references:in-reply-to:from:dkim-signature; bh=Sf56SkwawGpbC/RXPSnmT5Ux3keGTDqMFdPqD5kK9Z4=; fh=CFfXwBWlpeevCxbArWaZ8E2o1MkiLWbUetXezsnyzSs=; b=MpO6bDlJwC/SVIuDMqBXd4mBViNP7CpHUBC9aIN8Q6EjP/Hj1FBDcrR8NsfahpiESh M64Mmog3uSX+bK2yxNNJEtAGO7QLTeg2MeSo7Oaw/zHLqjXEjHnjmn6KD+Gt3+5E5K0t FEY4+jNPL3JOlUzUOMjBd2oR7YJtPe6FA60EWM9MO47rbR2WBMwxyzF5JUgelmasFgDc n8rW5niMeJT86sFHBLHRMMnL+34MAd5q8smoEDIWPHc8eeGji4sQA4T8sGFy+r2Gu1vB 6dzUcODfDfh9zrflKD4YUy6c5Mba3YeyXvKKVvruWMZw5vKTGDm4ogyZnup4ttGa9IVB ONFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="O0qtfvA/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id n17-20020a170902d2d100b001bbc855a8fcsi9572311plc.488.2023.09.12.20.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 20:41:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="O0qtfvA/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0FF0C84EE556; Tue, 12 Sep 2023 06:20:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235511AbjILNUS (ORCPT + 99 others); Tue, 12 Sep 2023 09:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235501AbjILNUQ (ORCPT ); Tue, 12 Sep 2023 09:20:16 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FB9210CE for ; Tue, 12 Sep 2023 06:20:11 -0700 (PDT) Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id E01443F196 for ; Tue, 12 Sep 2023 13:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1694524809; bh=Sf56SkwawGpbC/RXPSnmT5Ux3keGTDqMFdPqD5kK9Z4=; h=From:In-Reply-To:References:Mime-Version:Date:Message-ID:Subject: To:Cc:Content-Type; b=O0qtfvA/Dr9x7CWNrHDBntzk5TKybBarsUQKGf4ap/xA3xGF4OWpqxi5P7rV67YDt B4belnNHzsoNrzuU/eogwYa5jcrVQVd9exFkbh/EKJ5ctE3VRQBiLD5uPPEEGXQ/Mo cCe+5pcq2L9iveev0fk3WV+NISWCjA6J4Y8bUJOeqprLYi4aRa8GeODc7UPwhurP7Y +CNYnJXIckHlD8ZaV8J1QntZfuNwrKyy+7h9y68ahDR8aIzN1PepIDxj7l9UlZkeEz GWch2L1gRTi9anCKC1Jpg8W2obOqYS7FsfKRgzMutaq+fOJ3rzvMmdKMAmyfqhS/yx 9J3PJ2EcLpsBQ== Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3aa142796a5so7016246b6e.0 for ; Tue, 12 Sep 2023 06:20:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694524809; x=1695129609; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Sf56SkwawGpbC/RXPSnmT5Ux3keGTDqMFdPqD5kK9Z4=; b=Rv+mqNE1aRcyM0WgutYCqaSc/LsRpd9v68kQ9iOyNYdvc2PO8/b4ZqimQ8lyaoeOS0 K5Fz8en+Oe9NpY5Koua+4j/E7MqjC1Z6EH35pDfpSGOTh9JlvplIEL0nd2IFClN/QiMn 6P/u3Rd7IqaoLrpQrYijuNqS+yNStLDDGkWyN1FIeHtBQ7p5B5gPXAwTwuc5EXVRNCcK vV9YsRTQRjME9T6sqBg+jJiL6r5DfSaPagsn2L5fOa6vfQmqV3zgM3uj+5lWt1SABjYS Iv3n1e8pZGPhnU97lH8YjeTB50jeROfN9qtwGhoBLdaUw3P/snjWzkUvnQJunJJgTx57 VdfA== X-Gm-Message-State: AOJu0YziqQri8tudl8ljYD33+kJEbO/HeO0sFOQdo3JyaJ1k0YcCOsQR HfEKhQtmkcYnUxwiEQ226fk/MUs2E1vw0JSF+hEpG0bepdL6po3aq3zDiVGJ2uI4GADiszEG3gQ TuDr6dvXhoRusLSTf6/7KILrlM1NjOTtQCP6ri7Gugfgx2cpvmv5qBx4cDg== X-Received: by 2002:a54:4101:0:b0:3a4:1f0f:d108 with SMTP id l1-20020a544101000000b003a41f0fd108mr14393063oic.46.1694524808734; Tue, 12 Sep 2023 06:20:08 -0700 (PDT) X-Received: by 2002:a54:4101:0:b0:3a4:1f0f:d108 with SMTP id l1-20020a544101000000b003a41f0fd108mr14393037oic.46.1694524808389; Tue, 12 Sep 2023 06:20:08 -0700 (PDT) Received: from 348282803490 named unknown by gmailapi.google.com with HTTPREST; Tue, 12 Sep 2023 06:20:07 -0700 From: Emil Renner Berthing In-Reply-To: <20230912081402.51477-6-william.qiu@starfivetech.com> References: <20230912081402.51477-1-william.qiu@starfivetech.com> <20230912081402.51477-6-william.qiu@starfivetech.com> Mime-Version: 1.0 Date: Tue, 12 Sep 2023 06:20:07 -0700 Message-ID: Subject: Re: [PATCH v2 2/3] mmc: starfive: Change tuning implementation To: William Qiu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mmc@vger.kernel.org Cc: Emil Renner Berthing , Rob Herring , Jaehoon Chung , Ulf Hansson , Krzysztof Kozlowski , Conor Dooley , Paul Walmsley , Palmer Dabbelt , Albert Ou Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 06:20:19 -0700 (PDT) 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 | 137 +++++++++-------------------- > 1 file changed, 40 insertions(+), 97 deletions(-) > > diff --git a/drivers/mmc/host/dw_mmc-starfive.c b/drivers/mmc/host/dw_mmc-starfive.c > index fd05a648a8bb..ad8f39c62fed 100644 > --- a/drivers/mmc/host/dw_mmc-starfive.c > +++ b/drivers/mmc/host/dw_mmc-starfive.c > @@ -5,6 +5,7 @@ > * Copyright (c) 2022 StarFive Technology Co., Ltd. > */ > > +#include > #include > #include > #include > @@ -20,13 +21,7 @@ > #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; > -}; > +#define STARFIVE_SMPL_PHASE GENMASK(20, 16) > > static void dw_mci_starfive_set_ios(struct dw_mci *host, struct mmc_ios *ios) > { > @@ -44,117 +39,65 @@ static void dw_mci_starfive_set_ios(struct dw_mci *host, struct mmc_ios *ios) > } > } > > +static void dw_mci_starfive_set_sample_phase(struct dw_mci *host, u32 smpl_phase) > +{ > + /* change driver phase and sample phase */ > + u32 reg_value = mci_readl(host, UHS_REG_EXT); > + > + /* In UHS_REG_EXT, only 5 bits valid in DRV_PHASE and SMPL_PHASE */ > + reg_value &= ~STARFIVE_SMPL_PHASE; > + reg_value |= FIELD_PREP(STARFIVE_SMPL_PHASE, smpl_phase); > + mci_writel(host, UHS_REG_EXT, reg_value); > + > + /* We should delay 1ms wait for timing setting finished. */ > + mdelay(1); > +} > + > 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 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; > + int smpl_phase, smpl_raise = -1, smpl_fall = -1; > + int ret; > + > + for (smpl_phase = 0; smpl_phase < grade; smpl_phase++) { > + dw_mci_starfive_set_sample_phase(host, smpl_phase); > mci_writel(host, RINTSTS, ALL_INT_CLR); > > - err = mmc_send_tuning(slot->mmc, opcode, NULL); > - if (!err) > - found = 1; > + ret = mmc_send_tuning(slot->mmc, opcode, NULL); > > - if (i > 0) { > - if (err && !prev_err) > - fall_point = i - 1; > - if (!err && prev_err) > - rise_point = i; > + if (!ret && smpl_raise < 0) { > + smpl_raise = smpl_phase; > + } else if (ret && smpl_raise >= 0) { > + smpl_fall = smpl_phase - 1; > + break; > } > - > - 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; > - } > - > - 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 (smpl_phase >= grade && smpl_raise >= 0) > + smpl_fall = grade - 1; If you switch the order of the two if's above and below you won't need the smpl_raise >= 0 clause here. With that cleaned up: Reviewed-by: Emil Renner Berthing > > - dev_info(host->dev, "Found valid delay chain! use it [delay=%d]\n", i); > - } else { > + if (smpl_raise < 0) { > + smpl_phase = 0; > dev_err(host->dev, "No valid delay chain! use default\n"); > - err = -EINVAL; > + ret = -EINVAL; > + goto out; > } > > - mci_writel(host, RINTSTS, ALL_INT_CLR); > - return err; > -} > - > -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; > + smpl_phase = (smpl_raise + smpl_fall) / 2; > + dev_dbg(host->dev, "Found valid delay chain! use it [delay=%d]\n", smpl_phase); > + ret = 0; > > - 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; > +out: > + dw_mci_starfive_set_sample_phase(host, smpl_phase); > + mci_writel(host, RINTSTS, ALL_INT_CLR); > + return ret; > } > > 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