From nobody Thu Apr 2 12:35:28 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010016.outbound.protection.outlook.com [52.101.85.16]) (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 5514F38911B; Fri, 13 Mar 2026 09:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773392968; cv=fail; b=QPyj48Gp4CP+jccvawcpr2W0WJj5DyBLoksw44AQZvmiaexg5/QqC67Zp3l7GUUmbr1HzJIUSXqxySx7nLdQSLvBmaTBIpyT0xc/3qtI24eh95rbGPlwJIu6MgwAHzSWmaTDxqdRhkKPDWnyjJIBs6ysEuF7HPPNjiLXCw+qDlA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773392968; c=relaxed/simple; bh=tU3uJjNszh3qKivEzdM14aWtAtALIZLzt8Ds7no8Xgs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IQT8ovZ63pKTHOK7T3/GhTAD/OwuwQ4z+s5Z/+wpW0ql+x51ucqQ3el+3Jffng7kDIc8Fhu+FLk7GUyv7yhPce90C8H4nksi4EdVFlYjsRkb01eOrzwWd+T3aYcogAUMyX2AlXu+MJTWZArmXUabq53L4TaGQhEbM9uck49v+jI= ARC-Authentication-Results: i=2; 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=rvyiY+u+; arc=fail smtp.client-ip=52.101.85.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="rvyiY+u+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tZVpNs2nOUh9fbJTq4dRzOGwilFnm84xkmpuvGc8ZRfMnD6fxRiRzOAAUVPyTMTv+BBArfOqZiZxv7RTU0MK/S6rv2L/Ckpl0bgT1AJOm/0+9lQCKXi/JGbK7ZAC7/gAzpVOksXY8GiuQT/hCRGtEOxhJYm/HnLGTzo0hzq1Rvjx2DHNTzjke6M0oy+NN8xLW8YPkxpLidSA3XROM/EYb9/diwaT7nUb2A95LaBxUHhfgt9HNHLDnq/owXa/jvVcpPApRpRcwOhNI6AOo5w75WOYNk+rBVsSU649FRSQc/qTdmVICWMv6vuoj7SrXoUFZfyCD9rU0GRuKXG8mjiapQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mtnbczT82O3/VOfxqppJVtMs94oF+v9mlNGVSF1FtrQ=; b=vuyk8xw+GCgv1/DqzyyNwEMmG6p8qP8P0dB6JN/vnQ/HYdjRSeC0oW1YoOLML4tNmkB2NqDjdz/fyYxIKohlUKv/XmML2DFMvTL9uCE7ApHLu0315srIY+MXjvCN53Aii+2Re78N/abGDHeX6OopW8hlf/Bf74Lh6Fm/adwVn0pin7WCHd73MlqCldYr98Ch7M4ZKDG6WFKo0XEUuSZyjFJufh29Vznyz0WqpS8/T2CAytGjAsYNaHVwbF82uYWDMLLm5PEpg1knK2Jy8lry9sUABSpQqILkXJALViRrz+L2kDuyhXl94mqgNEf5MqiNAcLb+NAg6Finz+ufOsNL+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.21.195) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mtnbczT82O3/VOfxqppJVtMs94oF+v9mlNGVSF1FtrQ=; b=rvyiY+u+a6J7eWSOOCijAtHYklaPipIHL6qOCTYiQZ2NIaLctejWg1PSOgWGWX6S14dVmWz3MmB2FuTgX9lLnbmLHH9DMdYTm7ZEl5LYBsbiVuv5L7mEX5iHa4Gj1nSyGyaRWe1hosEkDUBFKGujpDy+80zDGsMDOUwbq0iDskU= Received: from MN0PR02CA0017.namprd02.prod.outlook.com (2603:10b6:208:530::35) by LV3PR10MB8179.namprd10.prod.outlook.com (2603:10b6:408:28a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9700.15; Fri, 13 Mar 2026 09:09:24 +0000 Received: from BL02EPF0001A108.namprd05.prod.outlook.com (2603:10b6:208:530:cafe::c5) by MN0PR02CA0017.outlook.office365.com (2603:10b6:208:530::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9700.16 via Frontend Transport; Fri, 13 Mar 2026 09:09:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.21.195) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.21.195 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.21.195; helo=flwvzet201.ext.ti.com; pr=C Received: from flwvzet201.ext.ti.com (198.47.21.195) by BL02EPF0001A108.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9700.17 via Frontend Transport; Fri, 13 Mar 2026 09:09:22 +0000 Received: from DFLE201.ent.ti.com (10.64.6.59) by flwvzet201.ext.ti.com (10.248.192.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Fri, 13 Mar 2026 04:08:48 -0500 Received: from DFLE212.ent.ti.com (10.64.6.70) by DFLE201.ent.ti.com (10.64.6.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Fri, 13 Mar 2026 04:08:47 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DFLE212.ent.ti.com (10.64.6.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Fri, 13 Mar 2026 04:08:47 -0500 Received: from ws.dhcp.ti.com (ws.dhcp.ti.com [172.24.233.149]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 62D972bj274611; Fri, 13 Mar 2026 04:08:41 -0500 From: Rishikesh Donadkar To: , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v12 15/17] media: cadence: csi2rx: Support runtime PM Date: Fri, 13 Mar 2026 14:36:59 +0530 Message-ID: <20260313090701.646534-16-r-donadkar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260313090701.646534-1-r-donadkar@ti.com> References: <20260313090701.646534-1-r-donadkar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A108:EE_|LV3PR10MB8179:EE_ X-MS-Office365-Filtering-Correlation-Id: a80a339f-d410-43de-96c1-08de80e037ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|36860700016|82310400026|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: g8EBCJhXYeQ9P2TTT2JrVj96a2MzkbC9nDCuOKq+PqA3XzsoYGZXMgQSQWjxipLcNWpL6i/fvCu6iNgZUmKN/yGyoACi0mgCv337BXyqkgAe8J2taNVCPK8YlToxOPD2UJAD9IjUdSBaUNLVoIV9pGAEXef0tlnPOS3B0EsN+pvKUXR+jinNBqDkdlc8F1pEZOtNApD11MRL2sS1Xv8VBVWG8a3OXaENfrDp0P+MFuo1MUXMMQEEuawJJ5ki++ilVc5F1O3mGWwylBgZELec1txHkJSY9yFAFqmve+ehEq0on9lm7At51D6LK/+ovX+L3ZZOzmOIUsAFO54vJ4Sv4a6bUxWPWvpF+g74ChP/MwXQgDfb5H99aGqniMqT+MPs3GMDmZcSvfClHrqTx41UDWGlwTAByXezqss3kXNY6U3K2RVqmIdyNxjXNY4sas5rx++NnVNuIVJX3qYELMRGd0UQ7LfbdiyHhrbudesouijCStHrZ2lH6n5zIJBFcBLtfGiv+F6xfbEDMYUR8o5HNhgTehk0Czj9kO1neRTTf6v4SCSVUUrgNwLs1YJJg53gRfnNluXoIuwnnurzz/8t1Qr1TGWmO6LeJ+NIdBKZavB6fR/jGnMQTgRy59wOVZxafyolM5ESQ2Pqqhbz4vLCjnB4lihABqa+O1yBjeJQv3FGT0TQUCbCu0Zt1yi+lC7/BiQTIPM0KH0YOrKivQTDA0Ub5b1tl+MgUI2ejoHOcY+sZHJCuwLr25le2MuRwGJodHZxwt5EU/6J+VzbyubXCA== X-Forefront-Antispam-Report: CIP:198.47.21.195;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:flwvzet201.ext.ti.com;PTR:ErrorRetry;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(36860700016)(82310400026)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +1teycymBcWsVKqDXIfThEWpGmdy25xfzth/DtLGtpS1d2dHZBetnNbpUYmwHk04oC4NRROwIPa0+hLHkiH5We7WTEkaD8jdntQwnXziKd3ivHK16QFRD0vPxh5PELG1C4XBn49pPTjV9MGzoI3NjMVUbF5b2b5jjNQW3pylUYCEpAcHsuKpytxeA9Z1O+2yhsHnEt6tEklSDBpqO19/Py/0IrPYaj/Skfal68M1wxMrtqZQOgjUxHlnbQ0ZUXUkWif7bfha08kvrxS2INMewXl6+lvdjiPuh6Xiq0+nz2YCu8T5ZckSTHt/EMipZqMzfOjidAZnkBSdv0OkkzhAIBNwVhps1O4r7WU3LAK8wz299fFvY5Rs/4KIphDJts+FVRqHZhSnnBr3C/3CxQ+WlzM+II9pblEoItcHhJeEw8Vu6Nrrn1/OCo/Fd25zOtyA X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2026 09:09:22.9132 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a80a339f-d410-43de-96c1-08de80e037ca X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.21.195];Helo=[flwvzet201.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A108.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR10MB8179 Content-Type: text/plain; charset="utf-8" From: Changhuang Liang Use runtime power management hooks to save power when CSI-RX is not in use. Also, shift to goto based error handling in csi2rx_enable_streams() function Signed-off-by: Changhuang Liang Tested-by: Rishikesh Donadkar Reviewed-by: Rishikesh Donadkar Reviewed-by: Tomi Valkeinen Signed-off-by: Jai Luthra Signed-off-by: Rishikesh Donadkar --- drivers/media/platform/cadence/Kconfig | 1 + drivers/media/platform/cadence/cdns-csi2rx.c | 136 ++++++++++++------- 2 files changed, 88 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/cadence/Kconfig b/drivers/media/platfor= m/cadence/Kconfig index 1aa608c00dbce..ea85ef82760e6 100644 --- a/drivers/media/platform/cadence/Kconfig +++ b/drivers/media/platform/cadence/Kconfig @@ -5,6 +5,7 @@ comment "Cadence media platform drivers" config VIDEO_CADENCE_CSI2RX tristate "Cadence MIPI-CSI2 RX Controller" depends on VIDEO_DEV + depends on PM select MEDIA_CONTROLLER select VIDEO_V4L2_SUBDEV_API select V4L2_FWNODE diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/p= latform/cadence/cdns-csi2rx.c index f34df341a2cac..18737d00a7d7a 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -340,11 +340,6 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) u32 reg; int ret; =20 - ret =3D clk_prepare_enable(csi2rx->p_clk); - if (ret) - return ret; - - reset_control_deassert(csi2rx->p_rst); csi2rx_reset(csi2rx); =20 if (csi2rx->error_irq >=3D 0) @@ -385,7 +380,7 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) if (ret) { dev_err(csi2rx->dev, "Failed to configure external DPHY: %d\n", ret); - goto err_disable_pclk; + return ret; } } =20 @@ -400,12 +395,6 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) * hence the reference counting. */ for (i =3D 0; i < csi2rx->max_streams; i++) { - ret =3D clk_prepare_enable(csi2rx->pixel_clk[i]); - if (ret) - goto err_disable_pixclk; - - reset_control_deassert(csi2rx->pixel_rst[i]); - writel(CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF | FIELD_PREP(CSI2RX_STREAM_CFG_NUM_PIXELS_MASK, csi2rx->num_pixels[i]), @@ -418,30 +407,8 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) csi2rx->base + CSI2RX_STREAM_CTRL_REG(i)); } =20 - ret =3D clk_prepare_enable(csi2rx->sys_clk); - if (ret) - goto err_disable_pixclk; - - reset_control_deassert(csi2rx->sys_rst); - - clk_disable_unprepare(csi2rx->p_clk); =20 return 0; - -err_disable_pixclk: - for (; i > 0; i--) { - reset_control_assert(csi2rx->pixel_rst[i - 1]); - clk_disable_unprepare(csi2rx->pixel_clk[i - 1]); - } - - if (csi2rx->dphy) { - writel(0, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG); - phy_power_off(csi2rx->dphy); - } -err_disable_pclk: - clk_disable_unprepare(csi2rx->p_clk); - - return ret; } =20 static void csi2rx_stop(struct csi2rx_priv *csi2rx) @@ -450,10 +417,6 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx) u32 val; int ret; =20 - clk_prepare_enable(csi2rx->p_clk); - reset_control_assert(csi2rx->sys_rst); - clk_disable_unprepare(csi2rx->sys_clk); - writel(0, csi2rx->base + CSI2RX_ERROR_IRQS_MASK_REG); =20 for (i =3D 0; i < csi2rx->max_streams; i++) { @@ -468,14 +431,8 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx) if (ret) dev_warn(csi2rx->dev, "Failed to stop streaming on pad%u\n", i); - - reset_control_assert(csi2rx->pixel_rst[i]); - clk_disable_unprepare(csi2rx->pixel_clk[i]); } =20 - reset_control_assert(csi2rx->p_rst); - clk_disable_unprepare(csi2rx->p_clk); - if (csi2rx->dphy) { writel(0, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG); =20 @@ -549,10 +506,15 @@ static int csi2rx_enable_streams(struct v4l2_subdev *= subdev, * enable the whole controller. */ if (!csi2rx->count) { + ret =3D pm_runtime_resume_and_get(csi2rx->dev); + if (ret < 0) + goto err; + csi2rx_update_vc_select(csi2rx, state); + ret =3D csi2rx_start(csi2rx); if (ret) - return ret; + goto err_put_pm; } =20 /* Start streaming on the source */ @@ -562,13 +524,20 @@ static int csi2rx_enable_streams(struct v4l2_subdev *= subdev, dev_err(csi2rx->dev, "Failed to start streams %#llx on subdev\n", sink_streams); - if (!csi2rx->count) - csi2rx_stop(csi2rx); - return ret; + goto err_stop_csi; } =20 csi2rx->count++; return 0; + +err_stop_csi: + if (!csi2rx->count) + csi2rx_stop(csi2rx); +err_put_pm: + if (!csi2rx->count) + pm_runtime_put(csi2rx->dev); +err: + return ret; } =20 static int csi2rx_disable_streams(struct v4l2_subdev *subdev, @@ -590,8 +559,10 @@ static int csi2rx_disable_streams(struct v4l2_subdev *= subdev, csi2rx->count--; =20 /* Let the last user turn off the lights. */ - if (!csi2rx->count) + if (!csi2rx->count) { csi2rx_stop(csi2rx); + pm_runtime_put(csi2rx->dev); + } =20 return 0; } @@ -1078,6 +1049,7 @@ static int csi2rx_probe(struct platform_device *pdev) if (ret) goto err_cleanup; =20 + pm_runtime_enable(csi2rx->dev); ret =3D v4l2_async_register_subdev(&csi2rx->subdev); if (ret < 0) goto err_free_state; @@ -1092,6 +1064,7 @@ static int csi2rx_probe(struct platform_device *pdev) =20 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); @@ -1110,9 +1083,73 @@ static void csi2rx_remove(struct platform_device *pd= ev) v4l2_async_unregister_subdev(&csi2rx->subdev); v4l2_subdev_cleanup(&csi2rx->subdev); media_entity_cleanup(&csi2rx->subdev.entity); + pm_runtime_disable(csi2rx->dev); kfree(csi2rx); } =20 +static int csi2rx_runtime_suspend(struct device *dev) +{ + struct csi2rx_priv *csi2rx =3D dev_get_drvdata(dev); + unsigned int i; + + reset_control_assert(csi2rx->sys_rst); + clk_disable_unprepare(csi2rx->sys_clk); + + for (i =3D 0; i < csi2rx->max_streams; i++) { + reset_control_assert(csi2rx->pixel_rst[i]); + clk_disable_unprepare(csi2rx->pixel_clk[i]); + } + + reset_control_assert(csi2rx->p_rst); + clk_disable_unprepare(csi2rx->p_clk); + + return 0; +} + +static int csi2rx_runtime_resume(struct device *dev) +{ + struct csi2rx_priv *csi2rx =3D dev_get_drvdata(dev); + unsigned int i; + int ret; + + ret =3D clk_prepare_enable(csi2rx->p_clk); + if (ret) + return ret; + + reset_control_deassert(csi2rx->p_rst); + + for (i =3D 0; i < csi2rx->max_streams; i++) { + ret =3D clk_prepare_enable(csi2rx->pixel_clk[i]); + if (ret) + goto err_disable_pixclk; + + reset_control_deassert(csi2rx->pixel_rst[i]); + } + + ret =3D clk_prepare_enable(csi2rx->sys_clk); + if (ret) + goto err_disable_pixclk; + + reset_control_deassert(csi2rx->sys_rst); + + return 0; + +err_disable_pixclk: + for (; i > 0; i--) { + reset_control_assert(csi2rx->pixel_rst[i - 1]); + clk_disable_unprepare(csi2rx->pixel_clk[i - 1]); + } + + reset_control_assert(csi2rx->p_rst); + clk_disable_unprepare(csi2rx->p_clk); + + return ret; +} + +static const struct dev_pm_ops csi2rx_pm_ops =3D { + RUNTIME_PM_OPS(csi2rx_runtime_suspend, csi2rx_runtime_resume, NULL) +}; + static const struct of_device_id csi2rx_of_table[] =3D { { .compatible =3D "starfive,jh7110-csi2rx" }, { .compatible =3D "cdns,csi2rx" }, @@ -1127,6 +1164,7 @@ static struct platform_driver csi2rx_driver =3D { .driver =3D { .name =3D "cdns-csi2rx", .of_match_table =3D csi2rx_of_table, + .pm =3D &csi2rx_pm_ops, }, }; module_platform_driver(csi2rx_driver); --=20 2.34.1