Skip to contentSkip to conversation

Add ADRF5740 driver

PATCH Superseded Ana-Maria Cusco 3 participants 5 messages Nov 7, 2023 – Nov 9, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add ADRF5740 driver

From: Ana-Maria Cusco <[email protected]>

This patch series adds support for the ADRF5740 Attenuator within the existing HMC425A driver.

The ADRF5740 is a silicon, 4-bit digital attenuator with 22 dB attenuation control range in 2 dB steps.
It offers parallel control mode through four digitally controlled inputs.

V1 -> V2:
* dt-bindings: arrange entry in alphabetical order
* improve title clarity

Ana-Maria Cusco (2):
iio: amplifiers: hmc425a: add support for ADRF5740 Attenuator
dt-bindings: iio: hmc425a: add entry for ADRF5740 Attenuator

 .../bindings/iio/amplifiers/adi,hmc425a.yaml  |  4 ++++
 drivers/iio/amplifiers/hmc425a.c              | 23 +++++++++++++++++++
 2 files changed, 27 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 iio: amplifiers: hmc425a: add support for ADRF5740 Attenuator

From: Ana-Maria Cusco <[email protected]>

This adds support for the Analog Devices ADRF5740 2 dB LSB, 4-Bit, Silicon Digital Attenuator, 10 MHz to 60 GHz

---
 drivers/iio/amplifiers/hmc425a.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/iio/amplifiers/hmc425a.c +23 -0
index e87d35d50a95..ed4d72922696 100644
@@ -5,6 +5,7 @@
  * Copyright 2020 Analog Devices Inc.
  */
 
+#include <linux/bitops.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
@@ -22,6 +23,7 @@
 enum hmc425a_type {
 	ID_HMC425A,
 	ID_HMC540S,
+	ID_ADRF5740
 };
 
 struct hmc425a_chip_info {
@@ -74,6 +76,10 @@ static int hmc425a_read_raw(struct iio_dev *indio_dev,
 		case ID_HMC540S:
 			gain = ~code * -1000;
 			break;
+		case ID_ADRF5740:
+			code = code & BIT(3) ? code & ~BIT(2) : code;
+			gain = code * -2000;
+			break;
 		}
 
 		*val = gain / 1000;
@@ -113,6 +119,10 @@ static int hmc425a_write_raw(struct iio_dev *indio_dev,
 	case ID_HMC540S:
 		code = ~((abs(gain) / 1000) & 0xF);
 		break;
+	case ID_ADRF5740:
+		code = (abs(gain) / 2000) & 0xF;
+		code = code & BIT(3) ? code | BIT(2) : code;
+		break;
 	}
 
 	mutex_lock(&st->lock);
@@ -165,6 +175,7 @@ static const struct iio_chan_spec hmc425a_channels[] = {
 static const struct of_device_id hmc425a_of_match[] = {
 	{ .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A },
 	{ .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S },
+	{ .compatible = "adi,adrf5740", .data = (void *)ID_ADRF5740 },
 	{},
 };
 MODULE_DEVICE_TABLE(of, hmc425a_of_match);
@@ -188,6 +199,15 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = {
 		.gain_max = 0,
 		.default_gain = -0x10, /* set default gain -15.0db*/
 	},
+	[ID_ADRF5740] = {
+		.name = "adrf5740",
+		.channels = hmc425a_channels,
+		.num_channels = ARRAY_SIZE(hmc425a_channels),
+		.num_gpios = 4,
+		.gain_min = -22000,
+		.gain_max = 0,
+		.default_gain = 0xF, /* set default gain -22.0db*/
+	},
 };
 
 static int hmc425a_probe(struct platform_device *pdev)
@@ -229,6 +249,9 @@ static int hmc425a_probe(struct platform_device *pdev)
 	indio_dev->info = &hmc425a_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
+	/* Set default gain */
+	hmc425a_write(indio_dev, st->gain);
+
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }
 
Signature · 1 line
2.34.1
Reviewed-by Nuno Sa on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] iio: amplifiers: hmc425a: add support for ADRF5740 Attenuator

Quoted 82 lines · Ana-Maria Cusco

From: Ana-Maria Cusco <[email protected]>

This adds support for the Analog Devices ADRF5740 2 dB LSB, 4-Bit, Silicon Digital Attenuator, 10 MHz to 60 GHz

---
 drivers/iio/amplifiers/hmc425a.c | 23 +++++++++++++++++++++++

 1 file changed, 23 insertions(+)
drivers/iio/amplifiers/hmc425a.c +0 -0
index e87d35d50a95..ed4d72922696 100644
@@ -5,6 +5,7 @@
   * Copyright 2020 Analog Devices Inc.
   */


+#include <linux/bitops.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>

drivers/iio/amplifiers/hmc425a.c +1 -0
@@ -22,6 +23,7 @@
  enum hmc425a_type {
  	ID_HMC425A,
  	ID_HMC540S,
+	ID_ADRF5740
  };


 struct hmc425a_chip_info {

drivers/iio/amplifiers/hmc425a.c +0 -0
@@ -74,6 +76,10 @@ static int hmc425a_read_raw(struct iio_dev *indio_dev,

  case ID_HMC540S:
  gain = ~code * -1000;
  break;

drivers/iio/amplifiers/hmc425a.c +4 -0
+		case ID_ADRF5740:
+			code = code & BIT(3) ? code & ~BIT(2) : code;
+			gain = code * -2000;
+			break;

  }

  *val = gain / 1000;

drivers/iio/amplifiers/hmc425a.c +0 -0
@@ -113,6 +119,10 @@ static int hmc425a_write_raw(struct iio_dev *indio_dev,

  case ID_HMC540S:
  code = ~((abs(gain) / 1000) & 0xF); break;

drivers/iio/amplifiers/hmc425a.c +4 -0
+	case ID_ADRF5740:
+		code = (abs(gain) / 2000) & 0xF;
+		code = code & BIT(3) ? code | BIT(2) : code;
+		break;

  }

  mutex_lock(&st->lock);

drivers/iio/amplifiers/hmc425a.c +1 -0
@@ -165,6 +175,7 @@ static const struct iio_chan_spec hmc425a_channels[] = {
  static const struct of_device_id hmc425a_of_match[] = {
  	{ .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A },
  	{ .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S },
+	{ .compatible = "adi,adrf5740", .data = (void *)ID_ADRF5740 },
  	{},
  };
  MODULE_DEVICE_TABLE(of, hmc425a_of_match);
@@ -188,6 +199,15 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] =
 {
  		.gain_max = 0,

  .default_gain = -0x10, /* set default gain -15.0db*/ },

drivers/iio/amplifiers/hmc425a.c +9 -0
+	[ID_ADRF5740] = {
+		.name = "adrf5740",
+		.channels = hmc425a_channels,
+		.num_channels = ARRAY_SIZE(hmc425a_channels),
+		.num_gpios = 4,
+		.gain_min = -22000,
+		.gain_max = 0,
+		.default_gain = 0xF, /* set default gain -22.0db*/
+	},

 };

 static int hmc425a_probe(struct platform_device *pdev)

drivers/iio/amplifiers/hmc425a.c +0 -0
@@ -229,6 +249,9 @@ static int hmc425a_probe(struct platform_device *pdev)
  	indio_dev->info = &hmc425a_info;
  	indio_dev->modes = INDIO_DIRECT_MODE;

drivers/iio/amplifiers/hmc425a.c static int hmc425a_probe(struct platform_device *pdev) · line 254

Quoted 3 lines
drivers/iio/amplifiers/hmc425a.c +3 -0
+	/* Set default gain */
+	hmc425a_write(indio_dev, st->gain);
+

This is an unrelated change. It's simple enough to sneak it in but you should at least mention it in the commit message.

With that,

#3 lore raw

PATCH v2 2/2 dt-bindings: iio: hmc425a: add entry for ADRF5740 Attenuator

In reply to Ana-Maria Cusco

From: Ana-Maria Cusco <[email protected]>

The ADRF5740 is a silicon, 4-bit digital attenuator with 22 dB attenuation control range in 2 dB steps.

---
 .../devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml       | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/iio/amplifiers/adi,hmc425a.yaml +4 -0
index 2ee6080deac7..67de9d4e3a1d 100644
@@ -12,6 +12,9 @@ maintainers:
 description: |
   Digital Step Attenuator IIO devices with gpio interface.
   Offer various frequency and attenuation ranges.
+  ADRF5750 2 dB LSB, 4-Bit, Silicon Digital Attenuator, 10 MHz to 60 GHz
+    https://www.analog.com/media/en/technical-documentation/data-sheets/adrf5740.pdf
+
   HMC425A 0.5 dB LSB GaAs MMIC 6-BIT DIGITAL POSITIVE CONTROL ATTENUATOR, 2.2 - 8.0 GHz
     https://www.analog.com/media/en/technical-documentation/data-sheets/hmc425A.pdf
 
@@ -22,6 +25,7 @@ description: |
 properties:
   compatible:
     enum:
+      - adi,adrf5740
       - adi,hmc425a
       - adi,hmc540s
 
Signature · 1 line
2.34.1