Merge tag 'perf-tools-for-v6.0-2022-08-04' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-microblaze.git] / drivers / iio / adc / ad7606_par.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * AD7606 Parallel Interface ADC driver
4  *
5  * Copyright 2011 Analog Devices Inc.
6  */
7
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/types.h>
12 #include <linux/err.h>
13 #include <linux/io.h>
14
15 #include <linux/iio/iio.h>
16 #include "ad7606.h"
17
18 static int ad7606_par16_read_block(struct device *dev,
19                                    int count, void *buf)
20 {
21         struct iio_dev *indio_dev = dev_get_drvdata(dev);
22         struct ad7606_state *st = iio_priv(indio_dev);
23
24         insw((unsigned long)st->base_address, buf, count);
25
26         return 0;
27 }
28
29 static const struct ad7606_bus_ops ad7606_par16_bops = {
30         .read_block = ad7606_par16_read_block,
31 };
32
33 static int ad7606_par8_read_block(struct device *dev,
34                                   int count, void *buf)
35 {
36         struct iio_dev *indio_dev = dev_get_drvdata(dev);
37         struct ad7606_state *st = iio_priv(indio_dev);
38
39         insb((unsigned long)st->base_address, buf, count * 2);
40
41         return 0;
42 }
43
44 static const struct ad7606_bus_ops ad7606_par8_bops = {
45         .read_block = ad7606_par8_read_block,
46 };
47
48 static int ad7606_par_probe(struct platform_device *pdev)
49 {
50         const struct platform_device_id *id = platform_get_device_id(pdev);
51         struct resource *res;
52         void __iomem *addr;
53         resource_size_t remap_size;
54         int irq;
55
56         irq = platform_get_irq(pdev, 0);
57         if (irq < 0)
58                 return irq;
59
60         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
61         addr = devm_ioremap_resource(&pdev->dev, res);
62         if (IS_ERR(addr))
63                 return PTR_ERR(addr);
64
65         remap_size = resource_size(res);
66
67         return ad7606_probe(&pdev->dev, irq, addr,
68                             id->name, id->driver_data,
69                             remap_size > 1 ? &ad7606_par16_bops :
70                             &ad7606_par8_bops);
71 }
72
73 static const struct platform_device_id ad7606_driver_ids[] = {
74         { .name = "ad7605-4", .driver_data = ID_AD7605_4, },
75         { .name = "ad7606-4", .driver_data = ID_AD7606_4, },
76         { .name = "ad7606-6", .driver_data = ID_AD7606_6, },
77         { .name = "ad7606-8", .driver_data = ID_AD7606_8, },
78         { }
79 };
80 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
81
82 static const struct of_device_id ad7606_of_match[] = {
83         { .compatible = "adi,ad7605-4" },
84         { .compatible = "adi,ad7606-4" },
85         { .compatible = "adi,ad7606-6" },
86         { .compatible = "adi,ad7606-8" },
87         { },
88 };
89 MODULE_DEVICE_TABLE(of, ad7606_of_match);
90
91 static struct platform_driver ad7606_driver = {
92         .probe = ad7606_par_probe,
93         .id_table = ad7606_driver_ids,
94         .driver = {
95                 .name = "ad7606",
96                 .pm = AD7606_PM_OPS,
97                 .of_match_table = ad7606_of_match,
98         },
99 };
100 module_platform_driver(ad7606_driver);
101
102 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
103 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
104 MODULE_LICENSE("GPL v2");
105 MODULE_IMPORT_NS(IIO_AD7606);