]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pwm: fsl-ftm: Drop driver local locking
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Tue, 24 Jun 2025 18:15:39 +0000 (20:15 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Mon, 7 Jul 2025 06:39:36 +0000 (08:39 +0200)
The pwm core serializes calls to .apply(), so the driver local lock isn't
needed for that. It only has the effect to serialize .apply() with
.request() and .free() for a different PWM, and .request() and .free
against each other. But given that .request and .free() only do a single
regmap operation under the lock and regmap itself serializes register
accesses, it might happen without the lock that the calls are interleaved
now, but affecting different PWMs, so nothing bad can happen.

So the mutex has no effect and can be dropped.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/6b72104e5e1823170c7c9664189cc0f2ca5c2347.1750788649.git.u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-fsl-ftm.c

index c45a5fca4cbbd296e49fcf13c46920423063a11a..6683931872fc745b4844af57530fed3f563e0df9 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/mutex.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
@@ -40,7 +39,6 @@ struct fsl_pwm_periodcfg {
 };
 
 struct fsl_pwm_chip {
-       struct mutex lock;
        struct regmap *regmap;
 
        /* This value is valid iff a pwm is running */
@@ -89,11 +87,8 @@ static int fsl_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
        struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
 
        ret = clk_prepare_enable(fpc->ipg_clk);
-       if (!ret && fpc->soc->has_enable_bits) {
-               mutex_lock(&fpc->lock);
+       if (!ret && fpc->soc->has_enable_bits)
                regmap_set_bits(fpc->regmap, FTM_SC, BIT(pwm->hwpwm + 16));
-               mutex_unlock(&fpc->lock);
-       }
 
        return ret;
 }
@@ -102,11 +97,8 @@ static void fsl_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 {
        struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
 
-       if (fpc->soc->has_enable_bits) {
-               mutex_lock(&fpc->lock);
+       if (fpc->soc->has_enable_bits)
                regmap_clear_bits(fpc->regmap, FTM_SC, BIT(pwm->hwpwm + 16));
-               mutex_unlock(&fpc->lock);
-       }
 
        clk_disable_unprepare(fpc->ipg_clk);
 }
@@ -304,7 +296,7 @@ static int fsl_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 {
        struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
        struct pwm_state *oldstate = &pwm->state;
-       int ret = 0;
+       int ret;
 
        /*
         * oldstate to newstate : action
@@ -315,8 +307,6 @@ static int fsl_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
         * disabled to enabled : update settings + enable
         */
 
-       mutex_lock(&fpc->lock);
-
        if (!newstate->enabled) {
                if (oldstate->enabled) {
                        regmap_set_bits(fpc->regmap, FTM_OUTMASK,
@@ -325,30 +315,28 @@ static int fsl_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
                        clk_disable_unprepare(fpc->clk[fpc->period.clk_select]);
                }
 
-               goto end_mutex;
+               return 0;
        }
 
        ret = fsl_pwm_apply_config(chip, pwm, newstate);
        if (ret)
-               goto end_mutex;
+               return ret;
 
        /* check if need to enable */
        if (!oldstate->enabled) {
                ret = clk_prepare_enable(fpc->clk[fpc->period.clk_select]);
                if (ret)
-                       goto end_mutex;
+                       return ret;
 
                ret = clk_prepare_enable(fpc->clk[FSL_PWM_CLK_CNTEN]);
                if (ret) {
                        clk_disable_unprepare(fpc->clk[fpc->period.clk_select]);
-                       goto end_mutex;
+                       return ret;
                }
 
                regmap_clear_bits(fpc->regmap, FTM_OUTMASK, BIT(pwm->hwpwm));
        }
 
-end_mutex:
-       mutex_unlock(&fpc->lock);
        return ret;
 }
 
@@ -408,8 +396,6 @@ static int fsl_pwm_probe(struct platform_device *pdev)
                return PTR_ERR(chip);
        fpc = to_fsl_chip(chip);
 
-       mutex_init(&fpc->lock);
-
        fpc->soc = of_device_get_match_data(&pdev->dev);
 
        base = devm_platform_ioremap_resource(pdev, 0);