Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: add regulator consumer abstraction #1040

Draft
wants to merge 23 commits into
base: rust-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cf1c264
rust: init: introduce `Opaque::try_ffi_init`
wedsonaf Sep 29, 2023
8aeeac0
rust: introduce `InPlaceModule`
wedsonaf Sep 29, 2023
87c42cc
rust: pass module name to `Module::init`
dakr Jun 3, 2024
8a35ce7
rust: implement generic driver registration
dakr Jun 14, 2024
ac78255
rust: implement `IdArray`, `IdTable` and `RawDeviceId`
wedsonaf Jun 14, 2024
06f7253
rust: add rcu abstraction
wedsonaf Sep 4, 2023
0a825e9
rust: add `Revocable` type
wedsonaf Sep 4, 2023
6eff552
rust: add `dev_*` print macros.
wedsonaf Feb 16, 2023
179b336
rust: add `io::Io` base type
dakr Jun 14, 2024
0090972
rust: add devres abstraction
dakr May 6, 2024
ff8aaa1
ASAHI: rust: device_id: Support passing ID tables to modpost for alia…
Fabo Apr 28, 2024
24034de
IMPORT: rust: port 'of' api from 'rust' branch
Fabo Nov 10, 2023
3f9c822
IMPORT: rust: port platform api from 'rust' branch
Fabo Nov 10, 2023
191b0bb
rust: str: allow dereferencing BStr in a const ctx
Fabo Mar 6, 2024
70ed30f
rust: add I2C client abstraction
kloenk Dec 17, 2022
5c50ca2
rust: add function to create masks
Fabo Dec 16, 2023
9633937
rust: macros: paste: add support for using var as part of group
Fabo Dec 19, 2023
0b998f3
rust: macros: add foreach! macro to repeat code
Fabo Dec 20, 2023
ec0b740
rust: Add new abstraction for regmap
Fabo Nov 29, 2023
8b27764
rust: error: Add declaration for ENOTRECOVERABLE error
Fabo Feb 8, 2024
a48271f
rust: regulator: add regulator consumer abstractions
Fabo Nov 13, 2023
5a70950
rust: regulator: add Regulator Driver abstraction
Fabo Dec 6, 2023
0abbabb
rust: regulator: Add support for regmap
Fabo Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rust/bindings/bindings_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
#include <linux/errname.h>
#include <linux/ethtool.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
#include <linux/jiffies.h>
#include <linux/mdio.h>
#include <linux/phy.h>
#include <linux/platform_device.h>
#include <linux/refcount.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/driver.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/wait.h>
Expand Down
8 changes: 8 additions & 0 deletions rust/helpers/devm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/device.h>

int rust_helper_devm_add_action(struct device *dev, void (*action)(void *), void *data)
{
return devm_add_action(dev, action, data);
}
7 changes: 7 additions & 0 deletions rust/helpers/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
#include "bug.c"
#include "build_assert.c"
#include "build_bug.c"
#include "devm.c"
#include "err.c"
#include "i2c.c"
#include "io.c"
#include "kunit.c"
#include "mutex.c"
#include "of.c"
#include "page.c"
#include "platform.c"
#include "rbtree.c"
#include "rcu.c"
#include "refcount.c"
#include "regmap.c"
#include "signal.c"
#include "slab.c"
#include "spinlock.c"
Expand Down
13 changes: 13 additions & 0 deletions rust/helpers/i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/i2c.h>

void *rust_helper_i2c_get_clientdata(const struct i2c_client *client)
{
return i2c_get_clientdata(client);
}

void rust_helper_i2c_set_clientdata(struct i2c_client *client, void *data)
{
i2c_set_clientdata(client, data);
}
91 changes: 91 additions & 0 deletions rust/helpers/io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/io.h>

u8 rust_helper_readb(const volatile void __iomem *addr)
{
return readb(addr);
}

u16 rust_helper_readw(const volatile void __iomem *addr)
{
return readw(addr);
}

u32 rust_helper_readl(const volatile void __iomem *addr)
{
return readl(addr);
}

#ifdef CONFIG_64BIT
u64 rust_helper_readq(const volatile void __iomem *addr)
{
return readq(addr);
}
#endif

void rust_helper_writeb(u8 value, volatile void __iomem *addr)
{
writeb(value, addr);
}

void rust_helper_writew(u16 value, volatile void __iomem *addr)
{
writew(value, addr);
}

void rust_helper_writel(u32 value, volatile void __iomem *addr)
{
writel(value, addr);
}

#ifdef CONFIG_64BIT
void rust_helper_writeq(u64 value, volatile void __iomem *addr)
{
writeq(value, addr);
}
#endif

u8 rust_helper_readb_relaxed(const volatile void __iomem *addr)
{
return readb_relaxed(addr);
}

u16 rust_helper_readw_relaxed(const volatile void __iomem *addr)
{
return readw_relaxed(addr);
}

u32 rust_helper_readl_relaxed(const volatile void __iomem *addr)
{
return readl_relaxed(addr);
}

#ifdef CONFIG_64BIT
u64 rust_helper_readq_relaxed(const volatile void __iomem *addr)
{
return readq_relaxed(addr);
}
#endif

void rust_helper_writeb_relaxed(u8 value, volatile void __iomem *addr)
{
writeb_relaxed(value, addr);
}

void rust_helper_writew_relaxed(u16 value, volatile void __iomem *addr)
{
writew_relaxed(value, addr);
}

void rust_helper_writel_relaxed(u32 value, volatile void __iomem *addr)
{
writel_relaxed(value, addr);
}

#ifdef CONFIG_64BIT
void rust_helper_writeq_relaxed(u64 value, volatile void __iomem *addr)
{
writeq_relaxed(value, addr);
}
#endif
9 changes: 9 additions & 0 deletions rust/helpers/of.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/of_device.h>

const struct of_device_id *rust_helper_of_match_device(
const struct of_device_id *matches, const struct device *dev)
{
return of_match_device(matches, dev);
}
13 changes: 13 additions & 0 deletions rust/helpers/platform.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/platform_device.h>

void *rust_helper_platform_get_drvdata(const struct platform_device *pdev)
{
return platform_get_drvdata(pdev);
}

void rust_helper_platform_set_drvdata(struct platform_device *pdev, void *data)
{
return platform_set_drvdata(pdev, data);
}
13 changes: 13 additions & 0 deletions rust/helpers/rcu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/rcupdate.h>

void rust_helper_rcu_read_lock(void)
{
rcu_read_lock();
}

void rust_helper_rcu_read_unlock(void)
{
rcu_read_unlock();
}
48 changes: 48 additions & 0 deletions rust/helpers/regmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/i2c.h>
#include <linux/regmap.h>

#if IS_BUILTIN(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);
}
#endif

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

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

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);
}

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

int rust_helper_regmap_field_clear_bits(struct regmap_field *field,
unsigned int bits)
{
return regmap_field_clear_bits(field, 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);
}
12 changes: 12 additions & 0 deletions rust/kernel/bits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-2.0

//! Bit manipulation helpers
//!
//! C header: [`include/linux/bits.h`](srctree/include/linux/bits.h)

/// Generate a mask where all bits >= `h` and <= `l` are set
///
/// This is a re-implementation in rust of `GENMASK`
pub const fn genmask(h: u32, l: u32) -> u32 {
((!0u32) - (1 << l) + 1) & ((!0u32) >> (32 - 1 - h))
}
Loading