pwm: jz4740: Make use of devm_pwmchip_alloc() function

This prepares the pwm-jz4740 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: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/14a081c097b4e7c7f346ca6557ece8d16ad5749d.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:44 +01:00
parent 4eeb33229c
commit 5d0237a7b0

View File

@ -25,14 +25,13 @@ struct soc_info {
};
struct jz4740_pwm_chip {
struct pwm_chip chip;
struct regmap *map;
struct clk *clk[];
};
static inline struct jz4740_pwm_chip *to_jz4740(struct pwm_chip *chip)
{
return container_of(chip, struct jz4740_pwm_chip, chip);
return pwmchip_get_drvdata(chip);
}
static bool jz4740_pwm_can_use_chn(struct pwm_chip *chip, unsigned int channel)
@ -224,6 +223,7 @@ static const struct pwm_ops jz4740_pwm_ops = {
static int jz4740_pwm_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct pwm_chip *chip;
struct jz4740_pwm_chip *jz;
const struct soc_info *info;
@ -231,10 +231,10 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
if (!info)
return -EINVAL;
jz = devm_kzalloc(dev, struct_size(jz, clk, info->num_pwms),
GFP_KERNEL);
if (!jz)
return -ENOMEM;
chip = devm_pwmchip_alloc(dev, info->num_pwms, struct_size(jz, clk, info->num_pwms));
if (IS_ERR(chip))
return PTR_ERR(chip);
jz = to_jz4740(chip);
jz->map = device_node_to_regmap(dev->parent->of_node);
if (IS_ERR(jz->map)) {
@ -242,11 +242,9 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
return PTR_ERR(jz->map);
}
jz->chip.dev = dev;
jz->chip.ops = &jz4740_pwm_ops;
jz->chip.npwm = info->num_pwms;
chip->ops = &jz4740_pwm_ops;
return devm_pwmchip_add(dev, &jz->chip);
return devm_pwmchip_add(dev, chip);
}
static const struct soc_info jz4740_soc_info = {