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

pwm: tiecap: Change prototype of helpers to prepare further changes

This prepares the driver for further changes that will make it harder to
determine the pwm_chip from a given ecap_pwm_chip. To just not have to
do that, rework ecap_pwm_save_context() and ecap_pwm_restore_context
take a pwm_chip. Also use the pwm_chip as driver data instead of the
ecap_pwm_chip.

Link: https://lore.kernel.org/r/ed031f201ff52c6b298de2dc81b06aad3a0207f8.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 62f59c10
...@@ -218,6 +218,7 @@ static int ecap_pwm_probe(struct platform_device *pdev) ...@@ -218,6 +218,7 @@ static int ecap_pwm_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct ecap_pwm_chip *pc; struct ecap_pwm_chip *pc;
struct pwm_chip *chip;
struct clk *clk; struct clk *clk;
int ret; int ret;
...@@ -244,21 +245,22 @@ static int ecap_pwm_probe(struct platform_device *pdev) ...@@ -244,21 +245,22 @@ static int ecap_pwm_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
pc->chip.dev = &pdev->dev; chip = &pc->chip;
pc->chip.ops = &ecap_pwm_ops; chip->dev = &pdev->dev;
pc->chip.npwm = 1; chip->ops = &ecap_pwm_ops;
chip->npwm = 1;
pc->mmio_base = devm_platform_ioremap_resource(pdev, 0); pc->mmio_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pc->mmio_base)) if (IS_ERR(pc->mmio_base))
return PTR_ERR(pc->mmio_base); return PTR_ERR(pc->mmio_base);
ret = devm_pwmchip_add(&pdev->dev, &pc->chip); ret = devm_pwmchip_add(&pdev->dev, 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);
return ret; return ret;
} }
platform_set_drvdata(pdev, pc); platform_set_drvdata(pdev, chip);
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
return 0; return 0;
...@@ -269,17 +271,21 @@ static void ecap_pwm_remove(struct platform_device *pdev) ...@@ -269,17 +271,21 @@ static void ecap_pwm_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
} }
static void ecap_pwm_save_context(struct ecap_pwm_chip *pc) static void ecap_pwm_save_context(struct pwm_chip *chip)
{ {
pm_runtime_get_sync(pc->chip.dev); struct ecap_pwm_chip *pc = to_ecap_pwm_chip(chip);
pm_runtime_get_sync(chip->dev);
pc->ctx.ecctl2 = readw(pc->mmio_base + ECCTL2); pc->ctx.ecctl2 = readw(pc->mmio_base + ECCTL2);
pc->ctx.cap4 = readl(pc->mmio_base + CAP4); pc->ctx.cap4 = readl(pc->mmio_base + CAP4);
pc->ctx.cap3 = readl(pc->mmio_base + CAP3); pc->ctx.cap3 = readl(pc->mmio_base + CAP3);
pm_runtime_put_sync(pc->chip.dev); pm_runtime_put_sync(chip->dev);
} }
static void ecap_pwm_restore_context(struct ecap_pwm_chip *pc) static void ecap_pwm_restore_context(struct pwm_chip *chip)
{ {
struct ecap_pwm_chip *pc = to_ecap_pwm_chip(chip);
writel(pc->ctx.cap3, pc->mmio_base + CAP3); writel(pc->ctx.cap3, pc->mmio_base + CAP3);
writel(pc->ctx.cap4, pc->mmio_base + CAP4); writel(pc->ctx.cap4, pc->mmio_base + CAP4);
writew(pc->ctx.ecctl2, pc->mmio_base + ECCTL2); writew(pc->ctx.ecctl2, pc->mmio_base + ECCTL2);
...@@ -287,10 +293,10 @@ static void ecap_pwm_restore_context(struct ecap_pwm_chip *pc) ...@@ -287,10 +293,10 @@ static void ecap_pwm_restore_context(struct ecap_pwm_chip *pc)
static int ecap_pwm_suspend(struct device *dev) static int ecap_pwm_suspend(struct device *dev)
{ {
struct ecap_pwm_chip *pc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct pwm_device *pwm = pc->chip.pwms; struct pwm_device *pwm = chip->pwms;
ecap_pwm_save_context(pc); ecap_pwm_save_context(chip);
/* Disable explicitly if PWM is running */ /* Disable explicitly if PWM is running */
if (pwm_is_enabled(pwm)) if (pwm_is_enabled(pwm))
...@@ -301,14 +307,14 @@ static int ecap_pwm_suspend(struct device *dev) ...@@ -301,14 +307,14 @@ static int ecap_pwm_suspend(struct device *dev)
static int ecap_pwm_resume(struct device *dev) static int ecap_pwm_resume(struct device *dev)
{ {
struct ecap_pwm_chip *pc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct pwm_device *pwm = pc->chip.pwms; struct pwm_device *pwm = chip->pwms;
/* Enable explicitly if PWM was running */ /* Enable explicitly if PWM was running */
if (pwm_is_enabled(pwm)) if (pwm_is_enabled(pwm))
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
ecap_pwm_restore_context(pc); ecap_pwm_restore_context(chip);
return 0; return 0;
} }
......
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