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=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 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 0E8FDC43460 for ; Wed, 28 Apr 2021 07:13:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFF19613DC for ; Wed, 28 Apr 2021 07:13:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236437AbhD1HN5 (ORCPT ); Wed, 28 Apr 2021 03:13:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:60210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbhD1HNx (ORCPT ); Wed, 28 Apr 2021 03:13:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 235D4601FC; Wed, 28 Apr 2021 07:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619593988; bh=vtrlu5NLjbjl/L0tLDBVhlFvjRnFBvLZFZImEEWL/Kk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ASBSV4p3ulPv6GeE1EBbPsFhZFJ1rt+T2/fgFgVHaSSfDBmaXJ6jMnj4uIXzWZAif 52hCdOB9hI0jNZcosW6vQuQSbJHgqaXCtBhEreWRKeBCo+DgiGEeJpwRgwaiGKuPm0 iXkKeSc3++o0Zec4DrZuAjSsLmhPqysBNEeYT291HbxWt6zxxetc/7aeKcnQeD+BEs MJolRy7Vb3GItE3x/agrXCYfFL/R/iYOLARwkY4nYjI2eAWvNSfiz1t6OieD5dZQ6H E4vgkcykWfEKqRkIbSuQu2fRPgj0s9+E0RG1GEiT2Vb14Gz5vTM3ksc4H0KD6gsyRn ClKUXZOd+KNbA== Date: Wed, 28 Apr 2021 09:13:02 +0200 From: Mauro Carvalho Chehab To: Sylwester Nawrocki Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Ezequiel Garcia , Hans Verkuil , Krzysztof Kozlowski , Mauro Carvalho Chehab , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get() Message-ID: <20210428091302.64af1e5d@coco.lan> In-Reply-To: <5f6088c7-c839-f097-737f-b4234c413eac@samsung.com> References: <9c7d683907b9f9cf4a99f57f978671ec7f5a1dbc.1619191723.git.mchehab+huawei@kernel.org> <20210427113055.745d0560@coco.lan> <20210427114235.45a7b2a4@coco.lan> <5f6088c7-c839-f097-737f-b4234c413eac@samsung.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, 27 Apr 2021 13:50:44 +0200 Sylwester Nawrocki escreveu: > On 27.04.2021 11:42, Mauro Carvalho Chehab wrote: > > Em Tue, 27 Apr 2021 11:30:55 +0200 > > Mauro Carvalho Chehab escreveu: > > > >> Em Tue, 27 Apr 2021 10:18:12 +0200 > >> Sylwester Nawrocki escreveu: > >> > >>> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote: > >>>> Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") > >>>> added pm_runtime_resume_and_get() in order to automatically handle > >>>> dev->power.usage_count decrement on errors. > >>>> > >>>> Use the new API, in order to cleanup the error check logic. > >>>> > >>>> Signed-off-by: Mauro Carvalho Chehab > >>>> --- > >>>> drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- > >>>> drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- > >>>> 2 files changed, 2 insertions(+), 3 deletions(-) > >>>> > >>>> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c > >>>> index 9f41c2e7097a..9d5841194f6b 100644 > >>>> --- a/drivers/media/platform/exynos-gsc/gsc-core.c > >>>> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c > >>>> @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev) > >>>> struct gsc_dev *gsc = platform_get_drvdata(pdev); > >>>> int i; > >>>> > >>>> - pm_runtime_get_sync(&pdev->dev); > >>>> + pm_runtime_resume_and_get(&pdev->dev); > >>>> > >>>> gsc_unregister_m2m_device(gsc); > >>>> v4l2_device_unregister(&gsc->v4l2_dev); > >>>> @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev) > >>>> for (i = 0; i < gsc->num_clocks; i++) > >>>> clk_disable_unprepare(gsc->clock[i]); > >>>> > >>>> - pm_runtime_put_noidle(&pdev->dev); > >>> > >>> If we do this then the device usage count will not get decremented > >>> after the pm_runtime_resume_and_get() call above and after driver > >>> unload/load cycle it will not be possible to suspend the device. > >>> I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync() > >>> works better in that case. > >> > >> Good point. > >> > >> Actually, I don't see any reason why to call a PM resume > >> function - either being pm_runtime_get_sync() or > >> pm_runtime_resume_and_get(). > >> > >> The code there could simply be: > >> > >> static int gsc_remove(struct platform_device *pdev) > >> { > >> struct gsc_dev *gsc = platform_get_drvdata(pdev); > >> int i; > >> > >> gsc_unregister_m2m_device(gsc); > >> v4l2_device_unregister(&gsc->v4l2_dev); > >> > >> vb2_dma_contig_clear_max_seg_size(&pdev->dev); > >> for (i = 0; i < gsc->num_clocks; i++) > >> clk_disable_unprepare(gsc->clock[i]); > >> > >> pm_runtime_disable(&pdev->dev); > >> > >> dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); > >> return 0; > >> } > >> > >> Eventually also adding: > >> pm_runtime_suspended(&pdev->dev); > > > > In time: I actually meant: > > > > pm_runtime_set_suspended(&pdev->dev); > > > > but after double-checking the PM runtime code, it sounds to me that > > just calling pm_runtime_disable() would be enough. Not 100% sure > > here. Btw, some media drivers call it after pm_runtime_disable(), > > while others don't do. > > I think if the device is brought into suspended state (e.g. by > disabling clocks as above) the pm_runtime_set_suspended() call > should be there. IOW a following sequence: > > pm_runtime_disable(dev); > if (!pm_runtime_status_suspended(dev)) > /* put device into suspended state (disable clocks, > voltage regulators, assert GPIOs, etc. */ > pm_runtime_set_suspended(dev); Not sure if this would work, as the clock framework would try to do things like calling clk_pm_runtime_put(). Perhaps an alternative would be to just return an error if it can't resume PM runtime, e. g.: diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c index 9f41c2e7097a..d47d02c75484 100644 --- a/drivers/media/platform/exynos-gsc/gsc-core.c +++ b/drivers/media/platform/exynos-gsc/gsc-core.c @@ -1208,9 +1208,11 @@ static int gsc_probe(struct platform_device *pdev) static int gsc_remove(struct platform_device *pdev) { struct gsc_dev *gsc = platform_get_drvdata(pdev); - int i; + int ret, i; - pm_runtime_get_sync(&pdev->dev); + ret = pm_runtime_resume_and_get(&pdev->dev); + if (ret < 0) + return ret; gsc_unregister_m2m_device(gsc); v4l2_device_unregister(&gsc->v4l2_dev); Thanks, Mauro 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 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 D7EC4C433B4 for ; Wed, 28 Apr 2021 07:14:45 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F8CC601FC for ; Wed, 28 Apr 2021 07:14:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F8CC601FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=La6Ts/KTXEBMAEd+q4LuY4dtm5Fb7+kFEL2kyqWkXqE=; b=bjWdPnjSWB6WrsjTPbcCiNTp2 A9ghRRu+DolNZ8UOfd+XCXWqJepatGE3kHP1iEnYOeISWbxuR8lr1b+0OTNgq6P1Qj8w2QaYSLp5h ULFYisfuc7m5eza/SrJqEW+ccPzPbC7oX9m/zlyxF+fhvk78S4hE656FHPWKMnTU2Sj77siB+bYLs RhFrQii189Wx0/oJYBJPOwg8/L+Wj+6SPdWmt4c4LQNsUR9L4uHR9q+v9xOVeVP9cV1M5IJrNFvwe WcTmBARneUKM1phGeKI4KBNZyZoKTSsAOqIBKfkprWMYTAMSnTZNUKU8fIWQmn7APKtBAQNmeN4dk DY69aN0bg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lbeNp-0032MS-0a; Wed, 28 Apr 2021 07:13:17 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbeNk-0032MG-91 for linux-arm-kernel@desiato.infradead.org; Wed, 28 Apr 2021 07:13:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Sender:Reply-To:Content-ID:Content-Description; bh=+C+FMCs/aDlbj23jAgNohs7S5YsSJG3EBgGkq41o5cw=; b=H5iiTGSEuzVTJlVFHPrL/mFQ7C ZZ5oG82k+RRyGKKSf6Dvy3IjTnAZ8+opk3oexBciAtWRzTyqw34+frGszruqwUkusjB89y9hr/bYt ohYWsMerDDUhuFF4D6TkXeAo1jGhdXg4u9F8CYKxFEcYWcm323JwzUSabTWvj9BrgZJblVu0s4Bfm qbechh8CYW9cbB44zuRU//Q2SdRAVmQXeGp6I5cHzrHsV0zJCGFoyk4r1g+1aDnaZexgJwUXX6D+s V26NWFruhESaei3chJFfT6LvNK0ynZmaC7VbCT63+mWzpabzVgEJpZcFgFeIJYAtQAc+aajzWtdkv V5/kstYg==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbeNh-00HF4J-Ia for linux-arm-kernel@lists.infradead.org; Wed, 28 Apr 2021 07:13:11 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 235D4601FC; Wed, 28 Apr 2021 07:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619593988; bh=vtrlu5NLjbjl/L0tLDBVhlFvjRnFBvLZFZImEEWL/Kk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ASBSV4p3ulPv6GeE1EBbPsFhZFJ1rt+T2/fgFgVHaSSfDBmaXJ6jMnj4uIXzWZAif 52hCdOB9hI0jNZcosW6vQuQSbJHgqaXCtBhEreWRKeBCo+DgiGEeJpwRgwaiGKuPm0 iXkKeSc3++o0Zec4DrZuAjSsLmhPqysBNEeYT291HbxWt6zxxetc/7aeKcnQeD+BEs MJolRy7Vb3GItE3x/agrXCYfFL/R/iYOLARwkY4nYjI2eAWvNSfiz1t6OieD5dZQ6H E4vgkcykWfEKqRkIbSuQu2fRPgj0s9+E0RG1GEiT2Vb14Gz5vTM3ksc4H0KD6gsyRn ClKUXZOd+KNbA== Date: Wed, 28 Apr 2021 09:13:02 +0200 From: Mauro Carvalho Chehab To: Sylwester Nawrocki Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Ezequiel Garcia , Hans Verkuil , Krzysztof Kozlowski , Mauro Carvalho Chehab , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get() Message-ID: <20210428091302.64af1e5d@coco.lan> In-Reply-To: <5f6088c7-c839-f097-737f-b4234c413eac@samsung.com> References: <9c7d683907b9f9cf4a99f57f978671ec7f5a1dbc.1619191723.git.mchehab+huawei@kernel.org> <20210427113055.745d0560@coco.lan> <20210427114235.45a7b2a4@coco.lan> <5f6088c7-c839-f097-737f-b4234c413eac@samsung.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210428_001309_722513_BF44C10F X-CRM114-Status: GOOD ( 32.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Em Tue, 27 Apr 2021 13:50:44 +0200 Sylwester Nawrocki escreveu: > On 27.04.2021 11:42, Mauro Carvalho Chehab wrote: > > Em Tue, 27 Apr 2021 11:30:55 +0200 > > Mauro Carvalho Chehab escreveu: > > > >> Em Tue, 27 Apr 2021 10:18:12 +0200 > >> Sylwester Nawrocki escreveu: > >> > >>> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote: > >>>> Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") > >>>> added pm_runtime_resume_and_get() in order to automatically handle > >>>> dev->power.usage_count decrement on errors. > >>>> > >>>> Use the new API, in order to cleanup the error check logic. > >>>> > >>>> Signed-off-by: Mauro Carvalho Chehab > >>>> --- > >>>> drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- > >>>> drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- > >>>> 2 files changed, 2 insertions(+), 3 deletions(-) > >>>> > >>>> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c > >>>> index 9f41c2e7097a..9d5841194f6b 100644 > >>>> --- a/drivers/media/platform/exynos-gsc/gsc-core.c > >>>> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c > >>>> @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev) > >>>> struct gsc_dev *gsc = platform_get_drvdata(pdev); > >>>> int i; > >>>> > >>>> - pm_runtime_get_sync(&pdev->dev); > >>>> + pm_runtime_resume_and_get(&pdev->dev); > >>>> > >>>> gsc_unregister_m2m_device(gsc); > >>>> v4l2_device_unregister(&gsc->v4l2_dev); > >>>> @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev) > >>>> for (i = 0; i < gsc->num_clocks; i++) > >>>> clk_disable_unprepare(gsc->clock[i]); > >>>> > >>>> - pm_runtime_put_noidle(&pdev->dev); > >>> > >>> If we do this then the device usage count will not get decremented > >>> after the pm_runtime_resume_and_get() call above and after driver > >>> unload/load cycle it will not be possible to suspend the device. > >>> I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync() > >>> works better in that case. > >> > >> Good point. > >> > >> Actually, I don't see any reason why to call a PM resume > >> function - either being pm_runtime_get_sync() or > >> pm_runtime_resume_and_get(). > >> > >> The code there could simply be: > >> > >> static int gsc_remove(struct platform_device *pdev) > >> { > >> struct gsc_dev *gsc = platform_get_drvdata(pdev); > >> int i; > >> > >> gsc_unregister_m2m_device(gsc); > >> v4l2_device_unregister(&gsc->v4l2_dev); > >> > >> vb2_dma_contig_clear_max_seg_size(&pdev->dev); > >> for (i = 0; i < gsc->num_clocks; i++) > >> clk_disable_unprepare(gsc->clock[i]); > >> > >> pm_runtime_disable(&pdev->dev); > >> > >> dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); > >> return 0; > >> } > >> > >> Eventually also adding: > >> pm_runtime_suspended(&pdev->dev); > > > > In time: I actually meant: > > > > pm_runtime_set_suspended(&pdev->dev); > > > > but after double-checking the PM runtime code, it sounds to me that > > just calling pm_runtime_disable() would be enough. Not 100% sure > > here. Btw, some media drivers call it after pm_runtime_disable(), > > while others don't do. > > I think if the device is brought into suspended state (e.g. by > disabling clocks as above) the pm_runtime_set_suspended() call > should be there. IOW a following sequence: > > pm_runtime_disable(dev); > if (!pm_runtime_status_suspended(dev)) > /* put device into suspended state (disable clocks, > voltage regulators, assert GPIOs, etc. */ > pm_runtime_set_suspended(dev); Not sure if this would work, as the clock framework would try to do things like calling clk_pm_runtime_put(). Perhaps an alternative would be to just return an error if it can't resume PM runtime, e. g.: diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c index 9f41c2e7097a..d47d02c75484 100644 --- a/drivers/media/platform/exynos-gsc/gsc-core.c +++ b/drivers/media/platform/exynos-gsc/gsc-core.c @@ -1208,9 +1208,11 @@ static int gsc_probe(struct platform_device *pdev) static int gsc_remove(struct platform_device *pdev) { struct gsc_dev *gsc = platform_get_drvdata(pdev); - int i; + int ret, i; - pm_runtime_get_sync(&pdev->dev); + ret = pm_runtime_resume_and_get(&pdev->dev); + if (ret < 0) + return ret; gsc_unregister_m2m_device(gsc); v4l2_device_unregister(&gsc->v4l2_dev); Thanks, Mauro _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel