Skip to content

Commit

Permalink
rust: Add new abstraction for regmap
Browse files Browse the repository at this point in the history
Signed-off-by: Fabien Parent <[email protected]>
  • Loading branch information
Fabo committed Mar 1, 2024
1 parent da7df7f commit a88ecd3
Show file tree
Hide file tree
Showing 4 changed files with 799 additions and 0 deletions.
1 change: 1 addition & 0 deletions rust/bindings/bindings_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/platform_device.h>
#include <linux/poll.h>
#include <linux/refcount.h>
#include <linux/regmap.h>
#include <linux/sched.h>
#include <linux/security.h>
#include <linux/slab.h>
Expand Down
52 changes: 52 additions & 0 deletions rust/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/refcount.h>
#include <linux/regmap.h>
#include <linux/sched/signal.h>
#include <linux/security.h>
#include <linux/spinlock.h>
Expand Down Expand Up @@ -298,6 +299,57 @@ void rust_helper_i2c_set_clientdata(struct i2c_client *client, void *data)
}
EXPORT_SYMBOL_GPL(rust_helper_i2c_set_clientdata);

#ifdef CONFIG_REGMAP_I2C
struct regmap *rust_helper_regmap_init_i2c(struct i2c_client *i2c,
const struct regmap_config *config)
{
return regmap_init_i2c(i2c, config);
}
EXPORT_SYMBOL_GPL(rust_helper_regmap_init_i2c);
#endif

int rust_helper_regmap_field_write(struct regmap_field *field, unsigned int val)
{
return regmap_field_write(field, val);
}
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_write);

int rust_helper_regmap_field_force_write(struct regmap_field *field,
unsigned int val)
{
return regmap_field_force_write(field, val);
}
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_force_write);

int rust_helper_regmap_field_update_bits(struct regmap_field *field,
unsigned int mask, unsigned int val)
{
return regmap_field_update_bits(field, mask, val);
}
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_update_bits);

int rust_helper_regmap_field_set_bits(struct regmap_field *field,
unsigned int bits)
{
return regmap_field_set_bits(field, bits);
}
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_set_bits);

int rust_helper_regmap_field_clear_bits(struct regmap_field *field,
unsigned int bits)
{
return regmap_field_clear_bits(field, bits);
}
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_clear_bits);

int rust_helper_regmap_field_force_update_bits(struct regmap_field *field,
unsigned int mask,
unsigned int val)
{
return regmap_field_force_update_bits(field, mask, val);
}
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_force_update_bits);

/*
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
* use it in contexts where Rust expects a `usize` like slice (array) indices.
Expand Down
2 changes: 2 additions & 0 deletions rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub mod of;
pub mod platform;
pub mod prelude;
pub mod print;
#[cfg(CONFIG_REGMAP)]
pub mod regmap;
pub mod security;
mod static_assert;
#[doc(hidden)]
Expand Down
Loading

0 comments on commit a88ecd3

Please sign in to comment.