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(port: (unsigned long)st->base_address, addr: 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(port: (unsigned long)st->base_address, addr: buf, count: 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 | addr = devm_platform_get_and_ioremap_resource(pdev, index: 0, res: &res); |
61 | if (IS_ERR(ptr: addr)) |
62 | return PTR_ERR(ptr: addr); |
63 | |
64 | remap_size = resource_size(res); |
65 | |
66 | return ad7606_probe(dev: &pdev->dev, irq, base_address: addr, |
67 | name: id->name, id: id->driver_data, |
68 | bops: remap_size > 1 ? &ad7606_par16_bops : |
69 | &ad7606_par8_bops); |
70 | } |
71 | |
72 | static const struct platform_device_id ad7606_driver_ids[] = { |
73 | { .name = "ad7605-4" , .driver_data = ID_AD7605_4, }, |
74 | { .name = "ad7606-4" , .driver_data = ID_AD7606_4, }, |
75 | { .name = "ad7606-6" , .driver_data = ID_AD7606_6, }, |
76 | { .name = "ad7606-8" , .driver_data = ID_AD7606_8, }, |
77 | { } |
78 | }; |
79 | MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); |
80 | |
81 | static const struct of_device_id ad7606_of_match[] = { |
82 | { .compatible = "adi,ad7605-4" }, |
83 | { .compatible = "adi,ad7606-4" }, |
84 | { .compatible = "adi,ad7606-6" }, |
85 | { .compatible = "adi,ad7606-8" }, |
86 | { }, |
87 | }; |
88 | MODULE_DEVICE_TABLE(of, ad7606_of_match); |
89 | |
90 | static struct platform_driver ad7606_driver = { |
91 | .probe = ad7606_par_probe, |
92 | .id_table = ad7606_driver_ids, |
93 | .driver = { |
94 | .name = "ad7606" , |
95 | .pm = AD7606_PM_OPS, |
96 | .of_match_table = ad7606_of_match, |
97 | }, |
98 | }; |
99 | module_platform_driver(ad7606_driver); |
100 | |
101 | MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>" ); |
102 | MODULE_DESCRIPTION("Analog Devices AD7606 ADC" ); |
103 | MODULE_LICENSE("GPL v2" ); |
104 | MODULE_IMPORT_NS(IIO_AD7606); |
105 | |