Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp61903pxv; Wed, 21 Jul 2021 15:44:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbDRNEd+QkeAgcRey+dYtz4iu76xjcH44L4HRwk5vAPpEpQ3hhXZAKJJfMkg0QLs983vbq X-Received: by 2002:a05:6638:270c:: with SMTP id m12mr33019635jav.5.1626907459978; Wed, 21 Jul 2021 15:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626907459; cv=none; d=google.com; s=arc-20160816; b=PnftNQ+wrwqnRH1Yc3/hdFtCzHZqIv4u/V1nLH+AbEo0dZcAhglopQkJvNlvwPP281 xP2BywBIIP2C1GVTJ68dFvkljnG9FZnvN4obF7IeN4b79BIQuphMe8fKXIHIf1VthQ8v 6Rb6Beywj6epScCbtqx05aGxmoL3CkQ8XTLjOL1xaHBN2xwxYT9yVran5bh85NEbuyqA sojlL2NfS/nSVTQy5UTH2A05+l5U/kqq3tHX9iZUvtP5gxpsfduHQaV86aG824fbEPEz wGJdG4fRoXhqrXBPbkKXdaF2Ys53Zd8dt2xBXwhIAZvbib3dCbayDpwc30kxYM9xZt1+ OPtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=w+LgJYfusI5YMGYPMF7cuC+Cq9HtcH15BzfhaRWAMPw=; b=Gy9furms2+nqEBgx/KYk4KW4rNbU/nR4Ijm7D9BURfciCSXamroz8Cj9Nj8JKJ9reB wXFBSr243zplW1OtjD/pE6JEG/AzMOR9lvCjDS+lfiMDjvg6aJ4K59Zmy79KxVYWoTC4 XH9C5IyRdfOvwLGnG8EDfdYnhTjO/3M9ssP/zr6uSgFo34gDS112GP4iASGOqfZv8IQD CzC5aKy62cImEkUu6yeEdl4hfa21I1t/ENgi1VKfuZMPTuM/SuJbK0FFVJzkqOK9CgXc y4ZTJ9/Vf4bqvO/sjCcP4/LHqhlAd79gaUr5pqsdIEZiFshThxp3EbLg0mohBOs1mYGr 4O9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fsUKMEBh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q41si26185585jav.74.2021.07.21.15.44.07; Wed, 21 Jul 2021 15:44:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fsUKMEBh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230126AbhGUWCE (ORCPT + 99 others); Wed, 21 Jul 2021 18:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbhGUWCD (ORCPT ); Wed, 21 Jul 2021 18:02:03 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7AC1C061757 for ; Wed, 21 Jul 2021 15:42:39 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id t6so4654905oic.0 for ; Wed, 21 Jul 2021 15:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=w+LgJYfusI5YMGYPMF7cuC+Cq9HtcH15BzfhaRWAMPw=; b=fsUKMEBheNnp9SKgGqK4T9dpmFOcdhpECJI7i+Xu9IOVLc38AT8UGMOHwsrsniOj6/ 31EN3k9VrUWwibSlt6hGI/vpAhB4TcHE74KonoGmExtcYqFF/eT3K5b1E5OQ94yjqaVd J28MNjwsWZQnPQMlhKTQ12eRUNfqiBMUHr+ryacLQ2BycjYZXhWs4vSX3muLQYUs9bbo IQG+6FR7UIsR5gS3P8JXAQ9Ai5DAK+TpyoOmoXkn/VdEugR8TSLqNPezTra4SWlXeIlf +9auSoMbKspsio3Isf2aKwlE9pAmt8uZrnZ3/ObBJpj1UOihEwqG1EcFickrVwpQzLDk 0mLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=w+LgJYfusI5YMGYPMF7cuC+Cq9HtcH15BzfhaRWAMPw=; b=hu2aCVxP2hyUEM6pEV61k2s5yKOlJsK5RWnClGEpVjBsYHCN0ytvn2d9o0cstbmw7H ZmD8upqasDORuQYLBSRB/WygQDfE+ZZSaeyeszjyBMiX0zW32vc+es4XBWVoAf5byXOx Gvcah14mvo6GWQHe5ABKH3HZA4KFnzUt/aBjrzXlQaSyeH1ElYhPDPOP8BoQnnN/RREm lkXI0uUZymqHfLypeJmSobmdySQ1LYSzAWGTexzeJQ4EQ50oQ7Yu4WGq2aQDTjVjZ4df CLuwRjKb2+poqMH75XPL+hLI9ripImWfPGY7k8fp99j2+wpkufGlcqtNxlxSOzRbTqlq dtmA== X-Gm-Message-State: AOAM530ug/TnGlVnHGLVks0sJVJUdlEndnHebynwxnopDjCdRcS7LhU7 Z1v+xaH4tJfRlED8mPYqEt+mmg== X-Received: by 2002:a05:6808:8e5:: with SMTP id d5mr17741046oic.51.1626907359037; Wed, 21 Jul 2021 15:42:39 -0700 (PDT) Received: from localhost.localdomain (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id a193sm3870712oob.45.2021.07.21.15.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:42:38 -0700 (PDT) From: Bjorn Andersson To: Andy Gross , Bjorn Andersson , Michael Turquette , Stephen Boyd , Vinod Koul , Mike Tipton , Taniya Das Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2] clk: qcom: gdsc: Ensure regulator init state matches GDSC state Date: Wed, 21 Jul 2021 15:40:56 -0700 Message-Id: <20210721224056.3035016-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As GDSCs are registered and found to be already enabled gdsc_init() ensures that 1) the kernel state matches the hardware state, and 2) votable GDSCs are properly enabled from this master as well. But as the (optional) supply regulator is enabled deep into gdsc_toggle_logic(), which is only executed for votable GDSCs the kernel's state of the regulator might not match the hardware. The regulator might be automatically turned off if no other users are present or the next call to gdsc_disable() would cause an unbalanced regulator_disable(). But as the votable case deals with an already enabled GDSC, most of gdsc_enable() and gdsc_toggle_logic() can be skipped. Reducing it to just clearing the SW_COLLAPSE_MASK and enabling hardware control allow us to simply call regulator_enable() in both cases. The enablement of hardware control seems to be an independent property from the GDSC being enabled, so this is moved outside that conditional segment. Lastly, as the propagation of ALWAY_ON to GENPD_FLAG_ALWAYS_ON needs to happen regardless of the initial state this is grouped together with the other sc->pd updates at the end of the function. Cc: stable@vger.kernel.org Fixes: 37416e554961 ("clk: qcom: gdsc: Handle GDSC regulator supplies") Signed-off-by: Bjorn Andersson --- Changes since v1: - Refactored into if (on) else if (ALWAYS_ON) style - Extracted relevant parts of gdsc_enable() to call under VOTABLE - Turn on hwctrl if requested for non-votable gdscs drivers/clk/qcom/gdsc.c | 54 +++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c index 51ed640e527b..4ece326ea233 100644 --- a/drivers/clk/qcom/gdsc.c +++ b/drivers/clk/qcom/gdsc.c @@ -357,27 +357,43 @@ static int gdsc_init(struct gdsc *sc) if (on < 0) return on; - /* - * Votable GDSCs can be ON due to Vote from other masters. - * If a Votable GDSC is ON, make sure we have a Vote. - */ - if ((sc->flags & VOTABLE) && on) - gdsc_enable(&sc->pd); + if (on) { + /* The regulator must be on, sync the kernel state */ + if (sc->rsupply) { + ret = regulator_enable(sc->rsupply); + if (ret < 0) + return ret; + } - /* - * Make sure the retain bit is set if the GDSC is already on, otherwise - * we end up turning off the GDSC and destroying all the register - * contents that we thought we were saving. - */ - if ((sc->flags & RETAIN_FF_ENABLE) && on) - gdsc_retain_ff_on(sc); + /* + * Votable GDSCs can be ON due to Vote from other masters. + * If a Votable GDSC is ON, make sure we have a Vote. + */ + if (sc->flags & VOTABLE) { + ret = regmap_update_bits(sc->regmap, sc->gdscr, + SW_COLLAPSE_MASK, val); + if (ret) + return ret; + } + + /* Turn on HW trigger mode if supported */ + if (sc->flags & HW_CTRL) { + ret = gdsc_hwctrl(sc, true); + if (ret < 0) + return ret; + } - /* If ALWAYS_ON GDSCs are not ON, turn them ON */ - if (sc->flags & ALWAYS_ON) { - if (!on) - gdsc_enable(&sc->pd); + /* + * Make sure the retain bit is set if the GDSC is already on, + * otherwise we end up turning off the GDSC and destroying all + * the register contents that we thought we were saving. + */ + if (sc->flags & RETAIN_FF_ENABLE) + gdsc_retain_ff_on(sc); + } else if (sc->flags & ALWAYS_ON) { + /* If ALWAYS_ON GDSCs are not ON, turn them ON */ + gdsc_enable(&sc->pd); on = true; - sc->pd.flags |= GENPD_FLAG_ALWAYS_ON; } if (on || (sc->pwrsts & PWRSTS_RET)) @@ -385,6 +401,8 @@ static int gdsc_init(struct gdsc *sc) else gdsc_clear_mem_on(sc); + if (sc->flags & ALWAYS_ON) + sc->pd.flags |= GENPD_FLAG_ALWAYS_ON; if (!sc->pd.power_off) sc->pd.power_off = gdsc_disable; if (!sc->pd.power_on) -- 2.29.2