From patchwork Tue Jul 27 20:20:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 486757 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp550807jas; Tue, 27 Jul 2021 13:20:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytDTF9nJE4S9B2Pwf6jdlmC/TbUDk5zXB7SkJyHfBSmlehyacyATAVbPk4LLE1DMdzBP7P X-Received: by 2002:a05:6402:5:: with SMTP id d5mr29229475edu.359.1627417230023; Tue, 27 Jul 2021 13:20:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627417230; cv=none; d=google.com; s=arc-20160816; b=afRMH1GfTJ4pv7OgG1Bmp/JsOuuTjBDv6OBTRqZBy7lG7UP3DI19hTgvC6xBjIBWIv PnofRKlb8gb3C0rpTy9aa0mC8BsJUSWWig2Kx6ZJuu6RB2oqNC8Yk8vO4HR/TW8bKe4K C0OX10ztVfNDrWAEIPziAeg+kVA1TUXidwiGv6Z43GbKPZ0nlMH4C+7jxdlOz45/H9yI UR2QOFJShHmo8qwDVc9t2SzUGwFJU+vKOxZuqjiqTtAuYiu4CJAJijoRM+xT+Usg5p1W PKnJFlue7vpDZS9mmf6WQH/s5vvRWwTLNJCnYlNBG4E7VIxRCw2GliSeSMuPzMsPa9Rw zDug== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lYWJNz4RjhdOK3xgOEToM1HEgwLI9uBrUK4vDt0ZL48=; b=X0qmeewwfw1PkowI1BdK9N75mh08WgXuh9XkideQmefD5UmbGpFHIoCaXhcVIw5NnM UTH+vy6kSQP7f9pfFsT3TWyEqhEcDfW2V/1B5yrGlHwAapMmNpcSiuXVKV4o0daxa6L5 Gk9DHQdmQJVnYuOslxLO7Amde04lcwclWJ7R1UFs6FvQ7HSMIh7UR6f6dBDcR7M/n587 Csi4RvG8UqHUt5QhNBqIxTtUbPNQ7NE0vRhRKLjkEVC/86hxPejkf5K/OHdjiASoTVUa JOfP5D7zSY+o68Q5BczaO8R07B9I92OpCiU2WQRlX5InG/u4R2R3AR+HVHor50y/x2cV btEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pJDVfXBe; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 qk43si2817945ejc.325.2021.07.27.13.20.29; Tue, 27 Jul 2021 13:20:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-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=pJDVfXBe; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S232376AbhG0UU1 (ORCPT + 17 others); Tue, 27 Jul 2021 16:20:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232306AbhG0UUY (ORCPT ); Tue, 27 Jul 2021 16:20:24 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B326C0613D5 for ; Tue, 27 Jul 2021 13:20:23 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id h14so23872715lfv.7 for ; Tue, 27 Jul 2021 13:20:22 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=lYWJNz4RjhdOK3xgOEToM1HEgwLI9uBrUK4vDt0ZL48=; b=pJDVfXBeH5zZuIkUTc6dlFWq2y/4wd8480RQGku9mv5FzorG0+Al4lOLY9oPQLHrok arGprfTsYayPY/UP0ZtN2NUJk6oWkPTwiQxxIOBj/fqVPkuyZfPHzB9J2r45qQsMjjDw QKWtpFcAy996KpqaQ2fWFyfi9Df4HMP9PtzQfCHy/AdpnHKpSLQxniGyD6p2wujYAdRD Dz2hZhaNmg6ZhYmIqTVyUvvoZG4fcN6sQsIwAQh9MpjEH0CINKRLOWqIPZTTpeKh1jNf e++8INbL2mv+lipNUn3hHjRu73Xc7XAofS6oPpY89MiHME4NNSBAC/AKJPV19kTxD5Hv YfUQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=lYWJNz4RjhdOK3xgOEToM1HEgwLI9uBrUK4vDt0ZL48=; b=AYfefwWGyyNzA4V1mZ0L3Iao9QtHKD0ZA4WADJpgpjBuSfbYTL5w1TqdOcpvYn2tQ0 p9Y2V+ZVoFoylFhnhoB5UHnSxHRLhmYQSxdt555vaYNOIAIRw7otQ/SA0h5fMDqDZIkL T3HHGQvynE57eVk4tkG0zreLT7i11cz8EjHgwp8kAvK2CFNVRLxczVY5bs40e7qgEHcE IomYkrsuu2KCKivtiRWTobpSl6KtYE0J3y41GJtumnKnO+za/yj1kgpUxeFfyBkLUHfm 8PdXBesMwK5HbPsfomWmP+tGHFWSWq/PuS2ezKeVeP9rMogN/b1S8iVt+h3bqWdB9QRw W15w== X-Gm-Message-State: AOAM532p+Wcgowb9ASB1QMAxQWkjwJ2Wp4iT2REY5kwuumbT/+mlzmNd g6gPtwwZb5a29dQiZHPXLPIsPg== X-Received: by 2002:ac2:5e67:: with SMTP id a7mr18103340lfr.450.1627417221398; Tue, 27 Jul 2021 13:20:21 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id i11sm376502lfe.215.2021.07.27.13.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 13:20:20 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , Rob Herring , Stephen Boyd , Taniya Das , Jonathan Marek , Michael Turquette Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, Bryan O'Donoghue , Mark Brown , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [PATCH v6 5/8] clk: qcom: gdsc: enable optional power domain support Date: Tue, 27 Jul 2021 23:20:01 +0300 Message-Id: <20210727202004.712665-6-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210727202004.712665-1-dmitry.baryshkov@linaro.org> References: <20210727202004.712665-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On sm8250 dispcc and videocc registers are powered up by the MMCX power domain. Currently we use a regulator to enable this domain on demand, however this has some consequences, as genpd code is not reentrant. Make gdsc code also use pm_runtime calls to ensure that registers are accessible during the gdsc_enable/gdsc_disable operations. Signed-off-by: Dmitry Baryshkov --- drivers/clk/qcom/gdsc.c | 59 ++++++++++++++++++++++++++++++++++++++--- drivers/clk/qcom/gdsc.h | 2 ++ 2 files changed, 58 insertions(+), 3 deletions(-) -- 2.30.2 diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c index 51ed640e527b..a0781d7284cc 100644 --- a/drivers/clk/qcom/gdsc.c +++ b/drivers/clk/qcom/gdsc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,22 @@ enum gdsc_status { GDSC_ON }; +static int gdsc_pm_runtime_get(struct gdsc *sc) +{ + if (!sc->dev) + return 0; + + return pm_runtime_resume_and_get(sc->dev); +} + +static int gdsc_pm_runtime_put(struct gdsc *sc) +{ + if (!sc->dev) + return 0; + + return pm_runtime_put_sync(sc->dev); +} + /* Returns 1 if GDSC status is status, 0 if not, and < 0 on error */ static int gdsc_check_status(struct gdsc *sc, enum gdsc_status status) { @@ -232,9 +249,8 @@ static void gdsc_retain_ff_on(struct gdsc *sc) regmap_update_bits(sc->regmap, sc->gdscr, mask, mask); } -static int gdsc_enable(struct generic_pm_domain *domain) +static int _gdsc_enable(struct gdsc *sc) { - struct gdsc *sc = domain_to_gdsc(domain); int ret; if (sc->pwrsts == PWRSTS_ON) @@ -290,11 +306,26 @@ static int gdsc_enable(struct generic_pm_domain *domain) return 0; } -static int gdsc_disable(struct generic_pm_domain *domain) +static int gdsc_enable(struct generic_pm_domain *domain) { struct gdsc *sc = domain_to_gdsc(domain); int ret; + ret = gdsc_pm_runtime_get(sc); + if (ret) + return ret; + + ret = _gdsc_enable(sc); + + gdsc_pm_runtime_put(sc); + + return ret; +} + +static int _gdsc_disable(struct gdsc *sc) +{ + int ret; + if (sc->pwrsts == PWRSTS_ON) return gdsc_assert_reset(sc); @@ -329,6 +360,22 @@ static int gdsc_disable(struct generic_pm_domain *domain) return 0; } +static int gdsc_disable(struct generic_pm_domain *domain) +{ + struct gdsc *sc = domain_to_gdsc(domain); + int ret; + + ret = gdsc_pm_runtime_get(sc); + if (ret) + return ret; + + ret = _gdsc_disable(sc); + + gdsc_pm_runtime_put(sc); + + return ret; +} + static int gdsc_init(struct gdsc *sc) { u32 mask, val; @@ -425,6 +472,8 @@ int gdsc_register(struct gdsc_desc *desc, for (i = 0; i < num; i++) { if (!scs[i]) continue; + if (pm_runtime_enabled(dev)) + scs[i]->dev = dev; scs[i]->regmap = regmap; scs[i]->rcdev = rcdev; ret = gdsc_init(scs[i]); @@ -439,6 +488,8 @@ int gdsc_register(struct gdsc_desc *desc, continue; if (scs[i]->parent) pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd); + else if (!IS_ERR_OR_NULL(dev->pm_domain)) + pm_genpd_add_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd); } return of_genpd_add_provider_onecell(dev->of_node, data); @@ -457,6 +508,8 @@ void gdsc_unregister(struct gdsc_desc *desc) continue; if (scs[i]->parent) pm_genpd_remove_subdomain(scs[i]->parent, &scs[i]->pd); + else if (!IS_ERR_OR_NULL(dev->pm_domain)) + pm_genpd_remove_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd); } of_genpd_del_provider(dev->of_node); } diff --git a/drivers/clk/qcom/gdsc.h b/drivers/clk/qcom/gdsc.h index 5bb396b344d1..702d47a87af6 100644 --- a/drivers/clk/qcom/gdsc.h +++ b/drivers/clk/qcom/gdsc.h @@ -25,6 +25,7 @@ struct reset_controller_dev; * @resets: ids of resets associated with this gdsc * @reset_count: number of @resets * @rcdev: reset controller + * @dev: the device holding the GDSC, used for pm_runtime calls */ struct gdsc { struct generic_pm_domain pd; @@ -58,6 +59,7 @@ struct gdsc { const char *supply; struct regulator *rsupply; + struct device *dev; }; struct gdsc_desc {