1 // SPDX-License-Identifier: GPL-2.0
3 * AD7606 Parallel Interface ADC driver
5 * Copyright 2011 Analog Devices Inc.
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/gpio/consumer.h>
11 #include <linux/platform_device.h>
12 #include <linux/types.h>
13 #include <linux/err.h>
16 #include <linux/iio/iio.h>
19 static int ad7606_par16_read_block(struct device *dev,
22 struct iio_dev *indio_dev = dev_get_drvdata(dev);
23 struct ad7606_state *st = iio_priv(indio_dev);
27 * On the parallel interface, the frstdata signal is set to high while
28 * and after reading the sample of the first channel and low for all
29 * other channels. This can be used to check that the incoming data is
30 * correctly aligned. During normal operation the data should never
31 * become unaligned, but some glitch or electrostatic discharge might
32 * cause an extra read or clock cycle. Monitoring the frstdata signal
33 * allows to recover from such failure situations.
38 if (st->gpio_frstdata) {
39 insw((unsigned long)st->base_address, _buf, 1);
40 if (!gpiod_get_value(st->gpio_frstdata)) {
47 insw((unsigned long)st->base_address, _buf, num);
51 static const struct ad7606_bus_ops ad7606_par16_bops = {
52 .read_block = ad7606_par16_read_block,
55 static int ad7606_par8_read_block(struct device *dev,
58 struct iio_dev *indio_dev = dev_get_drvdata(dev);
59 struct ad7606_state *st = iio_priv(indio_dev);
61 * On the parallel interface, the frstdata signal is set to high while
62 * and after reading the sample of the first channel and low for all
63 * other channels. This can be used to check that the incoming data is
64 * correctly aligned. During normal operation the data should never
65 * become unaligned, but some glitch or electrostatic discharge might
66 * cause an extra read or clock cycle. Monitoring the frstdata signal
67 * allows to recover from such failure situations.
72 if (st->gpio_frstdata) {
73 insb((unsigned long)st->base_address, _buf, 2);
74 if (!gpiod_get_value(st->gpio_frstdata)) {
81 insb((unsigned long)st->base_address, _buf, num * 2);
86 static const struct ad7606_bus_ops ad7606_par8_bops = {
87 .read_block = ad7606_par8_read_block,
90 static int ad7606_par_probe(struct platform_device *pdev)
92 const struct platform_device_id *id = platform_get_device_id(pdev);
95 resource_size_t remap_size;
98 irq = platform_get_irq(pdev, 0);
102 addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
104 return PTR_ERR(addr);
106 remap_size = resource_size(res);
108 return ad7606_probe(&pdev->dev, irq, addr,
109 id->name, id->driver_data,
110 remap_size > 1 ? &ad7606_par16_bops :
114 static const struct platform_device_id ad7606_driver_ids[] = {
115 { .name = "ad7605-4", .driver_data = ID_AD7605_4, },
116 { .name = "ad7606-4", .driver_data = ID_AD7606_4, },
117 { .name = "ad7606-6", .driver_data = ID_AD7606_6, },
118 { .name = "ad7606-8", .driver_data = ID_AD7606_8, },
121 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
123 static const struct of_device_id ad7606_of_match[] = {
124 { .compatible = "adi,ad7605-4" },
125 { .compatible = "adi,ad7606-4" },
126 { .compatible = "adi,ad7606-6" },
127 { .compatible = "adi,ad7606-8" },
130 MODULE_DEVICE_TABLE(of, ad7606_of_match);
132 static struct platform_driver ad7606_driver = {
133 .probe = ad7606_par_probe,
134 .id_table = ad7606_driver_ids,
138 .of_match_table = ad7606_of_match,
141 module_platform_driver(ad7606_driver);
144 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
145 MODULE_LICENSE("GPL v2");
146 MODULE_IMPORT_NS(IIO_AD7606);