From: "Gary Guo" <gary@garyguo.net>
To: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Drew Fustini" <fustini@kernel.org>,
"Guo Ren" <guoren@kernel.org>, "Fu Wei" <wefu@redhat.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
"Michael Turquette" <mturquette@baylibre.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>
Cc: <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>
Subject: Re: [PATCH v3 2/3] rust: clk: add devres-managed clks
Date: Mon, 19 Jan 2026 14:33:37 +0000 [thread overview]
Message-ID: <DFSN1M7NPLHX.20PQDYA5DU7RM@garyguo.net> (raw)
In-Reply-To: <20260107-clk-type-state-v3-2-77d3e3ee59c2@collabora.com>
On Wed Jan 7, 2026 at 3:09 PM GMT, 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 <daniel.almeida@collabora.com>
> ---
> rust/kernel/clk.rs | 43 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 43 insertions(+)
>
> diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
> index 6323b40dc7ba..e840e7c20af7 100644
> --- a/rust/kernel/clk.rs
> +++ b/rust/kernel/clk.rs
> @@ -95,6 +95,49 @@ 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
> + pub fn devm_enable(dev: &Device<Bound>, 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
> + // device pointer.
> + from_err_ptr(unsafe { bindings::devm_clk_get_enabled(dev.as_raw(), name) })?;
> + Ok(())
> + }
Would it make sense to have them as assoc functions instead of standalone?
Regardless, the code looks correct to me.
Reviewed-by: Gary Guo <gary@garyguo.net>
Best,
Gary
> +
> + /// 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
> + pub fn devm_enable_optional(dev: &Device<Bound>, 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.
> + 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())
> + })?;
> + Ok(())
> + }
> +
> /// A trait representing the different states that a [`Clk`] can be in.
> pub trait ClkState: private::Sealed {
> /// Whether the clock should be disabled when dropped.
WARNING: multiple messages have this Message-ID (diff)
From: "Gary Guo" <gary@garyguo.net>
To: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Drew Fustini" <fustini@kernel.org>,
"Guo Ren" <guoren@kernel.org>, "Fu Wei" <wefu@redhat.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
"Michael Turquette" <mturquette@baylibre.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>
Cc: <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>
Subject: Re: [PATCH v3 2/3] rust: clk: add devres-managed clks
Date: Mon, 19 Jan 2026 14:33:37 +0000 [thread overview]
Message-ID: <DFSN1M7NPLHX.20PQDYA5DU7RM@garyguo.net> (raw)
In-Reply-To: <20260107-clk-type-state-v3-2-77d3e3ee59c2@collabora.com>
On Wed Jan 7, 2026 at 3:09 PM GMT, 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 <daniel.almeida@collabora.com>
> ---
> rust/kernel/clk.rs | 43 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 43 insertions(+)
>
> diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
> index 6323b40dc7ba..e840e7c20af7 100644
> --- a/rust/kernel/clk.rs
> +++ b/rust/kernel/clk.rs
> @@ -95,6 +95,49 @@ 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
> + pub fn devm_enable(dev: &Device<Bound>, 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
> + // device pointer.
> + from_err_ptr(unsafe { bindings::devm_clk_get_enabled(dev.as_raw(), name) })?;
> + Ok(())
> + }
Would it make sense to have them as assoc functions instead of standalone?
Regardless, the code looks correct to me.
Reviewed-by: Gary Guo <gary@garyguo.net>
Best,
Gary
> +
> + /// 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
> + pub fn devm_enable_optional(dev: &Device<Bound>, 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.
> + 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())
> + })?;
> + Ok(())
> + }
> +
> /// A trait representing the different states that a [`Clk`] can be in.
> pub trait ClkState: private::Sealed {
> /// Whether the clock should be disabled when dropped.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-01-19 14:33 UTC|newest]
Thread overview: 136+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 15:09 [PATCH v3 0/3] Clk improvements Daniel Almeida
2026-01-07 15:09 ` Daniel Almeida
2026-01-07 15:09 ` [PATCH v3 1/3] rust: clk: use the type-state pattern Daniel Almeida
2026-01-07 15:09 ` Daniel Almeida
2026-01-08 8:07 ` Maxime Ripard
2026-01-08 8:07 ` Maxime Ripard
2026-01-08 13:57 ` Miguel Ojeda
2026-01-08 13:57 ` Miguel Ojeda
2026-01-08 14:18 ` Daniel Almeida
2026-01-08 14:18 ` Daniel Almeida
2026-01-08 14:14 ` Daniel Almeida
2026-01-08 14:14 ` Daniel Almeida
2026-01-19 10:45 ` Maxime Ripard
2026-01-19 10:45 ` Maxime Ripard
2026-01-19 12:13 ` Daniel Almeida
2026-01-19 12:13 ` Daniel Almeida
2026-01-19 12:35 ` Alice Ryhl
2026-01-19 12:35 ` Alice Ryhl
2026-01-19 12:54 ` Daniel Almeida
2026-01-19 12:54 ` Daniel Almeida
2026-01-19 13:13 ` Danilo Krummrich
2026-01-19 13:13 ` Danilo Krummrich
2026-01-19 14:18 ` Maxime Ripard
2026-01-19 14:18 ` Maxime Ripard
2026-01-19 14:37 ` Danilo Krummrich
2026-01-19 14:37 ` Danilo Krummrich
2026-01-22 13:44 ` Maxime Ripard
2026-01-22 13:44 ` Maxime Ripard
2026-01-23 0:29 ` Daniel Almeida
2026-01-23 0:29 ` Daniel Almeida
2026-02-04 9:15 ` Maxime Ripard
2026-02-04 9:15 ` Maxime Ripard
2026-02-04 12:43 ` Daniel Almeida
2026-02-04 12:43 ` Daniel Almeida
2026-02-04 14:34 ` Maxime Ripard
2026-02-04 14:34 ` Maxime Ripard
2026-02-09 9:50 ` Boris Brezillon
2026-02-09 9:50 ` Boris Brezillon
2026-02-11 16:37 ` Maxime Ripard
2026-02-11 16:37 ` Maxime Ripard
2026-02-11 16:47 ` Danilo Krummrich
2026-02-11 16:47 ` Danilo Krummrich
2026-02-12 7:59 ` Maxime Ripard
2026-02-12 7:59 ` Maxime Ripard
2026-02-12 8:52 ` Alice Ryhl
2026-02-12 8:52 ` Alice Ryhl
2026-02-12 9:23 ` Danilo Krummrich
2026-02-12 9:23 ` Danilo Krummrich
2026-02-12 14:01 ` Danilo Krummrich
2026-02-12 14:01 ` Danilo Krummrich
2026-02-12 16:50 ` Maxime Ripard
2026-02-12 16:50 ` Maxime Ripard
2026-02-12 11:45 ` Miguel Ojeda
2026-02-12 11:45 ` Miguel Ojeda
2026-02-12 8:16 ` Alice Ryhl
2026-02-12 8:16 ` Alice Ryhl
2026-02-12 13:38 ` Maxime Ripard
2026-02-12 13:38 ` Maxime Ripard
2026-02-12 14:02 ` Alice Ryhl
2026-02-12 14:02 ` Alice Ryhl
2026-02-12 16:48 ` Maxime Ripard
2026-02-12 16:48 ` Maxime Ripard
2026-01-23 10:25 ` Danilo Krummrich
2026-01-23 10:25 ` Danilo Krummrich
2026-01-19 12:57 ` Gary Guo
2026-01-19 12:57 ` Gary Guo
2026-01-19 14:27 ` Maxime Ripard
2026-01-19 14:27 ` Maxime Ripard
2026-02-03 10:39 ` Boris Brezillon
2026-02-03 10:39 ` Boris Brezillon
2026-02-03 11:26 ` Boris Brezillon
2026-02-03 11:26 ` Boris Brezillon
2026-02-03 14:53 ` Boris Brezillon
2026-02-03 14:53 ` Boris Brezillon
2026-02-03 13:33 ` Daniel Almeida
2026-02-03 13:33 ` Daniel Almeida
2026-02-03 13:42 ` Gary Guo
2026-02-03 13:42 ` Gary Guo
2026-02-03 13:55 ` Daniel Almeida
2026-02-03 13:55 ` Daniel Almeida
2026-02-03 14:33 ` Boris Brezillon
2026-02-03 14:33 ` Boris Brezillon
2026-02-03 14:08 ` Boris Brezillon
2026-02-03 14:08 ` Boris Brezillon
2026-02-03 16:28 ` Daniel Almeida
2026-02-03 16:28 ` Daniel Almeida
2026-02-03 16:55 ` Boris Brezillon
2026-02-03 16:55 ` Boris Brezillon
2026-02-03 16:59 ` Gary Guo
2026-02-03 16:59 ` Gary Guo
2026-02-03 19:26 ` Daniel Almeida
2026-02-03 19:26 ` Daniel Almeida
2026-02-03 19:43 ` Boris Brezillon
2026-02-03 19:43 ` Boris Brezillon
2026-02-03 20:36 ` Gary Guo
2026-02-03 20:36 ` Gary Guo
2026-02-04 8:11 ` Boris Brezillon
2026-02-04 8:11 ` Boris Brezillon
2026-02-04 9:18 ` Maxime Ripard
2026-02-04 9:18 ` Maxime Ripard
2026-01-19 14:26 ` Gary Guo
2026-01-19 14:26 ` Gary Guo
2026-01-19 15:44 ` Daniel Almeida
2026-01-19 15:44 ` Daniel Almeida
2026-01-19 14:20 ` Gary Guo
2026-01-19 14:20 ` Gary Guo
2026-01-19 15:22 ` Miguel Ojeda
2026-01-19 15:22 ` Miguel Ojeda
2026-01-19 15:36 ` Gary Guo
2026-01-19 15:36 ` Gary Guo
2026-01-19 15:46 ` Miguel Ojeda
2026-01-19 15:46 ` Miguel Ojeda
2026-01-19 16:10 ` Gary Guo
2026-01-19 16:10 ` Gary Guo
2026-02-02 16:10 ` Boris Brezillon
2026-02-02 16:10 ` Boris Brezillon
2026-02-03 9:09 ` Boris Brezillon
2026-02-03 9:09 ` Boris Brezillon
2026-02-03 9:47 ` Boris Brezillon
2026-02-03 9:47 ` Boris Brezillon
2026-02-03 13:37 ` Daniel Almeida
2026-02-03 13:37 ` Daniel Almeida
2026-02-03 14:18 ` Boris Brezillon
2026-02-03 14:18 ` Boris Brezillon
2026-02-03 9:17 ` Boris Brezillon
2026-02-03 9:17 ` Boris Brezillon
2026-02-03 13:35 ` Daniel Almeida
2026-02-03 13:35 ` Daniel Almeida
2026-01-07 15:09 ` [PATCH v3 2/3] rust: clk: add devres-managed clks Daniel Almeida
2026-01-07 15:09 ` Daniel Almeida
2026-01-19 14:33 ` Gary Guo [this message]
2026-01-19 14:33 ` Gary Guo
2026-01-07 15:09 ` [PATCH v3 3/3] rust: clk: use 'kernel vertical style' for imports Daniel Almeida
2026-01-07 15:09 ` Daniel Almeida
2026-01-08 7:53 ` Maxime Ripard
2026-01-08 7:53 ` Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DFSN1M7NPLHX.20PQDYA5DU7RM@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=fustini@kernel.org \
--cc=guoren@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lossin@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=mturquette@baylibre.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=tzimmermann@suse.de \
--cc=ukleinek@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=wefu@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.