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>
17 static int ad7606_par16_read_block(struct device *dev,
20 struct platform_device *pdev = to_platform_device(dev);
21 struct ad7606_state *st = platform_get_drvdata(pdev);
23 insw((unsigned long) st->base_address, buf, count);
28 static const struct ad7606_bus_ops ad7606_par16_bops = {
29 .read_block = ad7606_par16_read_block,
32 static int ad7606_par8_read_block(struct device *dev,
35 struct platform_device *pdev = to_platform_device(dev);
36 struct ad7606_state *st = platform_get_drvdata(pdev);
38 insb((unsigned long) st->base_address, buf, count * 2);
43 static const struct ad7606_bus_ops ad7606_par8_bops = {
44 .read_block = ad7606_par8_read_block,
47 static int __devinit ad7606_par_probe(struct platform_device *pdev)
50 struct ad7606_state *st;
52 resource_size_t remap_size;
55 irq = platform_get_irq(pdev, 0);
57 dev_err(&pdev->dev, "no irq\n");
61 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
65 remap_size = resource_size(res);
67 /* Request the regions */
68 if (!request_mem_region(res->start, remap_size, "iio-ad7606")) {
72 addr = ioremap(res->start, remap_size);
78 st = ad7606_probe(&pdev->dev, irq, addr,
79 platform_get_device_id(pdev)->driver_data,
80 remap_size > 1 ? &ad7606_par16_bops :
88 platform_set_drvdata(pdev, st);
95 release_mem_region(res->start, remap_size);
100 static int __devexit ad7606_par_remove(struct platform_device *pdev)
102 struct ad7606_state *st = platform_get_drvdata(pdev);
103 struct resource *res;
107 iounmap(st->base_address);
108 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
109 release_mem_region(res->start, resource_size(res));
111 platform_set_drvdata(pdev, NULL);
117 static int ad7606_par_suspend(struct device *dev)
119 struct ad7606_state *st = dev_get_drvdata(dev);
126 static int ad7606_par_resume(struct device *dev)
128 struct ad7606_state *st = dev_get_drvdata(dev);
135 static const struct dev_pm_ops ad7606_pm_ops = {
136 .suspend = ad7606_par_suspend,
137 .resume = ad7606_par_resume,
139 #define AD7606_PAR_PM_OPS (&ad7606_pm_ops)
142 #define AD7606_PAR_PM_OPS NULL
143 #endif /* CONFIG_PM */
145 static struct platform_device_id ad7606_driver_ids[] = {
148 .driver_data = ID_AD7606_8,
151 .driver_data = ID_AD7606_6,
154 .driver_data = ID_AD7606_4,
159 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
161 static struct platform_driver ad7606_driver = {
162 .probe = ad7606_par_probe,
163 .remove = __devexit_p(ad7606_par_remove),
164 .id_table = ad7606_driver_ids,
167 .owner = THIS_MODULE,
168 .pm = AD7606_PAR_PM_OPS,
172 static int __init ad7606_init(void)
174 return platform_driver_register(&ad7606_driver);
177 static void __exit ad7606_cleanup(void)
179 platform_driver_unregister(&ad7606_driver);
182 module_init(ad7606_init);
183 module_exit(ad7606_cleanup);
185 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
186 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
187 MODULE_LICENSE("GPL v2");
188 MODULE_ALIAS("platform:ad7606_par");