lkml.org 
[lkml]   [2024]   [Jan]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 1/3] pwm: dwc: Add 16 channel support for Intel Elkhart Lake
On Mon, Jan 22, 2024 at 08:32:36AM +0530, Raag Jadav wrote:
> Intel Elkhart Lake PSE includes two instances of PWM as a single PCI
> function with 8 channels each. Add support for the remaining channels.

..

> +static int dwc_pwm_init(struct device *dev, const struct dwc_pwm_info *info, void __iomem *base)
> +{
> + /* Default values for single instance devices */
> + unsigned int nr = 1, size = 0;
> + int i, ret;
> +
> + /* Fill up values from driver_data, if any */
> + if (info) {
> + nr = info->nr;
> + size = info->size;
> + }
> +
> + for (i = 0; i < nr; i++) {
> + struct dwc_pwm *dwc;
> +
> + dwc = dwc_pwm_alloc(dev);
> + if (!dwc)
> + return -ENOMEM;
> +
> + dwc->base = base + (i * size);
> +
> + ret = devm_pwmchip_add(dev, &dwc->chip);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}

Why not doing this slightly differently?

First option: Always provide driver data (info is never NULL).

Second option, have the body of the for-loop be factored to a helper
dwc_pwm_init_one() and here

if (!info)
return dwc_pwm_init_one(..., 1, 0);

for (i = 0; i < info->nr; i++) {
ret = dwc_pwm_init_one(...);
if (ret)
return ret;
}

--
With Best Regards,
Andy Shevchenko



\
 
 \ /
  Last update: 2024-05-27 14:37    [W:0.059 / U:1.748 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site