0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/mod_devicetable.h>
0009 #include <linux/module.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/types.h>
0012 #include <linux/err.h>
0013 #include <linux/io.h>
0014
0015 #include <linux/iio/iio.h>
0016 #include "ad7606.h"
0017
0018 static int ad7606_par16_read_block(struct device *dev,
0019 int count, void *buf)
0020 {
0021 struct iio_dev *indio_dev = dev_get_drvdata(dev);
0022 struct ad7606_state *st = iio_priv(indio_dev);
0023
0024 insw((unsigned long)st->base_address, buf, count);
0025
0026 return 0;
0027 }
0028
0029 static const struct ad7606_bus_ops ad7606_par16_bops = {
0030 .read_block = ad7606_par16_read_block,
0031 };
0032
0033 static int ad7606_par8_read_block(struct device *dev,
0034 int count, void *buf)
0035 {
0036 struct iio_dev *indio_dev = dev_get_drvdata(dev);
0037 struct ad7606_state *st = iio_priv(indio_dev);
0038
0039 insb((unsigned long)st->base_address, buf, count * 2);
0040
0041 return 0;
0042 }
0043
0044 static const struct ad7606_bus_ops ad7606_par8_bops = {
0045 .read_block = ad7606_par8_read_block,
0046 };
0047
0048 static int ad7606_par_probe(struct platform_device *pdev)
0049 {
0050 const struct platform_device_id *id = platform_get_device_id(pdev);
0051 struct resource *res;
0052 void __iomem *addr;
0053 resource_size_t remap_size;
0054 int irq;
0055
0056 irq = platform_get_irq(pdev, 0);
0057 if (irq < 0)
0058 return irq;
0059
0060 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0061 addr = devm_ioremap_resource(&pdev->dev, res);
0062 if (IS_ERR(addr))
0063 return PTR_ERR(addr);
0064
0065 remap_size = resource_size(res);
0066
0067 return ad7606_probe(&pdev->dev, irq, addr,
0068 id->name, id->driver_data,
0069 remap_size > 1 ? &ad7606_par16_bops :
0070 &ad7606_par8_bops);
0071 }
0072
0073 static const struct platform_device_id ad7606_driver_ids[] = {
0074 { .name = "ad7605-4", .driver_data = ID_AD7605_4, },
0075 { .name = "ad7606-4", .driver_data = ID_AD7606_4, },
0076 { .name = "ad7606-6", .driver_data = ID_AD7606_6, },
0077 { .name = "ad7606-8", .driver_data = ID_AD7606_8, },
0078 { }
0079 };
0080 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
0081
0082 static const struct of_device_id ad7606_of_match[] = {
0083 { .compatible = "adi,ad7605-4" },
0084 { .compatible = "adi,ad7606-4" },
0085 { .compatible = "adi,ad7606-6" },
0086 { .compatible = "adi,ad7606-8" },
0087 { },
0088 };
0089 MODULE_DEVICE_TABLE(of, ad7606_of_match);
0090
0091 static struct platform_driver ad7606_driver = {
0092 .probe = ad7606_par_probe,
0093 .id_table = ad7606_driver_ids,
0094 .driver = {
0095 .name = "ad7606",
0096 .pm = AD7606_PM_OPS,
0097 .of_match_table = ad7606_of_match,
0098 },
0099 };
0100 module_platform_driver(ad7606_driver);
0101
0102 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
0103 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
0104 MODULE_LICENSE("GPL v2");
0105 MODULE_IMPORT_NS(IIO_AD7606);