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

pwm: stm32: Prepare removing pwm_chip from driver data

This prepares the driver for further changes that will drop struct
pwm_chip chip from struct stm32_pwm. Use the pwm_chip as driver
data instead of the stm32_pwm to get access to the pwm_chip in
stm32_pwm_suspend() without using priv->chip.

Link: https://lore.kernel.org/r/3db96cd915d9d8fc350a7193c0d55dd109b1f035.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent fbde1289
...@@ -630,6 +630,7 @@ static int stm32_pwm_probe(struct platform_device *pdev) ...@@ -630,6 +630,7 @@ static int stm32_pwm_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent); struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
struct pwm_chip *chip;
struct stm32_pwm *priv; struct stm32_pwm *priv;
unsigned int num_enabled; unsigned int num_enabled;
unsigned int i; unsigned int i;
...@@ -638,6 +639,7 @@ static int stm32_pwm_probe(struct platform_device *pdev) ...@@ -638,6 +639,7 @@ static int stm32_pwm_probe(struct platform_device *pdev)
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
chip = &priv->chip;
mutex_init(&priv->lock); mutex_init(&priv->lock);
priv->regmap = ddata->regmap; priv->regmap = ddata->regmap;
...@@ -653,37 +655,38 @@ static int stm32_pwm_probe(struct platform_device *pdev) ...@@ -653,37 +655,38 @@ static int stm32_pwm_probe(struct platform_device *pdev)
stm32_pwm_detect_complementary(priv); stm32_pwm_detect_complementary(priv);
priv->chip.dev = dev; chip->dev = dev;
priv->chip.ops = &stm32pwm_ops; chip->ops = &stm32pwm_ops;
priv->chip.npwm = stm32_pwm_detect_channels(priv, &num_enabled); chip->npwm = stm32_pwm_detect_channels(priv, &num_enabled);
/* Initialize clock refcount to number of enabled PWM channels. */ /* Initialize clock refcount to number of enabled PWM channels. */
for (i = 0; i < num_enabled; i++) for (i = 0; i < num_enabled; i++)
clk_enable(priv->clk); clk_enable(priv->clk);
ret = devm_pwmchip_add(dev, &priv->chip); ret = devm_pwmchip_add(dev, chip);
if (ret < 0) if (ret < 0)
return ret; return ret;
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, chip);
return 0; return 0;
} }
static int stm32_pwm_suspend(struct device *dev) static int stm32_pwm_suspend(struct device *dev)
{ {
struct stm32_pwm *priv = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
unsigned int i; unsigned int i;
u32 ccer, mask; u32 ccer, mask;
/* Look for active channels */ /* Look for active channels */
ccer = active_channels(priv); ccer = active_channels(priv);
for (i = 0; i < priv->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
mask = TIM_CCER_CC1E << (i * 4); mask = TIM_CCER_CC1E << (i * 4);
if (ccer & mask) { if (ccer & mask) {
dev_err(dev, "PWM %u still in use by consumer %s\n", dev_err(dev, "PWM %u still in use by consumer %s\n",
i, priv->chip.pwms[i].label); i, chip->pwms[i].label);
return -EBUSY; return -EBUSY;
} }
} }
...@@ -693,7 +696,8 @@ static int stm32_pwm_suspend(struct device *dev) ...@@ -693,7 +696,8 @@ static int stm32_pwm_suspend(struct device *dev)
static int stm32_pwm_resume(struct device *dev) static int stm32_pwm_resume(struct device *dev)
{ {
struct stm32_pwm *priv = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
int ret; int ret;
ret = pinctrl_pm_select_default_state(dev); ret = pinctrl_pm_select_default_state(dev);
......
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