Skip to content

Commit ac06bae

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

File tree

4 files changed

+768
-0
lines changed

4 files changed

+768
-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: 50 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,55 @@ void rust_helper_i2c_set_clientdata(struct i2c_client *client, void *data)
298299
}
299300
EXPORT_SYMBOL_GPL(rust_helper_i2c_set_clientdata);
300301

302+
struct regmap *rust_helper_regmap_init_i2c(struct i2c_client *i2c,
303+
const struct regmap_config *config)
304+
{
305+
return regmap_init_i2c(i2c, config);
306+
}
307+
EXPORT_SYMBOL_GPL(rust_helper_regmap_init_i2c);
308+
309+
int rust_helper_regmap_field_write(struct regmap_field *field, unsigned int val)
310+
{
311+
return regmap_field_write(field, val);
312+
}
313+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_write);
314+
315+
int rust_helper_regmap_field_force_write(struct regmap_field *field,
316+
unsigned int val)
317+
{
318+
return regmap_field_force_write(field, val);
319+
}
320+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_force_write);
321+
322+
int rust_helper_regmap_field_update_bits(struct regmap_field *field,
323+
unsigned int mask, unsigned int val)
324+
{
325+
return regmap_field_update_bits(field, mask, val);
326+
}
327+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_update_bits);
328+
329+
int rust_helper_regmap_field_set_bits(struct regmap_field *field,
330+
unsigned int bits)
331+
{
332+
return regmap_field_set_bits(field, bits);
333+
}
334+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_set_bits);
335+
336+
int rust_helper_regmap_field_clear_bits(struct regmap_field *field,
337+
unsigned int bits)
338+
{
339+
return regmap_field_clear_bits(field, bits);
340+
}
341+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_clear_bits);
342+
343+
int rust_helper_regmap_field_force_update_bits(struct regmap_field *field,
344+
unsigned int mask,
345+
unsigned int val)
346+
{
347+
return regmap_field_force_update_bits(field, mask, val);
348+
}
349+
EXPORT_SYMBOL_GPL(rust_helper_regmap_field_force_update_bits);
350+
301351
/*
302352
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
303353
* 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)