Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1083079rwb; Wed, 7 Dec 2022 08:25:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf4iuGB8eTulQBDZ+NondLsMOmHcFCXcj3tAHkYKAC+5d2Pee+vFlULHOhcIZ3KrCV8TcPKL X-Received: by 2002:a17:902:e415:b0:189:e924:e27d with SMTP id m21-20020a170902e41500b00189e924e27dmr9206263ple.167.1670430315734; Wed, 07 Dec 2022 08:25:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670430315; cv=none; d=google.com; s=arc-20160816; b=eNX7QTLI6tO16T5unFvPUOndtnwnzWQuS8FehpwmkiMsWg1ZLMJ81pdynYEy6S6p2G rqH/gJsGTtc9GTxmQ/Q2d8n1VyJX0C6oBY8Cx0NR8W2Mg1zFPaktSE63ZF7QfmIIDarM 1DN03oFtduuToIkL35/z9nl+i6KQOB51NLmO87doUSx242lRHf1pVQjaxPlsO9AnZ8ik r2+YxaX5r8GxcLX+mtF5j/1m346Scz3PINxtBlCSKGONxNrYMzgXa2ZaiNrvTC+OrrK1 AfaDaUPDR0v/kroEV6A5iO2DR8ZpSGQrnbFK4/hb64Em9NhiuJt340uYSp60VM8HyI0+ 6Qaw== 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=UfOHvK7ecYIuUe0s4A5xd+Shfnx26W2C73pfnXWOFPw=; b=G6A1woeGK+lxR9YQOOSUhU2kmMWoaMQSv5WwnGeANPLxW7MYHOpNzETj3azaPICGQw JLp0PhBIZjl8O0bBdPoraOhHGPrAL0lKD1L8Kf1K5eMfa9SyrmesccR/eh8aQNviUOjW /MnltYYS4Y2rYwgI1onVBoVWu0XtqLdL443+eLynV6rbNivTKKktoBBPDUjx3v9e+wPy c2+5t6mCyFIXk3MveEqdWpmCal8GMAXrSlsme2SCzoFqnEr4MK33q/8PvpZmnDTN60Vj QqWlq7H5kDBLlToA+YiA2JWnl+eLqntS+rco9XN9P7TtWibn6+R0FjKt/zDZ5AOrifd/ Pz5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iT5h2rMg; 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 o14-20020a63f14e000000b004701dd79b20si21417909pgk.132.2022.12.07.08.25.05; Wed, 07 Dec 2022 08:25:15 -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=iT5h2rMg; 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 S229643AbiLGPqO (ORCPT + 76 others); Wed, 7 Dec 2022 10:46:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiLGPqM (ORCPT ); Wed, 7 Dec 2022 10:46:12 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E01C26ACB for ; Wed, 7 Dec 2022 07:46:11 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id t18so7454771pfq.13 for ; Wed, 07 Dec 2022 07:46:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=UfOHvK7ecYIuUe0s4A5xd+Shfnx26W2C73pfnXWOFPw=; b=iT5h2rMguX+IY5q8yLBNZmN/99vOp91cbgceJR1iIMkvim2gs5WBUbHDUfjpuyh0H+ uzXwjjS7uqH45oKea6deOwTqj2zlfFWOhsQTwYzT8WxQ5cjhPChGJQd8t0UwQN66xUN7 QV8nuyqydi5raOny0PZCpMlfZ9XQE2IwcZbnWzNskDHsPkKwnTPS7Me3nnP12TY9m6NO dbGAJGkjQzuRtXz0Y0XZEaim3vlqvfbkbQRK+SzWOZIrqR0SDFTGlByFU4ILTSI0DFwJ LGPPpy3VjocWPnrf7+O1+gA2pUvdbEP0tSuWlI3kBXgvvMEYfcTSO1aYrXgmfBI+ra3q nAMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UfOHvK7ecYIuUe0s4A5xd+Shfnx26W2C73pfnXWOFPw=; b=jeFcGUWFOJW6Y2IscdX7HB5Mqcg3sABy2F6CnKnG5RWGG6zOgOi+x5lLMEw+DbtWqa qc75WGnb2C1r0Ko+9zf6sQvqO9WOSOKb/Z3m606s+S8FC3l4RlYDAAyEAtVZv2/PqFr6 h9T1iyU6XQ/R9Gj416PZLkKBYTzc7OttyTp4sCN84ggBFAhtwykrADQUMh6f14c2iAUR 4y7MX/nHPHoNb8H5V60sl2l7DOOufe7f4ng/s/Rf8S2tWkzE4vQqO02XfwMGbstvReFb GtC49kbBYwOWS8yViGYJO6a+ggef+6ZT02OZUv49+AfmyI61fQxcOKMg5lHCyyqlnVgg Tg/g== X-Gm-Message-State: ANoB5plEsF7BNrSrnpD5gNB5ztPBfljS1+0uPHqhs2WQW+ZkjbtOaqPW 85atyFEZVZDQ9V6XxrhguVvst4n2eDVPZSVq3599TQ== X-Received: by 2002:aa7:951d:0:b0:577:3e5e:7a4 with SMTP id b29-20020aa7951d000000b005773e5e07a4mr8405149pfp.57.1670427970858; Wed, 07 Dec 2022 07:46:10 -0800 (PST) MIME-Version: 1.0 References: <1664960824-20951-1-git-send-email-quic_akhilpo@quicinc.com> <20221005143618.v7.3.I162c4be55f230cd439f0643f1624527bdc8a9831@changeid> In-Reply-To: <20221005143618.v7.3.I162c4be55f230cd439f0643f1624527bdc8a9831@changeid> From: Ulf Hansson Date: Wed, 7 Dec 2022 16:45:34 +0100 Message-ID: Subject: Re: [PATCH v7 3/6] clk: qcom: gdsc: Add a reset op to poll gdsc collapse To: Akhil P Oommen Cc: freedreno , dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Bjorn Andersson , Stephen Boyd , Dmitry Baryshkov , Philipp Zabel , Douglas Anderson , krzysztof.kozlowski@linaro.org, Andy Gross , Konrad Dybcio , Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org 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 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 Wed, 5 Oct 2022 at 11:08, Akhil P Oommen wrote: > > Add a reset op compatible function to poll for gdsc collapse. This is > required because: > 1. We don't wait for it to turn OFF at hardware for VOTABLE GDSCs. > 2. There is no way for client drivers (eg. gpu driver) to do > put-with-wait for these gdscs which is required in some scenarios > (eg. GPU recovery). What puzzles me a bit, who is the typical consumer of the reset. I looked at patch4 and tried to figure it out, but let's discuss that in that thread instead. Some more comments, see below. > > Signed-off-by: Akhil P Oommen > Reviewed-by: Dmitry Baryshkov > --- > > Changes in v7: > - Update commit message (Bjorn) > > Changes in v2: > - Minor update to function prototype > > drivers/clk/qcom/gdsc.c | 23 +++++++++++++++++++---- > drivers/clk/qcom/gdsc.h | 7 +++++++ > 2 files changed, 26 insertions(+), 4 deletions(-) > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c > index 7cf5e13..ccef742 100644 > --- a/drivers/clk/qcom/gdsc.c > +++ b/drivers/clk/qcom/gdsc.c > @@ -17,6 +17,7 @@ > #include > #include > #include "gdsc.h" > +#include "reset.h" > > #define PWR_ON_MASK BIT(31) > #define EN_REST_WAIT_MASK GENMASK_ULL(23, 20) > @@ -116,7 +117,8 @@ static int gdsc_hwctrl(struct gdsc *sc, bool en) > return regmap_update_bits(sc->regmap, sc->gdscr, HW_CONTROL_MASK, val); > } > > -static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status) > +static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status, > + s64 timeout_us, unsigned int interval_ms) > { > ktime_t start; > > @@ -124,7 +126,9 @@ static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status) > do { > if (gdsc_check_status(sc, status)) > return 0; > - } while (ktime_us_delta(ktime_get(), start) < TIMEOUT_US); > + if (interval_ms) > + msleep(interval_ms); > + } while (ktime_us_delta(ktime_get(), start) < timeout_us); Rather than continue to open code this polling loop, would it not make sense to convert the code into using readx_poll_timeout() (or some of its friends). Down the road, this leads to that the msleep() above should become usleep_range() instead, which seems more correct to me. > > if (gdsc_check_status(sc, status)) > return 0; > @@ -189,7 +193,7 @@ static int gdsc_toggle_logic(struct gdsc *sc, enum gdsc_status status) > udelay(1); > } > > - ret = gdsc_poll_status(sc, status); > + ret = gdsc_poll_status(sc, status, TIMEOUT_US, 0); > WARN(ret, "%s status stuck at 'o%s'", sc->pd.name, status ? "ff" : "n"); > > if (!ret && status == GDSC_OFF && sc->rsupply) { > @@ -360,7 +364,7 @@ static int _gdsc_disable(struct gdsc *sc) > */ > udelay(1); > > - ret = gdsc_poll_status(sc, GDSC_ON); > + ret = gdsc_poll_status(sc, GDSC_ON, TIMEOUT_US, 0); > if (ret) > return ret; > } > @@ -608,3 +612,14 @@ int gdsc_gx_do_nothing_enable(struct generic_pm_domain *domain) > return 0; > } > EXPORT_SYMBOL_GPL(gdsc_gx_do_nothing_enable); > + > +int gdsc_wait_for_collapse(void *priv) > +{ > + struct gdsc *sc = priv; > + int ret; > + > + ret = gdsc_poll_status(sc, GDSC_OFF, 500000, 5); > + WARN(ret, "%s status stuck at 'on'", sc->pd.name); > + return ret; > +} > +EXPORT_SYMBOL_GPL(gdsc_wait_for_collapse); > diff --git a/drivers/clk/qcom/gdsc.h b/drivers/clk/qcom/gdsc.h > index 981a12c..5395f69 100644 > --- a/drivers/clk/qcom/gdsc.h > +++ b/drivers/clk/qcom/gdsc.h > @@ -12,6 +12,7 @@ > struct regmap; > struct regulator; > struct reset_controller_dev; > +struct qcom_reset_map; > > /** > * struct gdsc - Globally Distributed Switch Controller > @@ -88,6 +89,7 @@ int gdsc_register(struct gdsc_desc *desc, struct reset_controller_dev *, > struct regmap *); > void gdsc_unregister(struct gdsc_desc *desc); > int gdsc_gx_do_nothing_enable(struct generic_pm_domain *domain); > +int gdsc_wait_for_collapse(void *priv); > #else > static inline int gdsc_register(struct gdsc_desc *desc, > struct reset_controller_dev *rcdev, > @@ -97,5 +99,10 @@ static inline int gdsc_register(struct gdsc_desc *desc, > } > > static inline void gdsc_unregister(struct gdsc_desc *desc) {}; > + > +static int gdsc_wait_for_collapse(void *priv) > +{ > + return -ENOSYS; > +} > #endif /* CONFIG_QCOM_GDSC */ > #endif /* __QCOM_GDSC_H__ */ Kind regards Uffe