From: "Danilo Krummrich" <dakr@kernel.org>
To: "Ke Sun" <sunke@kylinos.cn>
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"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>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-rtc@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Alvin Sun" <sk.alvin.x@gmail.com>
Subject: Re: [RFC PATCH v2 5/5] rust: add PL031 RTC driver
Date: Thu, 08 Jan 2026 12:57:53 +0100 [thread overview]
Message-ID: <DFJ6UDWFODEP.3RJFR83S468HV@kernel.org> (raw)
In-Reply-To: <20260107143738.3021892-6-sunke@kylinos.cn>
On Wed Jan 7, 2026 at 3:37 PM CET, Ke Sun wrote:
> +impl amba::Driver for Pl031AmbaDriver {
> + type IdInfo = Pl031Variant;
> + const AMBA_ID_TABLE: Option<amba::IdTable<Self::IdInfo>> = Some(&ID_TABLE);
> +
> + fn probe(
> + adev: &amba::Device<Core>,
> + id_info: Option<&Self::IdInfo>,
> + ) -> impl PinInit<Self, Error> {
> + let dev = adev.as_ref();
> + let io_request = adev.io_request().ok_or(ENODEV)?;
> + let variant = id_info
> + .map(|info| info.variant)
> + .unwrap_or(VendorVariant::Arm);
> +
> + let rtcdev = RtcDevice::<Pl031DrvData>::new(
> + dev,
> + try_pin_init!(Pl031DrvData {
> + base <- IoMem::new(io_request),
> + variant,
> + }),
> + )?;
> +
> + dev.devm_init_wakeup()?;
> +
> + let drvdata = rtcdev.drvdata()?;
> + let base_guard = drvdata.base.try_access().ok_or(ENXIO)?;
You can just use drvdata.base.access(adev.as_ref()), the &amba::Device<Core>
(which derives to device::Device<Bound>) proves that this access is valid
without any sychronization.
(This is also the reason why you want the parent device as &Device<Bound> in
your class device callbacks.)
> + let base = base_guard.deref();
> +
> + let mut cr = base.read32(RTC_CR);
> + if variant.clockwatch() {
> + cr |= RTC_CR_CWEN;
> + } else {
> + cr |= RTC_CR_EN;
> + }
> + base.write32(cr, RTC_CR);
> +
> + if variant.st_weekday() {
> + let bcd_year = base.read32(RTC_YDR);
> + if bcd_year == 0x2000 {
> + let st_time = base.read32(RTC_DR);
> + if (st_time & (RTC_MON_MASK | RTC_MDAY_MASK | RTC_WDAY_MASK)) == 0x02120000 {
> + base.write32(0x2000, RTC_YLR);
> + base.write32(st_time | (0x7 << RTC_WDAY_SHIFT), RTC_LR);
> + }
> + }
> + }
> +
> + rtcdev.set_range_min(variant.range_min());
> + rtcdev.set_range_max(variant.range_max());
> +
> + let irq_flags = if variant == VendorVariant::StV2 {
> + kernel::irq::Flags::SHARED | kernel::irq::Flags::COND_SUSPEND
> + } else {
> + kernel::irq::Flags::SHARED
> + };
> +
> + let rtcdev_clone = rtcdev.clone();
> + let init = adev.request_irq_by_index(
> + irq_flags,
> + 0,
> + c_str!("rtc-pl031"),
> + try_pin_init!(Pl031IrqHandler {
> + _pin: PhantomPinned,
> + rtcdev: rtcdev_clone,
> + }),
> + );
> +
> + match kernel::devres::register(dev, init, GFP_KERNEL) {
This is not needed, request_irq_by_index() already returns an
impl PinInit<Devres<_>, Error>, just store this in Pl031AmbaDriver.
> + Ok(()) => {
> + if let Ok(irq) = adev.irq_by_index(0) {
> + irq.set_wake_irq()?;
> + }
> + }
> + Err(_) => rtcdev.clear_feature(bindings::RTC_FEATURE_ALARM),
> + }
> +
> + Registration::<Pl031DrvData>::register(dev, rtcdev)?;
> + Ok(Pl031AmbaDriver)
> + }
> +}
> +
> +#[pinned_drop]
> +impl PinnedDrop for Pl031DrvData {
> + fn drop(self: Pin<&mut Self>) {
> + // Resources are automatically cleaned up by devres.
> + }
> +}
No need for this empty impl.
prev parent reply other threads:[~2026-01-08 11:57 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 14:37 [RFC PATCH v2 0/5] rust: Add RTC driver support Ke Sun
2026-01-07 14:37 ` [RFC PATCH v2 1/5] rtc: migrate driver data to RTC device Ke Sun
2026-01-07 14:41 ` Ke Sun
2026-01-07 16:12 ` Greg KH
2026-01-07 23:18 ` Ke Sun
2026-01-08 0:24 ` Ke Sun
2026-01-08 11:06 ` Danilo Krummrich
2026-01-08 5:46 ` Greg KH
2026-01-08 9:02 ` Ke Sun
2026-01-08 9:10 ` Greg KH
2026-01-08 11:12 ` Danilo Krummrich
2026-01-08 13:45 ` Ke Sun
2026-01-08 13:52 ` Danilo Krummrich
2026-01-08 14:01 ` Ke Sun
2026-01-08 14:01 ` Alexandre Belloni
2026-01-08 14:06 ` Danilo Krummrich
2026-02-20 23:19 ` Alexandre Belloni
2026-01-14 23:23 ` Ke Sun
2026-01-14 23:48 ` Danilo Krummrich
2026-01-07 14:37 ` [RFC PATCH v2 2/5] rust: add AMBA bus driver support Ke Sun
2026-01-08 11:29 ` Danilo Krummrich
2026-01-07 14:37 ` [RFC PATCH v2 3/5] rust: add device wakeup capability support Ke Sun
2026-01-07 14:57 ` Greg KH
2026-01-07 23:35 ` Ke Sun
2026-01-07 14:37 ` [RFC PATCH v2 4/5] rust: add RTC core abstractions and data structures Ke Sun
2026-01-08 11:50 ` Danilo Krummrich
2026-01-08 13:17 ` Ke Sun
2026-01-08 13:49 ` Miguel Ojeda
2026-01-08 13:56 ` Ke Sun
2026-01-08 23:31 ` Kari Argillander
2026-01-07 14:37 ` [RFC PATCH v2 5/5] rust: add PL031 RTC driver Ke Sun
2026-01-08 11:57 ` Danilo Krummrich [this message]
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=DFJ6UDWFODEP.3RJFR83S468HV@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-rtc@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sk.alvin.x@gmail.com \
--cc=sunke@kylinos.cn \
--cc=tmgross@umich.edu \
/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.