Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm: renesas-tpu: Make use of devm_pwmchip_alloc() function

This prepares the pwm-renesas-tpu 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.

Also convert the to_tpu_device() helper macro to a static inline to get
some type safety.

Link: https://lore.kernel.org/r/aac4a9546b0f474d991144aa925c83cfa7abe2c0.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

+11 -9
+11 -9
drivers/pwm/pwm-renesas-tpu.c
··· 79 79 80 80 struct tpu_device { 81 81 struct platform_device *pdev; 82 - struct pwm_chip chip; 83 82 spinlock_t lock; 84 83 85 84 void __iomem *base; ··· 86 87 struct tpu_pwm_device tpd[TPU_CHANNEL_MAX]; 87 88 }; 88 89 89 - #define to_tpu_device(c) container_of(c, struct tpu_device, chip) 90 + static inline struct tpu_device *to_tpu_device(struct pwm_chip *chip) 91 + { 92 + return pwmchip_get_drvdata(chip); 93 + } 90 94 91 95 static void tpu_pwm_write(struct tpu_pwm_device *tpd, int reg_nr, u16 value) 92 96 { ··· 440 438 441 439 static int tpu_probe(struct platform_device *pdev) 442 440 { 441 + struct pwm_chip *chip; 443 442 struct tpu_device *tpu; 444 443 int ret; 445 444 446 - tpu = devm_kzalloc(&pdev->dev, sizeof(*tpu), GFP_KERNEL); 447 - if (tpu == NULL) 448 - return -ENOMEM; 445 + chip = devm_pwmchip_alloc(&pdev->dev, TPU_CHANNEL_MAX, sizeof(*tpu)); 446 + if (IS_ERR(chip)) 447 + return PTR_ERR(chip); 448 + tpu = to_tpu_device(chip); 449 449 450 450 spin_lock_init(&tpu->lock); 451 451 tpu->pdev = pdev; ··· 464 460 /* Initialize and register the device. */ 465 461 platform_set_drvdata(pdev, tpu); 466 462 467 - tpu->chip.dev = &pdev->dev; 468 - tpu->chip.ops = &tpu_pwm_ops; 469 - tpu->chip.npwm = TPU_CHANNEL_MAX; 463 + chip->ops = &tpu_pwm_ops; 470 464 471 465 ret = devm_pm_runtime_enable(&pdev->dev); 472 466 if (ret < 0) 473 467 return dev_err_probe(&pdev->dev, ret, "Failed to enable runtime PM\n"); 474 468 475 - ret = devm_pwmchip_add(&pdev->dev, &tpu->chip); 469 + ret = devm_pwmchip_add(&pdev->dev, chip); 476 470 if (ret < 0) 477 471 return dev_err_probe(&pdev->dev, ret, "Failed to register PWM chip\n"); 478 472