mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-16 01:54:00 +00:00
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>
This commit is contained in:
parent
f0d907605d
commit
3a284e0eae
@ -79,7 +79,6 @@ struct tpu_pwm_device {
|
|||||||
|
|
||||||
struct tpu_device {
|
struct tpu_device {
|
||||||
struct platform_device *pdev;
|
struct platform_device *pdev;
|
||||||
struct pwm_chip chip;
|
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
|
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
@ -87,7 +86,10 @@ struct tpu_device {
|
|||||||
struct tpu_pwm_device tpd[TPU_CHANNEL_MAX];
|
struct tpu_pwm_device tpd[TPU_CHANNEL_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define to_tpu_device(c) container_of(c, struct tpu_device, chip)
|
static inline struct tpu_device *to_tpu_device(struct pwm_chip *chip)
|
||||||
|
{
|
||||||
|
return pwmchip_get_drvdata(chip);
|
||||||
|
}
|
||||||
|
|
||||||
static void tpu_pwm_write(struct tpu_pwm_device *tpd, int reg_nr, u16 value)
|
static void tpu_pwm_write(struct tpu_pwm_device *tpd, int reg_nr, u16 value)
|
||||||
{
|
{
|
||||||
@ -438,12 +440,14 @@ static const struct pwm_ops tpu_pwm_ops = {
|
|||||||
|
|
||||||
static int tpu_probe(struct platform_device *pdev)
|
static int tpu_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
struct pwm_chip *chip;
|
||||||
struct tpu_device *tpu;
|
struct tpu_device *tpu;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
tpu = devm_kzalloc(&pdev->dev, sizeof(*tpu), GFP_KERNEL);
|
chip = devm_pwmchip_alloc(&pdev->dev, TPU_CHANNEL_MAX, sizeof(*tpu));
|
||||||
if (tpu == NULL)
|
if (IS_ERR(chip))
|
||||||
return -ENOMEM;
|
return PTR_ERR(chip);
|
||||||
|
tpu = to_tpu_device(chip);
|
||||||
|
|
||||||
spin_lock_init(&tpu->lock);
|
spin_lock_init(&tpu->lock);
|
||||||
tpu->pdev = pdev;
|
tpu->pdev = pdev;
|
||||||
@ -460,15 +464,13 @@ static int tpu_probe(struct platform_device *pdev)
|
|||||||
/* Initialize and register the device. */
|
/* Initialize and register the device. */
|
||||||
platform_set_drvdata(pdev, tpu);
|
platform_set_drvdata(pdev, tpu);
|
||||||
|
|
||||||
tpu->chip.dev = &pdev->dev;
|
chip->ops = &tpu_pwm_ops;
|
||||||
tpu->chip.ops = &tpu_pwm_ops;
|
|
||||||
tpu->chip.npwm = TPU_CHANNEL_MAX;
|
|
||||||
|
|
||||||
ret = devm_pm_runtime_enable(&pdev->dev);
|
ret = devm_pm_runtime_enable(&pdev->dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return dev_err_probe(&pdev->dev, ret, "Failed to enable runtime PM\n");
|
return dev_err_probe(&pdev->dev, ret, "Failed to enable runtime PM\n");
|
||||||
|
|
||||||
ret = devm_pwmchip_add(&pdev->dev, &tpu->chip);
|
ret = devm_pwmchip_add(&pdev->dev, chip);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return dev_err_probe(&pdev->dev, ret, "Failed to register PWM chip\n");
|
return dev_err_probe(&pdev->dev, ret, "Failed to register PWM chip\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user