mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	 dri-devel@lists.freedesktop.org,
	 Detlev Casanova <detlev.casanova@collabora.com>,
	 Nicolas Dufresne <nicolas.dufresne@collabora.com>
Subject: [PATCH 7/7] rust: reset: add devm_deassert() and devm_deassert_optional()
Date: Thu, 26 Nov 2026 13:04:34 -0300	[thread overview]
Message-ID: <20261126-b4-rust-reset-v1-7-9c4c3d029080@collabora.com> (raw)
In-Reply-To: <20261126-b4-rust-reset-v1-0-9c4c3d029080@collabora.com>

Many drivers need the reset line of their device deasserted while the
device is bound, but otherwise do not care about exerting finer control
over it. C drivers do that with
devm_reset_control_get_exclusive_deasserted() and
devm_reset_control_get_optional_exclusive_deasserted().

Add ExclusiveResetControl::devm_deassert() and devm_deassert_optional(),
which call them and leave the reset control to devres.

Nothing uses them yet.

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
 rust/helpers/reset.c | 14 +++++++++++
 rust/kernel/reset.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/rust/helpers/reset.c b/rust/helpers/reset.c
index 9c106d8b6de1..aa20b3e7a88b 100644
--- a/rust/helpers/reset.c
+++ b/rust/helpers/reset.c
@@ -28,6 +28,20 @@ rust_helper_reset_control_get_optional_shared(struct device *dev,
 	return reset_control_get_optional_shared(dev, id);
 }
 
+__rust_helper struct reset_control *
+rust_helper_devm_reset_control_get_exclusive_deasserted(struct device *dev,
+							const char *id)
+{
+	return devm_reset_control_get_exclusive_deasserted(dev, id);
+}
+
+__rust_helper struct reset_control *
+rust_helper_devm_reset_control_get_optional_exclusive_deasserted(struct device *dev,
+								 const char *id)
+{
+	return devm_reset_control_get_optional_exclusive_deasserted(dev, id);
+}
+
 #ifndef CONFIG_RESET_CONTROLLER
 __rust_helper struct reset_control *
 rust_helper_fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
diff --git a/rust/kernel/reset.rs b/rust/kernel/reset.rs
index 85c51fc153ac..e2fbd4c2147c 100644
--- a/rust/kernel/reset.rs
+++ b/rust/kernel/reset.rs
@@ -19,6 +19,9 @@
 //! If the reset line is shared with other devices, the driver asks for a [`SharedResetControl`]
 //! instead.
 //!
+//! A driver that only needs its reset line deasserted while it is bound can call
+//! [`ExclusiveResetControl::devm_deassert`] instead of keeping a reset control.
+//!
 //! C header: [`include/linux/reset.h`](srctree/include/linux/reset.h)
 //!
 //! See [Reset controller API](https://docs.kernel.org/driver-api/reset.html) for more information.
@@ -324,6 +327,69 @@ pub fn get_array(dev: &'a Device<Bound>) -> Result<Self> {
     pub fn get_array_optional(dev: &'a Device<Bound>) -> Result<Self> {
         Self::get_array_internal(dev, true)
     }
+
+    /// Deasserts the reset line `name` of `dev`, or its first reset line if `name` is `None`, until
+    /// `dev` is unbound.
+    ///
+    /// The reset control is managed by devres, which asserts the line and releases the control
+    /// when `dev` is unbound. An error from that assert is discarded. Until then, devres holds
+    /// the line as an [`ExclusiveResetControl`] does.
+    ///
+    /// Equivalent to the kernel's [`devm_reset_control_get_exclusive_deasserted()`].
+    ///
+    /// # Examples
+    ///
+    /// Keeping the reset line of a device deasserted until the device is unbound:
+    ///
+    /// ```
+    /// use kernel::{
+    ///     device::{
+    ///         Bound,
+    ///         Device, //
+    ///     },
+    ///     reset::ExclusiveResetControl,
+    /// };
+    ///
+    /// fn probe(dev: &Device<Bound>) -> Result {
+    ///     ExclusiveResetControl::devm_deassert(dev, None)
+    /// }
+    /// ```
+    ///
+    /// [`devm_reset_control_get_exclusive_deasserted()`]:
+    /// https://docs.kernel.org/driver-api/reset.html#c.devm_reset_control_get_exclusive_deasserted
+    #[inline]
+    pub fn devm_deassert(dev: &Device<Bound>, name: Option<&CStr>) -> Result {
+        let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+        // SAFETY: `dev` is a valid and bound device, and `id` is `NULL` or a valid C string.
+        let inner =
+            unsafe { bindings::devm_reset_control_get_exclusive_deasserted(dev.as_raw(), id) };
+        from_err_ptr(inner)?;
+
+        Ok(())
+    }
+
+    /// Deasserts the reset line `name` of `dev` until `dev` is unbound, if there is such a line.
+    ///
+    /// Behaves the same as [`Self::devm_deassert`], except when the device has no such reset line
+    /// or `CONFIG_RESET_CONTROLLER` is disabled. In those cases, it succeeds and does nothing.
+    ///
+    /// Equivalent to the kernel's [`devm_reset_control_get_optional_exclusive_deasserted()`].
+    ///
+    /// [`devm_reset_control_get_optional_exclusive_deasserted()`]:
+    /// https://docs.kernel.org/driver-api/reset.html#c.devm_reset_control_get_optional_exclusive_deasserted
+    #[inline]
+    pub fn devm_deassert_optional(dev: &Device<Bound>, name: Option<&CStr>) -> Result {
+        let id = name.map_or(ptr::null(), |n| n.as_char_ptr());
+
+        // SAFETY: `dev` is a valid and bound device, and `id` is `NULL` or a valid C string.
+        let inner = unsafe {
+            bindings::devm_reset_control_get_optional_exclusive_deasserted(dev.as_raw(), id)
+        };
+        from_err_ptr(inner)?;
+
+        Ok(())
+    }
 }
 
 impl<'a, State: ResetState> ExclusiveResetControl<'a, State> {

-- 
2.56.0


  parent reply	other threads:[~2026-11-26 16:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
2026-11-26 16:04 ` [PATCH 1/7] rust: reset: add reset control helpers Daniel Almeida
2026-11-26 16:04 ` [PATCH 2/7] rust: reset: add ExclusiveResetControl Daniel Almeida
2026-11-26 16:04 ` [PATCH 3/7] rust: reset: add ExclusiveResetControl::get_array() and get_array_optional() Daniel Almeida
2026-11-26 16:04 ` [PATCH 4/7] rust: reset: add AssertedGuard Daniel Almeida
2026-11-26 16:04 ` [PATCH 5/7] rust: reset: add SharedResetControl Daniel Almeida
2026-11-26 19:14   ` Alice Ryhl
2026-11-26 16:04 ` [PATCH 6/7] rust: reset: add SharedResetControl::get_array() and get_array_optional() Daniel Almeida
2026-11-26 16:04 ` Daniel Almeida [this message]
2026-11-26 16:33 ` [PATCH 0/7] rust: reset: add reset control abstractions Nicolas Dufresne
2026-11-26 18:02   ` Daniel Almeida
2026-11-26 18:11     ` Nicolas Dufresne
2026-11-26 18:36       ` Daniel Almeida
2026-11-26 18:46         ` Nicolas Dufresne

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=20261126-b4-rust-reset-v1-7-9c4c3d029080@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=detlev.casanova@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=ojeda@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®