From: "Onur Özkan" <work@onurozkan.dev>
To: daniel.almeida@collabora.com, aliceryhl@google.com,
dakr@kernel.org, airlied@gmail.com, simona@ffwll.ch,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
lgirdwood@gmail.com, broonie@kernel.org, ojeda@kernel.org,
rust-for-linux@vger.kernel.org
Cc: "Onur Özkan" <work@onurozkan.dev>
Subject: [PATCH v2 1/1] drm/tyr: make SRAM supply optional like panthor
Date: Thu, 12 Feb 2026 13:05:38 +0300 [thread overview]
Message-ID: <20260212100538.170445-2-work@onurozkan.dev> (raw)
In-Reply-To: <20260212100538.170445-1-work@onurozkan.dev>
On rk3588s, `dmesg | grep 'tyr'` logs:
tyr fb000000.gpu: supply SRAM not found, using dummy regulator
This happens because Tyr calls Regulator<Enabled>::get() for SRAM,
which goes through the non-optional regulator_get() path. If the
device tree doesn't provide sram-supply, regulator core falls back
to a dummy regulator and writes that log.
Panthor handles SRAM as optional and tolerates missing sram-supply.
This patch matches that behavior in Tyr by using optional regulator
lookup and storing SRAM as Option<Regulator<Enabled>> which avoids
dummy-regulator fallback/noise when SRAM is not described inside
the device tree.
Link: https://rust-for-linux.zulipchat.com/#narrow/stream/x/topic/x/near/573210018
Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
drivers/gpu/drm/tyr/driver.rs | 5 ++--
rust/helpers/regulator.c | 5 ++++
rust/kernel/regulator.rs | 45 +++++++++++++++++++++++++++++++++--
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 0389c558c036..e0856deb83ec 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -113,7 +113,8 @@ fn probe(
coregroup_clk.prepare_enable()?;
let mali_regulator = Regulator::<regulator::Enabled>::get(pdev.as_ref(), c_str!("mali"))?;
- let sram_regulator = Regulator::<regulator::Enabled>::get(pdev.as_ref(), c_str!("sram"))?;
+ let sram_regulator =
+ Regulator::<regulator::Enabled>::get_optional(pdev.as_ref(), c_str!("sram"))?;
let request = pdev.io_request_by_index(0).ok_or(ENODEV)?;
let iomem = Arc::pin_init(request.iomap_sized::<SZ_2M>(), GFP_KERNEL)?;
@@ -201,5 +202,5 @@ struct Clocks {
#[pin_data]
struct Regulators {
mali: Regulator<regulator::Enabled>,
- sram: Regulator<regulator::Enabled>,
+ sram: Option<Regulator<regulator::Enabled>>,
}
diff --git a/rust/helpers/regulator.c b/rust/helpers/regulator.c
index 11bc332443bd..5ef45a8adf12 100644
--- a/rust/helpers/regulator.c
+++ b/rust/helpers/regulator.c
@@ -25,6 +25,11 @@ struct regulator *rust_helper_regulator_get(struct device *dev, const char *id)
return regulator_get(dev, id);
}
+struct regulator *rust_helper_regulator_get_optional(struct device *dev, const char *id)
+{
+ return regulator_get_optional(dev, id);
+}
+
int rust_helper_regulator_enable(struct regulator *regulator)
{
return regulator_enable(regulator);
diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs
index 2c44827ad0b7..d27ce3f6ef26 100644
--- a/rust/kernel/regulator.rs
+++ b/rust/kernel/regulator.rs
@@ -232,10 +232,11 @@ pub fn devm_enable_optional(dev: &Device<Bound>, name: &CStr) -> Result {
///
/// # Invariants
///
-/// - `inner` is a non-null wrapper over a pointer to a `struct
-/// regulator` obtained from [`regulator_get()`].
+/// - `inner` is a non-null wrapper over a pointer to a `struct regulator`
+/// obtained from [`regulator_get()`] or [`regulator_get_optional()`].
///
/// [`regulator_get()`]: https://docs.kernel.org/driver-api/regulator.html#c.regulator_get
+/// [`regulator_get_optional()`]: https://docs.kernel.org/driver-api/regulator.html#c.regulator_get_optional
pub struct Regulator<State>
where
State: RegulatorState,
@@ -283,6 +284,29 @@ fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
})
}
+ fn get_optional_internal(dev: &Device, name: &CStr) -> Result<Option<Regulator<T>>> {
+ // SAFETY: It is safe to call `regulator_get_optional()`, on a
+ // device pointer received from the C code.
+ let inner = from_err_ptr(unsafe {
+ bindings::regulator_get_optional(dev.as_raw(), name.as_char_ptr())
+ });
+
+ let inner = match inner {
+ Ok(inner) => inner,
+ Err(ENODEV) => return Ok(None),
+ Err(err) => return Err(err),
+ };
+
+ // SAFETY: We can safely trust `inner` to be a pointer to a valid
+ // regulator if `ERR_PTR` was not returned.
+ let inner = unsafe { NonNull::new_unchecked(inner) };
+
+ Ok(Some(Self {
+ inner,
+ _phantom: PhantomData,
+ }))
+ }
+
fn enable_internal(&self) -> Result {
// SAFETY: Safe as per the type invariants of `Regulator`.
to_result(unsafe { bindings::regulator_enable(self.inner.as_ptr()) })
@@ -300,6 +324,11 @@ pub fn get(dev: &Device, name: &CStr) -> Result<Self> {
Regulator::get_internal(dev, name)
}
+ /// Obtains an optional [`Regulator`] instance from the system.
+ pub fn get_optional(dev: &Device, name: &CStr) -> Result<Option<Self>> {
+ Regulator::get_optional_internal(dev, name)
+ }
+
/// Attempts to convert the regulator to an enabled state.
pub fn try_into_enabled(self) -> Result<Regulator<Enabled>, Error<Disabled>> {
// We will be transferring the ownership of our `regulator_get()` count to
@@ -329,6 +358,18 @@ pub fn get(dev: &Device, name: &CStr) -> Result<Self> {
.map_err(|error| error.error)
}
+ /// Obtains an optional [`Regulator`] instance from the system and enables it.
+ pub fn get_optional(dev: &Device, name: &CStr) -> Result<Option<Self>> {
+ match Regulator::<Disabled>::get_optional_internal(dev, name)? {
+ Some(regulator) => {
+ let enabled_regulator =
+ regulator.try_into_enabled().map_err(|error| error.error)?;
+ Ok(Some(enabled_regulator))
+ }
+ None => Ok(None),
+ }
+ }
+
/// Attempts to convert the regulator to a disabled state.
pub fn try_into_disabled(self) -> Result<Regulator<Disabled>, Error<Enabled>> {
// We will be transferring the ownership of our `regulator_get()` count
--
2.51.2
next prev parent reply other threads:[~2026-02-12 10:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 10:05 [PATCH v2 0/1] drm/tyr: make SRAM supply optional like panthor Onur Özkan
2026-02-12 10:05 ` Onur Özkan [this message]
2026-02-12 11:34 ` [PATCH v2 1/1] " Mark Brown
2026-02-12 12:16 ` Onur Özkan
2026-02-12 12:21 ` Mark Brown
2026-02-12 12:46 ` Boris Brezillon
2026-02-12 13:13 ` Mark Brown
2026-02-12 13:51 ` Boris Brezillon
2026-02-12 18:30 ` Onur Özkan
2026-02-13 12:15 ` Liviu Dudau
2026-02-13 12:42 ` Boris Brezillon
2026-02-13 12:59 ` Onur Özkan
2026-02-13 10:57 ` Liviu Dudau
2026-02-13 15:54 ` Mark Brown
2026-02-12 12:22 ` Boris Brezillon
2026-02-12 13:10 ` Mark Brown
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=20260212100538.170445-2-work@onurozkan.dev \
--to=work@onurozkan.dev \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=broonie@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/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.