mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
iio: dac: ltc2688: use the auto lock API
Make use of the cleanup API so that we can simplify some code paths. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
7798b50e00
commit
70fde04883
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/bits.h>
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
@@ -208,12 +209,12 @@ static int ltc2688_dac_code_write(struct ltc2688_state *st, u32 chan, u32 input,
|
||||
code = FIELD_PREP(LTC2688_DITHER_RAW_MASK, code);
|
||||
}
|
||||
|
||||
mutex_lock(&st->lock);
|
||||
guard(mutex)(&st->lock);
|
||||
/* select the correct input register to read from */
|
||||
ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
|
||||
input << chan);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* If in dither/toggle mode the dac should be updated by an
|
||||
@@ -224,10 +225,7 @@ static int ltc2688_dac_code_write(struct ltc2688_state *st, u32 chan, u32 input,
|
||||
else
|
||||
reg = LTC2688_CMD_CH_CODE(chan);
|
||||
|
||||
ret = regmap_write(st->regmap, reg, code);
|
||||
out_unlock:
|
||||
mutex_unlock(&st->lock);
|
||||
return ret;
|
||||
return regmap_write(st->regmap, reg, code);
|
||||
}
|
||||
|
||||
static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
|
||||
@@ -236,20 +234,20 @@ static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
|
||||
struct ltc2688_chan *c = &st->channels[chan];
|
||||
int ret;
|
||||
|
||||
mutex_lock(&st->lock);
|
||||
guard(mutex)(&st->lock);
|
||||
ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
|
||||
input << chan);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
return ret;
|
||||
|
||||
ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code);
|
||||
out_unlock:
|
||||
mutex_unlock(&st->lock);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!c->toggle_chan && input == LTC2688_INPUT_B)
|
||||
*code = FIELD_GET(LTC2688_DITHER_RAW_MASK, *code);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const int ltc2688_raw_range[] = {0, 1, U16_MAX};
|
||||
@@ -359,17 +357,15 @@ static ssize_t ltc2688_dither_toggle_set(struct iio_dev *indio_dev,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
mutex_lock(&st->lock);
|
||||
guard(mutex)(&st->lock);
|
||||
ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN,
|
||||
BIT(chan->channel), en << chan->channel);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
return ret;
|
||||
|
||||
c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT;
|
||||
out_unlock:
|
||||
mutex_unlock(&st->lock);
|
||||
|
||||
return ret ?: len;
|
||||
return len;
|
||||
}
|
||||
|
||||
static ssize_t ltc2688_reg_bool_get(struct iio_dev *indio_dev,
|
||||
|
||||
Reference in New Issue
Block a user