Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1475689pxu; Thu, 17 Dec 2020 10:48:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxC7s6PUX8AMnYEb1Ua0m+mRDIce7X3gFhpNWlIZpxD/G4QudFyQFIp3X0P00Tr1OzRjjfF X-Received: by 2002:a17:906:1a4e:: with SMTP id j14mr333371ejf.507.1608230907344; Thu, 17 Dec 2020 10:48:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608230907; cv=none; d=google.com; s=arc-20160816; b=FCJ9xYtj18cT2vj10An4j+xGRbNvzRCWJPxHEgskVnSizqI/kK71x7QWjwYnCzAzcE 7mKu5YyUIYRKnPYDsWNn21b77L97lzVl2tFz8SuFApifudTu9dTC6UKqsLVc4RSTDc2t foBA95CeiQcwroBKfYcsW7W1k4g+7kz965JnLp8SXugCgK1GfTlfPzAcmSBThN3BnM/M T0TM0x1GLjtjdm1y2LSRgvSKoJTXAY7wt4cNhDrQTPZZq0KVNzmm/0sq5fTlGR2+Q/sJ zfrB5fWoBvJIyqfmxB1/w8eY01bh1G8fqyoXhxrcLUcPNArf1JbQZhNdNfq7iEiXTotk N3TA== 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=eSYB0Y/xRIZysMaCL0aa3isjLo158W5WBPwwbHOrbfE=; b=oK84jzXnVfyE3uBrCpcd4WILpb7/RuI2sqIHH7mncQO2lOFwCr1PVBDSbnCVT9kClb 8k1ftSJ6I809XHv7rHiODDWVAjF8w2yAlriM2D50PAn7dV21gTaD7s8QAcaioqaJHEDv JnRI4MijOkE3mLFJuiTvmn1X9VH+dbx8T2SZkoGOG4LBhAiGKIHI8T7dfjvu/JCAIlgV g9YqU4SqcWzTwZIUd3Y58c273huvkzQ+4LEfIX4tycoWgXBoEsmPqkIbHdbxvTMKGSov hNF5o9g4PzSPlEYCjGJLL7W5Lqb3OpzNfy35yAVfBWV58wlNgew5uX4lQ3h2mUpBc7E5 Cguw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IQJRL+Lb; 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 a24si5081919edy.25.2020.12.17.10.48.04; Thu, 17 Dec 2020 10:48:27 -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=IQJRL+Lb; 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 S1730287AbgLQSqn (ORCPT + 99 others); Thu, 17 Dec 2020 13:46:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729157AbgLQSqm (ORCPT ); Thu, 17 Dec 2020 13:46:42 -0500 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 588F1C06138C; Thu, 17 Dec 2020 10:46:02 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id m25so60105102lfc.11; Thu, 17 Dec 2020 10:46:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=eSYB0Y/xRIZysMaCL0aa3isjLo158W5WBPwwbHOrbfE=; b=IQJRL+Lb7PAb96r55KxH7ztRsHpbX849w3oGSThKsjbwhrR5HEGjKItUC60H3ZsJPW PNjoDJv35lDBQiaI37xd7K1t6ho+m0NsdCOzHfJvA6u35zE+4urqIb3xWFcuysXktB4A ebI7unXgw0tsxCPEYs2n2MzQ2XDKRE7E8U0Wo4vNLztrImRrsmKUMUntAw+xWJ9xHtF2 zo9ZuUMJIYMdtFrY9oBOvPRlyiqALTvZrla3ds/OD77gU23VkbZn40HFvsYyboUVxS2v gyhg4MCmQlOY5eGpJIFk4J22PqHBSenwJbr6df3n2gsjjRa6zhntGM8mckwXXqW0cVha qleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eSYB0Y/xRIZysMaCL0aa3isjLo158W5WBPwwbHOrbfE=; b=iRKL56Y89QbFofGfCsq3WqaugjFYpUVIgwDhqyehaq9EcO+ErqVrNGaK0A0/eVqr73 yZMXly5Vo9UexREV7locP7o492vXQKLj0ecbHCN54fPZ4pBfxC+AvDyZteamBzIm5kYY hUpaDY1Q6wmuIL69R2Q+D2c8TxfQsoPYYfQXEgtOPD6Sx1rvKnWgH631J1KBqwbsq02W IDQe54kwGxAwufy5inVZQDDOetNtwM1IHCeIlIhGCf3h1MVWLfGmgpxX1N+m41hwhTJx e0Ba/fc7tBwMjBETcFcyVDi+2ULKJAHY3Vbl2sj6RgSoADYze3A3CLv+gms+ntVk8Shj Gq/A== X-Gm-Message-State: AOAM533cACCOhW5nNBtOUFdQtd6qJy4Ug9D+8/oiBGKasD+5hGrRLVxo F2Z7f5baOpqKrVavc32hxvDGXUgLj7c= X-Received: by 2002:a05:6512:3593:: with SMTP id m19mr35943lfr.221.1608230760739; Thu, 17 Dec 2020 10:46:00 -0800 (PST) Received: from [192.168.2.145] (109-252-192-57.dynamic.spd-mgts.ru. [109.252.192.57]) by smtp.googlemail.com with ESMTPSA id i19sm756871ljj.26.2020.12.17.10.45.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Dec 2020 10:46:00 -0800 (PST) Subject: Re: [PATCH v2 34/48] gpu: host1x: Support power management To: Mikko Perttunen , 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: Dmitry Osipenko Message-ID: Date: Thu, 17 Dec 2020 21:45:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 17.12.2020 21:21, Mikko Perttunen пишет: > 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. Indeed, thanks. I'll correct it in the next revision. Perhaps the actual save/restore needs to be moved to the runtime callbacks. At least I can't remember right now why this wasn't done in the first place.