Commit bb9fc6ad authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

staging:iio:ad7606: Add support for the ad7605-4

Add support for the AD7605-4 to the AD7606 driver. The AD7605-4 is mostly
interface compatible to the AD7606-6 with the only difference being not
having support for oversampling.
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 6eb17c6c
...@@ -11,7 +11,7 @@ config AD7606 ...@@ -11,7 +11,7 @@ config AD7606
select IIO_TRIGGERED_BUFFER select IIO_TRIGGERED_BUFFER
help help
Say yes here to build support for Analog Devices: Say yes here to build support for Analog Devices:
ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC). ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called ad7606. module will be called ad7606.
......
...@@ -276,7 +276,7 @@ static const struct attribute_group ad7606_attribute_group_range = { ...@@ -276,7 +276,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
.attrs = ad7606_attributes_range, .attrs = ad7606_attributes_range,
}; };
#define AD7606_CHANNEL(num) \ #define AD760X_CHANNEL(num, mask) \
{ \ { \
.type = IIO_VOLTAGE, \ .type = IIO_VOLTAGE, \
.indexed = 1, \ .indexed = 1, \
...@@ -284,8 +284,7 @@ static const struct attribute_group ad7606_attribute_group_range = { ...@@ -284,8 +284,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
.address = num, \ .address = num, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
.info_mask_shared_by_all = \ .info_mask_shared_by_all = mask, \
BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
.scan_index = num, \ .scan_index = num, \
.scan_type = { \ .scan_type = { \
.sign = 's', \ .sign = 's', \
...@@ -295,6 +294,20 @@ static const struct attribute_group ad7606_attribute_group_range = { ...@@ -295,6 +294,20 @@ static const struct attribute_group ad7606_attribute_group_range = {
}, \ }, \
} }
#define AD7605_CHANNEL(num) \
AD760X_CHANNEL(num, 0)
#define AD7606_CHANNEL(num) \
AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
static const struct iio_chan_spec ad7605_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(4),
AD7605_CHANNEL(0),
AD7605_CHANNEL(1),
AD7605_CHANNEL(2),
AD7605_CHANNEL(3),
};
static const struct iio_chan_spec ad7606_channels[] = { static const struct iio_chan_spec ad7606_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(8), IIO_CHAN_SOFT_TIMESTAMP(8),
AD7606_CHANNEL(0), AD7606_CHANNEL(0),
...@@ -311,17 +324,24 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { ...@@ -311,17 +324,24 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
/* /*
* More devices added in future * More devices added in future
*/ */
[ID_AD7605_4] = {
.channels = ad7605_channels,
.num_channels = 5,
},
[ID_AD7606_8] = { [ID_AD7606_8] = {
.channels = ad7606_channels, .channels = ad7606_channels,
.num_channels = 9, .num_channels = 9,
.has_oversampling = true,
}, },
[ID_AD7606_6] = { [ID_AD7606_6] = {
.channels = ad7606_channels, .channels = ad7606_channels,
.num_channels = 7, .num_channels = 7,
.has_oversampling = true,
}, },
[ID_AD7606_4] = { [ID_AD7606_4] = {
.channels = ad7606_channels, .channels = ad7606_channels,
.num_channels = 5, .num_channels = 5,
.has_oversampling = true,
}, },
}; };
...@@ -352,6 +372,9 @@ static int ad7606_request_gpios(struct ad7606_state *st) ...@@ -352,6 +372,9 @@ static int ad7606_request_gpios(struct ad7606_state *st)
if (IS_ERR(st->gpio_frstdata)) if (IS_ERR(st->gpio_frstdata))
return PTR_ERR(st->gpio_frstdata); return PTR_ERR(st->gpio_frstdata);
if (!st->chip_info->has_oversampling)
return 0;
st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio", st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
GPIOD_OUT_LOW); GPIOD_OUT_LOW);
return PTR_ERR_OR_ZERO(st->gpio_os); return PTR_ERR_OR_ZERO(st->gpio_os);
...@@ -430,12 +453,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, ...@@ -430,12 +453,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
return ret; return ret;
} }
st->chip_info = &ad7606_chip_info_tbl[id];
ret = ad7606_request_gpios(st); ret = ad7606_request_gpios(st);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
st->chip_info = &ad7606_chip_info_tbl[id];
indio_dev->dev.parent = dev; indio_dev->dev.parent = dev;
if (st->gpio_os) { if (st->gpio_os) {
if (st->gpio_range) if (st->gpio_range)
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
* struct ad7606_chip_info - chip specific information * struct ad7606_chip_info - chip specific information
* @channels: channel specification * @channels: channel specification
* @num_channels: number of channels * @num_channels: number of channels
* @has_oversampling: whether the device has oversampling support
*/ */
struct ad7606_chip_info { struct ad7606_chip_info {
const struct iio_chan_spec *channels; const struct iio_chan_spec *channels;
unsigned int num_channels; unsigned int num_channels;
bool has_oversampling;
}; };
/** /**
...@@ -88,6 +90,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, ...@@ -88,6 +90,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
int ad7606_remove(struct device *dev, int irq); int ad7606_remove(struct device *dev, int irq);
enum ad7606_supported_device_ids { enum ad7606_supported_device_ids {
ID_AD7605_4,
ID_AD7606_8, ID_AD7606_8,
ID_AD7606_6, ID_AD7606_6,
ID_AD7606_4 ID_AD7606_4
......
...@@ -79,6 +79,9 @@ static int ad7606_par_remove(struct platform_device *pdev) ...@@ -79,6 +79,9 @@ static int ad7606_par_remove(struct platform_device *pdev)
static const struct platform_device_id ad7606_driver_ids[] = { static const struct platform_device_id ad7606_driver_ids[] = {
{ {
.name = "ad7605-4",
.driver_data = ID_AD7605_4,
}, {
.name = "ad7606-8", .name = "ad7606-8",
.driver_data = ID_AD7606_8, .driver_data = ID_AD7606_8,
}, { }, {
......
...@@ -55,6 +55,7 @@ static int ad7606_spi_remove(struct spi_device *spi) ...@@ -55,6 +55,7 @@ static int ad7606_spi_remove(struct spi_device *spi)
} }
static const struct spi_device_id ad7606_id[] = { static const struct spi_device_id ad7606_id[] = {
{"ad7605-4", ID_AD7605_4},
{"ad7606-8", ID_AD7606_8}, {"ad7606-8", ID_AD7606_8},
{"ad7606-6", ID_AD7606_6}, {"ad7606-6", ID_AD7606_6},
{"ad7606-4", ID_AD7606_4}, {"ad7606-4", ID_AD7606_4},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment