Skip to content

Commit 9bc1789

Browse files
scuciureanjic23
authored andcommitted
iio: dac: ad5421: Replace indio_dev->mlock with own device lock
As part of the general cleanup of indio_dev->mlock, this change replaces it with a local lock on the device's state structure. Signed-off-by: Sergiu Cuciurean <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent fa444a1 commit 9bc1789

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

drivers/iio/dac/ad5421.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@
6262
* @current_range: current range which the device is configured for
6363
* @data: spi transfer buffers
6464
* @fault_mask: software masking of events
65+
* @lock lock to protect the data buffer during SPI ops
6566
*/
6667
struct ad5421_state {
6768
struct spi_device *spi;
6869
unsigned int ctrl;
6970
enum ad5421_current_range current_range;
7071
unsigned int fault_mask;
72+
struct mutex lock;
7173

7274
/*
7375
* DMA (thus cache coherency maintenance) requires the
@@ -142,11 +144,12 @@ static int ad5421_write_unlocked(struct iio_dev *indio_dev,
142144
static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
143145
unsigned int val)
144146
{
147+
struct ad5421_state *st = iio_priv(indio_dev);
145148
int ret;
146149

147-
mutex_lock(&indio_dev->mlock);
150+
mutex_lock(&st->lock);
148151
ret = ad5421_write_unlocked(indio_dev, reg, val);
149-
mutex_unlock(&indio_dev->mlock);
152+
mutex_unlock(&st->lock);
150153

151154
return ret;
152155
}
@@ -166,15 +169,15 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
166169
},
167170
};
168171

169-
mutex_lock(&indio_dev->mlock);
172+
mutex_lock(&st->lock);
170173

171174
st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
172175

173176
ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
174177
if (ret >= 0)
175178
ret = be32_to_cpu(st->data[1].d32) & 0xffff;
176179

177-
mutex_unlock(&indio_dev->mlock);
180+
mutex_unlock(&st->lock);
178181

179182
return ret;
180183
}
@@ -185,14 +188,14 @@ static int ad5421_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
185188
struct ad5421_state *st = iio_priv(indio_dev);
186189
unsigned int ret;
187190

188-
mutex_lock(&indio_dev->mlock);
191+
mutex_lock(&st->lock);
189192

190193
st->ctrl &= ~clr;
191194
st->ctrl |= set;
192195

193196
ret = ad5421_write_unlocked(indio_dev, AD5421_REG_CTRL, st->ctrl);
194197

195-
mutex_unlock(&indio_dev->mlock);
198+
mutex_unlock(&st->lock);
196199

197200
return ret;
198201
}
@@ -400,12 +403,12 @@ static int ad5421_write_event_config(struct iio_dev *indio_dev,
400403
return -EINVAL;
401404
}
402405

403-
mutex_lock(&indio_dev->mlock);
406+
mutex_lock(&st->lock);
404407
if (state)
405408
st->fault_mask |= mask;
406409
else
407410
st->fault_mask &= ~mask;
408-
mutex_unlock(&indio_dev->mlock);
411+
mutex_unlock(&st->lock);
409412

410413
return 0;
411414
}
@@ -491,6 +494,8 @@ static int ad5421_probe(struct spi_device *spi)
491494
indio_dev->channels = ad5421_channels;
492495
indio_dev->num_channels = ARRAY_SIZE(ad5421_channels);
493496

497+
mutex_init(&st->lock);
498+
494499
st->ctrl = AD5421_CTRL_WATCHDOG_DISABLE |
495500
AD5421_CTRL_AUTO_FAULT_READBACK;
496501

0 commit comments

Comments
 (0)