Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1449817pxu; Thu, 17 Dec 2020 10:10:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTQre/6b3e8srNHzxAFWczKfpHboqzkxa43AmU8mGMajV6k4l2afnnmJtHdBieQCjL6yBj X-Received: by 2002:a17:906:5841:: with SMTP id h1mr211442ejs.77.1608228626767; Thu, 17 Dec 2020 10:10:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608228626; cv=none; d=google.com; s=arc-20160816; b=kWP0jw/ThJ2OaHm2zfkCBpjDzjN5VQusGwpTFiGZ/jiGI68Xl+tHd+gApoQApSiv2u tp1rJw+kNkY0sUrMuYhPw1V+8Zlc+LPiudzlwTIktbsuucsQEiBlqbqU80f5RnTS11hi V339hVcwaQ5AZ7ljE4KsqM/H27qHQFzs5gnD8UPT7V4ZDwmvEaE6fl2wFR8bxXc5Ose1 btWBjy28rigR538EGyoBgnoZAUkqYleSJKJS/x8JtTta3Qd918DFfITDFhFcJnsYUtKZ ujqUFq1G3fTCVIwrxBO72aZygcidW2Pg/kL6ECiZI5CbEuo9UKiYVsLtCq+MQ0mb6Flf J7lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aGHKx42MfDPDBxR4DOfvxOz7/Acf8JGv695v+njpFiw=; b=wBpP64nPOqw1w2CbXck7zuHEwe/KfUVLHtofYIw3mUJs/CxhS8F78OjGWyrPpIFSPp b9na1MKOUhfCoGw/2jCSwJo/JuvJpSMYAMJy+lR5MsKF+5dvp77/yGYeYtPrGDCkm/vT bsZYogF1i7rdPuYK7NqwLvJmEeOa1L7glh4bmeW0D7bXamollShroDA34P48GRJ128NC jCJLkLcD1BiFC8ep6Dbr4aRAAA+DP07furdVZKvz3cS8Pl1k0Xc7xrNSePtAb426nbh9 Ey4hyRvHMrvj1EVMOJNfVWLf6N1K3sNgyOuZHnqoPMKi3HKb/VunNcIQxQ+zkCD8L7Nk aGoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=APzhHWry; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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.10.00; Thu, 17 Dec 2020 10:10:26 -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=pass header.i=@gmail.com header.s=20161025 header.b=APzhHWry; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730860AbgLQSJI (ORCPT + 99 others); Thu, 17 Dec 2020 13:09:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbgLQSJB (ORCPT ); Thu, 17 Dec 2020 13:09:01 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D13CDC0619FA; Thu, 17 Dec 2020 10:08:00 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id a12so59839722lfl.6; Thu, 17 Dec 2020 10:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aGHKx42MfDPDBxR4DOfvxOz7/Acf8JGv695v+njpFiw=; b=APzhHWryK80KbNYYXej8HpuMRxROpNpavnwx1kCJM5bBVa+TdnqcKt2RdY4SHrVcMt W32uT9CDUxgZFM5ZaDWbgo1obHaTQ1kGwhJG++8pUONg2zS9xnH2pzU8uyJ6hB+j4PGX 1MqSTqHOmRR4oxYHzrG398GEVxIjKP0fRVqwZMLdKEqIdB1HPy2mp9iXuZShti/PjFyY zg1UQpEpkEy5lqEu4XzkhaFTH8uLVwRO4o9uco4kum/fI3IXc3ln3x8P6KAG8+NBMkxm aBvJj5J91tJlBSHYLO4l1LvQKn29JZGFsLwDihxkT203GN1ZlQqTQLh5/Nq0qb56d/Sx uI/w== 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=aGHKx42MfDPDBxR4DOfvxOz7/Acf8JGv695v+njpFiw=; b=Z0MAUhlfYseIx3NpG9dw9WqffIK6vhTngdbbMxvXEe4vxcLA/nl4w7Pa7arGCtwnET 1B/JXdKzzz3VeiCrfgYR/rjz3okwcvpiYovR5dMTeoyMn+EVussQR8UYPDSuAmBJwgig 8qNsWyQVE1BOfHW9j0wI+/CFQzgl80C/hkqCe+IDTRsIoGBgg1dLjx1+LrDax+lfG3c6 aD/IXig4QzHIq1MjR4S5SDyKANDO6FgSP0Zn/6uVIK30B7i1zMscmcV2+XT1Gh+SBakU NcevYMwyEyo1GFsiNCn++eLsELK3yGC4dD0TGXidHDffVbT79E+qJJKUweBmcfW+pPhO JTnA== X-Gm-Message-State: AOAM533GiLApO2Xd0lL9mbF9eyz8DyNGbbB3h5ygVjhxAE/yu7gKYKY9 GVG8JsVVMhpgy8ej0R7uJHY= X-Received: by 2002:a19:be16:: with SMTP id o22mr15087043lff.109.1608228479360; Thu, 17 Dec 2020 10:07:59 -0800 (PST) Received: from localhost.localdomain (109-252-192-57.dynamic.spd-mgts.ru. [109.252.192.57]) by smtp.gmail.com with ESMTPSA id u5sm655596lff.78.2020.12.17.10.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Dec 2020 10:07:58 -0800 (PST) From: Dmitry Osipenko To: 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 Subject: [PATCH v2 34/48] gpu: host1x: Support power management Date: Thu, 17 Dec 2020 21:06:24 +0300 Message-Id: <20201217180638.22748-35-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201217180638.22748-1-digetx@gmail.com> References: <20201217180638.22748-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + + 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, -- 2.29.2