• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
ad7606_par16_read_block(struct device * dev,int count,void * buf)18 static int ad7606_par16_read_block(struct device *dev,
19 				   int count, void *buf)
20 {
21 	struct platform_device *pdev = to_platform_device(dev);
22 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
23 	struct ad7606_state *st = iio_priv(indio_dev);
24 
25 	insw((unsigned long)st->base_address, buf, count);
26 
27 	return 0;
28 }
29 
30 static const struct ad7606_bus_ops ad7606_par16_bops = {
31 	.read_block	= ad7606_par16_read_block,
32 };
33 
ad7606_par8_read_block(struct device * dev,int count,void * buf)34 static int ad7606_par8_read_block(struct device *dev,
35 				  int count, void *buf)
36 {
37 	struct platform_device *pdev = to_platform_device(dev);
38 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
39 	struct ad7606_state *st = iio_priv(indio_dev);
40 
41 	insb((unsigned long)st->base_address, buf, count * 2);
42 
43 	return 0;
44 }
45 
46 static const struct ad7606_bus_ops ad7606_par8_bops = {
47 	.read_block	= ad7606_par8_read_block,
48 };
49 
ad7606_par_probe(struct platform_device * pdev)50 static int ad7606_par_probe(struct platform_device *pdev)
51 {
52 	struct resource *res;
53 	struct iio_dev *indio_dev;
54 	void __iomem *addr;
55 	resource_size_t remap_size;
56 	int irq;
57 
58 	irq = platform_get_irq(pdev, 0);
59 	if (irq < 0) {
60 		dev_err(&pdev->dev, "no irq\n");
61 		return -ENODEV;
62 	}
63 
64 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
65 	addr = devm_ioremap_resource(&pdev->dev, res);
66 	if (IS_ERR(addr))
67 		return PTR_ERR(addr);
68 
69 	remap_size = resource_size(res);
70 
71 	indio_dev = ad7606_probe(&pdev->dev, irq, addr,
72 				 platform_get_device_id(pdev)->driver_data,
73 				 remap_size > 1 ? &ad7606_par16_bops :
74 				 &ad7606_par8_bops);
75 
76 	if (IS_ERR(indio_dev))
77 		return PTR_ERR(indio_dev);
78 
79 	platform_set_drvdata(pdev, indio_dev);
80 
81 	return 0;
82 }
83 
ad7606_par_remove(struct platform_device * pdev)84 static int ad7606_par_remove(struct platform_device *pdev)
85 {
86 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
87 
88 	ad7606_remove(indio_dev, platform_get_irq(pdev, 0));
89 
90 	return 0;
91 }
92 
93 #ifdef CONFIG_PM
ad7606_par_suspend(struct device * dev)94 static int ad7606_par_suspend(struct device *dev)
95 {
96 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
97 
98 	ad7606_suspend(indio_dev);
99 
100 	return 0;
101 }
102 
ad7606_par_resume(struct device * dev)103 static int ad7606_par_resume(struct device *dev)
104 {
105 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
106 
107 	ad7606_resume(indio_dev);
108 
109 	return 0;
110 }
111 
112 static const struct dev_pm_ops ad7606_pm_ops = {
113 	.suspend = ad7606_par_suspend,
114 	.resume  = ad7606_par_resume,
115 };
116 
117 #define AD7606_PAR_PM_OPS (&ad7606_pm_ops)
118 
119 #else
120 #define AD7606_PAR_PM_OPS NULL
121 #endif  /* CONFIG_PM */
122 
123 static const struct platform_device_id ad7606_driver_ids[] = {
124 	{
125 		.name		= "ad7606-8",
126 		.driver_data	= ID_AD7606_8,
127 	}, {
128 		.name		= "ad7606-6",
129 		.driver_data	= ID_AD7606_6,
130 	}, {
131 		.name		= "ad7606-4",
132 		.driver_data	= ID_AD7606_4,
133 	},
134 	{ }
135 };
136 
137 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
138 
139 static struct platform_driver ad7606_driver = {
140 	.probe = ad7606_par_probe,
141 	.remove	= ad7606_par_remove,
142 	.id_table = ad7606_driver_ids,
143 	.driver = {
144 		.name	 = "ad7606",
145 		.pm    = AD7606_PAR_PM_OPS,
146 	},
147 };
148 
149 module_platform_driver(ad7606_driver);
150 
151 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
152 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
153 MODULE_LICENSE("GPL v2");
154