@@ -156,7 +156,6 @@ static void ad5592r_gpio_cleanup(struct ad5592r_state *st)
156
156
static int ad5592r_reset (struct ad5592r_state * st )
157
157
{
158
158
struct gpio_desc * gpio ;
159
- struct iio_dev * iio_dev = iio_priv_to_dev (st );
160
159
161
160
gpio = devm_gpiod_get_optional (st -> dev , "reset" , GPIOD_OUT_LOW );
162
161
if (IS_ERR (gpio ))
@@ -166,10 +165,10 @@ static int ad5592r_reset(struct ad5592r_state *st)
166
165
udelay (1 );
167
166
gpiod_set_value (gpio , 1 );
168
167
} else {
169
- mutex_lock (& iio_dev -> mlock );
168
+ mutex_lock (& st -> lock );
170
169
/* Writing this magic value resets the device */
171
170
st -> ops -> reg_write (st , AD5592R_REG_RESET , 0xdac );
172
- mutex_unlock (& iio_dev -> mlock );
171
+ mutex_unlock (& st -> lock );
173
172
}
174
173
175
174
udelay (250 );
@@ -197,7 +196,6 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
197
196
const struct ad5592r_rw_ops * ops = st -> ops ;
198
197
int ret ;
199
198
unsigned i ;
200
- struct iio_dev * iio_dev = iio_priv_to_dev (st );
201
199
u8 pulldown = 0 , tristate = 0 , dac = 0 , adc = 0 ;
202
200
u16 read_back ;
203
201
@@ -247,7 +245,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
247
245
}
248
246
}
249
247
250
- mutex_lock (& iio_dev -> mlock );
248
+ mutex_lock (& st -> lock );
251
249
252
250
/* Pull down unused pins to GND */
253
251
ret = ops -> reg_write (st , AD5592R_REG_PULLDOWN , pulldown );
@@ -285,7 +283,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
285
283
ret = - EIO ;
286
284
287
285
err_unlock :
288
- mutex_unlock (& iio_dev -> mlock );
286
+ mutex_unlock (& st -> lock );
289
287
return ret ;
290
288
}
291
289
@@ -314,11 +312,11 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
314
312
if (!chan -> output )
315
313
return - EINVAL ;
316
314
317
- mutex_lock (& iio_dev -> mlock );
315
+ mutex_lock (& st -> lock );
318
316
ret = st -> ops -> write_dac (st , chan -> channel , val );
319
317
if (!ret )
320
318
st -> cached_dac [chan -> channel ] = val ;
321
- mutex_unlock (& iio_dev -> mlock );
319
+ mutex_unlock (& st -> lock );
322
320
return ret ;
323
321
case IIO_CHAN_INFO_SCALE :
324
322
if (chan -> type == IIO_VOLTAGE ) {
@@ -333,12 +331,12 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
333
331
else
334
332
return - EINVAL ;
335
333
336
- mutex_lock (& iio_dev -> mlock );
334
+ mutex_lock (& st -> lock );
337
335
338
336
ret = st -> ops -> reg_read (st , AD5592R_REG_CTRL ,
339
337
& st -> cached_gp_ctrl );
340
338
if (ret < 0 ) {
341
- mutex_unlock (& iio_dev -> mlock );
339
+ mutex_unlock (& st -> lock );
342
340
return ret ;
343
341
}
344
342
@@ -360,7 +358,7 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
360
358
361
359
ret = st -> ops -> reg_write (st , AD5592R_REG_CTRL ,
362
360
st -> cached_gp_ctrl );
363
- mutex_unlock (& iio_dev -> mlock );
361
+ mutex_unlock (& st -> lock );
364
362
365
363
return ret ;
366
364
}
@@ -382,7 +380,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
382
380
383
381
switch (m ) {
384
382
case IIO_CHAN_INFO_RAW :
385
- mutex_lock (& iio_dev -> mlock );
383
+ mutex_lock (& st -> lock );
386
384
387
385
if (!chan -> output ) {
388
386
ret = st -> ops -> read_adc (st , chan -> channel , & read_val );
@@ -419,7 +417,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
419
417
} else {
420
418
int mult ;
421
419
422
- mutex_lock (& iio_dev -> mlock );
420
+ mutex_lock (& st -> lock );
423
421
424
422
if (chan -> output )
425
423
mult = !!(st -> cached_gp_ctrl &
@@ -437,7 +435,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
437
435
case IIO_CHAN_INFO_OFFSET :
438
436
ret = ad5592r_get_vref (st );
439
437
440
- mutex_lock (& iio_dev -> mlock );
438
+ mutex_lock (& st -> lock );
441
439
442
440
if (st -> cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE )
443
441
* val = (-34365 * 25 ) / ret ;
@@ -450,7 +448,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
450
448
}
451
449
452
450
unlock :
453
- mutex_unlock (& iio_dev -> mlock );
451
+ mutex_unlock (& st -> lock );
454
452
return ret ;
455
453
}
456
454
@@ -625,6 +623,8 @@ int ad5592r_probe(struct device *dev, const char *name,
625
623
iio_dev -> info = & ad5592r_info ;
626
624
iio_dev -> modes = INDIO_DIRECT_MODE ;
627
625
626
+ mutex_init (& st -> lock );
627
+
628
628
ad5592r_init_scales (st , ad5592r_get_vref (st ));
629
629
630
630
ret = ad5592r_reset (st );
0 commit comments