devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Wahren <wahrenst@gmx.net>
To: Dhruva Gole <d-gole@ti.com>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	andy.shevchenko@gmail.com,
	"Angelo Compagnucci" <angelo.compagnucci@gmail.com>,
	"Philip Howard" <phil@gadgetoid.com>,
	"Sean Young" <sean@mess.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH V4 2/2] pwm: Add GPIO PWM driver
Date: Mon, 5 Feb 2024 08:16:09 +0100	[thread overview]
Message-ID: <182bf1bb-cc90-4fe8-a226-1cfd5c10e41f@gmx.net> (raw)
In-Reply-To: <20240205061129.gdwzmpuxrzxj5cov@dhruva>

Hi Dhruva,

[drop Vincent's address because it bounces]

Am 05.02.24 um 07:11 schrieb Dhruva Gole:
> On Feb 04, 2024 at 23:08:51 +0100, Stefan Wahren wrote:
>> From: Vincent Whitchurch <vincent.whitchurch@axis.com>
>>
>> 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@axis.com>
>> Co-developed-by: Stefan Wahren <wahrenst@gmx.net>
>> Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
>> ---
>>   drivers/pwm/Kconfig    |  11 ++
>>   drivers/pwm/Makefile   |   1 +
>>   drivers/pwm/pwm-gpio.c | 228 +++++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 240 insertions(+)
>>   create mode 100644 drivers/pwm/pwm-gpio.c
>>
>> diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
>> index 4b956d661755..7cfda2cde130 100644
>> --- a/drivers/pwm/Kconfig
>> +++ b/drivers/pwm/Kconfig
>> @@ -227,6 +227,17 @@ config PWM_FSL_FTM
>>   	  To compile this driver as a module, choose M here: the module
>>   	  will be called pwm-fsl-ftm.
>>
>> +config PWM_GPIO
>> +	tristate "GPIO PWM support"
>> +	depends on GPIOLIB
>> +	depends on HIGH_RES_TIMERS
>> +	help
>> +	  Generic PWM framework driver for a software PWM toggling a GPIO pin
>>> a software PWM
> Nit: remove the "a", as it's not required.
thanks will fix this.
>
>> +	  from kernel high-resolution timers.
>> +
>> +	  To compile this driver as a module, choose M here: the module
>> +	  will be called pwm-gpio.
>> +
> [..snip..]
>> +
>> +static int pwm_gpio_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>> +			       struct pwm_state *state)
>> +{
>> +	struct pwm_gpio *gpwm = container_of(chip, struct pwm_gpio, chip);
>> +	unsigned long flags;
>> +
>> +	spin_lock_irqsave(&gpwm->lock, flags);
>> +
>> +	if (gpwm->changing)
>> +		*state = gpwm->next_state;
>> +	else
>> +		*state = gpwm->state;
>> +
>> +	spin_unlock_irqrestore(&gpwm->lock, flags);
>> +
>> +	return 0;
>> +}
>> +
>> +static const struct pwm_ops pwm_gpio_ops = {
>> +	.apply = pwm_gpio_apply,
> Kinda looks like this is setting state? Can we be consistent with the
> naming then, like pwm_gpio_set_state?
The pwm_op is called apply, so the expected suffix would be _apply like
all the other PWM driver does.

grep ".apply =" drivers/pwm/*
drivers/pwm/pwm-ab8500.c:    .apply = ab8500_pwm_apply,
drivers/pwm/pwm-apple.c:    .apply = apple_pwm_apply,
drivers/pwm/pwm-atmel.c:    .apply = atmel_pwm_apply,
...

> This will help those contributing to the driver or referring to it to
> understand better what each function is doing exactly.
Using ...set_state here would confuse all the experienced kernel developer.
>
>> +	.get_state = pwm_gpio_get_state,
>> +};
> Otherwise, driver looks good to me,
> Reviewed-by: Dhruva Gole <d-gole@ti.com>
>


  reply	other threads:[~2024-02-05  7:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-04 22:08 [PATCH V4 0/2] pwm: Add GPIO PWM driver Stefan Wahren
2024-02-04 22:08 ` [PATCH V4 1/2] dt-bindings: pwm: Add pwm-gpio Stefan Wahren
2024-02-04 22:47   ` Linus Walleij
2024-02-05  5:58   ` Dhruva Gole
2024-02-05  7:44   ` Krzysztof Kozlowski
2024-02-05  9:15   ` Uwe Kleine-König
2024-02-05 11:58     ` Stefan Wahren
2024-02-04 22:08 ` [PATCH V4 2/2] pwm: Add GPIO PWM driver Stefan Wahren
2024-02-04 22:50   ` Linus Walleij
2024-02-05  6:11   ` Dhruva Gole
2024-02-05  7:16     ` Stefan Wahren [this message]
2024-02-05 10:09   ` Uwe Kleine-König
2024-02-05 12:21     ` Stefan Wahren
2024-02-27 15:32   ` Chris Morgan
2024-02-27 16:59     ` Stefan Wahren
2024-02-28 12:43       ` Phil Howard
2024-02-29  8:45       ` Sean Young
2024-02-29  8:57         ` Sean Young
2024-02-27 16:41   ` Andy Shevchenko
2024-02-27 20:24     ` Stefan Wahren
2024-02-27 20:47       ` Andy Shevchenko
2024-02-28 18:06         ` Stefan Wahren
2024-02-05  5:55 ` [PATCH V4 0/2] " Dhruva Gole
2024-02-05  7:08   ` Stefan Wahren
2024-02-05 13:06 ` Phil Howard
2024-05-27  8:22 ` Linus Walleij
2024-05-27  8:44   ` Stefan Wahren
2024-05-27  9:56     ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=182bf1bb-cc90-4fe8-a226-1cfd5c10e41f@gmx.net \
    --to=wahrenst@gmx.net \
    --cc=andy.shevchenko@gmail.com \
    --cc=angelo.compagnucci@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=d-gole@ti.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=phil@gadgetoid.com \
    --cc=robh+dt@kernel.org \
    --cc=sean@mess.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).