public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-pwm@vger.kernel.org,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Lee Jones" <lee@kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Rob Herring" <robh@kernel.org>,
	"Uwe Kleine-König" <ukleinek@kernel.org>,
	"Clark Wang" <xiaoning.wang@nxp.com>
Subject: Re: [PATCH v4 4/4] pwm: adp5585: Add Analog Devices ADP5585 support
Date: Mon, 10 Jun 2024 18:28:33 +0300	[thread overview]
Message-ID: <20240610152833.GW18479@pendragon.ideasonboard.com> (raw)
In-Reply-To: <ZmcWi08u6-u4MyKu@surfacebook.localdomain>

On Mon, Jun 10, 2024 at 06:06:51PM +0300, Andy Shevchenko wrote:
> Sat, Jun 08, 2024 at 05:16:33PM +0300, Laurent Pinchart kirjoitti:
> > From: Clark Wang <xiaoning.wang@nxp.com>
> > 
> > The ADP5585 is a 10/11 input/output port expander with a built in keypad
> > matrix decoder, programmable logic, reset generator, and PWM generator.
> > This driver supports the PWM function using the platform device
> > registered by the core MFD driver.
> > 
> > The driver is derived from an initial implementation from NXP, available
> > in commit 113113742208 ("MLK-25922-1 pwm: adp5585: add adp5585 PWM
> > support") in their BSP kernel tree. It has been extensively rewritten.
> 
> ...
> 
> > +#define ADP5585_PWM_OSC_FREQ_HZ		1000000U
> 
> (1 * HZ_PER_MHZ) ?
> 
> Variant to use MEGA. Or even #define MHz in units.h if you wish.
> Putting a few 0:s in a row is error prone.

Feel free to send follow-up patches.

Andy, we're reaching a level of nitpicking and yakshaving that even I
can't deal with. I will have to simply ignore the comments I disagree
with.

> ...
> 
> > +	ret = regmap_write(regmap, ADP5585_PWM_OFFT_LOW,
> > +			   off & 0xff);
> > +	if (ret)
> > +		return ret;
> > +	ret = regmap_write(regmap, ADP5585_PWM_OFFT_HIGH,
> > +			   (off >> 8) & 0xff);
> > +	if (ret)
> > +		return ret;
> 
> This is regular I²C regmap, why do you avoid using regmap bulk APIs?
> 
> > +	ret = regmap_write(regmap, ADP5585_PWM_ONT_LOW,
> > +			   on & 0xff);
> > +	if (ret)
> > +		return ret;
> > +	ret = regmap_write(regmap, ADP5585_PWM_ONT_HIGH,
> > +			   (on >> 8) & 0xff);
> > +	if (ret)
> > +		return ret;
> 
> Ditto.
> 
> ...
> 
> > +static int pwm_adp5585_get_state(struct pwm_chip *chip,
> > +				 struct pwm_device *pwm,
> > +				 struct pwm_state *state)
> > +{
> > +	struct regmap *regmap = pwmchip_get_drvdata(chip);
> > +	unsigned int on, off;
> > +	unsigned int val;
> > +
> > +	regmap_read(regmap, ADP5585_PWM_OFFT_LOW, &off);
> > +	regmap_read(regmap, ADP5585_PWM_OFFT_HIGH, &val);
> > +	off |= val << 8;
> 
> Ditto.
> 
> > +	regmap_read(regmap, ADP5585_PWM_ONT_LOW, &on);
> > +	regmap_read(regmap, ADP5585_PWM_ONT_HIGH, &val);
> > +	on |= val << 8;
> 
> Ditto.
> 
> > +	state->duty_cycle = on * (NSEC_PER_SEC / ADP5585_PWM_OSC_FREQ_HZ);
> > +	state->period = (on + off) * (NSEC_PER_SEC / ADP5585_PWM_OSC_FREQ_HZ);
> > +
> > +	state->polarity = PWM_POLARITY_NORMAL;
> > +
> > +	regmap_read(regmap, ADP5585_PWM_CFG, &val);
> > +	state->enabled = !!(val & ADP5585_PWM_EN);
> > +
> > +	return 0;
> 
> Besides that, how do you guarantee that no IO may happen in between of those
> calls? Probably you want a driver explicit lock? In that case, would you still
> want to have a regmap internal lock?
> 
> > +}
> 
> ...
> 
> > +static int adp5585_pwm_probe(struct platform_device *pdev)
> > +{
> > +	struct device *dev = &pdev->dev;
> > +	struct adp5585_dev *adp5585 = dev_get_drvdata(dev->parent);
> > +	struct pwm_chip *chip;
> > +	int ret;
> > +
> > +	chip = devm_pwmchip_alloc(dev, ADP5585_PWM_CHAN_NUM, 0);
> > +	if (IS_ERR(chip))
> > +		return PTR_ERR(chip);
> 
> > +	device_set_of_node_from_dev(dev, dev->parent);
> 
> Still unclear to me why only few drivers use this.
> 
> > +	pwmchip_set_drvdata(chip, adp5585->regmap);
> > +	chip->ops = &adp5585_pwm_ops;
> > +
> > +	ret = devm_pwmchip_add(dev, chip);
> > +	if (ret)
> > +		return dev_err_probe(dev, ret, "failed to add PWM chip\n");
> > +
> > +	return 0;
> > +}
> 
> ...
> 
> > +static const struct platform_device_id adp5585_pwm_id_table[] = {
> > +	{ "adp5585-pwm" },
> > +	{ /* Sentinel */ },
> 
> Drop comma. Otherwise it's not a sentinel strictly speaking.
>
> > +};

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2024-06-10 15:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-08 14:16 [PATCH v4 0/4] ADP5585 GPIO expander, PWM and keypad controller support Laurent Pinchart
2024-06-08 14:16 ` [PATCH v4 1/4] dt-bindings: mfd: Add Analog Devices ADP5585 Laurent Pinchart
2024-06-10  6:21   ` Stanislav Jakubek
2024-06-10 15:34     ` Laurent Pinchart
2024-06-08 14:16 ` [PATCH v4 2/4] mfd: adp5585: Add Analog Devices ADP5585 core support Laurent Pinchart
2024-06-10 15:11   ` Andy Shevchenko
2024-07-17  2:39   ` Frank Li
2024-07-19  7:36     ` Laurent Pinchart
2024-06-08 14:16 ` [PATCH v4 3/4] gpio: adp5585: Add Analog Devices ADP5585 support Laurent Pinchart
2024-06-10 15:15   ` Andy Shevchenko
2024-06-10 15:25     ` Laurent Pinchart
2024-06-10 16:29       ` Andy Shevchenko
2024-07-19 13:55         ` Laurent Pinchart
2024-08-01 23:15           ` Andy Shevchenko
2024-06-08 14:16 ` [PATCH v4 4/4] pwm: " Laurent Pinchart
2024-06-10 15:06   ` Andy Shevchenko
2024-06-10 15:28     ` Laurent Pinchart [this message]
2024-06-10 16:31       ` Andy Shevchenko
2024-07-19 14:07         ` Laurent Pinchart
2024-08-01 23:21           ` Andy Shevchenko

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=20240610152833.GW18479@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=ukleinek@kernel.org \
    --cc=xiaoning.wang@nxp.com \
    /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