diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-07 13:11:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-07 13:11:22 +0000 |
commit | b20732900e4636a467c0183a47f7396700f5f743 (patch) | |
tree | 42f079ff82e701ebcb76829974b4caca3e5b6798 /drivers/pwm/pwm-img.c | |
parent | Adding upstream version 6.8.12. (diff) | |
download | linux-b20732900e4636a467c0183a47f7396700f5f743.tar.xz linux-b20732900e4636a467c0183a47f7396700f5f743.zip |
Adding upstream version 6.9.7.upstream/6.9.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/pwm/pwm-img.c')
-rw-r--r-- | drivers/pwm/pwm-img.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c index 54dbafc516..d6596583ed 100644 --- a/drivers/pwm/pwm-img.c +++ b/drivers/pwm/pwm-img.c @@ -59,8 +59,6 @@ struct img_pwm_soc_data { }; struct img_pwm_chip { - struct device *dev; - struct pwm_chip chip; struct clk *pwm_clk; struct clk *sys_clk; void __iomem *base; @@ -74,7 +72,7 @@ struct img_pwm_chip { static inline struct img_pwm_chip *to_img_pwm_chip(struct pwm_chip *chip) { - return container_of(chip, struct img_pwm_chip, chip); + return pwmchip_get_drvdata(chip); } static inline void img_pwm_writel(struct img_pwm_chip *imgchip, @@ -99,7 +97,7 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, if (period_ns < imgchip->min_period_ns || period_ns > imgchip->max_period_ns) { - dev_err(chip->dev, "configured period not in range\n"); + dev_err(pwmchip_parent(chip), "configured period not in range\n"); return -ERANGE; } @@ -120,14 +118,14 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, div = PWM_CTRL_CFG_SUB_DIV0_DIV1; timebase = DIV_ROUND_UP(mul, 512); } else { - dev_err(chip->dev, + dev_err(pwmchip_parent(chip), "failed to configure timebase steps/divider value\n"); return -EINVAL; } duty = DIV_ROUND_UP(timebase * duty_ns, period_ns); - ret = pm_runtime_resume_and_get(chip->dev); + ret = pm_runtime_resume_and_get(pwmchip_parent(chip)); if (ret < 0) return ret; @@ -141,8 +139,8 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, (timebase << PWM_CH_CFG_TMBASE_SHIFT); img_pwm_writel(imgchip, PWM_CH_CFG(pwm->hwpwm), val); - pm_runtime_mark_last_busy(chip->dev); - pm_runtime_put_autosuspend(chip->dev); + pm_runtime_mark_last_busy(pwmchip_parent(chip)); + pm_runtime_put_autosuspend(pwmchip_parent(chip)); return 0; } @@ -153,7 +151,7 @@ static int img_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); int ret; - ret = pm_runtime_resume_and_get(chip->dev); + ret = pm_runtime_resume_and_get(pwmchip_parent(chip)); if (ret < 0) return ret; @@ -177,8 +175,8 @@ static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) val &= ~BIT(pwm->hwpwm); img_pwm_writel(imgchip, PWM_CTRL_CFG, val); - pm_runtime_mark_last_busy(chip->dev); - pm_runtime_put_autosuspend(chip->dev); + pm_runtime_mark_last_busy(pwmchip_parent(chip)); + pm_runtime_put_autosuspend(pwmchip_parent(chip)); } static int img_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, @@ -225,7 +223,8 @@ MODULE_DEVICE_TABLE(of, img_pwm_of_match); static int img_pwm_runtime_suspend(struct device *dev) { - struct img_pwm_chip *imgchip = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); clk_disable_unprepare(imgchip->pwm_clk); clk_disable_unprepare(imgchip->sys_clk); @@ -235,7 +234,8 @@ static int img_pwm_runtime_suspend(struct device *dev) static int img_pwm_runtime_resume(struct device *dev) { - struct img_pwm_chip *imgchip = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); int ret; ret = clk_prepare_enable(imgchip->sys_clk); @@ -259,13 +259,13 @@ static int img_pwm_probe(struct platform_device *pdev) int ret; u64 val; unsigned long clk_rate; + struct pwm_chip *chip; struct img_pwm_chip *imgchip; - imgchip = devm_kzalloc(&pdev->dev, sizeof(*imgchip), GFP_KERNEL); - if (!imgchip) - return -ENOMEM; - - imgchip->dev = &pdev->dev; + chip = devm_pwmchip_alloc(&pdev->dev, IMG_PWM_NPWM, sizeof(*imgchip)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + imgchip = to_img_pwm_chip(chip); imgchip->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(imgchip->base)) @@ -290,7 +290,7 @@ static int img_pwm_probe(struct platform_device *pdev) return PTR_ERR(imgchip->pwm_clk); } - platform_set_drvdata(pdev, imgchip); + platform_set_drvdata(pdev, chip); pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT); pm_runtime_use_autosuspend(&pdev->dev); @@ -317,11 +317,9 @@ static int img_pwm_probe(struct platform_device *pdev) do_div(val, clk_rate); imgchip->min_period_ns = val; - imgchip->chip.dev = &pdev->dev; - imgchip->chip.ops = &img_pwm_ops; - imgchip->chip.npwm = IMG_PWM_NPWM; + chip->ops = &img_pwm_ops; - ret = pwmchip_add(&imgchip->chip); + ret = pwmchip_add(chip); if (ret < 0) { dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); goto err_suspend; @@ -340,19 +338,20 @@ err_pm_disable: static void img_pwm_remove(struct platform_device *pdev) { - struct img_pwm_chip *imgchip = platform_get_drvdata(pdev); + struct pwm_chip *chip = platform_get_drvdata(pdev); pm_runtime_disable(&pdev->dev); if (!pm_runtime_status_suspended(&pdev->dev)) img_pwm_runtime_suspend(&pdev->dev); - pwmchip_remove(&imgchip->chip); + pwmchip_remove(chip); } #ifdef CONFIG_PM_SLEEP static int img_pwm_suspend(struct device *dev) { - struct img_pwm_chip *imgchip = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); int i, ret; if (pm_runtime_status_suspended(dev)) { @@ -361,7 +360,7 @@ static int img_pwm_suspend(struct device *dev) return ret; } - for (i = 0; i < imgchip->chip.npwm; i++) + for (i = 0; i < chip->npwm; i++) imgchip->suspend_ch_cfg[i] = img_pwm_readl(imgchip, PWM_CH_CFG(i)); @@ -374,7 +373,8 @@ static int img_pwm_suspend(struct device *dev) static int img_pwm_resume(struct device *dev) { - struct img_pwm_chip *imgchip = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); int ret; int i; @@ -382,13 +382,13 @@ static int img_pwm_resume(struct device *dev) if (ret) return ret; - for (i = 0; i < imgchip->chip.npwm; i++) + for (i = 0; i < chip->npwm; i++) img_pwm_writel(imgchip, PWM_CH_CFG(i), imgchip->suspend_ch_cfg[i]); img_pwm_writel(imgchip, PWM_CTRL_CFG, imgchip->suspend_ctrl_cfg); - for (i = 0; i < imgchip->chip.npwm; i++) + for (i = 0; i < chip->npwm; i++) if (imgchip->suspend_ctrl_cfg & BIT(i)) regmap_clear_bits(imgchip->periph_regs, PERIP_PWM_PDM_CONTROL, |