Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp730193pxm; Thu, 3 Mar 2022 03:33:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtEHs4niwjKIXIXjpkJj+BK5AziWNhmCQaZ5Nyp164SQrIMJLzs3GDNewzStaHNEkGtVdJ X-Received: by 2002:a17:90a:bb8d:b0:1bc:72a9:a07d with SMTP id v13-20020a17090abb8d00b001bc72a9a07dmr4824677pjr.9.1646307210125; Thu, 03 Mar 2022 03:33:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646307210; cv=none; d=google.com; s=arc-20160816; b=lGF7JNyf1D7KVbDaa3niDNSsvTzzHW2G+w/oGGUWcyADf5aBCCbKW2JJq1/sHjwqr3 aLykfjwGyGmKzn85hweYVHszJX8Xu17y6DMBkHqSwTyBf4fPXLcxbX1GVlHM6j1ExbDu y09R5HT7FwZKF154b4GmnVxb48Nrxn0pmLlYtI7CNyTlWzxM6PFEpLTBBsuqxdxd0M8R bq86sVfdXdBM+tHkd8IRD3d315TZH1+k86aC6DRbTX+gO12Titzbzi0ZXHbByWQMuSm7 7ouOxxTq4vUv7Wji5t2qEyzsMKi3BqLuCN6TunC/74cjKpkeBCL7E8uSF8Qk5FmvqzuC VR3w== 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:from:in-reply-to :references:mime-version:dkim-signature; bh=YzVwY3mEdfiRjeh2nt8836txEmK+uEtk2JZC3Nb2yhk=; b=KFKWRz/WdYj4g5agT90blZZUWIfss2ECcBa3xMsH4XXQPZWGNP0K4xx9IZykLv2mDc FZcZf18OhSEsQ77KZCR2rx/Ql838f2kPOZSUsVRtnUKJJV/JH4SogCjhoq1z59esylo/ Oz50YNuwxS2ZixLhW0yzMHPX74amcnYUIPRGeI/y/O2nqsRxenMo5JXC43aHHUdI9LgD xIDJ5siieDmwR4LKPcianFkbKTTQax0PitqTlUuuw1oGy8buqA/w62hFnBr3JRbCFDiz klLGVyjhJddf6zxb5dmxUu8B+gvtj/eY+nns2KAyRMgQDZImdypUR16WDz5dyVCQjCZT 6KZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j9gu4Mu0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l184-20020a6388c1000000b003661623dc0bsi1631224pgd.867.2022.03.03.03.33.15; Thu, 03 Mar 2022 03:33:30 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=j9gu4Mu0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232256AbiCCKWh (ORCPT + 99 others); Thu, 3 Mar 2022 05:22:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232128AbiCCKWf (ORCPT ); Thu, 3 Mar 2022 05:22:35 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7341D488B5 for ; Thu, 3 Mar 2022 02:21:50 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id b9so7572749lfv.7 for ; Thu, 03 Mar 2022 02:21:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YzVwY3mEdfiRjeh2nt8836txEmK+uEtk2JZC3Nb2yhk=; b=j9gu4Mu0aHrDPXhX9fLc18SmXl5WKdNcVj8zUgG/jHfez5HDyr9OyMW5K/I1w4bV0n 3FyDjFem2mdqFd/HELZ7FQCZ16utQ2I5Z0/CDl4ifmZceSJL85dgADz05D3Fm0waPatR gWtWwWZhpWz/BJZM6C8Vk92O4ir6gZk10aNCluzkdRMPkgM9508C/R22kC3AoF585IN4 0HNHImtsgHLkeAiz/Zsq8AzGJolAUFXeP7BQNP8+SKWXE7fF1UQvzGu4To+hAIA/d6GJ DAfx7RMicH8qS89PmQS+1ClQmTMREGz68SNsPB0y1tuMaruAeBQ6AZVQXaEc+KsoeFS0 ab/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YzVwY3mEdfiRjeh2nt8836txEmK+uEtk2JZC3Nb2yhk=; b=WlT6beAyh0e43JwyHOucNT1mettBlyVsrOUnA7H/aZ1deyDQ/WZOT4xtZd34Pnybz/ 97QJLyIs2KbZVEisc47ohls2kk3Bg6hWMyZkjE/rJ8DbxR26KbXnT1SvxcNR9rVlQFHw i7sUfGNoWi9Z58dRtlxNgRI5ZITF03QNQzD1/JZmLBi0aG0MwaZSRKRW5TSH3Ty03Hkb h3gbil3F3rY3OWSHBft9tMKLSDHP6IEP5njJ56yYQr3O28hAvRC6oPGrzxIcVqwJMIBZ zxubUZ5EKVESkDKqF2g/qlNl0L1Ews62lajxlB/nHbkYi9zW32cWgjxb/ROvAfIvBAOp UxGg== X-Gm-Message-State: AOAM532qpXI4he7QXYPAWVc2Z5cX7GCLHOgtdbXVwMpGx/zzGTLD1lce MmZeHKghQ1NBwCYtbzn+SajBGoXq98dM5h+Pp6w6Xw== X-Received: by 2002:a05:6512:260b:b0:445:c54c:4157 with SMTP id bt11-20020a056512260b00b00445c54c4157mr1496331lfb.254.1646302908794; Thu, 03 Mar 2022 02:21:48 -0800 (PST) MIME-Version: 1.0 References: <20220303015151.1711860-1-pgwipeout@gmail.com> In-Reply-To: From: Ulf Hansson Date: Thu, 3 Mar 2022 11:21:12 +0100 Message-ID: Subject: Re: [PATCH] mmc: host: dw-mmc-rockchip: fix handling invalid clock rates To: Peter Geis Cc: Robin Murphy , Jaehoon Chung , Heiko Stuebner , Addy Ke , Doug Anderson , linux-mmc@vger.kernel.org, arm-mail-list , "open list:ARM/Rockchip SoC..." , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Thu, 3 Mar 2022 at 10:49, Peter Geis wrote: > > On Thu, Mar 3, 2022 at 2:53 AM Ulf Hansson wrote: > > > > On Thu, 3 Mar 2022 at 02:52, Peter Geis wrote: > > > > > > The Rockchip ciu clock cannot be set as low as the dw-mmc hardware > > > supports. This leads to a situation during card initialization where the > > > ciu clock is set lower than the clock driver can support. The > > > dw-mmc-rockchip driver spews errors when this happens. > > > For normal operation this only happens a few times during boot, but when > > > cd-broken is enabled (in cases such as the SoQuartz module) this fires > > > multiple times each poll cycle. > > > > > > Fix this by testing the minimum frequency the clock driver can support > > > that is within the mmc specification, then divide that by the internal > > > clock divider. Set the f_min frequency to this value, or if it fails, > > > set f_min to the downstream driver's default. > > > > > > Fixes: f629ba2c04c9 ("mmc: dw_mmc: add support for RK3288") > > > > > > Signed-off-by: Peter Geis > > > --- > > > drivers/mmc/host/dw_mmc-rockchip.c | 31 ++++++++++++++++++++++++++---- > > > 1 file changed, 27 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c > > > index 95d0ec0f5f3a..c198590cd74a 100644 > > > --- a/drivers/mmc/host/dw_mmc-rockchip.c > > > +++ b/drivers/mmc/host/dw_mmc-rockchip.c > > > @@ -15,7 +15,9 @@ > > > #include "dw_mmc.h" > > > #include "dw_mmc-pltfm.h" > > > > > > -#define RK3288_CLKGEN_DIV 2 > > > +#define RK3288_CLKGEN_DIV 2 > > > +#define RK3288_MIN_INIT_FREQ 375000 > > > +#define MMC_MAX_INIT_FREQ 400000 > > > > > > struct dw_mci_rockchip_priv_data { > > > struct clk *drv_clk; > > > @@ -27,6 +29,7 @@ struct dw_mci_rockchip_priv_data { > > > static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios) > > > { > > > struct dw_mci_rockchip_priv_data *priv = host->priv; > > > + struct mmc_host *mmc = mmc_from_priv(host); > > > int ret; > > > unsigned int cclkin; > > > u32 bus_hz; > > > @@ -34,6 +37,10 @@ static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios) > > > if (ios->clock == 0) > > > return; > > > > > > + /* the clock will fail if below the f_min rate */ > > > + if (ios->clock < mmc->f_min) > > > + ios->clock = mmc->f_min; > > > + > > > > You shouldn't need this. The mmc core should manage this already. > > I thought so too, but while setting f_min did reduce the number of > errors, it didn't stop them completely. > Each tick I was getting three failures, it turns out mmc core tries > anyways with 300000, 200000, and 100000. > Clamping it here was necessary to stop these. Ohh, that was certainly a surprise to me. Unless the dw_mmc driver invokes this path on it's own in some odd way, that means the mmc core has a bug that we need to fix. Would you mind taking a stack trace or debug this so we understand in what case the mmc core doesn't respect f_min? It really should. [...] Kind regards Uffe