Add support for LTC2688
Nuno Sá
maintainerv3 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'.
Changes in v3:
ltc2688:
* Fix mismatch between functions and function pointers detected by kernel
test bot;
* Always use if (ret) when ret > 0 has no meaning;
* Rename ltc2688_bulk_disable -> ltc2688_disable_regulators;
* Report dither phase in radians rather than degrees.
ABI:
* Specify units for dither_phase and dither_freqency;
* Say why its useful to have dither_en and toggle_en;
* Combine out_voltageY_raw0 and out_voltageY_raw1;
* Fix some description issues in out_voltageY_raw{0|1} andout_voltageY_symbol.
Bindings:
* Remove mentions to ABI (linux specifix);
* Slightly rephrased VREF and adi,toggle-dither-input properties and
suggested.
[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 | 86 ++ .../bindings/iio/dac/adi,ltc2688.yaml | 146 +++ MAINTAINERS | 9 + drivers/iio/dac/Kconfig | 11 + drivers/iio/dac/Makefile | 1 + drivers/iio/dac/ltc2688.c | 1070 +++++++++++++++++ 6 files changed, 1323 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.34.1
Nuno Sá
maintainerPATCH v3 3/3 dt-bindings: iio: Add ltc2688 documentation
Document the LTC2688 devicetree properties.
--- .../bindings/iio/dac/adi,ltc2688.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml new file +146 -0
@@ -0,0 +1,146 @@ +# 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. If not provided the internal reference is used and + also provided on the VREF 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. + 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 + input pins + 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
@@ -11196,6 +11196,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.34.1
Nuno Sá
maintainerPATCH v3 2/3 iio: ABI: add ABI file for the LTC2688 DAC
In reply to Nuno Sá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
The common interface present in all channels is:
* out_voltageY_raw (not present in toggle enabled channels)
* out_voltageY_raw_available
* out_voltageY_powerdown
* out_voltageY_scale
* out_voltageY_offset
* out_voltageY_calibbias
* out_voltageY_calibscale
--- .../ABI/testing/sysfs-bus-iio-dac-ltc2688 | 86 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 87 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688
Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 new file +86 -0
@@ -0,0 +1,86 @@ +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. This is useful + for changing the dither parameters. They way it should be done is: + + - disable dither operation; + - change dither parameters (eg: frequency, phase...); + - enabled dither operation + +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. Units are in Hz. + +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 are in Radians. + +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. This is + useful when one wants to change the DAC output codes. The way it should + be done is: + + - disable toggle operation; + - change out_voltageY_raw0 and out_voltageY_raw1; + - enable toggle operation. + +What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_raw0 +What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_raw1 +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 (_raw0) and INPUT_B (_raw1). The same scale and offset + as in out_voltageY_raw applies. + +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_raw0 + and out_voltageY_raw1 through software. Writing 0 will select + out_voltageY_raw0 while 1 selects out_voltageY_raw1.
MAINTAINERS +1 -0
@@ -11195,6 +11195,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.34.1
Nuno Sá
maintainerPATCH v3 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
@@ -11190,6 +11190,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
@@ -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
@@ -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.34.1
Jonathan Cameron
maintainerQuoted 83 lines · On Fri, 21 Jan 2022 15:24:58 +0100 Nuno Sá <[email protected]> wrote:
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_symboldither 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_availableDefault 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 staticext_infoarrays;
* 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 ofupdate_bitsfor 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 usingdevice_node. Note that I could use 'to_of_node()' but mixingof.handproperty.hdoes not feel like a good idea.ABI:
* Addedout_voltageY_raw0ABI for toggle mode;
* Addedout_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'.Changes in v3:
ltc2688:
* Fix mismatch between functions and function pointers detected by kernel
test bot;
* Always use if (ret) when ret > 0 has no meaning;
* Renameltc2688_bulk_disable->ltc2688_disable_regulators;
* Report dither phase in radians rather than degrees.ABI:
* Specify units fordither_phaseanddither_freqency;
* Say why its useful to havedither_enandtoggle_en;
* Combineout_voltageY_raw0andout_voltageY_raw1;
* Fix some description issues in out_voltageY_raw{0|1} andout_voltageY_symbol.
Quoted 6 lines
Bindings:
* Remove mentions to ABI (linux specifix);
* Slightly rephrased VREF and adi,toggle-dither-input properties and
suggested.
Series looks good to me, but will have to wait a little longer for DT and any other review before I apply it.
Thanks,
Jonathan
Quoted 17 lines
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 | 86 ++ .../bindings/iio/dac/adi,ltc2688.yaml | 146 +++ MAINTAINERS | 9 + drivers/iio/dac/Kconfig | 11 + drivers/iio/dac/Makefile | 1 + drivers/iio/dac/ltc2688.c | 1070 +++++++++++++++++ 6 files changed, 1323 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
kernel test robot
build bot[RFC PATCH] iio: dac: ltc2688_regmap_bus can be static
In reply to Nuno Sádrivers/iio/dac/ltc2688.c:942:19: warning: symbol 'ltc2688_regmap_bus' was not declared. Should it be static?
drivers/iio/dac/ltc2688.c:942:19: warning: symbol 'ltc2688_regmap_bus' was not declared. Should it be static?
--- ltc2688.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ltc2688.c +1 -1
@@ -939,7 +939,7 @@ static bool ltc2688_reg_writable(struct device *dev, unsigned int reg)return false; } -struct regmap_bus ltc2688_regmap_bus = { +static struct regmap_bus ltc2688_regmap_bus = { .read = ltc2688_spi_read, .write = ltc2688_spi_write, .read_flag_mask =LTC2688_READ_OPERATION ,
kernel test robot
build botRe: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Nuno SáI love your patch! Perhaps something to improve:
Hi "Nuno,
I love your patch! Perhaps something to improve:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on robh/for-next linus/master v5.17-rc1 next-20220124] [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/20220121-222705 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg config: i386-randconfig-s031-20220124 (https://download.01.org/0day-ci/archive/20220124/202201241727.j3X0hKVI-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.4-dirty # https://github.com/0day-ci/linux/commit/2493f2a925ebd05e3afc2e5632452566cfa6cbb5 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Nuno-S/Add-support-for-LTC2688/20220121-222705 git checkout 2493f2a925ebd05e3afc2e5632452566cfa6cbb5 # save the config file to linux build tree mkdir build_dir make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash drivers/iio/dac/
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> drivers/iio/dac/ltc2688.c:942:19: sparse: sparse: symbol 'ltc2688_regmap_bus' was not declared. Should it be static?
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v3 3/3] dt-bindings: iio: Add ltc2688 documentation
In reply to Nuno SáQuoted 9 lines · Nuno Sá
Document the LTC2688 devicetree properties.
Signed-off-by Nuno Sá <[email protected]>--- .../bindings/iio/dac/adi,ltc2688.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
Quoted 2 lines · Jonathan Cameron
On Fri, 21 Jan 2022 15:24:58 +0100
Nuno Sá <[email protected]> wrote:
...
Quoted 2 lines
Series looks good to me, but will have to wait a little longer for DT and any other review before I apply it.
Thanks! I have comments.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/3] iio: ABI: add ABI file for the LTC2688 DAC
In reply to Nuno SáQuoted 28 lines · Nuno Sá
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_availableToggle enabled channels will have:
*
out_voltageY_toggle_en
*out_voltageY_raw0
*out_voltageY_raw1
*out_voltageY_symbolThe common interface present in all channels is:
*
out_voltageY_raw(not present in toggle enabled channels)
*out_voltageY_raw_available
*out_voltageY_powerdown
*out_voltageY_scale
*out_voltageY_offset
*out_voltageY_calibbias
*out_voltageY_calibscale
...
Quoted 1 line
+KernelVersion: 5.17
v5.17 alredy gone for new features.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Nuno SáQuoted 3 lines · 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.
...
Quoted 1 line
+#include <
linux/of.h>
property.h please/
...
Quoted 19 lines
drivers/iio/dac/ltc2688.c new file +18
-0+static int ltc2688_spi_read (void *context,const void *reg,size_t reg_size, +void *val,size_t val_size) +{ +struct ltc2688_state *st = context; +struct spi_transfer xfers[] = { + { + .tx_buf = st->tx_data, + .bits_per_word =8 , + .len =3 , + .cs_change =1 , + }, { + .tx_buf = st->tx_data +3 , + .rx_buf = st->rx_data, + .bits_per_word =8 , + .len =3 , + }, + }; +int ret;
drivers/iio/dac/ltc2688.c line 128
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+memcpy (st->tx_data, reg, reg_size); + + ret =spi_sync_transfer (st->spi, xfers,ARRAY_SIZE (xfers)); +if (ret) +return ret; + +memcpy (val, &st->rx_data[1 ], val_size); + +return 0 ; +}
First of all, yuo have fixed len in transfer sizes, so what the purpose of the reg_size / val_size? Second, why do you need this specific function instead of regmap bulk ops against be24/le24?
...
Quoted 1 line
+unlock:
out_unlock: ?
(And in similar cases)
...
drivers/iio/dac/ltc2688.c line 411
Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4
-0+if (ret) +return ret; + +return len;
In some cases the return ret ?: len; is used, in some like above. Maybe a bit of consistency?
...
drivers/iio/dac/ltc2688.c line 502
Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4
-0+if (private ==LTC2688_INPUT_B_AVAIL ) +return sysfs_emit (buf,"[%u %u %u]\n" , ltc2688_raw_range[0 ], + ltc2688_raw_range[1 ], + ltc2688_raw_range[2 ] /4 );
Is it standard form "[A B C]" for ranges in IIO? I haven't looked into the code deeply (and datasheet at all) to understand meaning. To me range is usually out of two numbers.
drivers/iio/dac/ltc2688.c line 511
Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +7
-0+if (private ==LTC2688_DITHER_OFF ) +return sysfs_emit (buf,"0\n" ); + ret =ltc2688_dac_code_read (st, chan->channel, private, &val); +if (ret) +return ret; + +return sysfs_emit (buf,"%u\n" , val);
These three types of output for one sysfs node? Seems it's not align with the idea behind sysfs. It maybe that I missed something.
...
drivers/iio/dac/ltc2688.c line 526
Quoted 1 line
drivers/iio/dac/ltc2688.c new file +1
-0+ ret =kstrtou16 (buf,10 , &val);
In other function you have long, here u16. I would expect that the types are of the same class, e.g. if here you have u16, then there something like s32 / s64. Or here something like unsigned short.
A bit of elaboration why u16 is chosen here?
...
drivers/iio/dac/ltc2688.c line 670
Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2
-0+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW), \ + .ext_info = ltc2688_ext_info \
+ Comma
...
drivers/iio/dac/ltc2688.c line 710
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+static int ltc2688_tgp_clk_setup (struct ltc2688_state *st, +struct ltc2688_chan *chan, +struct device_node *np,int tgp) +{ +unsigned long rate; +struct clk *clk; +int ret, f; + + clk =devm_get_clk_from_child (&st->spi->dev, np,NULL ); +if (IS_ERR (clk))
Make it optional for non-OF, can be done as easy as
if (IS_ERR(clk)) {
if (PTR_ERR(clk) == -ENOENT)
clk = NULL;
else
return dev_err_probe(...);
}Quoted 22 lines
drivers/iio/dac/ltc2688.c new file +22
-0+return dev_err_probe (&st->spi->dev,PTR_ERR (clk), +"failed to get tgp clk.\n" ); + + ret =clk_prepare_enable (clk); +if (ret) +return dev_err_probe (&st->spi->dev, ret, +"failed to enable tgp clk.\n" ); + + ret =devm_add_action_or_reset (&st->spi->dev, ltc2688_clk_disable, clk); +if (ret) +return ret; + +if (chan->toggle_chan) +return 0 ; + +/* calculate available dither frequencies */ + rate =clk_get_rate (clk); +for (f =0 ; f <ARRAY_SIZE (chan->dither_frequency); f++) + chan->dither_frequency[f] =DIV_ROUND_CLOSEST (rate, ltc2688_period[f]); + +return 0 ; +}
...
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) {
device_for_each_child_node()
Quoted 19 lines
drivers/iio/dac/ltc2688.c new file +19
-0+struct ltc2688_chan *chan; + + ret =of_property_read_u32 (child,"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" )) {
drivers/iio/dac/ltc2688.c line 782
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +9
-0+ 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);
Do you need atomic operation here?
Quoted 74 lines
drivers/iio/dac/ltc2688.c new file +74
-0+ } + + 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 ; +}
...
drivers/iio/dac/ltc2688.c line 947
Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6
-0+struct regmap_bus ltc2688_regmap_bus = { + .read = ltc2688_spi_read, + .write = ltc2688_spi_write, + .read_flag_mask =LTC2688_READ_OPERATION , + .reg_format_endian_default =REGMAP_ENDIAN_BIG , + .val_format_endian_default =REGMAP_ENDIAN_BIG
+ Comma.
drivers/iio/dac/ltc2688.c line 956
Quoted 9 lines
drivers/iio/dac/ltc2688.c new file +9
-0+}; + +static const struct regmap_config ltc2688_regmap_config = { + .reg_bits =8 , + .val_bits =16 , + .readable_reg = ltc2688_reg_readable, + .writeable_reg = ltc2688_reg_writable, +/* ignoring the no op command */ + .max_register =LTC2688_CMD_UPDATE_ALL
Ditto.
Quoted 1 line
+};
...
drivers/iio/dac/ltc2688.c line 1007
Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +2
-0+ vref_reg =devm_regulator_get_optional (dev,"vref" ); +if (!IS_ERR (vref_reg)) {
Why not positive conditional check (and hence standard pattern -- error handling first)?
Quoted 24 lines
drivers/iio/dac/ltc2688.c new file +24
-0+ ret =regulator_enable (vref_reg); +if (ret) +return dev_err_probe (dev, ret, +"Failed to enable vref regulators\n" ); + + ret =devm_add_action_or_reset (dev, ltc2688_disable_regulator, + vref_reg); +if (ret) +return ret; + + ret =regulator_get_voltage (vref_reg); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to get vref\n" ); + + st->vref = ret /1000 ; + }else { +if (PTR_ERR (vref_reg) != -ENODEV ) +return dev_err_probe (dev,PTR_ERR (vref_reg), +"Failed to get vref regulator" ); + + vref_reg =NULL ; +/* internal reference */ + st->vref =4096 ; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v3 1/3] iio: dac: add support for ltc2688
On Sat, 5 Feb 2022 19:29:39 +0200
Andy Shevchenko <[email protected]> wrote:
A few comments from me, mostly because I couldn't resist jumping in ;) Note this is only some of the things Andy raised....
Jonathan
Quoted 9 lines
drivers/iio/dac/ltc2688.c line 502
Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +4
-0+if (private ==LTC2688_INPUT_B_AVAIL ) +return sysfs_emit (buf,"[%u %u %u]\n" , ltc2688_raw_range[0 ], + ltc2688_raw_range[1 ], + ltc2688_raw_range[2 ] /4 );Is it standard form "[A B C]" for ranges in IIO? I haven't looked into the code deeply (and datasheet at all) to understand meaning. To me range is usually out of two numbers.
https://elixir.bootlin.com/linux/latest/source/Documentation/ABI/testing/sysfs-bus-iio#L105
Yes, [Min Step Max]
Quoted 4 lines
Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +2
-0+if (private ==LTC2688_DITHER_OFF ) +return sysfs_emit (buf,"0\n" );
Quoted 8 lines
drivers/iio/dac/ltc2688.c line 511
Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5
-0+ ret =ltc2688_dac_code_read (st, chan->channel, private, &val); +if (ret) +return ret; + +return sysfs_emit (buf,"%u\n" , val);These three types of output for one sysfs node? Seems it's not align with the idea behind sysfs. It maybe that I missed something.
Different sysfs nodes. Though it's a fair question on whether this would be better done as a bunch of separate callbacks, rather than one with a lookup on the private parameter.
Quoted 14 lines
drivers/iio/dac/ltc2688.c line 710
Quoted 11 lines
drivers/iio/dac/ltc2688.c new file +10
-0+static int ltc2688_tgp_clk_setup (struct ltc2688_state *st, +struct ltc2688_chan *chan, +struct device_node *np,int tgp) +{ +unsigned long rate; +struct clk *clk; +int ret, f; + + clk =devm_get_clk_from_child (&st->spi->dev, np,NULL ); +if (IS_ERR (clk))Make it optional for non-OF, can be done as easy as
Quoted 6 lines
if (IS_ERR(clk)) {
if (PTR_ERR(clk) == -ENOENT)
clk = NULL;
else
return dev_err_probe(...);
}Interesting. We should probably look at where else this is appropriate.
Quoted 26 lines
Quoted 23 lines
drivers/iio/dac/ltc2688.c new file +22
-0+return dev_err_probe (&st->spi->dev,PTR_ERR (clk), +"failed to get tgp clk.\n" ); + + ret =clk_prepare_enable (clk); +if (ret) +return dev_err_probe (&st->spi->dev, ret, +"failed to enable tgp clk.\n" ); + + ret =devm_add_action_or_reset (&st->spi->dev, ltc2688_clk_disable, clk); +if (ret) +return ret; + +if (chan->toggle_chan) +return 0 ; + +/* calculate available dither frequencies */ + rate =clk_get_rate (clk); +for (f =0 ; f <ARRAY_SIZE (chan->dither_frequency); f++) + chan->dither_frequency[f] =DIV_ROUND_CLOSEST (rate, ltc2688_period[f]); + +return 0 ; +}...
Quoted 10 lines
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) {
device_for_each_child_node()
This is the old issue with missing device_for_each_available_child_node()
though can just add a check on whether it's available inside the loop.
Quoted 3 lines
Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +2
-0+struct ltc2688_chan *chan; +
...
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 5 lines · Jonathan Cameron
On Sat, 5 Feb 2022 19:29:39 +0200
Andy Shevchenko <[email protected]> wrote:A few comments from me, mostly because I couldn't resist jumping in ;) Note this is only some of the things Andy raised....
...
Quoted 11 lines
Quoted 10 lines
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) {
device_for_each_child_node()
Quoted 3 lines
This is the old issue with missing
device_for_each_available_child_node()
though can just add a check on whether it's available inside the loop.
Didn't we discuss this with Rob and he told that device_for_each_child_node() is already for available only?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2
-0+struct ltc2688_chan *chan; +
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 20 lines · Andy Shevchenko
Quoted 5 lines · Jonathan Cameron
On Sat, 5 Feb 2022 19:29:39 +0200
Andy Shevchenko <[email protected]> wrote:A few comments from me, mostly because I couldn't resist jumping in ;) Note this is only some of the things Andy raised....
...
Quoted 11 lines
Quoted 10 lines
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) {
device_for_each_child_node()
Quoted 6 lines
Quoted 3 lines
This is the old issue with missing
device_for_each_available_child_node()
though can just add a check on whether it's available inside the loop.Didn't we discuss this with Rob and he told that
device_for_each_child_node()is already for available only?
https://lore.kernel.org/lkml/20211205190101.26de4a57@jic23-huawei/T/#u
So, the fwnode has a correct implementation, and we may use it here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerRE: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Andy ShevchenkoQuoted 17 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]; [email protected]; Rob Herring <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v3 1/3] iio: dac: add support for ltc2688[External]
Quoted 3 lines · 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.
Quoted 5 lines
...
Quoted 1 line
+#include <
linux/of.h>
property.hplease/
That probably means property and of both included. See below in the clock_get comments...
Quoted 22 lines
...
Quoted 1 line
+static int ltc2688_spi_read(void *context, const void *reg,
size_t
reg_size,Quoted 17 lines
drivers/iio/dac/ltc2688.c new file +17
-0+ void *val, size_t val_size) +{ +struct ltc2688_state *st = context; +struct spi_transfer xfers[] = { + { + .tx_buf = st->tx_data, + .bits_per_word =8 , + .len =3 , + .cs_change =1 , + }, { + .tx_buf = st->tx_data +3 , + .rx_buf = st->rx_data, + .bits_per_word =8 , + .len =3 , + }, + }; +int ret;
Quoted 13 lines
drivers/iio/dac/ltc2688.c line 128
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+memcpy (st->tx_data, reg, reg_size); + + ret =spi_sync_transfer (st->spi, xfers,ARRAY_SIZE (xfers)); +if (ret) +return ret; + +memcpy (val, &st->rx_data[1 ], val_size); + +return 0 ; +}First of all, yuo have fixed len in transfer sizes, so what the purpose of the
reg_size/val_size?
Well, reg_size is 1 byte and val_size is 2 as defined in the regmap_bus struct. And that is what it must be used for the transfer to work. I could also hardcode 1 and 2 but I preferred to use the parameters. I guess you can argue (and probably this is why you are complaining about this) for me to use reg_size + val_size in the transfer length for consistency. That's fair but I do not think this is __that__ bad... Can make that change though.
Quoted 3 lines
Second, why do you need this specific function instead of regmap bulk ops against be24/le24?
Not sure I'm following this one... If you mean why am I using a custom regmap_bus implementation, that was already explained in the RFC patch. And IIRC, you were the one already asking 😉.
Quoted 6 lines
...
Quoted 1 line
+unlock:
out_unlock: ?
(And in similar cases)
Well, why not? can do that...
Quoted 10 lines
...
drivers/iio/dac/ltc2688.c line 411
Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4
-0+if (ret) +return ret; + +return len;In some cases the return ret ?: len; is used, in some like above. Maybe a bit
of consistency?
That's fair... At this point, I will go with the one that evolves less changes unless noted otherwise.
Quoted 37 lines
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (private == LTC2688_INPUT_B_AVAIL) + return sysfs_emit(buf, "[%u %u %u]\n",ltc2688_raw_range[0],
drivers/iio/dac/ltc2688.c line 502
Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2
-0+ ltc2688_raw_range[1 ], + ltc2688_raw_range[2] / 4);Is it standard form "[A B C]" for ranges in IIO? I haven't looked into the code
deeply (and datasheet at all) to understand meaning. To me range is usually out
of two numbers.drivers/iio/dac/ltc2688.c line 511
Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +7
-0+if (private ==LTC2688_DITHER_OFF ) +return sysfs_emit (buf,"0\n" ); + ret =ltc2688_dac_code_read (st, chan->channel, private, &val); +if (ret) +return ret; + +return sysfs_emit (buf,"%u\n" , val);These three types of output for one sysfs node? Seems it's not align with the
idea behind sysfs. It maybe that I missed something....
drivers/iio/dac/ltc2688.c line 526
Quoted 1 line
drivers/iio/dac/ltc2688.c new file +1
-0+ ret =kstrtou16 (buf,10 , &val);In other function you have long, here u16. I would expect that the types are of
the same class, e.g. if here you have u16, then there something like s32 / s64.
Or here something like unsigned short.
Quoted 1 line
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather than using stdint types...). So I pretty much just use these in unsigned types because I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan really asks for it, I prefer not to go all over the driver and change this...
Quoted 30 lines
...
Review
Quoted 1 line
(quoted diff) +1
-0+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW),\drivers/iio/dac/ltc2688.c line 670
Quoted 1 line
drivers/iio/dac/ltc2688.c new file +1
-0+ .ext_info = ltc2688_ext_info \+ Comma
...
drivers/iio/dac/ltc2688.c line 710
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+static int ltc2688_tgp_clk_setup (struct ltc2688_state *st, +struct ltc2688_chan *chan, +struct device_node *np,int tgp) +{ +unsigned long rate; +struct clk *clk; +int ret, f; + + clk =devm_get_clk_from_child (&st->spi->dev, np,NULL ); +if (IS_ERR (clk))Make it optional for non-OF, can be done as easy as
if (IS_ERR(clk)) { if (PTR_ERR(clk) == -ENOENT) clk = NULL; else return dev_err_probe(...); }
Quoted 2 lines
drivers/iio/dac/ltc2688.c line 712
Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2
-0+return dev_err_probe (&st->spi->dev,PTR_ERR (clk), +"failed to get tgp clk.\n" );
Well, I might be missing the point but I think this is not so straight.... We will only get here if the property " adi,toggle-dither-input" is given in which case having the associated clocks is __mandatory__. Hence, once we are here, this can never be optional. That said, we need device_node and hence of.h to be included and this was the main reason why I changed from property.h to of.h (once I started to use 'devm_get_clk_from_child()'. I don’t really think that using both of and property is a good idea and I raised this in the previous version of this series and no one made it clear that using both of and property would be acceptable so I kept my move to of in the current version.
Quoted 62 lines
drivers/iio/dac/ltc2688.c
Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6
-0+ ret =clk_prepare_enable (clk); +if (ret) +return dev_err_probe (&st->spi->dev, ret, +"failed to enable tgp clk.\n" ); + + ret = devm_add_action_or_reset(&st->spi->dev,
ltc2688_clk_disable, clk);drivers/iio/dac/ltc2688.c
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+if (ret) +return ret; + +if (chan->toggle_chan) +return 0 ; + +/* calculate available dither frequencies */ + rate =clk_get_rate (clk); +for (f =0 ; f <ARRAY_SIZE (chan->dither_frequency); f++) + chan->dither_frequency[f] =
DIV_ROUND_CLOSEST(rate, ltc2688_period[f]);Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3
-0+ +return 0 ; +}...
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) {
device_for_each_child_node()drivers/iio/dac/ltc2688.c
Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7
-0+struct ltc2688_chan *chan; + + ret =of_property_read_u32 (child,"reg" , ®); +if (ret) { +of_node_put (child); + return dev_err_probe(dev, ret, + "Failed to get regproperty\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 togglechannels expose
Quoted 8 lines
Quoted 6 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);
Do you need atomic operation here?
Not really, but I still prefer to use 'clear_bit()' rather than doing it by hand... Is there another utility for this?
Quoted 121 lines
drivers/iio/dac/ltc2688.c
Quoted 3 lines
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 notvalid:[%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-inputinv 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 alreadyenabled).
Review
Quoted 1 line
(quoted diff) +1
-0+ * On top of this we just set here the dither bitin the
Review
Quoted 1 line
(quoted diff) +1
-0+ * channel settings. It won't have any effectuntil 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 chansettings\n");
Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5
-0+ } + } + +return 0 ; +}...
drivers/iio/dac/ltc2688.c line 947
Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6
-0+struct regmap_bus ltc2688_regmap_bus = { + .read = ltc2688_spi_read, + .write = ltc2688_spi_write, + .read_flag_mask =LTC2688_READ_OPERATION , + .reg_format_endian_default =REGMAP_ENDIAN_BIG , + .val_format_endian_default =REGMAP_ENDIAN_BIG + Comma.
drivers/iio/dac/ltc2688.c line 956
Quoted 9 lines
drivers/iio/dac/ltc2688.c new file +9
-0+}; + +static const struct regmap_config ltc2688_regmap_config = { + .reg_bits =8 , + .val_bits =16 , + .readable_reg = ltc2688_reg_readable, + .writeable_reg = ltc2688_reg_writable, +/* ignoring the no op command */ + .max_register =LTC2688_CMD_UPDATE_ALL Ditto.
Quoted 1 line
+};
...
Quoted 8 lines
drivers/iio/dac/ltc2688.c line 1007
Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +2
-0+ vref_reg =devm_regulator_get_optional (dev,"vref" ); +if (!IS_ERR (vref_reg)) {Why not positive conditional check (and hence standard pattern -- error
handling first)?
No reason.. I can flip the logic...
- Nuno Sá
Jonathan Cameron
maintainerRe: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Andy ShevchenkoQuoted 25 lines · On Sat, 5 Feb 2022 20:58:12 +0200 Andy Shevchenko…
Quoted 24 lines · Andy Shevchenko
Quoted 5 lines · Jonathan Cameron
On Sat, 5 Feb 2022 19:29:39 +0200
Andy Shevchenko <[email protected]> wrote:A few comments from me, mostly because I couldn't resist jumping in ;) Note this is only some of the things Andy raised....
...
Quoted 14 lines
Quoted 10 lines
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) {
device_for_each_child_node()This is the old issue with missing
device_for_each_available_child_node()
though can just add a check on whether it's available inside the loop.
Quoted 7 lines
Quoted 2 lines
Didn't we discuss this with Rob and he told that
device_for_each_child_node()is already for available only?https://lore.kernel.org/lkml/20211205190101.26de4a57@jic23-huawei/T/#u
So, the fwnode has a correct implementation, and we may use it here.
I wasn't totally sure of the conclusion of that discussion.
a) Fine to just use device_for_each_child_node() for this case and not worry about it.
b) Worth adding device_for_each_available_child_node() with the same implementation
c) (possibly workaround / avoid the issue) Use device_for_each_child_node() but also check validity (hopefully compiler would remove the check) in order to act as documentation.
I'm fine with any of the above.
J
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 3 lines · Jonathan Cameron
Quoted 1 line · On Sat, 5 Feb 2022 20:58:12 +0200 Andy Shevchenko…
On Sat, Feb 05, 2022 at 08:50:31PM +0200, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 4 lines
https://lore.kernel.org/lkml/20211205190101.26de4a57@jic23-huawei/T/#u
So, the fwnode has a correct implementation, and we may use it here.
I wasn't totally sure of the conclusion of that discussion.
a) Fine to just usedevice_for_each_child_node()for this case and not worry about it.
Yes. As he mentioned the device_for_each_child_node() is implemented correctly from day 1.
Quoted 2 lines
b) Worth adding
device_for_each_available_child_node()with the same implementation
I believe it's an opposite prospective, i.e. drop of_for_each_available_child_node() and use the of_for_each_child_node() everywhere.
Quoted 3 lines
c) (possibly workaround / avoid the issue) Use
device_for_each_child_node()but also check validity (hopefully compiler would remove the check) in order to act as documentation.
Makes no sense because implementation does it already.
Quoted 1 line
I'm fine with any of the above.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Sa, NunoQuoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:
...
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+#include <
linux/of.h>
property.hplease/That probably means property and of both included. See below in the
clock_getcomments...
Why? OF won't be used at all.
...
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5
-0+memcpy (st->tx_data, reg, reg_size); + + ret =spi_sync_transfer (st->spi, xfers,ARRAY_SIZE (xfers)); +if (ret) +return ret;Quoted 8 lines
drivers/iio/dac/ltc2688.c line 128
Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5
-0+ +memcpy (val, &st->rx_data[1 ], val_size); + +return 0 ; +}First of all, yuo have fixed len in transfer sizes, so what the purpose of the
reg_size/val_size?
Quoted 6 lines
Well,
reg_sizeis 1 byte andval_sizeis 2 as defined in theregmap_busstruct. And that is what it must be used for the transfer to work. I could also hardcode 1 and 2 but I preferred to use the parameters. I guess you can argue (and probably this is why you are complaining about this) for me to usereg_size+val_sizein the transfer length for consistency. That's fair but I do not think this is__that__bad...
It's not bad, but I think that division between register and value is a good thing to have.
Quoted 1 line
Can make that change though.
Would be nice!
...
Quoted 6 lines
Quoted 2 lines
Second, why do you need this specific function instead of regmap bulk ops against be24/le24?
Not sure I'm following this one... If you mean why am I using a custom
regmap_busimplementation, that was already explained in the RFC patch. And IIRC, you were the one already asking 😉.
Hmm... It was some time I have looked there. Any message ID to share, so I can find it quickly?
...
Quoted 8 lines
Quoted 8 lines
drivers/iio/dac/ltc2688.c line 526
Quoted 1 line
drivers/iio/dac/ltc2688.c new file +1
-0+ ret =kstrtou16 (buf,10 , &val);In other function you have long, here u16. I would expect that the types are of
the same class, e.g. if here you have u16, then there something like s32 / s64.
Or here something like unsigned short.
Quoted 6 lines
Quoted 1 line
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather than using stdint types...). So I pretty much just use these in unsigned types because I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan really asks for it, I prefer not to go all over the driver and change this...
This is about consistency. It may work as is, but it feels not good when for int (or unsigned int) one uses fixed-width types. Also it's non-written advice to use fixed-width variables when it's about programming registers or so, for the rest, use POD types.
...
Quoted 20 lines
Quoted 20 lines
drivers/iio/dac/ltc2688.c line 710
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+static int ltc2688_tgp_clk_setup (struct ltc2688_state *st, +struct ltc2688_chan *chan, +struct device_node *np,int tgp) +{ +unsigned long rate; +struct clk *clk; +int ret, f; + + clk =devm_get_clk_from_child (&st->spi->dev, np,NULL ); +if (IS_ERR (clk))Make it optional for non-OF, can be done as easy as
if (IS_ERR(clk)) { if (PTR_ERR(clk) == -ENOENT) clk = NULL; else return dev_err_probe(...); }
Quoted 6 lines
Quoted 2 lines
drivers/iio/dac/ltc2688.c line 712
Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2
-0+return dev_err_probe (&st->spi->dev,PTR_ERR (clk), +"failed to get tgp clk.\n" );Well, I might be missing the point but I think this is not so straight.... We will only get here if the property " adi,toggle-dither-input" is given in which case having the associated clocks is
__mandatory__.
Ah, okay, would be a limitation for non-OF platforms.
Quoted 3 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_node
That's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.h
Why? This header doesn't bring anything you will use here.
Quoted 6 lines
to be included and this was the main reason
why I changed fromproperty.htoof.h(once I started to use 'devm_get_clk_from_child()'. I don’t really think that using both of and property is a good idea and I raised this in the previous version of this series and no one made it clear that using both of and property would be acceptable so I kept my move to of in the current version.
It's a good idea for sensors to be able to use them outside of OF platforms. CCF is PITA, but at least with the conversion to device property API, this become the only one (and it has a few possible workarounds).
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4
-0+ ret =clk_prepare_enable (clk); +if (ret) +return dev_err_probe (&st->spi->dev, ret, +"failed to enable tgp clk.\n" );
...
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
(quoted diff) +2
-0+ clear_bit(IIO_CHAN_INFO_RAW, + &st-iio_chan[reg].info_mask_separate);
Do you need atomic operation here?
Not really, but I still prefer to use '
clear_bit()' rather than doing it by hand... Is there another utility for this?
__clear_bit().
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+#include <
linux/of.h>
property.hplease/That probably means property and of both included. See below in the
clock_getcomments...Why? OF won't be used at all.
see below on the clock function...
Quoted 51 lines
...
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
+ memcpy(st->tx_data, reg,
reg_size);
+
+ ret = spi_sync_transfer(st->spi, xfers,ARRAY_SIZE(xfers));
+ if (ret)
+ return ret;
+Quoted 8 lines
drivers/iio/dac/ltc2688.c line 128
Quoted 4 lines
+ memcpy(val, &st->rx_data[1],
val_size);drivers/iio/dac/ltc2688.c new file +3
-0+ + return 0; +}First of all, yuo have fixed len in transfer sizes, so what the purpose of
thereg_size/val_size?Quoted 11 lines
Well,
reg_sizeis 1 byte andval_sizeis 2 as defined in theregmap_bus
struct. And that is what it must be used for the transfer to work. I
could also hardcode 1 and 2 but I preferred to use the parameters. I guess
you can argue (and probably this is why you are complaining about this)
for me to usereg_size+val_sizein the transfer length for consistency.
That's fair but I do not think this is__that__bad...It's not bad, but I think that division between register and value is a good
thing to have.Quoted 1 line
Can make that change though.
Would be nice!
...
Quoted 9 lines
Quoted 3 lines
Second, why do you need this specific function instead of regmap bulk
ops against be24/le24?Not sure I'm following this one... If you mean why am I using a custom
regmap_busimplementation, that was already explained in the RFC patch.
And IIRC, you were the one already asking 😉.
Quoted 4 lines
Hmm... It was some time I have looked there. Any message ID to share, so
I can find it quickly?
https://lore.kernel.org/all/20211112152235.12fdcc49@jic23-huawei/
Quoted 31 lines
...
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the
types are of
the same class, e.g. if here you have u16, then there something like
s32 / s64.
Or here something like unsigned short.A bit of elaboration why u16 is chosen here?
Quoted 8 lines
Well, I never really saw any enforcement here to be honest (rather than using
stdint types...). So I pretty much just use these in unsigned types because
I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan
really asks for it, I prefer not to go all over the driver and change this...This is about consistency. It may work as is, but it feels not good when for
int (or unsigned int) one uses fixed-width types. Also it's non- written advice
to use fixed-width variables when it's about programming registers or so, for
the rest, use POD types.
Quoted 1 line
...
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it if it really becomes something that we will try to "enforce" in IIO. Otherwise it just feels as a random nitpick :).
Quoted 39 lines
Quoted 27 lines
Quoted 15 lines
drivers/iio/dac/ltc2688.c line 710
Quoted 12 lines
+static int ltc2688_tgp_clk_setup(struct
ltc2688_state*st, + structltc2688_chan*chan, + structdevice_node*np, int tgp)drivers/iio/dac/ltc2688.c new file +7
-0+{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev, np, NULL); + if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
Quoted 11 lines
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 4 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk),
+ "failed to get tgp clk.\n");Quoted 5 lines
Well, I might be missing the point but I think this is not so straight....
We will only get here if the property " adi,toggle-dither-input" is given
in which case having the associated clocks is__mandatory__.Ah, okay, would be a limitation for non-OF platforms.
Quoted 3 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_node
Quoted 5 lines
That's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.hWhy? This header doesn't bring anything you will use here.
Correct me if Im missing something. AFAIU, the idea is to use 'device_for_each_child_node()' which returns a fwnode_handle. That means, that we will have to pass that to this function and use 'to_of_node()' to pass a device_node to 'devm_get_clk_from_child()'.
This means, we need of.h for 'to_of_node()'...
- Nuno Sá
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 168 lines · Nuno Sá
Quoted 9 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+#include <
linux/of.h>Quoted 8 lines
Quoted 5 lines
Quoted 1 line
property.hplease/That probably means property and of both included. See below in the
clock_getcomments...Why? OF won't be used at all.
see below on the clock function...
Quoted 55 lines
...
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
+ memcpy(st->tx_data, reg,
reg_size);
+
+ ret = spi_sync_transfer(st->spi, xfers,ARRAY_SIZE(xfers));
+ if (ret)
+ return ret;
+Quoted 8 lines
drivers/iio/dac/ltc2688.c line 128
Quoted 4 lines
+ memcpy(val, &st->rx_data[1],
val_size);drivers/iio/dac/ltc2688.c new file +3
-0+ + return 0; +}First of all, yuo have fixed len in transfer sizes, so what the purpose of
thereg_size/val_size?Quoted 13 lines
Well,
reg_sizeis 1 byte andval_sizeis 2 as defined in theregmap_bus
struct. And that is what it must be used for the transfer to work.
I
could also hardcode 1 and 2 but I preferred to use the parameters.
I guess
you can argue (and probably this is why you are complaining about this)
for me to usereg_size+val_sizein the transfer length for consistency.
That's fair but I do not think this is__that__bad...It's not bad, but I think that division between register and value is
a good
thing to have.Quoted 1 line
Can make that change though.
Would be nice!
...
Quoted 10 lines
Quoted 4 lines
Second, why do you need this specific function instead of regmap
bulk
ops against be24/le24?Not sure I'm following this one... If you mean why am I using a custom
regmap_busimplementation, that was already explained in the RFC patch.
And IIRC, you were the one already asking 😉.Quoted 5 lines
Hmm... It was some time I have looked there. Any message ID to share,
so
I can find it quickly?https://lore.kernel.org/all/20211112152235.12fdcc49@jic23-huawei/
Quoted 34 lines
...
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the
types are of
the same class, e.g. if here you have u16, then there something like
s32 / s64.
Or here something like unsigned short.A bit of elaboration why u16 is chosen here?
Quoted 10 lines
Well, I never really saw any enforcement here to be honest (rather
than using
stdint types...). So I pretty much just use these in unsigned types
because
I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan
really asks for it, I prefer not to go all over the driver and change this...This is about consistency. It may work as is, but it feels not good when for
int (or unsigned int) one uses fixed-width types. Also it's non- written advice
to use fixed-width variables when it's about programming registers or
so, for
the rest, use POD types.Quoted 1 line
...
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it if it really becomes something that we will try to "enforce" in IIO. Otherwise it just feels as a random nitpick :).
Quoted 45 lines
Quoted 28 lines
Quoted 16 lines
Quoted 11 lines
+static int ltc2688_tgp_clk_setup(struct
ltc2688_state*st, + structltc2688_chan*chan, + structdevice_node*np, int tgp)drivers/iio/dac/ltc2688.c new file +6
-0+{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev, np,Quoted 2 lines
NULL);
+ if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
Quoted 11 lines
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 4 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk),
+ "failed to get tgp clk.\n");Quoted 6 lines
Well, I might be missing the point but I think this is not so straight....
We will only get here if the property " adi,toggle-dither-input" is
given
in which case having the associated clocks is__mandatory__.Ah, okay, would be a limitation for non-OF platforms.
Quoted 3 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_nodeThat's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.h
Quoted 10 lines
Quoted 1 line
Why? This header doesn't bring anything you will use here.
Correct me if Im missing something. AFAIU, the idea is to use '
device_for_each_child_node()' which returns afwnode_handle. That means, that we will have to pass that to this function and use 'to_of_node()' to pass adevice_nodeto 'devm_get_clk_from_child()'.This means, we need
of.hfor 'to_of_node()'...
Andy, Jonathan,
I would definetly like to have some settlement on the above (before sending a v4). It kind of was discussed a bit already in [1] where I felt we had to live with OF for this driver (that is why I kept OF in v3. With the above, I cannot
really see how we can have device API with also including OF... If I missing something please let me know :)
[1]: https://lore.kernel.org/all/CAHp75VczFs8QpsY7tuB-h4X=H54nyjABA4qDSmpQ+FRYAHZdrA@mail.gmail.com/
- Nuno Sá
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Nuno SáQuoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:
...
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
Second, why do you need this specific function instead of regmap bulk
ops against be24/le24?Not sure I'm following this one... If you mean why am I using a custom
regmap_busimplementation, that was already explained in the RFC patch.
And IIRC, you were the one already asking 😉.
Quoted 5 lines
Quoted 3 lines
Hmm... It was some time I have looked there. Any message ID to share, so
I can find it quickly?https://lore.kernel.org/all/20211112152235.12fdcc49@jic23-huawei/
Thanks!
So, it's all about cs_change, right?
But doesn't bulk operation work exactly as we need here?
Looking again to the RFC code, it seems like we can still do it
First, you call _gather_write() followed by _read(). It will show exactly what you do, i.e. you send command first with the value 0x0000, followed by sending command and reading back the value at the same time.
Would it work?
...
Quoted 29 lines
Quoted 21 lines
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the
types are of
the same class, e.g. if here you have u16, then there something like
s32 / s64.
Or here something like unsigned short.A bit of elaboration why u16 is chosen here?
Quoted 8 lines
Well, I never really saw any enforcement here to be honest (rather than using
stdint types...). So I pretty much just use these in unsigned types because
I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan
really asks for it, I prefer not to go all over the driver and change this...Quoted 7 lines
This is about consistency. It may work as is, but it feels not good when for
int (or unsigned int) one uses fixed-width types. Also it's non- written advice
to use fixed-width variables when it's about programming registers or so, for
the rest, use POD types.
Quoted 4 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it if it really becomes something that we will try to "enforce" in IIO. Otherwise it just feels as a random nitpick :).
No, this is about consistency and common sense. If you define type uXX, we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.
Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.
...
Quoted 42 lines
Quoted 42 lines
Quoted 26 lines
Quoted 14 lines
drivers/iio/dac/ltc2688.c line 710
Quoted 11 lines
+static int ltc2688_tgp_clk_setup(struct
ltc2688_state*st, + structltc2688_chan*chan, + structdevice_node*np, int tgp)drivers/iio/dac/ltc2688.c new file +7
-0+{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev, np, NULL); + if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
Quoted 11 lines
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 4 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk),
+ "failed to get tgp clk.\n");Quoted 5 lines
Well, I might be missing the point but I think this is not so straight....
We will only get here if the property " adi,toggle-dither-input" is given
in which case having the associated clocks is__mandatory__.Ah, okay, would be a limitation for non-OF platforms.
Quoted 3 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_nodeThat's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.h
Quoted 8 lines
Quoted 1 line
Why? This header doesn't bring anything you will use here.
Correct me if Im missing something. AFAIU, the idea is to use '
device_for_each_child_node()' which returns afwnode_handle. That means, that we will have to pass that to this function and use 'to_of_node()' to pass adevice_nodeto 'devm_get_clk_from_child()'.This means, we need
of.hfor 'to_of_node()'...
Yeah, you are right, but it would be still better since it narrows the problem to the CCF calls only.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Nuno SáQuoted 8 lines · Nuno Sá
On Mon, 2022-02-07 at 21:19 +0100, Nuno Sá wrote:
I would definetly like to have some settlement on the above (before sending a v4). It kind of was discussed a bit already in [1] where I felt we had to live with OF for this driver (that is why I kept OF in v3. With the above, I cannot
really see how we can have device API with also including OF... If I missing something please let me know :)
Sorry for the delay, answered to your previous message.
Quoted 1 line
[1]: https://lore.kernel.org/all/CAHp75VczFs8QpsY7tuB-h4X=H54nyjABA4qDSmpQ+FRYAHZdrA@mail.gmail.com/
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Nuno Sá
On Mon, 2022-02-07 at 21:19 +0100, Nuno Sá wrote:
I would definetly like to have some settlement on the above (before sending a v4). It kind of was discussed a bit already in [1] where I
felt we had to live with OF for this driver (that is why I kept OF in
v3. With the above, I cannot
really see how we can have device API with also including OF... If I
missing something please let me know :)
Quoted 1 line
Sorry for the delay, answered to your previous message.
No worries. As I already said, I'm not doing much till the end of the month but I definetly wanted the device vs OF question settled before starting v4.
- Nuno Sá
Quoted 1 line
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Andy ShevchenkoQuoted 26 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 4 lines
Second, why do you need this specific function instead of regmap
bulk
ops against be24/le24?Not sure I'm following this one... If you mean why am I using a custom
regmap_busimplementation, that was already explained in the RFC
patch.
And IIRC, you were the one already asking 😉.Hmm... It was some time I have looked there. Any message ID to share,
so
I can find it quickly?
Quoted 7 lines
Thanks!
So, it's all about
cs_change, right?
But doesn't bulk operation work exactly as we need here?
Yes... that and we need to send the NOOP command in the second TX transfer.
Quoted 9 lines
Looking again to the RFC code, it seems like we can still do it
First, you call
_gather_write()followed by_read(). It will show exactly what
you do, i.e. you send command first with the value0x0000, followed by sending
command and reading back the value at the same time.Would it work?
Well, _gather_write() are 2 spi transfers only with TX set. That means that only on the _read() (which will be another spi_message) we will ask for the data. Im not really sure this would work being it on a different message. This would also mean, one extra dummy transfer. To me that already feels that a custom bus implementation is not a bad idea...
Quoted 29 lines
...
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 12 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that
the
types are of
the same class, e.g. if here you have u16, then there something
like
s32 / s64.
Or here something like unsigned short.Quoted 1 line
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather
than using
stdint types...). So I pretty much just use these in unsigned types
because
I'm lazy and u16 is faster to type than unsigned short... In this
case, unless Jonathan
really asks for it, I prefer not to go all over the driver and change this...
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
This is about consistency. It may work as is, but it feels not good
when for
int (or unsigned int) one uses fixed-width types. Also it's non- written advice
to use fixed-width variables when it's about programming registers or
so, for
the rest, use POD types.
Ok, going a bit back in the discussion, you argued that in one place I was using long while here u16. Well, in the place I'm using long, that was on purpose because that value is to be compared against an array of longs (which has to be long because it depends on CCF rates). I guess I can als0 use s64, but there is also a reason why long was used.
In the u16 case, we really want to have 2 bytes because I'm going to use that value to write the dac code which is 2 bytes.
Quoted 71 lines
Quoted 6 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it
if it really becomes something that we will try to "enforce" in IIO.
Otherwise it just feels as a random nitpick :).No, this is about consistency and common sense. If you define type uXX,
we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.
...
Quoted 54 lines
Quoted 42 lines
Quoted 28 lines
Quoted 16 lines
Quoted 11 lines
+static int ltc2688_tgp_clk_setup(struct
ltc2688_state*st, + structltc2688_chan*chan, + structdevice_node*np, int
tgp)drivers/iio/dac/ltc2688.c new file +6
-0+{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev, np,Quoted 2 lines
NULL);
+ if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
Quoted 11 lines
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 4 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk),
+ "failed to get tgp clk.\n");Quoted 6 lines
Well, I might be missing the point but I think this is not so straight....
We will only get here if the property " adi,toggle-dither- input" is
given
in which case having the associated clocks is__mandatory__.Ah, okay, would be a limitation for non-OF platforms.
Quoted 4 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_nodeQuoted 5 lines
That's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.hWhy? This header doesn't bring anything you will use here.
Correct me if Im missing something. AFAIU, the idea is to use '
device_for_each_child_node()' which returns afwnode_handle. That means, that we will have to pass that to this function and use 'to_of_node()' to pass adevice_nodeto 'devm_get_clk_from_child()'.
Quoted 5 lines
Quoted 1 line
This means, we need
of.hfor 'to_of_node()'...Yeah, you are right, but it would be still better since it narrows the problem to the CCF calls only.
So, to clear....
In your opinion, you are fine whith using device properties and just have 'to_of_node()' in this CCF call? I'm fine with it, so if Jonathan does not have any complain about it, will do like this in v4,
Jonathan, any comment on this one?
- Nuno Sá
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 180 lines · On Fri, 18 Feb 2022 14:51:28 +0100 Nuno Sá <[email protected]> wrote:
Quoted 26 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 4 lines
Second, why do you need this specific function instead of regmap
bulk
ops against be24/le24?Not sure I'm following this one... If you mean why am I using a custom
regmap_busimplementation, that was already explained in the RFC
patch.
And IIRC, you were the one already asking 😉.Hmm... It was some time I have looked there. Any message ID to share,
so
I can find it quickly?Quoted 7 lines
Thanks!
So, it's all about
cs_change, right?
But doesn't bulk operation work exactly as we need here?Yes... that and we need to send the NOOP command in the second TX transfer.
Quoted 9 lines
Looking again to the RFC code, it seems like we can still do it
First, you call
_gather_write()followed by_read(). It will show exactly what
you do, i.e. you send command first with the value0x0000, followed by sending
command and reading back the value at the same time.Would it work?
Well,
_gather_write()are 2 spi transfers only with TX set. That means that only on the_read()(which will be anotherspi_message) we will ask for the data. Im not really sure this would work being it on a different message. This would also mean, one extra dummy transfer. To me that already feels that a custom bus implementation is not a bad idea...Quoted 29 lines
...
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 12 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that
the
types are of
the same class, e.g. if here you have u16, then there something
like
s32 / s64.
Or here something like unsigned short.Quoted 1 line
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather
than using
stdint types...). So I pretty much just use these in unsigned types
because
I'm lazy and u16 is faster to type than unsigned short... In this
case, unless Jonathan
really asks for it, I prefer not to go all over the driver and change this...Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
This is about consistency. It may work as is, but it feels not good
when for
int (or unsigned int) one uses fixed-width types. Also it's non- written advice
to use fixed-width variables when it's about programming registers or
so, for
the rest, use POD types.Ok, going a bit back in the discussion, you argued that in one place I was using long while here u16. Well, in the place I'm using long, that was on purpose because that value is to be compared against an array of longs (which has to be long because it depends on CCF rates). I guess I can als0 use s64, but there is also a reason why long was used.
In the u16 case, we really want to have 2 bytes because I'm going to use that value to write the dac code which is 2 bytes.
Quoted 71 lines
Quoted 6 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it
if it really becomes something that we will try to "enforce" in IIO.
Otherwise it just feels as a random nitpick :).No, this is about consistency and common sense. If you define type uXX,
we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.
...
Quoted 54 lines
Quoted 42 lines
Quoted 28 lines
Quoted 16 lines
Quoted 11 lines
+static int ltc2688_tgp_clk_setup(struct
ltc2688_state*st, + structltc2688_chan*chan, + structdevice_node*np, int
tgp)(quoted diff) +6
-0+{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev, np,Quoted 2 lines
NULL);
+ if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
Quoted 11 lines
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 4 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk),
+ "failed to get tgp clk.\n");Quoted 6 lines
Well, I might be missing the point but I think this is not so straight....
We will only get here if the property " adi,toggle-dither- input" is
given
in which case having the associated clocks is__mandatory__.Ah, okay, would be a limitation for non-OF platforms.
Quoted 4 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_nodeQuoted 5 lines
That's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.hWhy? This header doesn't bring anything you will use here.
Correct me if Im missing something. AFAIU, the idea is to use '
device_for_each_child_node()' which returns afwnode_handle. That means, that we will have to pass that to this function and use 'to_of_node()' to pass adevice_nodeto 'devm_get_clk_from_child()'.Quoted 5 lines
Quoted 1 line
This means, we need
of.hfor 'to_of_node()'...Yeah, you are right, but it would be still better since it narrows the problem to the CCF calls only.
Quoted 7 lines
So, to clear....
In your opinion, you are fine whith using device properties and just have '
to_of_node()' in this CCF call? I'm fine with it, so if Jonathan does not have any complain about it, will do like this in v4,Jonathan, any comment on this one?
Whilst it's less than ideal, I'm fine with it being all generic except for the clock part and using to_of_node() which I think is what Andy is suggesting.
Thanks,
Jonathan
Quoted 3 lines
- Nuno Sá
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Andy ShevchenkoQuoted 58 lines · Andy Shevchenko
Quoted 3 lines · 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.
...
Quoted 1 line
+#include <
linux/of.h>
property.hplease/...
Quoted 20 lines
+static int ltc2688_spi_read(void *context, const void *reg,
size_treg_size,
+ void *val,size_tval_size)drivers/iio/dac/ltc2688.c new file +16
-0+{ + struct ltc2688_state *st = context; + struct spi_transfer xfers[] = { + { + .tx_buf = st->tx_data, + .bits_per_word = 8, + .len = 3, + .cs_change = 1, + }, { + .tx_buf = st->tx_data + 3, + .rx_buf = st->rx_data, + .bits_per_word = 8, + .len = 3, + }, + }; + int ret;drivers/iio/dac/ltc2688.c line 128
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+ memcpy(st->tx_data, reg, reg_size); + + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); + if (ret) + return ret; + + memcpy(val, &st->rx_data[1], val_size); + + return 0; +}First of all, yuo have fixed len in transfer sizes, so what the purpose of the
reg_size/val_size?
Second, why do you need this specific function instead of regmap bulk ops against be24/le24?...
Quoted 1 line
+unlock:
out_unlock: ?
(And in similar cases)...
Quoted 9 lines
Quoted 4 lines
+ if (ret)
+ return ret;
+
+ return len;In some cases the return ret ?: len; is used, in some like above. Maybe a bit
of consistency?
Hmm, when doing some changes for v4 I realized why I used the ternary operator here (typically I'm not a fan). The thing is that we already check the error condition after calling regmap_update_bits() which is not the last code executed. Hence, I didn't want to do again
if (ret)
return ret
after unlocking the mutex.
In the other places the error check is always on the last lines where nothing else will happen (either return error or len).
Alternatively, to remove the ternary operator, I would prefer to actually remove the label and goto and after regmap_update_bits(), do:
if (ret) {
mutex_unlock();
return ret;
}It might be not consistent with other places were goto is used but this function also has it's differencies...
- Nuno Sá
Quoted 309 lines
...
Quoted 5 lines
+ if (private ==
LTC2688_INPUT_B_AVAIL)
+ return sysfs_emit(buf, "[%u %u %u]\n", ltc2688_raw_range[0],
+ ltc2688_raw_range[1], + ltc2688_raw_range[2] / 4);Is it standard form "[A B C]" for ranges in IIO? I haven't looked into the code
deeply (and datasheet at all) to understand meaning. To me range is usually out
of two numbers.Quoted 9 lines
+ if (private ==
LTC2688_DITHER_OFF)
+ returnsysfs_emit(buf, "0\n");+ ret =
ltc2688_dac_code_read(st, chan->channel, private, &val);
+ if (ret)
+ return ret;
+
+ returnsysfs_emit(buf, "%u\n", val);These three types of output for one sysfs node? Seems it's not align with the
idea behind sysfs. It maybe that I missed something....
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the types are of
the same class, e.g. if here you have u16, then there something like s32 / s64.
Or here something like unsigned short.A bit of elaboration why u16 is chosen here?
...
Quoted 4 lines
+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW), \
+ .ext_info =
ltc2688_ext_info \+ Comma
...
drivers/iio/dac/ltc2688.c line 710
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10
-0+static int ltc2688_tgp_clk_setup (struct ltc2688_state *st, + struct ltc2688_chan *chan, + struct device_node *np, int tgp) +{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev, np, NULL); + if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 25 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk), + "failed to get tgp clk.\n"); +
+ ret =clk_prepare_enable(clk);
+ if (ret)
+ return dev_err_probe(&st->spi->dev, ret, + "failed to enable tgp clk.\n");
+
+ ret =devm_add_action_or_reset(&st->spi->dev, ltc2688_clk_disable, clk);
+ if (ret)
+ return ret;drivers/iio/dac/ltc2688.c new file +8
-0+ + if (chan->toggle_chan) + return 0; + + /* calculate available dither frequencies */ + rate = clk_get_rate(clk); + for (f = 0; f < ARRAY_SIZE(chan->dither_frequency); f++) + chan->dither_frequency[f] = DIV_ROUND_CLOSEST(rate,ltc2688_period[f]);
drivers/iio/dac/ltc2688.c new file +3
-0+ + return 0; +}...
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) {
device_for_each_child_node()Quoted 32 lines
+ struct
ltc2688_chan*chan;
+
+ ret =of_property_read_u32(child, "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;
+ /*
+ * ClearIIO_CHAN_INFO_RAWbit as toggle channels expose
+ * out_voltage_raw{0|1} files.
+ */Quoted 3 lines
+ clear_bit(IIO_CHAN_INFO_RAW, + &st-
Quoted 1 line
iio_chan[reg].info_mask_separate);
Do you need atomic operation here?
Quoted 95 lines
+ }
+
+ 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; + }drivers/iio/dac/ltc2688.c new file +5
-0+ + 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");
+ }
+ }drivers/iio/dac/ltc2688.c new file +3
-0+ + return 0; +}...
Quoted 6 lines
+struct
regmap_busltc2688_regmap_bus= {
+ .read =ltc2688_spi_read,
+ .write =ltc2688_spi_write,
+ .read_flag_mask =LTC2688_READ_OPERATION, + .reg_format_endian_default =REGMAP_ENDIAN_BIG, + .val_format_endian_default =REGMAP_ENDIAN_BIG+ Comma.
drivers/iio/dac/ltc2688.c line 956
Quoted 9 lines
drivers/iio/dac/ltc2688.c new file +9
-0+}; + +static const struct regmap_config ltc2688_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .readable_reg = ltc2688_reg_readable, + .writeable_reg = ltc2688_reg_writable, + /* ignoring the no op command */ + .max_register = LTC2688_CMD_UPDATE_ALLDitto.
Quoted 1 line
+};
...
Quoted 3 lines
+ vref_reg =
devm_regulator_get_optional(dev, "vref");+ if (!IS_ERR(vref_reg)) {
Why not positive conditional check (and hence standard pattern -- error
handling first)?Quoted 29 lines
+ ret =
regulator_enable(vref_reg);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to enable vref regulators\n");
+
+ ret = devm_add_action_or_reset(dev,ltc2688_disable_regulator,
+vref_reg); + if (ret)
+ return ret;
+
+ ret =regulator_get_voltage(vref_reg);
+ if (ret < 0)
+ returndev_err_probe(dev, ret, "Failed to get vref\n");
+
+ st->vref = ret / 1000;
+ } else {
+ if (PTR_ERR(vref_reg)!=-ENODEV)
+ return dev_err_probe(dev,PTR_ERR(vref_reg),
+ "Failed to get vref regulator");
+
+ vref_reg = NULL;
+ /* internal reference */
+ st->vref = 4096;
+ }
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
In reply to Nuno SáQuoted 7 lines · Nuno Sá
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:
...
Quoted 36 lines
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 4 lines
Second, why do you need this specific function instead of regmap
bulk
ops against be24/le24?Not sure I'm following this one... If you mean why am I using a custom
regmap_busimplementation, that was already explained in the RFC
patch.
And IIRC, you were the one already asking 😉.Hmm... It was some time I have looked there. Any message ID to share,
so
I can find it quickly?Quoted 7 lines
Thanks!
So, it's all about
cs_change, right?
But doesn't bulk operation work exactly as we need here?Yes... that and we need to send the NOOP command in the second TX transfer.
Quoted 8 lines
Looking again to the RFC code, it seems like we can still do it
First, you call
_gather_write()followed by_read(). It will show exactly what
you do, i.e. you send command first with the value0x0000, followed by sending
command and reading back the value at the same time.
Quoted 8 lines
Quoted 1 line
Would it work?
Well,
_gather_write()are 2 spi transfers only with TX set. That means that only on the_read()(which will be anotherspi_message) we will ask for the data. Im not really sure this would work being it on a different message. This would also mean, one extra dummy transfer. To me that already feels that a custom bus implementation is not a bad idea...
I see, okay, what Jonothan decides then. Still I'm not convinced.
...
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 12 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that
the
types are of
the same class, e.g. if here you have u16, then there something
like
s32 / s64.
Or here something like unsigned short.Quoted 1 line
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather
than using
stdint types...). So I pretty much just use these in unsigned types
because
I'm lazy and u16 is faster to type than unsigned short... In this
case, unless Jonathan
really asks for it, I prefer not to go all over the driver and change this...Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
This is about consistency. It may work as is, but it feels not good
when for
int (or unsigned int) one uses fixed-width types. Also it's non- written advice
to use fixed-width variables when it's about programming registers or
so, for
the rest, use POD types.
Quoted 8 lines
Ok, going a bit back in the discussion, you argued that in one place I was using long while here u16. Well, in the place I'm using long, that was on purpose because that value is to be compared against an array of longs (which has to be long because it depends on CCF rates). I guess I can als0 use s64, but there is also a reason why long was used.
In the u16 case, we really want to have 2 bytes because I'm going to use that value to write the dac code which is 2 bytes.
Okay, that's what I want to hear. If it's indeed goes to be a value to the register, then it's fine.
Perhaps a comment?
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it
if it really becomes something that we will try to "enforce" in IIO.
Otherwise it just feels as a random nitpick :).No, this is about consistency and common sense. If you define type uXX,
we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.
...
Quoted 56 lines
Quoted 56 lines
Quoted 55 lines
Quoted 42 lines
Quoted 28 lines
Quoted 16 lines
Quoted 11 lines
+static int ltc2688_tgp_clk_setup(struct
ltc2688_state*st, + structltc2688_chan*chan, + structdevice_node*np, int
tgp)(quoted diff) +6
-0+{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev, np,Quoted 2 lines
NULL);
+ if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
Quoted 11 lines
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 4 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk),
+ "failed to get tgp clk.\n");Quoted 6 lines
Well, I might be missing the point but I think this is not so straight....
We will only get here if the property " adi,toggle-dither- input" is
given
in which case having the associated clocks is__mandatory__.Ah, okay, would be a limitation for non-OF platforms.
Quoted 4 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_nodeQuoted 5 lines
That's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.hWhy? This header doesn't bring anything you will use here.
Correct me if Im missing something. AFAIU, the idea is to use '
device_for_each_child_node()' which returns afwnode_handle. That means, that we will have to pass that to this function and use 'to_of_node()' to pass adevice_nodeto 'devm_get_clk_from_child()'.This means, we need
of.hfor 'to_of_node()'...
Quoted 8 lines
Quoted 2 lines
Yeah, you are right, but it would be still better since it narrows the problem to the CCF calls only.
So, to clear....
In your opinion, you are fine whith using device properties and just have '
to_of_node()' in this CCF call? I'm fine with it, so if Jonathan does not have any complain about it, will do like this in v4,
Yes, that will show that only CCF is missing the fwnode APIs.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 122 lines · Andy Shevchenko
Quoted 7 lines · Nuno Sá
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 42 lines
Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 5 lines
Quoted 4 lines
Second, why do you need this specific function instead of regmap
bulk
ops against be24/le24?Quoted 8 lines
Not sure I'm following this one... If you mean why am I using a
customregmap_busimplementation, that was already explained in the
RFC
patch.
And IIRC, you were the one already asking 😉.Hmm... It was some time I have looked there. Any message ID to
share,
so
I can find it quickly?Quoted 7 lines
Thanks!
So, it's all about
cs_change, right?
But doesn't bulk operation work exactly as we need here?Yes... that and we need to send the NOOP command in the second TX transfer.
Quoted 10 lines
Looking again to the RFC code, it seems like we can still do it
First, you call
_gather_write()followed by_read(). It will show exactly what
you do, i.e. you send command first with the value0x0000, followed
by sending
command and reading back the value at the same time.Would it work?
Quoted 9 lines
Well,
_gather_write()are 2 spi transfers only with TX set. That means
that only on the_read()(which will be anotherspi_message) we will
ask for the data. Im not really sure this would work being it on a different message. This would also mean, one extra dummy transfer. To
me that already feels that a custom bus implementation is not a bad idea...I see, okay, what Jonothan decides then. Still I'm not convinced.
...
Quoted 51 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 12 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that
the
types are of
the same class, e.g. if here you have u16, then there something
like
s32 / s64.
Or here something like unsigned short.Quoted 1 line
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather
than using
stdint types...). So I pretty much just use these in unsigned
types
because
I'm lazy and u16 is faster to type than unsigned short... In
this
case, unless Jonathan
really asks for it, I prefer not to go all over the driver and
change this...Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
This is about consistency. It may work as is, but it feels not
good
when for
int (or unsigned int) one uses fixed-width types. Also it's non-
written advice
to use fixed-width variables when it's about programming registers or
so, for
the rest, use POD types.Ok, going a bit back in the discussion, you argued that in one place I
was using long while here u16. Well, in the place I'm using long, that
was on purpose because that value is to be compared against an array of
longs (which has to be long because it depends on CCF rates). I guess I
can als0 use s64, but there is also a reason why long was used.Quoted 3 lines
In the u16 case, we really want to have 2 bytes because I'm going to
use that value to write the dac code which is 2 bytes.
Quoted 6 lines
Okay, that's what I want to hear. If it's indeed goes to be a value to the
register, then it's fine.Perhaps a comment?
I guess you mean to have a comment to state that here we have fixed size type (as opposed to long, used in another place), because we directly use the value on a register write?
Asking it because I'm not planning to add comments in all the places where I have fixed size types for register read/writes...
Quoted 91 lines
Quoted 19 lines
Quoted 19 lines
Quoted 8 lines
I can understand your reasoning but again this is something that
I never really saw being enforced. So, I'm more than ok to change
it
if it really becomes something that we will try to "enforce" in IIO.
Otherwise it just feels as a random nitpick :).No, this is about consistency and common sense. If you define type
uXX,
we have an API for that exact type. It's confusing why POD type APIs
are used with fixed-width types or vise versa.Moreover (which is pure theoretical, though) some architectures might
have no (mutual) equivalency between these types....
Quoted 69 lines
Quoted 61 lines
Quoted 61 lines
Quoted 48 lines
Quoted 32 lines
Quoted 20 lines
Quoted 14 lines
+static int ltc2688_tgp_clk_setup(struct
ltc2688_state*st,
+ structltc2688_chan*chan,
+ structdevice_node*np,
int
tgp)(quoted diff) +6
-0+{ + unsigned long rate; + struct clk *clk; + int ret, f; + + clk = devm_get_clk_from_child(&st->spi->dev,Quoted 3 lines
np,
NULL);
+ if (IS_ERR(clk))Make it optional for non-OF, can be done as easy as
Quoted 11 lines
if (
IS_ERR(clk)) {
if (PTR_ERR(clk)==-ENOENT) clk = NULL;
else
returndev_err_probe(...); }Quoted 4 lines
+ return dev_err_probe(&st->spi->dev,
PTR_ERR(clk),
+ "failed to get tgp clk.\n");Quoted 8 lines
Well, I might be missing the point but I think this is not so
straight....
We will only get here if the property " adi,toggle-dither- input" is
given
in which case having the associated clocks is__mandatory__.Ah, okay, would be a limitation for non-OF platforms.
Quoted 4 lines
Hence,
once we are here, this can never be optional. That said, we needdevice_nodeQuoted 5 lines
That's fine, since CCF is OF-centric API.
Quoted 1 line
and hence
of.hWhy? This header doesn't bring anything you will use here.
Correct me if Im missing something. AFAIU, the idea is to use '
device_for_each_child_node()' which returns afwnode_handle. That
means, that we will have to pass that to this function and use 'to_of_node()' to pass adevice_nodeto 'devm_get_clk_from_child()'.Quoted 5 lines
Quoted 1 line
This means, we need
of.hfor 'to_of_node()'...Yeah, you are right, but it would be still better since it narrows
the problem to the CCF calls only.So, to clear....
Quoted 8 lines
Quoted 5 lines
In your opinion, you are fine whith using device properties and just
have 'to_of_node()' in this CCF call? I'm fine with it, so if Jonathan
does not have any complain about it, will do like this in v4,Yes, that will show that only CCF is missing the fwnode APIs.
Ok, it's settled then...
- Nuno Sá
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 9 lines · Nuno Sá
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Nuno Sá
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:
...
Quoted 33 lines
Quoted 33 lines
Quoted 21 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the types are of the same class, e.g. if here you have u16, then there something like s32 / s64. Or here something like unsigned short.
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather than using stdint types...). So I pretty much just use these in unsigned types because I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan really asks for it, I prefer not to go all over the driver and change this...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This is about consistency. It may work as is, but it feels not good when for int (or unsigned int) one uses fixed-width types. Also it's non- written advice to use fixed-width variables when it's about programming registers or so, for the rest, use POD types.
Quoted 8 lines
Ok, going a bit back in the discussion, you argued that in one place I was using long while here u16. Well, in the place I'm using long, that was on purpose because that value is to be compared against an array of longs (which has to be long because it depends on CCF rates). I guess I can als0 use s64, but there is also a reason why long was used.
In the u16 case, we really want to have 2 bytes because I'm going to use that value to write the dac code which is 2 bytes.
Okay, that's what I want to hear. If it's indeed goes to be a value to the register, then it's fine.
Quoted 8 lines
Quoted 1 line
Perhaps a comment?
I guess you mean to have a comment to state that here we have fixed size type (as opposed to long, used in another place), because we directly use the value on a register write?
Asking it because I'm not planning to add comments in all the places where I have fixed size types for register read/writes...
Thinking more about it and now I'm convinced that using the value that goes to the register in ABI is bad idea (means that user space must not care about the size or contents of the hardware register and should be abstract representation of the HW).
OTOH this seems to be "raw" value of something. So, I maybe missed the convention in IIO about this kind of values WRT the variable types used on ABI side.
That said, I leave it to Jonathan since I'm not convinced that u16 is a proper choice here.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it if it really becomes something that we will try to "enforce" in IIO. Otherwise it just feels as a random nitpick :).
No, this is about consistency and common sense. If you define type uXX, we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.
Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 60 lines · On Mon, 21 Feb 2022 19:04:38 +0200 Andy Shevchenko…
Quoted 9 lines · Nuno Sá
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Nuno Sá
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 33 lines
Quoted 33 lines
Quoted 21 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the types are of the same class, e.g. if here you have u16, then there something like s32 / s64. Or here something like unsigned short.
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather than using stdint types...). So I pretty much just use these in unsigned types because I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan really asks for it, I prefer not to go all over the driver and change this...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This is about consistency. It may work as is, but it feels not good when for int (or unsigned int) one uses fixed-width types. Also it's non- written advice to use fixed-width variables when it's about programming registers or so, for the rest, use POD types.
Quoted 8 lines
Ok, going a bit back in the discussion, you argued that in one place I was using long while here u16. Well, in the place I'm using long, that was on purpose because that value is to be compared against an array of longs (which has to be long because it depends on CCF rates). I guess I can als0 use s64, but there is also a reason why long was used.
In the u16 case, we really want to have 2 bytes because I'm going to use that value to write the dac code which is 2 bytes.
Okay, that's what I want to hear. If it's indeed goes to be a value to the register, then it's fine.
Quoted 8 lines
Quoted 1 line
Perhaps a comment?
I guess you mean to have a comment to state that here we have fixed size type (as opposed to long, used in another place), because we directly use the value on a register write?
Asking it because I'm not planning to add comments in all the places where I have fixed size types for register read/writes...
Thinking more about it and now I'm convinced that using the value that goes to the register in ABI is bad idea (means that user space must not care about the size or contents of the hardware register and should be abstract representation of the HW).
Quoted 5 lines
OTOH this seems to be "raw" value of something. So, I maybe missed the convention in IIO about this kind of values WRT the variable types used on ABI side.
That said, I leave it to Jonathan since I'm not convinced that u16 is a proper choice here.
From a userspace point of view it doesn't care as it's writing a string. In this particular case the string only has valid values that from 0-(2^16-1) (i.e. 16 bits). So if it writes outside of that range it is an error. You could read it into an unsigned long and then check against the range, but there is little point given you'd still return an error if it was out of range. The fact that kstrto16() does that for you really just a shortcut though it will return -ERANGE rather than perhaps -EINVAL which might be used for a more generic "not this value".
Userspace can also read the range that is acceptable from out_voltage0_raw_available [0 1 2^16-1] and hence not write an invalid value in the first place - which is obviously preferred to getting an error. Scaling etc is also expressed to userspace so it it wants to write a particular voltage it can perform the appropriate scaling. Note that moving linear scaling like this to userspace allows easy use of floating point + may be a significant performance advantage if using the chrdev interface which uses the same approach (and values) as the sysfs interface.
Jonathan
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it if it really becomes something that we will try to "enforce" in IIO. Otherwise it just feels as a random nitpick :).
No, this is about consistency and common sense. If you define type uXX, we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.
Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 78 lines · Jonathan Cameron
Quoted 60 lines · On Mon, 21 Feb 2022 19:04:38 +0200 Andy Shevchenko…
Quoted 9 lines · Nuno Sá
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Nuno Sá
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 33 lines
Quoted 33 lines
Quoted 21 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the types are of the same class, e.g. if here you have u16, then there something like s32 / s64. Or here something like unsigned short.
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather than using stdint types...). So I pretty much just use these in unsigned types because I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan really asks for it, I prefer not to go all over the driver and change this...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This is about consistency. It may work as is, but it feels not good when for int (or unsigned int) one uses fixed-width types. Also it's non- written advice to use fixed-width variables when it's about programming registers or so, for the rest, use POD types.
Quoted 8 lines
Ok, going a bit back in the discussion, you argued that in one place I was using long while here u16. Well, in the place I'm using long, that was on purpose because that value is to be compared against an array of longs (which has to be long because it depends on CCF rates). I guess I can als0 use s64, but there is also a reason why long was used.
In the u16 case, we really want to have 2 bytes because I'm going to use that value to write the dac code which is 2 bytes.
Okay, that's what I want to hear. If it's indeed goes to be a value to the register, then it's fine.
Quoted 8 lines
Quoted 1 line
Perhaps a comment?
I guess you mean to have a comment to state that here we have fixed size type (as opposed to long, used in another place), because we directly use the value on a register write?
Asking it because I'm not planning to add comments in all the places where I have fixed size types for register read/writes...
Thinking more about it and now I'm convinced that using the value that goes to the register in ABI is bad idea (means that user space must not care about the size or contents of the hardware register and should be abstract representation of the HW).
Quoted 5 lines
OTOH this seems to be "raw" value of something. So, I maybe missed the convention in IIO about this kind of values WRT the variable types used on ABI side.
That said, I leave it to Jonathan since I'm not convinced that u16 is a proper choice here.
From a userspace point of view it doesn't care as it's writing a string. In this particular case the string only has valid values that from 0-(2^16-1) (i.e. 16 bits). So if it writes outside of that range it is an error. You could read it into an unsigned long and then check against the range, but there is little point given you'd still return an error if it was out of range. The fact that
kstrto16()does that for you really just a shortcut though it will return-ERANGErather than perhaps-EINVALwhich might be used for a more generic "not this value".
Quoted 8 lines
Userspace can also read the range that is acceptable from
out_voltage0_raw_available[0 1 2^16-1] and hence not write an invalid value in the first place - which is obviously preferred to getting an error. Scaling etc is also expressed to userspace so it it wants to write a particular voltage it can perform the appropriate scaling. Note that moving linear scaling like this to userspace allows easy use of floating point + may be a significant performance advantage if using the chrdev interface which uses the same approach (and values) as the sysfs interface.
With the same logic it can be unsigned short, no?
The point is to use u16 when it's indeed fixed-width value that goes to hardware or being used as part of a protocol. And thus mentioning of the IOCTL protocols may justify the choice. Then the question to the other values, shouldn't they be also fixed-width ones?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it if it really becomes something that we will try to "enforce" in IIO. Otherwise it just feels as a random nitpick :).
No, this is about consistency and common sense. If you define type uXX, we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.
Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/3] iio: dac: add support for ltc2688
Quoted 88 lines · On Mon, 21 Feb 2022 20:49:48 +0200 Andy Shevchenko…
Quoted 78 lines · Jonathan Cameron
Quoted 60 lines · On Mon, 21 Feb 2022 19:04:38 +0200 Andy Shevchenko…
Quoted 9 lines · Nuno Sá
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Nuno Sá
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Nuno Sá
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Nuno
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Saturday, February 5, 2022 6:30 PM
On Fri, Jan 21, 2022 at 03:24:59PM +0100, Nuno Sá wrote:...
Quoted 33 lines
Quoted 33 lines
Quoted 21 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 1 line
+ ret =
kstrtou16(buf, 10, &val);In other function you have long, here u16. I would expect that the types are of the same class, e.g. if here you have u16, then there something like s32 / s64. Or here something like unsigned short.
A bit of elaboration why u16 is chosen here?
Well, I never really saw any enforcement here to be honest (rather than using stdint types...). So I pretty much just use these in unsigned types because I'm lazy and u16 is faster to type than unsigned short... In this case, unless Jonathan really asks for it, I prefer not to go all over the driver and change this...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This is about consistency. It may work as is, but it feels not good when for int (or unsigned int) one uses fixed-width types. Also it's non- written advice to use fixed-width variables when it's about programming registers or so, for the rest, use POD types.
Quoted 8 lines
Ok, going a bit back in the discussion, you argued that in one place I was using long while here u16. Well, in the place I'm using long, that was on purpose because that value is to be compared against an array of longs (which has to be long because it depends on CCF rates). I guess I can als0 use s64, but there is also a reason why long was used.
In the u16 case, we really want to have 2 bytes because I'm going to use that value to write the dac code which is 2 bytes.
Okay, that's what I want to hear. If it's indeed goes to be a value to the register, then it's fine.
Quoted 8 lines
Quoted 1 line
Perhaps a comment?
I guess you mean to have a comment to state that here we have fixed size type (as opposed to long, used in another place), because we directly use the value on a register write?
Asking it because I'm not planning to add comments in all the places where I have fixed size types for register read/writes...
Thinking more about it and now I'm convinced that using the value that goes to the register in ABI is bad idea (means that user space must not care about the size or contents of the hardware register and should be abstract representation of the HW).
Quoted 5 lines
OTOH this seems to be "raw" value of something. So, I maybe missed the convention in IIO about this kind of values WRT the variable types used on ABI side.
That said, I leave it to Jonathan since I'm not convinced that u16 is a proper choice here.
From a userspace point of view it doesn't care as it's writing a string. In this particular case the string only has valid values that from 0-(2^16-1) (i.e. 16 bits). So if it writes outside of that range it is an error. You could read it into an unsigned long and then check against the range, but there is little point given you'd still return an error if it was out of range. The fact that
kstrto16()does that for you really just a shortcut though it will return-ERANGErather than perhaps-EINVALwhich might be used for a more generic "not this value".Quoted 8 lines
Userspace can also read the range that is acceptable from
out_voltage0_raw_available[0 1 2^16-1] and hence not write an invalid value in the first place - which is obviously preferred to getting an error. Scaling etc is also expressed to userspace so it it wants to write a particular voltage it can perform the appropriate scaling. Note that moving linear scaling like this to userspace allows easy use of floating point + may be a significant performance advantage if using the chrdev interface which uses the same approach (and values) as the sysfs interface.
Quoted 1 line
With the same logic it can be unsigned short, no?
It could be any integer as long as it is at least as large as a u16. But it it is larger than a u16 you'll need an additional check on the maximum.
Quoted 5 lines
The point is to use u16 when it's indeed fixed-width value that goes to hardware or being used as part of a protocol. And thus mentioning of the IOCTL protocols may justify the choice. Then the question to the other values, shouldn't they be also fixed-width ones?
If we had a fixed width type that took the values 0-4 sure using such a magic type would make sense, but we don't.
Note that internally kstrtou16 is just strtoull and a range check. The one other case we have here does pretty much the same thing.
Jonathan
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
I can understand your reasoning but again this is something that I never really saw being enforced. So, I'm more than ok to change it if it really becomes something that we will try to "enforce" in IIO. Otherwise it just feels as a random nitpick :).
No, this is about consistency and common sense. If you define type uXX, we have an API for that exact type. It's confusing why POD type APIs are used with fixed-width types or vise versa.
Moreover (which is pure theoretical, though) some architectures might have no (mutual) equivalency between these types.