Skip to content

Commit 10a7413

Browse files
ukleineknunojsa
authored andcommitted
iio: adc: ad_sigma_delta: Store information about reset sequence length
The various chips can be reset using a sequence of SPI transfers with MOSI = 1. The length of such a sequence varies from chip to chip. Store that length in struct ad_sigma_delta_info and replace the respective parameter to ad_sd_reset() with it. Note the ad7192 used to pass 48 as length but the documentation specifies 40 as the required length. Assuming the latter is right. (Using a too long sequence doesn't hurt apart from using a longer spi transfer than necessary, so this is no relevant fix.) The motivation for storing this information is that this is useful to clear a pending R̅D̅Y̅ signal in the next change. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://patch.msgid.link/9750db62fce638bf140ff48172c23bff7f785e5b.1733504533.git.u.kleine-koenig@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Origin: next-20241216~37^2~19, commit:07a28874bb49700036a3ab435dd95ae31afd21ae
1 parent 3e95ba8 commit 10a7413

File tree

7 files changed

+13
-8
lines changed

7 files changed

+13
-8
lines changed

drivers/iio/adc/ad7124.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
578578
.data_reg = AD7124_DATA,
579579
.num_slots = 8,
580580
.irq_flags = IRQF_TRIGGER_FALLING,
581+
.num_resetclks = 64,
581582
};
582583

583584
static int ad7124_read_raw(struct iio_dev *indio_dev,
@@ -763,7 +764,7 @@ static int ad7124_soft_reset(struct ad7124_state *st)
763764
unsigned int readval, timeout;
764765
int ret;
765766

766-
ret = ad_sd_reset(&st->sd, 64);
767+
ret = ad_sd_reset(&st->sd);
767768
if (ret < 0)
768769
return ret;
769770

drivers/iio/adc/ad7173.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ static struct ad_sigma_delta_info ad7173_sigma_delta_info = {
747747
.read_mask = BIT(6),
748748
.status_ch_mask = GENMASK(3, 0),
749749
.data_reg = AD7173_REG_DATA,
750+
.num_resetclks = 64,
750751
};
751752

752753
static int ad7173_setup(struct iio_dev *indio_dev)

drivers/iio/adc/ad7192.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ static const struct ad_sigma_delta_info ad7192_sigma_delta_info = {
341341
.status_ch_mask = GENMASK(3, 0),
342342
.num_slots = 4,
343343
.irq_flags = IRQF_TRIGGER_FALLING,
344+
.num_resetclks = 40,
344345
};
345346

346347
static const struct ad_sd_calib_data ad7192_calib_arr[8] = {
@@ -396,7 +397,7 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device *dev)
396397
int i, ret, id;
397398

398399
/* reset the serial interface */
399-
ret = ad_sd_reset(&st->sd, 48);
400+
ret = ad_sd_reset(&st->sd);
400401
if (ret < 0)
401402
return ret;
402403
usleep_range(500, 1000); /* Wait for at least 500us */

drivers/iio/adc/ad7791.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ static const struct ad_sigma_delta_info ad7791_sigma_delta_info = {
261261
.addr_shift = 4,
262262
.read_mask = BIT(3),
263263
.irq_flags = IRQF_TRIGGER_FALLING,
264+
.num_resetclks = 32,
264265
};
265266

266267
static int ad7791_read_raw(struct iio_dev *indio_dev,

drivers/iio/adc/ad7793.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static const struct ad_sigma_delta_info ad7793_sigma_delta_info = {
220220
.addr_shift = 3,
221221
.read_mask = BIT(6),
222222
.irq_flags = IRQF_TRIGGER_FALLING,
223+
.num_resetclks = 32,
223224
};
224225

225226
static const struct ad_sd_calib_data ad7793_calib_arr[6] = {
@@ -279,7 +280,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
279280
return ret;
280281

281282
/* reset the serial interface */
282-
ret = ad_sd_reset(&st->sd, 32);
283+
ret = ad_sd_reset(&st->sd);
283284
if (ret < 0)
284285
goto out;
285286
usleep_range(500, 2000); /* Wait for at least 500us */

drivers/iio/adc/ad_sigma_delta.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,12 @@ EXPORT_SYMBOL_NS_GPL(ad_sd_read_reg, IIO_AD_SIGMA_DELTA);
179179
* ad_sd_reset() - Reset the serial interface
180180
*
181181
* @sigma_delta: The sigma delta device
182-
* @reset_length: Number of SCLKs with DIN = 1
183182
*
184183
* Returns 0 on success, an error code otherwise.
185184
**/
186-
int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
187-
unsigned int reset_length)
185+
int ad_sd_reset(struct ad_sigma_delta *sigma_delta)
188186
{
187+
unsigned int reset_length = sigma_delta->info->num_resetclks;
189188
uint8_t *buf;
190189
unsigned int size;
191190
int ret;

include/linux/iio/adc/ad_sigma_delta.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct iio_dev;
5252
* @irq_flags: flags for the interrupt used by the triggered buffer
5353
* @num_slots: Number of sequencer slots
5454
* @irq_line: IRQ for reading conversions. If 0, spi->irq will be used
55+
* @num_resetclks: Number of SPI clk cycles with MOSI=1 to reset the chip.
5556
*/
5657
struct ad_sigma_delta_info {
5758
int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
@@ -68,6 +69,7 @@ struct ad_sigma_delta_info {
6869
unsigned long irq_flags;
6970
unsigned int num_slots;
7071
int irq_line;
72+
unsigned int num_resetclks;
7173
};
7274

7375
/**
@@ -179,8 +181,7 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
179181
int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
180182
unsigned int size, unsigned int *val);
181183

182-
int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
183-
unsigned int reset_length);
184+
int ad_sd_reset(struct ad_sigma_delta *sigma_delta);
184185

185186
int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
186187
const struct iio_chan_spec *chan, int *val);

0 commit comments

Comments
 (0)