Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: ad_sigma_delta: Implement a dedicated reset function

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>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Dragos Bogdan and committed by
Jonathan Cameron
7fc10de8 4b1f0c31

+31
+28
drivers/iio/adc/ad_sigma_delta.c
··· 177 177 } 178 178 EXPORT_SYMBOL_GPL(ad_sd_read_reg); 179 179 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 + 180 208 static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta, 181 209 unsigned int mode, unsigned int channel) 182 210 {
+3
include/linux/iio/adc/ad_sigma_delta.h
··· 111 111 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg, 112 112 unsigned int size, unsigned int *val); 113 113 114 + int ad_sd_reset(struct ad_sigma_delta *sigma_delta, 115 + unsigned int reset_length); 116 + 114 117 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, 115 118 const struct iio_chan_spec *chan, int *val); 116 119 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,