From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 28F83C2BB9A for ; Thu, 17 Dec 2020 18:22:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA119238EF for ; Thu, 17 Dec 2020 18:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730070AbgLQSWN (ORCPT ); Thu, 17 Dec 2020 13:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729923AbgLQSWL (ORCPT ); Thu, 17 Dec 2020 13:22:11 -0500 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24205C0617A7; Thu, 17 Dec 2020 10:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=k+TBWoCCmuI+juM/RDKcFjuPs5RlB1YJML8ROgxtvlw=; b=R5sL7KBWSOcu7q0eGSq07mz0ho j0+NPSXrRL9yeaniOZDHuWaAUVw2P1el8IkVWHrEKPgMyaBC6tPpkE02x+lkmACRyi1nUI8VYhEba GryzGGyvSAdgSkDMTxMEKoCwwgzZfq4x5sor0wcLurTcDMASw+FAGnWD3u9srW/2m1KyFb3bq1BD8 YIjjrqGYlG6Uvnupn5dUXS/wm/r8RC4x4SnsVeQY9X9POgEG7Psy8lft01Vqfa3Qk/L1JC82JFrZE b6BZqcQDoGn0v3nSv9BC56rPFVkFjCWUpKHpOZ7VRD+T1n5S+8IZ4gdI2K2JtncSw/+m1ibYAuSDI 8HY+qvmA==; Received: from dsl-hkibng22-54f986-236.dhcp.inet.fi ([84.249.134.236] helo=[192.168.1.10]) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1kpxu0-000859-J2; Thu, 17 Dec 2020 20:21:24 +0200 Subject: Re: [PATCH v2 34/48] gpu: host1x: Support power management To: Dmitry Osipenko , Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Mauro Carvalho Chehab , Rob Herring , Peter Geis , Nicolas Chauvet , Krzysztof Kozlowski , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Michael Turquette Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org References: <20201217180638.22748-1-digetx@gmail.com> <20201217180638.22748-35-digetx@gmail.com> From: Mikko Perttunen Message-ID: Date: Thu, 17 Dec 2020 20:21:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201217180638.22748-35-digetx@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 84.249.134.236 X-SA-Exim-Mail-From: cyndis@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/17/20 8:06 PM, Dmitry Osipenko wrote: > Add suspend/resume and generic power domain support to the Host1x driver. > This is required for enabling system-wide DVFS and supporting dynamic > power management using a generic power domain. > > Tested-by: Peter Geis > Tested-by: Nicolas Chauvet > Signed-off-by: Dmitry Osipenko > --- > drivers/gpu/host1x/dev.c | 102 ++++++++++++++++++++++++++++++++++----- > 1 file changed, 91 insertions(+), 11 deletions(-) > > diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c > index d0ebb70e2fdd..c1525cffe7b1 100644 > --- a/drivers/gpu/host1x/dev.c > +++ b/drivers/gpu/host1x/dev.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > #include > > #define CREATE_TRACE_POINTS > @@ -417,7 +418,7 @@ static int host1x_probe(struct platform_device *pdev) > return err; > } > > - host->rst = devm_reset_control_get(&pdev->dev, "host1x"); > + host->rst = devm_reset_control_get_exclusive_released(&pdev->dev, "host1x"); > if (IS_ERR(host->rst)) { > err = PTR_ERR(host->rst); > dev_err(&pdev->dev, "failed to get reset: %d\n", err); > @@ -437,16 +438,15 @@ static int host1x_probe(struct platform_device *pdev) > goto iommu_exit; > } > > - err = clk_prepare_enable(host->clk); > - if (err < 0) { > - dev_err(&pdev->dev, "failed to enable clock\n"); > - goto free_channels; > - } > + pm_runtime_enable(&pdev->dev); > + err = pm_runtime_get_sync(&pdev->dev); > + if (err < 0) > + goto rpm_disable; > > err = reset_control_deassert(host->rst); > if (err < 0) { > dev_err(&pdev->dev, "failed to deassert reset: %d\n", err); > - goto unprepare_disable; > + goto rpm_disable; > } > > err = host1x_syncpt_init(host); > @@ -485,9 +485,10 @@ static int host1x_probe(struct platform_device *pdev) > host1x_syncpt_deinit(host); > reset_assert: > reset_control_assert(host->rst); > -unprepare_disable: > - clk_disable_unprepare(host->clk); > -free_channels: > +rpm_disable: > + pm_runtime_put(&pdev->dev); > + pm_runtime_disable(&pdev->dev); > + > host1x_channel_list_free(&host->channel_list); > iommu_exit: > host1x_iommu_exit(host); > @@ -504,16 +505,95 @@ static int host1x_remove(struct platform_device *pdev) > host1x_intr_deinit(host); > host1x_syncpt_deinit(host); > reset_control_assert(host->rst); > - clk_disable_unprepare(host->clk); > + pm_runtime_put(&pdev->dev); > + pm_runtime_disable(&pdev->dev); > host1x_iommu_exit(host); > > return 0; > } > > +static int __maybe_unused host1x_runtime_suspend(struct device *dev) > +{ > + struct host1x *host = dev_get_drvdata(dev); > + > + clk_disable_unprepare(host->clk); > + reset_control_release(host->rst); > + > + return 0; > +} > + > +static int __maybe_unused host1x_runtime_resume(struct device *dev) > +{ > + struct host1x *host = dev_get_drvdata(dev); > + int err; > + > + err = reset_control_acquire(host->rst); > + if (err) { > + dev_err(dev, "failed to acquire reset: %d\n", err); > + return err; > + } > + > + err = clk_prepare_enable(host->clk); > + if (err) { > + dev_err(dev, "failed to enable clock: %d\n", err); > + goto release_reset; > + } > + > + return 0; > + > +release_reset: > + reset_control_release(host->rst); > + > + return err; > +} > + > +static __maybe_unused int host1x_suspend(struct device *dev) > +{ > + struct host1x *host = dev_get_drvdata(dev); > + int err; > + > + host1x_syncpt_save(host); > + > + err = pm_runtime_force_suspend(dev); > + if (err < 0) > + return err; > + > + return 0; > +} > + > +static __maybe_unused int host1x_resume(struct device *dev) > +{ > + struct host1x *host = dev_get_drvdata(dev); > + struct host1x_channel *channel; > + unsigned int index; > + int err; > + > + err = pm_runtime_force_resume(dev); > + if (err < 0) > + return err; > + > + host1x_syncpt_restore(host); We also need to execute 'host1x_setup_sid_table' upon resume. cheers, Mikko > + > + for_each_set_bit(index, host->channel_list.allocated_channels, > + host->info->nb_channels) { > + channel = &host->channel_list.channels[index]; > + host1x_hw_channel_init(host, channel, channel->id); > + } > + > + return 0; > +} > + > +static const struct dev_pm_ops host1x_pm = { > + SET_RUNTIME_PM_OPS(host1x_runtime_suspend, host1x_runtime_resume, > + NULL) > + SET_SYSTEM_SLEEP_PM_OPS(host1x_suspend, host1x_resume) > +}; > + > static struct platform_driver tegra_host1x_driver = { > .driver = { > .name = "tegra-host1x", > .of_match_table = host1x_of_match, > + .pm = &host1x_pm, > }, > .probe = host1x_probe, > .remove = host1x_remove, >