From patchwork Thu Feb 22 11:31:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 204694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp189030dyb; Thu, 22 Feb 2024 03:34:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXasd/mf6dQtqu+rXJmc48T96FXDCF++kgJpAuz6tylwyGDjgyud7U5Nwlvjf1ensgF4n0w2L2TMT5RpR7gq0GzJgMilg== X-Google-Smtp-Source: AGHT+IE5byQZ8TVShK4GyZcRnQmisFqx06/lYIkcb4FZ3P6dYiPnVVrslUkO76yISh6iSMjfeMQq X-Received: by 2002:a05:6358:57a8:b0:17b:5c7c:2801 with SMTP id m40-20020a05635857a800b0017b5c7c2801mr4575497rwf.14.1708601661418; Thu, 22 Feb 2024 03:34:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708601661; cv=pass; d=google.com; s=arc-20160816; b=M6wotPNIcCExdMLw3ZeuiZhG+qqxy6PTJuxgWAzLyk1oFAYnay1S4Zjct1TqTegQCU qxmubWE+U1Mvjsnf/qKpUNG801LOHgPIls53dA9RCZaiuwW14mbdSNNJaF7PHUQY3Sl4 wW5l/32J6WDD4E+zb7p9jM1NGooCO656e0mPE49bHY3cZtbYDDd/TkYqkpdFOVDCJsqH Qe1W8Xtz+QogUl0aKfS+VMGdaAP2Vstprna0PEJn/6Xfy/voyGRdTyX+34xfNudYyZgu Tcdemqsh5a7aoYkskYOFSJAaTrz3pAZgaRB2WYLzX3+VRwTjDCxY5ssY4TNxb1oDDCJR eDXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=/i192URWf1TmsQf1cjCbx2z4wkXH+kCVVw7/yDHFIIc=; fh=7Ze5xPQXuwRxFNHD2ILqwMPZ5wjg3PcSuREjIh8VhDo=; b=K9OQsNDyXw5mzfB/dz8p2nEoj+ty6hne+cJc7wqKuRGZB6YkgYl5eOLt0+bISzQsD8 KDmWS/+EemSvtfV+rGgNkwwVgpX56yGu+5YZ7PTomoJPqAAR/pLwZ6yHs+ad6LvvnzQY blA9HfIyWyBnLpJ/JEDifWZjmAd5g8zqKGXTGl1d3EhrGVE6XDFXAQ9p0hjOneDeJdsh nJZbZ4N7/bHLHx8m9UoBAZcNBEcojGVOs3M53m+lTcRY94U9CCoUrSf/L5rzI8EOqiPQ B72jXEONkyZyijDYismYovG+TlGT37OLABBrkHTNnq5wN2upckjP9Qs6x0cctbihNOq0 du3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=chrMIB7d; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-76415-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76415-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a185-20020a6390c2000000b005cddfe0c82bsi9948193pge.211.2024.02.22.03.34.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:34:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76415-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=chrMIB7d; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-76415-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76415-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 347E7282256 for ; Thu, 22 Feb 2024 11:34:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B85E8481A5; Thu, 22 Feb 2024 11:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="chrMIB7d" Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CF4E3FB27; Thu, 22 Feb 2024 11:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708601607; cv=none; b=ejzlw6zrufrQQMexCS0Ok2d8Yl9k/K/dR83qFG/9t4XPA3IDWzD4t5dCQM4renyqq3+FfuJz/c8y3lYkxQS0LitT1xwPf1DwTUniQY7POmbKA5fVPsGEZLKiBicXg6my3qNr4PXS9n9SUoAR10zoryYaZpMHav+c3Koa57CUmCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708601607; c=relaxed/simple; bh=awIpiB7+rPodbBNyQqhDBuuBw28/P0JB2hHzrKB5VA4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=t39wjWHcZQ5zpm+aPAMdEjv//S3tb22ebY97ghoLHruBBP/lFBDG6zqg9uhXtpuAsTLzAyiFMdr2QZyXWAk1sG3Juv+RB+kiIa/2MzPjHZ9ppGVw76sM09uxHs3Mi75xh1g1yEQbvZn16niZZLdI3a50GkIzWlQvilf5hUq+v2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=chrMIB7d; arc=none smtp.client-ip=198.47.19.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 41MBXB5o059128; Thu, 22 Feb 2024 05:33:11 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1708601591; bh=/i192URWf1TmsQf1cjCbx2z4wkXH+kCVVw7/yDHFIIc=; h=From:Date:Subject:References:In-Reply-To:To:CC; b=chrMIB7dp3IKQEymdm3CWvDJVVSoZfG0hEMJxegDDTlwcQIjaP9MYC+lvDwnKIXm3 A6gIdV5pStPsmzC3yVWiVwOXS4PGwQYdaE90KeZ4qXFiJm/vFBuhIPp0oKmvaROS8F zCxOSKZZNyaYBx5lNzl1N5olUB+ut9SfHQ0HZp18= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 41MBXBJP059184 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 22 Feb 2024 05:33:11 -0600 Received: from DLEE101.ent.ti.com (157.170.170.31) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Thu, 22 Feb 2024 05:33:11 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE101.ent.ti.com (157.170.170.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Thu, 22 Feb 2024 05:33:10 -0600 Received: from localhost (jluthra.dhcp.ti.com [172.24.227.217]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 41MBX9Xf090998; Thu, 22 Feb 2024 05:33:10 -0600 From: Jai Luthra Date: Thu, 22 Feb 2024 17:01:19 +0530 Subject: [PATCH RFC 03/21] media: cadence: csi2rx: Support runtime PM Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <20240222-multistream-v1-3-1837ed916eeb@ti.com> References: <20240222-multistream-v1-0-1837ed916eeb@ti.com> In-Reply-To: <20240222-multistream-v1-0-1837ed916eeb@ti.com> To: Tomi Valkeinen , Mauro Carvalho Chehab , Sakari Ailus , Hans Verkuil , Vaishnav Achath , Maxime Ripard , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: , , , Vignesh Raghavendra , Aradhya Bhatia , Devarsh Thakkar , Changhuang Liang , Jack Zhu , Julien Massot , Jayshri Pawar , Jai Luthra X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3486; i=j-luthra@ti.com; h=from:subject:message-id; bh=gL2KFHtJC4ZaxiomDu0d9bCTf1l/780KtEZpDitoGVM=; b=owEBbQKS/ZANAwAIAUPekfkkmnFFAcsmYgBl1zDcRZ3wPVgXir6vjlfdPfIq2tLGr5W8ntgai IjeS9CnSIaJAjMEAAEIAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCZdcw3AAKCRBD3pH5JJpx RWSID/4y9uUWJ4VVRhH5Z8m4Ax0uHMLG/1DV4f6Oxvy5YHjlLCbnQYES2t7Sfi6MITcec60nqbL 3wz1HnCS5iNsOSATsfm3PtjfWdC32y+4DNCbYPWVg5VnA2wYMiqhhYlYdzFsBSbR1HPxXXo9PgP sHIEhIm/B3/H13dFjZg3wK9Rgw4HjX6e4s/bomaNSwB/+G/Jys56hvE5Oadcl9aCbJRWP1ohZcq DasQ03br2FebIWUmNI+BrNAh1J3PtxWc8E6SsgzXvhoeUT8FAuDUSzEKMrGr4JSkHz1beqxsFQa pGqhzBnn1omCZN+r1Zg5B5Bm+kwt2UTOcDwcstIQxEzgzqw7r7w2LQotTsoXyDfN3Z76r5Nj0za xpRtOIbwYy5PwTViofUWXqpstad7HyjS6LwQKjr8nvWy8IuvAe8psCWKHrNpWPvCLTM65s7nIWI 1jB4jfhlUvwexFUmXobQAizia8vHPkJnqjuW1lId0AtVfzuiBye5ZhzvJMBeGpxBHgXVsLcGhQs aCHqOdt659HM59/2CYf6Di3YzGvIY8lnX2/wwguCkSDlSCdoNlmPhHTDXTJzV6dKH3+3C6aaLbr X+0a6hxbJnbV7nriu2W/667n+zscIl4/SuCdtippfyskWfombECI3AsbC2Nkucd8UHxWFdFjBRn c3CcUeLsp/1Nyqw== X-Developer-Key: i=j-luthra@ti.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791598695696649004 X-GMAIL-MSGID: 1791598695696649004 From: Jayshri Pawar Use runtime power management hooks to save power when CSI-RX is not in use. Also stop/start any in-progress streams, which might happen during a system suspend/resume cycle. Signed-off-by: Jayshri Pawar Co-developed-by: Jai Luthra Signed-off-by: Jai Luthra --- drivers/media/platform/cadence/cdns-csi2rx.c | 43 +++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index 75e602c1d762..e19993ed351c 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -370,6 +370,12 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable) struct csi2rx_priv *csi2rx = v4l2_subdev_to_csi2rx(subdev); int ret = 0; + if (enable) { + ret = pm_runtime_resume_and_get(csi2rx->dev); + if (ret < 0) + return ret; + } + mutex_lock(&csi2rx->lock); if (enable) { @@ -379,8 +385,10 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable) */ if (!csi2rx->count) { ret = csi2rx_start(csi2rx); - if (ret) + if (ret) { + pm_runtime_put(csi2rx->dev); goto out; + } } csi2rx->count++; @@ -392,6 +400,8 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable) */ if (!csi2rx->count) csi2rx_stop(csi2rx); + + pm_runtime_put(csi2rx->dev); } out: @@ -665,6 +675,29 @@ static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx) return ret; } +static int csi2rx_suspend(struct device *dev) +{ + struct csi2rx_priv *csi2rx = dev_get_drvdata(dev); + + mutex_lock(&csi2rx->lock); + if (csi2rx->count) + csi2rx_stop(csi2rx); + mutex_unlock(&csi2rx->lock); + + return 0; +} + +static int csi2rx_resume(struct device *dev) +{ + struct csi2rx_priv *csi2rx = dev_get_drvdata(dev); + + mutex_lock(&csi2rx->lock); + if (csi2rx->count) + csi2rx_start(csi2rx); + mutex_unlock(&csi2rx->lock); + return 0; +} + static int csi2rx_probe(struct platform_device *pdev) { struct csi2rx_priv *csi2rx; @@ -711,6 +744,7 @@ static int csi2rx_probe(struct platform_device *pdev) if (ret) goto err_cleanup; + pm_runtime_enable(csi2rx->dev); ret = v4l2_async_register_subdev(&csi2rx->subdev); if (ret < 0) goto err_free_state; @@ -725,6 +759,7 @@ static int csi2rx_probe(struct platform_device *pdev) err_free_state: v4l2_subdev_cleanup(&csi2rx->subdev); + pm_runtime_disable(csi2rx->dev); err_cleanup: v4l2_async_nf_unregister(&csi2rx->notifier); v4l2_async_nf_cleanup(&csi2rx->notifier); @@ -743,9 +778,14 @@ static void csi2rx_remove(struct platform_device *pdev) v4l2_async_unregister_subdev(&csi2rx->subdev); v4l2_subdev_cleanup(&csi2rx->subdev); media_entity_cleanup(&csi2rx->subdev.entity); + pm_runtime_disable(csi2rx->dev); kfree(csi2rx); } +static const struct dev_pm_ops csi2rx_pm_ops = { + SET_RUNTIME_PM_OPS(csi2rx_suspend, csi2rx_resume, NULL) +}; + static const struct of_device_id csi2rx_of_table[] = { { .compatible = "starfive,jh7110-csi2rx" }, { .compatible = "cdns,csi2rx" }, @@ -760,6 +800,7 @@ static struct platform_driver csi2rx_driver = { .driver = { .name = "cdns-csi2rx", .of_match_table = csi2rx_of_table, + .pm = &csi2rx_pm_ops, }, }; module_platform_driver(csi2rx_driver);