Skip to contentSkip to conversation

iio: frequency: adrf6780: add support for ADRF6780

PATCH Superseded Antoniu Miclaus 2 participants 3 messages Oct 11, 2021 – Oct 17, 2021

Subsystems (4)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Antoniu Miclaus

author maintainer
#0 lore raw

PATCH v7 1/2 iio: frequency: adrf6780: add support for ADRF6780

The ADRF6780 is a silicon germanium (SiGe) design, wideband, microwave upconverter optimized for point to point microwave radio designs operating in the 5.9 GHz to 23.6 GHz frequency range.

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

---
changes in v7:
- add device remove path and disable all circuitry controlled via Enable Register.
- rename adrf6780_dt_parse -> adrf6780_properties_parse

 drivers/iio/frequency/Kconfig    |  12 +
 drivers/iio/frequency/Makefile   |   1 +
 drivers/iio/frequency/adrf6780.c | 503 +++++++++++++++++++++++++++++++
 3 files changed, 516 insertions(+)
 create mode 100644 drivers/iio/frequency/adrf6780.c
drivers/iio/frequency/Kconfig +12 -0
index 240b81502512..2c9e0559e8a4 100644
@@ -49,5 +49,17 @@ config ADF4371
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called adf4371.
+
+config ADRF6780
+        tristate "Analog Devices ADRF6780 Microwave Upconverter"
+        depends on SPI
+        depends on COMMON_CLK
+        help
+          Say yes here to build support for Analog Devices ADRF6780
+          5.9 GHz to 23.6 GHz, Wideband, Microwave Upconverter.
+
+          To compile this driver as a module, choose M here: the
+          module will be called adrf6780.
+
 endmenu
 endmenu
drivers/iio/frequency/Makefile +1 -0
index 518b1e50caef..ae3136c79202 100644
@@ -7,3 +7,4 @@
 obj-$(CONFIG_AD9523) += ad9523.o
 obj-$(CONFIG_ADF4350) += adf4350.o
 obj-$(CONFIG_ADF4371) += adf4371.o
+obj-$(CONFIG_ADRF6780) += adrf6780.o
drivers/iio/frequency/adrf6780.c new file +503 -0

503 lines not on this page · raw message

Signature · 1 line
2.33.0
author maintainer
#1 lore raw

PATCH v7 2/2 dt-bindings: iio: frequency: add adrf6780 doc

Add device tree bindings for the ADRF6780 Upconverter.

---
changes in v7:
- improve description of the device properties based on the feedback received from the datasheet people

 .../bindings/iio/frequency/adi,adrf6780.yaml  | 131 ++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adi,adrf6780.yaml
Documentation/devicetree/bindings/iio/frequency/adi,adrf6780.yaml new file +131 -0
new file mode 100644
index 000000000000..3a8ea93f4e0c
@@ -0,0 +1,131 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adi,adrf6780.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ADRF6780 Microwave Upconverter
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+   Wideband, microwave upconverter optimized for point to point microwave
+   radio designs operating in the 5.9 GHz to 23.6 GHz frequency range.
+
+   https://www.analog.com/en/products/adrf6780.html
+
+properties:
+  compatible:
+    enum:
+      - adi,adrf6780
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 1000000
+
+  clocks:
+    description:
+      Definition of the external clock.
+    minItems: 1
+
+  clock-names:
+    items:
+      - const: lo_in
+
+  clock-output-names:
+    maxItems: 1
+
+  adi,vga-buff-en:
+    description:
+      RF Variable Gain Amplifier Buffer Enable. Gain is controlled by
+      the voltage on the VATT pin.
+    type: boolean
+
+  adi,lo-buff-en:
+    description:
+      Local Oscillator Amplifier Enable. Disable to put the part in
+      a power down state.
+    type: boolean
+
+  adi,if-mode-en:
+    description:
+      Intermediate Frequency Mode Enable. Either IF Mode or I/Q Mode
+      can be enabled at a time.
+    type: boolean
+
+  adi,iq-mode-en:
+    description:
+      I/Q Mode Enable. Either IF Mode or I/Q Mode can be enabled at a
+      time.
+    type: boolean
+
+  adi,lo-x2-en:
+    description:
+      Double the Local Oscillator output frequency from the Local
+      Oscillator Input Frequency. Either LOx1 or LOx2 can be enabled
+      at a time.
+    type: boolean
+
+  adi,lo-ppf-en:
+    description:
+      Local Oscillator input frequency equal to the Local Oscillator
+      output frequency (LO x1). Either LOx1 or LOx2 can be enabled
+      at a time.
+    type: boolean
+
+  adi,lo-en:
+    description:
+      Enable additional cirtuitry in the LO chain. Disable to put the
+      part in a power down state.
+    type: boolean
+
+  adi,uc-bias-en:
+    description:
+      Enable all bias circuitry thourghout the entire part.
+      Disable to put the part in a power down state.
+    type: boolean
+
+  adi,lo-sideband:
+    description:
+      Switch to the Lower LO Sideband. By default the Upper LO
+      sideband is enabled.
+    type: boolean
+
+  adi,vdet-out-en:
+    description:
+      VDET Output Select Enable. Expose the RF detector output to the
+      VDET external pin.
+    type: boolean
+
+  '#clock-cells':
+    const: 0
+
+dependencies:
+  adi,lo-x2-en: [ "adi,lo-en" ]
+  adi,lo-ppf-en: [ "adi,lo-en" ]
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      adrf6780@0 {
+        compatible = "adi,adrf6780";
+        reg = <0>;
+        spi-max-frequency = <1000000>;
+        clocks = <&adrf6780_lo>;
+        clock-names = "lo_in";
+      };
+    };
+...
Signature · 1 line
2.33.0
maintainer
#2 lore raw
In reply to Antoniu Miclaus
Quoted 9 lines · On Mon, 11 Oct 2021 14:00:10 +0300 Antoniu Miclaus…

The ADRF6780 is a silicon germanium (SiGe) design, wideband, microwave upconverter optimized for point to point microwave radio designs operating in the 5.9 GHz to 23.6 GHz frequency range.

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

Hi Antoniu,

A few things went wrong with the addition of the remove path changes that you will want to clean up.

Also just noticed your ADC channel is an output which seems unlikely...

See comments inline.

Thanks,

Jonathan

Quoted 12 lines

---
changes in v7:
- add device remove path and disable all circuitry controlled via Enable Register.
- rename adrf6780_dt_parse -> adrf6780_properties_parse

 drivers/iio/frequency/Kconfig    |  12 +
 drivers/iio/frequency/Makefile   |   1 +
 drivers/iio/frequency/adrf6780.c | 503 +++++++++++++++++++++++++++++++
 3 files changed, 516 insertions(+)
 create mode 100644 drivers/iio/frequency/adrf6780.c

...

Quoted 6 lines
drivers/iio/frequency/adrf6780.c new file +0 -0
new file mode 100644
index 000000000000..2daa728d2ff4
@@ -0,0 +1,503 @@

...

Quoted 5 lines
drivers/iio/frequency/adrf6780.c new file +5 -0
+#define ADRF6780_CHAN_ADC(_channel) {			\
+	.type = IIO_ALTVOLTAGE,				\
+	.output = 1,					\
+	.indexed = 1,					\
+	.channel = _channel,				\

drivers/iio/frequency/adrf6780.c line 297

Quoted 10 lines
drivers/iio/frequency/adrf6780.c new file +10 -0
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW)	\
+}
+
+#define ADRF6780_CHAN_RDAC(_channel) {			\
+	.type = IIO_ALTVOLTAGE,				\
+	.output = 1,					\
+	.indexed = 1,					\
+	.channel = _channel,				\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_SCALE)	\
+}

Just noticed, but as you use the same index for ADC(0) and RDAC(0) and both are output channels(odd for something called ADC?) you might as well combine the info_masks and have just one entry.

I'm guessing that ADC channel might not be an output one though...

Quoted 19 lines
drivers/iio/frequency/adrf6780.c new file +18 -0
+
+#define ADRF6780_CHAN_IQ_PHASE(_channel, rf_comp) {		\
+	.type = IIO_ALTVOLTAGE,					\
+	.modified = 1,						\
+	.output = 1,						\
+	.indexed = 1,						\
+	.channel2 = IIO_MOD_##rf_comp,				\
+	.channel = _channel,					\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_PHASE)		\
+}
+
+static const struct iio_chan_spec adrf6780_channels[] = {
+	ADRF6780_CHAN_ADC(0),
+	ADRF6780_CHAN_RDAC(0),
+	ADRF6780_CHAN_IQ_PHASE(0, I),
+	ADRF6780_CHAN_IQ_PHASE(0, Q),
+};
+

...

Quoted 44 lines
drivers/iio/frequency/adrf6780.c new file +44 -0
+static int adrf6780_init(struct adrf6780_dev *dev)
+{
+	int ret;
+	unsigned int chip_id, enable_reg, enable_reg_msk;
+	struct spi_device *spi = dev->spi;
+
+	/* Perform a software reset */
+	ret = adrf6780_reset(dev);
+	if (ret)
+		return ret;
+
+	ret = adrf6780_spi_read(dev, ADRF6780_REG_CONTROL, &chip_id);
+	if (ret)
+		return ret;
+
+	chip_id = FIELD_GET(ADRF6780_CHIP_ID_MSK, chip_id);
+	if (chip_id != ADRF6780_CHIP_ID) {
+		dev_err(&spi->dev, "ADRF6780 Invalid Chip ID.\n");
+		return -EINVAL;
+	}
+
+	enable_reg_msk = ADRF6780_VGA_BUFFER_EN_MSK |
+			ADRF6780_DETECTOR_EN_MSK |
+			ADRF6780_LO_BUFFER_EN_MSK |
+			ADRF6780_IF_MODE_EN_MSK |
+			ADRF6780_IQ_MODE_EN_MSK |
+			ADRF6780_LO_X2_EN_MSK |
+			ADRF6780_LO_PPF_EN_MSK |
+			ADRF6780_LO_EN_MSK |
+			ADRF6780_UC_BIAS_EN_MSK;
+
+	enable_reg = FIELD_PREP(ADRF6780_VGA_BUFFER_EN_MSK, dev->vga_buff_en) |
+			FIELD_PREP(ADRF6780_DETECTOR_EN_MSK, 1) |
+			FIELD_PREP(ADRF6780_LO_BUFFER_EN_MSK, dev->lo_buff_en) |
+			FIELD_PREP(ADRF6780_IF_MODE_EN_MSK, dev->if_mode_en) |
+			FIELD_PREP(ADRF6780_IQ_MODE_EN_MSK, dev->iq_mode_en) |
+			FIELD_PREP(ADRF6780_LO_X2_EN_MSK, dev->lo_x2_en) |
+			FIELD_PREP(ADRF6780_LO_PPF_EN_MSK, dev->lo_ppf_en) |
+			FIELD_PREP(ADRF6780_LO_EN_MSK, dev->lo_en) |
+			FIELD_PREP(ADRF6780_UC_BIAS_EN_MSK, dev->uc_bias_en);
+
+	ret = adrf6780_spi_update_bits(dev, ADRF6780_REG_ENABLE, enable_reg_msk, enable_reg);
+	if (ret)
+		return ret;

drivers/iio/frequency/adrf6780.c line 393

Quoted 10 lines
drivers/iio/frequency/adrf6780.c new file +10 -0
+
+	ret = adrf6780_spi_update_bits(dev, ADRF6780_REG_LO_PATH,
+						ADRF6780_LO_SIDEBAND_MSK,
+						FIELD_PREP(ADRF6780_LO_SIDEBAND_MSK, dev->lo_sideband));
+	if (ret)
+		return ret;
+
+	return adrf6780_spi_update_bits(dev, ADRF6780_REG_ADC_CONTROL,
+						ADRF6780_VDET_OUTPUT_SELECT_MSK,
+						FIELD_PREP(ADRF6780_VDET_OUTPUT_SELECT_MSK, dev->vdet_out_en));

Very long line so perhaps add an additional line break after the ,

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

...

Quoted 13 lines
drivers/iio/frequency/adrf6780.c new file +13 -0
+
+static int adrf6780_probe(struct spi_device *spi)
+{
+	struct iio_dev *indio_dev;
+	struct adrf6780_dev *dev;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*dev));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	dev = iio_priv(indio_dev);
+

drivers/iio/frequency/adrf6780.c line 433

Quoted 10 lines
drivers/iio/frequency/adrf6780.c new file +10 -0
+	indio_dev->info = &adrf6780_info;
+	indio_dev->name = "adrf6780";
+	indio_dev->channels = adrf6780_channels;
+	indio_dev->num_channels = ARRAY_SIZE(adrf6780_channels);
+
+	dev->spi = spi;
+
+	adrf6780_properties_parse(dev);
+
+	dev->clkin = devm_clk_get(&spi->dev, "lo_in");

Please add an error message to things that might result in a deferred probe via dev_err_probe() as it stores more debugging information for those trying to chase down why a probe was deferred. Note this is a new thing, but as you are going to need to do another version anyway, nice to tidy it up in the initial driver rather than as a follow up patch.

Quoted 10 lines
drivers/iio/frequency/adrf6780.c new file +10 -0
+	if (IS_ERR(dev->clkin))
+		return PTR_ERR(dev->clkin);
+
+	ret = clk_prepare_enable(dev->clkin);
+	if (ret < 0)
+		goto error_disable_clk;
+
+	mutex_init(&dev->lock);
+
+	ret = adrf6780_init(dev);

drivers/iio/frequency/adrf6780.c line 453

Quoted 10 lines
drivers/iio/frequency/adrf6780.c new file +10 -0
+	if (ret)
+		goto error_disable_clk;;
+
+	ret = iio_device_register(indio_dev);
+	if (ret)
+		goto error_disable_clk;
+
+	return 0;
+
+error_disable_clk:

An easy way to spot inconsistencies is to compare what is done in the error path in probe() with what occurs in remove(). They should only differ in that the first element in remove() often won't appear in the probe error handling. So why am I not seeing the disable write to the device here?

drivers/iio/frequency/adrf6780.c line 466

Quoted 13 lines
drivers/iio/frequency/adrf6780.c new file +13 -0
+	clk_disable_unprepare(dev->clkin);
+
+	return ret;
+}
+
+static int adrf6780_remove(struct spi_device *spi)
+{
+	int ret;
+	struct iio_dev *indio_dev = spi_get_drvdata(spi);
+	struct adrf6780_dev *dev = iio_priv(indio_dev);
+
+	/* Disable all components in the Enable Register */
+	ret = adrf6780_spi_write(dev, ADRF6780_REG_ENABLE, 0x0);

What call in probe() is this matched against? Looks to be the
_init() call. In which case this should be after the iio_device_unregister(). Particularly obvious here as turning off the device 'before' we remove the userspace interface is never a good plan.

Also, there is no point in returning an error code from probe so just carry on if this fails and we'll disable as much as possible. Note that there are lots of patches removing returns from spi driver remove functions at the moment.

Everything you are doing in this remove could be easily handled automatically with a few devm_add_action_or_reset() calls in probe. See the many patches Alexandru Ardelean has sent converting driver to that approach. One side effect is that the ordering is automatically correct.

drivers/iio/frequency/adrf6780.c line 477

Quoted 11 lines
drivers/iio/frequency/adrf6780.c new file +11 -0
+	if(ret)
+		return ret;
+
+	iio_device_unregister(indio_dev);
+
+	clk_disable_unprepare(dev->clkin);
+
+	return 0;
+}
+
+

One blank line is almost always enough.

Quoted 4 lines
drivers/iio/frequency/adrf6780.c new file +4 -0
+static const struct spi_device_id adrf6780_id[] = {
+	{ "adrf6780", 0 },
+	{}
+};