rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] rust: i2c: Add basic I2C driver abstractions
@ 2025-08-01 15:37 Igor Korotin
  2025-08-01 15:40 ` [PATCH v3 1/3] rust: i2c: add basic I2C device and " Igor Korotin
                   ` (3 more replies)
  0 siblings, 4 replies; 39+ messages in thread
From: Igor Korotin @ 2025-08-01 15:37 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	rust-for-linux

This patch series lays the groundwork for writing Linux I2C drivers in 
Rust by:

 1. Core abstractions 
    Introduce `i2c::Device`, `i2c::Driver` and `i2c::Adapter` built on 
    the existing `struct i2c_client` and `struct i2c_driver`, with safe 
    Rust wrappers around probe, transfer, and teardown logic.

 2. Manual device creation  
    Provide an API to register an I2C device at runtime from Rust using
    `I2cBoardInfo`, including automatic cleanup when the driver unloads.

 3. Sample driver (legacy table, OF & ACPI)  
    Add `rust_driver_i2c`, a sample that:
      - creates an I2C client device using `i2c::Registration::new()`
      - binds to an I2C client via: 
        - legacy I2C-ID table, 
        - Open Firmware (device-tree) compatible strings, or
        - ACPI IDs.
      - destroyes the I2C client device on exit.

Together, these three patches:

- Establish the essential Rust traits and types for I2C drivers.
- Enable driver binding via legacy ID table, device-tree (OF), or ACPI
- Enable manual device creation at runtime.
- Ship a samples showing typical usage 

Igor Korotin (3):
  rust: i2c: add basic I2C device and driver abstractions
  rust: i2c: add manual I2C device creation abstractions
  samples: rust: add Rust I2C sample driver

Changelog
---------
v3: 
 - removed unnecessary i2c_get_clientdata and i2c_set_clientdata rust 
   helpers. Using generic accessors implemented in [1] instead.
 - Reimplemented i2c::DeviceId based on changes in [2].
 - Using from_result in i2c::Adapter::probe_callback
 - Using explicit drop() for i2c client private data in 
   `i2c::Adapter::remove_callback`
 - replaced device::Device::as_ref() with device::Device::from_raw in 
   `i2c::Device::as_ref()`. It is renamed in device::Device.
 - Build Rust I2C only if I2C is built-in
 - Reimplement overcomplicated trait i2c::DeviceOwned the same way it is 
   implemented in auxiliary [3].
 - Merge rust_device_i2c and rust_driver_i2c samples. Resulting 
   rust_driver_i2c creates pined i2c_client using i2c::Registration::new 
   and probes newly created i2c_client.
 - Created a new entry in MAINTAINERS file containing i2c.rs and 
   rust_driver_i2c.rs in it.
 - Link to v2: [4] 

 [1] https://lore.kernel.org/lkml/20250621195118.124245-3-dakr@kernel.org/
 [2] https://lore.kernel.org/rust-for-linux/20250711040947.1252162-1-fujita.tomonori@gmail.com/
 [3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/rust/kernel/auxiliary.rs?h=v6.16-rc4#n299
 [4] https://lore.kernel.org/rust-for-linux/20250704153332.1193214-1-igor.korotin.linux@gmail.com/ 

v2:
 - Merged separated ACPI support patches since ACPI-table support is 
   merged into driver-core-next.
 - Added I2cAdapterRef and I2cBoardInfo abstractions 
 - Added DeviceState generic parameter which is used for `i2c::Device`
   as a sign if the device is created manually
 - Added `DeviceOwned` abstraction which is a safe reference to a 
   manually created `i2c::Device<Ctx, state::Owned>`. 
 - Added Rust manual I2C device creation sample
 - Link to v1: https://lore.kernel.org/rust-for-linux/20250626174623.904917-1-igor.korotin.linux@gmail.com/

 MAINTAINERS                     |   8 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/i2c.rs              | 498 ++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |   2 +
 samples/rust/Kconfig            |  11 +
 samples/rust/Makefile           |   1 +
 samples/rust/rust_driver_i2c.rs | 106 +++++++
 7 files changed, 627 insertions(+)
 create mode 100644 rust/kernel/i2c.rs
 create mode 100644 samples/rust/rust_driver_i2c.rs


base-commit: 260f6f4fda93c8485c8037865c941b42b9cba5d2
-- 
2.43.0


^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2025-08-15 17:16 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-01 15:37 [PATCH v3 0/3] rust: i2c: Add basic I2C driver abstractions Igor Korotin
2025-08-01 15:40 ` [PATCH v3 1/3] rust: i2c: add basic I2C device and " Igor Korotin
2025-08-01 17:14   ` Daniel Almeida
2025-08-02  0:22     ` Danilo Krummrich
2025-08-04 14:16     ` Igor Korotin
2025-08-02  0:00   ` Danilo Krummrich
2025-08-02  9:07     ` Wolfram Sang
2025-08-02 10:51       ` Danilo Krummrich
2025-08-02 12:14         ` Wolfram Sang
2025-08-02 12:41           ` Danilo Krummrich
2025-08-04 14:58     ` Igor Korotin
2025-08-04 15:17       ` Danilo Krummrich
2025-08-04 15:24         ` Miguel Ojeda
2025-08-04 15:40         ` Igor Korotin
2025-08-04 16:11           ` Wolfram Sang
2025-08-04 17:15             ` Danilo Krummrich
2025-08-04 22:01               ` Wolfram Sang
2025-08-05  8:37                 ` Igor Korotin
2025-08-05  9:28                   ` Wolfram Sang
2025-08-05 12:40                 ` Daniel Almeida
2025-08-04 17:26             ` Igor Korotin
2025-08-04 17:46               ` Miguel Ojeda
2025-08-04 21:57               ` Wolfram Sang
2025-08-15 15:40     ` Igor Korotin
2025-08-15 16:03       ` Danilo Krummrich
2025-08-15 17:04         ` Greg KH
2025-08-15 17:16           ` Danilo Krummrich
2025-08-01 15:44 ` [PATCH v3 2/3] rust: i2c: add manual I2C device creation abstractions Igor Korotin
2025-08-01 17:59   ` Daniel Almeida
2025-08-02  0:26     ` Danilo Krummrich
2025-08-04 14:38     ` Igor Korotin
2025-08-02  0:12   ` Danilo Krummrich
2025-08-01 15:45 ` [PATCH v3 3/3] samples: rust: add Rust I2C sample driver Igor Korotin
2025-08-01 18:09   ` Daniel Almeida
2025-08-04 14:43     ` Igor Korotin
2025-08-04 14:58       ` Daniel Almeida
2025-08-02  0:18   ` Danilo Krummrich
2025-08-07  8:42   ` kernel test robot
2025-08-04 15:07 ` [PATCH v3 0/3] rust: i2c: Add basic I2C driver abstractions Daniel Almeida

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).