Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: pwm: Drop wrapping of PWM polarity and state

These were introduced and used in an earlier revision of the patch that
became commit fb3957af9ec6 ("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>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
a69a54f8 264b501b

+1 -55
+1 -55
rust/kernel/pwm.rs
··· 15 15 prelude::*, 16 16 types::{ARef, AlwaysRefCounted, Opaque}, 17 17 }; 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}; 50 19 51 20 /// Represents a PWM waveform configuration. 52 21 /// Mirrors struct [`struct pwm_waveform`](srctree/include/linux/pwm.h). ··· 55 86 duty_length_ns: wf.duty_length_ns, 56 87 duty_offset_ns: wf.duty_offset_ns, 57 88 } 58 - } 59 - } 60 - 61 - /// Wrapper for PWM state [`struct pwm_state`](srctree/include/linux/pwm.h). 62 - #[repr(transparent)] 63 - pub struct State(bindings::pwm_state); 64 - 65 - impl State { 66 - /// Creates a `State` wrapper by taking ownership of a C `pwm_state` value. 67 - pub(crate) fn from_c(c_state: bindings::pwm_state) -> Self { 68 - State(c_state) 69 - } 70 - 71 - /// Returns `true` if the PWM signal is enabled. 72 - pub fn enabled(&self) -> bool { 73 - self.0.enabled 74 89 } 75 90 } 76 91 ··· 115 162 // SAFETY: label_ptr is non-null and points to a C string 116 163 // managed by the kernel, valid for the lifetime of the PWM device. 117 164 Some(unsafe { CStr::from_char_ptr(label_ptr) }) 118 - } 119 - 120 - /// Gets a copy of the current state of this PWM device. 121 - pub fn state(&self) -> State { 122 - // SAFETY: `self.as_raw()` gives a valid pointer. `(*self.as_raw()).state` 123 - // is a valid `pwm_state` struct. `State::from_c` copies this data. 124 - State::from_c(unsafe { (*self.as_raw()).state }) 125 165 } 126 166 127 167 /// Sets the PWM waveform configuration and enables the PWM signal.