hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/mfd/ezx-pcap.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for Motorola PCAP2 as present in EZX phones
34 *
45 * Copyright (C) 2006 Harald Welte <laforge@openezx.org>
56 * Copyright (C) 2009 Daniel Ribeiro <drwyrm@gmail.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
10
- *
117 */
128
139 #include <linux/module.h>
....@@ -39,7 +35,7 @@
3935
4036 /* IO */
4137 u32 buf;
42
- struct mutex io_mutex;
38
+ spinlock_t io_lock;
4339
4440 /* IRQ */
4541 unsigned int irq_base;
....@@ -52,7 +48,7 @@
5248 struct pcap_adc_request *adc_queue[PCAP_ADC_MAXQ];
5349 u8 adc_head;
5450 u8 adc_tail;
55
- struct mutex adc_mutex;
51
+ spinlock_t adc_lock;
5652 };
5753
5854 /* IO */
....@@ -80,14 +76,15 @@
8076
8177 int ezx_pcap_write(struct pcap_chip *pcap, u8 reg_num, u32 value)
8278 {
79
+ unsigned long flags;
8380 int ret;
8481
85
- mutex_lock(&pcap->io_mutex);
82
+ spin_lock_irqsave(&pcap->io_lock, flags);
8683 value &= PCAP_REGISTER_VALUE_MASK;
8784 value |= PCAP_REGISTER_WRITE_OP_BIT
8885 | (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
8986 ret = ezx_pcap_putget(pcap, &value);
90
- mutex_unlock(&pcap->io_mutex);
87
+ spin_unlock_irqrestore(&pcap->io_lock, flags);
9188
9289 return ret;
9390 }
....@@ -95,14 +92,15 @@
9592
9693 int ezx_pcap_read(struct pcap_chip *pcap, u8 reg_num, u32 *value)
9794 {
95
+ unsigned long flags;
9896 int ret;
9997
100
- mutex_lock(&pcap->io_mutex);
98
+ spin_lock_irqsave(&pcap->io_lock, flags);
10199 *value = PCAP_REGISTER_READ_OP_BIT
102100 | (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
103101
104102 ret = ezx_pcap_putget(pcap, value);
105
- mutex_unlock(&pcap->io_mutex);
103
+ spin_unlock_irqrestore(&pcap->io_lock, flags);
106104
107105 return ret;
108106 }
....@@ -110,11 +108,12 @@
110108
111109 int ezx_pcap_set_bits(struct pcap_chip *pcap, u8 reg_num, u32 mask, u32 val)
112110 {
111
+ unsigned long flags;
113112 int ret;
114113 u32 tmp = PCAP_REGISTER_READ_OP_BIT |
115114 (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
116115
117
- mutex_lock(&pcap->io_mutex);
116
+ spin_lock_irqsave(&pcap->io_lock, flags);
118117 ret = ezx_pcap_putget(pcap, &tmp);
119118 if (ret)
120119 goto out_unlock;
....@@ -125,7 +124,7 @@
125124
126125 ret = ezx_pcap_putget(pcap, &tmp);
127126 out_unlock:
128
- mutex_unlock(&pcap->io_mutex);
127
+ spin_unlock_irqrestore(&pcap->io_lock, flags);
129128
130129 return ret;
131130 }
....@@ -216,14 +215,15 @@
216215 /* ADC */
217216 void pcap_set_ts_bits(struct pcap_chip *pcap, u32 bits)
218217 {
218
+ unsigned long flags;
219219 u32 tmp;
220220
221
- mutex_lock(&pcap->adc_mutex);
221
+ spin_lock_irqsave(&pcap->adc_lock, flags);
222222 ezx_pcap_read(pcap, PCAP_REG_ADC, &tmp);
223223 tmp &= ~(PCAP_ADC_TS_M_MASK | PCAP_ADC_TS_REF_LOWPWR);
224224 tmp |= bits & (PCAP_ADC_TS_M_MASK | PCAP_ADC_TS_REF_LOWPWR);
225225 ezx_pcap_write(pcap, PCAP_REG_ADC, tmp);
226
- mutex_unlock(&pcap->adc_mutex);
226
+ spin_unlock_irqrestore(&pcap->adc_lock, flags);
227227 }
228228 EXPORT_SYMBOL_GPL(pcap_set_ts_bits);
229229
....@@ -238,15 +238,16 @@
238238
239239 static void pcap_adc_trigger(struct pcap_chip *pcap)
240240 {
241
+ unsigned long flags;
241242 u32 tmp;
242243 u8 head;
243244
244
- mutex_lock(&pcap->adc_mutex);
245
+ spin_lock_irqsave(&pcap->adc_lock, flags);
245246 head = pcap->adc_head;
246247 if (!pcap->adc_queue[head]) {
247248 /* queue is empty, save power */
248249 pcap_disable_adc(pcap);
249
- mutex_unlock(&pcap->adc_mutex);
250
+ spin_unlock_irqrestore(&pcap->adc_lock, flags);
250251 return;
251252 }
252253 /* start conversion on requested bank, save TS_M bits */
....@@ -258,7 +259,7 @@
258259 tmp |= PCAP_ADC_AD_SEL1;
259260
260261 ezx_pcap_write(pcap, PCAP_REG_ADC, tmp);
261
- mutex_unlock(&pcap->adc_mutex);
262
+ spin_unlock_irqrestore(&pcap->adc_lock, flags);
262263 ezx_pcap_write(pcap, PCAP_REG_ADR, PCAP_ADR_ASC);
263264 }
264265
....@@ -269,11 +270,11 @@
269270 u16 res[2];
270271 u32 tmp;
271272
272
- mutex_lock(&pcap->adc_mutex);
273
+ spin_lock(&pcap->adc_lock);
273274 req = pcap->adc_queue[pcap->adc_head];
274275
275276 if (WARN(!req, "adc irq without pending request\n")) {
276
- mutex_unlock(&pcap->adc_mutex);
277
+ spin_unlock(&pcap->adc_lock);
277278 return IRQ_HANDLED;
278279 }
279280
....@@ -289,7 +290,7 @@
289290
290291 pcap->adc_queue[pcap->adc_head] = NULL;
291292 pcap->adc_head = (pcap->adc_head + 1) & (PCAP_ADC_MAXQ - 1);
292
- mutex_unlock(&pcap->adc_mutex);
293
+ spin_unlock(&pcap->adc_lock);
293294
294295 /* pass the results and release memory */
295296 req->callback(req->data, res);
....@@ -305,6 +306,7 @@
305306 void *callback, void *data)
306307 {
307308 struct pcap_adc_request *req;
309
+ unsigned long irq_flags;
308310
309311 /* This will be freed after we have a result */
310312 req = kmalloc(sizeof(struct pcap_adc_request), GFP_KERNEL);
....@@ -318,15 +320,15 @@
318320 req->callback = callback;
319321 req->data = data;
320322
321
- mutex_lock(&pcap->adc_mutex);
323
+ spin_lock_irqsave(&pcap->adc_lock, irq_flags);
322324 if (pcap->adc_queue[pcap->adc_tail]) {
323
- mutex_unlock(&pcap->adc_mutex);
325
+ spin_unlock_irqrestore(&pcap->adc_lock, irq_flags);
324326 kfree(req);
325327 return -EBUSY;
326328 }
327329 pcap->adc_queue[pcap->adc_tail] = req;
328330 pcap->adc_tail = (pcap->adc_tail + 1) & (PCAP_ADC_MAXQ - 1);
329
- mutex_unlock(&pcap->adc_mutex);
331
+ spin_unlock_irqrestore(&pcap->adc_lock, irq_flags);
330332
331333 /* start conversion */
332334 pcap_adc_trigger(pcap);
....@@ -393,16 +395,17 @@
393395 static int ezx_pcap_remove(struct spi_device *spi)
394396 {
395397 struct pcap_chip *pcap = spi_get_drvdata(spi);
398
+ unsigned long flags;
396399 int i;
397400
398401 /* remove all registered subdevs */
399402 device_for_each_child(&spi->dev, NULL, pcap_remove_subdev);
400403
401404 /* cleanup ADC */
402
- mutex_lock(&pcap->adc_mutex);
405
+ spin_lock_irqsave(&pcap->adc_lock, flags);
403406 for (i = 0; i < PCAP_ADC_MAXQ; i++)
404407 kfree(pcap->adc_queue[i]);
405
- mutex_unlock(&pcap->adc_mutex);
408
+ spin_unlock_irqrestore(&pcap->adc_lock, flags);
406409
407410 /* cleanup irqchip */
408411 for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++)
....@@ -430,8 +433,8 @@
430433 goto ret;
431434 }
432435
433
- mutex_init(&pcap->io_mutex);
434
- mutex_init(&pcap->adc_mutex);
436
+ spin_lock_init(&pcap->io_lock);
437
+ spin_lock_init(&pcap->adc_lock);
435438 INIT_WORK(&pcap->isr_work, pcap_isr_work);
436439 INIT_WORK(&pcap->msr_work, pcap_msr_work);
437440 spi_set_drvdata(spi, pcap);