Skip to content

Commit 9b614ce

Browse files
dwlsalmeidabroonie
authored andcommitted
rust: regulator: add a bare minimum regulator abstraction
Add a bare minimum regulator abstraction to be used by Rust drivers. This abstraction adds a small subset of the regulator API, which is thought to be sufficient for the drivers we have now. Regulators provide the power needed by many hardware blocks and thus are likely to be needed by a lot of drivers. It was tested on rk3588, where it was used to power up the "mali" regulator in order to power up the GPU. Reviewed-by: Alexandre Courbot <[email protected]> Signed-off-by: Daniel Almeida <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 347e9f5 commit 9b614ce

File tree

5 files changed

+464
-0
lines changed

5 files changed

+464
-0
lines changed

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)