* [PATCH 00/11] pwm: Some random cleanups
@ 2023-09-29 16:19 Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions Uwe Kleine-König
` (12 more replies)
0 siblings, 13 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Ray Jui, Scott Branden, Broadcom internal kernel review list,
linux-pwm, linux-arm-kernel, kernel, Florian Fainelli,
linux-rpi-kernel, Shawn Guo, Sascha Hauer, Fabio Estevam,
NXP Linux Team, Matthias Brugger, AngeloGioacchino Del Regno,
linux-mediatek, Orson Zhai, Baolin Wang, Chunyan Zhang,
Krzysztof Kozlowski, Alim Akhtar, linux-samsung-soc, Benson Leung,
Guenter Roeck, chrome-platform
Hello,
this is a set of patches I based my efforts for closing a race condition
in the pwm core on. I thought I already sent them out, but it seems I
didn't. So here they come!
Best regards
Uwe
Uwe Kleine-König (11):
pwm: bcm-iproc: Simplify using devm functions
pwm: bcm2835: Simplify using devm functions
pwm: brcmstb: Simplify using devm functions
pwm: imx-tpm: Simplify using devm functions
pwm: mtk-disp: Simplify using devm_pwmchip_add()
pwm: spear: Simplify using devm functions
pwm: sprd: Provide a helper to cast a chip to driver data
pwm: sprd: Simplify using devm_pwmchip_add() and dev_err_probe()
pwm: vt8500: Simplify using devm functions
pwm: samsung: Consistently use the same name for driver data
pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()
drivers/pwm/pwm-bcm-iproc.c | 37 +++-------
drivers/pwm/pwm-bcm2835.c | 27 ++------
drivers/pwm/pwm-brcmstb.c | 42 +++---------
drivers/pwm/pwm-cros-ec.c | 33 +++------
drivers/pwm/pwm-imx-tpm.c | 29 ++------
drivers/pwm/pwm-mtk-disp.c | 24 ++-----
drivers/pwm/pwm-samsung.c | 130 ++++++++++++++++++------------------
drivers/pwm/pwm-spear.c | 40 +++--------
drivers/pwm/pwm-sprd.c | 28 +++-----
drivers/pwm/pwm-vt8500.c | 42 +++---------
10 files changed, 137 insertions(+), 295 deletions(-)
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
--
2.40.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-11-13 4:11 ` Florian Fainelli
2023-09-29 16:19 ` [PATCH 02/11] pwm: bcm2835: " Uwe Kleine-König
` (11 subsequent siblings)
12 siblings, 1 reply; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Ray Jui, Scott Branden, Broadcom internal kernel review list,
linux-pwm, linux-arm-kernel, kernel
With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
dropped from the error path and the remove callback. With
devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
callback is empty and can go away, too.
Also use dev_err_probe() for simplified (and improved) error reporting.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-bcm-iproc.c | 37 +++++++++----------------------------
1 file changed, 9 insertions(+), 28 deletions(-)
diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
index 7d70b6f186a6..39f93f76a310 100644
--- a/drivers/pwm/pwm-bcm-iproc.c
+++ b/drivers/pwm/pwm-bcm-iproc.c
@@ -207,18 +207,10 @@ static int iproc_pwmc_probe(struct platform_device *pdev)
if (IS_ERR(ip->base))
return PTR_ERR(ip->base);
- ip->clk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(ip->clk)) {
- dev_err(&pdev->dev, "failed to get clock: %ld\n",
- PTR_ERR(ip->clk));
- return PTR_ERR(ip->clk);
- }
-
- ret = clk_prepare_enable(ip->clk);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed to enable clock: %d\n", ret);
- return ret;
- }
+ ip->clk = devm_clk_get_enabled(&pdev->dev, NULL);
+ if (IS_ERR(ip->clk))
+ return dev_err_probe(&pdev->dev, PTR_ERR(ip->clk),
+ "failed to get clock\n");
/* Set full drive and normal polarity for all channels */
value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
@@ -230,22 +222,12 @@ static int iproc_pwmc_probe(struct platform_device *pdev)
writel(value, ip->base + IPROC_PWM_CTRL_OFFSET);
- ret = pwmchip_add(&ip->chip);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
- clk_disable_unprepare(ip->clk);
- }
+ ret = devm_pwmchip_add(&pdev->dev, &ip->chip);
+ if (ret < 0)
+ return dev_err_probe(&pdev->dev, ret,
+ "failed to add PWM chip\n");
- return ret;
-}
-
-static void iproc_pwmc_remove(struct platform_device *pdev)
-{
- struct iproc_pwmc *ip = platform_get_drvdata(pdev);
-
- pwmchip_remove(&ip->chip);
-
- clk_disable_unprepare(ip->clk);
+ return 0;
}
static const struct of_device_id bcm_iproc_pwmc_dt[] = {
@@ -260,7 +242,6 @@ static struct platform_driver iproc_pwmc_driver = {
.of_match_table = bcm_iproc_pwmc_dt,
},
.probe = iproc_pwmc_probe,
- .remove_new = iproc_pwmc_remove,
};
module_platform_driver(iproc_pwmc_driver);
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 02/11] pwm: bcm2835: Simplify using devm functions
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-11-13 4:21 ` Florian Fainelli
2023-09-29 16:19 ` [PATCH 03/11] pwm: brcmstb: " Uwe Kleine-König
` (10 subsequent siblings)
12 siblings, 1 reply; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Florian Fainelli, Broadcom internal kernel review list, Ray Jui,
Scott Branden, linux-pwm, linux-rpi-kernel, linux-arm-kernel,
kernel
With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
dropped from the error path and the remove callback. With
devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
callback is empty and can go away, too. With bcm2835_pwm_remove() the only
user of platform_get_drvdata() is gone and so platform_set_drvdata() can
be dropped from .probe(), too.
Also use dev_err_probe() for simplified (and improved) error reporting.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-bcm2835.c | 27 ++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)
diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index bdfc2a5ec0d6..7261e57159b1 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -147,39 +147,21 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
if (IS_ERR(pc->base))
return PTR_ERR(pc->base);
- pc->clk = devm_clk_get(&pdev->dev, NULL);
+ pc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(pc->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk),
"clock not found\n");
- ret = clk_prepare_enable(pc->clk);
- if (ret)
- return ret;
-
pc->chip.dev = &pdev->dev;
pc->chip.ops = &bcm2835_pwm_ops;
pc->chip.npwm = 2;
- platform_set_drvdata(pdev, pc);
-
- ret = pwmchip_add(&pc->chip);
+ ret = devm_pwmchip_add(&pdev->dev, &pc->chip);
if (ret < 0)
- goto add_fail;
+ return dev_err_probe(&pdev->dev, ret,
+ "failed to add pwmchip\n");
return 0;
-
-add_fail:
- clk_disable_unprepare(pc->clk);
- return ret;
-}
-
-static void bcm2835_pwm_remove(struct platform_device *pdev)
-{
- struct bcm2835_pwm *pc = platform_get_drvdata(pdev);
-
- pwmchip_remove(&pc->chip);
-
- clk_disable_unprepare(pc->clk);
}
static const struct of_device_id bcm2835_pwm_of_match[] = {
@@ -194,7 +176,6 @@ static struct platform_driver bcm2835_pwm_driver = {
.of_match_table = bcm2835_pwm_of_match,
},
.probe = bcm2835_pwm_probe,
- .remove_new = bcm2835_pwm_remove,
};
module_platform_driver(bcm2835_pwm_driver);
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 03/11] pwm: brcmstb: Simplify using devm functions
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 02/11] pwm: bcm2835: " Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-11-13 4:22 ` Florian Fainelli
2023-09-29 16:19 ` [PATCH 04/11] pwm: imx-tpm: " Uwe Kleine-König
` (9 subsequent siblings)
12 siblings, 1 reply; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Florian Fainelli, Broadcom internal kernel review list, linux-pwm,
linux-arm-kernel, kernel
With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
dropped from the error path and the remove callback. With
devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
callback is empty and can go away, too.
Also use dev_err_probe() for simplified (and improved) error reporting.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-brcmstb.c | 42 +++++++++------------------------------
1 file changed, 9 insertions(+), 33 deletions(-)
diff --git a/drivers/pwm/pwm-brcmstb.c b/drivers/pwm/pwm-brcmstb.c
index a3faa9a3de7c..7b6336e22e20 100644
--- a/drivers/pwm/pwm-brcmstb.c
+++ b/drivers/pwm/pwm-brcmstb.c
@@ -238,17 +238,10 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
if (!p)
return -ENOMEM;
- p->clk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(p->clk)) {
- dev_err(&pdev->dev, "failed to obtain clock\n");
- return PTR_ERR(p->clk);
- }
-
- ret = clk_prepare_enable(p->clk);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed to enable clock: %d\n", ret);
- return ret;
- }
+ p->clk = devm_clk_get_enabled(&pdev->dev, NULL);
+ if (IS_ERR(p->clk))
+ return dev_err_probe(&pdev->dev, PTR_ERR(p->clk),
+ "failed to obtain clock\n");
platform_set_drvdata(pdev, p);
@@ -257,30 +250,14 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
p->chip.npwm = 2;
p->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(p->base)) {
- ret = PTR_ERR(p->base);
- goto out_clk;
- }
+ if (IS_ERR(p->base))
+ return PTR_ERR(p->base);
- ret = pwmchip_add(&p->chip);
- if (ret) {
- dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
- goto out_clk;
- }
+ ret = devm_pwmchip_add(&pdev->dev, &p->chip);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
return 0;
-
-out_clk:
- clk_disable_unprepare(p->clk);
- return ret;
-}
-
-static void brcmstb_pwm_remove(struct platform_device *pdev)
-{
- struct brcmstb_pwm *p = platform_get_drvdata(pdev);
-
- pwmchip_remove(&p->chip);
- clk_disable_unprepare(p->clk);
}
#ifdef CONFIG_PM_SLEEP
@@ -308,7 +285,6 @@ static SIMPLE_DEV_PM_OPS(brcmstb_pwm_pm_ops, brcmstb_pwm_suspend,
static struct platform_driver brcmstb_pwm_driver = {
.probe = brcmstb_pwm_probe,
- .remove_new = brcmstb_pwm_remove,
.driver = {
.name = "pwm-brcmstb",
.of_match_table = brcmstb_pwm_of_match,
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 04/11] pwm: imx-tpm: Simplify using devm functions
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (2 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 03/11] pwm: brcmstb: " Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 05/11] pwm: mtk-disp: Simplify using devm_pwmchip_add() Uwe Kleine-König
` (8 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team, linux-pwm, linux-arm-kernel
With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
dropped from the error path and the remove callback. With
devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
callback is empty and can go away, too.
Also use dev_err_probe() for simplified (and improved) error reporting.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-imx-tpm.c | 29 +++++------------------------
1 file changed, 5 insertions(+), 24 deletions(-)
diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
index 98ab65c89685..3ffc89b4f3fe 100644
--- a/drivers/pwm/pwm-imx-tpm.c
+++ b/drivers/pwm/pwm-imx-tpm.c
@@ -351,18 +351,11 @@ static int pwm_imx_tpm_probe(struct platform_device *pdev)
if (IS_ERR(tpm->base))
return PTR_ERR(tpm->base);
- tpm->clk = devm_clk_get(&pdev->dev, NULL);
+ tpm->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(tpm->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(tpm->clk),
"failed to get PWM clock\n");
- ret = clk_prepare_enable(tpm->clk);
- if (ret) {
- dev_err(&pdev->dev,
- "failed to prepare or enable clock: %d\n", ret);
- return ret;
- }
-
tpm->chip.dev = &pdev->dev;
tpm->chip.ops = &imx_tpm_pwm_ops;
@@ -372,22 +365,11 @@ static int pwm_imx_tpm_probe(struct platform_device *pdev)
mutex_init(&tpm->lock);
- ret = pwmchip_add(&tpm->chip);
- if (ret) {
- dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
- clk_disable_unprepare(tpm->clk);
- }
+ ret = devm_pwmchip_add(&pdev->dev, &tpm->chip);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
- return ret;
-}
-
-static void pwm_imx_tpm_remove(struct platform_device *pdev)
-{
- struct imx_tpm_pwm_chip *tpm = platform_get_drvdata(pdev);
-
- pwmchip_remove(&tpm->chip);
-
- clk_disable_unprepare(tpm->clk);
+ return 0;
}
static int __maybe_unused pwm_imx_tpm_suspend(struct device *dev)
@@ -437,7 +419,6 @@ static struct platform_driver imx_tpm_pwm_driver = {
.pm = &imx_tpm_pwm_pm,
},
.probe = pwm_imx_tpm_probe,
- .remove_new = pwm_imx_tpm_remove,
};
module_platform_driver(imx_tpm_pwm_driver);
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 05/11] pwm: mtk-disp: Simplify using devm_pwmchip_add()
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (3 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 04/11] pwm: imx-tpm: " Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-10-02 10:44 ` AngeloGioacchino Del Regno
2023-09-29 16:19 ` [PATCH 06/11] pwm: spear: Simplify using devm functions Uwe Kleine-König
` (7 subsequent siblings)
12 siblings, 1 reply; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Matthias Brugger, AngeloGioacchino Del Regno, linux-pwm, kernel,
linux-arm-kernel, linux-mediatek
With devm_pwmchip_add() pwmchip_remove() can be dropped from the remove
callback. Then the remove callback is empty and can go away, too. With
mtk_disp_pwm_remove() the last user of platform_get_drvdata() is gone and
so platform_set_drvdata() can be dropped, too.
Also use dev_err_probe() for simplified (and improved) error reporting.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-mtk-disp.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
index a83bd6e18b07..e34fb4409695 100644
--- a/drivers/pwm/pwm-mtk-disp.c
+++ b/drivers/pwm/pwm-mtk-disp.c
@@ -247,34 +247,25 @@ static int mtk_disp_pwm_probe(struct platform_device *pdev)
mdp->clk_main = devm_clk_get(&pdev->dev, "main");
if (IS_ERR(mdp->clk_main))
- return PTR_ERR(mdp->clk_main);
+ return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_main),
+ "Failed to get main clock\n");
mdp->clk_mm = devm_clk_get(&pdev->dev, "mm");
if (IS_ERR(mdp->clk_mm))
- return PTR_ERR(mdp->clk_mm);
+ return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_mm),
+ "Failed to get mm clock\n");
mdp->chip.dev = &pdev->dev;
mdp->chip.ops = &mtk_disp_pwm_ops;
mdp->chip.npwm = 1;
- ret = pwmchip_add(&mdp->chip);
- if (ret < 0) {
- dev_err(&pdev->dev, "pwmchip_add() failed: %pe\n", ERR_PTR(ret));
- return ret;
- }
-
- platform_set_drvdata(pdev, mdp);
+ ret = devm_pwmchip_add(&pdev->dev, &mdp->chip);
+ if (ret < 0)
+ return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
return 0;
}
-static void mtk_disp_pwm_remove(struct platform_device *pdev)
-{
- struct mtk_disp_pwm *mdp = platform_get_drvdata(pdev);
-
- pwmchip_remove(&mdp->chip);
-}
-
static const struct mtk_pwm_data mt2701_pwm_data = {
.enable_mask = BIT(16),
.con0 = 0xa8,
@@ -320,7 +311,6 @@ static struct platform_driver mtk_disp_pwm_driver = {
.of_match_table = mtk_disp_pwm_of_match,
},
.probe = mtk_disp_pwm_probe,
- .remove_new = mtk_disp_pwm_remove,
};
module_platform_driver(mtk_disp_pwm_driver);
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 06/11] pwm: spear: Simplify using devm functions
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (4 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 05/11] pwm: mtk-disp: Simplify using devm_pwmchip_add() Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 07/11] pwm: sprd: Provide a helper to cast a chip to driver data Uwe Kleine-König
` (6 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding; +Cc: linux-pwm, kernel
With devm_clk_get_prepared() the call to clk_unprepare() can be dropped
from the error path and the remove callback. With devm_pwmchip_add()
pwmchip_remove() can be dropped. Then the remove callback is empty and
can go away, too. With spear_pwm_remove() the last user of
platform_get_drvdata() is gone and so platform_set_drvdata() can be
dropped, too.
Also use dev_err_probe() for simplified (and improved) error reporting.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-spear.c | 40 +++++++++++-----------------------------
1 file changed, 11 insertions(+), 29 deletions(-)
diff --git a/drivers/pwm/pwm-spear.c b/drivers/pwm/pwm-spear.c
index 4e1cfd8d7c03..0ebdf99453fa 100644
--- a/drivers/pwm/pwm-spear.c
+++ b/drivers/pwm/pwm-spear.c
@@ -207,26 +207,21 @@ static int spear_pwm_probe(struct platform_device *pdev)
if (IS_ERR(pc->mmio_base))
return PTR_ERR(pc->mmio_base);
- pc->clk = devm_clk_get(&pdev->dev, NULL);
+ pc->clk = devm_clk_get_prepared(&pdev->dev, NULL);
if (IS_ERR(pc->clk))
- return PTR_ERR(pc->clk);
-
- platform_set_drvdata(pdev, pc);
+ return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk),
+ "Failed to get clock\n");
pc->chip.dev = &pdev->dev;
pc->chip.ops = &spear_pwm_ops;
pc->chip.npwm = NUM_PWM;
- ret = clk_prepare(pc->clk);
- if (ret)
- return ret;
-
if (of_device_is_compatible(np, "st,spear1340-pwm")) {
ret = clk_enable(pc->clk);
- if (ret) {
- clk_unprepare(pc->clk);
- return ret;
- }
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to enable clk\n");
+
/*
* Following enables PWM chip, channels would still be
* enabled individually through their control register
@@ -238,23 +233,11 @@ static int spear_pwm_probe(struct platform_device *pdev)
clk_disable(pc->clk);
}
- ret = pwmchip_add(&pc->chip);
- if (ret < 0) {
- clk_unprepare(pc->clk);
- dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
- }
+ ret = devm_pwmchip_add(&pdev->dev, &pc->chip);
+ if (ret < 0)
+ return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
- return ret;
-}
-
-static void spear_pwm_remove(struct platform_device *pdev)
-{
- struct spear_pwm_chip *pc = platform_get_drvdata(pdev);
-
- pwmchip_remove(&pc->chip);
-
- /* clk was prepared in probe, hence unprepare it here */
- clk_unprepare(pc->clk);
+ return 0;
}
static const struct of_device_id spear_pwm_of_match[] = {
@@ -271,7 +254,6 @@ static struct platform_driver spear_pwm_driver = {
.of_match_table = spear_pwm_of_match,
},
.probe = spear_pwm_probe,
- .remove_new = spear_pwm_remove,
};
module_platform_driver(spear_pwm_driver);
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 07/11] pwm: sprd: Provide a helper to cast a chip to driver data
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (5 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 06/11] pwm: spear: Simplify using devm functions Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 08/11] pwm: sprd: Simplify using devm_pwmchip_add() and dev_err_probe() Uwe Kleine-König
` (5 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding; +Cc: Orson Zhai, Baolin Wang, Chunyan Zhang, linux-pwm, kernel
Similar to most other PWM drivers provide a static inline function to
calculate driver data from a given pwmchip.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-sprd.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c
index 1499c8c1fe37..a3020bf164c8 100644
--- a/drivers/pwm/pwm-sprd.c
+++ b/drivers/pwm/pwm-sprd.c
@@ -40,6 +40,11 @@ struct sprd_pwm_chip {
struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM];
};
+static inline struct sprd_pwm_chip* sprd_pwm_from_chip(struct pwm_chip *chip)
+{
+ return container_of(chip, struct sprd_pwm_chip, chip);
+}
+
/*
* The list of clocks required by PWM channels, and each channel has 2 clocks:
* enable clock and pwm clock.
@@ -69,8 +74,7 @@ static void sprd_pwm_write(struct sprd_pwm_chip *spc, u32 hwid,
static int sprd_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_state *state)
{
- struct sprd_pwm_chip *spc =
- container_of(chip, struct sprd_pwm_chip, chip);
+ struct sprd_pwm_chip *spc = sprd_pwm_from_chip(chip);
struct sprd_pwm_chn *chn = &spc->chn[pwm->hwpwm];
u32 val, duty, prescale;
u64 tmp;
@@ -162,8 +166,7 @@ static int sprd_pwm_config(struct sprd_pwm_chip *spc, struct pwm_device *pwm,
static int sprd_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
- struct sprd_pwm_chip *spc =
- container_of(chip, struct sprd_pwm_chip, chip);
+ struct sprd_pwm_chip *spc = sprd_pwm_from_chip(chip);
struct sprd_pwm_chn *chn = &spc->chn[pwm->hwpwm];
struct pwm_state *cstate = &pwm->state;
int ret;
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 08/11] pwm: sprd: Simplify using devm_pwmchip_add() and dev_err_probe()
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (6 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 07/11] pwm: sprd: Provide a helper to cast a chip to driver data Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 09/11] pwm: vt8500: Simplify using devm functions Uwe Kleine-König
` (4 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding; +Cc: Orson Zhai, Baolin Wang, Chunyan Zhang, linux-pwm, kernel
Using devm_pwmchip_add() allows to drop pwmchip_remove() from the remove
function which makes this function empty. Then there is no user of
drvdata left and platform_set_drvdata() can be dropped, too.
Further simplify and improve error returning using dev_err_probe().
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-sprd.c | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c
index a3020bf164c8..42bd9608bc1e 100644
--- a/drivers/pwm/pwm-sprd.c
+++ b/drivers/pwm/pwm-sprd.c
@@ -243,10 +243,8 @@ static int sprd_pwm_clk_init(struct sprd_pwm_chip *spc)
chn->clk_rate = clk_get_rate(clk_pwm);
}
- if (!i) {
- dev_err(spc->dev, "no available PWM channels\n");
- return -ENODEV;
- }
+ if (!i)
+ return dev_err_probe(spc->dev, -ENODEV, "no available PWM channels\n");
spc->num_pwms = i;
@@ -267,7 +265,6 @@ static int sprd_pwm_probe(struct platform_device *pdev)
return PTR_ERR(spc->base);
spc->dev = &pdev->dev;
- platform_set_drvdata(pdev, spc);
ret = sprd_pwm_clk_init(spc);
if (ret)
@@ -277,20 +274,13 @@ static int sprd_pwm_probe(struct platform_device *pdev)
spc->chip.ops = &sprd_pwm_ops;
spc->chip.npwm = spc->num_pwms;
- ret = pwmchip_add(&spc->chip);
+ ret = devm_pwmchip_add(&pdev->dev, &spc->chip);
if (ret)
dev_err(&pdev->dev, "failed to add PWM chip\n");
return ret;
}
-static void sprd_pwm_remove(struct platform_device *pdev)
-{
- struct sprd_pwm_chip *spc = platform_get_drvdata(pdev);
-
- pwmchip_remove(&spc->chip);
-}
-
static const struct of_device_id sprd_pwm_of_match[] = {
{ .compatible = "sprd,ums512-pwm", },
{ },
@@ -303,7 +293,6 @@ static struct platform_driver sprd_pwm_driver = {
.of_match_table = sprd_pwm_of_match,
},
.probe = sprd_pwm_probe,
- .remove_new = sprd_pwm_remove,
};
module_platform_driver(sprd_pwm_driver);
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 09/11] pwm: vt8500: Simplify using devm functions
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (7 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 08/11] pwm: sprd: Simplify using devm_pwmchip_add() and dev_err_probe() Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 10/11] pwm: samsung: Consistently use the same name for driver data Uwe Kleine-König
` (3 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding; +Cc: linux-arm-kernel, linux-pwm, kernel
With devm_clk_get_prepared() the call to clk_unprepare() can be dropped
from the error path and the remove callback. With devm_pwmchip_add()
pwmchip_remove() can be dropped. Then the remove callback is empty and
can go away, too. With vt8500_pwm_remove() the last user of
platform_get_drvdata() is gone and so platform_set_drvdata() can be
dropped, too.
Also use dev_err_probe() for simplified (and improved) error reporting.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-vt8500.c | 42 +++++++++-------------------------------
1 file changed, 9 insertions(+), 33 deletions(-)
diff --git a/drivers/pwm/pwm-vt8500.c b/drivers/pwm/pwm-vt8500.c
index 6d46db51daac..25fee12d2131 100644
--- a/drivers/pwm/pwm-vt8500.c
+++ b/drivers/pwm/pwm-vt8500.c
@@ -236,10 +236,8 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
int ret;
- if (!np) {
- dev_err(&pdev->dev, "invalid devicetree node\n");
- return -EINVAL;
- }
+ if (!np)
+ return dev_err_probe(&pdev->dev, -EINVAL, "invalid devicetree node\n");
vt8500 = devm_kzalloc(&pdev->dev, sizeof(*vt8500), GFP_KERNEL);
if (vt8500 == NULL)
@@ -249,45 +247,23 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
vt8500->chip.ops = &vt8500_pwm_ops;
vt8500->chip.npwm = VT8500_NR_PWMS;
- vt8500->clk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(vt8500->clk)) {
- dev_err(&pdev->dev, "clock source not specified\n");
- return PTR_ERR(vt8500->clk);
- }
+ vt8500->clk = devm_clk_get_prepared(&pdev->dev, NULL);
+ if (IS_ERR(vt8500->clk))
+ return dev_err_probe(&pdev->dev, PTR_ERR(vt8500->clk), "clock source not specified\n");
vt8500->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(vt8500->base))
return PTR_ERR(vt8500->base);
- ret = clk_prepare(vt8500->clk);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed to prepare clock\n");
- return ret;
- }
+ ret = devm_pwmchip_add(&pdev->dev, &vt8500->chip);
+ if (ret < 0)
+ return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
- ret = pwmchip_add(&vt8500->chip);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed to add PWM chip\n");
- clk_unprepare(vt8500->clk);
- return ret;
- }
-
- platform_set_drvdata(pdev, vt8500);
- return ret;
-}
-
-static void vt8500_pwm_remove(struct platform_device *pdev)
-{
- struct vt8500_chip *vt8500 = platform_get_drvdata(pdev);
-
- pwmchip_remove(&vt8500->chip);
-
- clk_unprepare(vt8500->clk);
+ return 0;
}
static struct platform_driver vt8500_pwm_driver = {
.probe = vt8500_pwm_probe,
- .remove_new = vt8500_pwm_remove,
.driver = {
.name = "vt8500-pwm",
.of_match_table = vt8500_pwm_dt_ids,
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 10/11] pwm: samsung: Consistently use the same name for driver data
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (8 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 09/11] pwm: vt8500: Simplify using devm functions Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe() Uwe Kleine-König
` (2 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Krzysztof Kozlowski, Alim Akhtar, linux-arm-kernel,
linux-samsung-soc, linux-pwm, kernel
The driver uses mostly "chip" to name samsung_pwm_chip pointers:
$ git grep -Pho 'samsung_pwm_chip \*[a-zA-Z0-9_]+(*nla:[a-zA-Z0-9_(])' v6.5-rc1 -- drivers/pwm/pwm-samsung.c | sort | uniq -c
10 samsung_pwm_chip *chip
6 samsung_pwm_chip *our_chip
1 samsung_pwm_chip *pwm
However "chip" is supposed to be used for struct pwm_chip pointers and
"pwm" for struct pwm_device pointers. So consistently use "our_chip".
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-samsung.c | 130 +++++++++++++++++++-------------------
1 file changed, 65 insertions(+), 65 deletions(-)
diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c
index e8828f57ab15..8d13a05d8d12 100644
--- a/drivers/pwm/pwm-samsung.c
+++ b/drivers/pwm/pwm-samsung.c
@@ -117,21 +117,21 @@ static inline unsigned int to_tcon_channel(unsigned int channel)
return (channel == 0) ? 0 : (channel + 1);
}
-static void __pwm_samsung_manual_update(struct samsung_pwm_chip *chip,
+static void __pwm_samsung_manual_update(struct samsung_pwm_chip *our_chip,
struct pwm_device *pwm)
{
unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm);
u32 tcon;
- tcon = readl(chip->base + REG_TCON);
+ tcon = readl(our_chip->base + REG_TCON);
tcon |= TCON_MANUALUPDATE(tcon_chan);
- writel(tcon, chip->base + REG_TCON);
+ writel(tcon, our_chip->base + REG_TCON);
tcon &= ~TCON_MANUALUPDATE(tcon_chan);
- writel(tcon, chip->base + REG_TCON);
+ writel(tcon, our_chip->base + REG_TCON);
}
-static void pwm_samsung_set_divisor(struct samsung_pwm_chip *pwm,
+static void pwm_samsung_set_divisor(struct samsung_pwm_chip *our_chip,
unsigned int channel, u8 divisor)
{
u8 shift = TCFG1_SHIFT(channel);
@@ -139,39 +139,39 @@ static void pwm_samsung_set_divisor(struct samsung_pwm_chip *pwm,
u32 reg;
u8 bits;
- bits = (fls(divisor) - 1) - pwm->variant.div_base;
+ bits = (fls(divisor) - 1) - our_chip->variant.div_base;
spin_lock_irqsave(&samsung_pwm_lock, flags);
- reg = readl(pwm->base + REG_TCFG1);
+ reg = readl(our_chip->base + REG_TCFG1);
reg &= ~(TCFG1_MUX_MASK << shift);
reg |= bits << shift;
- writel(reg, pwm->base + REG_TCFG1);
+ writel(reg, our_chip->base + REG_TCFG1);
spin_unlock_irqrestore(&samsung_pwm_lock, flags);
}
-static int pwm_samsung_is_tdiv(struct samsung_pwm_chip *chip, unsigned int chan)
+static int pwm_samsung_is_tdiv(struct samsung_pwm_chip *our_chip, unsigned int chan)
{
- struct samsung_pwm_variant *variant = &chip->variant;
+ struct samsung_pwm_variant *variant = &our_chip->variant;
u32 reg;
- reg = readl(chip->base + REG_TCFG1);
+ reg = readl(our_chip->base + REG_TCFG1);
reg >>= TCFG1_SHIFT(chan);
reg &= TCFG1_MUX_MASK;
return (BIT(reg) & variant->tclk_mask) == 0;
}
-static unsigned long pwm_samsung_get_tin_rate(struct samsung_pwm_chip *chip,
+static unsigned long pwm_samsung_get_tin_rate(struct samsung_pwm_chip *our_chip,
unsigned int chan)
{
unsigned long rate;
u32 reg;
- rate = clk_get_rate(chip->base_clk);
+ rate = clk_get_rate(our_chip->base_clk);
- reg = readl(chip->base + REG_TCFG0);
+ reg = readl(our_chip->base + REG_TCFG0);
if (chan >= 2)
reg >>= TCFG0_PRESCALER1_SHIFT;
reg &= TCFG0_PRESCALER_MASK;
@@ -179,28 +179,28 @@ static unsigned long pwm_samsung_get_tin_rate(struct samsung_pwm_chip *chip,
return rate / (reg + 1);
}
-static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *chip,
+static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *our_chip,
unsigned int chan, unsigned long freq)
{
- struct samsung_pwm_variant *variant = &chip->variant;
+ struct samsung_pwm_variant *variant = &our_chip->variant;
unsigned long rate;
struct clk *clk;
u8 div;
- if (!pwm_samsung_is_tdiv(chip, chan)) {
- clk = (chan < 2) ? chip->tclk0 : chip->tclk1;
+ if (!pwm_samsung_is_tdiv(our_chip, chan)) {
+ clk = (chan < 2) ? our_chip->tclk0 : our_chip->tclk1;
if (!IS_ERR(clk)) {
rate = clk_get_rate(clk);
if (rate)
return rate;
}
- dev_warn(chip->chip.dev,
+ dev_warn(our_chip->chip.dev,
"tclk of PWM %d is inoperational, using tdiv\n", chan);
}
- rate = pwm_samsung_get_tin_rate(chip, chan);
- dev_dbg(chip->chip.dev, "tin parent at %lu\n", rate);
+ rate = pwm_samsung_get_tin_rate(our_chip, chan);
+ dev_dbg(our_chip->chip.dev, "tin parent at %lu\n", rate);
/*
* Compare minimum PWM frequency that can be achieved with possible
@@ -220,7 +220,7 @@ static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *chip,
div = variant->div_base;
}
- pwm_samsung_set_divisor(chip, chan, BIT(div));
+ pwm_samsung_set_divisor(our_chip, chan, BIT(div));
return rate >> div;
}
@@ -302,14 +302,14 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm)
spin_unlock_irqrestore(&samsung_pwm_lock, flags);
}
-static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip,
+static void pwm_samsung_manual_update(struct samsung_pwm_chip *our_chip,
struct pwm_device *pwm)
{
unsigned long flags;
spin_lock_irqsave(&samsung_pwm_lock, flags);
- __pwm_samsung_manual_update(chip, pwm);
+ __pwm_samsung_manual_update(our_chip, pwm);
spin_unlock_irqrestore(&samsung_pwm_lock, flags);
}
@@ -393,7 +393,7 @@ static int pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
return __pwm_samsung_config(chip, pwm, duty_ns, period_ns, false);
}
-static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip,
+static void pwm_samsung_set_invert(struct samsung_pwm_chip *our_chip,
unsigned int channel, bool invert)
{
unsigned int tcon_chan = to_tcon_channel(channel);
@@ -402,17 +402,17 @@ static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip,
spin_lock_irqsave(&samsung_pwm_lock, flags);
- tcon = readl(chip->base + REG_TCON);
+ tcon = readl(our_chip->base + REG_TCON);
if (invert) {
- chip->inverter_mask |= BIT(channel);
+ our_chip->inverter_mask |= BIT(channel);
tcon |= TCON_INVERT(tcon_chan);
} else {
- chip->inverter_mask &= ~BIT(channel);
+ our_chip->inverter_mask &= ~BIT(channel);
tcon &= ~TCON_INVERT(tcon_chan);
}
- writel(tcon, chip->base + REG_TCON);
+ writel(tcon, our_chip->base + REG_TCON);
spin_unlock_irqrestore(&samsung_pwm_lock, flags);
}
@@ -517,9 +517,9 @@ static const struct of_device_id samsung_pwm_matches[] = {
};
MODULE_DEVICE_TABLE(of, samsung_pwm_matches);
-static int pwm_samsung_parse_dt(struct samsung_pwm_chip *chip)
+static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip)
{
- struct device_node *np = chip->chip.dev->of_node;
+ struct device_node *np = our_chip->chip.dev->of_node;
const struct of_device_id *match;
struct property *prop;
const __be32 *cur;
@@ -529,22 +529,22 @@ static int pwm_samsung_parse_dt(struct samsung_pwm_chip *chip)
if (!match)
return -ENODEV;
- memcpy(&chip->variant, match->data, sizeof(chip->variant));
+ memcpy(&our_chip->variant, match->data, sizeof(our_chip->variant));
of_property_for_each_u32(np, "samsung,pwm-outputs", prop, cur, val) {
if (val >= SAMSUNG_PWM_NUM) {
- dev_err(chip->chip.dev,
+ dev_err(our_chip->chip.dev,
"%s: invalid channel index in samsung,pwm-outputs property\n",
__func__);
continue;
}
- chip->variant.output_mask |= BIT(val);
+ our_chip->variant.output_mask |= BIT(val);
}
return 0;
}
#else
-static int pwm_samsung_parse_dt(struct samsung_pwm_chip *chip)
+static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip)
{
return -ENODEV;
}
@@ -553,21 +553,21 @@ static int pwm_samsung_parse_dt(struct samsung_pwm_chip *chip)
static int pwm_samsung_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct samsung_pwm_chip *chip;
+ struct samsung_pwm_chip *our_chip;
unsigned int chan;
int ret;
- chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
- if (chip == NULL)
+ our_chip = devm_kzalloc(&pdev->dev, sizeof(*our_chip), GFP_KERNEL);
+ if (our_chip == NULL)
return -ENOMEM;
- chip->chip.dev = &pdev->dev;
- chip->chip.ops = &pwm_samsung_ops;
- chip->chip.npwm = SAMSUNG_PWM_NUM;
- chip->inverter_mask = BIT(SAMSUNG_PWM_NUM) - 1;
+ our_chip->chip.dev = &pdev->dev;
+ our_chip->chip.ops = &pwm_samsung_ops;
+ our_chip->chip.npwm = SAMSUNG_PWM_NUM;
+ our_chip->inverter_mask = BIT(SAMSUNG_PWM_NUM) - 1;
if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
- ret = pwm_samsung_parse_dt(chip);
+ ret = pwm_samsung_parse_dt(our_chip);
if (ret)
return ret;
} else {
@@ -576,58 +576,58 @@ static int pwm_samsung_probe(struct platform_device *pdev)
return -EINVAL;
}
- memcpy(&chip->variant, pdev->dev.platform_data,
- sizeof(chip->variant));
+ memcpy(&our_chip->variant, pdev->dev.platform_data,
+ sizeof(our_chip->variant));
}
- chip->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(chip->base))
- return PTR_ERR(chip->base);
+ our_chip->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(our_chip->base))
+ return PTR_ERR(our_chip->base);
- chip->base_clk = devm_clk_get(&pdev->dev, "timers");
- if (IS_ERR(chip->base_clk)) {
+ our_chip->base_clk = devm_clk_get(&pdev->dev, "timers");
+ if (IS_ERR(our_chip->base_clk)) {
dev_err(dev, "failed to get timer base clk\n");
- return PTR_ERR(chip->base_clk);
+ return PTR_ERR(our_chip->base_clk);
}
- ret = clk_prepare_enable(chip->base_clk);
+ ret = clk_prepare_enable(our_chip->base_clk);
if (ret < 0) {
dev_err(dev, "failed to enable base clock\n");
return ret;
}
for (chan = 0; chan < SAMSUNG_PWM_NUM; ++chan)
- if (chip->variant.output_mask & BIT(chan))
- pwm_samsung_set_invert(chip, chan, true);
+ if (our_chip->variant.output_mask & BIT(chan))
+ pwm_samsung_set_invert(our_chip, chan, true);
/* Following clocks are optional. */
- chip->tclk0 = devm_clk_get(&pdev->dev, "pwm-tclk0");
- chip->tclk1 = devm_clk_get(&pdev->dev, "pwm-tclk1");
+ our_chip->tclk0 = devm_clk_get(&pdev->dev, "pwm-tclk0");
+ our_chip->tclk1 = devm_clk_get(&pdev->dev, "pwm-tclk1");
- platform_set_drvdata(pdev, chip);
+ platform_set_drvdata(pdev, our_chip);
- ret = pwmchip_add(&chip->chip);
+ ret = pwmchip_add(&our_chip->chip);
if (ret < 0) {
dev_err(dev, "failed to register PWM chip\n");
- clk_disable_unprepare(chip->base_clk);
+ clk_disable_unprepare(our_chip->base_clk);
return ret;
}
dev_dbg(dev, "base_clk at %lu, tclk0 at %lu, tclk1 at %lu\n",
- clk_get_rate(chip->base_clk),
- !IS_ERR(chip->tclk0) ? clk_get_rate(chip->tclk0) : 0,
- !IS_ERR(chip->tclk1) ? clk_get_rate(chip->tclk1) : 0);
+ clk_get_rate(our_chip->base_clk),
+ !IS_ERR(our_chip->tclk0) ? clk_get_rate(our_chip->tclk0) : 0,
+ !IS_ERR(our_chip->tclk1) ? clk_get_rate(our_chip->tclk1) : 0);
return 0;
}
static void pwm_samsung_remove(struct platform_device *pdev)
{
- struct samsung_pwm_chip *chip = platform_get_drvdata(pdev);
+ struct samsung_pwm_chip *our_chip = platform_get_drvdata(pdev);
- pwmchip_remove(&chip->chip);
+ pwmchip_remove(&our_chip->chip);
- clk_disable_unprepare(chip->base_clk);
+ clk_disable_unprepare(our_chip->base_clk);
}
#ifdef CONFIG_PM_SLEEP
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (9 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 10/11] pwm: samsung: Consistently use the same name for driver data Uwe Kleine-König
@ 2023-09-29 16:19 ` Uwe Kleine-König
2023-10-02 6:01 ` Tzung-Bi Shih
2023-11-13 3:23 ` [PATCH 00/11] pwm: Some random cleanups patchwork-bot+chrome-platform
2023-11-13 3:42 ` patchwork-bot+chrome-platform
12 siblings, 1 reply; 20+ messages in thread
From: Uwe Kleine-König @ 2023-09-29 16:19 UTC (permalink / raw)
To: Thierry Reding
Cc: Benson Leung, Guenter Roeck, linux-pwm, chrome-platform, kernel
Using devm_pwmchip_add() allows to drop pwmchip_remove() from the remove
function which makes this function empty. Then there is no user of
drvdata left and platform_set_drvdata() can be dropped, too.
Further simplify and improve error returning using dev_err_probe().
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-cros-ec.c | 33 ++++++++-------------------------
1 file changed, 8 insertions(+), 25 deletions(-)
diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
index baaac0c33aa0..f048150fffc7 100644
--- a/drivers/pwm/pwm-cros-ec.c
+++ b/drivers/pwm/pwm-cros-ec.c
@@ -286,10 +286,8 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
struct pwm_chip *chip;
int ret;
- if (!ec) {
- dev_err(dev, "no parent EC device\n");
- return -EINVAL;
- }
+ if (!ec)
+ return dev_err_probe(dev, -EINVAL, "no parent EC device\n");
ec_pwm = devm_kzalloc(dev, sizeof(*ec_pwm), GFP_KERNEL);
if (!ec_pwm)
@@ -310,32 +308,18 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
chip->npwm = CROS_EC_PWM_DT_COUNT;
} else {
ret = cros_ec_num_pwms(ec_pwm);
- if (ret < 0) {
- dev_err(dev, "Couldn't find PWMs: %d\n", ret);
- return ret;
- }
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Couldn't find PWMs\n");
chip->npwm = ret;
}
dev_dbg(dev, "Probed %u PWMs\n", chip->npwm);
- ret = pwmchip_add(chip);
- if (ret < 0) {
- dev_err(dev, "cannot register PWM: %d\n", ret);
- return ret;
- }
+ ret = devm_pwmchip_add(dev, chip);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "cannot register PWM\n");
- platform_set_drvdata(pdev, ec_pwm);
-
- return ret;
-}
-
-static void cros_ec_pwm_remove(struct platform_device *dev)
-{
- struct cros_ec_pwm_device *ec_pwm = platform_get_drvdata(dev);
- struct pwm_chip *chip = &ec_pwm->chip;
-
- pwmchip_remove(chip);
+ return 0;
}
#ifdef CONFIG_OF
@@ -349,7 +333,6 @@ MODULE_DEVICE_TABLE(of, cros_ec_pwm_of_match);
static struct platform_driver cros_ec_pwm_driver = {
.probe = cros_ec_pwm_probe,
- .remove_new = cros_ec_pwm_remove,
.driver = {
.name = "cros-ec-pwm",
.of_match_table = of_match_ptr(cros_ec_pwm_of_match),
--
2.40.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()
2023-09-29 16:19 ` [PATCH 11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe() Uwe Kleine-König
@ 2023-10-02 6:01 ` Tzung-Bi Shih
0 siblings, 0 replies; 20+ messages in thread
From: Tzung-Bi Shih @ 2023-10-02 6:01 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Thierry Reding, Benson Leung, Guenter Roeck, linux-pwm,
chrome-platform, kernel
On Fri, Sep 29, 2023 at 06:19:18PM +0200, Uwe Kleine-König wrote:
> Using devm_pwmchip_add() allows to drop pwmchip_remove() from the remove
> function which makes this function empty. Then there is no user of
> drvdata left and platform_set_drvdata() can be dropped, too.
>
> Further simplify and improve error returning using dev_err_probe().
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 05/11] pwm: mtk-disp: Simplify using devm_pwmchip_add()
2023-09-29 16:19 ` [PATCH 05/11] pwm: mtk-disp: Simplify using devm_pwmchip_add() Uwe Kleine-König
@ 2023-10-02 10:44 ` AngeloGioacchino Del Regno
0 siblings, 0 replies; 20+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-10-02 10:44 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding
Cc: Matthias Brugger, linux-pwm, kernel, linux-arm-kernel,
linux-mediatek
Il 29/09/23 18:19, Uwe Kleine-König ha scritto:
> With devm_pwmchip_add() pwmchip_remove() can be dropped from the remove
> callback. Then the remove callback is empty and can go away, too. With
> mtk_disp_pwm_remove() the last user of platform_get_drvdata() is gone and
> so platform_set_drvdata() can be dropped, too.
>
> Also use dev_err_probe() for simplified (and improved) error reporting.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
I actually wanted to do that myself, but I see you came in first. :-)
Looks good to me!
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 00/11] pwm: Some random cleanups
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (10 preceding siblings ...)
2023-09-29 16:19 ` [PATCH 11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe() Uwe Kleine-König
@ 2023-11-13 3:23 ` patchwork-bot+chrome-platform
2023-11-13 3:42 ` patchwork-bot+chrome-platform
12 siblings, 0 replies; 20+ messages in thread
From: patchwork-bot+chrome-platform @ 2023-11-13 3:23 UTC (permalink / raw)
To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig_=3Cu=2Ekleine-koenig=40pengutronix=2Ede=3E?=
Cc: thierry.reding, rjui, sbranden, bcm-kernel-feedback-list,
linux-pwm, linux-arm-kernel, kernel, florian.fainelli,
linux-rpi-kernel, shawnguo, s.hauer, festevam, linux-imx,
matthias.bgg, angelogioacchino.delregno, linux-mediatek,
orsonzhai, baolin.wang, zhang.lyra, krzysztof.kozlowski,
alim.akhtar, linux-samsung-soc, bleung, groeck, chrome-platform
Hello:
This patch was applied to chrome-platform/linux.git (for-kernelci)
by Thierry Reding <thierry.reding@gmail.com>:
On Fri, 29 Sep 2023 18:19:07 +0200 you wrote:
> Hello,
>
> this is a set of patches I based my efforts for closing a race condition
> in the pwm core on. I thought I already sent them out, but it seems I
> didn't. So here they come!
>
> Best regards
> Uwe
>
> [...]
Here is the summary with links:
- [11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()
https://git.kernel.org/chrome-platform/c/896c450960f5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 00/11] pwm: Some random cleanups
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
` (11 preceding siblings ...)
2023-11-13 3:23 ` [PATCH 00/11] pwm: Some random cleanups patchwork-bot+chrome-platform
@ 2023-11-13 3:42 ` patchwork-bot+chrome-platform
12 siblings, 0 replies; 20+ messages in thread
From: patchwork-bot+chrome-platform @ 2023-11-13 3:42 UTC (permalink / raw)
To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig_=3Cu=2Ekleine-koenig=40pengutronix=2Ede=3E?=
Cc: thierry.reding, rjui, sbranden, bcm-kernel-feedback-list,
linux-pwm, linux-arm-kernel, kernel, florian.fainelli,
linux-rpi-kernel, shawnguo, s.hauer, festevam, linux-imx,
matthias.bgg, angelogioacchino.delregno, linux-mediatek,
orsonzhai, baolin.wang, zhang.lyra, krzysztof.kozlowski,
alim.akhtar, linux-samsung-soc, bleung, groeck, chrome-platform
Hello:
This patch was applied to chrome-platform/linux.git (for-next)
by Thierry Reding <thierry.reding@gmail.com>:
On Fri, 29 Sep 2023 18:19:07 +0200 you wrote:
> Hello,
>
> this is a set of patches I based my efforts for closing a race condition
> in the pwm core on. I thought I already sent them out, but it seems I
> didn't. So here they come!
>
> Best regards
> Uwe
>
> [...]
Here is the summary with links:
- [11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()
https://git.kernel.org/chrome-platform/c/896c450960f5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions
2023-09-29 16:19 ` [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions Uwe Kleine-König
@ 2023-11-13 4:11 ` Florian Fainelli
2023-11-13 8:35 ` Uwe Kleine-König
0 siblings, 1 reply; 20+ messages in thread
From: Florian Fainelli @ 2023-11-13 4:11 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding
Cc: Ray Jui, Scott Branden, Broadcom internal kernel review list,
linux-pwm, linux-arm-kernel, kernel
On 9/29/2023 9:19 AM, Uwe Kleine-König wrote:
> With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
> dropped from the error path and the remove callback. With
> devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
> callback is empty and can go away, too.
>
> Also use dev_err_probe() for simplified (and improved) error reporting.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 02/11] pwm: bcm2835: Simplify using devm functions
2023-09-29 16:19 ` [PATCH 02/11] pwm: bcm2835: " Uwe Kleine-König
@ 2023-11-13 4:21 ` Florian Fainelli
0 siblings, 0 replies; 20+ messages in thread
From: Florian Fainelli @ 2023-11-13 4:21 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding
Cc: Broadcom internal kernel review list, Ray Jui, Scott Branden,
linux-pwm, linux-rpi-kernel, linux-arm-kernel, kernel
[-- Attachment #1: Type: text/plain, Size: 769 bytes --]
On 9/29/2023 9:19 AM, Uwe Kleine-König wrote:
> With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
> dropped from the error path and the remove callback. With
> devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
> callback is empty and can go away, too. With bcm2835_pwm_remove() the only
> user of platform_get_drvdata() is gone and so platform_set_drvdata() can
> be dropped from .probe(), too.
I don't think you can remove the call to platform_set_drvdata() because
that is implicitly used by bcm2835_pwm_{suspend,resume} and their calls
to dev_get_drvdata() as of:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/pwm/pwm-bcm2835.c?id=119a508c4dc956c859854f40a504c577598b68a8
--
Florian
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 03/11] pwm: brcmstb: Simplify using devm functions
2023-09-29 16:19 ` [PATCH 03/11] pwm: brcmstb: " Uwe Kleine-König
@ 2023-11-13 4:22 ` Florian Fainelli
0 siblings, 0 replies; 20+ messages in thread
From: Florian Fainelli @ 2023-11-13 4:22 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding
Cc: Broadcom internal kernel review list, linux-pwm, linux-arm-kernel,
kernel
[-- Attachment #1: Type: text/plain, Size: 517 bytes --]
On 9/29/2023 9:19 AM, Uwe Kleine-König wrote:
> With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
> dropped from the error path and the remove callback. With
> devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
> callback is empty and can go away, too.
>
> Also use dev_err_probe() for simplified (and improved) error reporting.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions
2023-11-13 4:11 ` Florian Fainelli
@ 2023-11-13 8:35 ` Uwe Kleine-König
0 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2023-11-13 8:35 UTC (permalink / raw)
To: Florian Fainelli
Cc: Thierry Reding, linux-pwm, Scott Branden, Ray Jui,
Broadcom internal kernel review list, kernel, linux-arm-kernel
[-- Attachment #1: Type: text/plain, Size: 1017 bytes --]
Hallo Florian,
On Sun, Nov 12, 2023 at 08:11:15PM -0800, Florian Fainelli wrote:
> On 9/29/2023 9:19 AM, Uwe Kleine-König wrote:
> > With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
> > dropped from the error path and the remove callback. With
> > devm_pwmchip_add() pwmchip_remove() can be dropped. Then the remove
> > callback is empty and can go away, too.
> >
> > Also use dev_err_probe() for simplified (and improved) error reporting.
> >
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>
> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Unfortunately you're too late with your review, this patch is already in
v6.7-rc1 (as b498c14efd4241d79999b9bb943e963eb982450c). Ditto for the
other patches in this thread (with different commit ids obviously :-)
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2023-11-13 8:35 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-29 16:19 [PATCH 00/11] pwm: Some random cleanups Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 01/11] pwm: bcm-iproc: Simplify using devm functions Uwe Kleine-König
2023-11-13 4:11 ` Florian Fainelli
2023-11-13 8:35 ` Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 02/11] pwm: bcm2835: " Uwe Kleine-König
2023-11-13 4:21 ` Florian Fainelli
2023-09-29 16:19 ` [PATCH 03/11] pwm: brcmstb: " Uwe Kleine-König
2023-11-13 4:22 ` Florian Fainelli
2023-09-29 16:19 ` [PATCH 04/11] pwm: imx-tpm: " Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 05/11] pwm: mtk-disp: Simplify using devm_pwmchip_add() Uwe Kleine-König
2023-10-02 10:44 ` AngeloGioacchino Del Regno
2023-09-29 16:19 ` [PATCH 06/11] pwm: spear: Simplify using devm functions Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 07/11] pwm: sprd: Provide a helper to cast a chip to driver data Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 08/11] pwm: sprd: Simplify using devm_pwmchip_add() and dev_err_probe() Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 09/11] pwm: vt8500: Simplify using devm functions Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 10/11] pwm: samsung: Consistently use the same name for driver data Uwe Kleine-König
2023-09-29 16:19 ` [PATCH 11/11] pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe() Uwe Kleine-König
2023-10-02 6:01 ` Tzung-Bi Shih
2023-11-13 3:23 ` [PATCH 00/11] pwm: Some random cleanups patchwork-bot+chrome-platform
2023-11-13 3:42 ` patchwork-bot+chrome-platform
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox