lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240405003025.739603-4-tgamblin@baylibre.com>
Date: Thu,  4 Apr 2024 20:30:25 -0400
From: Trevor Gamblin <tgamblin@...libre.com>
To: linux-pwm@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
	u.kleine-koenig@...gutronix.de,
	michael.hennerich@...log.com,
	nuno.sa@...log.com,
	tgamblin@...libre.com,
	dlechner@...libre.com
Subject: [RFC PATCH 3/3] pwm: add pwm_config_full to pwm.h

Add a function that performs the old pwm_config operations while also
handling duty_offset. Change pwm_config to use pwm_config_full with the
duty_offset_ns argument set to 0.

Signed-off-by: Trevor Gamblin <tgamblin@...libre.com>
---
 include/linux/pwm.h | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index e0e5960f91ba..eb018f11a48f 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -347,33 +347,51 @@ int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state);
 int pwm_adjust_config(struct pwm_device *pwm);
 
 /**
- * pwm_config() - change a PWM device configuration
+ * pwm_config_full() - change a PWM device configuration, including duty
+ * offset
  * @pwm: PWM device
  * @duty_ns: "on" time (in nanoseconds)
+ * @duty_offset_ns: offset (in nanoseconds) of "on" pulse
  * @period_ns: duration (in nanoseconds) of one cycle
  *
  * Returns: 0 on success or a negative error code on failure.
  */
-static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
-			     int period_ns)
+static inline int pwm_config_full(struct pwm_device *pwm, int duty_ns,
+				  int duty_offset_ns, int period_ns)
 {
 	struct pwm_state state;
 
 	if (!pwm)
 		return -EINVAL;
 
-	if (duty_ns < 0 || period_ns < 0)
+	if (duty_ns < 0 || period_ns < 0 || duty_offset_ns < 0)
 		return -EINVAL;
 
 	pwm_get_state(pwm, &state);
-	if (state.duty_cycle == duty_ns && state.period == period_ns)
+	if (state.duty_cycle == duty_ns && state.period == period_ns &&
+	    state.duty_offset == duty_offset_ns)
 		return 0;
 
 	state.duty_cycle = duty_ns;
+	state.duty_offset = duty_offset_ns;
 	state.period = period_ns;
 	return pwm_apply_might_sleep(pwm, &state);
 }
 
+/**
+ * pwm_config() - change a PWM device configuration
+ * @pwm: PWM device
+ * @duty_ns: "on" time (in nanoseconds)
+ * @period_ns: duration (in nanoseconds) of one cycle
+ *
+ * Returns: 0 on success or a negative error code on failure.
+ */
+static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
+			     int period_ns)
+{
+	return pwm_config_full(pwm, duty_ns, 0, period_ns);
+}
+
 /**
  * pwm_enable() - start a PWM output toggling
  * @pwm: PWM device
@@ -480,6 +498,13 @@ static inline int pwm_adjust_config(struct pwm_device *pwm)
 	return -EOPNOTSUPP;
 }
 
+static inline int pwm_config_full(struct pwm_device *pwm, int duty_ns,
+				  int duty_offset_ns, int period_ns)
+{
+	might_sleep();
+	return -EINVAL;
+}
+
 static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
 			     int period_ns)
 {
-- 
2.44.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ