2018-12-17 20:23:36 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-02-23 04:46:18 +08:00
|
|
|
/*
|
|
|
|
* AD7606 Parallel Interface ADC driver
|
|
|
|
*
|
|
|
|
* Copyright 2011 Analog Devices Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
|
2012-04-25 22:54:58 +08:00
|
|
|
#include <linux/iio/iio.h>
|
2011-02-23 04:46:18 +08:00
|
|
|
#include "ad7606.h"
|
|
|
|
|
|
|
|
static int ad7606_par16_read_block(struct device *dev,
|
2015-10-15 02:14:13 +08:00
|
|
|
int count, void *buf)
|
2011-02-23 04:46:18 +08:00
|
|
|
{
|
2018-04-19 22:06:18 +08:00
|
|
|
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
2011-05-18 21:42:01 +08:00
|
|
|
struct ad7606_state *st = iio_priv(indio_dev);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
2015-10-15 02:14:15 +08:00
|
|
|
insw((unsigned long)st->base_address, buf, count);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ad7606_bus_ops ad7606_par16_bops = {
|
2018-12-17 20:23:38 +08:00
|
|
|
.read_block = ad7606_par16_read_block,
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ad7606_par8_read_block(struct device *dev,
|
2015-10-15 02:14:13 +08:00
|
|
|
int count, void *buf)
|
2011-02-23 04:46:18 +08:00
|
|
|
{
|
2018-04-19 22:06:18 +08:00
|
|
|
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
2011-05-18 21:42:01 +08:00
|
|
|
struct ad7606_state *st = iio_priv(indio_dev);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
2015-10-15 02:14:15 +08:00
|
|
|
insb((unsigned long)st->base_address, buf, count * 2);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ad7606_bus_ops ad7606_par8_bops = {
|
2018-12-17 20:23:38 +08:00
|
|
|
.read_block = ad7606_par8_read_block,
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
|
|
|
|
2012-11-20 02:21:57 +08:00
|
|
|
static int ad7606_par_probe(struct platform_device *pdev)
|
2011-02-23 04:46:18 +08:00
|
|
|
{
|
2016-10-20 01:06:57 +08:00
|
|
|
const struct platform_device_id *id = platform_get_device_id(pdev);
|
2011-02-23 04:46:18 +08:00
|
|
|
struct resource *res;
|
|
|
|
void __iomem *addr;
|
|
|
|
resource_size_t remap_size;
|
2014-01-08 03:44:00 +08:00
|
|
|
int irq;
|
2011-02-23 04:46:18 +08:00
|
|
|
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
2019-07-31 02:15:19 +08:00
|
|
|
if (irq < 0)
|
2017-08-09 23:38:56 +08:00
|
|
|
return irq;
|
2011-02-23 04:46:18 +08:00
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2014-01-08 03:44:00 +08:00
|
|
|
addr = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(addr))
|
|
|
|
return PTR_ERR(addr);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
|
|
|
remap_size = resource_size(res);
|
|
|
|
|
2016-10-20 01:07:04 +08:00
|
|
|
return ad7606_probe(&pdev->dev, irq, addr,
|
|
|
|
id->name, id->driver_data,
|
|
|
|
remap_size > 1 ? &ad7606_par16_bops :
|
|
|
|
&ad7606_par8_bops);
|
2011-02-23 04:46:18 +08:00
|
|
|
}
|
|
|
|
|
2015-05-01 23:43:22 +08:00
|
|
|
static const struct platform_device_id ad7606_driver_ids[] = {
|
2018-12-17 20:23:38 +08:00
|
|
|
{ .name = "ad7605-4", .driver_data = ID_AD7605_4, },
|
|
|
|
{ .name = "ad7606-4", .driver_data = ID_AD7606_4, },
|
|
|
|
{ .name = "ad7606-6", .driver_data = ID_AD7606_6, },
|
|
|
|
{ .name = "ad7606-8", .driver_data = ID_AD7606_8, },
|
2011-02-23 04:46:18 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
|
|
|
|
|
2018-12-13 20:46:20 +08:00
|
|
|
static const struct of_device_id ad7606_of_match[] = {
|
|
|
|
{ .compatible = "adi,ad7605-4" },
|
|
|
|
{ .compatible = "adi,ad7606-4" },
|
|
|
|
{ .compatible = "adi,ad7606-6" },
|
|
|
|
{ .compatible = "adi,ad7606-8" },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, ad7606_of_match);
|
|
|
|
|
2011-02-23 04:46:18 +08:00
|
|
|
static struct platform_driver ad7606_driver = {
|
|
|
|
.probe = ad7606_par_probe,
|
|
|
|
.id_table = ad7606_driver_ids,
|
|
|
|
.driver = {
|
2018-12-17 20:23:38 +08:00
|
|
|
.name = "ad7606",
|
|
|
|
.pm = AD7606_PM_OPS,
|
2018-12-13 20:46:20 +08:00
|
|
|
.of_match_table = ad7606_of_match,
|
2011-02-23 04:46:18 +08:00
|
|
|
},
|
|
|
|
};
|
2012-03-01 17:51:05 +08:00
|
|
|
module_platform_driver(ad7606_driver);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
2018-08-14 19:23:17 +08:00
|
|
|
MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
|
2011-02-23 04:46:18 +08:00
|
|
|
MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
|
|
|
|
MODULE_LICENSE("GPL v2");
|