Skip to content

Commit ef616b9

Browse files
committed
Add a bare-minimum Regulator abstraction
Merge series from Daniel Almeida <[email protected]>: Add basic rust bindings for the regulator API.
2 parents 63be976 + d9f334f commit ef616b9

File tree

6 files changed

+465
-0
lines changed

6 files changed

+465
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26561,6 +26561,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git
2656126561
F: Documentation/devicetree/bindings/regulator/
2656226562
F: Documentation/power/regulator/
2656326563
F: drivers/regulator/
26564+
F: rust/kernel/regulator.rs
2656426565
F: include/dt-bindings/regulator/
2656526566
F: include/linux/regulator/
2656626567
K: regulator_get_optional

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <linux/poll.h>
6666
#include <linux/property.h>
6767
#include <linux/refcount.h>
68+
#include <linux/regulator/consumer.h>
6869
#include <linux/sched.h>
6970
#include <linux/security.h>
7071
#include <linux/slab.h>

rust/helpers/helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "pci.c"
3434
#include "pid_namespace.c"
3535
#include "rbtree.c"
36+
#include "regulator.c"
3637
#include "rcu.c"
3738
#include "refcount.c"
3839
#include "security.c"

rust/helpers/regulator.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/regulator/consumer.h>
4+
5+
#ifndef CONFIG_REGULATOR
6+
7+
void rust_helper_regulator_put(struct regulator *regulator)
8+
{
9+
regulator_put(regulator);
10+
}
11+
12+
int rust_helper_regulator_set_voltage(struct regulator *regulator, int min_uV,
13+
int max_uV)
14+
{
15+
return regulator_set_voltage(regulator, min_uV, max_uV);
16+
}
17+
18+
int rust_helper_regulator_get_voltage(struct regulator *regulator)
19+
{
20+
return regulator_get_voltage(regulator);
21+
}
22+
23+
struct regulator *rust_helper_regulator_get(struct device *dev, const char *id)
24+
{
25+
return regulator_get(dev, id);
26+
}
27+
28+
int rust_helper_regulator_enable(struct regulator *regulator)
29+
{
30+
return regulator_enable(regulator);
31+
}
32+
33+
int rust_helper_regulator_disable(struct regulator *regulator)
34+
{
35+
return regulator_disable(regulator);
36+
}
37+
38+
int rust_helper_regulator_is_enabled(struct regulator *regulator)
39+
{
40+
return regulator_is_enabled(regulator);
41+
}
42+
43+
#endif

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub mod platform;
100100
pub mod prelude;
101101
pub mod print;
102102
pub mod rbtree;
103+
pub mod regulator;
103104
pub mod revocable;
104105
pub mod security;
105106
pub mod seq_file;

0 commit comments

Comments
 (0)