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

pwm: img: Prepare removing pwm_chip from driver data

This prepares the driver for further changes that will drop struct
pwm_chip chip from struct img_pwm_chip. Use the pwm_chip as driver data
instead of the img_pwm_chip to get access to the pwm_chip in
img_pwm_remove() and the PM callbacks without using imgchip->chip.

Link: https://lore.kernel.org/r/2ddf76d127f69eca7d9faa6475091e432e890ac9.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 2231f6fe
...@@ -224,7 +224,8 @@ MODULE_DEVICE_TABLE(of, img_pwm_of_match); ...@@ -224,7 +224,8 @@ MODULE_DEVICE_TABLE(of, img_pwm_of_match);
static int img_pwm_runtime_suspend(struct device *dev) 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->pwm_clk);
clk_disable_unprepare(imgchip->sys_clk); clk_disable_unprepare(imgchip->sys_clk);
...@@ -234,7 +235,8 @@ static int img_pwm_runtime_suspend(struct device *dev) ...@@ -234,7 +235,8 @@ static int img_pwm_runtime_suspend(struct device *dev)
static int img_pwm_runtime_resume(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; int ret;
ret = clk_prepare_enable(imgchip->sys_clk); ret = clk_prepare_enable(imgchip->sys_clk);
...@@ -258,11 +260,13 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -258,11 +260,13 @@ static int img_pwm_probe(struct platform_device *pdev)
int ret; int ret;
u64 val; u64 val;
unsigned long clk_rate; unsigned long clk_rate;
struct pwm_chip *chip;
struct img_pwm_chip *imgchip; struct img_pwm_chip *imgchip;
imgchip = devm_kzalloc(&pdev->dev, sizeof(*imgchip), GFP_KERNEL); imgchip = devm_kzalloc(&pdev->dev, sizeof(*imgchip), GFP_KERNEL);
if (!imgchip) if (!imgchip)
return -ENOMEM; return -ENOMEM;
chip = &imgchip->chip;
imgchip->base = devm_platform_ioremap_resource(pdev, 0); imgchip->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(imgchip->base)) if (IS_ERR(imgchip->base))
...@@ -287,7 +291,7 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -287,7 +291,7 @@ static int img_pwm_probe(struct platform_device *pdev)
return PTR_ERR(imgchip->pwm_clk); 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_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT);
pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_use_autosuspend(&pdev->dev);
...@@ -314,11 +318,11 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -314,11 +318,11 @@ static int img_pwm_probe(struct platform_device *pdev)
do_div(val, clk_rate); do_div(val, clk_rate);
imgchip->min_period_ns = val; imgchip->min_period_ns = val;
imgchip->chip.dev = &pdev->dev; chip->dev = &pdev->dev;
imgchip->chip.ops = &img_pwm_ops; chip->ops = &img_pwm_ops;
imgchip->chip.npwm = IMG_PWM_NPWM; chip->npwm = IMG_PWM_NPWM;
ret = pwmchip_add(&imgchip->chip); ret = pwmchip_add(chip);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret);
goto err_suspend; goto err_suspend;
...@@ -337,19 +341,20 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -337,19 +341,20 @@ static int img_pwm_probe(struct platform_device *pdev)
static void img_pwm_remove(struct platform_device *pdev) 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); pm_runtime_disable(&pdev->dev);
if (!pm_runtime_status_suspended(&pdev->dev)) if (!pm_runtime_status_suspended(&pdev->dev))
img_pwm_runtime_suspend(&pdev->dev); img_pwm_runtime_suspend(&pdev->dev);
pwmchip_remove(&imgchip->chip); pwmchip_remove(chip);
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int img_pwm_suspend(struct device *dev) 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; int i, ret;
if (pm_runtime_status_suspended(dev)) { if (pm_runtime_status_suspended(dev)) {
...@@ -358,7 +363,7 @@ static int img_pwm_suspend(struct device *dev) ...@@ -358,7 +363,7 @@ static int img_pwm_suspend(struct device *dev)
return ret; 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, imgchip->suspend_ch_cfg[i] = img_pwm_readl(imgchip,
PWM_CH_CFG(i)); PWM_CH_CFG(i));
...@@ -371,7 +376,8 @@ static int img_pwm_suspend(struct device *dev) ...@@ -371,7 +376,8 @@ static int img_pwm_suspend(struct device *dev)
static int img_pwm_resume(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 ret;
int i; int i;
...@@ -379,13 +385,13 @@ static int img_pwm_resume(struct device *dev) ...@@ -379,13 +385,13 @@ static int img_pwm_resume(struct device *dev)
if (ret) if (ret)
return 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), img_pwm_writel(imgchip, PWM_CH_CFG(i),
imgchip->suspend_ch_cfg[i]); imgchip->suspend_ch_cfg[i]);
img_pwm_writel(imgchip, PWM_CTRL_CFG, imgchip->suspend_ctrl_cfg); 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)) if (imgchip->suspend_ctrl_cfg & BIT(i))
regmap_clear_bits(imgchip->periph_regs, regmap_clear_bits(imgchip->periph_regs,
PERIP_PWM_PDM_CONTROL, PERIP_PWM_PDM_CONTROL,
......
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