Skip to content

Commit 2c06a21

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: twl-led: Drop driver local locking
The pwm core already serializes .apply(). twl6030's .request() and .free() are also already serialized against .apply() because there is only a single PWM. So the mutex doesn't add any additional protection and can be dropped. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/c1c7f646190f7cb2fe43b10959aa8dade80cb79e.1750788649.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent dce0df8 commit 2c06a21

File tree

1 file changed

+7
-42
lines changed

1 file changed

+7
-42
lines changed

drivers/pwm/pwm-twl-led.c

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@
6161
#define TWL6040_LED_MODE_OFF 0x02
6262
#define TWL6040_LED_MODE_MASK 0x03
6363

64-
struct twl_pwmled_chip {
65-
struct mutex mutex;
66-
};
67-
6864
static inline struct twl_pwmled_chip *to_twl(struct pwm_chip *chip)
6965
{
7066
return pwmchip_get_drvdata(chip);
@@ -106,15 +102,13 @@ static int twl4030_pwmled_config(struct pwm_chip *chip, struct pwm_device *pwm,
106102

107103
static int twl4030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm)
108104
{
109-
struct twl_pwmled_chip *twl = to_twl(chip);
110105
int ret;
111106
u8 val;
112107

113-
mutex_lock(&twl->mutex);
114108
ret = twl_i2c_read_u8(TWL4030_MODULE_LED, &val, TWL4030_LEDEN_REG);
115109
if (ret < 0) {
116110
dev_err(pwmchip_parent(chip), "%s: Failed to read LEDEN\n", pwm->label);
117-
goto out;
111+
return ret;
118112
}
119113

120114
val |= TWL4030_LED_TOGGLE(pwm->hwpwm, TWL4030_LED_PINS);
@@ -123,33 +117,26 @@ static int twl4030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm)
123117
if (ret < 0)
124118
dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label);
125119

126-
out:
127-
mutex_unlock(&twl->mutex);
128120
return ret;
129121
}
130122

131123
static void twl4030_pwmled_disable(struct pwm_chip *chip,
132124
struct pwm_device *pwm)
133125
{
134-
struct twl_pwmled_chip *twl = to_twl(chip);
135126
int ret;
136127
u8 val;
137128

138-
mutex_lock(&twl->mutex);
139129
ret = twl_i2c_read_u8(TWL4030_MODULE_LED, &val, TWL4030_LEDEN_REG);
140130
if (ret < 0) {
141131
dev_err(pwmchip_parent(chip), "%s: Failed to read LEDEN\n", pwm->label);
142-
goto out;
132+
return;
143133
}
144134

145135
val &= ~TWL4030_LED_TOGGLE(pwm->hwpwm, TWL4030_LED_PINS);
146136

147137
ret = twl_i2c_write_u8(TWL4030_MODULE_LED, val, TWL4030_LEDEN_REG);
148138
if (ret < 0)
149139
dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label);
150-
151-
out:
152-
mutex_unlock(&twl->mutex);
153140
}
154141

155142
static int twl4030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -209,16 +196,14 @@ static int twl6030_pwmled_config(struct pwm_chip *chip, struct pwm_device *pwm,
209196

210197
static int twl6030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm)
211198
{
212-
struct twl_pwmled_chip *twl = to_twl(chip);
213199
int ret;
214200
u8 val;
215201

216-
mutex_lock(&twl->mutex);
217202
ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, TWL6030_LED_PWM_CTRL2);
218203
if (ret < 0) {
219204
dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n",
220205
pwm->label);
221-
goto out;
206+
return ret;
222207
}
223208

224209
val &= ~TWL6040_LED_MODE_MASK;
@@ -228,24 +213,20 @@ static int twl6030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm)
228213
if (ret < 0)
229214
dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label);
230215

231-
out:
232-
mutex_unlock(&twl->mutex);
233216
return ret;
234217
}
235218

236219
static void twl6030_pwmled_disable(struct pwm_chip *chip,
237220
struct pwm_device *pwm)
238221
{
239-
struct twl_pwmled_chip *twl = to_twl(chip);
240222
int ret;
241223
u8 val;
242224

243-
mutex_lock(&twl->mutex);
244225
ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, TWL6030_LED_PWM_CTRL2);
245226
if (ret < 0) {
246227
dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n",
247228
pwm->label);
248-
goto out;
229+
return;
249230
}
250231

251232
val &= ~TWL6040_LED_MODE_MASK;
@@ -254,9 +235,6 @@ static void twl6030_pwmled_disable(struct pwm_chip *chip,
254235
ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_LED_PWM_CTRL2);
255236
if (ret < 0)
256237
dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label);
257-
258-
out:
259-
mutex_unlock(&twl->mutex);
260238
}
261239

262240
static int twl6030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -287,16 +265,14 @@ static int twl6030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm,
287265

288266
static int twl6030_pwmled_request(struct pwm_chip *chip, struct pwm_device *pwm)
289267
{
290-
struct twl_pwmled_chip *twl = to_twl(chip);
291268
int ret;
292269
u8 val;
293270

294-
mutex_lock(&twl->mutex);
295271
ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, TWL6030_LED_PWM_CTRL2);
296272
if (ret < 0) {
297273
dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n",
298274
pwm->label);
299-
goto out;
275+
return ret;
300276
}
301277

302278
val &= ~TWL6040_LED_MODE_MASK;
@@ -306,23 +282,19 @@ static int twl6030_pwmled_request(struct pwm_chip *chip, struct pwm_device *pwm)
306282
if (ret < 0)
307283
dev_err(pwmchip_parent(chip), "%s: Failed to request PWM\n", pwm->label);
308284

309-
out:
310-
mutex_unlock(&twl->mutex);
311285
return ret;
312286
}
313287

314288
static void twl6030_pwmled_free(struct pwm_chip *chip, struct pwm_device *pwm)
315289
{
316-
struct twl_pwmled_chip *twl = to_twl(chip);
317290
int ret;
318291
u8 val;
319292

320-
mutex_lock(&twl->mutex);
321293
ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, TWL6030_LED_PWM_CTRL2);
322294
if (ret < 0) {
323295
dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n",
324296
pwm->label);
325-
goto out;
297+
return;
326298
}
327299

328300
val &= ~TWL6040_LED_MODE_MASK;
@@ -331,9 +303,6 @@ static void twl6030_pwmled_free(struct pwm_chip *chip, struct pwm_device *pwm)
331303
ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_LED_PWM_CTRL2);
332304
if (ret < 0)
333305
dev_err(pwmchip_parent(chip), "%s: Failed to free PWM\n", pwm->label);
334-
335-
out:
336-
mutex_unlock(&twl->mutex);
337306
}
338307

339308
static const struct pwm_ops twl6030_pwmled_ops = {
@@ -345,7 +314,6 @@ static const struct pwm_ops twl6030_pwmled_ops = {
345314
static int twl_pwmled_probe(struct platform_device *pdev)
346315
{
347316
struct pwm_chip *chip;
348-
struct twl_pwmled_chip *twl;
349317
unsigned int npwm;
350318
const struct pwm_ops *ops;
351319

@@ -357,15 +325,12 @@ static int twl_pwmled_probe(struct platform_device *pdev)
357325
npwm = 1;
358326
}
359327

360-
chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*twl));
328+
chip = devm_pwmchip_alloc(&pdev->dev, npwm, 0);
361329
if (IS_ERR(chip))
362330
return PTR_ERR(chip);
363-
twl = to_twl(chip);
364331

365332
chip->ops = ops;
366333

367-
mutex_init(&twl->mutex);
368-
369334
return devm_pwmchip_add(&pdev->dev, chip);
370335
}
371336

0 commit comments

Comments
 (0)