Skip to contentSkip to conversation

iio: amplifiers: add support for ADL8113 Low Noise Amplifier

PATCH Superseded Antoniu Miclaus 4 participants 7 messages Nov 28, 2025 – Dec 4, 2025

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Antoniu Miclaus

author maintainer
#0 lore raw

v5 cover iio: amplifiers: add support for ADL8113 Low Noise Amplifier

This patch series adds support for the Analog Devices ADL8113, a 10MHz to 12GHz Low Noise Amplifier with integrated bypass switches.

The ADL8113 provides four operation modes controlled by two GPIO pins:
- Internal Amplifier (14dB gain)
- Internal Bypass (0dB gain)
- External Bypass A (0dB gain) - Signal routes from RFIN to OUT_A and from IN_A to RFOUT
- External Bypass B (0dB gain) - Signal routes from RFIN to OUT_B and from IN_B to RFOUT

Antoniu Miclaus (2):
dt-bindings: iio: amplifiers: add adl8113
iio: amplifiers: adl8113: add driver support

 .../bindings/iio/amplifiers/adi,adl8113.yaml  |  89 ++++++
 drivers/iio/amplifiers/Kconfig                |  12 +
 drivers/iio/amplifiers/Makefile               |   1 +
 drivers/iio/amplifiers/adl8113.c              | 290 ++++++++++++++++++
 4 files changed, 392 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml
 create mode 100644 drivers/iio/amplifiers/adl8113.c
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v5 1/2 dt-bindings: iio: amplifiers: add adl8113

Add devicetree bindings for adl8113.

---
Changes in v5:
- Replace separate va-gpios and vb-gpios properties with single ctrl-gpios array
- Remove second example, keep only one with external bypass configuration
- Add comments to external bypass gains in example

 .../bindings/iio/amplifiers/adi,adl8113.yaml  | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml
Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml new file +89 -0
new file mode 100644
index 000000000000..43ba51f8a235
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/amplifiers/adi,adl8113.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADL8113 Low Noise Amplifier with integrated bypass switches
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+  The ADL8113 is a 10MHz to 12GHz Low Noise Amplifier with integrated bypass
+  switches controlled by two GPIO pins (VA and VB). The device supports four
+  operation modes:
+    - Internal Amplifier: VA=0, VB=0 - Signal passes through the internal LNA
+    - Internal Bypass: VA=1, VB=1 - Signal bypasses through internal path
+    - External Bypass A: VA=0, VB=1 - Signal routes from RFIN to OUT_A and from IN_A to RFOUT
+    - External Bypass B: VA=1, VB=0 - Signal routes from RFIN to OUT_B and from IN_B to RFOUT
+
+    https://www.analog.com/en/products/adl8113.html
+
+properties:
+  compatible:
+    const: adi,adl8113
+
+  vdd1-supply: true
+
+  vdd2-supply: true
+
+  vss2-supply: true
+
+  ctrl-gpios:
+    description:
+      GPIOs connected to the VA and VB control pins (in that order).
+      Must be specified as GPIO_ACTIVE_HIGH.
+    minItems: 2
+    maxItems: 2
+
+  adi,external-bypass-a-gain-db:
+    description:
+      Gain in dB of external amplifier connected to bypass path A (OUT_A/IN_A).
+      When specified, this gain value becomes selectable via the hardwaregain
+      attribute and automatically routes through the external A path.
+
+  adi,external-bypass-b-gain-db:
+    description:
+      Gain in dB of external amplifier connected to bypass path B (OUT_B/IN_B).
+      When specified, this gain value becomes selectable via the hardwaregain
+      attribute and automatically routes through the external B path.
+
+required:
+  - compatible
+  - ctrl-gpios
+  - vdd1-supply
+  - vdd2-supply
+  - vss2-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    /* Basic configuration with only internal paths */
+    amplifier {
+        compatible = "adi,adl8113";
+        ctrl-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>,
+                     <&gpio 23 GPIO_ACTIVE_HIGH>;
+        vdd1-supply = <&vdd1_5v>;
+        vdd2-supply = <&vdd2_3v3>;
+        vss2-supply = <&vss2_neg>;
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    /* Configuration with external bypass amplifiers */
+    amplifier {
+        compatible = "adi,adl8113";
+        ctrl-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>,
+                     <&gpio 25 GPIO_ACTIVE_HIGH>;
+        vdd1-supply = <&vdd1_5v>;
+        vdd2-supply = <&vdd2_3v3>;
+        vss2-supply = <&vss2_neg>;
+        adi,external-bypass-a-gain-db = <20>;  /* 20dB external amp on path A */
+        adi,external-bypass-b-gain-db = <6>;   /* 6dB external amp on path B */
+    };
+...
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v5 1/2] dt-bindings: iio: amplifiers: add adl8113

Quoted 9 lines · Antoniu Miclaus

Add devicetree bindings for adl8113.

---
Changes in v5:
- Replace separate va-gpios and vb-gpios properties with single ctrl-gpios array
- Remove second example, keep only one with external bypass configuration
- Add comments to external bypass gains in example

Quoted 4 lines
 .../bindings/iio/amplifiers/adi,adl8113.yaml  | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 428, in get_or_retrieve
resource = registry._retrieve(uri)
File "/usr/local/lib/python3.13/dist-packages/dtschema/validator.py", line 426, in retrieve

    return DRAFT201909.create_resource(self.schemas[uri])
                                       ~~~~~~~~~~~~^^^^^

KeyError: 'http://devicetree.org/schemas/thermal/qcom-tsens.yaml'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 682, in lookup
retrieved = self._registry.get_or_retrieve(uri)
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 435, in get_or_retrieve
raise exceptions.Unretrievable(ref=uri) from error
referencing.exceptions.Unretrievable: 'http://devicetree.org/schemas/thermal/qcom-tsens.yaml'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 463, in _validate_reference
resolved = self._resolver.lookup(ref)
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 686, in lookup
raise exceptions.Unresolvable(ref=ref) from error
referencing.exceptions.Unresolvable: /schemas/thermal/qcom-tsens.yaml#

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/dt-validate", line 8, in <module>

    sys.exit(main())
             ~~~~^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 158, in main
    sg.check_dtb(filename)
    ~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 95, in check_dtb
    self.check_subtree(dt, subtree, False, "/", "/", filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 88, in check_subtree
    self.check_subtree(tree, value, disabled, name, fullname + name, filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 88, in check_subtree
    self.check_subtree(tree, value, disabled, name, fullname + name, filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 83, in check_subtree
    self.check_node(tree, subtree, disabled, nodename, fullname, filename)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 34, in check_node
    for error in self.validator.iter_errors(node, filter=match_schema_file,
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                            compatible_match=compatible_match):
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/validator.py", line 448, in iter_errors
    for error in self.DtValidator(schema, registry=self.registry).iter_errors(instance):
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 384, in iter_errors
    for error in errors:
                 ^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/_keywords.py", line 296, in properties
    yield from validator.descend(
    ...<4 lines>...
    )

File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 432, in descend
for error in errors:
^^^^^^
File "/usr/local/lib/python3.13/dist-packages/jsonschema/_keywords.py", line 275, in ref
yield from validator._validate_reference(ref=ref, instance=instance)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 465, in _validate_reference
raise exceptions._WrappedReferencingError(err) from err
jsonschema.exceptions._WrappedReferencingError: Unresolvable: /schemas/thermal/qcom-tsens.yaml# Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 428, in get_or_retrieve
resource = registry._retrieve(uri)
File "/usr/local/lib/python3.13/dist-packages/dtschema/validator.py", line 426, in retrieve

    return DRAFT201909.create_resource(self.schemas[uri])
                                       ~~~~~~~~~~~~^^^^^

KeyError: 'http://devicetree.org/schemas/thermal/qcom-tsens.yaml'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 682, in lookup
retrieved = self._registry.get_or_retrieve(uri)
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 435, in get_or_retrieve
raise exceptions.Unretrievable(ref=uri) from error
referencing.exceptions.Unretrievable: 'http://devicetree.org/schemas/thermal/qcom-tsens.yaml'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 463, in _validate_reference
resolved = self._resolver.lookup(ref)
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 686, in lookup
raise exceptions.Unresolvable(ref=ref) from error
referencing.exceptions.Unresolvable: /schemas/thermal/qcom-tsens.yaml#

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/dt-validate", line 8, in <module>

    sys.exit(main())
             ~~~~^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 158, in main
    sg.check_dtb(filename)
    ~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 95, in check_dtb
    self.check_subtree(dt, subtree, False, "/", "/", filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 88, in check_subtree
    self.check_subtree(tree, value, disabled, name, fullname + name, filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 88, in check_subtree
    self.check_subtree(tree, value, disabled, name, fullname + name, filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 83, in check_subtree
    self.check_node(tree, subtree, disabled, nodename, fullname, filename)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 34, in check_node
    for error in self.validator.iter_errors(node, filter=match_schema_file,
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                            compatible_match=compatible_match):
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/validator.py", line 448, in iter_errors
    for error in self.DtValidator(schema, registry=self.registry).iter_errors(instance):
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 384, in iter_errors
    for error in errors:
                 ^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/_keywords.py", line 296, in properties
    yield from validator.descend(
    ...<4 lines>...
    )

File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 432, in descend
for error in errors:
^^^^^^
File "/usr/local/lib/python3.13/dist-packages/jsonschema/_keywords.py", line 334, in allOf
yield from validator.descend(instance, subschema, schema_path=index)
File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 432, in descend
for error in errors:
^^^^^^
File "/usr/local/lib/python3.13/dist-packages/jsonschema/_keywords.py", line 275, in ref
yield from validator._validate_reference(ref=ref, instance=instance)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 465, in _validate_reference
raise exceptions._WrappedReferencingError(err) from err
jsonschema.exceptions._WrappedReferencingError: Unresolvable: /schemas/thermal/qcom-tsens.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#3 lore raw

Re: [PATCH v5 1/2] dt-bindings: iio: amplifiers: add adl8113

In reply to Antoniu Miclaus
Quoted 47 lines · Antoniu Miclaus

Add devicetree bindings for adl8113.

---
Changes in v5:
- Replace separate va-gpios and vb-gpios properties with single ctrl-gpios array
- Remove second example, keep only one with external bypass configuration
- Add comments to external bypass gains in example

 .../bindings/iio/amplifiers/adi,adl8113.yaml  | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml
Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml new file +28 -0
new file mode 100644
index 000000000000..43ba51f8a235
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/amplifiers/adi,adl8113.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADL8113 Low Noise Amplifier with integrated bypass switches
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+  The ADL8113 is a 10MHz to 12GHz Low Noise Amplifier with integrated bypass
+  switches controlled by two GPIO pins (VA and VB). The device supports four
+  operation modes:
+    - Internal Amplifier: VA=0, VB=0 - Signal passes through the internal LNA
+    - Internal Bypass: VA=1, VB=1 - Signal bypasses through internal path
+    - External Bypass A: VA=0, VB=1 - Signal routes from RFIN to OUT_A and from IN_A to RFOUT
+    - External Bypass B: VA=1, VB=0 - Signal routes from RFIN to OUT_B and from IN_B to RFOUT
+
+    https://www.analog.com/en/products/adl8113.html
+
+properties:
+  compatible:
+    const: adi,adl8113
+
+  vdd1-supply: true
+

Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml line 38

Quoted 10 lines
Documentation/devicetree/bindings/iio/amplifiers/adi,adl8113.yaml new file +10 -0
+  vdd2-supply: true
+
+  vss2-supply: true
+
+  ctrl-gpios:
+    description:
+      GPIOs connected to the VA and VB control pins (in that order).
+      Must be specified as GPIO_ACTIVE_HIGH.
+    minItems: 2
+    maxItems: 2

"maxItems: 2" should suffice here, minItems defaults to maxItems if not specified. Although, this seems like it should be an items list, since that avoids defining ordering in free-form text as you are.

pw-bot: changes-requested

Cheers,
Conor.

author maintainer
#4 lore raw

PATCH v5 2/2 iio: amplifiers: adl8113: add driver support

In reply to Antoniu Miclaus

Add support for adl8113 10MHz to 12GHz Low Noise Amplifier with 10MHz to 14GHz bypass switches.

---
Changes in v5:
- Replace separate gpio_va and gpio_vb with gpio_descs array
- Use devm_gpiod_get_array() instead of devm_gpiod_get() with validation
- Update adl8113_set_path() to use bitmap and gpiod_set_array_value_cansleep()
- Change internal bypass gain from 0dB to -2dB (insertion loss)
- Add INT_MIN gain value for unused external bypass paths (testing)
- Fix error propagation in adl8113_write_raw() to return actual error code
- Change duplicate gain error handling to use dev_err_probe()
- Remove indexed and channel fields from IIO channel spec
- Reorder supply names array (vss2 before vdd2)

 drivers/iio/amplifiers/Kconfig   |  12 ++
 drivers/iio/amplifiers/Makefile  |   1 +
 drivers/iio/amplifiers/adl8113.c | 290 +++++++++++++++++++++++++++++++
 3 files changed, 303 insertions(+)
 create mode 100644 drivers/iio/amplifiers/adl8113.c
drivers/iio/amplifiers/Kconfig +12 -0
index 55eb16b32f6c..a8a604863eed 100644
@@ -36,6 +36,18 @@ config ADA4250
 	  To compile this driver as a module, choose M here: the
 	  module will be called ada4250.
 
+config ADL8113
+	tristate "Analog Devices ADL8113 Low Noise Amplifier"
+	depends on GPIOLIB
+	help
+	  Say yes here to build support for Analog Devices ADL8113 Low Noise
+	  Amplifier with integrated bypass switches. The device supports four
+	  operation modes controlled by GPIO pins: internal amplifier,
+	  internal bypass, and two external bypass modes.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called adl8113.
+
 config HMC425
 	tristate "Analog Devices HMC425A and similar GPIO Gain Amplifiers"
 	depends on GPIOLIB
drivers/iio/amplifiers/Makefile +1 -0
index 2126331129cf..0a76443be1aa 100644
@@ -6,4 +6,5 @@
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD8366) += ad8366.o
 obj-$(CONFIG_ADA4250) += ada4250.o
+obj-$(CONFIG_ADL8113) += adl8113.o
 obj-$(CONFIG_HMC425) += hmc425a.o
drivers/iio/amplifiers/adl8113.c new file +290 -0

290 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v5 2/2] iio: amplifiers: adl8113: add driver support

Quoted 3 lines · Antoniu Miclaus

Add support for adl8113 10MHz to 12GHz Low Noise Amplifier with 10MHz to 14GHz bypass switches.

Almost there, it's the 5th version and looks good (no major issues), so if you address my comments below in v6, I'll give a tag.

...

Quoted 1 line

+#include <linux/array_size.h>

+ bitmap.h // bitmap_*(), BIT(), GENMASK(), etc.

Quoted 1 line

+#include <linux/device.h>

Is it really used? I found

+ dev_printk.h // dev_err_probe() et al.
+ device/devres.h // devm_k*alloc*()

drivers/iio/amplifiers/adl8113.c line 12

Quoted 3 lines
drivers/iio/amplifiers/adl8113.c new file +3 -0
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/iio/iio.h>

+ limits.h // INT_MIN

drivers/iio/amplifiers/adl8113.c line 19

Quoted 8 lines
drivers/iio/amplifiers/adl8113.c new file +7 -0
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regulator/consumer.h>
 
+#include <linux/slab.h>
+#include <linux/sysfs.h>

Are those two being used? (device/devres.h should provide what devm_k*alloc*() needs)

+ types.h // DECLARE_BITMAP()

...

drivers/iio/amplifiers/adl8113.c line 38

Quoted 4 lines
drivers/iio/amplifiers/adl8113.c new file +4 -0
+struct adl8113_state {
+       struct gpio_descs *gpios;
+       struct adl8113_gain_config *gain_configs;
+       int num_gain_configs;

Do you need this to be signed?

Quoted 2 lines
(quoted diff) +2 -0
+       enum adl8113_signal_path current_path;
+};

...

drivers/iio/amplifiers/adl8113.c line 45

Quoted 4 lines
drivers/iio/amplifiers/adl8113.c new file +4 -0
+static const char * const adl8113_supply_names[] = {
+       "vdd1",
+       "vss2",
+       "vdd2"

Please, keep the trailing comma.

Quoted 1 line

+};

...

drivers/iio/amplifiers/adl8113.c line 54

Quoted 7 lines
drivers/iio/amplifiers/adl8113.c new file +6 -0
+static int adl8113_set_path(struct adl8113_state *st,
+                           enum adl8113_signal_path path)
+{
+       DECLARE_BITMAP(values, 2);
+       int ret;
 
+       bitmap_zero(values, 2);

Move this to the switch case...

drivers/iio/amplifiers/adl8113.c line 59

Quoted 5 lines
drivers/iio/amplifiers/adl8113.c new file +4 -0
+       /* Determine GPIO values based on signal path */
+       switch (path) {
+       case ADL8113_INTERNAL_AMP:
 
+               /* va=0, vb=0 - already zero */

Unneeded comment here and below, just put a number to the bitmap

  bitmap_write(..., 0x00);

drivers/iio/amplifiers/adl8113.c line 64

Quoted 5 lines
drivers/iio/amplifiers/adl8113.c new file +5 -0
+               break;
+       case ADL8113_INTERNAL_BYPASS:
+               /* va=1, vb=1 */
+               __set_bit(0, values);
+               __set_bit(1, values);
  bitmap_write(..., 0x03);

drivers/iio/amplifiers/adl8113.c line 68

Quoted 4 lines
drivers/iio/amplifiers/adl8113.c new file +4 -0
+               break;
+       case ADL8113_EXTERNAL_A:
+               /* va=0, vb=1 */
+               __set_bit(1, values);
  bitmap_write(..., 0x02);

drivers/iio/amplifiers/adl8113.c line 72

Quoted 4 lines
drivers/iio/amplifiers/adl8113.c new file +4 -0
+               break;
+       case ADL8113_EXTERNAL_B:
+               /* va=1, vb=0 */
+               __set_bit(0, values);
  bitmap_write(..., 0x01);
Quoted 13 lines
drivers/iio/amplifiers/adl8113.c new file +13 -0
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       ret = gpiod_set_array_value_cansleep(st->gpios->ndescs, st->gpios->desc,
+                                            st->gpios->info, values);
+       if (ret)
+               return ret;
+
+       st->current_path = path;
+       return 0;
+}

...

drivers/iio/amplifiers/adl8113.c line 89

Quoted 3 lines
drivers/iio/amplifiers/adl8113.c new file +3 -0
+static int adl8113_find_gain_config(struct adl8113_state *st, int gain_db)
+{
+       int i;

Does it need to be signed?

Quoted 6 lines
drivers/iio/amplifiers/adl8113.c new file +6 -0
+       for (i = 0; i < st->num_gain_configs; i++) {
+               if (st->gain_configs[i].gain_db == gain_db)
+                       return i;
+       }
+       return -EINVAL;
+}

...

drivers/iio/amplifiers/adl8113.c line 110

Quoted 6 lines
drivers/iio/amplifiers/adl8113.c new file +6 -0
+static int adl8113_read_raw(struct iio_dev *indio_dev,
+                           struct iio_chan_spec const *chan,
+                           int *val, int *val2, long mask)
+{
+       struct adl8113_state *st = iio_priv(indio_dev);
+       int i;

unsigned int i;

Quoted 15 lines
drivers/iio/amplifiers/adl8113.c new file +15 -0
+       switch (mask) {
+       case IIO_CHAN_INFO_HARDWAREGAIN:
+               /* Find current gain configuration */
+               for (i = 0; i < st->num_gain_configs; i++) {
+                       if (st->gain_configs[i].path == st->current_path) {
+                               *val = st->gain_configs[i].gain_db;
+                               *val2 = 0;
+                               return IIO_VAL_INT_PLUS_MICRO_DB;
+                       }
+               }
+               return -EINVAL;
+       default:
+               return -EINVAL;
+       }
+}

...

drivers/iio/amplifiers/adl8113.c line 157

Quoted 3 lines
drivers/iio/amplifiers/adl8113.c new file +3 -0
+static int adl8113_init_gain_configs(struct device *dev, struct adl8113_state *st)
+{
+       int external_a_gain, external_b_gain, i = 0, j;

unsigned int i, j;

And it's better to decouple assignment

drivers/iio/amplifiers/adl8113.c line 167

Quoted 9 lines
drivers/iio/amplifiers/adl8113.c new file +9 -0
+       /*
+        * Allocate for all 4 possible paths:
+        * - Internal amp and bypass (always present)
+        * - External bypass A and B (optional, or INT_MIN for testing)
+        */
+       st->gain_configs = devm_kcalloc(dev, 4,
+                                       sizeof(*st->gain_configs), GFP_KERNEL);
+       if (!st->gain_configs)
+               return -ENOMEM;

/* Start filling the gain configurations with data */ i = 0;

Quoted 19 lines
drivers/iio/amplifiers/adl8113.c new file +19 -0
+       /* Always include internal amplifier (14dB) */
+       st->gain_configs[i].path = ADL8113_INTERNAL_AMP;
+       st->gain_configs[i].gain_db = 14;
+       i++;
+
+       /* Always include internal bypass (-2dB insertion loss) */
+       st->gain_configs[i].path = ADL8113_INTERNAL_BYPASS;
+       st->gain_configs[i].gain_db = -2;
+       i++;
+
+       /* Add external bypass A if configured */
+       if (!device_property_read_u32(dev, "adi,external-bypass-a-gain-db",
+                                     &external_a_gain)) {
+               st->gain_configs[i].path = ADL8113_EXTERNAL_A;
+               st->gain_configs[i].gain_db = external_a_gain;
+               i++;
+       }
+
+       /* Add external bypass B if configured */

drivers/iio/amplifiers/adl8113.c line 197

Quoted 10 lines
drivers/iio/amplifiers/adl8113.c new file +10 -0
+       if (!device_property_read_u32(dev, "adi,external-bypass-b-gain-db",
+                                     &external_b_gain)) {
+               st->gain_configs[i].path = ADL8113_EXTERNAL_B;
+               st->gain_configs[i].gain_db = external_b_gain;
+               i++;
+       }
+
+       /*
+        * If there's a free external bypass path, add one with INT_MIN gain
+        * to represent "nothing connected" for testing purposes

Missing period at the end.

Quoted 37 lines
drivers/iio/amplifiers/adl8113.c new file +37 -0
+        */
+       if (!device_property_present(dev, "adi,external-bypass-a-gain-db")) {
+               st->gain_configs[i].path = ADL8113_EXTERNAL_A;
+               st->gain_configs[i].gain_db = INT_MIN;
+               i++;
+       } else if (!device_property_present(dev, "adi,external-bypass-b-gain-db")) {
+               st->gain_configs[i].path = ADL8113_EXTERNAL_B;
+               st->gain_configs[i].gain_db = INT_MIN;
+               i++;
+       }
+
+       st->num_gain_configs = i;
+
+       /* Check for duplicate gain values */
+       for (i = 0; i < st->num_gain_configs - 1; i++) {
+               for (j = i + 1; j < st->num_gain_configs; j++) {
+                       if (st->gain_configs[i].gain_db == st->gain_configs[j].gain_db)
+                               return dev_err_probe(dev, -EINVAL,
+                                                    "Duplicate gain values not allowed: %d dB\n",
+                                                    st->gain_configs[i].gain_db);
+               }
+       }
+
+       return 0;
+}
+
+static int adl8113_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct adl8113_state *st;
+       struct iio_dev *indio_dev;
+       int ret;
+
+       indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+       if (!indio_dev)
+               return -ENOMEM;
+

drivers/iio/amplifiers/adl8113.c line 244

Quoted 10 lines
drivers/iio/amplifiers/adl8113.c new file +10 -0
+       st = iio_priv(indio_dev);
+
+       st->gpios = devm_gpiod_get_array(dev, "ctrl", GPIOD_OUT_LOW);
+       if (IS_ERR(st->gpios))
+               return dev_err_probe(dev, PTR_ERR(st->gpios),
+                                    "failed to get control GPIOs\n");
+
+       if (st->gpios->ndescs != 2)
+               return dev_err_probe(dev, -EINVAL,
+                                    "expected 2 control GPIOs, got %d\n",

%u

Quoted 26 lines
drivers/iio/amplifiers/adl8113.c new file +26 -0
+                                    st->gpios->ndescs);
+
+       ret = devm_regulator_bulk_get_enable(dev,
+                                            ARRAY_SIZE(adl8113_supply_names),
+                                            adl8113_supply_names);
+       if (ret)
+               return dev_err_probe(dev, ret,
+                                    "failed to get and enable supplies\n");
+
+       /* Initialize gain configurations from devicetree */
+       ret = adl8113_init_gain_configs(dev, st);
+       if (ret)
+               return ret;
+
+       /* Initialize to internal amplifier path (14dB) */
+       ret = adl8113_set_path(st, ADL8113_INTERNAL_AMP);
+       if (ret)
+               return ret;
+
+       indio_dev->info = &adl8113_info;
+       indio_dev->name = "adl8113";
+       indio_dev->channels = adl8113_channels;
+       indio_dev->num_channels = ARRAY_SIZE(adl8113_channels);
+
+       return devm_iio_device_register(dev, indio_dev);
+}

...

drivers/iio/amplifiers/adl8113.c line 285

Quoted 9 lines
drivers/iio/amplifiers/adl8113.c new file +8 -0
+static struct platform_driver adl8113_driver = {
+       .driver = {
+               .name = "adl8113",
+               .of_match_table = adl8113_of_match,
+       },
+       .probe = adl8113_probe,
+};
 
+

Redundant blank line.

Quoted 1 line

+module_platform_driver(adl8113_driver);

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v5 2/2] iio: amplifiers: adl8113: add driver support

Quoted 2 lines · Andy Shevchenko

On Fri, Nov 28, 2025 at 4:45 PM Antoniu Miclaus
<[email protected]> wrote:

...

Quoted 11 lines

drivers/iio/amplifiers/adl8113.c line 54

Quoted 7 lines
drivers/iio/amplifiers/adl8113.c new file +6 -0
+static int adl8113_set_path(struct adl8113_state *st,
+                           enum adl8113_signal_path path)
+{
+       DECLARE_BITMAP(values, 2);
+       int ret;
 
+       bitmap_zero(values, 2);

Move this to the switch case...

Quoted 1 line

+ /* Determine GPIO values based on signal path */

Note, you may extend this comment to show the mapping, e.g.,

/*
* Determine GPIO values based on signal path.
* Va: bit 0, Vb: bit 1.
*/

Quoted 44 lines

drivers/iio/amplifiers/adl8113.c line 59

Quoted 4 lines
drivers/iio/amplifiers/adl8113.c new file +3 -0
+       switch (path) {
+       case ADL8113_INTERNAL_AMP:
 
+               /* va=0, vb=0 - already zero */

Unneeded comment here and below, just put a number to the bitmap

  bitmap_write(..., 0x00);

drivers/iio/amplifiers/adl8113.c line 64

Quoted 5 lines
drivers/iio/amplifiers/adl8113.c new file +5 -0
+               break;
+       case ADL8113_INTERNAL_BYPASS:
+               /* va=1, vb=1 */
+               __set_bit(0, values);
+               __set_bit(1, values);
  bitmap_write(..., 0x03);

drivers/iio/amplifiers/adl8113.c line 68

Quoted 4 lines
drivers/iio/amplifiers/adl8113.c new file +4 -0
+               break;
+       case ADL8113_EXTERNAL_A:
+               /* va=0, vb=1 */
+               __set_bit(1, values);
  bitmap_write(..., 0x02);

drivers/iio/amplifiers/adl8113.c line 72

Quoted 4 lines
drivers/iio/amplifiers/adl8113.c new file +4 -0
+               break;
+       case ADL8113_EXTERNAL_B:
+               /* va=1, vb=0 */
+               __set_bit(0, values);
  bitmap_write(..., 0x01);
Quoted 13 lines
drivers/iio/amplifiers/adl8113.c new file +13 -0
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       ret = gpiod_set_array_value_cansleep(st->gpios->ndescs, st->gpios->desc,
+                                            st->gpios->info, values);
+       if (ret)
+               return ret;
+
+       st->current_path = path;
+       return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko