From patchwork Fri Jul 9 17:31:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 472472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8D2EC11F75 for ; Fri, 9 Jul 2021 17:32:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84E72613D9 for ; Fri, 9 Jul 2021 17:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbhGIRe7 (ORCPT ); Fri, 9 Jul 2021 13:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbhGIRex (ORCPT ); Fri, 9 Jul 2021 13:34:53 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B3BC0613DD for ; Fri, 9 Jul 2021 10:32:09 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 8so13015131lfp.9 for ; Fri, 09 Jul 2021 10:32:08 -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=SjFzSjONYuEpNPrn8vILKcXv8t+6phQCfA+Cce2Zw8Y=; b=p1R064hgfUHwIESmq5LWdQ94d96i6QYw/zDC96aRgFZNeECDduxwX5DPaypaqL8KvL qq9vz4ZgnML2KJfPa6ObS6NeNfG2TIX1xOGXMZRdjMtDU3+ZwhWDlWgwL2Y2t6QBllsZ xJCH8mDwzSbeJ+L7X8saMxxPRidmmJ8fMQNF0ifXOaa/ZyOjmVQYOuh2zhGUKEgBQTL7 a7BLDovTgb7UTa8F9oH64kxrVpk8PMltfj7qNrUZVtpFKwraRRPtpGiY5pVOuk/DK8iu esK8He96Cw4cAEP84HrkKLYrb1Qh0kfK7hCyuGXXa4bakHyxLUsT4f8tpPxe+AHKTtpt 0IMw== 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=SjFzSjONYuEpNPrn8vILKcXv8t+6phQCfA+Cce2Zw8Y=; b=Wn97GzKZGPiIlrC6YVdULaVkgBHgwD+SMN9sF24rTc9jLNW46a0MftzpTkz+8VnbQL urDRVtq/sVKXkl/JtkVsrlyoUr6KeUn7XRTFfpLPsFzD8AtFVbtxm5283kyLHOsVrWGd 89MVkr/Nan5tQ6/wjytmCOqYu/U1Jp7zzQpk9PDF5OkPe5GkHyqIcXACatWDhXwyPXRp UbHANFxHku3B2yXBhX5Za3rHQomRGRPgDLDxX3OVSD/y68qscijI1Aa3vh8MZUPLw66H HG1wPgnGJ61JC5ze78Ktu6X01fPklwE7PDIVOUbC7nKNX2VTZjymxY+Yu06T+vfHIqTV zmHg== X-Gm-Message-State: AOAM533kJm9CHQbmgw7xUm2ohftrH8Owywte29n7pKJfRBZsfHlCS0hz 68q4SCSRxsmDfKHgI5O+uUOa1A== X-Google-Smtp-Source: ABdhPJxxhH7SM7baNOUo0Mq3dmeWjfYanS0QKQOTHAWpnSZ35GCpRbqzhPLXwGtMNwnpbKIk3Yhe5Q== X-Received: by 2002:a19:6a09:: with SMTP id u9mr1385279lfu.119.1625851927371; Fri, 09 Jul 2021 10:32:07 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id b14sm511129lfb.132.2021.07.09.10.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 10:32:07 -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 v3 4/7] clk: qcom: gdsc: call runtime PM functions for the provider device Date: Fri, 9 Jul 2021 20:31:59 +0300 Message-Id: <20210709173202.667820-5-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210709173202.667820-1-dmitry.baryshkov@linaro.org> References: <20210709173202.667820-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In order to properly handle runtime PM status of the provider device, call pm_runtime_get/pm_runtime_put on the clock controller device. Signed-off-by: Dmitry Baryshkov --- drivers/clk/qcom/gdsc.c | 66 ++++++++++++++++++++++++++++++++++++++--- drivers/clk/qcom/gdsc.h | 2 ++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c index ccd36617d067..6bec31fccb09 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,30 @@ enum gdsc_status { GDSC_ON }; +static int gdsc_pm_runtime_get(struct gdsc *sc) +{ + int ret; + + if (!sc->rpm_dev) + return 0; + + ret = pm_runtime_get_sync(sc->rpm_dev); + if (ret < 0) { + pm_runtime_put_noidle(sc->rpm_dev); + return ret; + } + + return 0; +} + +static int gdsc_pm_runtime_put(struct gdsc *sc) +{ + if (!sc->rpm_dev) + return 0; + + return pm_runtime_put_sync(sc->rpm_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 +257,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 +314,28 @@ 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); + if (ret) { + gdsc_pm_runtime_put(sc); + return ret; + } + + return 0; +} + +static int _gdsc_disable(struct gdsc *sc) +{ + int ret; + if (sc->pwrsts == PWRSTS_ON) return gdsc_assert_reset(sc); @@ -329,6 +370,18 @@ 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_disable(sc); + if (ret) + return ret; + + return gdsc_pm_runtime_put(sc); +} + static int gdsc_init(struct gdsc *sc) { u32 mask, val; @@ -425,6 +478,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]->rpm_dev = dev; scs[i]->regmap = regmap; scs[i]->rcdev = rcdev; ret = gdsc_init(scs[i]); @@ -486,7 +541,10 @@ void gdsc_unregister(struct gdsc_desc *desc) */ int gdsc_gx_do_nothing_enable(struct generic_pm_domain *domain) { + struct gdsc *sc = domain_to_gdsc(domain); + /* Do nothing but give genpd the impression that we were successful */ - return 0; + /* Get the runtime PM device only */ + return gdsc_pm_runtime_get(sc); } EXPORT_SYMBOL_GPL(gdsc_gx_do_nothing_enable); diff --git a/drivers/clk/qcom/gdsc.h b/drivers/clk/qcom/gdsc.h index 5bb396b344d1..a82982df0a55 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 + * @rpm_dev: runtime PM device */ struct gdsc { struct generic_pm_domain pd; @@ -58,6 +59,7 @@ struct gdsc { const char *supply; struct regulator *rsupply; + struct device *rpm_dev; }; struct gdsc_desc {