linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] pwm: Drop local locking in several drivers
@ 2025-06-24 18:15 Uwe Kleine-König
  2025-06-24 18:15 ` [PATCH 1/8] pwm: atmel: Drop driver local locking Uwe Kleine-König
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2025-06-24 18:15 UTC (permalink / raw)
  To: linux-pwm
  Cc: Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	linux-arm-kernel, Vladimir Zapolskiy, Conor Dooley,
	Daire McNamara, linux-riscv, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-sunxi

Hello,

some time ago the pwm core implemented additional locking to protect
lowlevel driver callbacks against driver removal. A side effect is that
.apply() and .get_state() are serialized. This allows to drop some
locking that is now superfluous due to the core's locking.

I identified a few drivers that are affected; these are cleaned up
accordingly here.

Best regards
Uwe

Uwe Kleine-König (8):
  pwm: atmel: Drop driver local locking
  pwm: clps711x: Drop driver local locking
  pwm: fsl-ftm: Drop driver local locking
  pwm: lpc18xx-sct: Drop driver local locking
  pwm: microchip-core: Drop driver local locking
  pwm: sti: Drop driver local locking
  pwm: sun4i: Drop driver local locking
  pwm: twl-led: Drop driver local locking

 drivers/pwm/pwm-atmel.c          | 12 --------
 drivers/pwm/pwm-clps711x.c       |  8 ------
 drivers/pwm/pwm-fsl-ftm.c        | 28 +++++-------------
 drivers/pwm/pwm-lpc18xx-sct.c    | 14 ---------
 drivers/pwm/pwm-microchip-core.c | 17 +----------
 drivers/pwm/pwm-sti.c            | 23 ++++-----------
 drivers/pwm/pwm-sun4i.c          | 10 -------
 drivers/pwm/pwm-twl-led.c        | 49 +++++---------------------------
 8 files changed, 21 insertions(+), 140 deletions(-)

base-commit: f817b6dd2b62d921a6cdc0a3ac599cd1851f343c
-- 
2.49.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/8] pwm: atmel: Drop driver local locking
  2025-06-24 18:15 [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
@ 2025-06-24 18:15 ` Uwe Kleine-König
  2025-06-24 18:15 ` [PATCH 4/8] pwm: lpc18xx-sct: " Uwe Kleine-König
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2025-06-24 18:15 UTC (permalink / raw)
  To: linux-pwm
  Cc: Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	linux-arm-kernel

The two functions making use of the lock are only called transitively from
.apply(). Calls to .apply() are already serialized by the pwm core so the
lock in the driver has no effect and can safely be dropped.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 drivers/pwm/pwm-atmel.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index b2f0abbbad63..06d22d0f7b26 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -91,9 +91,6 @@ struct atmel_pwm_chip {
 	 * hardware.
 	 */
 	u32 update_pending;
-
-	/* Protects .update_pending */
-	spinlock_t lock;
 };
 
 static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
@@ -145,8 +142,6 @@ static void atmel_pwm_update_pending(struct atmel_pwm_chip *chip)
 
 static void atmel_pwm_set_pending(struct atmel_pwm_chip *chip, unsigned int ch)
 {
-	spin_lock(&chip->lock);
-
 	/*
 	 * Clear pending flags in hardware because otherwise there might still
 	 * be a stale flag in ISR.
@@ -154,16 +149,12 @@ static void atmel_pwm_set_pending(struct atmel_pwm_chip *chip, unsigned int ch)
 	atmel_pwm_update_pending(chip);
 
 	chip->update_pending |= (1 << ch);
-
-	spin_unlock(&chip->lock);
 }
 
 static int atmel_pwm_test_pending(struct atmel_pwm_chip *chip, unsigned int ch)
 {
 	int ret = 0;
 
-	spin_lock(&chip->lock);
-
 	if (chip->update_pending & (1 << ch)) {
 		atmel_pwm_update_pending(chip);
 
@@ -171,8 +162,6 @@ static int atmel_pwm_test_pending(struct atmel_pwm_chip *chip, unsigned int ch)
 			ret = 1;
 	}
 
-	spin_unlock(&chip->lock);
-
 	return ret;
 }
 
@@ -509,7 +498,6 @@ static int atmel_pwm_probe(struct platform_device *pdev)
 	atmel_pwm->data = of_device_get_match_data(&pdev->dev);
 
 	atmel_pwm->update_pending = 0;
-	spin_lock_init(&atmel_pwm->lock);
 
 	atmel_pwm->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(atmel_pwm->base))
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/8] pwm: lpc18xx-sct: Drop driver local locking
  2025-06-24 18:15 [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
  2025-06-24 18:15 ` [PATCH 1/8] pwm: atmel: Drop driver local locking Uwe Kleine-König
@ 2025-06-24 18:15 ` Uwe Kleine-König
  2025-06-24 18:22   ` Vladimir Zapolskiy
  2025-06-24 18:15 ` [PATCH 7/8] pwm: sun4i: " Uwe Kleine-König
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2025-06-24 18:15 UTC (permalink / raw)
  To: linux-pwm; +Cc: Vladimir Zapolskiy, linux-arm-kernel

Both mutexes are only used in one function each. These functions are only
called by the .apply() callback. As the .apply() calls are serialized by
the core since commit 1cc2e1faafb3 ("pwm: Add more locking") the mutexes
have no effect apart from runtime overhead. Drop them.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 drivers/pwm/pwm-lpc18xx-sct.c | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/drivers/pwm/pwm-lpc18xx-sct.c b/drivers/pwm/pwm-lpc18xx-sct.c
index f351baa63453..1e614b2a0227 100644
--- a/drivers/pwm/pwm-lpc18xx-sct.c
+++ b/drivers/pwm/pwm-lpc18xx-sct.c
@@ -100,8 +100,6 @@ struct lpc18xx_pwm_chip {
 	u64 max_period_ns;
 	unsigned int period_event;
 	unsigned long event_map;
-	struct mutex res_lock;
-	struct mutex period_lock;
 	struct lpc18xx_pwm_data channeldata[LPC18XX_NUM_PWMS];
 };
 
@@ -129,8 +127,6 @@ static void lpc18xx_pwm_set_conflict_res(struct lpc18xx_pwm_chip *lpc18xx_pwm,
 {
 	u32 val;
 
-	mutex_lock(&lpc18xx_pwm->res_lock);
-
 	/*
 	 * Simultaneous set and clear may happen on an output, that is the case
 	 * when duty_ns == period_ns. LPC18xx SCT allows to set a conflict
@@ -140,8 +136,6 @@ static void lpc18xx_pwm_set_conflict_res(struct lpc18xx_pwm_chip *lpc18xx_pwm,
 	val &= ~LPC18XX_PWM_RES_MASK(pwm->hwpwm);
 	val |= LPC18XX_PWM_RES(pwm->hwpwm, action);
 	lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_RES_BASE, val);
-
-	mutex_unlock(&lpc18xx_pwm->res_lock);
 }
 
 static void lpc18xx_pwm_config_period(struct pwm_chip *chip, u64 period_ns)
@@ -200,8 +194,6 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 		return -ERANGE;
 	}
 
-	mutex_lock(&lpc18xx_pwm->period_lock);
-
 	requested_events = bitmap_weight(&lpc18xx_pwm->event_map,
 					 LPC18XX_PWM_EVENT_MAX);
 
@@ -214,7 +206,6 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	    lpc18xx_pwm->period_ns) {
 		dev_err(pwmchip_parent(chip), "conflicting period requested for PWM %u\n",
 			pwm->hwpwm);
-		mutex_unlock(&lpc18xx_pwm->period_lock);
 		return -EBUSY;
 	}
 
@@ -224,8 +215,6 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 		lpc18xx_pwm_config_period(chip, period_ns);
 	}
 
-	mutex_unlock(&lpc18xx_pwm->period_lock);
-
 	lpc18xx_pwm_config_duty(chip, pwm, duty_ns);
 
 	return 0;
@@ -377,9 +366,6 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev)
 	if (lpc18xx_pwm->clk_rate > NSEC_PER_SEC)
 		return dev_err_probe(&pdev->dev, -EINVAL, "pwm clock to fast\n");
 
-	mutex_init(&lpc18xx_pwm->res_lock);
-	mutex_init(&lpc18xx_pwm->period_lock);
-
 	lpc18xx_pwm->max_period_ns =
 		mul_u64_u64_div_u64(NSEC_PER_SEC, LPC18XX_PWM_TIMER_MAX, lpc18xx_pwm->clk_rate);
 
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 7/8] pwm: sun4i: Drop driver local locking
  2025-06-24 18:15 [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
  2025-06-24 18:15 ` [PATCH 1/8] pwm: atmel: Drop driver local locking Uwe Kleine-König
  2025-06-24 18:15 ` [PATCH 4/8] pwm: lpc18xx-sct: " Uwe Kleine-König
@ 2025-06-24 18:15 ` Uwe Kleine-König
  2025-07-01  7:57 ` [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
  2025-08-10 21:12 ` patchwork-bot+linux-riscv
  4 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2025-06-24 18:15 UTC (permalink / raw)
  To: linux-pwm
  Cc: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, linux-arm-kernel,
	linux-sunxi

The pwm core serializes calls to .apply(), so the driver lock doesn't
add any protection and can safely be dropped.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 drivers/pwm/pwm-sun4i.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index e60dc7d6b591..6c5591ca868b 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -21,7 +21,6 @@
 #include <linux/pwm.h>
 #include <linux/reset.h>
 #include <linux/slab.h>
-#include <linux/spinlock.h>
 #include <linux/time.h>
 
 #define PWM_CTRL_REG		0x0
@@ -85,7 +84,6 @@ struct sun4i_pwm_chip {
 	struct clk *clk;
 	struct reset_control *rst;
 	void __iomem *base;
-	spinlock_t ctrl_lock;
 	const struct sun4i_pwm_data *data;
 };
 
@@ -258,7 +256,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 		return ret;
 	}
 
-	spin_lock(&sun4ichip->ctrl_lock);
 	ctrl = sun4i_pwm_readl(sun4ichip, PWM_CTRL_REG);
 
 	if (sun4ichip->data->has_direct_mod_clk_output) {
@@ -266,7 +263,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 			ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);
 			/* We can skip other parameter */
 			sun4i_pwm_writel(sun4ichip, ctrl, PWM_CTRL_REG);
-			spin_unlock(&sun4ichip->ctrl_lock);
 			return 0;
 		}
 
@@ -297,8 +293,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 
 	sun4i_pwm_writel(sun4ichip, ctrl, PWM_CTRL_REG);
 
-	spin_unlock(&sun4ichip->ctrl_lock);
-
 	if (state->enabled)
 		return 0;
 
@@ -309,12 +303,10 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 	else
 		usleep_range(delay_us, delay_us * 2);
 
-	spin_lock(&sun4ichip->ctrl_lock);
 	ctrl = sun4i_pwm_readl(sun4ichip, PWM_CTRL_REG);
 	ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm);
 	ctrl &= ~BIT_CH(PWM_EN, pwm->hwpwm);
 	sun4i_pwm_writel(sun4ichip, ctrl, PWM_CTRL_REG);
-	spin_unlock(&sun4ichip->ctrl_lock);
 
 	clk_disable_unprepare(sun4ichip->clk);
 
@@ -456,8 +448,6 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
 
 	chip->ops = &sun4i_pwm_ops;
 
-	spin_lock_init(&sun4ichip->ctrl_lock);
-
 	ret = pwmchip_add(chip);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/8] pwm: lpc18xx-sct: Drop driver local locking
  2025-06-24 18:15 ` [PATCH 4/8] pwm: lpc18xx-sct: " Uwe Kleine-König
@ 2025-06-24 18:22   ` Vladimir Zapolskiy
  0 siblings, 0 replies; 7+ messages in thread
From: Vladimir Zapolskiy @ 2025-06-24 18:22 UTC (permalink / raw)
  To: Uwe Kleine-König, linux-pwm; +Cc: linux-arm-kernel

On 6/24/25 21:15, Uwe Kleine-König wrote:
> Both mutexes are only used in one function each. These functions are only
> called by the .apply() callback. As the .apply() calls are serialized by
> the core since commit 1cc2e1faafb3 ("pwm: Add more locking") the mutexes
> have no effect apart from runtime overhead. Drop them.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>

Reviewed-by: Vladimir Zapolskiy <vz@mleia.com>

Thank you for the change.

-- 
Best wishes,
Vladimir


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/8] pwm: Drop local locking in several drivers
  2025-06-24 18:15 [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
                   ` (2 preceding siblings ...)
  2025-06-24 18:15 ` [PATCH 7/8] pwm: sun4i: " Uwe Kleine-König
@ 2025-07-01  7:57 ` Uwe Kleine-König
  2025-08-10 21:12 ` patchwork-bot+linux-riscv
  4 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2025-07-01  7:57 UTC (permalink / raw)
  To: linux-pwm
  Cc: Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	linux-arm-kernel, Vladimir Zapolskiy, Conor Dooley,
	Daire McNamara, linux-riscv, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-sunxi

[-- Attachment #1: Type: text/plain, Size: 589 bytes --]

Hello,

On Tue, Jun 24, 2025 at 08:15:36PM +0200, Uwe Kleine-König wrote:
> some time ago the pwm core implemented additional locking to protect
> lowlevel driver callbacks against driver removal. A side effect is that
> .apply() and .get_state() are serialized. This allows to drop some
> locking that is now superfluous due to the core's locking.
> 
> I identified a few drivers that are affected; these are cleaned up
> accordingly here.

I applied these patches to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next
now.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/8] pwm: Drop local locking in several drivers
  2025-06-24 18:15 [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
                   ` (3 preceding siblings ...)
  2025-07-01  7:57 ` [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
@ 2025-08-10 21:12 ` patchwork-bot+linux-riscv
  4 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-08-10 21:12 UTC (permalink / raw)
  To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig_=3Cu=2Ekleine-koenig=40baylibre=2Ecom=3E?=
  Cc: linux-riscv, linux-pwm, claudiu.beznea, nicolas.ferre,
	alexandre.belloni, linux-arm-kernel, vz, conor.dooley,
	daire.mcnamara, wens, jernej.skrabec, samuel, linux-sunxi

Hello:

This patch was applied to riscv/linux.git (fixes)
by Uwe Kleine-König <ukleinek@kernel.org>:

On Tue, 24 Jun 2025 20:15:36 +0200 you wrote:
> Hello,
> 
> some time ago the pwm core implemented additional locking to protect
> lowlevel driver callbacks against driver removal. A side effect is that
> .apply() and .get_state() are serialized. This allows to drop some
> locking that is now superfluous due to the core's locking.
> 
> [...]

Here is the summary with links:
  - [5/8] pwm: microchip-core: Drop driver local locking
    https://git.kernel.org/riscv/c/9470e7d11fe2

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] 7+ messages in thread

end of thread, other threads:[~2025-08-10 21:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 18:15 [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
2025-06-24 18:15 ` [PATCH 1/8] pwm: atmel: Drop driver local locking Uwe Kleine-König
2025-06-24 18:15 ` [PATCH 4/8] pwm: lpc18xx-sct: " Uwe Kleine-König
2025-06-24 18:22   ` Vladimir Zapolskiy
2025-06-24 18:15 ` [PATCH 7/8] pwm: sun4i: " Uwe Kleine-König
2025-07-01  7:57 ` [PATCH 0/8] pwm: Drop local locking in several drivers Uwe Kleine-König
2025-08-10 21:12 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).