Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

+9 -7
+9 -7
drivers/pwm/pwm-sifive.c
··· 42 42 43 43 struct pwm_sifive_ddata { 44 44 struct pwm_chip chip; 45 + struct device *parent; 45 46 struct mutex lock; /* lock to protect user_count and approx_period */ 46 47 struct notifier_block notifier; 47 48 struct clk *clk; ··· 103 102 /* As scale <= 15 the shift operation cannot overflow. */ 104 103 num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); 105 104 ddata->real_period = div64_ul(num, rate); 106 - dev_dbg(ddata->chip.dev, 105 + dev_dbg(ddata->parent, 107 106 "New real_period = %u ns\n", ddata->real_period); 108 107 } 109 108 ··· 237 236 238 237 mutex_init(&ddata->lock); 239 238 chip = &ddata->chip; 240 - chip->dev = dev; 239 + chip->dev = ddata->parent = dev; 241 240 chip->ops = &pwm_sifive_ops; 242 241 chip->npwm = 4; 243 242 ··· 297 296 goto unregister_clk; 298 297 } 299 298 300 - platform_set_drvdata(pdev, ddata); 299 + platform_set_drvdata(pdev, chip); 301 300 dev_dbg(dev, "SiFive PWM chip registered %d PWMs\n", chip->npwm); 302 301 303 302 return 0; ··· 315 314 316 315 static void pwm_sifive_remove(struct platform_device *dev) 317 316 { 318 - struct pwm_sifive_ddata *ddata = platform_get_drvdata(dev); 317 + struct pwm_chip *chip = platform_get_drvdata(dev); 318 + struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); 319 319 struct pwm_device *pwm; 320 320 int ch; 321 321 322 - pwmchip_remove(&ddata->chip); 322 + pwmchip_remove(chip); 323 323 clk_notifier_unregister(ddata->clk, &ddata->notifier); 324 324 325 - for (ch = 0; ch < ddata->chip.npwm; ch++) { 326 - pwm = &ddata->chip.pwms[ch]; 325 + for (ch = 0; ch < chip->npwm; ch++) { 326 + pwm = &chip->pwms[ch]; 327 327 if (pwm->state.enabled) 328 328 clk_disable(ddata->clk); 329 329 }