From 27262029e9fd88e313a719258713af441cd5db1c Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 14 Feb 2024 10:32:20 +0100 Subject: pwm: rz-mtu3: Make use of pwmchip_parent() accessor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit struct pwm_chip::dev is about to change. To not have to touch this driver in the same commit as struct pwm_chip::dev, use the accessor function provided for exactly this purpose. Link: https://lore.kernel.org/r/90e6b5d5215425f3a5ff4468ba8aedf3d387f812.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-rz-mtu3.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/pwm/pwm-rz-mtu3.c') diff --git a/drivers/pwm/pwm-rz-mtu3.c b/drivers/pwm/pwm-rz-mtu3.c index bdda315b3bd3..acdc45ff90cf 100644 --- a/drivers/pwm/pwm-rz-mtu3.c +++ b/drivers/pwm/pwm-rz-mtu3.c @@ -219,7 +219,7 @@ static int rz_mtu3_pwm_enable(struct rz_mtu3_pwm_chip *rz_mtu3_pwm, u8 val; int rc; - rc = pm_runtime_resume_and_get(rz_mtu3_pwm->chip.dev); + rc = pm_runtime_resume_and_get(pwmchip_parent(&rz_mtu3_pwm->chip)); if (rc) return rc; @@ -265,7 +265,7 @@ static void rz_mtu3_pwm_disable(struct rz_mtu3_pwm_chip *rz_mtu3_pwm, mutex_unlock(&rz_mtu3_pwm->lock); - pm_runtime_put_sync(rz_mtu3_pwm->chip.dev); + pm_runtime_put_sync(pwmchip_parent(&rz_mtu3_pwm->chip)); } static int rz_mtu3_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, @@ -274,7 +274,7 @@ static int rz_mtu3_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip); int rc; - rc = pm_runtime_resume_and_get(chip->dev); + rc = pm_runtime_resume_and_get(pwmchip_parent(chip)); if (rc) return rc; @@ -307,7 +307,7 @@ static int rz_mtu3_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, } state->polarity = PWM_POLARITY_NORMAL; - pm_runtime_put(chip->dev); + pm_runtime_put(pwmchip_parent(chip)); return 0; } @@ -362,7 +362,7 @@ static int rz_mtu3_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, if (!pwm->state.enabled) { int rc; - rc = pm_runtime_resume_and_get(chip->dev); + rc = pm_runtime_resume_and_get(pwmchip_parent(chip)); if (rc) return rc; } @@ -399,7 +399,7 @@ static int rz_mtu3_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, /* If the PWM is not enabled, turn the clock off again to save power. */ if (!pwm->state.enabled) - pm_runtime_put(chip->dev); + pm_runtime_put(pwmchip_parent(chip)); return 0; } @@ -465,8 +465,8 @@ static void rz_mtu3_pwm_pm_disable(void *data) struct rz_mtu3_pwm_chip *rz_mtu3_pwm = data; clk_rate_exclusive_put(rz_mtu3_pwm->clk); - pm_runtime_disable(rz_mtu3_pwm->chip.dev); - pm_runtime_set_suspended(rz_mtu3_pwm->chip.dev); + pm_runtime_disable(pwmchip_parent(&rz_mtu3_pwm->chip)); + pm_runtime_set_suspended(pwmchip_parent(&rz_mtu3_pwm->chip)); } static int rz_mtu3_pwm_probe(struct platform_device *pdev) -- cgit v1.2.3 From dfec83b4fe455224ccd9117dbe3bb1c0c79cbf66 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 14 Feb 2024 10:32:21 +0100 Subject: pwm: rz-mtu3: Prepare removing pwm_chip from driver data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prepares the driver for further changes that will drop struct pwm_chip chip from struct rz_mtu3_pwm_chip. Use the pwm_chip as driver data and devm callback parameter instead of the rz_mtu3_pwm_chip to get access to the pwm_chip in various functions without using rz_mtu3_pwm->chip. Link: https://lore.kernel.org/r/707f2aced94a235f244022f10202ce7730b1168b.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-rz-mtu3.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'drivers/pwm/pwm-rz-mtu3.c') diff --git a/drivers/pwm/pwm-rz-mtu3.c b/drivers/pwm/pwm-rz-mtu3.c index acdc45ff90cf..a129ae4ef338 100644 --- a/drivers/pwm/pwm-rz-mtu3.c +++ b/drivers/pwm/pwm-rz-mtu3.c @@ -211,15 +211,15 @@ static void rz_mtu3_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) mutex_unlock(&rz_mtu3_pwm->lock); } -static int rz_mtu3_pwm_enable(struct rz_mtu3_pwm_chip *rz_mtu3_pwm, - struct pwm_device *pwm) +static int rz_mtu3_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) { + struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip); struct rz_mtu3_pwm_channel *priv; u32 ch; u8 val; int rc; - rc = pm_runtime_resume_and_get(pwmchip_parent(&rz_mtu3_pwm->chip)); + rc = pm_runtime_resume_and_get(pwmchip_parent(chip)); if (rc) return rc; @@ -243,9 +243,9 @@ static int rz_mtu3_pwm_enable(struct rz_mtu3_pwm_chip *rz_mtu3_pwm, return 0; } -static void rz_mtu3_pwm_disable(struct rz_mtu3_pwm_chip *rz_mtu3_pwm, - struct pwm_device *pwm) +static void rz_mtu3_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) { + struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip); struct rz_mtu3_pwm_channel *priv; u32 ch; @@ -265,7 +265,7 @@ static void rz_mtu3_pwm_disable(struct rz_mtu3_pwm_chip *rz_mtu3_pwm, mutex_unlock(&rz_mtu3_pwm->lock); - pm_runtime_put_sync(pwmchip_parent(&rz_mtu3_pwm->chip)); + pm_runtime_put_sync(pwmchip_parent(chip)); } static int rz_mtu3_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, @@ -416,7 +416,7 @@ static int rz_mtu3_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (!state->enabled) { if (enabled) - rz_mtu3_pwm_disable(rz_mtu3_pwm, pwm); + rz_mtu3_pwm_disable(chip, pwm); return 0; } @@ -428,7 +428,7 @@ static int rz_mtu3_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return ret; if (!enabled) - ret = rz_mtu3_pwm_enable(rz_mtu3_pwm, pwm); + ret = rz_mtu3_pwm_enable(chip, pwm); return ret; } @@ -442,7 +442,8 @@ static const struct pwm_ops rz_mtu3_pwm_ops = { static int rz_mtu3_pwm_pm_runtime_suspend(struct device *dev) { - struct rz_mtu3_pwm_chip *rz_mtu3_pwm = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip); clk_disable_unprepare(rz_mtu3_pwm->clk); @@ -451,7 +452,8 @@ static int rz_mtu3_pwm_pm_runtime_suspend(struct device *dev) static int rz_mtu3_pwm_pm_runtime_resume(struct device *dev) { - struct rz_mtu3_pwm_chip *rz_mtu3_pwm = dev_get_drvdata(dev); + struct pwm_chip *chip = dev_get_drvdata(dev); + struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip); return clk_prepare_enable(rz_mtu3_pwm->clk); } @@ -462,17 +464,19 @@ static DEFINE_RUNTIME_DEV_PM_OPS(rz_mtu3_pwm_pm_ops, static void rz_mtu3_pwm_pm_disable(void *data) { - struct rz_mtu3_pwm_chip *rz_mtu3_pwm = data; + struct pwm_chip *chip = data; + struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip); clk_rate_exclusive_put(rz_mtu3_pwm->clk); - pm_runtime_disable(pwmchip_parent(&rz_mtu3_pwm->chip)); - pm_runtime_set_suspended(pwmchip_parent(&rz_mtu3_pwm->chip)); + pm_runtime_disable(pwmchip_parent(chip)); + pm_runtime_set_suspended(pwmchip_parent(chip)); } static int rz_mtu3_pwm_probe(struct platform_device *pdev) { struct rz_mtu3 *parent_ddata = dev_get_drvdata(pdev->dev.parent); struct rz_mtu3_pwm_chip *rz_mtu3_pwm; + struct pwm_chip *chip; struct device *dev = &pdev->dev; unsigned int i, j = 0; int ret; @@ -480,6 +484,7 @@ static int rz_mtu3_pwm_probe(struct platform_device *pdev) rz_mtu3_pwm = devm_kzalloc(&pdev->dev, sizeof(*rz_mtu3_pwm), GFP_KERNEL); if (!rz_mtu3_pwm) return -ENOMEM; + chip = &rz_mtu3_pwm->chip; rz_mtu3_pwm->clk = parent_ddata->clk; @@ -494,7 +499,7 @@ static int rz_mtu3_pwm_probe(struct platform_device *pdev) } mutex_init(&rz_mtu3_pwm->lock); - platform_set_drvdata(pdev, rz_mtu3_pwm); + platform_set_drvdata(pdev, chip); ret = clk_prepare_enable(rz_mtu3_pwm->clk); if (ret) return dev_err_probe(dev, ret, "Clock enable failed\n"); @@ -514,15 +519,15 @@ static int rz_mtu3_pwm_probe(struct platform_device *pdev) pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); - rz_mtu3_pwm->chip.dev = &pdev->dev; + chip->dev = &pdev->dev; ret = devm_add_action_or_reset(&pdev->dev, rz_mtu3_pwm_pm_disable, - rz_mtu3_pwm); + chip); if (ret < 0) return ret; - rz_mtu3_pwm->chip.ops = &rz_mtu3_pwm_ops; - rz_mtu3_pwm->chip.npwm = RZ_MTU3_MAX_PWM_CHANNELS; - ret = devm_pwmchip_add(&pdev->dev, &rz_mtu3_pwm->chip); + chip->ops = &rz_mtu3_pwm_ops; + chip->npwm = RZ_MTU3_MAX_PWM_CHANNELS; + ret = devm_pwmchip_add(&pdev->dev, chip); if (ret) return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); -- cgit v1.2.3 From a629a77e9dfb94f98b3b450cc0309cec1b594157 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 14 Feb 2024 10:32:22 +0100 Subject: pwm: rz-mtu3: Make use of devm_pwmchip_alloc() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prepares the pwm-rz-mtu3 driver to further changes of the pwm core outlined in the commit introducing devm_pwmchip_alloc(). There is no intended semantical change and the driver should behave as before. Link: https://lore.kernel.org/r/b05ffb9bcaf4ddb6305f8505715a5542805e3227.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-rz-mtu3.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'drivers/pwm/pwm-rz-mtu3.c') diff --git a/drivers/pwm/pwm-rz-mtu3.c b/drivers/pwm/pwm-rz-mtu3.c index a129ae4ef338..ab39bd37edaf 100644 --- a/drivers/pwm/pwm-rz-mtu3.c +++ b/drivers/pwm/pwm-rz-mtu3.c @@ -61,7 +61,6 @@ struct rz_mtu3_pwm_channel { /** * struct rz_mtu3_pwm_chip - MTU3 pwm private data * - * @chip: MTU3 pwm chip data * @clk: MTU3 module clock * @lock: Lock to prevent concurrent access for usage count * @rate: MTU3 clock rate @@ -72,7 +71,6 @@ struct rz_mtu3_pwm_channel { */ struct rz_mtu3_pwm_chip { - struct pwm_chip chip; struct clk *clk; struct mutex lock; unsigned long rate; @@ -92,7 +90,7 @@ static const struct rz_mtu3_channel_io_map channel_map[] = { static inline struct rz_mtu3_pwm_chip *to_rz_mtu3_pwm_chip(struct pwm_chip *chip) { - return container_of(chip, struct rz_mtu3_pwm_chip, chip); + return pwmchip_get_drvdata(chip); } static void rz_mtu3_pwm_read_tgr_registers(struct rz_mtu3_pwm_channel *priv, @@ -481,10 +479,11 @@ static int rz_mtu3_pwm_probe(struct platform_device *pdev) unsigned int i, j = 0; int ret; - rz_mtu3_pwm = devm_kzalloc(&pdev->dev, sizeof(*rz_mtu3_pwm), GFP_KERNEL); - if (!rz_mtu3_pwm) - return -ENOMEM; - chip = &rz_mtu3_pwm->chip; + chip = devm_pwmchip_alloc(&pdev->dev, RZ_MTU3_MAX_PWM_CHANNELS, + sizeof(*rz_mtu3_pwm)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip); rz_mtu3_pwm->clk = parent_ddata->clk; @@ -519,14 +518,12 @@ static int rz_mtu3_pwm_probe(struct platform_device *pdev) pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); - chip->dev = &pdev->dev; ret = devm_add_action_or_reset(&pdev->dev, rz_mtu3_pwm_pm_disable, chip); if (ret < 0) return ret; chip->ops = &rz_mtu3_pwm_ops; - chip->npwm = RZ_MTU3_MAX_PWM_CHANNELS; ret = devm_pwmchip_add(&pdev->dev, chip); if (ret) return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); -- cgit v1.2.3