From patchwork Sun Sep 26 22:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12518573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08D0AC4167B for ; Sun, 26 Sep 2021 22:43:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC05D6108E for ; Sun, 26 Sep 2021 22:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232647AbhIZWp3 (ORCPT ); Sun, 26 Sep 2021 18:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232012AbhIZWoY (ORCPT ); Sun, 26 Sep 2021 18:44:24 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D4DC06176E; Sun, 26 Sep 2021 15:42:47 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id z24so69311976lfu.13; Sun, 26 Sep 2021 15:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kMziebaAeLQX+HJyIYKw3fi1qml9OJEejLLtUc1VAqA=; b=PT1Yy/8LKdyb2dqxJOr/iidph7J5J5Mqk977Qt0LrelGBdfatFjMDChx64e5N+CwzR oitEapRtBNzEL/wasyYmsHp2IpWf3FUq3Jx4IRiKZ09nZPf1oPYOosHp26qLMdzYAd6j 2FqxItiiFLl3IrxSCQq2J4XquKOznZFedpPe/Pwtv6/bF4FK/3eIO/Za0bebsRVv76XV ggoxWd5KFtvs8yrMJmdsMAkoziOo9iFvIutFiccv6Yh+ZuHdGAOmSQXkO2S7BgDcFvLA u7mozTiqmFjAeHdqmQiYRvfVoPKW/BQNtUwl59ajDLKbeoN94j1SXl9ZAmkaUAotf1mS Vulw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kMziebaAeLQX+HJyIYKw3fi1qml9OJEejLLtUc1VAqA=; b=DlCdR7RkhEpx01PTb+dd9grcOVNQBImcxR6WSXYhQHov9BMhbNF+DHNzXJ7ABQGsCh 7Xic5uUVzTdOFuOCGoiY4KBgdoLD2t82bdO2F6J37sYSUqlIMpsNTSA9l5lbbvbUPJsN JCXL3Hyn5Sf6711HcaLQxidNKNUCmesjfDAcVAaqOCabaE7t70y5GwQ8pEyHiNm/cDd+ Hr+ljy9q04dXsq28QEdifDlUQ/DoPS5G/bSwc/11lb6kXwHkWtq/lVQrcss7jTXVE7L9 m0Wfc4psRhZgosSHQa5cvghj3t3dsCxq/R8K1HBnBCNg2qLfqGxwYVQ+WUWXa9XE2Oxb 5R8A== X-Gm-Message-State: AOAM531+Ya3c8Op6ADIysr//rFjGvwKnNKl3syhC1x7yU80wwSt+Ljmm vdY6n73p/JVqs4jHIYB+dycM4bavWEc= X-Google-Smtp-Source: ABdhPJxEXxCkuRjC1HExeSNNePw0IIRPcITUp3jaJDpkAxPhjOuYsSpnYgnQoXQnt0n4+zKXNTfl1Q== X-Received: by 2002:a2e:d19:: with SMTP id 25mr21213721ljn.167.1632696165967; Sun, 26 Sep 2021 15:42:45 -0700 (PDT) Received: from localhost.localdomain (46-138-80-108.dynamic.spd-mgts.ru. [46.138.80.108]) by smtp.gmail.com with ESMTPSA id m10sm1408899lfr.272.2021.09.26.15.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 15:42:45 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Ulf Hansson , Viresh Kumar , Stephen Boyd , Peter De Schrijver , Mikko Perttunen , Peter Chen , Lee Jones , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Nishanth Menon , Adrian Hunter , Michael Turquette Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-staging@lists.linux.dev, linux-pwm@vger.kernel.org, linux-mmc@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, Mark Brown , Vignesh Raghavendra , Richard Weinberger , Miquel Raynal , Lucas Stach , Stefan Agner , Mauro Carvalho Chehab , David Heidelberg Subject: [PATCH v13 17/35] bus: tegra-gmi: Add runtime PM and OPP support Date: Mon, 27 Sep 2021 01:40:40 +0300 Message-Id: <20210926224058.1252-18-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210926224058.1252-1-digetx@gmail.com> References: <20210926224058.1252-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The GMI bus on Tegra belongs to the core power domain and we're going to enable GENPD support for the core domain. Now GMI must be resumed using runtime PM API in order to initialize the GMI power state. Add runtime PM and OPP support to the GMI driver. Signed-off-by: Dmitry Osipenko --- drivers/bus/tegra-gmi.c | 52 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/drivers/bus/tegra-gmi.c b/drivers/bus/tegra-gmi.c index a6570789f7af..72ef8a8c236b 100644 --- a/drivers/bus/tegra-gmi.c +++ b/drivers/bus/tegra-gmi.c @@ -13,8 +13,11 @@ #include #include #include +#include #include +#include + #define TEGRA_GMI_CONFIG 0x00 #define TEGRA_GMI_CONFIG_GO BIT(31) #define TEGRA_GMI_BUS_WIDTH_32BIT BIT(30) @@ -54,9 +57,9 @@ static int tegra_gmi_enable(struct tegra_gmi *gmi) { int err; - err = clk_prepare_enable(gmi->clk); - if (err < 0) { - dev_err(gmi->dev, "failed to enable clock: %d\n", err); + err = pm_runtime_resume_and_get(gmi->dev); + if (err) { + pm_runtime_disable(gmi->dev); return err; } @@ -83,7 +86,8 @@ static void tegra_gmi_disable(struct tegra_gmi *gmi) writel(config, gmi->base + TEGRA_GMI_CONFIG); reset_control_assert(gmi->rst); - clk_disable_unprepare(gmi->clk); + + pm_runtime_put(gmi->dev); } static int tegra_gmi_parse_dt(struct tegra_gmi *gmi) @@ -213,6 +217,7 @@ static int tegra_gmi_probe(struct platform_device *pdev) if (!gmi) return -ENOMEM; + platform_set_drvdata(pdev, gmi); gmi->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -232,6 +237,14 @@ static int tegra_gmi_probe(struct platform_device *pdev) return PTR_ERR(gmi->rst); } + err = devm_pm_runtime_enable(gmi->dev); + if (err) + return err; + + err = devm_tegra_core_dev_init_opp_table_common(&pdev->dev); + if (err) + return err; + err = tegra_gmi_parse_dt(gmi); if (err) return err; @@ -247,8 +260,6 @@ static int tegra_gmi_probe(struct platform_device *pdev) return err; } - platform_set_drvdata(pdev, gmi); - return 0; } @@ -262,6 +273,34 @@ static int tegra_gmi_remove(struct platform_device *pdev) return 0; } +static int __maybe_unused tegra_gmi_runtime_resume(struct device *dev) +{ + struct tegra_gmi *gmi = dev_get_drvdata(dev); + int err; + + err = clk_prepare_enable(gmi->clk); + if (err < 0) { + dev_err(gmi->dev, "failed to enable clock: %d\n", err); + return err; + } + + return 0; +} + +static int __maybe_unused tegra_gmi_runtime_suspend(struct device *dev) +{ + struct tegra_gmi *gmi = dev_get_drvdata(dev); + + clk_disable_unprepare(gmi->clk); + + return 0; +} + +static const struct dev_pm_ops tegra_gmi_pm = { + SET_RUNTIME_PM_OPS(tegra_gmi_runtime_suspend, tegra_gmi_runtime_resume, + NULL) +}; + static const struct of_device_id tegra_gmi_id_table[] = { { .compatible = "nvidia,tegra20-gmi", }, { .compatible = "nvidia,tegra30-gmi", }, @@ -275,6 +314,7 @@ static struct platform_driver tegra_gmi_driver = { .driver = { .name = "tegra-gmi", .of_match_table = tegra_gmi_id_table, + .pm = &tegra_gmi_pm, }, }; module_platform_driver(tegra_gmi_driver);