Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752214AbdIEMn0 (ORCPT ); Tue, 5 Sep 2017 08:43:26 -0400 Received: from www381.your-server.de ([78.46.137.84]:33280 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbdIEMnO (ORCPT ); Tue, 5 Sep 2017 08:43:14 -0400 Subject: Re: [PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function To: Dragos Bogdan , Michael Hennerich , Jonathan Cameron Cc: Hartmut Knaack , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20170905121445.26913-1-dragos.bogdan@analog.com> From: Lars-Peter Clausen Message-ID: <0ea75f81-fe63-4d54-6167-463c53dd8fd5@metafoo.de> Date: Tue, 5 Sep 2017 14:16:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170905121445.26913-1-dragos.bogdan@analog.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: lars@metafoo.de Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2346 Lines: 68 On 09/05/2017 02:14 PM, Dragos Bogdan wrote: > 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. > > Signed-off-by: Dragos Bogdan Acked-by: Lars-Peter Clausen > --- > drivers/iio/adc/ad_sigma_delta.c | 28 ++++++++++++++++++++++++++++ > include/linux/iio/adc/ad_sigma_delta.h | 3 +++ > 2 files changed, 31 insertions(+) > > diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c > index d10bd0c97233..22c4c17cd996 100644 > --- a/drivers/iio/adc/ad_sigma_delta.c > +++ b/drivers/iio/adc/ad_sigma_delta.c > @@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, > } > EXPORT_SYMBOL_GPL(ad_sd_read_reg); > > +/** > + * ad_sd_reset() - Reset the serial interface > + * > + * @sigma_delta: The sigma delta device > + * @reset_length: Number of SCLKs with DIN = 1 > + * > + * Returns 0 on success, an error code otherwise. > + **/ > +int ad_sd_reset(struct ad_sigma_delta *sigma_delta, > + unsigned int reset_length) > +{ > + uint8_t *buf; > + unsigned int size; > + int ret; > + > + size = DIV_ROUND_UP(reset_length, 8); > + buf = kcalloc(size, sizeof(*buf), GFP_KERNEL); > + if (!buf) > + return -ENOMEM; > + > + memset(buf, 0xff, size); > + ret = spi_write(sigma_delta->spi, buf, size); > + kfree(buf); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(ad_sd_reset); > + > static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta, > unsigned int mode, unsigned int channel) > { > diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h > index 5ba430cc9a87..1fc7abd28b0b 100644 > --- a/include/linux/iio/adc/ad_sigma_delta.h > +++ b/include/linux/iio/adc/ad_sigma_delta.h > @@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg, > int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg, > unsigned int size, unsigned int *val); > > +int ad_sd_reset(struct ad_sigma_delta *sigma_delta, > + unsigned int reset_length); > + > int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, > const struct iio_chan_spec *chan, int *val); > int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta, >