[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <DCQ9K980YX1W.HZIQI6S5MST9@kernel.org>
Date: Thu, 11 Sep 2025 22:46:27 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Igor Korotin" <igor.korotin.linux@...il.com>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
<alex.gaynor@...il.com>, "Wolfram Sang" <wsa+renesas@...g-engineering.com>,
"Boqun Feng" <boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Alice
Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>, "Greg
Kroah-Hartman" <gregkh@...uxfoundation.org>, "Viresh Kumar"
<viresh.kumar@...aro.org>, "Asahi Lina" <lina+kernel@...hilina.net>,
"Wedson Almeida Filho" <wedsonaf@...il.com>, "Alex Hung"
<alex.hung@....com>, "Tamir Duberstein" <tamird@...il.com>, "Xiangfei Ding"
<dingxiangfei2009@...il.com>, <linux-kernel@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>, <linux-i2c@...r.kernel.org>
Subject: Re: [PATCH v5 3/3] samples: rust: add Rust I2C sample driver
On Thu Sep 11, 2025 at 5:50 PM CEST, Igor Korotin wrote:
> +// NOTE: The code below is expanded macro module_i2c_driver. It is not used here
> +// because we need to manually create an I2C client in `init()`. The macro
> +// hides `init()`, so to demo client creation on adapter SAMPLE_I2C_ADAPTER_INDEX
> +// we expand it by hand.
> +type Ops<T> = kernel::i2c::Adapter<T>;
Not a huge fan of this type alias, but up to you. :)
> +#[pin_data]
> +struct DriverModule {
> + #[pin]
> + _driver: kernel::driver::Registration<Ops<SampleDriver>>,
> + _reg: i2c::Registration,
> +}
> +
> +impl kernel::InPlaceModule for DriverModule {
> + fn init(
> + module: &'static kernel::ThisModule,
> + ) -> impl ::pin_init::PinInit<Self, kernel::error::Error> {
> + kernel::try_pin_init!(Self {
> + _reg <- {
> + let adapter = i2c::I2cAdapter::<Normal>::get(SAMPLE_I2C_ADAPTER_INDEX)?;
Just i2c::I2cAdapter::get() is fine.
> +
> + i2c::Registration::new(adapter.as_ref(), &BOARD_INFO)
Does i2c_new_client_device() grab a reference count of the adapter? If not, you
have to store an ARef<I2cAdapter> within your i2c::Registration as well.
> + },
> + _driver <- kernel::driver::Registration::new(<Self as kernel::ModuleMetadata>::NAME,module,),
> + })
> + }
> +}
Powered by blists - more mailing lists