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

iio: adc: ad7476: Support ROHM BD79105

The ROHM BD79105 is a simple 16-bit ADC accessible via SPI*.

The BD79105 has a CONVSTART pin, which must be set high to start the ADC
conversion. Unlike with the ad7091 and ad7091r which also have a
CONVSTART pin, the BD79105 requires that the pin must remain high also
for the duration of the SPI access.

(*) Couple of words about the SPI. The BD79105 has pins named as
CONVSTART, SCLK, DIN and DOUT. For the curious reader, DIN is not SPI
ISO.

DIN is a signal which can be used as a chip-select. When DIN is pulled
low, the ADC will output the completed measurement via DOUT as SCLK is
clocked. According to the data-sheet, the DIN can also be used for
daisy-chaining multiple ADCs. Furthermore, DOUT can be used also for a
'data-ready' -IRQ. These modes aren't supported by this driver.

Support reading ADC scale and data from the BD79105 using SPI, when DIN
is used as a chip-select.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://patch.msgid.link/6ee06d551256db9213ccbe72f44cfe9452717716.1754901948.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
6c27bf9b 261b9076

+39
+39
drivers/iio/adc/ad7476.c
··· 32 32 struct iio_chan_spec channel[2]; 33 33 void (*reset)(struct ad7476_state *); 34 34 void (*conversion_pre_op)(struct ad7476_state *st); 35 + void (*conversion_post_op)(struct ad7476_state *st); 35 36 bool has_vref; 36 37 bool has_vdrive; 38 + bool convstart_required; 37 39 }; 38 40 39 41 struct ad7476_state { ··· 66 64 udelay(1); /* Conversion time: 650 ns max */ 67 65 } 68 66 67 + static void bd79105_convst_disable(struct ad7476_state *st) 68 + { 69 + gpiod_set_value_cansleep(st->convst_gpio, 0); 70 + } 71 + 72 + static void bd79105_convst_enable(struct ad7476_state *st) 73 + { 74 + gpiod_set_value_cansleep(st->convst_gpio, 1); 75 + /* Worst case, 2790 ns required for conversion */ 76 + ndelay(2790); 77 + } 78 + 69 79 static irqreturn_t ad7476_trigger_handler(int irq, void *p) 70 80 { 71 81 struct iio_poll_func *pf = p; ··· 95 81 iio_push_to_buffers_with_ts(indio_dev, st->data, sizeof(st->data), 96 82 iio_get_time_ns(indio_dev)); 97 83 done: 84 + if (st->chip_info->conversion_post_op) 85 + st->chip_info->conversion_post_op(st); 98 86 iio_trigger_notify_done(indio_dev->trig); 99 87 100 88 return IRQ_HANDLED; ··· 118 102 ret = spi_sync(st->spi, &st->msg); 119 103 if (ret) 120 104 return ret; 105 + 106 + if (st->chip_info->conversion_post_op) 107 + st->chip_info->conversion_post_op(st); 121 108 122 109 return be16_to_cpup((__be16 *)st->data); 123 110 } ··· 292 273 .has_vref = true, 293 274 }; 294 275 276 + static const struct ad7476_chip_info bd79105_chip_info = { 277 + .channel[0] = AD7091R_CHAN(16), 278 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 279 + /* 280 + * The BD79105 starts ADC data conversion when the CONVSTART line is 281 + * set HIGH. The CONVSTART must be kept HIGH until the data has been 282 + * read from the ADC. 283 + */ 284 + .conversion_pre_op = bd79105_convst_enable, 285 + .conversion_post_op = bd79105_convst_disable, 286 + /* BD79105 won't do conversion without convstart */ 287 + .convstart_required = true, 288 + .has_vref = true, 289 + .has_vdrive = true, 290 + }; 291 + 295 292 static const struct iio_info ad7476_info = { 296 293 .read_raw = &ad7476_read_raw, 297 294 }; ··· 366 331 GPIOD_OUT_LOW); 367 332 if (IS_ERR(st->convst_gpio)) 368 333 return PTR_ERR(st->convst_gpio); 334 + 335 + if (st->chip_info->convstart_required && !st->convst_gpio) 336 + return dev_err_probe(&spi->dev, -EINVAL, "No convstart GPIO\n"); 369 337 370 338 /* 371 339 * This will never happen. Unless someone changes the channel specs ··· 439 401 { "ads7866", (kernel_ulong_t)&ads7866_chip_info }, 440 402 { "ads7867", (kernel_ulong_t)&ads7867_chip_info }, 441 403 { "ads7868", (kernel_ulong_t)&ads7868_chip_info }, 404 + { "bd79105", (kernel_ulong_t)&bd79105_chip_info }, 442 405 /* 443 406 * The ROHM BU79100G is identical to the TI's ADS7866 from the software 444 407 * point of view. The binding document mandates the ADS7866 to be