Commit Graph

7 Commits

Author SHA1 Message Date
Tamir Duberstein 9ce084e579 rust: regulator: use `CStr::as_char_ptr`
Replace the use of `as_ptr` which works through `<CStr as
Deref<Target=&[u8]>::deref()` in preparation for replacing
`kernel::str::CStr` with `core::ffi::CStr` as the latter does not
implement `Deref<Target=&[u8]>`.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Acked-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20251018-cstr-core-v18-13-9378a54385f8@gmail.com
[ Move safety comment below to support older Clippy. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-10-22 07:14:57 +02:00
Daniel Almeida 2e0fd4583d
rust: regulator: add devm_enable and devm_enable_optional
A lot of drivers only care about enabling the regulator for as long as
the underlying Device is bound. This can be easily observed due to the
extensive use of `devm_regulator_get_enable` and
`devm_regulator_get_enable_optional` throughout the kernel.

Therefore, make this helper available in Rust. Also add an example
noting how it should be the default API unless the driver needs more
fine-grained control over the regulator.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20250910-regulator-remove-dynamic-v3-2-07af4dfa97cc@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2025-09-10 21:02:16 +01:00
Daniel Almeida b87ecbc54f
rust: regulator: remove Regulator<Dynamic>
After some experimenting and further discussion, it is starting to look
like Regulator<Dynamic> might be a footgun. It turns out that one can
get the same behavior by correctly using just Regulator<Enabled> and
Regulator<Disabled>, so there is no need to directly expose the manual
refcounting ability of Regulator<Dynamic> to clients.

Remove it while we do not have any other users.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20250910-regulator-remove-dynamic-v3-1-07af4dfa97cc@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2025-09-10 21:02:15 +01:00
Onur Özkan e2ab5f600b
rust: regulator: use `to_result` for error handling
Simplifies error handling by replacing the manual check
of the return value with the `to_result` helper.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Message-ID: <20250821090720.23939-1-work@onurozkan.dev>
Signed-off-by: Mark Brown <broonie@kernel.org>
2025-08-28 11:08:39 +02:00
Daniel Almeida 9a200cbdb5 rust: regulator: implement Send and Sync for Regulator<T>
Sending a &Regulator<T> to another thread is safe, as the regulator core
will properly handle the locking for us. Additionally, there are no
restrictions that prevents sending a Regulator<T> to another thread.

Given these two facts, implement Send and Sync.

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20250729-regulator-send-sync-v1-2-8bcbd546b940@collabora.com
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2025-08-10 21:09:34 +01:00
Daniel Almeida f7fbf3091f rust: regulator: remove needless &mut from member functions
Regulator functions like "regulator_enable()" and "regulator_disable()"
already provide their own locking through "regulator_lock_dependent()", so
we can safely call the Rust API with a shared reference.

This was already the case with Regulator::set_voltage() on the Rust side,
but it was forgotten for Regulator::enable() and Regulator::disable().

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20250729-regulator-send-sync-v1-1-8bcbd546b940@collabora.com
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2025-08-10 21:09:33 +01:00
Daniel Almeida 9b614ceada
rust: regulator: add a bare minimum regulator abstraction
Add a bare minimum regulator abstraction to be used by Rust drivers.
This abstraction adds a small subset of the regulator API, which is
thought to be sufficient for the drivers we have now.

Regulators provide the power needed by many hardware blocks and thus are
likely to be needed by a lot of drivers.

It was tested on rk3588, where it was used to power up the "mali"
regulator in order to power up the GPU.

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20250714-topics-tyr-regulator2-v8-1-c7ab3955d524@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2025-07-15 15:07:40 +01:00