Re: [PATCH v6 04/12] pwm: max7360: Add MAX7360 PWM support

Andy Shevchenko
2025-04-09T17:01:03Z

On Wed, Apr 09, 2025 at 04:55:51PM +0200, mathieu.dubois-briand@bootlin.com wrote:
> From: Kamel Bouhara <kamel.bouhara@bootlin.com>
>
> Add driver for Maxim Integrated MAX7360 PWM controller, supporting up to
> 8 independent PWM outputs.

...

> +static void max7360_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
> +{
> + struct regmap *regmap;
> + struct device *dev;
> +
> + regmap = pwmchip_get_drvdata(chip);
> + dev = regmap_get_device(regmap);
> +}

This will produce compiler warnings. Why do you have this at all?

...

> +static int max7360_pwm_round_waveform_tohw(struct pwm_chip *chip,
> + struct pwm_device *pwm,
> + const struct pwm_waveform *wf,
> + void *_wfhw)
> +{
> + struct max7360_pwm_waveform *wfhw = _wfhw;
> + u64 duty_steps;
> +
> + /*
> + * Ignore user provided values for period_length_ns and duty_offset_ns:
> + * we only support fixed period of MAX7360_PWM_PERIOD_NS and offset of 0.
> + */
> + duty_steps = mul_u64_u64_div_u64(wf->duty_length_ns, MAX7360_PWM_MAX_RES,
> + MAX7360_PWM_PERIOD_NS);
> +
> + wfhw->duty_steps = min(MAX7360_PWM_MAX_RES, duty_steps);

> + wfhw->enabled = (wf->duty_length_ns != 0);

Can be written as

wfhw->enabled = wf->duty_length_ns;

Or if you want really to be picky about rules,

wfhw->enabled = !!wf->duty_length_ns;

> + return 0;
> +}

...

> +static int max7360_pwm_read_waveform(struct pwm_chip *chip,
> + struct pwm_device *pwm,
> + void *_wfhw)
> +{
> + struct max7360_pwm_waveform *wfhw = _wfhw;
> + struct regmap *regmap;
> + unsigned int val;
> + int ret;

> + regmap = pwmchip_get_drvdata(chip);

Why not move this to the definition block above?

struct regmap *regmap = pwmchip_get_drvdata(chip);

> + ret = regmap_read(regmap, MAX7360_REG_GPIOCTRL, &val);
> + if (ret)
> + return ret;
> +
> + if (val & BIT(pwm->hwpwm)) {
> + wfhw->enabled = true;
> + ret = regmap_read(regmap, MAX7360_REG_PWM(pwm->hwpwm), &val);

if (ret)
return ret;

> + if (!ret)
> + wfhw->duty_steps = val;
> + } else {
> + wfhw->enabled = false;
> + wfhw->duty_steps = 0;
> + }
> +
> + return ret;

return 0;

> +}

...

> + device_set_of_node_from_dev(dev, dev->parent);

This needs broader discussion.

--
With Best Regards,
Andy Shevchenko