Skip to content

Commit a88ecd3

Browse files
committed
rust: Add new abstraction for regmap
Signed-off-by: Fabien Parent <[email protected]>
1 parent da7df7f commit a88ecd3

File tree

4 files changed

+799
-0
lines changed

4 files changed

+799
-0
lines changed

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/platform_device.h>
2424
#include <linux/poll.h>
2525
#include <linux/refcount.h>
26+
#include <linux/regmap.h>
2627
#include <linux/sched.h>
2728
#include <linux/security.h>
2829
#include <linux/slab.h>

rust/helpers.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/of_device.h>
3434
#include <linux/platform_device.h>
3535
#include <linux/refcount.h>
36+
#include <linux/regmap.h>
3637
#include <linux/sched/signal.h>
3738
#include <linux/security.h>
3839
#include <linux/spinlock.h>
@@ -298,6 +299,57 @@ void rust_helper_i2c_set_clientdata(struct i2c_client *client, void *data)
298299
}
299300
EXPORT_SYMBOL_GPL(rust_helper_i2c_set_clientdata);
300301

302+
#ifdef CONFIG_REGMAP_I2C
303+
struct regmap *rust_helper_regmap_init_i2c(struct i2c_client *i2c,
304+
const struct regmap_config *config)
305+
{
306+
return regmap_init_i2c(i2c, config);
307+
}
308+
EXPORT_SYMBOL_GPL(rust_helper_regmap_init_i2c);
309+
#endif
310+
311+
int rust_helper_regmap_field_write(struct regmap_field *field, unsigned int val)
312+
{
313+
return regmap_field_write(field, val);
314+
}
315+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_write);
316+
317+
int rust_helper_regmap_field_force_write(struct regmap_field *field,
318+
unsigned int val)
319+
{
320+
return regmap_field_force_write(field, val);
321+
}
322+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_force_write);
323+
324+
int rust_helper_regmap_field_update_bits(struct regmap_field *field,
325+
unsigned int mask, unsigned int val)
326+
{
327+
return regmap_field_update_bits(field, mask, val);
328+
}
329+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_update_bits);
330+
331+
int rust_helper_regmap_field_set_bits(struct regmap_field *field,
332+
unsigned int bits)
333+
{
334+
return regmap_field_set_bits(field, bits);
335+
}
336+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_set_bits);
337+
338+
int rust_helper_regmap_field_clear_bits(struct regmap_field *field,
339+
unsigned int bits)
340+
{
341+
return regmap_field_clear_bits(field, bits);
342+
}
343+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_clear_bits);
344+
345+
int rust_helper_regmap_field_force_update_bits(struct regmap_field *field,
346+
unsigned int mask,
347+
unsigned int val)
348+
{
349+
return regmap_field_force_update_bits(field, mask, val);
350+
}
351+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_force_update_bits);
352+
301353
/*
302354
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
303355
* use it in contexts where Rust expects a `usize` like slice (array) indices.

rust/kernel/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub mod of;
5353
pub mod platform;
5454
pub mod prelude;
5555
pub mod print;
56+
#[cfg(CONFIG_REGMAP)]
57+
pub mod regmap;
5658
pub mod security;
5759
mod static_assert;
5860
#[doc(hidden)]

0 commit comments

Comments
 (0)