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

pwm: sifive: Prepare removing pwm_chip from driver data

This prepares the driver for further changes that will drop struct
pwm_chip chip from struct pwm_sifive_ddata. Use the pwm_chip as driver
data instead of the pwm_sifive_ddata to get access to the pwm_chip in
pwm_sifive_remove() without using ddata->chip. In the clock rate
notifier it's not possible to get the pwm_chip without adding a pointer
to this to struct pwm_sifive_ddata. Instead of that add a parent device
pointer which is all that is needed there.

Link: https://lore.kernel.org/r/b7b7985f4dc746f6a36c5048d428c4ed0a2d42dc.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent c63f0bbb
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
struct pwm_sifive_ddata { struct pwm_sifive_ddata {
struct pwm_chip chip; struct pwm_chip chip;
struct device *parent;
struct mutex lock; /* lock to protect user_count and approx_period */ struct mutex lock; /* lock to protect user_count and approx_period */
struct notifier_block notifier; struct notifier_block notifier;
struct clk *clk; struct clk *clk;
...@@ -102,7 +103,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, ...@@ -102,7 +103,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata,
/* As scale <= 15 the shift operation cannot overflow. */ /* As scale <= 15 the shift operation cannot overflow. */
num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale);
ddata->real_period = div64_ul(num, rate); ddata->real_period = div64_ul(num, rate);
dev_dbg(ddata->chip.dev, dev_dbg(ddata->parent,
"New real_period = %u ns\n", ddata->real_period); "New real_period = %u ns\n", ddata->real_period);
} }
...@@ -236,7 +237,7 @@ static int pwm_sifive_probe(struct platform_device *pdev) ...@@ -236,7 +237,7 @@ static int pwm_sifive_probe(struct platform_device *pdev)
mutex_init(&ddata->lock); mutex_init(&ddata->lock);
chip = &ddata->chip; chip = &ddata->chip;
chip->dev = dev; chip->dev = ddata->parent = dev;
chip->ops = &pwm_sifive_ops; chip->ops = &pwm_sifive_ops;
chip->npwm = 4; chip->npwm = 4;
...@@ -296,7 +297,7 @@ static int pwm_sifive_probe(struct platform_device *pdev) ...@@ -296,7 +297,7 @@ static int pwm_sifive_probe(struct platform_device *pdev)
goto unregister_clk; goto unregister_clk;
} }
platform_set_drvdata(pdev, ddata); platform_set_drvdata(pdev, chip);
dev_dbg(dev, "SiFive PWM chip registered %d PWMs\n", chip->npwm); dev_dbg(dev, "SiFive PWM chip registered %d PWMs\n", chip->npwm);
return 0; return 0;
...@@ -314,15 +315,16 @@ static int pwm_sifive_probe(struct platform_device *pdev) ...@@ -314,15 +315,16 @@ static int pwm_sifive_probe(struct platform_device *pdev)
static void pwm_sifive_remove(struct platform_device *dev) static void pwm_sifive_remove(struct platform_device *dev)
{ {
struct pwm_sifive_ddata *ddata = platform_get_drvdata(dev); struct pwm_chip *chip = platform_get_drvdata(dev);
struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip);
struct pwm_device *pwm; struct pwm_device *pwm;
int ch; int ch;
pwmchip_remove(&ddata->chip); pwmchip_remove(chip);
clk_notifier_unregister(ddata->clk, &ddata->notifier); clk_notifier_unregister(ddata->clk, &ddata->notifier);
for (ch = 0; ch < ddata->chip.npwm; ch++) { for (ch = 0; ch < chip->npwm; ch++) {
pwm = &ddata->chip.pwms[ch]; pwm = &chip->pwms[ch];
if (pwm->state.enabled) if (pwm->state.enabled)
clk_disable(ddata->clk); clk_disable(ddata->clk);
} }
......
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