pwm: bcm-kona: Make use of devm_pwmchip_alloc() function

This prepares the pwm-bcm-kona driver to further changes of the pwm core
outlined in the commit introducing devm_pwmchip_alloc(). There is no
intended semantical change and the driver should behave as before.

Link: https://lore.kernel.org/r/b50fe94dc72af602e7061839b24f48af6e005ef8.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
This commit is contained in:
Uwe Kleine-König 2024-02-14 10:31:06 +01:00
parent 2089ecaa49
commit e5c368b821

View File

@ -56,14 +56,13 @@
#define DUTY_CYCLE_HIGH_MAX 0x00ffffff #define DUTY_CYCLE_HIGH_MAX 0x00ffffff
struct kona_pwmc { struct kona_pwmc {
struct pwm_chip chip;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
}; };
static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *chip) static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *chip)
{ {
return container_of(chip, struct kona_pwmc, chip); return pwmchip_get_drvdata(chip);
} }
/* /*
@ -273,18 +272,18 @@ static const struct pwm_ops kona_pwm_ops = {
static int kona_pwmc_probe(struct platform_device *pdev) static int kona_pwmc_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct kona_pwmc *kp; struct kona_pwmc *kp;
unsigned int chan; unsigned int chan;
unsigned int value = 0; unsigned int value = 0;
int ret = 0; int ret = 0;
kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 6, sizeof(*kp));
if (kp == NULL) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
kp = to_kona_pwmc(chip);
kp->chip.dev = &pdev->dev; chip->ops = &kona_pwm_ops;
kp->chip.ops = &kona_pwm_ops;
kp->chip.npwm = 6;
kp->base = devm_platform_ioremap_resource(pdev, 0); kp->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(kp->base)) if (IS_ERR(kp->base))
@ -304,14 +303,14 @@ static int kona_pwmc_probe(struct platform_device *pdev)
} }
/* Set push/pull for all channels */ /* Set push/pull for all channels */
for (chan = 0; chan < kp->chip.npwm; chan++) for (chan = 0; chan < chip->npwm; chan++)
value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan)); value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan));
writel(value, kp->base + PWM_CONTROL_OFFSET); writel(value, kp->base + PWM_CONTROL_OFFSET);
clk_disable_unprepare(kp->clk); clk_disable_unprepare(kp->clk);
ret = devm_pwmchip_add(&pdev->dev, &kp->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);