GNU Linux-libre 4.19.264-gnu1
[releases.git] / drivers / staging / iio / adc / ad7606_par.c
1 /*
2  * AD7606 Parallel Interface ADC driver
3  *
4  * Copyright 2011 Analog Devices Inc.
5  *
6  * Licensed under the GPL-2.
7  */
8
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                 dev_err(&pdev->dev, "no irq: %d\n", irq);
59                 return irq;
60         }
61
62         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
63         addr = devm_ioremap_resource(&pdev->dev, res);
64         if (IS_ERR(addr))
65                 return PTR_ERR(addr);
66
67         remap_size = resource_size(res);
68
69         return ad7606_probe(&pdev->dev, irq, addr,
70                             id->name, id->driver_data,
71                             remap_size > 1 ? &ad7606_par16_bops :
72                             &ad7606_par8_bops);
73 }
74
75 static int ad7606_par_remove(struct platform_device *pdev)
76 {
77         return ad7606_remove(&pdev->dev, platform_get_irq(pdev, 0));
78 }
79
80 static const struct platform_device_id ad7606_driver_ids[] = {
81         {
82                 .name           = "ad7606-8",
83                 .driver_data    = ID_AD7606_8,
84         }, {
85                 .name           = "ad7606-6",
86                 .driver_data    = ID_AD7606_6,
87         }, {
88                 .name           = "ad7606-4",
89                 .driver_data    = ID_AD7606_4,
90         },
91         { }
92 };
93
94 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
95
96 static struct platform_driver ad7606_driver = {
97         .probe = ad7606_par_probe,
98         .remove = ad7606_par_remove,
99         .id_table = ad7606_driver_ids,
100         .driver = {
101                 .name    = "ad7606",
102                 .pm      = AD7606_PM_OPS,
103         },
104 };
105
106 module_platform_driver(ad7606_driver);
107
108 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
109 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
110 MODULE_LICENSE("GPL v2");