Skip to content

Commit a69a54f

Browse files
ukleinekUwe Kleine-König
authored andcommitted
rust: pwm: Drop wrapping of PWM polarity and state
These were introduced and used in an earlier revision of the patch that became commit fb3957a ("pwm: Add Rust driver for T-HEAD TH1520 SoC"). The variant that was actually applied sticks to the modern waveform abstraction only (and other drivers are supposed to do that, too), so they can be dropped. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://patch.msgid.link/20251025122359.361372-2-u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent 264b501 commit a69a54f

1 file changed

Lines changed: 1 addition & 55 deletions

File tree

rust/kernel/pwm.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,7 @@ use crate::{
1515
prelude::*,
1616
types::{ARef, AlwaysRefCounted, Opaque},
1717
};
18-
use core::{convert::TryFrom, marker::PhantomData, ptr::NonNull};
19-
20-
/// PWM polarity. Mirrors [`enum pwm_polarity`](srctree/include/linux/pwm.h).
21-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
22-
pub enum Polarity {
23-
/// Normal polarity (duty cycle defines the high period of the signal).
24-
Normal,
25-
26-
/// Inversed polarity (duty cycle defines the low period of the signal).
27-
Inversed,
28-
}
29-
30-
impl TryFrom<bindings::pwm_polarity> for Polarity {
31-
type Error = Error;
32-
33-
fn try_from(polarity: bindings::pwm_polarity) -> Result<Self, Error> {
34-
match polarity {
35-
bindings::pwm_polarity_PWM_POLARITY_NORMAL => Ok(Polarity::Normal),
36-
bindings::pwm_polarity_PWM_POLARITY_INVERSED => Ok(Polarity::Inversed),
37-
_ => Err(EINVAL),
38-
}
39-
}
40-
}
41-
42-
impl From<Polarity> for bindings::pwm_polarity {
43-
fn from(polarity: Polarity) -> Self {
44-
match polarity {
45-
Polarity::Normal => bindings::pwm_polarity_PWM_POLARITY_NORMAL,
46-
Polarity::Inversed => bindings::pwm_polarity_PWM_POLARITY_INVERSED,
47-
}
48-
}
49-
}
18+
use core::{marker::PhantomData, ptr::NonNull};
5019

5120
/// Represents a PWM waveform configuration.
5221
/// Mirrors struct [`struct pwm_waveform`](srctree/include/linux/pwm.h).
@@ -89,22 +58,6 @@ impl From<Waveform> for bindings::pwm_waveform {
8958
}
9059
}
9160

92-
/// Wrapper for PWM state [`struct pwm_state`](srctree/include/linux/pwm.h).
93-
#[repr(transparent)]
94-
pub struct State(bindings::pwm_state);
95-
96-
impl State {
97-
/// Creates a `State` wrapper by taking ownership of a C `pwm_state` value.
98-
pub(crate) fn from_c(c_state: bindings::pwm_state) -> Self {
99-
State(c_state)
100-
}
101-
102-
/// Returns `true` if the PWM signal is enabled.
103-
pub fn enabled(&self) -> bool {
104-
self.0.enabled
105-
}
106-
}
107-
10861
/// Describes the outcome of a `round_waveform` operation.
10962
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11063
pub enum RoundingOutcome {
@@ -164,13 +117,6 @@ impl Device {
164117
Some(unsafe { CStr::from_char_ptr(label_ptr) })
165118
}
166119

167-
/// Gets a copy of the current state of this PWM device.
168-
pub fn state(&self) -> State {
169-
// SAFETY: `self.as_raw()` gives a valid pointer. `(*self.as_raw()).state`
170-
// is a valid `pwm_state` struct. `State::from_c` copies this data.
171-
State::from_c(unsafe { (*self.as_raw()).state })
172-
}
173-
174120
/// Sets the PWM waveform configuration and enables the PWM signal.
175121
pub fn set_waveform(&self, wf: &Waveform, exact: bool) -> Result {
176122
let c_wf = bindings::pwm_waveform::from(*wf);

0 commit comments

Comments
 (0)