From: Dumitru Ceclan <mitrutzceclan@gmail.com>
Cc: linus.walleij@linaro.org, brgl@bgdev.pl, andy@kernel.org,
linux-gpio@vger.kernel.org,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Jonathan Cameron" <jic23@kernel.org>,
"Rob Herring" <robh+dt@kernel.org>,
"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"ChiaEn Wu" <chiaen_wu@richtek.com>,
"Niklas Schnelle" <schnelle@linux.ibm.com>,
"Leonard Göhrs" <l.goehrs@pengutronix.de>,
"Mike Looijmans" <mike.looijmans@topic.nl>,
"Haibo Chen" <haibo.chen@nxp.com>,
"Hugo Villeneuve" <hvilleneuve@dimonoff.com>,
"Ceclan Dumitru" <dumitru.ceclan@analog.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Dumitru Ceclan" <mitrutzceclan@gmail.com>
Subject: [PATCH 2/2] iio: adc: ad7173: add support for additional models
Date: Mon, 15 Jan 2024 15:53:05 +0200 [thread overview]
Message-ID: <20240115135416.10595-3-mitrutzceclan@gmail.com> (raw)
In-Reply-To: <20240115135416.10595-1-mitrutzceclan@gmail.com>
Add support for Analog Devices AD7172-2, AD7175-8, AD7177-2
Signed-off-by: Dumitru Ceclan <mitrutzceclan@gmail.com>
---
drivers/iio/adc/ad7173.c | 76 ++++++++++++++++++++++++++++++++++++----
1 file changed, 69 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
index 7a7e8262f189..8ca9871cc9cb 100644
--- a/drivers/iio/adc/ad7173.c
+++ b/drivers/iio/adc/ad7173.c
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: GPL-2.0+
/*
- * AD7172-2/AD7173-8/AD7175-2/AD7176-2 SPI ADC driver
+ * AD717X family SPI ADC driver
+ *
+ * Suported devices:
+ * AD7172-2 AD7172-4 AD7173-8 AD7175-2 AD7175-8 AD7176-2 AD7177-2
+ *
* Copyright (C) 2015, 2023 Analog Devices, Inc.
*/
@@ -59,10 +63,13 @@
#define AD7173_AIN_TEMP_POS 17
#define AD7173_AIN_TEMP_NEG 18
-#define AD7172_ID 0x00d0
+#define AD7172_2_ID 0x00d0
+#define AD7172_4_ID 0x2050
#define AD7173_ID 0x30d0
-#define AD7175_ID 0x0cd0
+#define AD7175_2_ID 0x0cd0
+#define AD7175_8_ID 0x3cd0
#define AD7176_ID 0x0c90
+#define AD7177_ID 0x4fd0
#define AD7173_ID_MASK GENMASK(15, 4)
#define AD7173_ADC_MODE_REF_EN BIT(15)
@@ -104,15 +111,19 @@
#define AD7173_SETUP_REF_SEL_EXT_REF 0x0
#define AD7173_VOLTAGE_INT_REF_uV 2500000
#define AD7173_TEMP_SENSIIVITY_uV_per_C 477
+#define AD7177_ODR_START_VALUE 0x07
#define AD7173_FILTER_ODR0_MASK GENMASK(5, 0)
#define AD7173_MAX_CONFIGS 8
enum ad7173_ids {
ID_AD7172_2,
+ ID_AD7172_4,
ID_AD7173_8,
ID_AD7175_2,
+ ID_AD7175_8,
ID_AD7176_2,
+ ID_AD7177_2,
};
struct ad7173_device_info {
@@ -182,7 +193,7 @@ static const unsigned int ad7175_sinc5_data_rates[] = {
static const struct ad7173_device_info ad7173_device_info[] = {
[ID_AD7172_2] = {
.name = "ad7172-2",
- .id = AD7172_ID,
+ .id = AD7172_2_ID,
.num_inputs = 5,
.num_channels = 4,
.num_configs = 4,
@@ -192,6 +203,17 @@ static const struct ad7173_device_info ad7173_device_info[] = {
.sinc5_data_rates = ad7173_sinc5_data_rates,
.num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates),
},
+ [ID_AD7172_4] = {
+ .id = AD7172_4_ID,
+ .num_inputs = 9,
+ .num_channels = 8,
+ .num_configs = 8,
+ .num_gpios = 4,
+ .has_temp = false,
+ .clock = 2 * HZ_PER_MHZ,
+ .sinc5_data_rates = ad7173_sinc5_data_rates,
+ .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates),
+ },
[ID_AD7173_8] = {
.name = "ad7173-8",
.id = AD7173_ID,
@@ -206,7 +228,7 @@ static const struct ad7173_device_info ad7173_device_info[] = {
},
[ID_AD7175_2] = {
.name = "ad7175-2",
- .id = AD7175_ID,
+ .id = AD7175_2_ID,
.num_inputs = 5,
.num_channels = 4,
.num_configs = 4,
@@ -216,6 +238,17 @@ static const struct ad7173_device_info ad7173_device_info[] = {
.sinc5_data_rates = ad7175_sinc5_data_rates,
.num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates),
},
+ [ID_AD7175_8] = {
+ .id = AD7175_8_ID,
+ .num_inputs = 17,
+ .num_channels = 16,
+ .num_configs = 8,
+ .num_gpios = 4,
+ .has_temp = true,
+ .clock = 16 * HZ_PER_MHZ,
+ .sinc5_data_rates = ad7175_sinc5_data_rates,
+ .num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates),
+ },
[ID_AD7176_2] = {
.name = "ad7176-2",
.id = AD7176_ID,
@@ -228,6 +261,17 @@ static const struct ad7173_device_info ad7173_device_info[] = {
.sinc5_data_rates = ad7175_sinc5_data_rates,
.num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates),
},
+ [ID_AD7177_2] = {
+ .id = AD7177_ID,
+ .num_inputs = 5,
+ .num_channels = 4,
+ .num_configs = 4,
+ .num_gpios = 2,
+ .has_temp = true,
+ .clock = 16 * HZ_PER_MHZ,
+ .sinc5_data_rates = ad7175_sinc5_data_rates,
+ .num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates),
+ },
};
static const char *const ad7173_ref_sel_str[] = {
@@ -636,7 +680,10 @@ static int ad7173_write_raw(struct iio_dev *indio_dev,
switch (info) {
case IIO_CHAN_INFO_SAMP_FREQ:
freq = val * MILLI + val2 / MILLI;
- for (i = 0; i < st->info->num_sinc5_data_rates - 1; i++)
+ //AD7177-2 has the filter values [0-6] marked as reserved
+ // datasheet page 58
+ i = (st->info->id == AD7177_ID) ? AD7177_ODR_START_VALUE : 0;
+ for (; i < st->info->num_sinc5_data_rates - 1; i++)
if (freq >= st->info->sinc5_data_rates[i])
break;
@@ -844,8 +891,14 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
else
ref_sel = ret;
+ if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF &&
+ st->info->id == AD7172_2_ID){
+ fwnode_handle_put(child);
+ return dev_err_probe(dev, -EINVAL, "Internal reference is not available on ad7172-2\n");
+ }
+
if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 &&
- st->info->id != AD7173_ID) {
+ st->info->id != AD7173_ID && st->info->id != AD7172_2_ID) {
fwnode_handle_put(child);
return dev_err_probe(dev, -EINVAL, "External reference 2 is only available on ad7173-8\n");
}
@@ -939,21 +992,30 @@ static int ad7173_probe(struct spi_device *spi)
static const struct of_device_id ad7173_of_match[] = {
{ .compatible = "adi,ad7172-2",
.data = &ad7173_device_info[ID_AD7172_2]},
+ { .compatible = "adi,ad7172-4",
+ .data = &ad7173_device_info[ID_AD7172_4]},
{ .compatible = "adi,ad7173-8",
.data = &ad7173_device_info[ID_AD7173_8]},
{ .compatible = "adi,ad7175-2",
.data = &ad7173_device_info[ID_AD7175_2]},
+ { .compatible = "adi,ad7175-8",
+ .data = &ad7173_device_info[ID_AD7175_8]},
{ .compatible = "adi,ad7176-2",
.data = &ad7173_device_info[ID_AD7176_2]},
+ { .compatible = "adi,ad7177-2",
+ .data = &ad7173_device_info[ID_AD7177_2]},
{ }
};
MODULE_DEVICE_TABLE(of, ad7173_of_match);
static const struct spi_device_id ad7173_id_table[] = {
{ "ad7172-2", (kernel_ulong_t)&ad7173_device_info[ID_AD7172_2]},
+ { "ad7172-4", (kernel_ulong_t)&ad7173_device_info[ID_AD7172_4] },
{ "ad7173-8", (kernel_ulong_t)&ad7173_device_info[ID_AD7173_8]},
{ "ad7175-2", (kernel_ulong_t)&ad7173_device_info[ID_AD7175_2]},
+ { "ad7175-8", (kernel_ulong_t)&ad7173_device_info[ID_AD7175_8]},
{ "ad7176-2", (kernel_ulong_t)&ad7173_device_info[ID_AD7176_2]},
+ { "ad7177-2", (kernel_ulong_t)&ad7173_device_info[ID_AD7177_2]},
{ }
};
MODULE_DEVICE_TABLE(spi, ad7173_id_table);
--
2.42.0
next prev parent reply other threads:[~2024-01-15 13:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 13:53 [PATCH 0/2] Add support for additional AD717X models Dumitru Ceclan
2024-01-15 13:53 ` [PATCH 1/2] dt-bindings: adc: ad7173: add support for additional models Dumitru Ceclan
2024-01-15 16:10 ` Conor Dooley
2024-01-15 13:53 ` Dumitru Ceclan [this message]
2024-01-15 19:52 ` [PATCH 2/2] iio: " Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240115135416.10595-3-mitrutzceclan@gmail.com \
--to=mitrutzceclan@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=arnd@arndb.de \
--cc=brgl@bgdev.pl \
--cc=chiaen_wu@richtek.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dumitru.ceclan@analog.com \
--cc=haibo.chen@nxp.com \
--cc=hvilleneuve@dimonoff.com \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=l.goehrs@pengutronix.de \
--cc=lars@metafoo.de \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.looijmans@topic.nl \
--cc=robh+dt@kernel.org \
--cc=schnelle@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox