]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.13.6/iio-ad_sigma_delta-implement-a-dedicated-reset-function.patch
fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.13.6 / iio-ad_sigma_delta-implement-a-dedicated-reset-function.patch
1 From 7fc10de8d49a748c476532c9d8e8fe19e548dd67 Mon Sep 17 00:00:00 2001
2 From: Dragos Bogdan <dragos.bogdan@analog.com>
3 Date: Tue, 5 Sep 2017 15:14:45 +0300
4 Subject: iio: ad_sigma_delta: Implement a dedicated reset function
5
6 From: Dragos Bogdan <dragos.bogdan@analog.com>
7
8 commit 7fc10de8d49a748c476532c9d8e8fe19e548dd67 upstream.
9
10 Since most of the SD ADCs have the option of reseting the serial
11 interface by sending a number of SCLKs with CS = 0 and DIN = 1,
12 a dedicated function that can do this is usefull.
13
14 Needed for the patch: iio: ad7793: Fix the serial interface reset
15 Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
16 Acked-by: Lars-Peter Clausen <lars@metafoo.de>
17 Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19
20 ---
21 drivers/iio/adc/ad_sigma_delta.c | 28 ++++++++++++++++++++++++++++
22 include/linux/iio/adc/ad_sigma_delta.h | 3 +++
23 2 files changed, 31 insertions(+)
24
25 --- a/drivers/iio/adc/ad_sigma_delta.c
26 +++ b/drivers/iio/adc/ad_sigma_delta.c
27 @@ -177,6 +177,34 @@ out:
28 }
29 EXPORT_SYMBOL_GPL(ad_sd_read_reg);
30
31 +/**
32 + * ad_sd_reset() - Reset the serial interface
33 + *
34 + * @sigma_delta: The sigma delta device
35 + * @reset_length: Number of SCLKs with DIN = 1
36 + *
37 + * Returns 0 on success, an error code otherwise.
38 + **/
39 +int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
40 + unsigned int reset_length)
41 +{
42 + uint8_t *buf;
43 + unsigned int size;
44 + int ret;
45 +
46 + size = DIV_ROUND_UP(reset_length, 8);
47 + buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
48 + if (!buf)
49 + return -ENOMEM;
50 +
51 + memset(buf, 0xff, size);
52 + ret = spi_write(sigma_delta->spi, buf, size);
53 + kfree(buf);
54 +
55 + return ret;
56 +}
57 +EXPORT_SYMBOL_GPL(ad_sd_reset);
58 +
59 static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
60 unsigned int mode, unsigned int channel)
61 {
62 --- a/include/linux/iio/adc/ad_sigma_delta.h
63 +++ b/include/linux/iio/adc/ad_sigma_delta.h
64 @@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delt
65 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
66 unsigned int size, unsigned int *val);
67
68 +int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
69 + unsigned int reset_length);
70 +
71 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
72 const struct iio_chan_spec *chan, int *val);
73 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,