4
4
//!
5
5
//! C header: [`include/linux/gpio/driver.h`](../../../../include/linux/gpio/driver.h)
6
6
7
+ use crate :: prelude:: * ;
7
8
use crate :: {
8
9
bindings, device, error:: code:: * , error:: from_kernel_result, sync:: LockClassKey ,
9
10
types:: PointerWrapper , Error , Result ,
@@ -27,16 +28,13 @@ pub enum LineDirection {
27
28
}
28
29
29
30
/// A gpio chip.
31
+ #[ vtable]
30
32
pub trait Chip {
31
33
/// Context data associated with the gpio chip.
32
34
///
33
35
/// It determines the type of the context data passed to each of the methods of the trait.
34
36
type Data : PointerWrapper + Sync + Send ;
35
37
36
- /// The methods to use to populate [`struct gpio_chip`]. This is typically populated with
37
- /// [`declare_gpio_chip_operations`].
38
- const TO_USE : ToUse ;
39
-
40
38
/// Returns the direction of the given gpio line.
41
39
fn get_direction (
42
40
_data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
@@ -73,52 +71,6 @@ pub trait Chip {
73
71
fn set ( _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > , _offset : u32 , _value : bool ) { }
74
72
}
75
73
76
- /// Represents which fields of [`struct gpio_chip`] should be populated with pointers.
77
- ///
78
- /// This is typically populated with the [`declare_gpio_chip_operations`] macro.
79
- pub struct ToUse {
80
- /// The `get_direction` field of [`struct gpio_chip`].
81
- pub get_direction : bool ,
82
-
83
- /// The `direction_input` field of [`struct gpio_chip`].
84
- pub direction_input : bool ,
85
-
86
- /// The `direction_output` field of [`struct gpio_chip`].
87
- pub direction_output : bool ,
88
-
89
- /// The `get` field of [`struct gpio_chip`].
90
- pub get : bool ,
91
-
92
- /// The `set` field of [`struct gpio_chip`].
93
- pub set : bool ,
94
- }
95
-
96
- /// A constant version where all values are set to `false`, that is, all supported fields will be
97
- /// set to null pointers.
98
- pub const USE_NONE : ToUse = ToUse {
99
- get_direction : false ,
100
- direction_input : false ,
101
- direction_output : false ,
102
- get : false ,
103
- set : false ,
104
- } ;
105
-
106
- /// Defines the [`Chip::TO_USE`] field based on a list of fields to be populated.
107
- #[ macro_export]
108
- macro_rules! declare_gpio_chip_operations {
109
- ( ) => {
110
- const TO_USE : $crate:: gpio:: ToUse = $crate:: gpio:: USE_NONE ;
111
- } ;
112
- ( $( $i: ident) ,+) => {
113
- #[ allow( clippy:: needless_update) ]
114
- const TO_USE : $crate:: gpio:: ToUse =
115
- $crate:: gpio:: ToUse {
116
- $( $i: true ) ,+ ,
117
- ..$crate:: gpio:: USE_NONE
118
- } ;
119
- } ;
120
- }
121
-
122
74
/// A registration of a gpio chip.
123
75
///
124
76
/// # Examples
@@ -130,9 +82,9 @@ macro_rules! declare_gpio_chip_operations {
130
82
/// use kernel::{device::RawDevice, gpio::{self, Registration}};
131
83
///
132
84
/// struct MyGpioChip;
85
+ /// #[vtable]
133
86
/// impl gpio::Chip for MyGpioChip {
134
87
/// type Data = ();
135
- /// kernel::declare_gpio_chip_operations!();
136
88
/// }
137
89
///
138
90
/// fn example(parent: &dyn RawDevice) -> Result<Pin<Box<Registration<MyGpioChip>>>> {
@@ -186,19 +138,19 @@ impl<T: Chip> Registration<T> {
186
138
// Set up the callbacks.
187
139
gc. request = Some ( bindings:: gpiochip_generic_request) ;
188
140
gc. free = Some ( bindings:: gpiochip_generic_free) ;
189
- if T :: TO_USE . get_direction {
141
+ if T :: HAS_GET_DIRECTION {
190
142
gc. get_direction = Some ( get_direction_callback :: < T > ) ;
191
143
}
192
- if T :: TO_USE . direction_input {
144
+ if T :: HAS_DIRECTION_INPUT {
193
145
gc. direction_input = Some ( direction_input_callback :: < T > ) ;
194
146
}
195
- if T :: TO_USE . direction_output {
147
+ if T :: HAS_DIRECTION_OUTPUT {
196
148
gc. direction_output = Some ( direction_output_callback :: < T > ) ;
197
149
}
198
- if T :: TO_USE . get {
150
+ if T :: HAS_GET {
199
151
gc. get = Some ( get_callback :: < T > ) ;
200
152
}
201
- if T :: TO_USE . set {
153
+ if T :: HAS_SET {
202
154
gc. set = Some ( set_callback :: < T > ) ;
203
155
}
204
156
0 commit comments