Merge tag 'for-linus-20190706' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / iio / adc / ad7606_par.c
blob1b08028facde8c25552a99a65489ae0671784abb
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * AD7606 Parallel Interface ADC driver
5 * Copyright 2011 Analog Devices Inc.
6 */
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/types.h>
11 #include <linux/err.h>
12 #include <linux/io.h>
14 #include <linux/iio/iio.h>
15 #include "ad7606.h"
17 static int ad7606_par16_read_block(struct device *dev,
18 int count, void *buf)
20 struct iio_dev *indio_dev = dev_get_drvdata(dev);
21 struct ad7606_state *st = iio_priv(indio_dev);
23 insw((unsigned long)st->base_address, buf, count);
25 return 0;
28 static const struct ad7606_bus_ops ad7606_par16_bops = {
29 .read_block = ad7606_par16_read_block,
32 static int ad7606_par8_read_block(struct device *dev,
33 int count, void *buf)
35 struct iio_dev *indio_dev = dev_get_drvdata(dev);
36 struct ad7606_state *st = iio_priv(indio_dev);
38 insb((unsigned long)st->base_address, buf, count * 2);
40 return 0;
43 static const struct ad7606_bus_ops ad7606_par8_bops = {
44 .read_block = ad7606_par8_read_block,
47 static int ad7606_par_probe(struct platform_device *pdev)
49 const struct platform_device_id *id = platform_get_device_id(pdev);
50 struct resource *res;
51 void __iomem *addr;
52 resource_size_t remap_size;
53 int irq;
55 irq = platform_get_irq(pdev, 0);
56 if (irq < 0) {
57 dev_err(&pdev->dev, "no irq: %d\n", irq);
58 return irq;
61 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
62 addr = devm_ioremap_resource(&pdev->dev, res);
63 if (IS_ERR(addr))
64 return PTR_ERR(addr);
66 remap_size = resource_size(res);
68 return ad7606_probe(&pdev->dev, irq, addr,
69 id->name, id->driver_data,
70 remap_size > 1 ? &ad7606_par16_bops :
71 &ad7606_par8_bops);
74 static const struct platform_device_id ad7606_driver_ids[] = {
75 { .name = "ad7605-4", .driver_data = ID_AD7605_4, },
76 { .name = "ad7606-4", .driver_data = ID_AD7606_4, },
77 { .name = "ad7606-6", .driver_data = ID_AD7606_6, },
78 { .name = "ad7606-8", .driver_data = ID_AD7606_8, },
79 { }
81 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
83 static const struct of_device_id ad7606_of_match[] = {
84 { .compatible = "adi,ad7605-4" },
85 { .compatible = "adi,ad7606-4" },
86 { .compatible = "adi,ad7606-6" },
87 { .compatible = "adi,ad7606-8" },
88 { },
90 MODULE_DEVICE_TABLE(of, ad7606_of_match);
92 static struct platform_driver ad7606_driver = {
93 .probe = ad7606_par_probe,
94 .id_table = ad7606_driver_ids,
95 .driver = {
96 .name = "ad7606",
97 .pm = AD7606_PM_OPS,
98 .of_match_table = ad7606_of_match,
101 module_platform_driver(ad7606_driver);
103 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
104 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
105 MODULE_LICENSE("GPL v2");