[PATCH 1/5] pwm: sun20i: Use devm_pwmchip_alloc() helper
Hironori KIKUCHI
kikuchan98 at gmail.com
Fri May 31 07:11:33 PDT 2024
This patch fixes a compile error by using the devm_pwmchip_alloc() helper
function along the way.
Signed-off-by: Hironori KIKUCHI <kikuchan98 at gmail.com>
---
drivers/pwm/pwm-sun20i.c | 45 ++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/drivers/pwm/pwm-sun20i.c b/drivers/pwm/pwm-sun20i.c
index 3e3b5b138b3..93782023af6 100644
--- a/drivers/pwm/pwm-sun20i.c
+++ b/drivers/pwm/pwm-sun20i.c
@@ -102,7 +102,7 @@ struct sun20i_pwm_chip {
static inline struct sun20i_pwm_chip *to_sun20i_pwm_chip(struct pwm_chip *chip)
{
- return container_of(chip, struct sun20i_pwm_chip, chip);
+ return pwmchip_get_drvdata(chip);
}
static inline u32 sun20i_pwm_readl(struct sun20i_pwm_chip *chip,
@@ -308,12 +308,31 @@ static void sun20i_pwm_reset_ctrl_release(void *data)
static int sun20i_pwm_probe(struct platform_device *pdev)
{
+ struct pwm_chip *chip;
struct sun20i_pwm_chip *sun20i_chip;
+ const struct sun20i_pwm_data *data;
+ u32 npwm;
int ret;
- sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
- if (!sun20i_chip)
- return -ENOMEM;
+ data = of_device_get_match_data(&pdev->dev);
+ if (!data)
+ return -ENODEV;
+
+ ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels", &npwm);
+ if (ret)
+ npwm = 8;
+
+ if (npwm > 16) {
+ dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16", npwm);
+ npwm = 16;
+ }
+
+ chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*sun20i_chip));
+ if (IS_ERR(chip))
+ return PTR_ERR(chip);
+ sun20i_chip = to_sun20i_pwm_chip(chip);
+
+ sun20i_chip->data = data;
sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(sun20i_chip->base))
@@ -339,17 +358,6 @@ static int sun20i_pwm_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
"failed to get bus reset\n");
- ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
- &sun20i_chip->chip.npwm);
- if (ret)
- sun20i_chip->chip.npwm = 8;
-
- if (sun20i_chip->chip.npwm > 16) {
- dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16",
- sun20i_chip->chip.npwm);
- sun20i_chip->chip.npwm = 16;
- }
-
/* Deassert reset */
ret = reset_control_deassert(sun20i_chip->rst);
if (ret)
@@ -359,17 +367,14 @@ static int sun20i_pwm_probe(struct platform_device *pdev)
if (ret)
return ret;
- sun20i_chip->chip.dev = &pdev->dev;
- sun20i_chip->chip.ops = &sun20i_pwm_ops;
+ chip->ops = &sun20i_pwm_ops;
mutex_init(&sun20i_chip->mutex);
- ret = devm_pwmchip_add(&pdev->dev, &sun20i_chip->chip);
+ ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
- platform_set_drvdata(pdev, sun20i_chip);
-
return 0;
}
--
2.45.1
More information about the linux-arm-kernel
mailing list