10 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
17 #include <linux/sched.h>
19 #include <linux/module.h>
91 .set_channel = ad7793_set_channel,
92 .set_mode = ad7793_set_mode,
93 .has_registers =
true,
113 static int ad7793_setup(
struct iio_dev *indio_dev,
118 unsigned long long scale_uv;
122 ret = spi_write(st->
sd.spi, (
u8 *)&ret,
sizeof(ret));
135 dev_err(&st->
sd.spi->dev,
"device ID query failed\n");
146 ret = ad7793_set_channel(&st->
sd, 0);
151 sizeof(pdata->
io), pdata->
io);
155 ret = ad7793_calibrate_all(st);
162 >> (st->
chip_info->channels[0].scan_type.realbits -
172 dev_err(&st->
sd.spi->dev,
"setup failed\n");
176 static const u16 sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39, 33, 19,
177 17, 16, 12, 10, 8, 6, 4};
183 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
195 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
201 if (iio_buffer_enabled(indio_dev)) {
213 for (i = 0; i <
ARRAY_SIZE(sample_freq_avail); i++)
214 if (lval == sample_freq_avail[i]) {
224 return ret ? ret : len;
228 ad7793_read_frequency,
229 ad7793_write_frequency);
232 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");
234 static ssize_t ad7793_show_scale_available(
struct device *dev,
237 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
245 len +=
sprintf(buf + len,
"\n");
251 in_voltage-voltage_scale_available,
S_IRUGO,
252 ad7793_show_scale_available,
NULL, 0);
254 static struct attribute *ad7793_attributes[] = {
255 &iio_dev_attr_sampling_frequency.dev_attr.attr,
256 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
257 &iio_dev_attr_in_m_in_scale_available.dev_attr.attr,
262 .attrs = ad7793_attributes,
265 static int ad7793_read_raw(
struct iio_dev *indio_dev,
273 unsigned long long scale_uv;
285 switch (chan->
type) {
295 scale_uv = (1170ULL * 100000000ULL * 6ULL);
300 scale_uv = 1444444444444ULL;
306 scale_uv >>= (chan->
scan_type.realbits - (unipolar ? 0 : 1));
312 *val = -(1 << (chan->
scan_type.realbits - 1));
318 unsigned long long offset;
321 shift = chan->
scan_type.realbits - (unipolar ? 0 : 1);
322 offset = 273ULL << shift;
331 static int ad7793_write_raw(
struct iio_dev *indio_dev,
342 if (iio_buffer_enabled(indio_dev)) {
362 ad7793_calibrate_all(st);
374 static int ad7793_write_raw_get_fmt(
struct iio_dev *indio_dev,
381 static const struct iio_info ad7793_info = {
382 .read_raw = &ad7793_read_raw,
383 .write_raw = &ad7793_write_raw,
384 .write_raw_get_fmt = &ad7793_write_raw_get_fmt,
385 .attrs = &ad7793_attribute_group,
390 #define DECLARE_AD7793_CHANNELS(_name, _b, _sb, _s) \
391 const struct iio_chan_spec _name##_channels[] = { \
392 AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \
393 AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), (_s)), \
394 AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), (_s)), \
395 AD_SD_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), (_s)), \
396 AD_SD_TEMP_CHANNEL(4, AD7793_CH_TEMP, (_b), (_sb), (_s)), \
397 AD_SD_SUPPLY_CHANNEL(5, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), (_s)), \
398 IIO_CHAN_SOFT_TIMESTAMP(6), \
401 #define DECLARE_AD7795_CHANNELS(_name, _b, _sb) \
402 const struct iio_chan_spec _name##_channels[] = { \
403 AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
404 AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \
405 AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \
406 AD_SD_DIFF_CHANNEL(3, 3, 3, AD7795_CH_AIN4P_AIN4M, (_b), (_sb), 0), \
407 AD_SD_DIFF_CHANNEL(4, 4, 4, AD7795_CH_AIN5P_AIN5M, (_b), (_sb), 0), \
408 AD_SD_DIFF_CHANNEL(5, 5, 5, AD7795_CH_AIN6P_AIN6M, (_b), (_sb), 0), \
409 AD_SD_SHORTED_CHANNEL(6, 0, AD7795_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
410 AD_SD_TEMP_CHANNEL(7, AD7793_CH_TEMP, (_b), (_sb), 0), \
411 AD_SD_SUPPLY_CHANNEL(8, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
412 IIO_CHAN_SOFT_TIMESTAMP(9), \
423 .channels = ad7785_channels,
427 .channels = ad7792_channels,
431 .channels = ad7793_channels,
435 .channels = ad7794_channels,
439 .channels = ad7795_channels,
449 int ret, voltage_uv = 0;
462 if (indio_dev ==
NULL)
465 st = iio_priv(indio_dev);
467 ad_sd_init(&st->
sd, indio_dev, spi, &ad7793_sigma_delta_info);
470 if (!IS_ERR(st->
reg)) {
488 spi_set_drvdata(spi, indio_dev);
490 indio_dev->
dev.parent = &spi->
dev;
495 indio_dev->
info = &ad7793_info;
499 goto error_disable_reg;
501 ret = ad7793_setup(indio_dev, pdata);
503 goto error_remove_trigger;
507 goto error_remove_trigger;
511 error_remove_trigger:
514 if (!IS_ERR(st->
reg))
517 if (!IS_ERR(st->
reg))
527 struct iio_dev *indio_dev = spi_get_drvdata(spi);
533 if (!IS_ERR(st->
reg)) {
558 .probe = ad7793_probe,
560 .id_table = ad7793_id,