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

pwm: tiehrpwm: 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 ehrpwm_pwm_chip. To just not have to
do that, rework ehrpwm_pwm_save_context() and
ehrpwm_pwm_restore_context() take a pwm_chip. Also use the pwm_chip as
driver data instead of the ehrpwm_pwm_chip.

Link: https://lore.kernel.org/r/79052207cdf71f0882ae13fe1a192ef6f6dba35b.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent b514a1b2
......@@ -450,6 +450,7 @@ static int ehrpwm_pwm_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct ehrpwm_pwm_chip *pc;
struct pwm_chip *chip;
struct clk *clk;
int ret;
......@@ -474,9 +475,10 @@ static int ehrpwm_pwm_probe(struct platform_device *pdev)
return -EINVAL;
}
pc->chip.dev = &pdev->dev;
pc->chip.ops = &ehrpwm_pwm_ops;
pc->chip.npwm = NUM_PWM_CHANNEL;
chip = &pc->chip;
chip->dev = &pdev->dev;
chip->ops = &ehrpwm_pwm_ops;
chip->npwm = NUM_PWM_CHANNEL;
pc->mmio_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pc->mmio_base))
......@@ -493,13 +495,13 @@ static int ehrpwm_pwm_probe(struct platform_device *pdev)
return ret;
}
ret = pwmchip_add(&pc->chip);
ret = pwmchip_add(chip);
if (ret < 0) {
dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
goto err_clk_unprepare;
}
platform_set_drvdata(pdev, pc);
platform_set_drvdata(pdev, chip);
pm_runtime_enable(&pdev->dev);
return 0;
......@@ -512,18 +514,21 @@ static int ehrpwm_pwm_probe(struct platform_device *pdev)
static void ehrpwm_pwm_remove(struct platform_device *pdev)
{
struct ehrpwm_pwm_chip *pc = platform_get_drvdata(pdev);
struct pwm_chip *chip = platform_get_drvdata(pdev);
struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
pwmchip_remove(&pc->chip);
pwmchip_remove(chip);
clk_unprepare(pc->tbclk);
pm_runtime_disable(&pdev->dev);
}
static void ehrpwm_pwm_save_context(struct ehrpwm_pwm_chip *pc)
static void ehrpwm_pwm_save_context(struct pwm_chip *chip)
{
pm_runtime_get_sync(pc->chip.dev);
struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
pm_runtime_get_sync(chip->dev);
pc->ctx.tbctl = ehrpwm_read(pc->mmio_base, TBCTL);
pc->ctx.tbprd = ehrpwm_read(pc->mmio_base, TBPRD);
......@@ -534,11 +539,13 @@ static void ehrpwm_pwm_save_context(struct ehrpwm_pwm_chip *pc)
pc->ctx.aqsfrc = ehrpwm_read(pc->mmio_base, AQSFRC);
pc->ctx.aqcsfrc = ehrpwm_read(pc->mmio_base, AQCSFRC);
pm_runtime_put_sync(pc->chip.dev);
pm_runtime_put_sync(chip->dev);
}
static void ehrpwm_pwm_restore_context(struct ehrpwm_pwm_chip *pc)
static void ehrpwm_pwm_restore_context(struct pwm_chip *chip)
{
struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
ehrpwm_write(pc->mmio_base, TBPRD, pc->ctx.tbprd);
ehrpwm_write(pc->mmio_base, CMPA, pc->ctx.cmpa);
ehrpwm_write(pc->mmio_base, CMPB, pc->ctx.cmpb);
......@@ -551,13 +558,13 @@ static void ehrpwm_pwm_restore_context(struct ehrpwm_pwm_chip *pc)
static int ehrpwm_pwm_suspend(struct device *dev)
{
struct ehrpwm_pwm_chip *pc = dev_get_drvdata(dev);
struct pwm_chip *chip = dev_get_drvdata(dev);
unsigned int i;
ehrpwm_pwm_save_context(pc);
ehrpwm_pwm_save_context(chip);
for (i = 0; i < pc->chip.npwm; i++) {
struct pwm_device *pwm = &pc->chip.pwms[i];
for (i = 0; i < chip->npwm; i++) {
struct pwm_device *pwm = &chip->pwms[i];
if (!pwm_is_enabled(pwm))
continue;
......@@ -571,11 +578,11 @@ static int ehrpwm_pwm_suspend(struct device *dev)
static int ehrpwm_pwm_resume(struct device *dev)
{
struct ehrpwm_pwm_chip *pc = dev_get_drvdata(dev);
struct pwm_chip *chip = dev_get_drvdata(dev);
unsigned int i;
for (i = 0; i < pc->chip.npwm; i++) {
struct pwm_device *pwm = &pc->chip.pwms[i];
for (i = 0; i < chip->npwm; i++) {
struct pwm_device *pwm = &chip->pwms[i];
if (!pwm_is_enabled(pwm))
continue;
......@@ -584,7 +591,7 @@ static int ehrpwm_pwm_resume(struct device *dev)
pm_runtime_get_sync(dev);
}
ehrpwm_pwm_restore_context(pc);
ehrpwm_pwm_restore_context(chip);
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