pwm: tegra: Prepare removing pwm_chip from driver data
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 14 Feb 2024 09:32:57 +0000 (10:32 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thu, 22 Feb 2024 13:39:26 +0000 (14:39 +0100)
This prepares the driver for further changes that will drop struct
pwm_chip chip from struct tegra_pwm_chip. Use the pwm_chip as driver
data instead of the tegra_pwm_chip to get access to the pwm_chip in
tegra_pwm_remove() without using pc->chip.

Link: https://lore.kernel.org/r/2813c63bf1317dee808f4c5c4a9411999f2d5746.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
drivers/pwm/pwm-tegra.c

index 0d5f57c9ee26429c39708f40158ba3e148c79b77..f61c24376523a4f24ea98d246dc617b9b97d09f9 100644 (file)
@@ -271,12 +271,14 @@ static const struct pwm_ops tegra_pwm_ops = {
 
 static int tegra_pwm_probe(struct platform_device *pdev)
 {
+       struct pwm_chip *chip;
        struct tegra_pwm_chip *pc;
        int ret;
 
        pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
        if (!pc)
                return -ENOMEM;
+       chip = &pc->chip;
 
        pc->soc = of_device_get_match_data(&pdev->dev);
 
@@ -284,7 +286,7 @@ static int tegra_pwm_probe(struct platform_device *pdev)
        if (IS_ERR(pc->regs))
                return PTR_ERR(pc->regs);
 
-       platform_set_drvdata(pdev, pc);
+       platform_set_drvdata(pdev, chip);
 
        pc->clk = devm_clk_get(&pdev->dev, NULL);
        if (IS_ERR(pc->clk))
@@ -326,11 +328,11 @@ static int tegra_pwm_probe(struct platform_device *pdev)
 
        reset_control_deassert(pc->rst);
 
-       pc->chip.dev = &pdev->dev;
-       pc->chip.ops = &tegra_pwm_ops;
-       pc->chip.npwm = pc->soc->num_channels;
+       chip->dev = &pdev->dev;
+       chip->ops = &tegra_pwm_ops;
+       chip->npwm = pc->soc->num_channels;
 
-       ret = pwmchip_add(&pc->chip);
+       ret = pwmchip_add(chip);
        if (ret < 0) {
                dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
                reset_control_assert(pc->rst);
@@ -348,9 +350,10 @@ put_pm:
 
 static void tegra_pwm_remove(struct platform_device *pdev)
 {
-       struct tegra_pwm_chip *pc = platform_get_drvdata(pdev);
+       struct pwm_chip *chip = platform_get_drvdata(pdev);
+       struct tegra_pwm_chip *pc = to_tegra_pwm_chip(chip);
 
-       pwmchip_remove(&pc->chip);
+       pwmchip_remove(chip);
 
        reset_control_assert(pc->rst);
 
@@ -359,7 +362,8 @@ static void tegra_pwm_remove(struct platform_device *pdev)
 
 static int __maybe_unused tegra_pwm_runtime_suspend(struct device *dev)
 {
-       struct tegra_pwm_chip *pc = dev_get_drvdata(dev);
+       struct pwm_chip *chip = dev_get_drvdata(dev);
+       struct tegra_pwm_chip *pc = to_tegra_pwm_chip(chip);
        int err;
 
        clk_disable_unprepare(pc->clk);
@@ -375,7 +379,8 @@ static int __maybe_unused tegra_pwm_runtime_suspend(struct device *dev)
 
 static int __maybe_unused tegra_pwm_runtime_resume(struct device *dev)
 {
-       struct tegra_pwm_chip *pc = dev_get_drvdata(dev);
+       struct pwm_chip *chip = dev_get_drvdata(dev);
+       struct tegra_pwm_chip *pc = to_tegra_pwm_chip(chip);
        int err;
 
        err = pinctrl_pm_select_default_state(dev);