mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mathieu Dubois-Briand" <mathieu.dubois-briand@bootlin.com>
To: "Uwe Kleine-König" <ukleinek@kernel.org>
Cc: "Lee Jones" <lee@kernel.org>, "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Kamel Bouhara" <kamel.bouhara@bootlin.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Michael Walle" <mwalle@kernel.org>,
	"Mark Brown" <broonie@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-input@vger.kernel.org,
	linux-pwm@vger.kernel.org, andriy.shevchenko@intel.com,
	"Grégory Clement" <gregory.clement@bootlin.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v10 04/11] pwm: max7360: Add MAX7360 PWM support
Date: Tue, 08 Jul 2025 13:31:19 +0200	[thread overview]
Message-ID: <DB6N1SVPVSQJ.15KQKOBOCHDCQ@bootlin.com> (raw)
In-Reply-To: <amukbuzpu34jbcjhmzmvfgh6eik5isrwcicfmlqmsyibvhij72@nnmhdj3celnt>

On Wed Jun 18, 2025 at 8:45 PM CEST, Uwe Kleine-König wrote:
> On Fri, May 30, 2025 at 12:00:12PM +0200, mathieu.dubois-briand@bootlin.com wrote:
>> From: Kamel Bouhara <kamel.bouhara@bootlin.com>
> ...
>> --- /dev/null
>> +++ b/drivers/pwm/pwm-max7360.c
>> @@ -0,0 +1,180 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright 2025 Bootlin
>> + *
>> + * Author: Kamel BOUHARA <kamel.bouhara@bootlin.com>
>> + * Author: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
>> + *
>> + * Limitations:
>> + * - Only supports normal polarity.
>> + * - The period is fixed to 2 ms.
>> + * - Only the duty cycle can be changed, new values are applied at the beginning
>> + *   of the next cycle.
>> + * - When disabled, the output is put in Hi-Z.
>> + */
>> +#include <linux/bits.h>
>> +#include <linux/dev_printk.h>
>> +#include <linux/err.h>
>> +#include <linux/math64.h>
>> +#include <linux/mfd/max7360.h>
>> +#include <linux/minmax.h>
>> +#include <linux/mod_devicetable.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/pwm.h>
>> +#include <linux/regmap.h>
>> +#include <linux/time.h>
>> +#include <linux/types.h>
>> +
>> +#define MAX7360_NUM_PWMS			8
>> +#define MAX7360_PWM_MAX_RES			255
>> +#define MAX7360_PWM_PERIOD_NS			(2 * NSEC_PER_MSEC)
>> +
>> +struct max7360_pwm_waveform {
>> +	u8 duty_steps;
>> +	bool enabled;
>> +};
>> +
>> +static int max7360_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
>> +{
>> +	struct regmap *regmap = pwmchip_get_drvdata(chip);
>> +
>> +	return regmap_write_bits(regmap, MAX7360_REG_PWMCFG(pwm->hwpwm),
>> +				 MAX7360_PORT_CFG_COMMON_PWM, 0);
>> +}
>
> Do you need to undo that in .free()?
>

No, this is just to make sure we use the individual PWM configuration
register and not the global one, so there is no need to revert it later.

I'm adding a comment explaining that.

> ...
>
>> +	wfhw->duty_steps = min(MAX7360_PWM_MAX_RES, duty_steps);
>> +	wfhw->enabled = !!wf->duty_length_ns;
>
> How does the output behave if you clean the respective bit in
> MAX7360_REG_GPIOCTRL? Unless it emits a constant low signal (and not
> e.g. High-Z) you have to do
>
> 	wfhw->enabled = !!wf->period_length_ns;
>
> here. Please document the behaviour in a paragraph at the top of
> the driver. Look at other drivers for the right format. The questions to
> answer are:
>
>  - How does the driver behave on disable? (Typical is constant low or
>    High-Z or freezing. Does it stop instantly or does it complete the
>    currently running period?)
>
>  - How does the driver behave on a (non-disabling) reconfiguration? Can
>    it happen that there are glitches? (Consider for example that
>    duty_cycle changes from 0.5 ms to 1.5ms while the hardware is just in
>    the middle of the 2ms period. Does the output go high immediately
>    then producing two 0.5ms pulses during that period?)
>

Ok, I'm fixing the wfhw->enabled value.

About the comment, I believe we already have everything, I'm just adding
that on disable, the output is put in Hi-Z immediately.

>> +	return 0;
>> +}
>> +
>> +static int max7360_pwm_round_waveform_fromhw(struct pwm_chip *chip, struct pwm_device *pwm,
>> +					     const void *_wfhw, struct pwm_waveform *wf)
>> +{
>> +	const struct max7360_pwm_waveform *wfhw = _wfhw;
>> +
>> +	wf->period_length_ns = wfhw->enabled ? MAX7360_PWM_PERIOD_NS : 0;
>> +	wf->duty_offset_ns = 0;
>> +	wf->duty_length_ns = DIV_ROUND_UP(wfhw->duty_steps * MAX7360_PWM_PERIOD_NS,
>> +					  MAX7360_PWM_MAX_RES);
>
> This should be 0 if !wfhw->enabled to make *wf a valid setting.
>

OK.

> A check for that in the core (with CONFIG_PWM_DEBUG) would be great.
>

I can submit a patch, but I'm not sure what that check should be.

So I believe the check would have to be made in __pwm_set_waveform(),
making sure wf_rounded.duty_length_ns is 0 if the PWM is not enabled or
in other words, if wf->period_length_ns is 0. I believe calling
pwm_wf_valid() on wf_rounded would be enough. Maybe I should add that as
a first check in pwm_check_rounding() to cover all call sites.

We already call pwm_check_rounding() code, so me already make sure that
if wf->period_length_ns is 0, wf_rounded->period_length_ns is 0. And
adding pwm_wf_valid(), would make sure that if
wf_rounded->period_length_ns is 0, wf_rounded->duty_length_ns is also 0.

Any opinion?

> ...
>
> Best regards
> Uwe

OK with all other comments.

Thanks for your review!

-- 
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  reply	other threads:[~2025-07-08 11:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 10:00 [PATCH v10 00/11] Add support for MAX7360 Mathieu Dubois-Briand
2025-05-30 10:00 ` [PATCH v10 01/11] dt-bindings: mfd: gpio: Add MAX7360 Mathieu Dubois-Briand
2025-06-02 11:21   ` Krzysztof Kozlowski
2025-06-03  8:14     ` Mathieu Dubois-Briand
2025-06-03  9:27       ` Krzysztof Kozlowski
2025-05-30 10:00 ` [PATCH v10 02/11] mfd: Add max7360 support mathieu.dubois-briand
2025-05-30 17:55   ` Andy Shevchenko
2025-06-13 14:15   ` Lee Jones
2025-05-30 10:00 ` [PATCH v10 03/11] pinctrl: Add MAX7360 pinctrl driver Mathieu Dubois-Briand
2025-05-30 10:00 ` [PATCH v10 04/11] pwm: max7360: Add MAX7360 PWM support mathieu.dubois-briand
2025-05-30 17:57   ` Andy Shevchenko
2025-06-18 18:45   ` Uwe Kleine-König
2025-07-08 11:31     ` Mathieu Dubois-Briand [this message]
2025-05-30 10:00 ` [PATCH v10 05/11] regmap: irq: Add support for chips without separate IRQ status Mathieu Dubois-Briand
2025-05-30 10:37   ` Mark Brown
2025-06-03  8:01     ` Mathieu Dubois-Briand
2025-06-03 12:45       ` Mark Brown
2025-05-30 10:00 ` [PATCH v10 06/11] gpio: regmap: Allow to allocate regmap-irq device Mathieu Dubois-Briand
2025-05-30 17:59   ` Andy Shevchenko
2025-06-02 10:19   ` Bartosz Golaszewski
2025-05-30 10:00 ` [PATCH v10 07/11] gpio: regmap: Allow to provide init_valid_mask callback Mathieu Dubois-Briand
2025-05-30 10:00 ` [PATCH v10 08/11] gpio: max7360: Add MAX7360 gpio support Mathieu Dubois-Briand
2025-05-30 18:03   ` Andy Shevchenko
2025-07-08  9:13     ` Mathieu Dubois-Briand
2025-05-30 10:00 ` [PATCH v10 09/11] input: keyboard: Add support for MAX7360 keypad Mathieu Dubois-Briand
2025-07-02 21:00   ` Dmitry Torokhov
2025-07-08  9:32     ` Mathieu Dubois-Briand
2025-05-30 10:00 ` [PATCH v10 10/11] input: misc: Add support for MAX7360 rotary Mathieu Dubois-Briand
2025-07-02 21:05   ` Dmitry Torokhov
2025-07-08  9:26     ` Mathieu Dubois-Briand
2025-05-30 10:00 ` [PATCH v10 11/11] MAINTAINERS: Add entry on MAX7360 driver Mathieu Dubois-Briand

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=DB6N1SVPVSQJ.15KQKOBOCHDCQ@bootlin.com \
    --to=mathieu.dubois-briand@bootlin.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=dakr@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregory.clement@bootlin.com \
    --cc=kamel.bouhara@bootlin.com \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=mwalle@kernel.org \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=ukleinek@kernel.org \
    /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

all inboxes | Powered by JetHome®