2018-12-17 20:23:36 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-02-23 04:46:18 +08:00
|
|
|
/*
|
|
|
|
* AD7606 SPI ADC driver
|
|
|
|
*
|
|
|
|
* Copyright 2011 Analog Devices Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/err.h>
|
2011-05-18 21:42:01 +08:00
|
|
|
|
2012-04-25 22:54:58 +08:00
|
|
|
#include <linux/iio/iio.h>
|
2011-02-23 04:46:18 +08:00
|
|
|
#include "ad7606.h"
|
|
|
|
|
|
|
|
#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */
|
|
|
|
|
|
|
|
static int ad7606_spi_read_block(struct device *dev,
|
|
|
|
int count, void *buf)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
|
|
int i, ret;
|
2016-05-30 21:50:24 +08:00
|
|
|
unsigned short *data = buf;
|
2016-03-23 19:06:34 +08:00
|
|
|
__be16 *bdata = buf;
|
2011-02-23 04:46:18 +08:00
|
|
|
|
2014-10-30 19:32:25 +08:00
|
|
|
ret = spi_read(spi, buf, count * 2);
|
2011-02-23 04:46:18 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&spi->dev, "SPI read error\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2016-03-23 19:06:34 +08:00
|
|
|
data[i] = be16_to_cpu(bdata[i]);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ad7606_bus_ops ad7606_spi_bops = {
|
2018-12-17 20:23:38 +08:00
|
|
|
.read_block = ad7606_spi_read_block,
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
|
|
|
|
2012-11-20 02:21:57 +08:00
|
|
|
static int ad7606_spi_probe(struct spi_device *spi)
|
2011-02-23 04:46:18 +08:00
|
|
|
{
|
2016-10-20 01:06:57 +08:00
|
|
|
const struct spi_device_id *id = spi_get_device_id(spi);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
2016-10-20 01:07:04 +08:00
|
|
|
return ad7606_probe(&spi->dev, spi->irq, NULL,
|
|
|
|
id->name, id->driver_data,
|
|
|
|
&ad7606_spi_bops);
|
2011-02-23 04:46:18 +08:00
|
|
|
}
|
|
|
|
|
2018-12-17 20:23:38 +08:00
|
|
|
static const struct spi_device_id ad7606_id_table[] = {
|
|
|
|
{ "ad7605-4", ID_AD7605_4 },
|
|
|
|
{ "ad7606-4", ID_AD7606_4 },
|
|
|
|
{ "ad7606-6", ID_AD7606_6 },
|
|
|
|
{ "ad7606-8", ID_AD7606_8 },
|
2011-02-23 04:46:18 +08:00
|
|
|
{}
|
|
|
|
};
|
2018-12-17 20:23:38 +08:00
|
|
|
MODULE_DEVICE_TABLE(spi, ad7606_id_table);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
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 spi_driver ad7606_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ad7606",
|
2018-12-13 20:46:20 +08:00
|
|
|
.of_match_table = ad7606_of_match,
|
2016-02-08 18:13:29 +08:00
|
|
|
.pm = AD7606_PM_OPS,
|
2011-02-23 04:46:18 +08:00
|
|
|
},
|
|
|
|
.probe = ad7606_spi_probe,
|
2018-12-17 20:23:38 +08:00
|
|
|
.id_table = ad7606_id_table,
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
2011-11-16 17:13:39 +08:00
|
|
|
module_spi_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");
|