From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 083693FC0 for ; Mon, 20 Sep 2021 18:12:23 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id t10so64976036lfd.8 for ; Mon, 20 Sep 2021 11:12:22 -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=Ss2xyv7r3CJzoqIgOFTsxcC6lv34A9WC+sgV9LT6ZdVr+X2r9+QufDqiqBX782HwRA b5tl3N5DVugpO6EtZTsfjMVlL2M3QxkLreFny8u6Ph1ZN87mm7oCbn5aKXGYJ3E897xF sh0nhMxDIHpHsj0MO9Sh2AfKA6UzgHYL1FH8RNnbTONNM/BkVSf3h2ybnXECY0J+ulBQ dQk+R5rXTwLQSpVLF+PXKry3lP9JSmb7Uz7ahwB+TFobAnsxZBn6SQmNxfNz0XCcatdt U2pzfc3kCecAYMHekub96FzOE7Mx1Cc2GfwxQwV41Mxnvp2wPPVCYrW7mqxC23Xkvx0B JBCw== 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=S9hZGckwoFMoSbV0x4YD1Al+JbJ+wpVXooOWP34vcWso9lGdugQONKlCEDKFQX1UiD Gpqd0UjhGsoI+hl06c6ap8O0wCwtY/k/6aSQDrRhoh4rJN8zRCNbVNuEm0Jknsvc5dM3 maJw0Dbq62aJt8s0/XTCStQGQKWshNYlLrBnrNKE9+zsIA9JmC2sbDfV4nVPcJqhpkRH lcV7+aMthVunLnuet6gNNeum4dAxhX/ujQiwqzyIPcftPWVNyWHjtFzn3gpvP/6IPnsJ YhfW9bE7n+Ar3XZUgLzqim4sgcZeVsdDBiGf2M/dTtlUOsMU7apIVOKFIkMZQ7LpkxiU yRAw== X-Gm-Message-State: AOAM530s0R5FzCPKO2y2828/+l/NwtweLXoRfsbi05erMInpld5d5Yc3 AuHTI/osY+japmNW7MFCu2s= X-Google-Smtp-Source: ABdhPJxo++5RejsG+AFOJsQ43vAIRIdeTCG3wzxp8hK+y+/URZRYFAd3WgCwXGPXRjkX5+WEcHyRNg== X-Received: by 2002:a2e:b051:: with SMTP id d17mr11734763ljl.470.1632161540669; Mon, 20 Sep 2021 11:12:20 -0700 (PDT) Received: from localhost.localdomain (46-138-151-206.dynamic.spd-mgts.ru. [46.138.151.206]) by smtp.gmail.com with ESMTPSA id u3sm1775677lju.107.2021.09.20.11.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 11:12:20 -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=20Kleine-K=C3=B6nig?= , Nishanth Menon , Adrian Hunter , Rob Herring , 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 v12 17/35] bus: tegra-gmi: Add runtime PM and OPP support Date: Mon, 20 Sep 2021 21:11:27 +0300 Message-Id: <20210920181145.19543-18-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210920181145.19543-1-digetx@gmail.com> References: <20210920181145.19543-1-digetx@gmail.com> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.32.0