Re: [PATCH v7 04/11] pwm: max7360: Add MAX7360 PWM support

From: Andy Shevchenko
Date: Fri May 02 2025 - 06:19:26 EST


On Mon, Apr 28, 2025 at 01:57:22PM +0200, mathieu.dubois-briand@xxxxxxxxxxx wrote:
> From: Kamel Bouhara <kamel.bouhara@xxxxxxxxxxx>
>
> Add driver for Maxim Integrated MAX7360 PWM controller, supporting up to
> 8 independent PWM outputs.

...

> +static int max7360_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
> +{
> + struct regmap *regmap;
> + int ret;

> + regmap = pwmchip_get_drvdata(chip);

Just unify this assignment with the definition. Will save you 1 LoC.

> + ret = regmap_write_bits(regmap, MAX7360_REG_PWMCFG(pwm->hwpwm),
> + MAX7360_PORT_CFG_COMMON_PWM, 0);
> + if (ret)
> + return ret;
> +
> + return regmap_write_bits(regmap, MAX7360_REG_PORTS, BIT(pwm->hwpwm), BIT(pwm->hwpwm));
> +}

...

> +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 = DIV64_U64_ROUND_UP(wfhw->duty_steps * MAX7360_PWM_PERIOD_NS,

Does the numerator have already 64-bit type? Otherwise (u)int*(u)int will be
just an (u)int.

> + MAX7360_PWM_MAX_RES);
> +
> + 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);
> +

Save 2 LoCs.

> + 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;
> +
> + wfhw->duty_steps = val;
> + } else {
> + wfhw->enabled = false;
> + wfhw->duty_steps = 0;
> + }
> +
> + return 0;
> +}

...

> +static int max7360_pwm_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct pwm_chip *chip;
> + struct regmap *regmap;
> + int ret;
> +
> + regmap = dev_get_regmap(dev->parent, NULL);
> + if (!regmap)
> + return dev_err_probe(dev, -ENODEV, "could not get parent regmap\n");

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

Probably same comment as per pin control driver case?

> + chip = devm_pwmchip_alloc(dev, MAX7360_NUM_PWMS, 0);
> + if (IS_ERR(chip))
> + return PTR_ERR(chip);
> + chip->ops = &max7360_pwm_ops;

> + pwmchip_set_drvdata(chip, regmap);

> + ret = devm_pwmchip_add(dev, chip);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to add PWM chip\n");
> +
> + return 0;
> +}

--
With Best Regards,
Andy Shevchenko