From patchwork Mon Mar 18 11:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13595266 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEF9636103; Mon, 18 Mar 2024 11:08: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=1710760138; cv=none; b=Qt8wuWsopn3oLj1SQGWOOMDcesmdNdWuuQrH3wBTBHEHUOSyOpMbFuSbmbqlnU3s0xVMoS9P25oppasb1uWOTuN7Ed0c57bblqF6ieXPTEsdQqRx7Hz3VqP00zGmYxKP05HofwqTWFW5WmvtZNKA+y+qB5FLNcQHLij++mTek9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710760138; c=relaxed/simple; bh=GusU4Gh1xCjEiEhu443u79bs/aqaVM5wHvkScYkv2ow=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nb+hF62FmiZ0iuRhP6QFF4ts76oGs78rZaZhMl0HmMVO/QbPsvRUX6Q0esC8CePLCs4o5tndWSZjA9oQdROA/McugBIFY1kYaaUZobNb3Ir6WQS47H4TuC/QfaxROATpB8gFuQrbi1hPJRfXRWI6dHMlGS0w46Lw4boo1Zg0DUU= 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.07,134,1708354800"; d="scan'208";a="198188837" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 18 Mar 2024 20:08:53 +0900 Received: from localhost.localdomain (unknown [10.226.93.20]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id C78CD4253BDA; Mon, 18 Mar 2024 20:08:49 +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 v3 1/3] clk: Update API documentation related to clock disable Date: Mon, 18 Mar 2024 11:08:40 +0000 Message-Id: <20240318110842.41956-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240318110842.41956-1-biju.das.jz@bp.renesas.com> References: <20240318110842.41956-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-clk@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 Acked-by: Russell King (Oracle) --- v2->v3: * No change. 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 25371c91a58f..f5fa91a339d7 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1010,7 +1010,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 4a537260f655..5b493024e1ec 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 00623f4de5e1..84b02518791f 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -681,7 +681,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 Mon Mar 18 11:08:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13595268 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C13531A66; Mon, 18 Mar 2024 11:08:57 +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=1710760140; cv=none; b=KRFWdvFgG1ek1WPdvs8X7R78/0E7cOfsrtFp4uUq6Qi21tQ9r41KdSNOaO7IFN/mk5VxHh4+xTGwzSvuryLW4OwV9dGnXCdLWmgP3Vqhmw3pCqOtdRNVwm/E2ra7J521X8TF0pvWqcxES+wZ3TXia0P2LbejmB+tosrgdTtu8BQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710760140; c=relaxed/simple; bh=LlN5vmoU3X09UJUTYhEgLanrVuqPgYAw3c3N6czQY5g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U6tXXcRTUwfF0O4bkL8TVTtS8ayAdrsDhX2/u/cXU3eWZoqYIILQ+F7gNn93kbpUYfPBkP3s4wNNkcjdIFmQr7jlkiGrNJGPw7S+IjG5aYoOcSz6zIx8H7MHm6BqW5NjdnqEdsaHF+fT6xudRYY038vR7CRQroLs0S0Uv0nFAnc= 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.07,134,1708354800"; d="scan'208";a="202139682" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 18 Mar 2024 20:08:56 +0900 Received: from localhost.localdomain (unknown [10.226.93.20]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 992114253BE5; Mon, 18 Mar 2024 20:08:53 +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 v3 2/3] clk: Add clk_poll_disable_unprepare() Date: Mon, 18 Mar 2024 11:08:41 +0000 Message-Id: <20240318110842.41956-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240318110842.41956-1-biju.das.jz@bp.renesas.com> References: <20240318110842.41956-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-clk@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 --- v2->v3: * Added WARN_ON(enable count non-zero) and return an error code (-EBUSY), if the user is not the sole user of the clock and the enable count is non-zero. * Returned an error if there's no is_enabled() callback. 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 | 29 ++++++++++++++++++++++++++++ include/linux/clk.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f5fa91a339d7..e10bb14c904d 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1160,6 +1161,34 @@ 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; + + if (!clk->core->ops->is_enabled) + return -EOPNOTSUPP; + + if (WARN(__clk_get_enable_count(clk), "clk is in use\n")) + return -EBUSY; + + 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 84b02518791f..7f714ecce0eb 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -693,6 +693,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. @@ -1030,6 +1044,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) {} @@ -1121,6 +1140,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) {