Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1459139pxu; Thu, 17 Dec 2020 10:23:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlOUWeAtPxSOKIgselq2dIXV93ne8/84c9sugesIuMUtSt6P4L8tGRtIb4YyEcZ5E/LBMA X-Received: by 2002:a17:906:3813:: with SMTP id v19mr285494ejc.462.1608229395772; Thu, 17 Dec 2020 10:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608229395; cv=none; d=google.com; s=arc-20160816; b=daEnmEmaDlt0q26vT9I+5AtHkvJGnv1ogQYntFAm3/GPZ5WHY+Hx8BiPOwonIdZIev z6wkLMmdBy9u0HWoVDSsSyVuF3fqztSauLDS5sA6wuNrONdy/GY3B8ceytXeL0IxOwAB zt0Nmiemt9VkoEDaZAgHrS01jJ1VaBVlWNoRa9jii8ltbtz4eNxJlzr8rF/fc0KzpkE9 5Uydv/Xgcesu+XgBjjkGbJ38JVDLUd8FHCNd3iM62kDr6zueJuuaUQ7d2WjWp2SxKg9j uOzXv8ficOgD5tvyEspJQdkoVz7FYy/np8gpv67mGSpL/NIB61TSxRnc7NUVL8u7+5Wk 32uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=k+TBWoCCmuI+juM/RDKcFjuPs5RlB1YJML8ROgxtvlw=; b=YHhj831+qu7IcurNWXa/sTeXkk8yRq0iD5xD8BcjrCDIeVYvFGr5R3B/l138fdu3nu 0VRDrBiKb7lU9ogsREtjpDOElBEFdz9PwKC97UMSPc7UUSLL+5HXSjpYPrQW6nQYnhig /EYd+GRt50umY9a8V0N+qPWAbwbFvBztyCSiQj/GErLncW9XvVThQpXPTh2FLx+oLoyr lCI/FpBNt1c9OuiNfjDhIimwB84AoGKviQ7ULqiFKdGKvBeu5VYi9oPIzcjw+RwzqQBy PR1Q1duzOOp5uzo0n9AcrTmSz8OB0zGc9QC9W8wRYsyAlhYOxa4MSfU0P1rnqpSbE1NG ocyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=R5sL7KBW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qn10si3077326ejb.591.2020.12.17.10.22.52; Thu, 17 Dec 2020 10:23:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=R5sL7KBW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730050AbgLQSWN (ORCPT + 99 others); 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, >