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