xref: /openbmc/linux/drivers/iio/adc/ad7606_par.c (revision 1f327613)
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 		dev_err(&pdev->dev, "no irq: %d\n", irq);
58 		return irq;
59 	}
60 
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);
65 
66 	remap_size = resource_size(res);
67 
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);
72 }
73 
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 	{ }
80 };
81 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
82 
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 	{ },
89 };
90 MODULE_DEVICE_TABLE(of, ad7606_of_match);
91 
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,
99 	},
100 };
101 module_platform_driver(ad7606_driver);
102 
103 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
104 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
105 MODULE_LICENSE("GPL v2");
106