Skip to content

Commit b7b7b98

Browse files
committed
rust: clk: Add helpers for Rust code
Non-trivial C macros and inlined C functions cannot be used directly in the Rust code and are used via functions ("helpers") that wrap those so that they can be called from Rust. In order to prepare for adding Rust abstractions for the clock APIs, add clock helpers required by the Rust implementation. Reviewed-by: Daniel Almeida <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent ab49f64 commit b7b7b98

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5883,6 +5883,7 @@ F: include/dt-bindings/clock/
58835883
F: include/linux/clk-pr*
58845884
F: include/linux/clk/
58855885
F: include/linux/of_clk.h
5886+
F: rust/helpers/clk.c
58865887
X: drivers/clk/clkdev.c
58875888

58885889
COMMON INTERNET FILE SYSTEM CLIENT (CIFS and SMB3)

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/blk-mq.h>
1111
#include <linux/blk_types.h>
1212
#include <linux/blkdev.h>
13+
#include <linux/clk.h>
1314
#include <linux/cpumask.h>
1415
#include <linux/cred.h>
1516
#include <linux/device/faux.h>

rust/helpers/clk.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/clk.h>
4+
5+
/*
6+
* The "inline" implementation of below helpers are only available when
7+
* CONFIG_HAVE_CLK or CONFIG_HAVE_CLK_PREPARE aren't set.
8+
*/
9+
#ifndef CONFIG_HAVE_CLK
10+
struct clk *rust_helper_clk_get(struct device *dev, const char *id)
11+
{
12+
return clk_get(dev, id);
13+
}
14+
15+
void rust_helper_clk_put(struct clk *clk)
16+
{
17+
clk_put(clk);
18+
}
19+
20+
int rust_helper_clk_enable(struct clk *clk)
21+
{
22+
return clk_enable(clk);
23+
}
24+
25+
void rust_helper_clk_disable(struct clk *clk)
26+
{
27+
clk_disable(clk);
28+
}
29+
30+
unsigned long rust_helper_clk_get_rate(struct clk *clk)
31+
{
32+
return clk_get_rate(clk);
33+
}
34+
35+
int rust_helper_clk_set_rate(struct clk *clk, unsigned long rate)
36+
{
37+
return clk_set_rate(clk, rate);
38+
}
39+
#endif
40+
41+
#ifndef CONFIG_HAVE_CLK_PREPARE
42+
int rust_helper_clk_prepare(struct clk *clk)
43+
{
44+
return clk_prepare(clk);
45+
}
46+
47+
void rust_helper_clk_unprepare(struct clk *clk)
48+
{
49+
clk_unprepare(clk);
50+
}
51+
#endif
52+
53+
struct clk *rust_helper_clk_get_optional(struct device *dev, const char *id)
54+
{
55+
return clk_get_optional(dev, id);
56+
}
57+
58+
int rust_helper_clk_prepare_enable(struct clk *clk)
59+
{
60+
return clk_prepare_enable(clk);
61+
}
62+
63+
void rust_helper_clk_disable_unprepare(struct clk *clk)
64+
{
65+
clk_disable_unprepare(clk);
66+
}

rust/helpers/helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "bug.c"
1212
#include "build_assert.c"
1313
#include "build_bug.c"
14+
#include "clk.c"
1415
#include "cpumask.c"
1516
#include "cred.c"
1617
#include "device.c"

0 commit comments

Comments
 (0)