Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16

Linux/drivers/staging/iio/adc/ad7606_par.c

  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 
 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 
 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 
 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 ret, 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         if (!res)
 66                 return -ENODEV;
 67 
 68         remap_size = resource_size(res);
 69 
 70         /* Request the regions */
 71         if (!request_mem_region(res->start, remap_size, "iio-ad7606")) {
 72                 ret = -EBUSY;
 73                 goto out1;
 74         }
 75         addr = ioremap(res->start, remap_size);
 76         if (!addr) {
 77                 ret = -ENOMEM;
 78                 goto out1;
 79         }
 80 
 81         indio_dev = ad7606_probe(&pdev->dev, irq, addr,
 82                           platform_get_device_id(pdev)->driver_data,
 83                           remap_size > 1 ? &ad7606_par16_bops :
 84                           &ad7606_par8_bops);
 85 
 86         if (IS_ERR(indio_dev))  {
 87                 ret = PTR_ERR(indio_dev);
 88                 goto out2;
 89         }
 90 
 91         platform_set_drvdata(pdev, indio_dev);
 92 
 93         return 0;
 94 
 95 out2:
 96         iounmap(addr);
 97 out1:
 98         release_mem_region(res->start, remap_size);
 99 
100         return ret;
101 }
102 
103 static int ad7606_par_remove(struct platform_device *pdev)
104 {
105         struct iio_dev *indio_dev = platform_get_drvdata(pdev);
106         struct resource *res;
107         struct ad7606_state *st = iio_priv(indio_dev);
108 
109         ad7606_remove(indio_dev, platform_get_irq(pdev, 0));
110 
111         iounmap(st->base_address);
112         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
113         release_mem_region(res->start, resource_size(res));
114 
115         return 0;
116 }
117 
118 #ifdef CONFIG_PM
119 static int ad7606_par_suspend(struct device *dev)
120 {
121         struct iio_dev *indio_dev = dev_get_drvdata(dev);
122 
123         ad7606_suspend(indio_dev);
124 
125         return 0;
126 }
127 
128 static int ad7606_par_resume(struct device *dev)
129 {
130         struct iio_dev *indio_dev = dev_get_drvdata(dev);
131 
132         ad7606_resume(indio_dev);
133 
134         return 0;
135 }
136 
137 static const struct dev_pm_ops ad7606_pm_ops = {
138         .suspend = ad7606_par_suspend,
139         .resume  = ad7606_par_resume,
140 };
141 #define AD7606_PAR_PM_OPS (&ad7606_pm_ops)
142 
143 #else
144 #define AD7606_PAR_PM_OPS NULL
145 #endif  /* CONFIG_PM */
146 
147 static struct platform_device_id ad7606_driver_ids[] = {
148         {
149                 .name           = "ad7606-8",
150                 .driver_data    = ID_AD7606_8,
151         }, {
152                 .name           = "ad7606-6",
153                 .driver_data    = ID_AD7606_6,
154         }, {
155                 .name           = "ad7606-4",
156                 .driver_data    = ID_AD7606_4,
157         },
158         { }
159 };
160 
161 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
162 
163 static struct platform_driver ad7606_driver = {
164         .probe = ad7606_par_probe,
165         .remove = ad7606_par_remove,
166         .id_table = ad7606_driver_ids,
167         .driver = {
168                 .name    = "ad7606",
169                 .owner  = THIS_MODULE,
170                 .pm    = AD7606_PAR_PM_OPS,
171         },
172 };
173 
174 module_platform_driver(ad7606_driver);
175 
176 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
177 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
178 MODULE_LICENSE("GPL v2");
179 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us