Skip to contentSkip to conversation

Add support for LTC2688

PATCH Superseded Nuno Sá 4 participants 15 messages Jan 15, 2022 – Jan 16, 2022

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Nuno Sá

author maintainer
#0 lore raw

v2 cover Add support for LTC2688

The ABI defined for this driver has some subtleties that were previously discussed in this RFC [1]. This might not be the final state but, hopefully, we are close to it:

toggle mode channels:

* out_voltageY_toggle_en
* out_voltageY_raw0
* out_voltageY_raw1
* out_voltageY_symbol

dither mode channels:

* out_voltageY_dither_en
* out_voltageY_dither_raw
* out_voltageY_dither_raw_available
* out_voltageY_dither_offset
* out_voltageY_dither_frequency
* out_voltageY_dither_frequency_available
* out_voltageY_dither_phase
* out_voltageY_dither_phase_available

Default channels won't have any of the above ABIs. A channel is toggle capable if the devicetree 'adi,toggle-mode' flag is set. For dither, the assumption is more silent. If 'adi,toggle-mode' is not given and a channel is associated with a TGPx pin through 'adi,toggle-dither-input', then the channel is assumed to be dither capable (there's no point in having a dither capable channel without an input clock).

changes in v2:

ltc2688:
* Use local buffer for regmap read. Do not assume that reg is part of
larger buffer;
* Renamed GPIO to "clr" so that is consistent with the datasheet;
* Renamed 'mask' and 'm' to info. 'mask' is a thing from the past;
* Removed 'LTC2688_CHAN_TOGGLE()' and defined to static ext_info arrays;
* Use 'regmap_set_bits' to set external ref;
* Use FIELD_{PREP|GET} for dither amplitude and channel calibbias where
only 13bits are used;
* Use 'regmap_write()' instead of update_bits for channels settings;
* Init 'val' at the beginning of the channel configuration loop
(and drop mask);
* Comment 'ltc2688_reg_writable()' to account for the special condition;
* Kmemdup default channels so that it can be safely changed per probed
device;
* Replace extended info multiplexer functions by individual functions;
* Use raw0 ABI for toggle channels;
* Use dedicated offset ABI for dither channels;
* Misc changes (spell fixes, blank lines...);
* Have a clock property per channel. Note that we this I moved to OF
since we now have to use 'devm_get_clk_from_child()' which is using device_node. Note that I could use 'to_of_node()' but mixing of.h and property.h does not feel like a good idea.

ABI:
* Added out_voltageY_raw0 ABI for toggle mode;
* Added out_voltageY_dither_offset.

Bindings:
* Use standard microvolt unit;
* Added constrains for adi,output-range-microvolt and removed negative
values from the dts example;
* Moved clocks to the channel object;
* Dropped clock-names;
* Add a dependency between 'adi,toggle-dither-input' and 'clocks'.

[1]: https://marc.info/?l=linux-iio&m=163662843603265&w=2

Nuno Sá (3):
iio: dac: add support for ltc2688
iio: ABI: add ABI file for the LTC2688 DAC
dt-bindings: iio: Add ltc2688 documentation

 .../ABI/testing/sysfs-bus-iio-dac-ltc2688     |   80 ++
 .../bindings/iio/dac/adi,ltc2688.yaml         |  147 +++
 MAINTAINERS                                   |    9 +
 drivers/iio/dac/Kconfig                       |   11 +
 drivers/iio/dac/Makefile                      |    1 +
 drivers/iio/dac/ltc2688.c                     | 1070 +++++++++++++++++
 6 files changed, 1318 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
 create mode 100644 drivers/iio/dac/ltc2688.c
Signature · 1 line
2.33.1
author maintainer
#7 lore raw

PATCH v2 2/3 iio: ABI: add ABI file for the LTC2688 DAC

Define the sysfs interface for toggle or dither capable channels. Dither capable channels will have the extended interface:

* out_voltageY_dither_en
* out_voltageY_dither_raw
* out_voltageY_dither_offset
* out_voltageY_dither_raw_available
* out_voltageY_dither_frequency
* out_voltageY_dither_frequency_available
* out_voltageY_dither_phase
* out_voltageY_dither_phase_available

Toggle enabled channels will have:

* out_voltageY_toggle_en
* out_voltageY_raw0
* out_voltageY_raw1
* out_voltageY_symbol

---
 .../ABI/testing/sysfs-bus-iio-dac-ltc2688     | 80 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 81 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +80 -0
new file mode 100644
index 000000000000..38d1df81c6dc
@@ -0,0 +1,80 @@
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_en
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Dither enable. Write 1 to enable dither or 0 to disable it.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_raw
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		This raw, unscaled value refers to the dither signal amplitude.
+		The same scale as in out_voltageY_raw applies. However, the
+		offset might be different as it's always 0 for this attribute.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_raw_available
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Available range for dither raw amplitude values.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_offset
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Offset applied to out_voltageY_dither_raw. Read only attribute
+		always set to 0.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_frequency
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Sets the dither signal frequency.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_frequency_available
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Returns the available values for the dither frequency.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_phase
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Sets the dither signal phase.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_phase_available
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Returns the available values for the dither phase.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_toggle_en
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Toggle enable. Write 1 to enable toggle or 0 to disable it.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_raw0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		It has the same meaning as out_voltageY_raw. This attribute is
+		specific to toggle enabled channels and refers to the DAC output
+		code in INPUT_A. The same scale, offset, etc applies.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_raw1
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Same as out_voltageY_raw0 but referring to the DAC output code
+		in INPUT_B.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_symbol
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Performs a SW toggle. This attribute is specific to toggle
+		enabled channels and allows to toggle between out_voltageY_raw
+		and out_voltageY_raw1 through software. Writing 0 will select
+		out_voltageY_raw while 1 selects out_voltageY_raw1.
MAINTAINERS +1 -0
index 16e344d52b1e..16a7fd7f98ee 100644
@@ -11187,6 +11187,7 @@ M:	Nuno Sá <[email protected]>
 L:	[email protected]
 S:	Supported
 W:	http://ez.analog.com/community/linux-device-drivers
+F:	Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
 F:	drivers/iio/dac/ltc2688.c
 
 LTC2947 HARDWARE MONITOR DRIVER
Signature · 1 line
2.33.1
author maintainer
#1 lore raw

PATCH v2 1/3 iio: dac: add support for ltc2688

In reply to Nuno Sá

The LTC2688 is a 16 channel, 16 bit, +-15V DAC with an integrated precision reference. It is guaranteed monotonic and has built in rail-to-rail output buffers that can source or sink up to 20 mA.

---
 MAINTAINERS               |    7 +
 drivers/iio/dac/Kconfig   |   11 +
 drivers/iio/dac/Makefile  |    1 +
 drivers/iio/dac/ltc2688.c | 1070 +++++++++++++++++++++++++++++++++++++
 4 files changed, 1089 insertions(+)
 create mode 100644 drivers/iio/dac/ltc2688.c
MAINTAINERS +7 -0
index de13836a8f7f..16e344d52b1e 100644
@@ -11182,6 +11182,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/dac/lltc,ltc1660.yaml
 F:	drivers/iio/dac/ltc1660.c
 
+LTC2688 IIO DAC DRIVER
+M:	Nuno Sá <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	http://ez.analog.com/community/linux-device-drivers
+F:	drivers/iio/dac/ltc2688.c
+
 LTC2947 HARDWARE MONITOR DRIVER
 M:	Nuno Sá <[email protected]>
 L:	[email protected]
drivers/iio/dac/Kconfig +11 -0
index bfcf7568de32..c0bf0d84197f 100644
@@ -131,6 +131,17 @@ config AD5624R_SPI
 	  Say yes here to build support for Analog Devices AD5624R, AD5644R and
 	  AD5664R converters (DAC). This driver uses the common SPI interface.
 
+config LTC2688
+	tristate "Analog Devices LTC2688 DAC spi driver"
+	depends on SPI
+	select REGMAP
+	help
+	  Say yes here to build support for Analog Devices
+	  LTC2688 converters (DAC).
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ltc2688.
+
 config AD5686
 	tristate
 
drivers/iio/dac/Makefile +1 -0
index 01a50131572f..ec3e42713f00 100644
@@ -35,6 +35,7 @@ obj-$(CONFIG_DS4424) += ds4424.o
 obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o
 obj-$(CONFIG_LTC1660) += ltc1660.o
 obj-$(CONFIG_LTC2632) += ltc2632.o
+obj-$(CONFIG_LTC2688) += ltc2688.o
 obj-$(CONFIG_M62332) += m62332.o
 obj-$(CONFIG_MAX517) += max517.o
 obj-$(CONFIG_MAX5821) += max5821.o
drivers/iio/dac/ltc2688.c new file +1070 -0

1,070 lines not on this page · raw message

Signature · 1 line
2.33.1
author maintainer
#10 lore raw

PATCH v2 3/3 dt-bindings: iio: Add ltc2688 documentation

In reply to Nuno Sá

Document the LTC2688 devicetree properties.

---
 .../bindings/iio/dac/adi,ltc2688.yaml         | 147 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 148 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +147 -0
new file mode 100644
index 000000000000..ecd0943fb813
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/dac/adi,ltc2688.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices LTC2688 DAC
+
+maintainers:
+  - Nuno Sá <[email protected]>
+
+description: |
+  Analog Devices LTC2688 16 channel, 16 bit, +-15V DAC
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ltc2688.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ltc2688
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:
+    description: Analog Supply Voltage Input.
+
+  iovcc-supply:
+    description: Digital Input/Output Supply Voltage.
+
+  vref-supply:
+    description:
+      Reference Input/Output. The voltage at the REF pin sets the full-scale
+      range of all channels. By default, the internal reference is routed to
+      this pin.
+
+  clr-gpios:
+    description:
+      If specified, it will be asserted during driver probe. As the line is
+      active low, it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+patternProperties:
+  "^channel@([0-9]|1[0-5])$":
+    type: object
+
+    properties:
+      reg:
+        description: The channel number representing the DAC output channel.
+        maximum: 15
+
+      adi,toggle-mode:
+        description:
+          Set the channel as a toggle enabled channel. Toggle operation enables
+          fast switching of a DAC output between two different DAC codes without
+          any SPI transaction. It will result in a different ABI for the
+          channel.
+        type: boolean
+
+      adi,output-range-microvolt:
+        description: Specify the channel output full scale range.
+        oneOf:
+          - items:
+              - const: 0
+              - enum: [5000000, 10000000]
+          - items:
+              - const: -5000000
+              - const: 5000000
+          - items:
+              - const: -10000000
+              - const: 10000000
+          - items:
+              - const: -15000000
+              - const: 15000000
+
+      adi,overrange:
+        description: Enable 5% overrange over the selected full scale range.
+        type: boolean
+
+      clocks:
+        maxItems: 1
+
+      adi,toggle-dither-input:
+        description:
+          Selects the TGPx pin to be associated with this channel. This setting
+          only makes sense for toggle or dither enabled channels. If
+          @adi,toggle-mode is not set and this property is given, the channel is
+          assumed to be a dither capable channel. Note that multiple channels
+          can be mapped to the same pin. If this setting is given, the
+          respective @clock must also be provided. Mappings between this and
+          clocks
+            0 - TGP1
+            1 - TGP2
+            2 - TGP3
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2]
+
+    dependencies:
+      adi,toggle-dither-input: [ clocks ]
+
+    required:
+      - reg
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+
+    spi {
+          #address-cells = <1>;
+          #size-cells = <0>;
+          ltc2688: ltc2688@0 {
+                  compatible = "adi,ltc2688";
+                  reg = <0>;
+
+                  vcc-supply = <&vcc>;
+                  iovcc-supply = <&vcc>;
+                  vref-supply = <&vref>;
+
+                  #address-cells = <1>;
+                  #size-cells = <0>;
+                  channel@0 {
+                          reg = <0>;
+                          adi,toggle-mode;
+                          adi,overrange;
+                  };
+
+                  channel@1 {
+                          reg = <1>;
+                          adi,output-range-microvolt = <0 10000000>;
+
+                          clocks = <&clock_tgp3>;
+                          adi,toggle-dither-input = <2>;
+                  };
+          };
+    };
+
+...
MAINTAINERS +1 -0
index 16a7fd7f98ee..137d4ed992cf 100644
@@ -11188,6 +11188,7 @@ L:	[email protected]
 S:	Supported
 W:	http://ez.analog.com/community/linux-device-drivers
 F:	Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
+F:	Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
 F:	drivers/iio/dac/ltc2688.c
 
 LTC2947 HARDWARE MONITOR DRIVER
Signature · 1 line
2.33.1
#2 lore raw

Re: [PATCH v2 1/3] iio: dac: add support for ltc2688

In reply to Nuno Sá
I love your patch! Yet something to improve:

Hi "Nuno,

I love your patch! Yet something to improve:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v5.16 next-20220115] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Nuno-S/Add-support-for-LTC2688/20220115-172930
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20220115/202201152138.RqRoWKHf-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 650fc40b6d8d9a5869b4fca525d5f237b0ee2803)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/d91bcc420e0c6077053e559f676fa4ae76114ba5
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nuno-S/Add-support-for-LTC2688/20220115-172930
git checkout d91bcc420e0c6077053e559f676fa4ae76114ba5
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/iio/dac/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/iio/dac/ltc2688.c:604:2: error: incompatible function pointer types initializing 'ssize_t (*)(struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'long (*)(struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') with an expression of type 'int (struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'int (struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types]
           LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_CMD_TOGGLE_DITHER_EN,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:11: note: expanded from macro 'LTC2688_CHAN_EXT_INFO'
           .write = (_write),                                              \
                    ^~~~~~~~
   drivers/iio/dac/ltc2688.c:619:2: error: incompatible function pointer types initializing 'ssize_t (*)(struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'long (*)(struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') with an expression of type 'int (struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'int (struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types]
           LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_CMD_TOGGLE_DITHER_EN,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:11: note: expanded from macro 'LTC2688_CHAN_EXT_INFO'
           .write = (_write),                                              \
                    ^~~~~~~~
   drivers/iio/dac/ltc2688.c:639:2: error: incompatible function pointer types initializing 'ssize_t (*)(struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'long (*)(struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') with an expression of type 'int (struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'int (struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types]
           LTC2688_CHAN_EXT_INFO("dither_frequency", 0, IIO_SEPARATE,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:11: note: expanded from macro 'LTC2688_CHAN_EXT_INFO'
           .write = (_write),                                              \
                    ^~~~~~~~
   drivers/iio/dac/ltc2688.c:641:2: error: incompatible function pointer types initializing 'ssize_t (*)(struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'long (*)(struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') with an expression of type 'int (struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'int (struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types]
           LTC2688_CHAN_EXT_INFO("dither_frequency_available",
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:11: note: expanded from macro 'LTC2688_CHAN_EXT_INFO'
           .write = (_write),                                              \
                    ^~~~~~~~
   drivers/iio/dac/ltc2688.c:647:2: error: incompatible function pointer types initializing 'ssize_t (*)(struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'long (*)(struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') with an expression of type 'int (struct iio_dev *, uintptr_t, const struct iio_chan_spec *, const char *, size_t)' (aka 'int (struct iio_dev *, unsigned long, const struct iio_chan_spec *, const char *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types]
           LTC2688_CHAN_EXT_INFO("dither_en", LTC2688_CMD_TOGGLE_DITHER_EN,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:11: note: expanded from macro 'LTC2688_CHAN_EXT_INFO'
           .write = (_write),                                              \
                    ^~~~~~~~

5 errors generated.

vim +604 drivers/iio/dac/ltc2688.c

594
595 /*
596 * For toggle mode we only expose the symbol attr (sw_toggle) in case a TGPx is
597 * not provided in dts.
598 */
599 static const struct iio_chan_spec_ext_info ltc2688_toggle_sym_ext_info[] = {
600 LTC2688_CHAN_EXT_INFO("raw0", LTC2688_INPUT_A, IIO_SEPARATE,
601 ltc2688_dac_input_read, ltc2688_dac_input_write),
602 LTC2688_CHAN_EXT_INFO("raw1", LTC2688_INPUT_B, IIO_SEPARATE,
603 ltc2688_dac_input_read, ltc2688_dac_input_write),

 > 604		LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_CMD_TOGGLE_DITHER_EN,

605 IIO_SEPARATE, ltc2688_reg_bool_get,
606 ltc2688_dither_toggle_set),
607 LTC2688_CHAN_EXT_INFO("powerdown", LTC2688_CMD_POWERDOWN, IIO_SEPARATE,
608 ltc2688_reg_bool_get, ltc2688_reg_bool_set),
609 LTC2688_CHAN_EXT_INFO("symbol", LTC2688_CMD_SW_TOGGLE, IIO_SEPARATE,
610 ltc2688_reg_bool_get, ltc2688_reg_bool_set),
611 {}
612 };
613

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw

Re: [PATCH v2 1/3] iio: dac: add support for ltc2688

In reply to Nuno Sá
I love your patch! Yet something to improve:

Hi "Nuno,

I love your patch! Yet something to improve:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v5.16 next-20220115] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Nuno-S/Add-support-for-LTC2688/20220115-172930
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20220116/202201160237.Mxs5GYw3-lkp(a)intel.com/config)
compiler: alpha-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d91bcc420e0c6077053e559f676fa4ae76114ba5
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nuno-S/Add-support-for-LTC2688/20220115-172930
git checkout d91bcc420e0c6077053e559f676fa4ae76114ba5
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/iio/dac/ltc2688.c:590:18: error: initialization of 'ssize_t (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'long int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} from incompatible pointer type 'int (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} [-Werror=incompatible-pointer-types]
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:604:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     604 |         LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_CMD_TOGGLE_DITHER_EN,
         |         ^~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:18: note: (near initialization for 'ltc2688_toggle_sym_ext_info[2].write')
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:604:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     604 |         LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_CMD_TOGGLE_DITHER_EN,
         |         ^~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/dac/ltc2688.c:590:18: error: initialization of 'ssize_t (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'long int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} from incompatible pointer type 'int (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} [-Werror=incompatible-pointer-types]
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:619:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     619 |         LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_CMD_TOGGLE_DITHER_EN,
         |         ^~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:18: note: (near initialization for 'ltc2688_toggle_ext_info[2].write')
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:619:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     619 |         LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_CMD_TOGGLE_DITHER_EN,
         |         ^~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/dac/ltc2688.c:590:18: error: initialization of 'ssize_t (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'long int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} from incompatible pointer type 'int (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} [-Werror=incompatible-pointer-types]
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:639:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     639 |         LTC2688_CHAN_EXT_INFO("dither_frequency", 0, IIO_SEPARATE,
         |         ^~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:18: note: (near initialization for 'ltc2688_dither_ext_info[3].write')
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:639:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     639 |         LTC2688_CHAN_EXT_INFO("dither_frequency", 0, IIO_SEPARATE,
         |         ^~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/dac/ltc2688.c:590:18: error: initialization of 'ssize_t (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'long int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} from incompatible pointer type 'int (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} [-Werror=incompatible-pointer-types]
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:641:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     641 |         LTC2688_CHAN_EXT_INFO("dither_frequency_available",
         |         ^~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:18: note: (near initialization for 'ltc2688_dither_ext_info[4].write')
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:641:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     641 |         LTC2688_CHAN_EXT_INFO("dither_frequency_available",
         |         ^~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/dac/ltc2688.c:590:18: error: initialization of 'ssize_t (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'long int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} from incompatible pointer type 'int (*)(struct iio_dev *, uintptr_t,  const struct iio_chan_spec *, const char *, size_t)' {aka 'int (*)(struct iio_dev *, long unsigned int,  const struct iio_chan_spec *, const char *, long unsigned int)'} [-Werror=incompatible-pointer-types]
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:647:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     647 |         LTC2688_CHAN_EXT_INFO("dither_en", LTC2688_CMD_TOGGLE_DITHER_EN,
         |         ^~~~~~~~~~~~~~~~~~~~~
   drivers/iio/dac/ltc2688.c:590:18: note: (near initialization for 'ltc2688_dither_ext_info[7].write')
     590 |         .write = (_write),                                              \
         |                  ^
   drivers/iio/dac/ltc2688.c:647:9: note: in expansion of macro 'LTC2688_CHAN_EXT_INFO'
     647 |         LTC2688_CHAN_EXT_INFO("dither_en", LTC2688_CMD_TOGGLE_DITHER_EN,
         |         ^~~~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +590 drivers/iio/dac/ltc2688.c

586
587 #define LTC2688_CHAN_EXT_INFO(_name, _what, _shared, _read, _write) { \
588 .name = _name, \
589 .read = (_read), \

 > 590		.write = (_write),						\

591 .private = (_what), \
592 .shared = (_shared), \
593 }
594

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#11 lore raw

Re: [PATCH v2 3/3] dt-bindings: iio: Add ltc2688 documentation

In reply to Nuno Sá
Quoted 3 lines · On Sat, 15 Jan 2022 10:27:05 +0100 Nuno Sá <[email protected]> wrote:

Document the LTC2688 devicetree properties.

Hi Nuno,

A few minor comments inline. I've reviewed this first so might find answers to some of them when reading the driver code.

Thanks,

Jonathan

Quoted 36 lines
---
 .../bindings/iio/dac/adi,ltc2688.yaml         | 147 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 148 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +24 -0
new file mode 100644
index 000000000000..ecd0943fb813
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/dac/adi,ltc2688.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices LTC2688 DAC
+
+maintainers:
+  - Nuno Sá <[email protected]>
+
+description: |
+  Analog Devices LTC2688 16 channel, 16 bit, +-15V DAC
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ltc2688.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ltc2688
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 34

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+    description: Analog Supply Voltage Input.
+
+  iovcc-supply:
+    description: Digital Input/Output Supply Voltage.
+
+  vref-supply:
+    description:
+      Reference Input/Output. The voltage at the REF pin sets the full-scale
+      range of all channels. By default, the internal reference is routed to
+      this pin.

Perhaps "If not provided the internal reference is used and also provided on the VREF pin".

Quoted 18 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +18 -0
+
+  clr-gpios:
+    description:
+      If specified, it will be asserted during driver probe. As the line is
+      active low, it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+patternProperties:
+  "^channel@([0-9]|1[0-5])$":
+    type: object
+
+    properties:

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 62

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+      reg:
+        description: The channel number representing the DAC output channel.
+        maximum: 15
+
+      adi,toggle-mode:
+        description:
+          Set the channel as a toggle enabled channel. Toggle operation enables
+          fast switching of a DAC output between two different DAC codes without
+          any SPI transaction. It will result in a different ABI for the
+          channel.

The ABI bit is a linux specific part so shouldn't be in the binding. Just leave it unsaid.

Quoted 7 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +7 -0
+        type: boolean
+
+      adi,output-range-microvolt:
+        description: Specify the channel output full scale range.
+        oneOf:
+          - items:
+              - const: 0

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 79

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+              - enum: [5000000, 10000000]
+          - items:
+              - const: -5000000
+              - const: 5000000
+          - items:
+              - const: -10000000
+              - const: 10000000
+          - items:
+              - const: -15000000
+              - const: 15000000

Not necessarily a thing to do now, but this is common enough we should make it a standard DAC channel property.

Quoted 7 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +7 -0
+
+      adi,overrange:
+        description: Enable 5% overrange over the selected full scale range.
+        type: boolean
+
+      clocks:
+        maxItems: 1

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 96

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+
+      adi,toggle-dither-input:
+        description:
+          Selects the TGPx pin to be associated with this channel. This setting
+          only makes sense for toggle or dither enabled channels. If
+          @adi,toggle-mode is not set and this property is given, the channel is
+          assumed to be a dither capable channel. Note that multiple channels
+          can be mapped to the same pin. If this setting is given, the
+          respective @clock must also be provided. Mappings between this and
+          clocks

That's not clear, mapping between this an input pin is probably more accurate?

Quoted 27 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +27 -0
+            0 - TGP1
+            1 - TGP2
+            2 - TGP3
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2]
+
+    dependencies:
+      adi,toggle-dither-input: [ clocks ]
+
+    required:
+      - reg
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+
+    spi {
+          #address-cells = <1>;
+          #size-cells = <0>;
+          ltc2688: ltc2688@0 {
+                  compatible = "adi,ltc2688";
+                  reg = <0>;

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 133

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+
+                  vcc-supply = <&vcc>;
+                  iovcc-supply = <&vcc>;
+                  vref-supply = <&vref>;
+
+                  #address-cells = <1>;
+                  #size-cells = <0>;
+                  channel@0 {
+                          reg = <0>;
+                          adi,toggle-mode;

Can do this without adi,toggle-dither-input?

Quoted 26 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +14 -0
+                          adi,overrange;
+                  };
+
+                  channel@1 {
+                          reg = <1>;
+                          adi,output-range-microvolt = <0 10000000>;
+
+                          clocks = <&clock_tgp3>;
+                          adi,toggle-dither-input = <2>;
+                  };
+          };
+    };
+
+...
MAINTAINERS +1 -0
index 16a7fd7f98ee..137d4ed992cf 100644
@@ -11188,6 +11188,7 @@ L:	[email protected]
 S:	Supported
 W:	http://ez.analog.com/community/linux-device-drivers
 F:	Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
+F:	Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
 F:	drivers/iio/dac/ltc2688.c
 
 LTC2947 HARDWARE MONITOR DRIVER
maintainer
#8 lore raw

Re: [PATCH v2 2/3] iio: ABI: add ABI file for the LTC2688 DAC

In reply to Nuno Sá
Quoted 12 lines · On Sat, 15 Jan 2022 10:27:04 +0100 Nuno Sá <[email protected]> wrote:

Define the sysfs interface for toggle or dither capable channels. Dither capable channels will have the extended interface:

* out_voltageY_dither_en
* out_voltageY_dither_raw
* out_voltageY_dither_offset
* out_voltageY_dither_raw_available
* out_voltageY_dither_frequency
* out_voltageY_dither_frequency_available
* out_voltageY_dither_phase
* out_voltageY_dither_phase_available

Quoted 6 lines

Toggle enabled channels will have:

* out_voltageY_toggle_en
* out_voltageY_raw0
* out_voltageY_raw1
* out_voltageY_symbol

Maybe worth just stating the normal interface here as well because it's not clear from these examples if
out_voltageY_raw still exists for toggle enabled channels (I'm assuming not?)

Quoted 2 lines

ABI seems good to me, just a few comments on details of the documentation.

Thanks,

Jonathan

Quoted 15 lines
---
 .../ABI/testing/sysfs-bus-iio-dac-ltc2688     | 80 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 81 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +3 -0
new file mode 100644
index 000000000000..38d1df81c6dc
@@ -0,0 +1,80 @@
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_en
+KernelVersion:	5.17
+Contact:	[email protected]

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 13

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +10 -0
+Description:
+		Dither enable. Write 1 to enable dither or 0 to disable it.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_raw
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		This raw, unscaled value refers to the dither signal amplitude.
+		The same scale as in out_voltageY_raw applies. However, the
+		offset might be different as it's always 0 for this attribute.

We'll have to be careful if we ever generalize these docs but what you have here is fine whilst it applies to just this device.

Quoted 9 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +9 -0
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_raw_available
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Available range for dither raw amplitude values.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_offset
+KernelVersion:	5.17

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 32

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +10 -0
+Contact:	[email protected]
+Description:
+		Offset applied to out_voltageY_dither_raw. Read only attribute
+		always set to 0.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_frequency
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Sets the dither signal frequency.

Units.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 44

Quoted 12 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +12 -0
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_frequency_available
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Returns the available values for the dither frequency.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_phase
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Sets the dither signal phase.

Units. Radians, or refer to the main _phase docs and say it's the same.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 56

Quoted 12 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +12 -0
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_phase_available
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Returns the available values for the dither phase.
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_toggle_en
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Toggle enable. Write 1 to enable toggle or 0 to disable it.

Say why this is useful (presumably toggle with a clock rather than via _symbol)

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 64

Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +8 -0
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_raw0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		It has the same meaning as out_voltageY_raw. This attribute is
+		specific to toggle enabled channels and refers to the DAC output
+		code in INPUT_A. The same scale, offset, etc applies.

Same as what?

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 71

Quoted 7 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +7 -0
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_raw1
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Same as out_voltageY_raw0 but referring to the DAC output code
+		in INPUT_B.

You could combine this with previous and have two what lines. Might allow a slightly more compact clear description.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 73

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+
+What:		/sys/bus/iio/devices/iio:deviceX/out_voltageY_symbol

Ah. That answers one of my binding related questions :) You have kept software control as an option for toggle.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 78

Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +5 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Performs a SW toggle. This attribute is specific to toggle
+		enabled channels and allows to toggle between out_voltageY_raw

_raw0

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 80

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+		and out_voltageY_raw1 through software. Writing 0 will select
+		out_voltageY_raw while 1 selects out_voltageY_raw1.

_raw0

Quoted 12 lines
MAINTAINERS +1 -0
index 16e344d52b1e..16a7fd7f98ee 100644
@@ -11187,6 +11187,7 @@ M:	Nuno Sá <[email protected]>
 L:	[email protected]
 S:	Supported
 W:	http://ez.analog.com/community/linux-device-drivers
+F:	Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
 F:	drivers/iio/dac/ltc2688.c
 
 LTC2947 HARDWARE MONITOR DRIVER
maintainer
#4 lore raw

Re: [PATCH v2 1/3] iio: dac: add support for ltc2688

In reply to Nuno Sá
Quoted 5 lines · On Sat, 15 Jan 2022 10:27:03 +0100 Nuno Sá <[email protected]> wrote:

The LTC2688 is a 16 channel, 16 bit, +-15V DAC with an integrated precision reference. It is guaranteed monotonic and has built in rail-to-rail output buffers that can source or sink up to 20 mA.

A few minor additions inline.

In particular I think we can work around that lack of device_for_each_available_child_node() issue and use generic fw propreties. rather than of ones. That way we can separate things from the question of how to 'fix' that issue.

One thing I'm not sure on is the phase units. Right now I think you are exposing just the raw register value whereas I think that needs converting to radians.

Jonathan

...

drivers/iio/dac/ltc2688.c line 754

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+static int ltc2688_channel_config(struct ltc2688_state *st)
+{
+	struct device *dev = &st->spi->dev;
+	struct device_node *child;
+	u32 reg, clk_input, val, tmp[2];
+	int ret, span;
+
+	for_each_available_child_of_node(dev->of_node, child) {

Gah. This still going on with there not being a generic _available_ specific form. We need to kick that again because I'm not keen to merge another driver we'll need to tidy up later to use generic properties.

Best bet is probably to just define device_for_each_available_child_node() and see if anyone shoots it down (even if it does the same as device_for_each_child_node() in at least some cases).

Or thinking about it.. Here you could use device_for_each_child_node() and then call fwnode_device_is_available() on the result and continue if not true.

Will always return true (I think) but will make the intent clear.

We can tidy up to a new for_* if / when it becomes available.

Quoted 115 lines
drivers/iio/dac/ltc2688.c new file +115 -0
+		struct ltc2688_chan *chan;
+
+		ret = of_property_read_u32(child, "reg", &reg);
+		if (ret) {
+			of_node_put(child);
+			return dev_err_probe(dev, ret,
+					     "Failed to get reg property\n");
+		}
+
+		if (reg >= LTC2688_DAC_CHANNELS) {
+			of_node_put(child);
+			return dev_err_probe(dev, -EINVAL,
+					     "reg bigger than: %d\n",
+					     LTC2688_DAC_CHANNELS);
+		}
+
+		val = 0;
+		chan = &st->channels[reg];
+		if (of_property_read_bool(child, "adi,toggle-mode")) {
+			chan->toggle_chan = true;
+			/* assume sw toggle ABI */
+			st->iio_chan[reg].ext_info = ltc2688_toggle_sym_ext_info;
+			/*
+			 * Clear IIO_CHAN_INFO_RAW bit as toggle channels expose
+			 * out_voltage_raw{0|1} files.
+			 */
+			clear_bit(IIO_CHAN_INFO_RAW,
+				  &st->iio_chan[reg].info_mask_separate);
+		}
+
+		ret = of_property_read_u32_array(child, "adi,output-range-microvolt",
+						 tmp, ARRAY_SIZE(tmp));
+		if (!ret) {
+			span = ltc2688_span_lookup(st, (int)tmp[0] / 1000,
+						   tmp[1] / 1000);
+			if (span < 0) {
+				of_node_put(child);
+				return dev_err_probe(dev, -EINVAL,
+						     "output range not valid:[%d %d]\n",
+						     tmp[0], tmp[1]);
+			}
+
+			val |= FIELD_PREP(LTC2688_CH_SPAN_MSK, span);
+		}
+
+		ret = of_property_read_u32(child, "adi,toggle-dither-input",
+					   &clk_input);
+		if (!ret) {
+			if (clk_input >= LTC2688_CH_TGP_MAX) {
+				of_node_put(child);
+				return dev_err_probe(dev, -EINVAL,
+						     "toggle-dither-input inv value(%d)\n",
+						     clk_input);
+			}
+
+			ret = ltc2688_tgp_clk_setup(st, chan, child, clk_input);
+			if (ret) {
+				of_node_put(child);
+				return ret;
+			}
+
+			/*
+			 * 0 means software toggle which is the default mode.
+			 * Hence the +1.
+			 */
+			val |= FIELD_PREP(LTC2688_CH_TD_SEL_MSK, clk_input + 1);
+
+			/*
+			 * If a TGPx is given, we automatically assume a dither
+			 * capable channel (unless toggle is already enabled).
+			 * On top of this we just set here the dither bit in the
+			 * channel settings. It won't have any effect until the
+			 * global toggle/dither bit is enabled.
+			 */
+			if (!chan->toggle_chan) {
+				val |= FIELD_PREP(LTC2688_CH_MODE_MSK, 1);
+				st->iio_chan[reg].ext_info = ltc2688_dither_ext_info;
+			} else {
+				/* wait, no sw toggle after all */
+				st->iio_chan[reg].ext_info = ltc2688_toggle_ext_info;
+			}
+		}
+
+		if (of_property_read_bool(child, "adi,overrange")) {
+			chan->overrange = true;
+			val |= LTC2688_CH_OVERRANGE_MSK;
+		}
+
+		if (!val)
+			continue;
+
+		ret = regmap_write(st->regmap, LTC2688_CMD_CH_SETTING(reg),
+				   val);
+		if (ret) {
+			of_node_put(child);
+			return dev_err_probe(dev, -EINVAL,
+					     "failed to set chan settings\n");
+		}
+	}
+
+	return 0;
+}
+
+static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref)
+{
+	struct gpio_desc *gpio;
+	int ret;
+
+	/*
+	 * If we have a reset pin, use that to reset the board, If not, use
+	 * the reset bit.
+	 */
+	gpio = devm_gpiod_get_optional(&st->spi->dev, "clr", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpio))
+		return dev_err_probe(&st->spi->dev, PTR_ERR(gpio),

drivers/iio/dac/ltc2688.c line 879

Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10 -0
+				     "Failed to get reset gpio");
+	if (gpio) {
+		usleep_range(1000, 1200);
+		/* bring device out of reset */
+		gpiod_set_value_cansleep(gpio, 0);
+	} else {
+		ret = regmap_update_bits(st->regmap, LTC2688_CMD_CONFIG,
+					 LTC2688_CONFIG_RST,
+					 LTC2688_CONFIG_RST);
+		if (ret < 0)

A bit of a mixture in here on whether you prefer if (ret) or if (ret < 0) for error returns you know can't be postive.

I'd go with if (ret) for all of them. It makes things consistent with the cases where you directly return the value without checking it for less than 0 like below.

Quoted 16 lines
drivers/iio/dac/ltc2688.c new file +16 -0
+			return ret;
+	}
+
+	usleep_range(10000, 12000);
+
+	/*
+	 * Duplicate the default channel configuration as it can change during
+	 * @ltc2688_channel_config()
+	 */
+	st->iio_chan = devm_kmemdup(&st->spi->dev, ltc2688_channels,
+				    sizeof(ltc2688_channels), GFP_KERNEL);
+	if (!st->iio_chan)
+		return -ENOMEM;
+
+	ret = ltc2688_channel_config(st);
+	if (ret)

drivers/iio/dac/ltc2688.c line 905

Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10 -0
+		return ret;
+
+	if (!vref)
+		return 0;
+
+	return regmap_set_bits(st->regmap, LTC2688_CMD_CONFIG,
+			       LTC2688_CONFIG_EXT_REF);
+}
+
+static void ltc2688_bulk_disable(void *data)

rename to mention regulators. Could be bulk disabling something else...

drivers/iio/dac/ltc2688.c line 911

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+{
+	struct ltc2688_state *st = data;
+
+	regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators);
+}
+

...

Thanks,

Jonathan

author maintainer
#9 lore raw

RE: [PATCH v2 2/3] iio: ABI: add ABI file for the LTC2688 DAC

In reply to Jonathan Cameron
Quoted 37 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, January 16, 2022 1:21 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]; [email protected]; Rob Herring <[email protected]>; Lars-Peter Clausen <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v2 2/3] iio: ABI: add ABI file for the LTC2688 DAC

[External]

Quoted 1 line · On Sat, 15 Jan 2022 10:27:04 +0100 Nuno Sá <[email protected]> wrote:

Define the sysfs interface for toggle or dither capable channels.

Dither

Quoted 11 lines

capable channels will have the extended interface:

* out_voltageY_dither_en
* out_voltageY_dither_raw
* out_voltageY_dither_offset
* out_voltageY_dither_raw_available
* out_voltageY_dither_frequency
* out_voltageY_dither_frequency_available
* out_voltageY_dither_phase
* out_voltageY_dither_phase_available

Quoted 6 lines

Toggle enabled channels will have:

* out_voltageY_toggle_en
* out_voltageY_raw0
* out_voltageY_raw1
* out_voltageY_symbol

Quoted 4 lines

Maybe worth just stating the normal interface here as well because it's not clear from these examples if
out_voltageY_raw still exists for toggle enabled channels (I'm assuming not?)

Yes, it does not exist as It would not make sense :)...

Quoted 132 lines
Quoted 2 lines

ABI seems good to me, just a few comments on details of the documentation.
Thanks,

Jonathan

Quoted 2 lines
---
 .../ABI/testing/sysfs-bus-iio-dac-ltc2688     | 80

+++++++++++++++++++

Quoted 3 lines
 MAINTAINERS                                   |  1 +
 2 files changed, 81 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-dac-

ltc2688

Review

Quoted 2 lines
(quoted diff) +0 -0

b/Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 1

Quoted 6 lines

new file mode 100644
index 000000000000..38d1df81c6dc

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
@@ -0,0 +1,80 @@
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_en

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +6 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Dither enable. Write 1 to enable dither or 0 to disable it.
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_raw

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +4 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		This raw, unscaled value refers to the dither signal

amplitude.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 12

Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
+		The same scale as in out_voltageY_raw applies.

However, the

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 13

Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
+		offset might be different as it's always 0 for this

attribute.

We'll have to be careful if we ever generalize these docs but what you have here
is fine whilst it applies to just this device.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 15

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_raw_av
ailable

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +6 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Available range for dither raw amplitude values.
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_offset

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +4 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Offset applied to out_voltageY_dither_raw. Read only

attribute

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +3 -0
+		always set to 0.
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_freque
ncy

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 32

Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +4 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Sets the dither signal frequency.

Units.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 34

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_freque
ncy_available

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +6 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Returns the available values for the dither frequency.
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_phase

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 44

Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +4 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Sets the dither signal phase.

Units. Radians, or refer to the main _phase docs and say it's the same.

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 46

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_dither_phase_
available

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +6 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Returns the available values for the dither phase.
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_toggle_en

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +4 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Toggle enable. Write 1 to enable toggle or 0 to disable

it.

Say why this is useful (presumably toggle with a clock rather than via _symbol)

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 58

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_raw0

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +4 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		It has the same meaning as out_voltageY_raw. This

attribute is

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 63

Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
+		specific to toggle enabled channels and refers to the

DAC output

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 64

Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
+		code in INPUT_A. The same scale, offset, etc applies.

Same as what?

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 66

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_raw1

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +4 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Same as out_voltageY_raw0 but referring to the DAC

output code

Quoted 5 lines

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 71

Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
+		in INPUT_B.

You could combine this with previous and have two what lines. Might allow
a slightly more compact clear description.

Did not remembered I could do that...

Quoted 8 lines

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 73

Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +2 -0
+
+What:

/sys/bus/iio/devices/iio:deviceX/out_voltageY_symbol

Ah. That answers one of my binding related questions :) You have kept
software control as an option for toggle.

Yeah... It was your suggestion to expose this one only when no pin is given in dts 😉.

Quoted 7 lines

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688

Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +5 -0
+KernelVersion:	5.17
+Contact:	[email protected]
+Description:
+		Performs a SW toggle. This attribute is specific to toggle
+		enabled channels and allows to toggle between

out_voltageY_raw

Quoted 6 lines

_raw0

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 79

Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
+		and out_voltageY_raw1 through software. Writing 0

will select

Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 line 80

Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +1 -0
+		out_voltageY_raw while 1 selects out_voltageY_raw1.

_raw0

Forgot to change it here and above :/

- Nuno Sá

author maintainer
#12 lore raw

RE: [PATCH v2 3/3] dt-bindings: iio: Add ltc2688 documentation

In reply to Jonathan Cameron
Quoted 86 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, January 16, 2022 1:02 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]; [email protected]; Rob Herring <[email protected]>; Lars-Peter Clausen <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v2 3/3] dt-bindings: iio: Add ltc2688 documentation

[External]

Quoted 3 lines · On Sat, 15 Jan 2022 10:27:05 +0100 Nuno Sá <[email protected]> wrote:

Document the LTC2688 devicetree properties.

Hi Nuno,

A few minor comments inline. I've reviewed this first so might find answers to some of them when reading the driver code.

Thanks,

Jonathan

Quoted 2 lines
---
 .../bindings/iio/dac/adi,ltc2688.yaml         | 147

++++++++++++++++++

Quoted 3 lines
 MAINTAINERS                                   |   1 +
 2 files changed, 148 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Quoted 2 lines

diff --git

a/Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 4

Quoted 9 lines

new file mode 100644
index 000000000000..ecd0943fb813

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +4 -0
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id:

https://urldefense.com/v3/__http://devicetree.org/schemas/iio/dac/
adi,ltc2688.yaml*__;Iw!!A3Ni8CS0y2Y!qhcjFFDY939hv3Lo2iT1fAIbSObt YscKoXjAnLgWZRNG6_WE2WXgZ8AdE4FUwg$

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 5

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +1 -0
+$schema:

https://urldefense.com/v3/__http://devicetree.org/meta-
schemas/core.yaml*__;Iw!!A3Ni8CS0y2Y!qhcjFFDY939hv3Lo2iT1fAIbS ObtYscKoXjAnLgWZRNG6_WE2WXgZ8BOzIvN9g$

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Quoted 9 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +9 -0
+
+title: Analog Devices LTC2688 DAC
+
+maintainers:
+  - Nuno Sá <[email protected]>
+
+description: |
+  Analog Devices LTC2688 16 channel, 16 bit, +-15V DAC
+  https://www.analog.com/media/en/technical-

documentation/data-sheets/ltc2688.pdf

Quoted 8 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +8 -0
+
+properties:
+  compatible:
+    enum:
+      - adi,ltc2688
+
+  reg:
+    maxItems: 1

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+
+  vcc-supply:
+    description: Analog Supply Voltage Input.
+
+  iovcc-supply:
+    description: Digital Input/Output Supply Voltage.
+
+  vref-supply:
+    description:
+      Reference Input/Output. The voltage at the REF pin sets the full-

scale

Quoted 7 lines

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 33

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +1 -0
+      range of all channels. By default, the internal reference is routed

to

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 34

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +1 -0
+      this pin.

Perhaps "If not provided the internal reference is used and also provided on the
VREF pin".

Sure...

Quoted 27 lines
Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+
+  clr-gpios:
+    description:
+      If specified, it will be asserted during driver probe. As the line is
+      active low, it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+  '#size-cells':
+    const: 0
+
+patternProperties:
+  "^channel@([0-9]|1[0-5])$":
+    type: object
+
+    properties:
+      reg:
+        description: The channel number representing the DAC output

channel.

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Quoted 5 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +5 -0
+        maximum: 15
+
+      adi,toggle-mode:
+        description:
+          Set the channel as a toggle enabled channel. Toggle operation

enables

Quoted 8 lines

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 60

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +1 -0
+          fast switching of a DAC output between two different DAC

codes without

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 62

Quoted 2 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +2 -0
+          any SPI transaction. It will result in a different ABI for the
+          channel.

The ABI bit is a linux specific part so shouldn't be in the binding. Just leave
it unsaid.

Makes sense...

Quoted 39 lines
Quoted 7 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +7 -0
+        type: boolean
+
+      adi,output-range-microvolt:
+        description: Specify the channel output full scale range.
+        oneOf:
+          - items:
+              - const: 0

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 79

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +10 -0
+              - enum: [5000000, 10000000]
+          - items:
+              - const: -5000000
+              - const: 5000000
+          - items:
+              - const: -10000000
+              - const: 10000000
+          - items:
+              - const: -15000000
+              - const: 15000000

Not necessarily a thing to do now, but this is common enough we should
make it a standard DAC channel property.

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Quoted 3 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +3 -0
+
+      adi,overrange:
+        description: Enable 5% overrange over the selected full scale

range.

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml

Quoted 8 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +8 -0
+        type: boolean
+
+      clocks:
+        maxItems: 1
+
+      adi,toggle-dither-input:
+        description:
+          Selects the TGPx pin to be associated with this channel. This

setting

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 92

Quoted 2 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +2 -0
+          only makes sense for toggle or dither enabled channels. If
+          @adi,toggle-mode is not set and this property is given, the

channel is

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 93

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +1 -0
+          assumed to be a dither capable channel. Note that multiple
Quoted 8 lines

channels

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 95

Quoted 2 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +2 -0
+          can be mapped to the same pin. If this setting is given, the
+          respective @clock must also be provided. Mappings between

this and

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 96

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +1 -0
+          clocks

That's not clear, mapping between this an input pin is probably more accurate?

Yeah, you're right. When I added this, I had the clock-names properties with these exact names. So, in the first version it was more acceptable but since I removed clock-names, this is not clear anymore...

Quoted 31 lines
Quoted 31 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +31 -0
+            0 - TGP1
+            1 - TGP2
+            2 - TGP3
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2]
+
+    dependencies:
+      adi,toggle-dither-input: [ clocks ]
+
+    required:
+      - reg
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+
+    spi {
+          #address-cells = <1>;
+          #size-cells = <0>;
+          ltc2688: ltc2688@0 {
+                  compatible = "adi,ltc2688";
+                  reg = <0>;
+
+                  vcc-supply = <&vcc>;
+                  iovcc-supply = <&vcc>;
+                  vref-supply = <&vref>;
Quoted 8 lines

Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml line 133

Quoted 6 lines
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +6 -0
+
+                  #address-cells = <1>;
+                  #size-cells = <0>;
+                  channel@0 {
+                          reg = <0>;
+                          adi,toggle-mode;

Can do this without adi,toggle-dither-input?

Yes, In this case it will assume SW toggle and expose the _symbol interface...

- Nuno Sá

author maintainer
#5 lore raw

RE: [PATCH v2 1/3] iio: dac: add support for ltc2688

In reply to Jonathan Cameron
Quoted 29 lines

From: Jonathan Cameron <[email protected]>
Sent: Sunday, January 16, 2022 1:44 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]; [email protected]; Rob Herring <[email protected]>; Lars-Peter Clausen <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v2 1/3] iio: dac: add support for ltc2688

[External]

Quoted 5 lines · On Sat, 15 Jan 2022 10:27:03 +0100 Nuno Sá <[email protected]> wrote:

The LTC2688 is a 16 channel, 16 bit, +-15V DAC with an integrated precision reference. It is guaranteed monotonic and has built in rail-to-rail output buffers that can source or sink up to 20 mA.

A few minor additions inline.

In particular I think we can work around that lack of device_for_each_available_child_node() issue and use generic fw propreties.
rather than of ones. That way we can separate things from the question of
how to 'fix' that issue.

Quoted 4 lines

One thing I'm not sure on is the phase units. Right now I think you are exposing just the raw register value whereas I think that needs converting
to radians.

It's returning degrees which I think is fairly ok. But I know that in general we report radians, so I'm more than fine in changing this if you prefer it.

Quoted 25 lines

Jonathan

...

drivers/iio/dac/ltc2688.c line 754

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+static int ltc2688_channel_config(struct ltc2688_state *st)
+{
+	struct device *dev = &st->spi->dev;
+	struct device_node *child;
+	u32 reg, clk_input, val, tmp[2];
+	int ret, span;
+
+	for_each_available_child_of_node(dev->of_node, child) {

Gah. This still going on with there not being a generic _available_ specific form. We need to kick that again because I'm not keen to merge another driver we'll need to tidy up later to use generic properties.

Best bet is probably to just define device_for_each_available_child_node() and see if anyone shoots it down (even if it does the same as device_for_each_child_node() in at least some cases).

Quoted 9 lines

Or thinking about it.. Here you could use device_for_each_child_node()
and then call fwnode_device_is_available() on the result and continue if not true.

Will always return true (I think) but will make the intent clear.

We can tidy up to a new for_* if / when it becomes available.

Hmm, not sure I'm following you... I mean, I understand what you're saying here but there is a reason for why I changed the whole thing to use OF. Please take a look at the cover... I explain why I've done it.

Quoted 155 lines

drivers/iio/dac/ltc2688.c

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+		struct ltc2688_chan *chan;
+
+		ret = of_property_read_u32(child, "reg", &reg);
+		if (ret) {
+			of_node_put(child);
+			return dev_err_probe(dev, ret,
+					     "Failed to get reg

property\n");

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+		}
+
+		if (reg >= LTC2688_DAC_CHANNELS) {
+			of_node_put(child);
+			return dev_err_probe(dev, -EINVAL,

drivers/iio/dac/ltc2688.c

Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10 -0
+					     "reg bigger than: %d\n",
+					     LTC2688_DAC_CHANNELS);
+		}
+
+		val = 0;
+		chan = &st->channels[reg];
+		if (of_property_read_bool(child, "adi,toggle-mode")) {
+			chan->toggle_chan = true;
+			/* assume sw toggle ABI */
+			st->iio_chan[reg].ext_info =

ltc2688_toggle_sym_ext_info;

Review

Quoted 2 lines
(quoted diff) +2 -0
+			/*
+			 * Clear IIO_CHAN_INFO_RAW bit as toggle

channels expose

drivers/iio/dac/ltc2688.c

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+			 * out_voltage_raw{0|1} files.
+			 */
+			clear_bit(IIO_CHAN_INFO_RAW,
+				  &st-

iio_chan[reg].info_mask_separate);

drivers/iio/dac/ltc2688.c new file +3 -0
+		}
+
+		ret = of_property_read_u32_array(child, "adi,output-

range-microvolt",

Review

Quoted 1 line
(quoted diff) +1 -0
+						 tmp,

ARRAY_SIZE(tmp));

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (!ret) {
+			span = ltc2688_span_lookup(st, (int)tmp[0] /

1000,

drivers/iio/dac/ltc2688.c

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+						   tmp[1] / 1000);
+			if (span < 0) {
+				of_node_put(child);
+				return dev_err_probe(dev, -EINVAL,
+						     "output range not

valid:[%d %d]\n",

drivers/iio/dac/ltc2688.c

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+						     tmp[0], tmp[1]);
+			}
+
+			val |= FIELD_PREP(LTC2688_CH_SPAN_MSK,

span);

drivers/iio/dac/ltc2688.c

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+		}
+
+		ret = of_property_read_u32(child, "adi,toggle-dither-

input",

drivers/iio/dac/ltc2688.c

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+					   &clk_input);
+		if (!ret) {
+			if (clk_input >= LTC2688_CH_TGP_MAX) {
+				of_node_put(child);
+				return dev_err_probe(dev, -EINVAL,
+						     "toggle-dither-input

inv value(%d)\n",

drivers/iio/dac/ltc2688.c

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+						     clk_input);
+			}
+
+			ret = ltc2688_tgp_clk_setup(st, chan, child,

clk_input);

drivers/iio/dac/ltc2688.c

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+			if (ret) {
+				of_node_put(child);
+				return ret;
+			}
+
+			/*
+			 * 0 means software toggle which is the default

mode.

drivers/iio/dac/ltc2688.c

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+			 * Hence the +1.
+			 */
+			val |= FIELD_PREP(LTC2688_CH_TD_SEL_MSK,

clk_input + 1);

drivers/iio/dac/ltc2688.c

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+
+			/*
+			 * If a TGPx is given, we automatically assume a

dither

Review

Quoted 1 line
(quoted diff) +1 -0
+			 * capable channel (unless toggle is already

enabled).

Review

Quoted 1 line
(quoted diff) +1 -0
+			 * On top of this we just set here the dither bit

in the

Review

Quoted 1 line
(quoted diff) +1 -0
+			 * channel settings. It won't have any effect

until the

drivers/iio/dac/ltc2688.c

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+			 * global toggle/dither bit is enabled.
+			 */
+			if (!chan->toggle_chan) {
+				val |=

FIELD_PREP(LTC2688_CH_MODE_MSK, 1);

Review

Quoted 1 line
(quoted diff) +1 -0
+				st->iio_chan[reg].ext_info =

ltc2688_dither_ext_info;

drivers/iio/dac/ltc2688.c

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+			} else {
+				/* wait, no sw toggle after all */
+				st->iio_chan[reg].ext_info =

ltc2688_toggle_ext_info;

drivers/iio/dac/ltc2688.c

Quoted 12 lines
drivers/iio/dac/ltc2688.c new file +12 -0
+			}
+		}
+
+		if (of_property_read_bool(child, "adi,overrange")) {
+			chan->overrange = true;
+			val |= LTC2688_CH_OVERRANGE_MSK;
+		}
+
+		if (!val)
+			continue;
+
+		ret = regmap_write(st->regmap,

LTC2688_CMD_CH_SETTING(reg),

drivers/iio/dac/ltc2688.c

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+				   val);
+		if (ret) {
+			of_node_put(child);
+			return dev_err_probe(dev, -EINVAL,
+					     "failed to set chan

settings\n");

drivers/iio/dac/ltc2688.c

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+		}
+	}
+
+	return 0;
+}
+
+static int ltc2688_setup(struct ltc2688_state *st, struct regulator

*vref)

drivers/iio/dac/ltc2688.c

Quoted 9 lines
drivers/iio/dac/ltc2688.c new file +9 -0
+{
+	struct gpio_desc *gpio;
+	int ret;
+
+	/*
+	 * If we have a reset pin, use that to reset the board, If not, use
+	 * the reset bit.
+	 */
+	gpio = devm_gpiod_get_optional(&st->spi->dev, "clr",

GPIOD_OUT_HIGH);

drivers/iio/dac/ltc2688.c

Quoted 9 lines
drivers/iio/dac/ltc2688.c new file +9 -0
+	if (IS_ERR(gpio))
+		return dev_err_probe(&st->spi->dev, PTR_ERR(gpio),
+				     "Failed to get reset gpio");
+	if (gpio) {
+		usleep_range(1000, 1200);
+		/* bring device out of reset */
+		gpiod_set_value_cansleep(gpio, 0);
+	} else {
+		ret = regmap_update_bits(st->regmap,

LTC2688_CMD_CONFIG,

drivers/iio/dac/ltc2688.c line 879

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+					 LTC2688_CONFIG_RST,
+					 LTC2688_CONFIG_RST);
+		if (ret < 0)

A bit of a mixture in here on whether you prefer if (ret) or if (ret < 0) for error returns you know can't be postive.

Quoted 3 lines

I'd go with if (ret) for all of them. It makes things consistent with the cases where you directly return the value without checking it for less than 0 like below.

Yeah, sometimes my hands get confused :). Or probably, just copy pasting. But I agree with you, when ret > 0 has no meaning I always want to do if (ret) but you know...

- Nuno Sá

maintainer
#6 lore raw

Re: [PATCH v2 1/3] iio: dac: add support for ltc2688

Quoted 29 lines · Nuno
Quoted 29 lines

From: Jonathan Cameron <[email protected]>
Sent: Sunday, January 16, 2022 1:44 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]; [email protected]; Rob Herring <[email protected]>; Lars-Peter Clausen <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v2 1/3] iio: dac: add support for ltc2688

[External]

Quoted 5 lines · On Sat, 15 Jan 2022 10:27:03 +0100 Nuno Sá <[email protected]> wrote:

The LTC2688 is a 16 channel, 16 bit, +-15V DAC with an integrated precision reference. It is guaranteed monotonic and has built in rail-to-rail output buffers that can source or sink up to 20 mA.

A few minor additions inline.

In particular I think we can work around that lack of device_for_each_available_child_node() issue and use generic fw propreties.
rather than of ones. That way we can separate things from the question of
how to 'fix' that issue.

Quoted 7 lines
Quoted 4 lines

One thing I'm not sure on is the phase units. Right now I think you are exposing just the raw register value whereas I think that needs converting
to radians.

It's returning degrees which I think is fairly ok. But I know that in general we report radians, so I'm more than fine in changing this if you prefer it.

Radians for consistency is a must as users reading the docs may see the main _phase descriptions and have no reason to think this one might be different.

Quoted 31 lines
Quoted 31 lines

Jonathan

...

drivers/iio/dac/ltc2688.c line 754

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+static int ltc2688_channel_config(struct ltc2688_state *st)
+{
+	struct device *dev = &st->spi->dev;
+	struct device_node *child;
+	u32 reg, clk_input, val, tmp[2];
+	int ret, span;
+
+	for_each_available_child_of_node(dev->of_node, child) {  

Gah. This still going on with there not being a generic _available_ specific form. We need to kick that again because I'm not keen to merge another driver we'll need to tidy up later to use generic properties.

Best bet is probably to just define device_for_each_available_child_node() and see if anyone shoots it down (even if it does the same as device_for_each_child_node() in at least some cases).

Or thinking about it.. Here you could use device_for_each_child_node()
and then call fwnode_device_is_available() on the result and continue if not true.

Quoted 8 lines
Quoted 4 lines

Will always return true (I think) but will make the intent clear.

We can tidy up to a new for_* if / when it becomes available.

Hmm, not sure I'm following you... I mean, I understand what you're saying here but there is a reason for why I changed the whole thing to use OF. Please take a look at the cover... I explain why I've done it.

Hohum. Reading the cover letter? :) Next you'll be suggesting I read manuals of new hardware! I'll take a look.

Jonathan

maintainer
#13 lore raw
In reply to Nuno Sá
Quoted 6 lines

* Have a clock property per channel. Note that we this I moved to OF
since we now have to use 'devm_get_clk_from_child()' which is using device_node. Note that I could use 'to_of_node()' but mixing of.h and property.h does not feel like a good idea.

Ah, that's unfortunate given the clk is only needed in certain modes...

Andy/Rafael/Rob, any thoughts on how we should handle this? Obviously ACPI and clocks is generally a no go, but in this particular case we aren't looking at a power management related use of clocks, but rather using the clk framework to provide a way to control one of our inputs used to generate the output dithered signal... If the device just its own clock then we'd just control it directly with no problems, but it uses and external source.

We don't know of anyone actually looking at this device in conjunction with ACPI so maybe just using dt specific calls for now rather than generic firmware properties is the best we can do.

Thanks,

Jonathan

Quoted 31 lines

ABI:
* Added out_voltageY_raw0 ABI for toggle mode;
* Added out_voltageY_dither_offset.

Bindings:
* Use standard microvolt unit;
* Added constrains for adi,output-range-microvolt and removed negative
values from the dts example;
* Moved clocks to the channel object;
* Dropped clock-names;
* Add a dependency between 'adi,toggle-dither-input' and 'clocks'.

[1]: https://marc.info/?l=linux-iio&m=163662843603265&w=2

Nuno Sá (3):
iio: dac: add support for ltc2688
iio: ABI: add ABI file for the LTC2688 DAC
dt-bindings: iio: Add ltc2688 documentation

 .../ABI/testing/sysfs-bus-iio-dac-ltc2688     |   80 ++
 .../bindings/iio/dac/adi,ltc2688.yaml         |  147 +++
 MAINTAINERS                                   |    9 +
 drivers/iio/dac/Kconfig                       |   11 +
 drivers/iio/dac/Makefile                      |    1 +
 drivers/iio/dac/ltc2688.c                     | 1070 +++++++++++++++++
 6 files changed, 1318 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
 create mode 100644 drivers/iio/dac/ltc2688.c
#14 lore raw
Quoted 18 lines · Jonathan Cameron
Quoted 7 lines

* Have a clock property per channel. Note that we this I moved to OF
since we now have to use 'devm_get_clk_from_child()' which is using device_node. Note that I could use 'to_of_node()' but mixing of.h and property.h does not feel like a good idea.

Ah, that's unfortunate given the clk is only needed in certain modes...

Andy/Rafael/Rob, any thoughts on how we should handle this? Obviously ACPI and clocks is generally a no go, but in this particular case we aren't looking at a power management related use of clocks, but rather using the clk framework to provide a way to control one of our inputs used to generate the output dithered signal... If the device just its own clock then we'd just control it directly with no problems, but it uses and external source.

Quoted 3 lines

We don't know of anyone actually looking at this device in conjunction with ACPI so maybe just using dt specific calls for now rather than generic firmware properties is the best we can do.

The problem is the CCF is so OF-centric and maintainer(s) seems skeptical about switching it to use fwnode APIs (they wanted, last time I tried, to show how exactly it will be used, so here is your chance!), but OTOH switching to fwnode API is a half made road, because for ACPI we might need a glue layer which may be way too tricky to be considered as a part of this series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko