From patchwork Tue Feb 20 10:43:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13563858 X-Patchwork-Delegate: geert@linux-m68k.org Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACA66626C6; Tue, 20 Feb 2024 10:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425831; cv=none; b=NS8Af+Pi48/hvxuqMTNVswKasYmpi1qvlzj4gut/x4KPnKgpEBkHuiU3paYOOiRuAI5byx1OuZ9HYgY6dB9vPi4ghpfQbw+H6p7Gp37x6q8Ylq+dBnycUcn7QUImZUQakNMg5XX6L/iViYm1z0Le1s5FxYZOftCiOM+ts6QxCqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425831; c=relaxed/simple; bh=xR+waViZbIHoeeUUPDFUbXsbVqEikabY6gu0aDYi7x0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ghpegpe0ODlpZiPmrSzpiMVRXzwY8w1EN11t0lwd9+qz3A3sD4fESB78kpXb5V4/ACNeBNUToEy/mEyOfyGK63zUwuzrY6jYViOwLc+9luaCBqvPJ4W57QKghFq12evoOnS1Uj9maiaQUdPann/YyDSQWDyuN7XuFbSHwlilVcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.06,172,1705330800"; d="scan'208";a="194579410" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 20 Feb 2024 19:43:47 +0900 Received: from localhost.localdomain (unknown [10.226.92.246]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 976D64001942; Tue, 20 Feb 2024 19:43:43 +0900 (JST) From: Biju Das To: Michael Turquette , Stephen Boyd , Sakari Ailus , Laurent Pinchart , Russell King Cc: Biju Das , linux-clk@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 1/3] clk: Update API documentation related to clock disable Date: Tue, 20 Feb 2024 10:43:34 +0000 Message-Id: <20240220104336.260194-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220104336.260194-1-biju.das.jz@bp.renesas.com> References: <20240220104336.260194-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The API's related to clk disable operation does not explicitly states the synchoronous or asynchrous behaviour as it is driver dependent. So make this part clear in API documentation. Suggested-by: Laurent Pinchart Signed-off-by: Biju Das --- v2: * New patch. --- drivers/clk/clk.c | 3 ++- include/linux/clk-provider.h | 3 ++- include/linux/clk.h | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 2253c154a824..9a09f51f4af1 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -988,7 +988,8 @@ static void clk_core_unprepare_lock(struct clk_core *core) * if the operation may sleep. One example is a clk which is accessed over * I2c. In the complex case a clk gate operation may require a fast and a slow * part. It is this reason that clk_unprepare and clk_disable are not mutually - * exclusive. In fact clk_disable must be called before clk_unprepare. + * exclusive. In fact clk_disable must be called before clk_unprepare. The + * synchronous or asynchronous clock gating operation is driver dependent. */ void clk_unprepare(struct clk *clk) { diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 1293c38ddb7f..50cd0f8d37cb 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -113,7 +113,8 @@ struct clk_duty { * sleep. * * @disable: Disable the clock atomically. Called with enable_lock held. - * This function must not sleep. + * This function must not sleep. The synchronous or asynchronous + * disabling of the clock is driver dependent. * * @is_enabled: Queries the hardware to determine if the clock is enabled. * This function must not sleep. Optional, if this op is not diff --git a/include/linux/clk.h b/include/linux/clk.h index 06f1b292f8a0..e6acec5d8dbe 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -653,7 +653,8 @@ int __must_check clk_bulk_enable(int num_clks, * @clk: clock source * * Inform the system that a clock source is no longer required by - * a driver and may be shut down. + * a driver and may be shut down. It is not guaranteed to ever actually + * be stopped, that will be driver dependent. * * May be called from atomic contexts. * From patchwork Tue Feb 20 10:43:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13563860 X-Patchwork-Delegate: geert@linux-m68k.org Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39AD2626C6; Tue, 20 Feb 2024 10:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425834; cv=none; b=o3padX+yuqnyDG8psxMLhfq7HShxGUbzT3Pbd2zr96m3s0DjZM2xTnq5PaiQ5GfYzVV1eXZfpq4K+uU5feWRI84pIhGLwQ26MTy8TNvsxS3YigQicC0lg/9VHbl3D4Ueya4kSk3P70r0fd/YJS70C5MVScEIpoUV25zVriXfaB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425834; c=relaxed/simple; bh=B2RnZXfNYMhUhiOdYc7+d0mAwKnhiBEQnEF1lJgHSVk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Aob7QAd/YQjMuXTOkjPzOCKKCCznPw1wX8u7T89dZdp3genMqTnom+y+njn+QrWoTTcQfHacE4SIz7TKE9xd+3NG8LKecsJqx0Rrhe2yzJsAt1k4cEFCd8Fwkf0QNudfOjG3Rl6PvsyujrE27dYB8PepqplsUKHMIGKtapf72Cc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.06,172,1705330800"; d="scan'208";a="198515571" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 20 Feb 2024 19:43:51 +0900 Received: from localhost.localdomain (unknown [10.226.92.246]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id A40844005658; Tue, 20 Feb 2024 19:43:47 +0900 (JST) From: Biju Das To: Michael Turquette , Stephen Boyd , Sakari Ailus , Laurent Pinchart , Russell King Cc: Biju Das , linux-clk@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 2/3] clk: Add clk_poll_disable_unprepare() Date: Tue, 20 Feb 2024 10:43:35 +0000 Message-Id: <20240220104336.260194-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220104336.260194-1-biju.das.jz@bp.renesas.com> References: <20240220104336.260194-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The clk_disable_unprepare() doesn't guarantee that a clock is gated after the execution as it is driver dependent. The Renesas and most of the other platforms don't wait until clock is stopped because of performance reason. But these platforms wait while turning on the clock. The normal case for shutting down the clock is unbind/close/suspend or error paths in the driver. Not waiting for the shutting down the clock will improve the suspend time. But on RZ/G2L Camera Data Receiving Unit (CRU) IP, initially the vclk is on. Before enabling link reception, we need to wait for vclk to be off and after enabling reception, we need to turn the vlck on. Special cases like this requires a sync API for clock gating. Add clk_poll_disable_unprepare() to poll the clock gate operation that guarantees gating of clk after the execution. Signed-off-by: Biju Das --- RFC->v2: * Renamed clk_disable_unprepare_sync()-->clk_poll_disable_unprepare() * Redesigned to make use of __clk_is_enabled() to poll the clock gating. --- drivers/clk/clk.c | 23 +++++++++++++++++++++++ include/linux/clk.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 9a09f51f4af1..0e66b7180388 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1138,6 +1139,28 @@ void clk_disable(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_disable); +/** + * clk_poll_disabled - poll for clock gating. + * @clk: the clk that is going to stop + * @sleep_us: Maximum time to sleep between reads in us (0 + * tight-loops). Should be less than ~20ms since usleep_range + * is used (see Documentation/timers/timers-howto.rst). + * @timeout_us: Timeout in us, 0 means never timeout + * + * It polls for a clk to be stopped. + */ +int clk_poll_disabled(struct clk *clk, unsigned long sleep_us, u64 timeout_us) +{ + bool status; + + if (IS_ERR_OR_NULL(clk)) + return 0; + + return read_poll_timeout(__clk_is_enabled, status, !status, sleep_us, + timeout_us, false, clk); +} +EXPORT_SYMBOL_GPL(clk_poll_disabled); + static int clk_core_enable(struct clk_core *core) { int ret = 0; diff --git a/include/linux/clk.h b/include/linux/clk.h index e6acec5d8dbe..2d63a12214e5 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -665,6 +665,20 @@ int __must_check clk_bulk_enable(int num_clks, */ void clk_disable(struct clk *clk); +/** + * clk_poll_disabled - inform the system whether the clock source is stopped. + * @clk: clock source + * @sleep_us: Maximum time to sleep between reads in us (0 + * tight-loops). Should be less than ~20ms since usleep_range + * is used (see Documentation/timers/timers-howto.rst). + * @timeout_us: Timeout in us, 0 means never timeout + * + * Poll for clock gating and Inform the system about it's status. + * + * Context: May sleep. + */ +int clk_poll_disabled(struct clk *clk, unsigned long sleep_us, u64 timeout_us); + /** * clk_bulk_disable - inform the system when the set of clks is no * longer required. @@ -996,6 +1010,11 @@ static inline int __must_check clk_bulk_enable(int num_clks, static inline void clk_disable(struct clk *clk) {} +static inline int clk_poll_disabled(struct clk *clk, unsigned long sleep_us, + u64 timeout_us) +{ + return 0; +} static inline void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks) {} @@ -1087,6 +1106,33 @@ static inline void clk_disable_unprepare(struct clk *clk) clk_unprepare(clk); } +/** + * clk_poll_disable_unprepare - Poll clk_disable_unprepare + * @clk: clock source + * @sleep_us: Maximum time to sleep between reads in us (0 + * tight-loops). Should be less than ~20ms since usleep_range + * is used (see Documentation/timers/timers-howto.rst). + * @timeout_us: Timeout in us, 0 means never timeout + * + * Context: May sleep. + * + * This function polls until the clock has stopped. + * + * Returns success (0) or negative errno. + */ +static inline int clk_poll_disable_unprepare(struct clk *clk, + unsigned long sleep_us, + u64 timeout_us) +{ + int ret; + + clk_disable(clk); + ret = clk_poll_disabled(clk, sleep_us, timeout_us); + clk_unprepare(clk); + + return ret; +} + static inline int __must_check clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks) { From patchwork Tue Feb 20 10:43:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13563861 X-Patchwork-Delegate: kieran@bingham.xyz Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 108EA62160; Tue, 20 Feb 2024 10:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425837; cv=none; b=rxZTyTbfO2zZQJYhqTFq/U0kYzqCOd1sFV0m85LIO5FMzguK8ZIV+oDxVUgYRm1DsezpDBmTSJjE7dNpP1ugQG3GGqXV7zMsIdH2s6qVP/uZq9Qm/cVPtajUMxh+8bFsF1lKIyszMy3ls0d3ESMes6MwNsjBUHdI3SNzUKz2s2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425837; c=relaxed/simple; bh=hk+SwYEtbz1YbuLnMcYcZXEyiHG0rluyq/cy+FSA2hA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rdnXgl+4AI+YCMsfqpqxvmx4tBkJgBT/wOT2FQWEXGgDwXokJyk25Ceqt4xOmlTN/x13EzH1zfJ+qfj9ytkaAgtvkW6ijw0QKx4kFDILzSzN/yJzGh9oTsBffQfliATCvIpLW8rMvDcC4ykiOz27p33TauYqqKH1XYt78MdQATA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.06,172,1705330800"; d="scan'208";a="194579423" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 20 Feb 2024 19:43:55 +0900 Received: from localhost.localdomain (unknown [10.226.92.246]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id AD77D4004BD4; Tue, 20 Feb 2024 19:43:51 +0900 (JST) From: Biju Das To: Mauro Carvalho Chehab Cc: Biju Das , Hans Verkuil , Sakari Ailus , Stephen Boyd , Laurent Pinchart , Lad Prabhakar , Rob Herring , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-media@vger.kernel.org, Geert Uytterhoeven , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 3/3] media: platform: rzg2l-cru: rzg2l-video: Use clk_poll_disable_unprepare() Date: Tue, 20 Feb 2024 10:43:36 +0000 Message-Id: <20240220104336.260194-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220104336.260194-1-biju.das.jz@bp.renesas.com> References: <20240220104336.260194-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the clk_poll_disable_unprepare() for synchronizing clk gating in rzg2l_csi2_mipi_link_enable(). Signed-off-by: Biju Das --- v1->v2: * Replaced clk_disable_unprepare_sync()-->clk_poll_disable_unprepare() and the error propagated to the caller. --- drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c index e68fcdaea207..986435bd85c1 100644 --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c @@ -366,6 +366,7 @@ static int rzg2l_csi2_mipi_link_enable(struct rzg2l_csi2 *csi2) { unsigned long vclk_rate = csi2->vclk_rate / HZ_PER_MHZ; u32 frrskw, frrclk, frrskw_coeff, frrclk_coeff; + int ret; /* Select data lanes */ rzg2l_csi2_write(csi2, CSI2nMCT0, CSI2nMCT0_VDLN(csi2->lanes)); @@ -387,7 +388,9 @@ static int rzg2l_csi2_mipi_link_enable(struct rzg2l_csi2 *csi2) rzg2l_csi2_write(csi2, CSI2nDTEL, 0xf778ff0f); rzg2l_csi2_write(csi2, CSI2nDTEH, 0x00ffff1f); - clk_disable_unprepare(csi2->vclk); + ret = clk_poll_disable_unprepare(csi2->vclk, 10, 10000); + if (ret) + return ret; /* Enable LINK reception */ rzg2l_csi2_write(csi2, CSI2nMCT3, CSI2nMCT3_RXEN);