Re: [PATCH V3 2/2] pwm: Add GPIO PWM driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Sean,

Am 30.01.24 um 10:08 schrieb Sean Young:
On Sun, Jan 28, 2024 at 05:36:30PM +0100, Stefan Wahren wrote:
From: Vincent Whitchurch <vincent.whitchurch@xxxxxxxx>

Add a software PWM which toggles a GPIO from a high-resolution timer.

This will naturally not be as accurate or as efficient as a hardware
PWM, but it is useful in some cases.  I have for example used it for
evaluating LED brightness handling (via leds-pwm) on a board where the
LED was just hooked up to a GPIO, and for a simple verification of the
timer frequency on another platform.

Since high-resolution timers are used, sleeping gpio chips are not
supported and are rejected in the probe function.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@xxxxxxxx>
Co-developed-by: Stefan Wahren <wahrenst@xxxxxxx>
Signed-off-by: Stefan Wahren <wahrenst@xxxxxxx>
---
...
+
+static int pwm_gpio_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+			  const struct pwm_state *state)
+{
+	struct pwm_gpio *gpwm = container_of(chip, struct pwm_gpio, chip);
+	bool invert = state->polarity == PWM_POLARITY_INVERSED;
+	unsigned long flags;
Not sure this is necessary but how about:

	if (state->duty_cycle < hrtimer_resolution ||
	    state->period - state->duty_cycle < hrtimer_resolution)
		return -EINVAL;

i think i get the idea, but we need to care about corner cases like
duty_cycle = 0





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux