From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013059.outbound.protection.outlook.com [40.107.201.59]) (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 4E7563DB96F; Wed, 20 May 2026 12:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.59 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779278591; cv=fail; b=PDsiMBK1WQbbGLMxjQwhv4o3cNzmG7rSrtnu6vjkPq75KGc/d06msIwNpiTxYHTtkrg0ux3sb2pgnpXUu65RmbluZ21Ye7ACYFpmBq+7G14x8KgOEJ9a45ZJgqIB8v5xsiwFWK0ZYRWaExZt/fIrdYsF7b6pHXeS4njM0CGKsKE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779278591; c=relaxed/simple; bh=p2I3U5tUYTnDQsaB1y5IgLWUuI8k2K+uERxS1owg/yw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FHqzEvpRTp8TlQL0xHfFIGVs3kXBaU6zkVW9eNEZcYCVn3xMS3Vt3X+9SAHFeUm3121wfvRHAuse6B/5v/i8cP+oTfLcmnFBxTPAgXwq8rguaoduiRYjIXI5Gw22SBYpXHaY3aRshzrZWj92NFnbaYWEZRIo90b+bZg/skPnUtk= 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=eO32vCLr; arc=fail smtp.client-ip=40.107.201.59 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="eO32vCLr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=haylHHUyj+Q2XzNoOtUc8KzyXfzyXj+PQDQ2/DVpkvCaovM4tmLp/P3C3ml3qfGQvtY5mppb6It17H2lIaSNFGbnnqF+ef8/VOAATKTnMYT4SVFdfNYQoSkC2FghQFNYcQEXKK0D/fZndaM6QrDCJ6jMWU00HKJtH6oYCdrfFCHp4laz4nGkdm9BF7MuIEmuuJYyHHTeaWQrmLG6zmr5tYfUBt2pTUKnr9VDIjwyxL6tq9KGJ+TWPZJQylXXgBz500OOWSnFOm6/o/0MXRTnpfJLafpXo26xyjsTSiL50ffRuoBP9LT6wNauEdHiGq3h3ela+uUJ9gCs7mCQO4481w== 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=iAMHx8PaG38Jo0f1m+PhhXaSsKmtBre3W6k0tMePoa8=; b=cT3mTOO3U270Jqj1rsTeBV/K/JA/EAJbLVQCLBoYWnhSoY0xaKlSZUFJdPXHVc1Q8Dgm8BiCo+OzC5m8qTWFJZx0ZQpOLabbfMchdjRpq3gsG5VLjDl8MjV6XEVtx+/FiIewPMZ41fYUW3kqjRMYQTMbr9pgZn/9LQS+2vz14emLCx5T9v4RKHxvLrQFHK0rueZRwLc+zQ0vfgCjAwPcn/upAs8GGl0pPIU+7gZbJvVPjIc3vFmsP3OVXzxFRkpb8wZ6lxXOsnL91ATEFPvL4icM8gg5ijrxyykpN8wXCwZ2A3kIq9HPnvNxkKaYVTlQSLsrCLgLUNgLdZkSpT8csA== 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=iAMHx8PaG38Jo0f1m+PhhXaSsKmtBre3W6k0tMePoa8=; b=eO32vCLrp3aqT9RB4DdavwsTx8VV6GXSsk77KNuPyYPc3dMbZ+kaVdNZIBS/Nk2ocZIhaB1GPWnLRhtNX/qqQ27PvNK4+ntD/6eyQ+d9EqIhKfksv1DF3b1krBr9L/LRCbfYFYv6gA83hQHs5luSwMpQEQNsyVOJSEkyfss62k4= Received: from BN9PR03CA0536.namprd03.prod.outlook.com (2603:10b6:408:131::31) by PH8PR10MB6526.namprd10.prod.outlook.com (2603:10b6:510:22a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.14; Wed, 20 May 2026 12:03:03 +0000 Received: from BN3PEPF0000B072.namprd04.prod.outlook.com (2603:10b6:408:131:cafe::5d) by BN9PR03CA0536.outlook.office365.com (2603:10b6:408:131::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.14 via Frontend Transport; Wed, 20 May 2026 12:03:03 +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 BN3PEPF0000B072.mail.protection.outlook.com (10.167.243.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Wed, 20 May 2026 12:03:02 +0000 Received: from DFLE207.ent.ti.com (10.64.6.65) 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.37; Wed, 20 May 2026 07:02:17 -0500 Received: from DFLE215.ent.ti.com (10.64.6.73) by DFLE207.ent.ti.com (10.64.6.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Wed, 20 May 2026 07:02:17 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DFLE215.ent.ti.com (10.64.6.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37 via Frontend Transport; Wed, 20 May 2026 07:02:17 -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 64KC0N3e1914726; Wed, 20 May 2026 07:02:10 -0500 From: Rishikesh Donadkar To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v13 15/17] media: cadence: csi2rx: Support runtime PM Date: Wed, 20 May 2026 17:30:20 +0530 Message-ID: <20260520120022.539913-16-r-donadkar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260520120022.539913-1-r-donadkar@ti.com> References: <20260520120022.539913-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: 8bit Content-Type: text/plain X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B072:EE_|PH8PR10MB6526:EE_ X-MS-Office365-Filtering-Correlation-Id: ee2138f0-6ff9-4112-a1b2-08deb667be7f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|7416014|376014|36860700016|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: VzB38vxSuCcmAEqdS74GlMTosegCFoxhNCoiNe9fsFbfp90eRJp+Qf5GRwXhZJukMkTTpJSm6aFa4mRnzGcrb5XkD7xkQAdqNEdAGqjnj//SsF6CzXNQBoSvjlwDssk5QXKuof7olHA9uh7ufEHFAgXQhojz9cPT1grtBLY2w6lMQhNFPfLi/nl3WRcJ7Vzl2kZHIXPeyNoV5QbN3H4WIuu1MJ1i9fj3P2p2Jla/5bgHIsUmau6taJeYVglJPIYGi5l8TSU9FTTq9DoN/APaCRJPgQSarZ/uPSvdBm1rbTztdr0oPpf5w9Cq9IE1r4rjsnZk4gQLnHIDwTnBaX7+NVSNui4wKheRcjbq569emxJaYi5jhXw22raIUFsaI6KPu0Rqe9y0UA76KalEl+FeQtTqlV2uN4s8CAVpNvQ6wsFTYV/LLzDA3+MCTHjCgkbi9+zfVXI412UYJwisTagAFA89b9OokyV24Qz3kC4Pi1IVK/W0RW8MerNsa3XEGAAR9TWE47xj0amTzlFmy9UU3QZOhx3x4NgWUIDCHcqZfHYosFiRV8xDaExfUKD1BaJTMN4fkTHuxKfZmjoV+p9XWghSd4Bo7nspjbfZeP8PMNclGF/LOtm9E5fGLoPajJbRa+L3jXJA5c7Y69ww6nB6RqOfx+2ifugLEpo17fJC+qP1/vbK/sHa02CcRDbSDcion+GVoe3yOyV5KBDOq3CP6C4Nl3r7pqmH31eREVhAWr4= 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)(82310400026)(1800799024)(7416014)(376014)(36860700016)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ahPELCta54diYvVPvGBonph0CXL+MfDU5m35qpBtDadf9OVMz/em0c1QEiKaTmGWjqAQ8UFiDP/Pszerj0xKIYXie9JN8kvsikY6p1usukbV8RlI+0Ho0Ip0vs7+RFyFoyEyxR7Jq9BeldcSqaAjX/ZhJ0doYsBQPSdMVN6o+yGBrMt7n6fFtbDHlfovqTVujFiMNSqVE4YXCkLlCGMM7ZICUfO985c21wzSjY4rLEDVoloBcek06+CKjshgXh/gFbbWm/4bzcvq/ZlKU3jCqHpyKkGCYO+lKCSx5vnHy8AwS10GFloYb1ueOr1pdGmNX1k5tOH6z7vS2m50Wh9tntM0wCk5wv5ETcxWSTcMIbb8uZPCutqcX5SkXDSZoBKuMZA4q/T6SVICveiQorWpaMKJ9f+vVmwaFxO6tisXOg7AfiyQcptYSLkXSd+Liqq7 X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2026 12:03:02.5761 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ee2138f0-6ff9-4112-a1b2-08deb667be7f 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: BN3PEPF0000B072.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6526 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 | 135 ++++++++++++------- 2 files changed, 87 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/cadence/Kconfig b/drivers/media/platform/cadence/Kconfig index 1aa608c00dbc..ea85ef82760e 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/platform/cadence/cdns-csi2rx.c index 8931e824c597..1ff2d8f78d5b 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; - ret = clk_prepare_enable(csi2rx->p_clk); - if (ret) - return ret; - - reset_control_deassert(csi2rx->p_rst); csi2rx_reset(csi2rx); if (csi2rx->error_irq >= 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; } } @@ -400,12 +395,6 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) * hence the reference counting. */ for (i = 0; i < csi2rx->max_streams; i++) { - ret = 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)); } - ret = clk_prepare_enable(csi2rx->sys_clk); - if (ret) - goto err_disable_pixclk; - - reset_control_deassert(csi2rx->sys_rst); - - clk_disable_unprepare(csi2rx->p_clk); 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; } static void csi2rx_stop(struct csi2rx_priv *csi2rx) @@ -450,10 +417,6 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx) u32 val; int ret; - 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); for (i = 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]); } - reset_control_assert(csi2rx->p_rst); - clk_disable_unprepare(csi2rx->p_clk); - if (csi2rx->dphy) { writel(0, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG); @@ -549,10 +506,15 @@ static int csi2rx_enable_streams(struct v4l2_subdev *subdev, * enable the whole controller. */ if (!csi2rx->count) { + ret = pm_runtime_resume_and_get(csi2rx->dev); + if (ret < 0) + goto err; + csi2rx_update_vc_select(csi2rx, state); + ret = csi2rx_start(csi2rx); if (ret) - return ret; + goto err_put_pm; } /* 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; } 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; } static int csi2rx_disable_streams(struct v4l2_subdev *subdev, @@ -590,8 +559,10 @@ static int csi2rx_disable_streams(struct v4l2_subdev *subdev, csi2rx->count--; /* Let the last user turn off the lights. */ - if (!csi2rx->count) + if (!csi2rx->count) { csi2rx_stop(csi2rx); + pm_runtime_put(csi2rx->dev); + } return 0; } @@ -1019,6 +990,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; @@ -1033,6 +1005,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); @@ -1051,9 +1024,72 @@ 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 int csi2rx_runtime_suspend(struct device *dev) +{ + struct csi2rx_priv *csi2rx = dev_get_drvdata(dev); + + reset_control_assert(csi2rx->sys_rst); + clk_disable_unprepare(csi2rx->sys_clk); + + for (unsigned int i = 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 = dev_get_drvdata(dev); + unsigned int i; + int ret; + + ret = clk_prepare_enable(csi2rx->p_clk); + if (ret) + return ret; + + reset_control_deassert(csi2rx->p_rst); + + for (i = 0; i < csi2rx->max_streams; i++) { + ret = clk_prepare_enable(csi2rx->pixel_clk[i]); + if (ret) + goto err_disable_pixclk; + + reset_control_deassert(csi2rx->pixel_rst[i]); + } + + ret = clk_prepare_enable(csi2rx->sys_clk); + if (ret) + goto err_disable_pixclk; + + reset_control_deassert(csi2rx->sys_rst); + + return 0; + +err_disable_pixclk: + while (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 ret; +} + +static const struct dev_pm_ops csi2rx_pm_ops = { + RUNTIME_PM_OPS(csi2rx_runtime_suspend, csi2rx_runtime_resume, NULL) +}; + static const struct of_device_id csi2rx_of_table[] = { { .compatible = "starfive,jh7110-csi2rx" }, { .compatible = "cdns,csi2rx" }, @@ -1068,6 +1104,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); -- 2.34.1