26 #include <linux/device.h>
27 #include <linux/kernel.h>
29 #include <linux/i2c.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
34 #include <linux/module.h>
102 static int ad7997_8_update_scan_mode(
struct iio_dev *indio_dev,
103 const unsigned long *scan_mask)
119 static int ad799x_scan_direct(
struct ad799x_state *st,
unsigned ch)
144 ret = ad799x_i2c_read16(st, cmd, &rxbuf);
151 static int ad799x_read_raw(
struct iio_dev *indio_dev,
159 unsigned int scale_uv;
164 if (iio_buffer_enabled(indio_dev))
167 ret = ad799x_scan_direct(st, chan->
scan_index);
177 *val = scale_uv / 1000;
178 *val2 = (scale_uv % 1000) * 1000;
183 static const unsigned int ad7998_frequencies[] = {
196 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
207 return sprintf(buf,
"%u\n", ad7998_frequencies[val]);
215 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
229 goto error_ret_mutex;
233 for (i = 0; i <
ARRAY_SIZE(ad7998_frequencies); i++)
234 if (val == ad7998_frequencies[i])
238 goto error_ret_mutex;
246 return ret ? ret : len;
249 static int ad799x_read_event_config(
struct iio_dev *indio_dev,
255 static const u8 ad799x_threshold_addresses[][2] = {
262 static int ad799x_write_event_value(
struct iio_dev *indio_dev,
273 ret = ad799x_i2c_write16(st,
274 ad799x_threshold_addresses[number][direction],
281 static int ad799x_read_event_value(
struct iio_dev *indio_dev,
293 ret = ad799x_i2c_read16(st,
294 ad799x_threshold_addresses[number][direction],
304 static ssize_t ad799x_read_channel_config(
struct device *dev,
308 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
314 ret = ad799x_i2c_read16(st, this_attr->
address, &val);
318 return sprintf(buf,
"%d\n", val);
321 static ssize_t ad799x_write_channel_config(
struct device *dev,
326 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
338 ret = ad799x_i2c_write16(st, this_attr->
address, val);
341 return ret ? ret : len;
344 static irqreturn_t ad799x_event_handler(
int irq,
void *
private)
346 struct iio_dev *indio_dev =
private;
360 for (i = 0; i < 8; i++) {
361 if (status & (1 << i))
381 ad799x_read_channel_config,
382 ad799x_write_channel_config,
387 ad799x_read_channel_config,
388 ad799x_write_channel_config,
393 ad799x_read_channel_config,
394 ad799x_write_channel_config,
399 ad799x_read_channel_config,
400 ad799x_write_channel_config,
404 ad799x_read_frequency,
405 ad799x_write_frequency);
408 static struct attribute *ad7993_4_7_8_event_attributes[] = {
409 &iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
410 &iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
411 &iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
412 &iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr,
413 &iio_dev_attr_sampling_frequency.dev_attr.attr,
414 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
419 .attrs = ad7993_4_7_8_event_attributes,
423 static struct attribute *ad7992_event_attributes[] = {
424 &iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
425 &iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
426 &iio_dev_attr_sampling_frequency.dev_attr.attr,
427 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
432 .attrs = ad7992_event_attributes,
436 static const struct iio_info ad7991_info = {
437 .read_raw = &ad799x_read_raw,
441 static const struct iio_info ad7992_info = {
442 .read_raw = &ad799x_read_raw,
443 .event_attrs = &ad7992_event_attrs_group,
444 .read_event_config = &ad799x_read_event_config,
445 .read_event_value = &ad799x_read_event_value,
446 .write_event_value = &ad799x_write_event_value,
450 static const struct iio_info ad7993_4_7_8_info = {
451 .read_raw = &ad799x_read_raw,
452 .event_attrs = &ad7993_4_7_8_event_attrs_group,
453 .read_event_config = &ad799x_read_event_config,
454 .read_event_value = &ad799x_read_event_value,
455 .write_event_value = &ad799x_write_event_value,
457 .update_scan_mode = ad7997_8_update_scan_mode,
460 #define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
461 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
472 .scan_type =
IIO_ST(
'u', 12, 16, 0),
480 .scan_type =
IIO_ST(
'u', 12, 16, 0),
488 .scan_type =
IIO_ST(
'u', 12, 16, 0),
496 .scan_type =
IIO_ST(
'u', 12, 16, 0),
502 .info = &ad7991_info,
512 .scan_type =
IIO_ST(
'u', 10, 16, 2),
520 .scan_type =
IIO_ST(
'u', 10, 16, 2),
528 .scan_type =
IIO_ST(
'u', 10, 16, 2),
536 .scan_type =
IIO_ST(
'u', 10, 16, 2),
542 .info = &ad7991_info,
552 .scan_type =
IIO_ST(
'u', 8, 16, 4),
560 .scan_type =
IIO_ST(
'u', 8, 16, 4),
568 .scan_type =
IIO_ST(
'u', 8, 16, 4),
576 .scan_type =
IIO_ST(
'u', 8, 16, 4),
582 .info = &ad7991_info,
592 .scan_type =
IIO_ST(
'u', 12, 16, 0),
601 .scan_type =
IIO_ST(
'u', 12, 16, 0),
609 .info = &ad7992_info,
619 .scan_type =
IIO_ST(
'u', 10, 16, 2),
628 .scan_type =
IIO_ST(
'u', 10, 16, 2),
637 .scan_type =
IIO_ST(
'u', 10, 16, 2),
646 .scan_type =
IIO_ST(
'u', 10, 16, 2),
654 .info = &ad7993_4_7_8_info,
664 .scan_type =
IIO_ST(
'u', 12, 16, 0),
673 .scan_type =
IIO_ST(
'u', 12, 16, 0),
682 .scan_type =
IIO_ST(
'u', 12, 16, 0),
691 .scan_type =
IIO_ST(
'u', 12, 16, 0),
699 .info = &ad7993_4_7_8_info,
709 .scan_type =
IIO_ST(
'u', 10, 16, 2),
718 .scan_type =
IIO_ST(
'u', 10, 16, 2),
727 .scan_type =
IIO_ST(
'u', 10, 16, 2),
736 .scan_type =
IIO_ST(
'u', 10, 16, 2),
745 .scan_type =
IIO_ST(
'u', 10, 16, 2),
753 .scan_type =
IIO_ST(
'u', 10, 16, 2),
761 .scan_type =
IIO_ST(
'u', 10, 16, 2),
769 .scan_type =
IIO_ST(
'u', 10, 16, 2),
776 .info = &ad7993_4_7_8_info,
786 .scan_type =
IIO_ST(
'u', 12, 16, 0),
795 .scan_type =
IIO_ST(
'u', 12, 16, 0),
804 .scan_type =
IIO_ST(
'u', 12, 16, 0),
813 .scan_type =
IIO_ST(
'u', 12, 16, 0),
822 .scan_type =
IIO_ST(
'u', 12, 16, 0),
830 .scan_type =
IIO_ST(
'u', 12, 16, 0),
838 .scan_type =
IIO_ST(
'u', 12, 16, 0),
846 .scan_type =
IIO_ST(
'u', 12, 16, 0),
853 .info = &ad7993_4_7_8_info,
865 if (indio_dev ==
NULL)
868 st = iio_priv(indio_dev);
870 i2c_set_clientdata(client, indio_dev);
872 st->
id =
id->driver_data;
884 if (!IS_ERR(st->
reg)) {
891 indio_dev->
dev.parent = &client->
dev;
892 indio_dev->
name =
id->name;
901 goto error_disable_reg;
903 if (client->
irq > 0) {
906 ad799x_event_handler,
912 goto error_cleanup_ring;
925 if (!IS_ERR(st->
reg))
928 if (!IS_ERR(st->
reg))
937 struct iio_dev *indio_dev = i2c_get_clientdata(client);
945 if (!IS_ERR(st->
reg)) {
972 .probe = ad799x_probe,
974 .id_table = ad799x_id,