Skip to content

Commit 33c53cb

Browse files
scuciureanjic23
authored andcommitted
iio: dac: ad5592r-base: 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. This also removes unused iio_dev pointers. Signed-off-by: Sergiu Cuciurean <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent ac101e6 commit 33c53cb

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

drivers/iio/dac/ad5592r-base.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ static void ad5592r_gpio_cleanup(struct ad5592r_state *st)
156156
static int ad5592r_reset(struct ad5592r_state *st)
157157
{
158158
struct gpio_desc *gpio;
159-
struct iio_dev *iio_dev = iio_priv_to_dev(st);
160159

161160
gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_LOW);
162161
if (IS_ERR(gpio))
@@ -166,10 +165,10 @@ static int ad5592r_reset(struct ad5592r_state *st)
166165
udelay(1);
167166
gpiod_set_value(gpio, 1);
168167
} else {
169-
mutex_lock(&iio_dev->mlock);
168+
mutex_lock(&st->lock);
170169
/* Writing this magic value resets the device */
171170
st->ops->reg_write(st, AD5592R_REG_RESET, 0xdac);
172-
mutex_unlock(&iio_dev->mlock);
171+
mutex_unlock(&st->lock);
173172
}
174173

175174
udelay(250);
@@ -197,7 +196,6 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
197196
const struct ad5592r_rw_ops *ops = st->ops;
198197
int ret;
199198
unsigned i;
200-
struct iio_dev *iio_dev = iio_priv_to_dev(st);
201199
u8 pulldown = 0, tristate = 0, dac = 0, adc = 0;
202200
u16 read_back;
203201

@@ -247,7 +245,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
247245
}
248246
}
249247

250-
mutex_lock(&iio_dev->mlock);
248+
mutex_lock(&st->lock);
251249

252250
/* Pull down unused pins to GND */
253251
ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown);
@@ -285,7 +283,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
285283
ret = -EIO;
286284

287285
err_unlock:
288-
mutex_unlock(&iio_dev->mlock);
286+
mutex_unlock(&st->lock);
289287
return ret;
290288
}
291289

@@ -314,11 +312,11 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
314312
if (!chan->output)
315313
return -EINVAL;
316314

317-
mutex_lock(&iio_dev->mlock);
315+
mutex_lock(&st->lock);
318316
ret = st->ops->write_dac(st, chan->channel, val);
319317
if (!ret)
320318
st->cached_dac[chan->channel] = val;
321-
mutex_unlock(&iio_dev->mlock);
319+
mutex_unlock(&st->lock);
322320
return ret;
323321
case IIO_CHAN_INFO_SCALE:
324322
if (chan->type == IIO_VOLTAGE) {
@@ -333,12 +331,12 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
333331
else
334332
return -EINVAL;
335333

336-
mutex_lock(&iio_dev->mlock);
334+
mutex_lock(&st->lock);
337335

338336
ret = st->ops->reg_read(st, AD5592R_REG_CTRL,
339337
&st->cached_gp_ctrl);
340338
if (ret < 0) {
341-
mutex_unlock(&iio_dev->mlock);
339+
mutex_unlock(&st->lock);
342340
return ret;
343341
}
344342

@@ -360,7 +358,7 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
360358

361359
ret = st->ops->reg_write(st, AD5592R_REG_CTRL,
362360
st->cached_gp_ctrl);
363-
mutex_unlock(&iio_dev->mlock);
361+
mutex_unlock(&st->lock);
364362

365363
return ret;
366364
}
@@ -382,7 +380,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
382380

383381
switch (m) {
384382
case IIO_CHAN_INFO_RAW:
385-
mutex_lock(&iio_dev->mlock);
383+
mutex_lock(&st->lock);
386384

387385
if (!chan->output) {
388386
ret = st->ops->read_adc(st, chan->channel, &read_val);
@@ -419,7 +417,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
419417
} else {
420418
int mult;
421419

422-
mutex_lock(&iio_dev->mlock);
420+
mutex_lock(&st->lock);
423421

424422
if (chan->output)
425423
mult = !!(st->cached_gp_ctrl &
@@ -437,7 +435,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
437435
case IIO_CHAN_INFO_OFFSET:
438436
ret = ad5592r_get_vref(st);
439437

440-
mutex_lock(&iio_dev->mlock);
438+
mutex_lock(&st->lock);
441439

442440
if (st->cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE)
443441
*val = (-34365 * 25) / ret;
@@ -450,7 +448,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
450448
}
451449

452450
unlock:
453-
mutex_unlock(&iio_dev->mlock);
451+
mutex_unlock(&st->lock);
454452
return ret;
455453
}
456454

@@ -625,6 +623,8 @@ int ad5592r_probe(struct device *dev, const char *name,
625623
iio_dev->info = &ad5592r_info;
626624
iio_dev->modes = INDIO_DIRECT_MODE;
627625

626+
mutex_init(&st->lock);
627+
628628
ad5592r_init_scales(st, ad5592r_get_vref(st));
629629

630630
ret = ad5592r_reset(st);

drivers/iio/dac/ad5592r-base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct ad5592r_state {
5252
struct regulator *reg;
5353
struct gpio_chip gpiochip;
5454
struct mutex gpio_lock; /* Protect cached gpio_out, gpio_val, etc. */
55+
struct mutex lock;
5556
unsigned int num_channels;
5657
const struct ad5592r_rw_ops *ops;
5758
int scale_avail[2][2];

0 commit comments

Comments
 (0)