From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A744C55172 for ; Sat, 1 Aug 2026 11:23:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 19EED10E08A; Sat, 1 Aug 2026 11:23:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="GBjamspr"; dkim-atps=neutral Received: from mail-244108.protonmail.ch (mail-244108.protonmail.ch [109.224.244.108]) by gabe.freedesktop.org (Postfix) with ESMTPS id E654610E08A for ; Sat, 1 Aug 2026 11:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=protonmail; t=1785583379; x=1785842579; bh=gNRt5vhm5rzA0r9SYRg4vpPJmSNy2rVVGJFfnD3HI1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=GBjamsprGcj4PJ+2tZTITaCwpA1KPghVP4Ho1RdnnRiTjaoLl+mtI4hCDjYBkjLBD 82KdhJDeKUC6ujY02rLVX+E1evUhCj5oKPoxhK4rx6b+vSEy0MkLDc9QfVLW9CXQ/O nTTnvcOMLqAxn1jP/gglcT78OMLop3pPKEj+mMgoNmbaTm2cEvHVaKNZeSSGIuDyj3 BacKGT25+a5IfltXpp5K+ufOdTr/zIaInIjO7KuOvmqeR0D0ueaHmsdtU7+kq6lQwk kMgPlUQaPo3e10IA8o1AO0u5WjhU+Fuu5lzfIXz/MfaglekZclzpTiRTakMZdZzFC+ KKEqnuS5GK7CA== X-Pm-Submission-Id: 4hC0sq5XCMz2Sd4d From: =?UTF-8?q?Onur=20=C3=96zkan?= To: Daniel Almeida Cc: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , Alice Ryhl , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Drew Fustini , Guo Ren , Fu Wei , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Michael Turquette , Stephen Boyd , Miguel Ojeda , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Michal Wilczynski , Boqun Feng , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org, linux-clk@vger.kernel.org, rust-for-linux@vger.kernel.org, Boris Brezillon , Maurice Subject: Re: [PATCH v5 3/4] rust: clk: add devres-managed clks Date: Sat, 1 Aug 2026 14:22:52 +0300 Message-ID: <20260801112254.313381-1-work@onurozkan.dev> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260706-clk-type-state-v5-3-67c5f326a16c@collabora.com> References: <20260706-clk-type-state-v5-0-67c5f326a16c@collabora.com> <20260706-clk-type-state-v5-3-67c5f326a16c@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Mon, 06 Jul 2026 11:37:14 -0300=0D Daniel Almeida wrote:=0D =0D > The clk API allows fine-grained control, but some drivers might be=0D > more interested in a "set and forget" API.=0D > =0D > Expand the current API to support this. The clock will automatically be=0D > disabled, unprepared and freed when the device is unbound from the bus=0D > without further intervention by the driver.=0D > =0D > Signed-off-by: Daniel Almeida =0D > ---=0D > rust/kernel/clk.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++=0D > 1 file changed, 46 insertions(+)=0D > =0D > diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs=0D > index dd5fd656271e..b9a44f83843a 100644=0D > --- a/rust/kernel/clk.rs=0D > +++ b/rust/kernel/clk.rs=0D > @@ -96,6 +96,52 @@ impl Sealed for super::Prepared {}=0D > impl Sealed for super::Enabled {}=0D > }=0D > =0D > + /// Obtains and enables a [`devres`]-managed [`Clk`] for a bound dev= ice.=0D > + ///=0D > + /// [`devres`]: crate::devres::Devres=0D > + #[inline]=0D > + pub fn devm_enable(dev: &Device, name: Option<&CStr>) -> Resu= lt {=0D > + let name =3D name.map_or(ptr::null(), |n| n.as_char_ptr());=0D > +=0D > + // SAFETY: It is safe to call [`devm_clk_get_enabled`] with a va= lid=0D =0D Intra-doc links won't work in regular comments.=0D =0D > + // device pointer.=0D > + from_err_ptr(unsafe { bindings::devm_clk_get_enabled(dev.as_raw(= ), name) })?;=0D > + Ok(())=0D > + }=0D > +=0D > + /// Obtains and enables a [`devres`]-managed [`Clk`] for a bound dev= ice.=0D > + ///=0D > + /// This does not print any error messages if the clock is not found= .=0D > + ///=0D > + /// [`devres`]: crate::devres::Devres=0D > + #[inline]=0D > + pub fn devm_enable_optional(dev: &Device, name: Option<&CStr>= ) -> Result {=0D > + let name =3D name.map_or(ptr::null(), |n| n.as_char_ptr());=0D > +=0D > + // SAFETY: It is safe to call [`devm_clk_get_optional_enabled`] = with a=0D > + // valid device pointer.=0D > + from_err_ptr(unsafe { bindings::devm_clk_get_optional_enabled(de= v.as_raw(), name) })?;=0D > + Ok(())=0D > + }=0D > +=0D > + /// Same as [`devm_enable_optional`], but also sets the rate.=0D > + #[inline]=0D > + pub fn devm_enable_optional_with_rate(=0D > + dev: &Device,=0D > + name: Option<&CStr>,=0D > + rate: Hertz,=0D > + ) -> Result {=0D > + let name =3D name.map_or(ptr::null(), |n| n.as_char_ptr());=0D > +=0D > + // SAFETY: It is safe to call=0D > + // [`devm_clk_get_optional_enabled_with_rate`] with a valid devi= ce=0D > + // pointer.=0D > + from_err_ptr(unsafe {=0D > + bindings::devm_clk_get_optional_enabled_with_rate(dev.as_raw= (), name, rate.as_hz())=0D > + })?;=0D =0D Just fyi, there's currently a bug in the C implementation of=0D devm_clk_get_optional_enabled_with_rate() which I caught while reviewing yo= ur=0D series. The fix patch is already on the list [1]. Other than that, this LGT= M.=0D =0D [1]: https://lore.kernel.org/all/20260801111637.304590-1-work@onurozkan.dev= =0D =0D Regards,=0D Onur=0D =0D > + Ok(())=0D > + }=0D > +=0D > /// A trait representing the different states that a [`Clk`] can be = in.=0D > pub trait ClkState: private::Sealed {=0D > /// Whether the clock is enabled in this state.=0D > =0D > -- =0D > 2.54.0=0D > =0D From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0AFE4C55173 for ; Sat, 1 Aug 2026 11:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=v0aLS4JSufeRY/h26DS7ZPXhehuzgmURV1cDrMpclmg=; b=qyTUjwYfsWzRDm T8eviinXBHYjrbHG+1ShP7tAAEh4evvNQGQ3q+j0/5thRylf+7Z5/iQ5A/SXMQzBXMmjtEP1/x8lv RPFlAvsxdpqBI6xhh94AOUnUXNaphTWpx3cn1vWGPQcDFAZXA2Nse0uJyVxN2yDG1sJzoNfmb2Rhh i3JMclI5Bb4zyefsPQqcKJxaSzFkbatkqNFAXd4/ZdZUR7U0oX5s7R4a09V8/5n8pu037S4p2PToT 5VJs+EYYAR908CO6yfNElsSoRI2apZyTMle9/G+Gt6iIa6tQjh37asOP8SKa1DjbIYC/6Cm2hyUes 4WP8GsXg1oZNue23TaHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq7o7-0000000EFhB-3k2N; Sat, 01 Aug 2026 11:23:11 +0000 Received: from mail-244108.protonmail.ch ([109.224.244.108]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq7o4-0000000EFdv-1zIM for linux-riscv@lists.infradead.org; Sat, 01 Aug 2026 11:23:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=protonmail; t=1785583379; x=1785842579; bh=gNRt5vhm5rzA0r9SYRg4vpPJmSNy2rVVGJFfnD3HI1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=GBjamsprGcj4PJ+2tZTITaCwpA1KPghVP4Ho1RdnnRiTjaoLl+mtI4hCDjYBkjLBD 82KdhJDeKUC6ujY02rLVX+E1evUhCj5oKPoxhK4rx6b+vSEy0MkLDc9QfVLW9CXQ/O nTTnvcOMLqAxn1jP/gglcT78OMLop3pPKEj+mMgoNmbaTm2cEvHVaKNZeSSGIuDyj3 BacKGT25+a5IfltXpp5K+ufOdTr/zIaInIjO7KuOvmqeR0D0ueaHmsdtU7+kq6lQwk kMgPlUQaPo3e10IA8o1AO0u5WjhU+Fuu5lzfIXz/MfaglekZclzpTiRTakMZdZzFC+ KKEqnuS5GK7CA== X-Pm-Submission-Id: 4hC0sq5XCMz2Sd4d From: =?UTF-8?q?Onur=20=C3=96zkan?= To: Daniel Almeida Cc: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , Alice Ryhl , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Drew Fustini , Guo Ren , Fu Wei , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Michael Turquette , Stephen Boyd , Miguel Ojeda , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Michal Wilczynski , Boqun Feng , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org, linux-clk@vger.kernel.org, rust-for-linux@vger.kernel.org, Boris Brezillon , Maurice Subject: Re: [PATCH v5 3/4] rust: clk: add devres-managed clks Date: Sat, 1 Aug 2026 14:22:52 +0300 Message-ID: <20260801112254.313381-1-work@onurozkan.dev> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260706-clk-type-state-v5-3-67c5f326a16c@collabora.com> References: <20260706-clk-type-state-v5-0-67c5f326a16c@collabora.com> <20260706-clk-type-state-v5-3-67c5f326a16c@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260801_042308_693113_FD651E2C X-CRM114-Status: GOOD ( 17.12 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Mon, 06 Jul 2026 11:37:14 -0300 Daniel Almeida wrote: > The clk API allows fine-grained control, but some drivers might be > more interested in a "set and forget" API. > > Expand the current API to support this. The clock will automatically be > disabled, unprepared and freed when the device is unbound from the bus > without further intervention by the driver. > > Signed-off-by: Daniel Almeida > --- > rust/kernel/clk.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs > index dd5fd656271e..b9a44f83843a 100644 > --- a/rust/kernel/clk.rs > +++ b/rust/kernel/clk.rs > @@ -96,6 +96,52 @@ impl Sealed for super::Prepared {} > impl Sealed for super::Enabled {} > } > > + /// Obtains and enables a [`devres`]-managed [`Clk`] for a bound device. > + /// > + /// [`devres`]: crate::devres::Devres > + #[inline] > + pub fn devm_enable(dev: &Device, name: Option<&CStr>) -> Result { > + let name = name.map_or(ptr::null(), |n| n.as_char_ptr()); > + > + // SAFETY: It is safe to call [`devm_clk_get_enabled`] with a valid Intra-doc links won't work in regular comments. > + // device pointer. > + from_err_ptr(unsafe { bindings::devm_clk_get_enabled(dev.as_raw(), name) })?; > + Ok(()) > + } > + > + /// Obtains and enables a [`devres`]-managed [`Clk`] for a bound device. > + /// > + /// This does not print any error messages if the clock is not found. > + /// > + /// [`devres`]: crate::devres::Devres > + #[inline] > + pub fn devm_enable_optional(dev: &Device, name: Option<&CStr>) -> Result { > + let name = name.map_or(ptr::null(), |n| n.as_char_ptr()); > + > + // SAFETY: It is safe to call [`devm_clk_get_optional_enabled`] with a > + // valid device pointer. > + from_err_ptr(unsafe { bindings::devm_clk_get_optional_enabled(dev.as_raw(), name) })?; > + Ok(()) > + } > + > + /// Same as [`devm_enable_optional`], but also sets the rate. > + #[inline] > + pub fn devm_enable_optional_with_rate( > + dev: &Device, > + name: Option<&CStr>, > + rate: Hertz, > + ) -> Result { > + let name = name.map_or(ptr::null(), |n| n.as_char_ptr()); > + > + // SAFETY: It is safe to call > + // [`devm_clk_get_optional_enabled_with_rate`] with a valid device > + // pointer. > + from_err_ptr(unsafe { > + bindings::devm_clk_get_optional_enabled_with_rate(dev.as_raw(), name, rate.as_hz()) > + })?; Just fyi, there's currently a bug in the C implementation of devm_clk_get_optional_enabled_with_rate() which I caught while reviewing your series. The fix patch is already on the list [1]. Other than that, this LGTM. [1]: https://lore.kernel.org/all/20260801111637.304590-1-work@onurozkan.dev Regards, Onur > + Ok(()) > + } > + > /// A trait representing the different states that a [`Clk`] can be in. > pub trait ClkState: private::Sealed { > /// Whether the clock is enabled in this state. > > -- > 2.54.0 > _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv