2 * AD7606 Parallel Interface ADC driver
4 * Copyright 2011 Analog Devices Inc.
6 * Licensed under the GPL-2.
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/types.h>
12 #include <linux/err.h>
15 #include <linux/iio/iio.h>
18 static int ad7606_par16_read_block(struct device
*dev
,
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
);
25 insw((unsigned long) st
->base_address
, buf
, count
);
30 static const struct ad7606_bus_ops ad7606_par16_bops
= {
31 .read_block
= ad7606_par16_read_block
,
34 static int ad7606_par8_read_block(struct device
*dev
,
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
);
41 insb((unsigned long) st
->base_address
, buf
, count
* 2);
46 static const struct ad7606_bus_ops ad7606_par8_bops
= {
47 .read_block
= ad7606_par8_read_block
,
50 static int __devinit
ad7606_par_probe(struct platform_device
*pdev
)
53 struct iio_dev
*indio_dev
;
55 resource_size_t remap_size
;
58 irq
= platform_get_irq(pdev
, 0);
60 dev_err(&pdev
->dev
, "no irq\n");
64 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
68 remap_size
= resource_size(res
);
70 /* Request the regions */
71 if (!request_mem_region(res
->start
, remap_size
, "iio-ad7606")) {
75 addr
= ioremap(res
->start
, remap_size
);
81 indio_dev
= ad7606_probe(&pdev
->dev
, irq
, addr
,
82 platform_get_device_id(pdev
)->driver_data
,
83 remap_size
> 1 ? &ad7606_par16_bops
:
86 if (IS_ERR(indio_dev
)) {
87 ret
= PTR_ERR(indio_dev
);
91 platform_set_drvdata(pdev
, indio_dev
);
98 release_mem_region(res
->start
, remap_size
);
103 static int __devexit
ad7606_par_remove(struct platform_device
*pdev
)
105 struct iio_dev
*indio_dev
= platform_get_drvdata(pdev
);
106 struct resource
*res
;
107 struct ad7606_state
*st
= iio_priv(indio_dev
);
109 ad7606_remove(indio_dev
, platform_get_irq(pdev
, 0));
111 iounmap(st
->base_address
);
112 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
113 release_mem_region(res
->start
, resource_size(res
));
115 platform_set_drvdata(pdev
, NULL
);
121 static int ad7606_par_suspend(struct device
*dev
)
123 struct iio_dev
*indio_dev
= dev_get_drvdata(dev
);
125 ad7606_suspend(indio_dev
);
130 static int ad7606_par_resume(struct device
*dev
)
132 struct iio_dev
*indio_dev
= dev_get_drvdata(dev
);
134 ad7606_resume(indio_dev
);
139 static const struct dev_pm_ops ad7606_pm_ops
= {
140 .suspend
= ad7606_par_suspend
,
141 .resume
= ad7606_par_resume
,
143 #define AD7606_PAR_PM_OPS (&ad7606_pm_ops)
146 #define AD7606_PAR_PM_OPS NULL
147 #endif /* CONFIG_PM */
149 static struct platform_device_id ad7606_driver_ids
[] = {
152 .driver_data
= ID_AD7606_8
,
155 .driver_data
= ID_AD7606_6
,
158 .driver_data
= ID_AD7606_4
,
163 MODULE_DEVICE_TABLE(platform
, ad7606_driver_ids
);
165 static struct platform_driver ad7606_driver
= {
166 .probe
= ad7606_par_probe
,
167 .remove
= __devexit_p(ad7606_par_remove
),
168 .id_table
= ad7606_driver_ids
,
171 .owner
= THIS_MODULE
,
172 .pm
= AD7606_PAR_PM_OPS
,
176 module_platform_driver(ad7606_driver
);
178 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
179 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
180 MODULE_LICENSE("GPL v2");