pwm: microchip-core: Make use of devm_pwmchip_alloc() function

This prepares the pwm-microchip-core 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.

Acked-by: Conor Dooley <conor.dooley@microchip.com>
Link: https://lore.kernel.org/r/c6660b655c1d4c9d79280030e24090a4a4c5dd8b.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:32:00 +01:00
parent 28ecf9bd5e
commit f962b190fe

View File

@ -54,7 +54,6 @@
#define MCHPCOREPWM_TIMEOUT_MS 100u #define MCHPCOREPWM_TIMEOUT_MS 100u
struct mchp_core_pwm_chip { struct mchp_core_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
struct mutex lock; /* protects the shared period */ struct mutex lock; /* protects the shared period */
@ -65,7 +64,7 @@ struct mchp_core_pwm_chip {
static inline struct mchp_core_pwm_chip *to_mchp_core_pwm(struct pwm_chip *chip) static inline struct mchp_core_pwm_chip *to_mchp_core_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct mchp_core_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static void mchp_core_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm, static void mchp_core_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm,
@ -447,13 +446,15 @@ MODULE_DEVICE_TABLE(of, mchp_core_of_match);
static int mchp_core_pwm_probe(struct platform_device *pdev) static int mchp_core_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct mchp_core_pwm_chip *mchp_core_pwm; struct mchp_core_pwm_chip *mchp_core_pwm;
struct resource *regs; struct resource *regs;
int ret; int ret;
mchp_core_pwm = devm_kzalloc(&pdev->dev, sizeof(*mchp_core_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 16, sizeof(*mchp_core_pwm));
if (!mchp_core_pwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
mchp_core_pwm = to_mchp_core_pwm(chip);
mchp_core_pwm->base = devm_platform_get_and_ioremap_resource(pdev, 0, &regs); mchp_core_pwm->base = devm_platform_get_and_ioremap_resource(pdev, 0, &regs);
if (IS_ERR(mchp_core_pwm->base)) if (IS_ERR(mchp_core_pwm->base))
@ -470,9 +471,7 @@ static int mchp_core_pwm_probe(struct platform_device *pdev)
mutex_init(&mchp_core_pwm->lock); mutex_init(&mchp_core_pwm->lock);
mchp_core_pwm->chip.dev = &pdev->dev; chip->ops = &mchp_core_pwm_ops;
mchp_core_pwm->chip.ops = &mchp_core_pwm_ops;
mchp_core_pwm->chip.npwm = 16;
mchp_core_pwm->channel_enabled = readb_relaxed(mchp_core_pwm->base + MCHPCOREPWM_EN(0)); mchp_core_pwm->channel_enabled = readb_relaxed(mchp_core_pwm->base + MCHPCOREPWM_EN(0));
mchp_core_pwm->channel_enabled |= mchp_core_pwm->channel_enabled |=
@ -485,7 +484,7 @@ static int mchp_core_pwm_probe(struct platform_device *pdev)
writel_relaxed(1U, mchp_core_pwm->base + MCHPCOREPWM_SYNC_UPD); writel_relaxed(1U, mchp_core_pwm->base + MCHPCOREPWM_SYNC_UPD);
mchp_core_pwm->update_timestamp = ktime_get(); mchp_core_pwm->update_timestamp = ktime_get();
ret = devm_pwmchip_add(&pdev->dev, &mchp_core_pwm->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret) if (ret)
return dev_err_probe(&pdev->dev, ret, "Failed to add pwmchip\n"); return dev_err_probe(&pdev->dev, ret, "Failed to add pwmchip\n");