xref: /linux/drivers/iio/adc/ad7606_par.c (revision 95298d63c67673c654c08952672d016212b26054)
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/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/types.h>
11 #include <linux/err.h>
12 #include <linux/io.h>
13 
14 #include <linux/iio/iio.h>
15 #include "ad7606.h"
16 
17 static int ad7606_par16_read_block(struct device *dev,
18 				   int count, void *buf)
19 {
20 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
21 	struct ad7606_state *st = iio_priv(indio_dev);
22 
23 	insw((unsigned long)st->base_address, buf, count);
24 
25 	return 0;
26 }
27 
28 static const struct ad7606_bus_ops ad7606_par16_bops = {
29 	.read_block = ad7606_par16_read_block,
30 };
31 
32 static int ad7606_par8_read_block(struct device *dev,
33 				  int count, void *buf)
34 {
35 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
36 	struct ad7606_state *st = iio_priv(indio_dev);
37 
38 	insb((unsigned long)st->base_address, buf, count * 2);
39 
40 	return 0;
41 }
42 
43 static const struct ad7606_bus_ops ad7606_par8_bops = {
44 	.read_block = ad7606_par8_read_block,
45 };
46 
47 static int ad7606_par_probe(struct platform_device *pdev)
48 {
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;
54 
55 	irq = platform_get_irq(pdev, 0);
56 	if (irq < 0)
57 		return irq;
58 
59 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
60 	addr = devm_ioremap_resource(&pdev->dev, res);
61 	if (IS_ERR(addr))
62 		return PTR_ERR(addr);
63 
64 	remap_size = resource_size(res);
65 
66 	return ad7606_probe(&pdev->dev, irq, addr,
67 			    id->name, id->driver_data,
68 			    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