Commit 19248d86 authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: hibvt: Make use of devm_pwmchip_alloc() function

This prepares the pwm-hibvt 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/7b12504b4128969bdc783bf2bff1ecc63b7c7bd4.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent c8cf5911
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#define PWM_DUTY_MASK GENMASK(31, 0) #define PWM_DUTY_MASK GENMASK(31, 0)
struct hibvt_pwm_chip { struct hibvt_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
struct reset_control *rstc; struct reset_control *rstc;
...@@ -65,7 +64,7 @@ static const struct hibvt_pwm_soc hi3559v100_soc_info = { ...@@ -65,7 +64,7 @@ static const struct hibvt_pwm_soc hi3559v100_soc_info = {
static inline struct hibvt_pwm_chip *to_hibvt_pwm_chip(struct pwm_chip *chip) static inline struct hibvt_pwm_chip *to_hibvt_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct hibvt_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static void hibvt_pwm_set_bits(void __iomem *base, u32 offset, static void hibvt_pwm_set_bits(void __iomem *base, u32 offset,
...@@ -191,12 +190,14 @@ static int hibvt_pwm_probe(struct platform_device *pdev) ...@@ -191,12 +190,14 @@ static int hibvt_pwm_probe(struct platform_device *pdev)
{ {
const struct hibvt_pwm_soc *soc = const struct hibvt_pwm_soc *soc =
of_device_get_match_data(&pdev->dev); of_device_get_match_data(&pdev->dev);
struct pwm_chip *chip;
struct hibvt_pwm_chip *hi_pwm_chip; struct hibvt_pwm_chip *hi_pwm_chip;
int ret, i; int ret, i;
hi_pwm_chip = devm_kzalloc(&pdev->dev, sizeof(*hi_pwm_chip), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, soc->num_pwms, sizeof(*hi_pwm_chip));
if (hi_pwm_chip == NULL) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
hi_pwm_chip = to_hibvt_pwm_chip(chip);
hi_pwm_chip->clk = devm_clk_get(&pdev->dev, NULL); hi_pwm_chip->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(hi_pwm_chip->clk)) { if (IS_ERR(hi_pwm_chip->clk)) {
...@@ -205,9 +206,7 @@ static int hibvt_pwm_probe(struct platform_device *pdev) ...@@ -205,9 +206,7 @@ static int hibvt_pwm_probe(struct platform_device *pdev)
return PTR_ERR(hi_pwm_chip->clk); return PTR_ERR(hi_pwm_chip->clk);
} }
hi_pwm_chip->chip.ops = &hibvt_pwm_ops; chip->ops = &hibvt_pwm_ops;
hi_pwm_chip->chip.dev = &pdev->dev;
hi_pwm_chip->chip.npwm = soc->num_pwms;
hi_pwm_chip->soc = soc; hi_pwm_chip->soc = soc;
hi_pwm_chip->base = devm_platform_ioremap_resource(pdev, 0); hi_pwm_chip->base = devm_platform_ioremap_resource(pdev, 0);
...@@ -228,29 +227,28 @@ static int hibvt_pwm_probe(struct platform_device *pdev) ...@@ -228,29 +227,28 @@ static int hibvt_pwm_probe(struct platform_device *pdev)
msleep(30); msleep(30);
reset_control_deassert(hi_pwm_chip->rstc); reset_control_deassert(hi_pwm_chip->rstc);
ret = pwmchip_add(&hi_pwm_chip->chip); ret = pwmchip_add(chip);
if (ret < 0) { if (ret < 0) {
clk_disable_unprepare(hi_pwm_chip->clk); clk_disable_unprepare(hi_pwm_chip->clk);
return ret; return ret;
} }
for (i = 0; i < hi_pwm_chip->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
hibvt_pwm_set_bits(hi_pwm_chip->base, PWM_CTRL_ADDR(i), hibvt_pwm_set_bits(hi_pwm_chip->base, PWM_CTRL_ADDR(i),
PWM_KEEP_MASK, (0x1 << PWM_KEEP_SHIFT)); PWM_KEEP_MASK, (0x1 << PWM_KEEP_SHIFT));
} }
platform_set_drvdata(pdev, hi_pwm_chip); platform_set_drvdata(pdev, chip);
return 0; return 0;
} }
static void hibvt_pwm_remove(struct platform_device *pdev) static void hibvt_pwm_remove(struct platform_device *pdev)
{ {
struct hibvt_pwm_chip *hi_pwm_chip; struct pwm_chip *chip = platform_get_drvdata(pdev);
struct hibvt_pwm_chip *hi_pwm_chip = to_hibvt_pwm_chip(chip);
hi_pwm_chip = platform_get_drvdata(pdev);
pwmchip_remove(&hi_pwm_chip->chip); pwmchip_remove(chip);
reset_control_assert(hi_pwm_chip->rstc); reset_control_assert(hi_pwm_chip->rstc);
msleep(30); msleep(30);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment