Skip to content

Commit 4b9c62a

Browse files
dbogdangregkh
authored andcommitted
iio: ad_sigma_delta: Implement a dedicated reset function
commit 7fc10de8d49a748c476532c9d8e8fe19e548dd67 upstream. Since most of the SD ADCs have the option of reseting the serial interface by sending a number of SCLKs with CS = 0 and DIN = 1, a dedicated function that can do this is usefull. Needed for the patch: iio: ad7793: Fix the serial interface reset Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com> Acked-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0bab541 commit 4b9c62a

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

drivers/iio/adc/ad_sigma_delta.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
177177
}
178178
EXPORT_SYMBOL_GPL(ad_sd_read_reg);
179179

180+
/**
181+
* ad_sd_reset() - Reset the serial interface
182+
*
183+
* @sigma_delta: The sigma delta device
184+
* @reset_length: Number of SCLKs with DIN = 1
185+
*
186+
* Returns 0 on success, an error code otherwise.
187+
**/
188+
int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
189+
unsigned int reset_length)
190+
{
191+
uint8_t *buf;
192+
unsigned int size;
193+
int ret;
194+
195+
size = DIV_ROUND_UP(reset_length, 8);
196+
buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
197+
if (!buf)
198+
return -ENOMEM;
199+
200+
memset(buf, 0xff, size);
201+
ret = spi_write(sigma_delta->spi, buf, size);
202+
kfree(buf);
203+
204+
return ret;
205+
}
206+
EXPORT_SYMBOL_GPL(ad_sd_reset);
207+
180208
static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
181209
unsigned int mode, unsigned int channel)
182210
{

include/linux/iio/adc/ad_sigma_delta.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
111111
int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
112112
unsigned int size, unsigned int *val);
113113

114+
int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
115+
unsigned int reset_length);
116+
114117
int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
115118
const struct iio_chan_spec *chan, int *val);
116119
int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,

0 commit comments

Comments
 (0)