Skip to contentSkip to conversation

iio:frequency:admv1014: add support for ADMV1014

PATCH Superseded Antoniu Miclaus 2 participants 6 messages Jan 27, 2022 – Jan 30, 2022

Subsystems (4)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Antoniu Miclaus

author maintainer
#0 lore raw

PATCH v4 1/4 iio:frequency:admv1014: add support for ADMV1014

The ADMV1014 is a silicon germanium (SiGe), wideband, microwave downconverter optimized for point to point microwave radio designs operating in the 24 GHz to 44 GHz frequency range.

Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADMV1014.pdf

---
changes in v4:
- make regulators mandatory
- use regulator bulk get/enable

 drivers/iio/frequency/Kconfig    |  10 +
 drivers/iio/frequency/Makefile   |   1 +
 drivers/iio/frequency/admv1014.c | 820 +++++++++++++++++++++++++++++++
 3 files changed, 831 insertions(+)
 create mode 100644 drivers/iio/frequency/admv1014.c
drivers/iio/frequency/Kconfig +10 -0
index 2c9e0559e8a4..493221f42077 100644
@@ -50,6 +50,16 @@ config ADF4371
 	  To compile this driver as a module, choose M here: the
 	  module will be called adf4371.
 
+config ADMV1014
+	tristate "Analog Devices ADMV1014 Microwave Downconverter"
+	depends on SPI && COMMON_CLK && 64BIT
+	help
+	  Say yes here to build support for Analog Devices ADMV1014
+	  24 GHz to 44 GHz, Wideband, Microwave Downconverter.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called admv1014.
+
 config ADRF6780
         tristate "Analog Devices ADRF6780 Microwave Upconverter"
         depends on SPI
drivers/iio/frequency/Makefile +1 -0
index ae3136c79202..5f0348e5eb53 100644
@@ -7,4 +7,5 @@
 obj-$(CONFIG_AD9523) += ad9523.o
 obj-$(CONFIG_ADF4350) += adf4350.o
 obj-$(CONFIG_ADF4371) += adf4371.o
+obj-$(CONFIG_ADMV1014) += admv1014.o
 obj-$(CONFIG_ADRF6780) += adrf6780.o
drivers/iio/frequency/admv1014.c new file +820 -0

820 lines not on this page · raw message

Signature · 1 line
2.35.0
author maintainer
#1 lore raw

PATCH v4 2/4 dt-bindings:iio:frequency: add admv1014 binding

Add device tree bindings for the ADMV1014 Upconverter.

---
changes in v4:
- add all regulators in the dts example

 .../bindings/iio/frequency/adi,admv1014.yaml  | 137 ++++++++++++++++++
 1 file changed, 137 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adi,admv1014.yaml
Documentation/devicetree/bindings/iio/frequency/adi,admv1014.yaml new file +137 -0
new file mode 100644
index 000000000000..fe352c01dd94
@@ -0,0 +1,137 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adi,admv1014.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ADMV1014 Microwave Downconverter
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+   Wideband, microwave downconverter optimized for point to point microwave
+   radio designs operating in the 24 GHz to 44 GHz frequency range.
+
+   https://www.analog.com/en/products/admv1014.html
+
+properties:
+  compatible:
+    enum:
+      - adi,admv1014
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 1000000
+
+  clocks:
+    minItems: 1
+
+  clock-names:
+    items:
+      - const: lo_in
+    description:
+      External clock that provides the Local Oscilator input.
+
+  vcm-supply:
+    description:
+      Common-mode voltage regulator.
+
+  vcc-if-bb-supply:
+    description:
+      BB and IF supply voltage regulator.
+
+  vcc-vga-supply:
+    description:
+      RF Amplifier supply voltage regulator.
+
+  vcc-vva-supply:
+    description:
+      VVA Control Circuit supply voltage regulator.
+
+  vcc-lna-3p3-supply:
+    description:
+      Low Noise Amplifier 3.3V supply voltage regulator.
+
+  vcc-lna-1p5-supply:
+    description:
+      Low Noise Amplifier 1.5V supply voltage regulator.
+
+  vcc-bg-supply:
+    description:
+      Band Gap Circuit supply voltage regulator.
+
+  vcc-quad-supply:
+    description:
+      Quadruple supply voltage regulator.
+
+  vcc-mixer-supply:
+    description:
+      Mixer supply voltage regulator.
+
+  adi,input-mode:
+    description:
+      Select the input mode.
+      iq - in-phase quadrature (I/Q) input
+      if - complex intermediate frequency (IF) input
+    enum: [iq, if]
+
+  adi,detector-enable:
+    description:
+      Digital Rx Detector Enable. The Square Law Detector output is
+      available at output pin VDET.
+    type: boolean
+
+  adi,p1db-compensation-enable:
+    description:
+      Turn on bits to optimize P1dB.
+    type: boolean
+
+  adi,quad-se-mode:
+    description:
+      Switch the LO path from differential to single-ended operation.
+      se-neg - Single-Ended Mode, Negative Side Disabled.
+      se-pos - Single-Ended Mode, Positive Side Disabled.
+      diff - Differential Mode.
+    enum: [se-neg, se-pos, diff]
+
+  '#clock-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - vcm-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      admv1014@0{
+        compatible = "adi,admv1014";
+        reg = <0>;
+        spi-max-frequency = <1000000>;
+        clocks = <&admv1014_lo>;
+        clock-names = "lo_in";
+        vcm-supply = <&vcm>;
+        vcc-if-bb-supply = <&vcc_if_bb>;
+        vcc-vga-supply = <&vcc_vga>;
+        vcc-vva-supply = <&vcc_vva>;
+        vcc-lna-3p3-supply = <&vcc_lna_3p3>;
+        vcc-lna-1p5-supply = <&vcc_lna_1p5>;
+        vcc-bg-supply = <&vcc_bg>;
+        vcc-quad-supply = <&vcc_quad>;
+        vcc-mixer-supply = <&vcc_mixer>;
+        adi,quad-se-mode = "diff";
+        adi,detector-enable;
+        adi,p1db-compensation-enable;
+      };
+    };
+...
Signature · 1 line
2.35.0
author maintainer
#2 lore raw

PATCH v4 3/4 Documentation:ABI:testing:admv1014: add ABI docs

In reply to Antoniu Miclaus

Add documentation for the use of the Digital Attenuator gain.

---
changes in v4:
- move in_altvoltage_calibscale to sysfs-bus-iio

 Documentation/ABI/testing/sysfs-bus-iio       |  7 ++++++
 .../testing/sysfs-bus-iio-frequency-admv1014  | 23 +++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-frequency-admv1014
Documentation/ABI/testing/sysfs-bus-iio +7 -0
index c551301b33f1..d7d96d3d6b7c 100644
@@ -476,6 +476,13 @@ What:		/sys/bus/iio/devices/iio:deviceX/in_voltageY_i_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltageY_q_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltage_i_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltage_q_calibscale
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage_calibscale
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Used in microwave converters to read/write value for the
+		digital attenuator gain (I/Q mode).
+
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltage_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_accel_x_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_accel_y_calibscale
Documentation/ABI/testing/sysfs-bus-iio-frequency-admv1014 new file +23 -0
new file mode 100644
index 000000000000..5bcd96d77f45
@@ -0,0 +1,23 @@
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_i_calibscale_coarse
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_I) with coarse steps.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_q_calibscale_coarse
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_Q) with coarse steps.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_i_calibscale_fine
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_I) with fine steps.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_q_calibscale_fine
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_Q) with fine steps.
Signature · 1 line
2.35.0
maintainer
#3 lore raw

Re: [PATCH v4 3/4] Documentation:ABI:testing:admv1014: add ABI docs

Quoted 16 lines · On Thu, 27 Jan 2022 12:55:57 +0200 Antoniu Miclaus…

Add documentation for the use of the Digital Attenuator gain.

---
changes in v4:
- move in_altvoltage_calibscale to sysfs-bus-iio

 Documentation/ABI/testing/sysfs-bus-iio       |  7 ++++++
 .../testing/sysfs-bus-iio-frequency-admv1014  | 23 +++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-frequency-admv1014
Documentation/ABI/testing/sysfs-bus-iio +0 -0
index c551301b33f1..d7d96d3d6b7c 100644

Documentation/ABI/testing/sysfs-bus-iio What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_i_calibscale · line 485

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio +7 -0
@@ -476,6 +476,13 @@ What:		/sys/bus/iio/devices/iio:deviceX/in_voltageY_i_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltageY_q_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltage_i_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltage_q_calibscale
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage_calibscale
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Used in microwave converters to read/write value for the
+		digital attenuator gain (I/Q mode).
+

You can't add description etc in the middle of a load of What: entries like this. Just add the What line. The generic description text should be sufficient.

Documentation/ABI/testing/sysfs-bus-iio-frequency-admv1014 line 2

Quoted 11 lines
Documentation/ABI/testing/sysfs-bus-iio +0 -0
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltage_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_accel_x_calibscale
 What:		/sys/bus/iio/devices/iio:deviceX/in_accel_y_calibscale
Documentation/ABI/testing/sysfs-bus-iio-frequency-admv1014 new file +2 -0
new file mode 100644
index 000000000000..5bcd96d77f45
@@ -0,0 +1,23 @@
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_i_calibscale_coarse
+KernelVersion:

Fill these in. If something odd happens to delay it getting merged I can fix them up, but I may well forget to fill them in if left empty. Basically make life easy for me in the common case. This 'should' be 5.18 material.

Quoted 21 lines
Documentation/ABI/testing/sysfs-bus-iio-frequency-admv1014 new file +21 -0
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_I) with coarse steps.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_q_calibscale_coarse
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_Q) with coarse steps.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_i_calibscale_fine
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_I) with fine steps.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltage0_q_calibscale_fine
+KernelVersion:
+Contact:	[email protected]
+Description:
+		Read/write value for the digital attenuator gain (IF_Q) with fine steps.
author maintainer
#4 lore raw

PATCH v4 4/4 MAINTAINERS: add maintainer for ADMV1014 driver

In reply to Antoniu Miclaus

Add myself as maintainer for the ADMV1014 driver.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 170bbbeefc3f..b05148cfd4aa 100644
@@ -1119,6 +1119,14 @@ W:	http://ez.analog.com/community/linux-device-drivers
 F:	Documentation/devicetree/bindings/hwmon/adi,adm1177.yaml
 F:	drivers/hwmon/adm1177.c
 
+ANALOG DEVICES INC ADMV1014 DRIVER
+M:	Antoniu Miclaus <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/iio/frequency/adi,admv1014.yaml
+F:	drivers/iio/frequency/admv1014.c
+
 ANALOG DEVICES INC ADP5061 DRIVER
 M:	Michael Hennerich <[email protected]>
 L:	[email protected]
Signature · 1 line
2.35.0
maintainer
#5 lore raw
In reply to Antoniu Miclaus
Quoted 10 lines · On Thu, 27 Jan 2022 12:55:55 +0200 Antoniu Miclaus…

The ADMV1014 is a silicon germanium (SiGe), wideband, microwave downconverter optimized for point to point microwave radio designs operating in the 24 GHz to 44 GHz frequency range.

Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADMV1014.pdf

---
changes in v4:
- make regulators mandatory
- use regulator bulk get/enable

The error handling and remove paths for these aren't correct. See inline.

So nearly there. I thought about fixing it up, but it's just beyond the boundary of the sort of change I'll make whilst applying. Sightly too complex.

Thanks,

Jonathan

Quoted 6 lines
 drivers/iio/frequency/Kconfig    |  10 +
 drivers/iio/frequency/Makefile   |   1 +
 drivers/iio/frequency/admv1014.c | 820 +++++++++++++++++++++++++++++++
 3 files changed, 831 insertions(+)
 create mode 100644 drivers/iio/frequency/admv1014.c

...

Quoted 6 lines
drivers/iio/frequency/admv1014.c new file +0 -0
new file mode 100644
index 000000000000..4ae422bd9bf4
@@ -0,0 +1,820 @@

...

drivers/iio/frequency/admv1014.c line 610

Quoted 10 lines
drivers/iio/frequency/admv1014.c new file +10 -0
+static int admv1014_init(struct admv1014_state *st)
+{
+	int ret;
+	unsigned int chip_id, enable_reg, enable_reg_msk;
+	struct spi_device *spi = st->spi;
+
+	ret = regulator_bulk_enable(ADMV1014_NUM_REGULATORS, st->regulators);
+	if (ret) {
+		dev_err(&spi->dev, "Failed to enable regulators");
+		goto error_disable_reg;

Firstly, you shouldn't be calling regulator_bulk_disable() if regulator_bulk_enable() has failed as like vast majority of such functions if it returns an error code it should have done it's own cleanup (disabled any regulators it had enable before the error happened)

Secondly there is no disabling of the regulators in error paths other than in this function or in the module remove path. Given everything else is managed you need a devm_add_action_or_reset() with appropriate callback to disable these regulators in both error and remove paths.

Quoted 82 lines
drivers/iio/frequency/admv1014.c new file +82 -0
+	}
+
+	ret = clk_prepare_enable(st->clkin);
+	if (ret)
+		goto error_disable_reg;
+
+	ret = devm_add_action_or_reset(&spi->dev, admv1014_clk_disable, st->clkin);
+	if (ret)
+		goto error_disable_reg;
+
+	st->nb.notifier_call = admv1014_freq_change;
+	ret = devm_clk_notifier_register(&spi->dev, st->clkin, &st->nb);
+	if (ret)
+		goto error_disable_reg;
+
+	ret = devm_add_action_or_reset(&spi->dev, admv1014_powerdown, st);
+	if (ret)
+		goto error_disable_reg;
+
+	/* Perform a software reset */
+	ret = __admv1014_spi_update_bits(st, ADMV1014_REG_SPI_CONTROL,
+					 ADMV1014_SPI_SOFT_RESET_MSK,
+					 FIELD_PREP(ADMV1014_SPI_SOFT_RESET_MSK, 1));
+	if (ret) {
+		dev_err(&spi->dev, "ADMV1014 SPI software reset failed.\n");
+		goto error_disable_reg;
+	}
+
+	ret = __admv1014_spi_update_bits(st, ADMV1014_REG_SPI_CONTROL,
+					 ADMV1014_SPI_SOFT_RESET_MSK,
+					 FIELD_PREP(ADMV1014_SPI_SOFT_RESET_MSK, 0));
+	if (ret) {
+		dev_err(&spi->dev, "ADMV1014 SPI software reset disable failed.\n");
+		goto error_disable_reg;
+	}
+
+	ret = __admv1014_spi_write(st, ADMV1014_REG_VVA_TEMP_COMP, 0x727C);
+	if (ret) {
+		dev_err(&spi->dev, "Writing default Temperature Compensation value failed.\n");
+		goto error_disable_reg;
+	}
+
+	ret = __admv1014_spi_read(st, ADMV1014_REG_SPI_CONTROL, &chip_id);
+	if (ret)
+		goto error_disable_reg;
+
+	chip_id = (chip_id & ADMV1014_CHIP_ID_MSK) >> 4;
+	if (chip_id != ADMV1014_CHIP_ID) {
+		dev_err(&spi->dev, "Invalid Chip ID.\n");
+		ret = -EINVAL;
+		goto error_disable_reg;
+	}
+
+	ret = __admv1014_spi_update_bits(st, ADMV1014_REG_QUAD,
+					 ADMV1014_QUAD_SE_MODE_MSK,
+					 FIELD_PREP(ADMV1014_QUAD_SE_MODE_MSK,
+						    st->quad_se_mode));
+	if (ret) {
+		dev_err(&spi->dev, "Writing Quad SE Mode failed.\n");
+		goto error_disable_reg;
+	}
+
+	ret = admv1014_update_quad_filters(st);
+	if (ret) {
+		dev_err(&spi->dev, "Update Quad Filters failed.\n");
+		goto error_disable_reg;
+	}
+
+	ret = admv1014_update_vcm_settings(st);
+	if (ret) {
+		dev_err(&spi->dev, "Update VCM Settings failed.\n");
+		goto error_disable_reg;
+	}
+
+	enable_reg_msk = ADMV1014_P1DB_COMPENSATION_MSK |
+			 ADMV1014_IF_AMP_PD_MSK |
+			 ADMV1014_BB_AMP_PD_MSK |
+			 ADMV1014_DET_EN_MSK;
+
+	enable_reg = FIELD_PREP(ADMV1014_P1DB_COMPENSATION_MSK, st->p1db_comp ? 3 : 0) |
+		     FIELD_PREP(ADMV1014_IF_AMP_PD_MSK, !(st->input_mode)) |
+		     FIELD_PREP(ADMV1014_BB_AMP_PD_MSK, st->input_mode) |

drivers/iio/frequency/admv1014.c line 702

Quoted 10 lines
drivers/iio/frequency/admv1014.c new file +10 -0
+		     FIELD_PREP(ADMV1014_DET_EN_MSK, st->det_en);
+
+	ret = __admv1014_spi_update_bits(st, ADMV1014_REG_ENABLE, enable_reg_msk, enable_reg);
+	if (ret)
+		goto error_disable_reg;
+
+	return 0;
+
+error_disable_reg:
+	regulator_bulk_disable(ADMV1014_NUM_REGULATORS, st->regulators);

This now doesn't happen in the remove path.

you need to use a devm_add_action_or_reset() with appropriate callback to clean these up.

Quoted 4 lines
drivers/iio/frequency/admv1014.c new file +4 -0
+
+	return ret;
+}
+

...

Quoted 26 lines
drivers/iio/frequency/admv1014.c new file +26 -0
+static int admv1014_probe(struct spi_device *spi)
+{
+	struct iio_dev *indio_dev;
+	struct admv1014_state *st;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+
+	ret = admv1014_properties_parse(st);
+	if (ret)
+		return ret;
+
+	indio_dev->info = &admv1014_info;
+	indio_dev->name = "admv1014";
+
+	if (st->input_mode == ADMV1014_IQ_MODE) {
+		indio_dev->channels = admv1014_channels_iq;
+		indio_dev->num_channels = ARRAY_SIZE(admv1014_channels_iq);
+	} else {
+		indio_dev->channels = admv1014_channels_if;
+		indio_dev->num_channels = ARRAY_SIZE(admv1014_channels_if);
+	}

drivers/iio/frequency/admv1014.c line 793

Quoted 10 lines
drivers/iio/frequency/admv1014.c new file +10 -0
+
+	st->spi = spi;
+
+	mutex_init(&st->lock);
+
+	ret = admv1014_init(st);
+	if (ret)
+		return ret;
+
+	return devm_iio_device_register(&spi->dev, indio_dev);

If this call fails regulators are left on. If you use devm_add_action_or_reset() magic then they won't be as that callback will get called in the error handling for the function that called probe()

Quoted 2 lines
drivers/iio/frequency/admv1014.c new file +2 -0
+}
+