* [PATCH v4 0/8] Add iio backend compatibility for ad7606
@ 2024-10-09 9:19 Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 1/8] dt-bindings: iio: adc: ad7606: Remove spi-cpha from required Guillaume Stols
` (7 more replies)
0 siblings, 8 replies; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
This series aims to add iio backend support for AD7606X ADCs.
In a nutshell, iio backend is a paradigm to shift the logic establishing
the connexion between iio buffers and backend buffers into the backend's
driver. This provides a more stable programming interface to the driver
developers, and give more flexibility in the way the hardware communicates.
The support will be first added on AD7606B, and on next patches AD7606C16
and AD7606C18 will be added. The series have been tested on a Zedboard,
using the latest HDL available, i.e
https://github.com/analogdevicesinc/hdl/commit/7d0a4cee1b5fa403f175af513d7eb804c3bd75d0
and an AD7606B FMCZ EKV. This HDL handles both the conversion trigger
(through a PWM), and the end of conversion interruption, and is compatible
with axi-adc, which is "iio-backendable".
More information about this HDL design can be found at:
https://wiki.analog.com/resources/eval/user-guides/ad7606x-fmc/hdl
The support is thus separated in two parts:
- PWM support was first added. My first intention was to make it available
for any version of the driver, but the time required to handle the
interruption is not neglectable, and I saw drifts that would eventually
cause an overlapping SPI read with a new conversion trigger, whith
catastrphic consequences. To mitigate this, CRC check must be
implemented, but indeed increasing the samplerate causes more sample to
be lost. Therefore, I decided to only allow PWM for iio-backend
powered device as a first intention, leaving open the possibility to
add the general compatibility afterwards.
- IIO backend support was added: Once the PWM support was ready, the driver
can be extended to iio-backend. The iio-backend powered version of the
driver is a platform driver, and an exemple devicetree node is available
in the bindings.
The following features will be added in subsequent patch series:
- software mode for iio backend
- 18 bits mode (AD7606C18)
- single read (IIO_CHAN_READ_RAW)
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
Changes in v4:
- Removal of accepted patches.
- Correction on fsleep (missing semicolon and incorrect spelling !).
- Correction on buffer initialization that should not be conditionned by
the presence or not of a PWM, but by the presence of a backend.
- Addition of blank lines between blocks.
- Modification of some declaration to switch variables to static.
- Link to v3: https://lore.kernel.org/r/20241004-ad7606_add_iio_backend_support-v3-0-38757012ce82@baylibre.com
Changes in v3:
- Rebase on top of the series adding ad7606C16 and AD7606C18 support.
- Addition of pwm-names actual values and improvement in the
description.
- Introduction of .num_adc_channels field in ad7606_chip_info that
defines the number of hardware inputs.
- Introduction of ad7606_bus_info which couples hardware and wiring
informations.
- Addition of a delay in the scan_direct function for the backend.
- Link to v2: https://lore.kernel.org/r/20240920-ad7606_add_iio_backend_support-v2-0-0e78782ae7d0@baylibre.com
Changes in v2:
- Logical change in dt-bindings, using a flag for the interface instead of
infering it from the value of the "reg" property.
- Removal of get_platform_match_data addition, instead the logic is
directly used in the file.
- Removal of use and export of pwm_get_state_hw, returning the configured
frequency instead of the running one.
- Correction on various typos, whitespaces, bad order of includes.
- Separation of SPI conditions and PWM disabling for no backend in other
commits.
- Link to v1: https://lore.kernel.org/r/20240815-ad7606_add_iio_backend_support-v1-0-cea3e11b1aa4@baylibre.com
---
Guillaume Stols (8):
dt-bindings: iio: adc: ad7606: Remove spi-cpha from required
dt-bindings: iio: adc: ad7606: Add iio backend bindings
Documentation: iio: Document ad7606 driver
iio: adc: ad7606: Add PWM support for conversion trigger
iio: adc: ad7606: Add compatibility to fw_nodes
iio: adc: ad7606: Introduce num_adc_channels
iio: adc: ad7606: Add iio-backend support
iio: adc: ad7606: Disable PWM usage for non backend version
.../devicetree/bindings/iio/adc/adi,ad7606.yaml | 72 ++-
Documentation/iio/ad7606.rst | 145 ++++++
Documentation/iio/index.rst | 1 +
MAINTAINERS | 1 +
drivers/iio/adc/Kconfig | 2 +
drivers/iio/adc/ad7606.c | 575 +++++++++++++++------
drivers/iio/adc/ad7606.h | 51 +-
drivers/iio/adc/ad7606_par.c | 123 ++++-
drivers/iio/adc/ad7606_spi.c | 96 ++--
9 files changed, 839 insertions(+), 227 deletions(-)
---
base-commit: 96be67caa0f0420d4128cb67f07bbd7a6f49e03a
change-id: 20240725-ad7606_add_iio_backend_support-c401305a6924
Best regards,
--
Guillaume Stols <gstols@baylibre.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/8] dt-bindings: iio: adc: ad7606: Remove spi-cpha from required
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 2/8] dt-bindings: iio: adc: ad7606: Add iio backend bindings Guillaume Stols
` (6 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
The documentation is erroneously stating that spi-cpha is required, and
the example is erroneously setting both spi-cpol and spi-cpha. According
to the datasheet, only cpol should be set.
On zedboard for instance, setting the devicetree as in the example will
simply not work.
Fixes: 416f882c3b40 ("dt-bindings: iio: adc: Migrate AD7606 documentation to yaml")
Fixes: 6e33a125df66 ("dt-bindings: iio: adc: Add docs for AD7606 ADC")
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
index bec7cfba52a7..47081c79a1cf 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
@@ -39,6 +39,11 @@ properties:
"#size-cells":
const: 0
+ # According to the datasheet, "Data is clocked in from SDI on the falling
+ # edge of SCLK, while data is clocked out on DOUTA on the rising edge of
+ # SCLK". Also, even if not stated textually in the datasheet, it is made
+ # clear on the diagrams that sclk idles at high. Subsequently, in case SPI
+ # interface is used, the correct way is to only set spi-cpol.
spi-cpha: true
spi-cpol: true
@@ -168,7 +173,6 @@ patternProperties:
required:
- compatible
- reg
- - spi-cpha
- avcc-supply
- vdrive-supply
- interrupts
@@ -255,7 +259,6 @@ examples:
reg = <0>;
spi-max-frequency = <1000000>;
spi-cpol;
- spi-cpha;
avcc-supply = <&adc_vref>;
vdrive-supply = <&vdd_supply>;
@@ -288,7 +291,6 @@ examples:
spi-max-frequency = <1000000>;
spi-cpol;
- spi-cpha;
avcc-supply = <&adc_vref>;
vdrive-supply = <&vdd_supply>;
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 2/8] dt-bindings: iio: adc: ad7606: Add iio backend bindings
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 1/8] dt-bindings: iio: adc: ad7606: Remove spi-cpha from required Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 3/8] Documentation: iio: Document ad7606 driver Guillaume Stols
` (5 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
Add the required properties for iio-backend support, as well as an
example and the conditions to mutually exclude interruption and
conversion trigger with iio-backend.
The iio-backend's function is to controls the communication, and thus the
interruption pin won't be available anymore.
As a consequence, the conversion pin must be controlled externally since
we will miss information about when every single conversion cycle (i.e
conversion + data transfer) ends, hence a PWM is introduced to trigger
the conversions.
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
.../devicetree/bindings/iio/adc/adi,ad7606.yaml | 64 +++++++++++++++++++++-
1 file changed, 62 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
index 47081c79a1cf..0a612844029a 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
@@ -129,6 +129,29 @@ properties:
assumed that the pins are hardwired to VDD.
type: boolean
+ pwms:
+ description:
+ In case the conversion is triggered by a PWM instead of a GPIO plugged to
+ the CONVST pin, the PWM must be referenced.
+ The first is the PWM connected to CONVST or CONVST1 for the chips with the
+ 2nd PWM connected to CONVST2, if CONVST2 is available and not shorted to
+ CONVST1.
+ minItems: 1
+ maxItems: 2
+
+ pwm-names:
+ items:
+ - const: convst1
+ - const: convst2
+
+ io-backends:
+ description:
+ A reference to the iio-backend, which is responsible handling the BUSY
+ pin's falling edge and communication.
+ An example of backend can be found at
+ http://analogdevicesinc.github.io/hdl/library/axi_ad7606x/index.html
+
+
patternProperties:
"^channel@[1-8]$":
type: object
@@ -175,12 +198,22 @@ required:
- reg
- avcc-supply
- vdrive-supply
- - interrupts
- - adi,conversion-start-gpios
allOf:
- $ref: /schemas/spi/spi-peripheral-props.yaml#
+ - oneOf:
+ - required:
+ - adi,conversion-start-gpios
+ - required:
+ - pwms
+
+ - oneOf:
+ - required:
+ - interrupts
+ - required:
+ - io-backends
+
- if:
properties:
compatible:
@@ -222,6 +255,10 @@ allOf:
adi,sw-mode: false
else:
properties:
+ pwms:
+ maxItems: 1
+ pwm-names:
+ maxItems: 1
adi,conversion-start-gpios:
maxItems: 1
@@ -247,6 +284,29 @@ allOf:
unevaluatedProperties: false
examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ iio-backend {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ adi_adc@0 {
+ compatible = "adi,ad7606b";
+ reg = <0>;
+ pwms = <&axi_pwm_gen 0 0>;
+
+ avcc-supply = <&adc_vref>;
+ vdrive-supply = <&vdd_supply>;
+
+ reset-gpios = <&gpio0 91 GPIO_ACTIVE_HIGH>;
+ standby-gpios = <&gpio0 90 GPIO_ACTIVE_LOW>;
+ adi,range-gpios = <&gpio0 89 GPIO_ACTIVE_HIGH>;
+ adi,oversampling-ratio-gpios = <&gpio0 88 GPIO_ACTIVE_HIGH
+ &gpio0 87 GPIO_ACTIVE_HIGH
+ &gpio0 86 GPIO_ACTIVE_HIGH>;
+ io-backends = <&iio_backend>;
+ };
+ };
+
- |
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 3/8] Documentation: iio: Document ad7606 driver
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 1/8] dt-bindings: iio: adc: ad7606: Remove spi-cpha from required Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 2/8] dt-bindings: iio: adc: ad7606: Add iio backend bindings Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 4/8] iio: adc: ad7606: Add PWM support for conversion trigger Guillaume Stols
` (4 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
The Analog Devices Inc. AD7606 (and similar chips) are complex ADCs that
will benefit from a detailed driver documentation.
This documents the current features supported by the driver.
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
Documentation/iio/ad7606.rst | 145 +++++++++++++++++++++++++++++++++++++++++++
Documentation/iio/index.rst | 1 +
MAINTAINERS | 1 +
3 files changed, 147 insertions(+)
diff --git a/Documentation/iio/ad7606.rst b/Documentation/iio/ad7606.rst
new file mode 100644
index 000000000000..a1173708b489
--- /dev/null
+++ b/Documentation/iio/ad7606.rst
@@ -0,0 +1,145 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+=============
+AD7606 driver
+=============
+
+ADC driver for Analog Devices Inc. AD7606 and similar devices. The module name
+is ``ad7606``.
+
+Supported devices
+=================
+
+The following chips are supported by this driver:
+
+* `AD7605 <https://www.analog.com/en/products/ad7605.html>`_
+* `AD7606 <https://www.analog.com/en/products/ad7606.html>`_
+* `AD7606B <https://www.analog.com/en/products/ad7606b.html>`_
+* `AD7616 <https://www.analog.com/en/products/ad7616.html>`_
+
+Supported features
+==================
+
+SPI wiring modes
+----------------
+
+These ADCs can output data on several SDO lines (1/2/4/8). The driver
+currently supports only 1 SDO line.
+
+Parallel wiring mode
+--------------------
+
+There is also a parallel interface, with 16 lines (that can be reduced to 8 in
+byte mode). The parallel interface is selected by declaring the device as
+platform in the device tree (with no io-backends node defined, see below).
+
+IIO-backend mode
+----------------
+
+This mode allows to reach the best sample rates, but it requires an external
+hardware (eg HDL or APU) to handle the low level communication.
+The backend mode is enabled when through the definition of the "io-backends"
+property in the device tree.
+
+The reference configuration for the current implementation of IIO-backend mode
+is the HDL reference provided by ADI:
+https://wiki.analog.com/resources/eval/user-guides/ad7606x-fmc/hdl
+
+This implementation embeds an IIO-backend compatible IP (adi-axi-adc) and a PWM
+connected to the conversion trigger pin.
+
+.. code-block::
+
+ +---+ +----------------------------
+ | | +-------+ |AD76xx
+ | A | controls | | |
+ | D |-------------->| PWM |-------------->| cnvst
+ | 7 | | | |
+ | 6 | +-------+ |
+ | 0 | controls +-----------+-----------+ |
+ | 6 |---------->| | |<--| frstdata
+ | | | Backend | Backend |<--| busy
+ | D | | Driver | | |
+ | R | | | |-->| clk
+ | I | requests |+---------+| DMA | |
+ | V |----------->| Buffer ||<---- |<=>| DATA
+ | E | |+---------+| | |
+ | R | +-----------+-----------+ |
+ | |-------------------------------------->| reset/configuration gpios
+ +---+ +-----------------------------
+
+
+Software and hardware modes
+---------------------------
+
+While all the AD7606/AD7616 series parts can be configured using GPIOs, some of
+them can be configured using register.
+
+The chips that support software mode have more values available for configuring
+the device, as well as more settings, and allow to control the range and
+calibration per channel.
+
+The following settings are available per channel in software mode:
+ - Scale
+
+Also, there is a broader choice of oversampling ratios in software mode.
+
+Conversion triggering
+---------------------
+
+The conversion can be triggered by two distinct ways:
+
+ - A GPIO is connected to the conversion trigger pin, and this GPIO is controlled
+ by the driver directly. In this configuration, the driver sets back the
+ conversion trigger pin to high as soon as it has read all the conversions.
+
+ - An external source is connected to the conversion trigger pin. In the
+ current implementation, it must be a PWM. In this configuration, the driver
+ does not control directly the conversion trigger pin. Instead, it can
+ control the PWM's frequency. This trigger is enabled only for iio-backend.
+
+Reference voltage
+-----------------
+
+2 possible reference voltage sources are supported:
+
+ - Internal reference (2.5V)
+ - External reference (2.5V)
+
+The source is determined by the device tree. If ``refin-supply`` is present,
+then the external reference is used, otherwise the internal reference is used.
+
+Oversampling
+------------
+
+This family supports oversampling to improve SNR.
+In software mode, the following ratios are available:
+1 (oversampling disabled)/2/4/8/16/32/64/128/256.
+
+Unimplemented features
+----------------------
+
+- 2/4/8 SDO lines
+- CRC indication
+- Calibration
+
+Device buffers
+==============
+
+IIO triggered buffer
+--------------------
+
+This driver supports IIO triggered buffers, with a "built in" trigger, i.e the
+trigger is allocated and linked by the driver, and a new conversion is triggered
+as soon as the samples are transferred, and a timestamp channel is added to make
+up for the potential jitter induced by the delays in the interrupt handling.
+
+IIO backend buffer
+------------------
+
+When IIO backend is used, the trigger is not needed, and the sample rate is
+considered as stable. There is no timestamp channel. The communication is
+delegated to an external logic, called a backend, and the backend's driver
+handles the buffer. When this mode is enabled, the driver cannot control the
+conversion pin, because the busy pin is bound to the backend.
+
diff --git a/Documentation/iio/index.rst b/Documentation/iio/index.rst
index dfcf9618568a..88bc36326b74 100644
--- a/Documentation/iio/index.rst
+++ b/Documentation/iio/index.rst
@@ -21,6 +21,7 @@ Industrial I/O Kernel Drivers
ad4000
ad4695
ad7380
+ ad7606
ad7944
adis16475
adis16480
diff --git a/MAINTAINERS b/MAINTAINERS
index 6011af70c12e..e5e52cfd5fe1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1561,6 +1561,7 @@ F: Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4350
F: Documentation/devicetree/bindings/iio/*/adi,*
F: Documentation/devicetree/bindings/iio/adc/lltc,ltc2496.yaml
F: Documentation/devicetree/bindings/iio/adc/lltc,ltc2497.yaml
+F: Documentation/iio/ad7606.rst
F: drivers/iio/*/ad*
F: drivers/iio/adc/ltc249*
F: drivers/iio/amplifiers/hmc425a.c
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 4/8] iio: adc: ad7606: Add PWM support for conversion trigger
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
` (2 preceding siblings ...)
2024-10-09 9:19 ` [PATCH v4 3/8] Documentation: iio: Document ad7606 driver Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 14:29 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes Guillaume Stols
` (3 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
Until now, the conversion were triggered by setting high the GPIO
connected to the convst pin. This commit gives the possibility to
connect the convst pin to a PWM.
Connecting a PWM allows to have a better control on the samplerate,
but it must be handled with care, as it is completely decorrelated of
the driver's busy pin handling.
Hence it is not recommended to be used "as is" but must be exploited
in conjunction with IIO backend, and for now only a mock functionality
is enabled, i.e PWM never swings, but is used as a GPIO, i.e duty_cycle
== period equals high state, duty_cycle == 0 equals low state.
This mock functionality will be disabled after the IIO backend usecase
is introduced.
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
drivers/iio/adc/ad7606.c | 143 +++++++++++++++++++++++++++++++++++++++++++----
drivers/iio/adc/ad7606.h | 2 +
2 files changed, 135 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index 71362eafe838..5b276d087ec3 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -13,10 +13,12 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/property.h>
+#include <linux/pwm.h>
#include <linux/regulator/consumer.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
+#include <linux/units.h>
#include <linux/util_macros.h>
#include <linux/iio/buffer.h>
@@ -299,6 +301,82 @@ static int ad7606_reg_access(struct iio_dev *indio_dev,
}
}
+static int ad7606_pwm_set_high(struct ad7606_state *st)
+{
+ struct pwm_state cnvst_pwm_state;
+ int ret;
+
+ if (!st->cnvst_pwm)
+ return -EINVAL;
+
+ pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
+ cnvst_pwm_state.enabled = true;
+ cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period;
+
+ ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
+ /* sleep 2 µS to let finish the current pulse */
+ fsleep(2);
+
+ return ret;
+}
+
+static int ad7606_pwm_set_low(struct ad7606_state *st)
+{
+ struct pwm_state cnvst_pwm_state;
+ int ret;
+
+ if (!st->cnvst_pwm)
+ return -EINVAL;
+
+ pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
+ cnvst_pwm_state.enabled = true;
+ cnvst_pwm_state.duty_cycle = 0;
+
+ ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
+ /* sleep 2 µS to let finish the current pulse */
+ fsleep(2);
+
+ return ret;
+}
+
+static bool ad7606_pwm_is_swinging(struct ad7606_state *st)
+{
+ struct pwm_state cnvst_pwm_state;
+
+ if (!st->cnvst_pwm)
+ return false;
+
+ pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
+
+ return cnvst_pwm_state.duty_cycle != cnvst_pwm_state.period &&
+ cnvst_pwm_state.duty_cycle != 0;
+}
+
+static int ad7606_set_sampling_freq(struct ad7606_state *st, unsigned long freq)
+{
+ struct pwm_state cnvst_pwm_state;
+ bool is_swinging = ad7606_pwm_is_swinging(st);
+ bool is_high;
+
+ if (freq == 0)
+ return -EINVAL;
+
+ /* Retrieve the previous state. */
+ pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
+ is_high = cnvst_pwm_state.duty_cycle == cnvst_pwm_state.period;
+
+ cnvst_pwm_state.period = DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq);
+ cnvst_pwm_state.polarity = PWM_POLARITY_NORMAL;
+ if (is_high)
+ cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period;
+ else if (is_swinging)
+ cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period / 2;
+ else
+ cnvst_pwm_state.duty_cycle = 0;
+
+ return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
+}
+
static int ad7606_read_samples(struct ad7606_state *st)
{
unsigned int num = st->chip_info->num_channels - 1;
@@ -325,6 +403,7 @@ static irqreturn_t ad7606_trigger_handler(int irq, void *p)
iio_trigger_notify_done(indio_dev->trig);
/* The rising edge of the CONVST signal starts a new conversion. */
gpiod_set_value(st->gpio_convst, 1);
+ ad7606_pwm_set_high(st);
return IRQ_HANDLED;
}
@@ -337,7 +416,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch,
const struct iio_chan_spec *chan;
int ret;
- gpiod_set_value(st->gpio_convst, 1);
+ if (st->gpio_convst) {
+ gpiod_set_value(st->gpio_convst, 1);
+ } else {
+ ret = ad7606_pwm_set_high(st);
+ if (ret < 0)
+ return ret;
+ }
ret = wait_for_completion_timeout(&st->completion,
msecs_to_jiffies(1000));
if (!ret) {
@@ -363,6 +448,11 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch,
}
error_ret:
+ if (!st->gpio_convst) {
+ ret = ad7606_pwm_set_low(st);
+ if (ret < 0)
+ return ret;
+ }
gpiod_set_value(st->gpio_convst, 0);
return ret;
@@ -662,8 +752,9 @@ static int ad7606_request_gpios(struct ad7606_state *st)
{
struct device *dev = st->dev;
- st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start",
- GPIOD_OUT_LOW);
+ st->gpio_convst = devm_gpiod_get_optional(dev, "adi,conversion-start",
+ GPIOD_OUT_LOW);
+
if (IS_ERR(st->gpio_convst))
return PTR_ERR(st->gpio_convst);
@@ -708,6 +799,7 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
if (iio_buffer_enabled(indio_dev)) {
gpiod_set_value(st->gpio_convst, 0);
+ ad7606_pwm_set_low(st);
iio_trigger_poll_nested(st->trig);
} else {
complete(&st->completion);
@@ -732,6 +824,7 @@ static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
struct ad7606_state *st = iio_priv(indio_dev);
gpiod_set_value(st->gpio_convst, 1);
+ ad7606_pwm_set_high(st);
return 0;
}
@@ -741,6 +834,7 @@ static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
struct ad7606_state *st = iio_priv(indio_dev);
gpiod_set_value(st->gpio_convst, 0);
+ ad7606_pwm_set_low(st);
return 0;
}
@@ -874,6 +968,11 @@ static int ad7606_chan_scales_setup(struct iio_dev *indio_dev)
return 0;
}
+static void ad7606_pwm_disable(void *data)
+{
+ pwm_disable(data);
+}
+
int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
const char *name, unsigned int id,
const struct ad7606_bus_ops *bops)
@@ -950,6 +1049,31 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
if (ret)
return ret;
+ /* If convst pin is not defined, setup PWM. */
+ if (!st->gpio_convst) {
+ st->cnvst_pwm = devm_pwm_get(dev, NULL);
+ if (IS_ERR(st->cnvst_pwm))
+ return PTR_ERR(st->cnvst_pwm);
+
+ /* The PWM is initialized at 1MHz to have a fast enough GPIO emulation. */
+ ret = ad7606_set_sampling_freq(st, 1 * MEGA);
+ if (ret)
+ return ret;
+
+ ret = ad7606_pwm_set_low(st);
+ if (ret)
+ return ret;
+
+ /*
+ * PWM is not disabled when sampling stops, but instead its duty cycle is set
+ * to 0% to be sure we have a "low" state. After we unload the driver, let's
+ * disable the PWM.
+ */
+ ret = devm_add_action_or_reset(dev, ad7606_pwm_disable,
+ st->cnvst_pwm);
+ if (ret)
+ return ret;
+ }
st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
indio_dev->name,
iio_device_id(indio_dev));
@@ -963,6 +1087,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
return ret;
indio_dev->trig = iio_trigger_get(st->trig);
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+ &iio_pollfunc_store_time,
+ &ad7606_trigger_handler,
+ &ad7606_buffer_ops);
+ if (ret)
+ return ret;
ret = devm_request_threaded_irq(dev, irq,
NULL,
@@ -972,13 +1102,6 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
if (ret)
return ret;
- ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
- &iio_pollfunc_store_time,
- &ad7606_trigger_handler,
- &ad7606_buffer_ops);
- if (ret)
- return ret;
-
return devm_iio_device_register(dev, indio_dev);
}
EXPORT_SYMBOL_NS_GPL(ad7606_probe, IIO_AD7606);
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index fc05a4afa3b8..760cf5e2ecb6 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -115,6 +115,7 @@ struct ad7606_chan_scale {
* @bops bus operations (SPI or parallel)
* @chan_scales scale configuration for channels
* @oversampling oversampling selection
+ * @cnvst_pwm pointer to the PWM device connected to the cnvst pin
* @base_address address from where to read data in parallel operation
* @sw_mode_en software mode enabled
* @oversampling_avail pointer to the array which stores the available
@@ -142,6 +143,7 @@ struct ad7606_state {
const struct ad7606_bus_ops *bops;
struct ad7606_chan_scale chan_scales[AD760X_MAX_CHANNELS];
unsigned int oversampling;
+ struct pwm_device *cnvst_pwm;
void __iomem *base_address;
bool sw_mode_en;
const unsigned int *oversampling_avail;
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
` (3 preceding siblings ...)
2024-10-09 9:19 ` [PATCH v4 4/8] iio: adc: ad7606: Add PWM support for conversion trigger Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 14:39 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 6/8] iio: adc: ad7606: Introduce num_adc_channels Guillaume Stols
` (2 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
On the parallel version, the current implementation is only compatible
with id tables and won't work with fw_nodes, this commit intends to fix
it.
Doing so required to declare ad7606_chip_info structures in the .h file
so to make them accessible to all the driver files that can set a
pointer to the corresponding chip as the driver data.
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
drivers/iio/adc/ad7606.c | 283 ++++++++++++++++++++++++-------------------
drivers/iio/adc/ad7606.h | 32 +++--
drivers/iio/adc/ad7606_par.c | 30 +++--
drivers/iio/adc/ad7606_spi.c | 96 +++++++++------
4 files changed, 254 insertions(+), 187 deletions(-)
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index 5b276d087ec3..dfbdea8c28ba 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -78,6 +78,155 @@ static const unsigned int ad7616_oversampling_avail[8] = {
1, 2, 4, 8, 16, 32, 64, 128,
};
+static const struct iio_chan_spec ad7605_channels[] = {
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ AD7605_CHANNEL(0),
+ AD7605_CHANNEL(1),
+ AD7605_CHANNEL(2),
+ AD7605_CHANNEL(3),
+};
+
+static const struct iio_chan_spec ad7606_channels_16bit[] = {
+ IIO_CHAN_SOFT_TIMESTAMP(8),
+ AD7606_CHANNEL(0, 16),
+ AD7606_CHANNEL(1, 16),
+ AD7606_CHANNEL(2, 16),
+ AD7606_CHANNEL(3, 16),
+ AD7606_CHANNEL(4, 16),
+ AD7606_CHANNEL(5, 16),
+ AD7606_CHANNEL(6, 16),
+ AD7606_CHANNEL(7, 16),
+};
+
+static const struct iio_chan_spec ad7606_channels_18bit[] = {
+ IIO_CHAN_SOFT_TIMESTAMP(8),
+ AD7606_CHANNEL(0, 18),
+ AD7606_CHANNEL(1, 18),
+ AD7606_CHANNEL(2, 18),
+ AD7606_CHANNEL(3, 18),
+ AD7606_CHANNEL(4, 18),
+ AD7606_CHANNEL(5, 18),
+ AD7606_CHANNEL(6, 18),
+ AD7606_CHANNEL(7, 18),
+};
+
+/*
+ * The current assumption that this driver makes for AD7616, is that it's
+ * working in Hardware Mode with Serial, Burst and Sequencer modes activated.
+ * To activate them, following pins must be pulled high:
+ * -SER/PAR
+ * -SEQEN
+ * And following pins must be pulled low:
+ * -WR/BURST
+ * -DB4/SER1W
+ */
+static const struct iio_chan_spec ad7616_channels[] = {
+ IIO_CHAN_SOFT_TIMESTAMP(16),
+ AD7606_CHANNEL(0, 16),
+ AD7606_CHANNEL(1, 16),
+ AD7606_CHANNEL(2, 16),
+ AD7606_CHANNEL(3, 16),
+ AD7606_CHANNEL(4, 16),
+ AD7606_CHANNEL(5, 16),
+ AD7606_CHANNEL(6, 16),
+ AD7606_CHANNEL(7, 16),
+ AD7606_CHANNEL(8, 16),
+ AD7606_CHANNEL(9, 16),
+ AD7606_CHANNEL(10, 16),
+ AD7606_CHANNEL(11, 16),
+ AD7606_CHANNEL(12, 16),
+ AD7606_CHANNEL(13, 16),
+ AD7606_CHANNEL(14, 16),
+ AD7606_CHANNEL(15, 16),
+};
+
+static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
+ struct iio_chan_spec *chan, int ch);
+static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
+ struct iio_chan_spec *chan, int ch);
+static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
+ struct iio_chan_spec *chan, int ch);
+
+const struct ad7606_chip_info ad7605_4_info = {
+ .channels = ad7605_channels,
+ .name = "ad7605-4",
+ .num_channels = 5,
+ .scale_setup_cb = ad7606_16bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7605_4_info, IIO_AD7606);
+
+const struct ad7606_chip_info ad7606_8_info = {
+ .channels = ad7606_channels_16bit,
+ .name = "ad7606-8",
+ .num_channels = 9,
+ .oversampling_avail = ad7606_oversampling_avail,
+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
+ .scale_setup_cb = ad7606_16bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7606_8_info, IIO_AD7606);
+
+const struct ad7606_chip_info ad7606_6_info = {
+ .channels = ad7606_channels_16bit,
+ .name = "ad7606-6",
+ .num_channels = 7,
+ .oversampling_avail = ad7606_oversampling_avail,
+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
+ .scale_setup_cb = ad7606_16bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7606_6_info, IIO_AD7606);
+
+const struct ad7606_chip_info ad7606_4_info = {
+ .channels = ad7606_channels_16bit,
+ .name = "ad7606-4",
+ .num_channels = 5,
+ .oversampling_avail = ad7606_oversampling_avail,
+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
+ .scale_setup_cb = ad7606_16bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606);
+
+const struct ad7606_chip_info ad7606b_info = {
+ .channels = ad7606_channels_16bit,
+ .name = "ad7606b",
+ .num_channels = 9,
+ .oversampling_avail = ad7606_oversampling_avail,
+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
+ .scale_setup_cb = ad7606_16bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7606b_info, IIO_AD7606);
+
+const struct ad7606_chip_info ad7606c_16_info = {
+ .channels = ad7606_channels_16bit,
+ .name = "ad7606c16",
+ .num_channels = 9,
+ .oversampling_avail = ad7606_oversampling_avail,
+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
+ .scale_setup_cb = ad7606c_16bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606);
+
+const struct ad7606_chip_info ad7606c_18_info = {
+ .channels = ad7606_channels_18bit,
+ .name = "ad7606c18",
+ .num_channels = 9,
+ .oversampling_avail = ad7606_oversampling_avail,
+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
+ .scale_setup_cb = ad7606c_18bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7606c_18_info, IIO_AD7606);
+
+const struct ad7606_chip_info ad7616_info = {
+ .channels = ad7616_channels,
+ .init_delay_ms = 15,
+ .name = "ad7616",
+ .num_channels = 17,
+ .oversampling_avail = ad7616_oversampling_avail,
+ .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
+ .os_req_reset = true,
+ .scale_setup_cb = ad7606_16bit_chan_scale_setup,
+};
+EXPORT_SYMBOL_NS_GPL(ad7616_info, IIO_AD7606);
+
int ad7606_reset(struct ad7606_state *st)
{
if (st->gpio_reset) {
@@ -626,128 +775,6 @@ static const struct attribute_group ad7606_attribute_group_range = {
.attrs = ad7606_attributes_range,
};
-static const struct iio_chan_spec ad7605_channels[] = {
- IIO_CHAN_SOFT_TIMESTAMP(4),
- AD7605_CHANNEL(0),
- AD7605_CHANNEL(1),
- AD7605_CHANNEL(2),
- AD7605_CHANNEL(3),
-};
-
-static const struct iio_chan_spec ad7606_channels_16bit[] = {
- IIO_CHAN_SOFT_TIMESTAMP(8),
- AD7606_CHANNEL(0, 16),
- AD7606_CHANNEL(1, 16),
- AD7606_CHANNEL(2, 16),
- AD7606_CHANNEL(3, 16),
- AD7606_CHANNEL(4, 16),
- AD7606_CHANNEL(5, 16),
- AD7606_CHANNEL(6, 16),
- AD7606_CHANNEL(7, 16),
-};
-
-static const struct iio_chan_spec ad7606_channels_18bit[] = {
- IIO_CHAN_SOFT_TIMESTAMP(8),
- AD7606_CHANNEL(0, 18),
- AD7606_CHANNEL(1, 18),
- AD7606_CHANNEL(2, 18),
- AD7606_CHANNEL(3, 18),
- AD7606_CHANNEL(4, 18),
- AD7606_CHANNEL(5, 18),
- AD7606_CHANNEL(6, 18),
- AD7606_CHANNEL(7, 18),
-};
-
-/*
- * The current assumption that this driver makes for AD7616, is that it's
- * working in Hardware Mode with Serial, Burst and Sequencer modes activated.
- * To activate them, following pins must be pulled high:
- * -SER/PAR
- * -SEQEN
- * And following pins must be pulled low:
- * -WR/BURST
- * -DB4/SER1W
- */
-static const struct iio_chan_spec ad7616_channels[] = {
- IIO_CHAN_SOFT_TIMESTAMP(16),
- AD7606_CHANNEL(0, 16),
- AD7606_CHANNEL(1, 16),
- AD7606_CHANNEL(2, 16),
- AD7606_CHANNEL(3, 16),
- AD7606_CHANNEL(4, 16),
- AD7606_CHANNEL(5, 16),
- AD7606_CHANNEL(6, 16),
- AD7606_CHANNEL(7, 16),
- AD7606_CHANNEL(8, 16),
- AD7606_CHANNEL(9, 16),
- AD7606_CHANNEL(10, 16),
- AD7606_CHANNEL(11, 16),
- AD7606_CHANNEL(12, 16),
- AD7606_CHANNEL(13, 16),
- AD7606_CHANNEL(14, 16),
- AD7606_CHANNEL(15, 16),
-};
-
-static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
- /* More devices added in future */
- [ID_AD7605_4] = {
- .channels = ad7605_channels,
- .num_channels = 5,
- .scale_setup_cb = ad7606_16bit_chan_scale_setup,
- },
- [ID_AD7606_8] = {
- .channels = ad7606_channels_16bit,
- .num_channels = 9,
- .scale_setup_cb = ad7606_16bit_chan_scale_setup,
- .oversampling_avail = ad7606_oversampling_avail,
- .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
- },
- [ID_AD7606_6] = {
- .channels = ad7606_channels_16bit,
- .num_channels = 7,
- .scale_setup_cb = ad7606_16bit_chan_scale_setup,
- .oversampling_avail = ad7606_oversampling_avail,
- .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
- },
- [ID_AD7606_4] = {
- .channels = ad7606_channels_16bit,
- .num_channels = 5,
- .scale_setup_cb = ad7606_16bit_chan_scale_setup,
- .oversampling_avail = ad7606_oversampling_avail,
- .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
- },
- [ID_AD7606B] = {
- .channels = ad7606_channels_16bit,
- .num_channels = 9,
- .scale_setup_cb = ad7606_16bit_chan_scale_setup,
- .oversampling_avail = ad7606_oversampling_avail,
- .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
- },
- [ID_AD7606C_16] = {
- .channels = ad7606_channels_16bit,
- .num_channels = 9,
- .scale_setup_cb = ad7606c_16bit_chan_scale_setup,
- .oversampling_avail = ad7606_oversampling_avail,
- .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
- },
- [ID_AD7606C_18] = {
- .channels = ad7606_channels_18bit,
- .num_channels = 9,
- .scale_setup_cb = ad7606c_18bit_chan_scale_setup,
- .oversampling_avail = ad7606_oversampling_avail,
- .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
- },
- [ID_AD7616] = {
- .channels = ad7616_channels,
- .num_channels = 17,
- .scale_setup_cb = ad7606_16bit_chan_scale_setup,
- .oversampling_avail = ad7616_oversampling_avail,
- .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
- .os_req_reset = true,
- .init_delay_ms = 15,
- },
-};
-
static int ad7606_request_gpios(struct ad7606_state *st)
{
struct device *dev = st->dev;
@@ -913,7 +940,7 @@ static const struct iio_trigger_ops ad7606_trigger_ops = {
.validate_device = iio_trigger_validate_own_device,
};
-static int ad7606_sw_mode_setup(struct iio_dev *indio_dev, unsigned int id)
+static int ad7606_sw_mode_setup(struct iio_dev *indio_dev)
{
struct ad7606_state *st = iio_priv(indio_dev);
@@ -974,7 +1001,7 @@ static void ad7606_pwm_disable(void *data)
}
int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
- const char *name, unsigned int id,
+ const struct ad7606_chip_info *chip_info,
const struct ad7606_bus_ops *bops)
{
struct ad7606_state *st;
@@ -999,7 +1026,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
return dev_err_probe(dev, ret,
"Failed to enable specified AVcc supply\n");
- st->chip_info = &ad7606_chip_info_tbl[id];
+ st->chip_info = chip_info;
if (st->chip_info->oversampling_num) {
st->oversampling_avail = st->chip_info->oversampling_avail;
@@ -1022,7 +1049,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
indio_dev->info = &ad7606_info_no_os_or_range;
}
indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->name = name;
+ indio_dev->name = chip_info->name;
indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = st->chip_info->num_channels;
@@ -1041,7 +1068,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
st->write_scale = ad7606_write_scale_hw;
st->write_os = ad7606_write_os_hw;
- ret = ad7606_sw_mode_setup(indio_dev, id);
+ ret = ad7606_sw_mode_setup(indio_dev);
if (ret)
return ret;
@@ -1098,7 +1125,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
NULL,
&ad7606_interrupt,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
- name, indio_dev);
+ chip_info->name, indio_dev);
if (ret)
return ret;
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index 760cf5e2ecb6..d401d3ab37e0 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -69,6 +69,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
/**
* struct ad7606_chip_info - chip specific information
* @channels: channel specification
+ * @name device name
* @num_channels: number of channels
* @scale_setup_cb: callback to setup the scales for each channel
* @oversampling_avail pointer to the array which stores the available
@@ -80,6 +81,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
*/
struct ad7606_chip_info {
const struct iio_chan_spec *channels;
+ const char *name;
unsigned int num_channels;
ad7606_scale_setup_cb_t scale_setup_cb;
const unsigned int *oversampling_avail;
@@ -199,22 +201,30 @@ struct ad7606_bus_ops {
u16 (*rd_wr_cmd)(int addr, char isWriteOp);
};
+/**
+ * struct ad7606_bus_info - agregate ad7606_chip_info and ad7606_bus_ops
+ * @chip_info entry in the table of chips that describes this device
+ * @bops bus operations (SPI or parallel)
+ */
+struct ad7606_bus_info {
+ const struct ad7606_chip_info *chip_info;
+ const struct ad7606_bus_ops *bops;
+};
+
int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
- const char *name, unsigned int id,
+ const struct ad7606_chip_info *info,
const struct ad7606_bus_ops *bops);
int ad7606_reset(struct ad7606_state *st);
-enum ad7606_supported_device_ids {
- ID_AD7605_4,
- ID_AD7606_8,
- ID_AD7606_6,
- ID_AD7606_4,
- ID_AD7606B,
- ID_AD7606C_16,
- ID_AD7606C_18,
- ID_AD7616,
-};
+extern const struct ad7606_chip_info ad7605_4_info;
+extern const struct ad7606_chip_info ad7606_8_info;
+extern const struct ad7606_chip_info ad7606_6_info;
+extern const struct ad7606_chip_info ad7606_4_info;
+extern const struct ad7606_chip_info ad7606b_info;
+extern const struct ad7606_chip_info ad7606c_16_info;
+extern const struct ad7606_chip_info ad7606c_18_info;
+extern const struct ad7606_chip_info ad7616_info;
#ifdef CONFIG_PM_SLEEP
extern const struct dev_pm_ops ad7606_pm_ops;
diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
index d651639c45eb..b87be2f1ca04 100644
--- a/drivers/iio/adc/ad7606_par.c
+++ b/drivers/iio/adc/ad7606_par.c
@@ -11,6 +11,7 @@
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/types.h>
#include <linux/iio/iio.h>
@@ -89,12 +90,20 @@ static const struct ad7606_bus_ops ad7606_par8_bops = {
static int ad7606_par_probe(struct platform_device *pdev)
{
- const struct platform_device_id *id = platform_get_device_id(pdev);
+ const struct ad7606_chip_info *chip_info;
+ const struct platform_device_id *id;
struct resource *res;
void __iomem *addr;
resource_size_t remap_size;
int irq;
+ if (dev_fwnode(&pdev->dev)) {
+ chip_info = device_get_match_data(&pdev->dev);
+ } else {
+ id = platform_get_device_id(pdev);
+ chip_info = (const struct ad7606_chip_info *)id->driver_data;
+ }
+
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
@@ -105,26 +114,25 @@ static int ad7606_par_probe(struct platform_device *pdev)
remap_size = resource_size(res);
- return ad7606_probe(&pdev->dev, irq, addr,
- id->name, id->driver_data,
+ return ad7606_probe(&pdev->dev, irq, addr, chip_info,
remap_size > 1 ? &ad7606_par16_bops :
&ad7606_par8_bops);
}
static const struct platform_device_id ad7606_driver_ids[] = {
- { .name = "ad7605-4", .driver_data = ID_AD7605_4, },
- { .name = "ad7606-4", .driver_data = ID_AD7606_4, },
- { .name = "ad7606-6", .driver_data = ID_AD7606_6, },
- { .name = "ad7606-8", .driver_data = ID_AD7606_8, },
+ { .name = "ad7605-4", .driver_data = (kernel_ulong_t)&ad7605_4_info, },
+ { .name = "ad7606-4", .driver_data = (kernel_ulong_t)&ad7606_4_info, },
+ { .name = "ad7606-6", .driver_data = (kernel_ulong_t)&ad7606_6_info, },
+ { .name = "ad7606-8", .driver_data = (kernel_ulong_t)&ad7606_8_info, },
{ }
};
MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
static const struct of_device_id ad7606_of_match[] = {
- { .compatible = "adi,ad7605-4" },
- { .compatible = "adi,ad7606-4" },
- { .compatible = "adi,ad7606-6" },
- { .compatible = "adi,ad7606-8" },
+ { .compatible = "adi,ad7605-4", .data = &ad7605_4_info },
+ { .compatible = "adi,ad7606-4", .data = &ad7606_4_info },
+ { .compatible = "adi,ad7606-6", .data = &ad7606_6_info },
+ { .compatible = "adi,ad7606-8", .data = &ad7606_8_info },
{ }
};
MODULE_DEVICE_TABLE(of, ad7606_of_match);
diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
index d12e55123888..44c6031e9e9a 100644
--- a/drivers/iio/adc/ad7606_spi.c
+++ b/drivers/iio/adc/ad7606_spi.c
@@ -334,7 +334,7 @@ static const struct ad7606_bus_ops ad7616_spi_bops = {
.sw_mode_config = ad7616_sw_mode_config,
};
-static const struct ad7606_bus_ops ad7606B_spi_bops = {
+static const struct ad7606_bus_ops ad7606b_spi_bops = {
.read_block = ad7606_spi_read_block,
.reg_read = ad7606_spi_reg_read,
.reg_write = ad7606_spi_reg_write,
@@ -352,54 +352,76 @@ static const struct ad7606_bus_ops ad7606c_18_spi_bops = {
.sw_mode_config = ad7606c_18_sw_mode_config,
};
+static const struct ad7606_bus_info ad7605_4_bus_info = {
+ .chip_info = &ad7605_4_info,
+ .bops = &ad7606_spi_bops,
+};
+
+static const struct ad7606_bus_info ad7606_8_bus_info = {
+ .chip_info = &ad7606_8_info,
+ .bops = &ad7606_spi_bops,
+};
+
+static const struct ad7606_bus_info ad7606_6_bus_info = {
+ .chip_info = &ad7606_6_info,
+ .bops = &ad7606_spi_bops,
+};
+
+static const struct ad7606_bus_info ad7606_4_bus_info = {
+ .chip_info = &ad7606_4_info,
+ .bops = &ad7606_spi_bops,
+};
+
+static const struct ad7606_bus_info ad7606b_bus_info = {
+ .chip_info = &ad7606b_info,
+ .bops = &ad7606b_spi_bops,
+};
+
+static const struct ad7606_bus_info ad7606c_16_bus_info = {
+ .chip_info = &ad7606c_16_info,
+ .bops = &ad7606b_spi_bops,
+};
+
+static const struct ad7606_bus_info ad7606c_18_bus_info = {
+ .chip_info = &ad7606c_18_info,
+ .bops = &ad7606c_18_spi_bops,
+};
+
+static const struct ad7606_bus_info ad7616_bus_info = {
+ .chip_info = &ad7616_info,
+ .bops = &ad7616_spi_bops,
+};
+
static int ad7606_spi_probe(struct spi_device *spi)
{
- const struct spi_device_id *id = spi_get_device_id(spi);
- const struct ad7606_bus_ops *bops;
-
- switch (id->driver_data) {
- case ID_AD7616:
- bops = &ad7616_spi_bops;
- break;
- case ID_AD7606B:
- case ID_AD7606C_16:
- bops = &ad7606B_spi_bops;
- break;
- case ID_AD7606C_18:
- bops = &ad7606c_18_spi_bops;
- break;
- default:
- bops = &ad7606_spi_bops;
- break;
- }
+ const struct ad7606_bus_info *bus_info = spi_get_device_match_data(spi);
return ad7606_probe(&spi->dev, spi->irq, NULL,
- id->name, id->driver_data,
- bops);
+ bus_info->chip_info, bus_info->bops);
}
static const struct spi_device_id ad7606_id_table[] = {
- { "ad7605-4", ID_AD7605_4 },
- { "ad7606-4", ID_AD7606_4 },
- { "ad7606-6", ID_AD7606_6 },
- { "ad7606-8", ID_AD7606_8 },
- { "ad7606b", ID_AD7606B },
- { "ad7606c-16", ID_AD7606C_16 },
- { "ad7606c-18", ID_AD7606C_18 },
- { "ad7616", ID_AD7616 },
+ { "ad7605-4", (kernel_ulong_t)&ad7605_4_bus_info },
+ { "ad7606-4", (kernel_ulong_t)&ad7606_4_bus_info },
+ { "ad7606-6", (kernel_ulong_t)&ad7606_6_bus_info },
+ { "ad7606-8", (kernel_ulong_t)&ad7606_8_bus_info },
+ { "ad7606b", (kernel_ulong_t)&ad7606b_bus_info },
+ { "ad7606c-16", (kernel_ulong_t)&ad7606c_16_bus_info },
+ { "ad7606c-18", (kernel_ulong_t)&ad7606c_18_bus_info },
+ { "ad7616", (kernel_ulong_t)&ad7616_bus_info },
{ }
};
MODULE_DEVICE_TABLE(spi, ad7606_id_table);
static const struct of_device_id ad7606_of_match[] = {
- { .compatible = "adi,ad7605-4" },
- { .compatible = "adi,ad7606-4" },
- { .compatible = "adi,ad7606-6" },
- { .compatible = "adi,ad7606-8" },
- { .compatible = "adi,ad7606b" },
- { .compatible = "adi,ad7606c-16" },
- { .compatible = "adi,ad7606c-18" },
- { .compatible = "adi,ad7616" },
+ { .compatible = "adi,ad7605-4", .data = &ad7605_4_bus_info },
+ { .compatible = "adi,ad7606-4", .data = &ad7606_4_bus_info },
+ { .compatible = "adi,ad7606-6", .data = &ad7606_6_bus_info },
+ { .compatible = "adi,ad7606-8", .data = &ad7606_8_bus_info },
+ { .compatible = "adi,ad7606b", .data = &ad7606b_bus_info },
+ { .compatible = "adi,ad7606c-16", .data = &ad7606c_16_bus_info },
+ { .compatible = "adi,ad7606c-18", .data = &ad7606c_18_bus_info },
+ { .compatible = "adi,ad7616", .data = &ad7616_bus_info },
{ }
};
MODULE_DEVICE_TABLE(of, ad7606_of_match);
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 6/8] iio: adc: ad7606: Introduce num_adc_channels
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
` (4 preceding siblings ...)
2024-10-09 9:19 ` [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 14:40 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 7/8] iio: adc: ad7606: Add iio-backend support Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version Guillaume Stols
7 siblings, 1 reply; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
This variable determines how many hardware channels has the chip,
oppositely to the num_channels that can contain more channels, e.g a
timestamp channel in our case. Introducing this variable avoids
decreasing the former num_channels variable when reading the ADC's
channels, and clarifies a bit the code.
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
drivers/iio/adc/ad7606.c | 10 +++++++++-
drivers/iio/adc/ad7606.h | 2 ++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index dfbdea8c28ba..ec902b268388 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -150,6 +150,7 @@ static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
const struct ad7606_chip_info ad7605_4_info = {
.channels = ad7605_channels,
.name = "ad7605-4",
+ .num_adc_channels = 4,
.num_channels = 5,
.scale_setup_cb = ad7606_16bit_chan_scale_setup,
};
@@ -158,6 +159,7 @@ EXPORT_SYMBOL_NS_GPL(ad7605_4_info, IIO_AD7606);
const struct ad7606_chip_info ad7606_8_info = {
.channels = ad7606_channels_16bit,
.name = "ad7606-8",
+ .num_adc_channels = 8,
.num_channels = 9,
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
@@ -168,6 +170,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_8_info, IIO_AD7606);
const struct ad7606_chip_info ad7606_6_info = {
.channels = ad7606_channels_16bit,
.name = "ad7606-6",
+ .num_adc_channels = 6,
.num_channels = 7,
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
@@ -178,6 +181,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_6_info, IIO_AD7606);
const struct ad7606_chip_info ad7606_4_info = {
.channels = ad7606_channels_16bit,
.name = "ad7606-4",
+ .num_adc_channels = 4,
.num_channels = 5,
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
@@ -188,6 +192,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606);
const struct ad7606_chip_info ad7606b_info = {
.channels = ad7606_channels_16bit,
.name = "ad7606b",
+ .num_adc_channels = 8,
.num_channels = 9,
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
@@ -198,6 +203,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606b_info, IIO_AD7606);
const struct ad7606_chip_info ad7606c_16_info = {
.channels = ad7606_channels_16bit,
.name = "ad7606c16",
+ .num_adc_channels = 8,
.num_channels = 9,
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
@@ -208,6 +214,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606);
const struct ad7606_chip_info ad7606c_18_info = {
.channels = ad7606_channels_18bit,
.name = "ad7606c18",
+ .num_adc_channels = 8,
.num_channels = 9,
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
@@ -219,6 +226,7 @@ const struct ad7606_chip_info ad7616_info = {
.channels = ad7616_channels,
.init_delay_ms = 15,
.name = "ad7616",
+ .num_adc_channels = 16,
.num_channels = 17,
.oversampling_avail = ad7616_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
@@ -528,7 +536,7 @@ static int ad7606_set_sampling_freq(struct ad7606_state *st, unsigned long freq)
static int ad7606_read_samples(struct ad7606_state *st)
{
- unsigned int num = st->chip_info->num_channels - 1;
+ unsigned int num = st->chip_info->num_adc_channels;
return st->bops->read_block(st->dev, num, &st->data);
}
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index d401d3ab37e0..b26a11b2eba1 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -71,6 +71,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
* @channels: channel specification
* @name device name
* @num_channels: number of channels
+ * @num_adc_channels the number of channels the ADC actually inputs.
* @scale_setup_cb: callback to setup the scales for each channel
* @oversampling_avail pointer to the array which stores the available
* oversampling ratios.
@@ -82,6 +83,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
struct ad7606_chip_info {
const struct iio_chan_spec *channels;
const char *name;
+ unsigned int num_adc_channels;
unsigned int num_channels;
ad7606_scale_setup_cb_t scale_setup_cb;
const unsigned int *oversampling_avail;
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 7/8] iio: adc: ad7606: Add iio-backend support
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
` (5 preceding siblings ...)
2024-10-09 9:19 ` [PATCH v4 6/8] iio: adc: ad7606: Introduce num_adc_channels Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 14:55 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version Guillaume Stols
7 siblings, 1 reply; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
- Basic support for iio backend.
- Supports IIO_CHAN_INFO_SAMP_FREQ R/W.
- Only hardware mode is available, and that IIO_CHAN_INFO_RAW is not
supported if iio-backend mode is selected.
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
drivers/iio/adc/Kconfig | 2 +
drivers/iio/adc/ad7606.c | 156 ++++++++++++++++++++++++++++++++++---------
drivers/iio/adc/ad7606.h | 15 +++++
drivers/iio/adc/ad7606_par.c | 93 +++++++++++++++++++++++++-
4 files changed, 234 insertions(+), 32 deletions(-)
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 85b82a708c36..9f7e9fc4b1fe 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -224,9 +224,11 @@ config AD7606_IFACE_PARALLEL
tristate "Analog Devices AD7606 ADC driver with parallel interface support"
depends on HAS_IOPORT
select AD7606
+ select IIO_BACKEND
help
Say yes here to build parallel interface support for Analog Devices:
ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
+ It also support iio_backended devices for AD7606B.
To compile this driver as a module, choose M here: the
module will be called ad7606_par.
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index ec902b268388..1313b5cbb0aa 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -21,6 +21,7 @@
#include <linux/units.h>
#include <linux/util_macros.h>
+#include <linux/iio/backend.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -191,6 +192,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606);
const struct ad7606_chip_info ad7606b_info = {
.channels = ad7606_channels_16bit,
+ .max_samplerate = 800 * KILO,
.name = "ad7606b",
.num_adc_channels = 8,
.num_channels = 9,
@@ -496,6 +498,20 @@ static int ad7606_pwm_set_low(struct ad7606_state *st)
return ret;
}
+static int ad7606_pwm_set_swing(struct ad7606_state *st)
+{
+ struct pwm_state cnvst_pwm_state;
+
+ if (!st->cnvst_pwm)
+ return -EINVAL;
+
+ pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
+ cnvst_pwm_state.enabled = true;
+ cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period / 2;
+
+ return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
+}
+
static bool ad7606_pwm_is_swinging(struct ad7606_state *st)
{
struct pwm_state cnvst_pwm_state;
@@ -580,11 +596,22 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch,
if (ret < 0)
return ret;
}
- ret = wait_for_completion_timeout(&st->completion,
- msecs_to_jiffies(1000));
- if (!ret) {
- ret = -ETIMEDOUT;
- goto error_ret;
+
+ /*
+ * If no backend, wait for the interruption on busy pin, otherwise just add
+ * a delay to leave time for the data to be available. For now, the latter
+ * will not happen because IIO_CHAN_INFO_RAW is not supported for the backend.
+ * TODO: Add support for reading a single value when the backend is used.
+ */
+ if (!st->back) {
+ ret = wait_for_completion_timeout(&st->completion,
+ msecs_to_jiffies(1000));
+ if (!ret) {
+ ret = -ETIMEDOUT;
+ goto error_ret;
+ }
+ } else {
+ fsleep(1);
}
ret = ad7606_read_samples(st);
@@ -624,6 +651,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
int ret, ch = 0;
struct ad7606_state *st = iio_priv(indio_dev);
struct ad7606_chan_scale *cs;
+ struct pwm_state cnvst_pwm_state;
switch (m) {
case IIO_CHAN_INFO_RAW:
@@ -644,6 +672,14 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
*val = st->oversampling;
return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SAMP_FREQ:
+ /*
+ * TODO: return the real frequency intead of the requested one once
+ * pwm_get_state_hw comes upstream.
+ */
+ pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
+ *val = DIV_ROUND_CLOSEST_ULL(NSEC_PER_SEC, cnvst_pwm_state.period);
+ return IIO_VAL_INT;
}
return -EINVAL;
}
@@ -736,6 +772,10 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
return ret;
return 0;
+ case IIO_CHAN_INFO_SAMP_FREQ:
+ if (val < 0 && val2 != 0)
+ return -EINVAL;
+ return ad7606_set_sampling_freq(st, val);
default:
return -EINVAL;
}
@@ -905,14 +945,50 @@ static int ad7606_read_avail(struct iio_dev *indio_dev,
return -EINVAL;
}
+static int ad7606_pwm_buffer_postenable(struct iio_dev *indio_dev)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+
+ return ad7606_pwm_set_swing(st);
+}
+
+static int ad7606_pwm_buffer_predisable(struct iio_dev *indio_dev)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+
+ return ad7606_pwm_set_low(st);
+}
+
+static int ad7606_update_scan_mode(struct iio_dev *indio_dev,
+ const unsigned long *scan_mask)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+
+ /*
+ * The update scan mode is only for iio backend compatible drivers.
+ * If the specific update_scan_mode is not defined in the bus ops,
+ * just do nothing and return 0.
+ */
+ if (!st->bops->update_scan_mode)
+ return 0;
+
+ return st->bops->update_scan_mode(indio_dev, scan_mask);
+}
+
static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
.postenable = &ad7606_buffer_postenable,
.predisable = &ad7606_buffer_predisable,
};
+static const struct iio_buffer_setup_ops ad7606_pwm_buffer_ops = {
+ .postenable = &ad7606_pwm_buffer_postenable,
+ .predisable = &ad7606_pwm_buffer_predisable,
+};
+
static const struct iio_info ad7606_info_no_os_or_range = {
.read_raw = &ad7606_read_raw,
.validate_trigger = &ad7606_validate_trigger,
+ .update_scan_mode = &ad7606_update_scan_mode,
};
static const struct iio_info ad7606_info_os_and_range = {
@@ -920,6 +996,7 @@ static const struct iio_info ad7606_info_os_and_range = {
.write_raw = &ad7606_write_raw,
.attrs = &ad7606_attribute_group_os_and_range,
.validate_trigger = &ad7606_validate_trigger,
+ .update_scan_mode = &ad7606_update_scan_mode,
};
static const struct iio_info ad7606_info_sw_mode = {
@@ -928,6 +1005,7 @@ static const struct iio_info ad7606_info_sw_mode = {
.read_avail = &ad7606_read_avail,
.debugfs_reg_access = &ad7606_reg_access,
.validate_trigger = &ad7606_validate_trigger,
+ .update_scan_mode = &ad7606_update_scan_mode,
};
static const struct iio_info ad7606_info_os = {
@@ -935,6 +1013,7 @@ static const struct iio_info ad7606_info_os = {
.write_raw = &ad7606_write_raw,
.attrs = &ad7606_attribute_group_os,
.validate_trigger = &ad7606_validate_trigger,
+ .update_scan_mode = &ad7606_update_scan_mode,
};
static const struct iio_info ad7606_info_range = {
@@ -942,6 +1021,7 @@ static const struct iio_info ad7606_info_range = {
.write_raw = &ad7606_write_raw,
.attrs = &ad7606_attribute_group_range,
.validate_trigger = &ad7606_validate_trigger,
+ .update_scan_mode = &ad7606_update_scan_mode,
};
static const struct iio_trigger_ops ad7606_trigger_ops = {
@@ -1061,8 +1141,6 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = st->chip_info->num_channels;
- init_completion(&st->completion);
-
ret = ad7606_reset(st);
if (ret)
dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
@@ -1109,34 +1187,50 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
if (ret)
return ret;
}
- st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
- indio_dev->name,
- iio_device_id(indio_dev));
- if (!st->trig)
- return -ENOMEM;
- st->trig->ops = &ad7606_trigger_ops;
- iio_trigger_set_drvdata(st->trig, indio_dev);
- ret = devm_iio_trigger_register(dev, st->trig);
- if (ret)
- return ret;
+ if (st->bops->iio_backend_config) {
+ /*
+ * If there is a backend, the PWM should not overpass the maximum sampling
+ * frequency the chip supports.
+ */
+ ret = ad7606_set_sampling_freq(st,
+ chip_info->max_samplerate ? : 2 * KILO);
+ if (ret)
+ return ret;
- indio_dev->trig = iio_trigger_get(st->trig);
- ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
- &iio_pollfunc_store_time,
- &ad7606_trigger_handler,
- &ad7606_buffer_ops);
- if (ret)
- return ret;
+ ret = st->bops->iio_backend_config(dev, indio_dev);
+ if (ret)
+ return ret;
- ret = devm_request_threaded_irq(dev, irq,
- NULL,
- &ad7606_interrupt,
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
- chip_info->name, indio_dev);
- if (ret)
- return ret;
+ indio_dev->setup_ops = &ad7606_pwm_buffer_ops;
+ } else {
+ init_completion(&st->completion);
+ st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
+ indio_dev->name,
+ iio_device_id(indio_dev));
+ if (!st->trig)
+ return -ENOMEM;
+
+ st->trig->ops = &ad7606_trigger_ops;
+ iio_trigger_set_drvdata(st->trig, indio_dev);
+ ret = devm_iio_trigger_register(dev, st->trig);
+ if (ret)
+ return ret;
+
+ indio_dev->trig = iio_trigger_get(st->trig);
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+ &iio_pollfunc_store_time,
+ &ad7606_trigger_handler,
+ &ad7606_buffer_ops);
+ if (ret)
+ return ret;
+ ret = devm_request_threaded_irq(dev, irq, NULL, &ad7606_interrupt,
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ chip_info->name, indio_dev);
+ if (ret)
+ return ret;
+ }
return devm_iio_device_register(dev, indio_dev);
}
EXPORT_SYMBOL_NS_GPL(ad7606_probe, IIO_AD7606);
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index b26a11b2eba1..2c629a15cc33 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -61,6 +61,12 @@
#define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16)
+#define AD7606_BI_CHANNEL(num) \
+ AD760X_CHANNEL(num, 0, \
+ BIT(IIO_CHAN_INFO_SCALE), \
+ BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 16)
+
struct ad7606_state;
typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
@@ -69,6 +75,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
/**
* struct ad7606_chip_info - chip specific information
* @channels: channel specification
+ * @max_samplerate: maximum supported samplerate
* @name device name
* @num_channels: number of channels
* @num_adc_channels the number of channels the ADC actually inputs.
@@ -82,6 +89,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
*/
struct ad7606_chip_info {
const struct iio_chan_spec *channels;
+ unsigned int max_samplerate;
const char *name;
unsigned int num_adc_channels;
unsigned int num_channels;
@@ -152,6 +160,7 @@ struct ad7606_state {
bool sw_mode_en;
const unsigned int *oversampling_avail;
unsigned int num_os_ratios;
+ struct iio_backend *back;
int (*write_scale)(struct iio_dev *indio_dev, int ch, int val);
int (*write_os)(struct iio_dev *indio_dev, int val);
@@ -180,16 +189,21 @@ struct ad7606_state {
/**
* struct ad7606_bus_ops - driver bus operations
+ * @iio_backend_config function pointer for configuring the iio_backend for
+ * the compatibles that use it
* @read_block function pointer for reading blocks of data
* @sw_mode_config: pointer to a function which configured the device
* for software mode
* @reg_read function pointer for reading spi register
* @reg_write function pointer for writing spi register
* @write_mask function pointer for write spi register with mask
+ * @update_scan_mode function pointer for handling the calls to iio_info's update_scan
+ * mode when enabling/disabling channels.
* @rd_wr_cmd pointer to the function which calculates the spi address
*/
struct ad7606_bus_ops {
/* more methods added in future? */
+ int (*iio_backend_config)(struct device *dev, struct iio_dev *indio_dev);
int (*read_block)(struct device *dev, int num, void *data);
int (*sw_mode_config)(struct iio_dev *indio_dev);
int (*reg_read)(struct ad7606_state *st, unsigned int addr);
@@ -200,6 +214,7 @@ struct ad7606_bus_ops {
unsigned int addr,
unsigned long mask,
unsigned int val);
+ int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *scan_mask);
u16 (*rd_wr_cmd)(int addr, char isWriteOp);
};
diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
index b87be2f1ca04..e0de8dc5f731 100644
--- a/drivers/iio/adc/ad7606_par.c
+++ b/drivers/iio/adc/ad7606_par.c
@@ -2,7 +2,8 @@
/*
* AD7606 Parallel Interface ADC driver
*
- * Copyright 2011 Analog Devices Inc.
+ * Copyright 2011 - 2024 Analog Devices Inc.
+ * Copyright 2024 BayLibre SAS.
*/
#include <linux/err.h>
@@ -14,9 +15,82 @@
#include <linux/property.h>
#include <linux/types.h>
+#include <linux/iio/backend.h>
#include <linux/iio/iio.h>
+
#include "ad7606.h"
+static const struct iio_chan_spec ad7606b_bi_channels[] = {
+ AD7606_BI_CHANNEL(0),
+ AD7606_BI_CHANNEL(1),
+ AD7606_BI_CHANNEL(2),
+ AD7606_BI_CHANNEL(3),
+ AD7606_BI_CHANNEL(4),
+ AD7606_BI_CHANNEL(5),
+ AD7606_BI_CHANNEL(6),
+ AD7606_BI_CHANNEL(7),
+};
+
+static int ad7606_bi_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+ unsigned int c, ret;
+
+ for (c = 0; c < indio_dev->num_channels; c++) {
+ if (test_bit(c, scan_mask))
+ ret = iio_backend_chan_enable(st->back, c);
+ else
+ ret = iio_backend_chan_disable(st->back, c);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int ad7606_bi_setup_iio_backend(struct device *dev, struct iio_dev *indio_dev)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+ unsigned int ret, c;
+ struct iio_backend_data_fmt data = {
+ .sign_extend = true,
+ .enable = true,
+ };
+
+ st->back = devm_iio_backend_get(dev, NULL);
+ if (IS_ERR(st->back))
+ return PTR_ERR(st->back);
+
+ /* If the device is iio_backend powered the PWM is mandatory */
+ if (!st->cnvst_pwm)
+ return dev_err_probe(st->dev, -EINVAL,
+ "A PWM is mandatory when using backend.\n");
+
+ ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
+ if (ret)
+ return ret;
+
+ ret = devm_iio_backend_enable(dev, st->back);
+ if (ret)
+ return ret;
+
+ for (c = 0; c < indio_dev->num_channels; c++) {
+ ret = iio_backend_data_format_set(st->back, c, &data);
+ if (ret)
+ return ret;
+ }
+
+ indio_dev->channels = ad7606b_bi_channels;
+ indio_dev->num_channels = 8;
+
+ return 0;
+}
+
+static const struct ad7606_bus_ops ad7606_bi_bops = {
+ .iio_backend_config = ad7606_bi_setup_iio_backend,
+ .update_scan_mode = ad7606_bi_update_scan_mode,
+};
+
static int ad7606_par16_read_block(struct device *dev,
int count, void *buf)
{
@@ -96,9 +170,23 @@ static int ad7606_par_probe(struct platform_device *pdev)
void __iomem *addr;
resource_size_t remap_size;
int irq;
+ struct iio_backend *back;
+ /*
+ * If a firmware node is available (ACPI or DT), platform_device_id is null
+ * and we must use get_match_data.
+ */
if (dev_fwnode(&pdev->dev)) {
chip_info = device_get_match_data(&pdev->dev);
+ back = devm_iio_backend_get(&pdev->dev, NULL);
+ if (!IS_ERR(back))
+ /*
+ * If a backend is available ,call the core probe with backend
+ * bops, otherwise use the former bops.
+ */
+ return ad7606_probe(&pdev->dev, 0, NULL,
+ chip_info,
+ &ad7606_bi_bops);
} else {
id = platform_get_device_id(pdev);
chip_info = (const struct ad7606_chip_info *)id->driver_data;
@@ -124,6 +212,7 @@ static const struct platform_device_id ad7606_driver_ids[] = {
{ .name = "ad7606-4", .driver_data = (kernel_ulong_t)&ad7606_4_info, },
{ .name = "ad7606-6", .driver_data = (kernel_ulong_t)&ad7606_6_info, },
{ .name = "ad7606-8", .driver_data = (kernel_ulong_t)&ad7606_8_info, },
+ { .name = "ad7606b", .driver_data = (kernel_ulong_t)&ad7606b_info, },
{ }
};
MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
@@ -133,6 +222,7 @@ static const struct of_device_id ad7606_of_match[] = {
{ .compatible = "adi,ad7606-4", .data = &ad7606_4_info },
{ .compatible = "adi,ad7606-6", .data = &ad7606_6_info },
{ .compatible = "adi,ad7606-8", .data = &ad7606_8_info },
+ { .compatible = "adi,ad7606b", .data = &ad7606b_info },
{ }
};
MODULE_DEVICE_TABLE(of, ad7606_of_match);
@@ -152,3 +242,4 @@ MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
MODULE_LICENSE("GPL v2");
MODULE_IMPORT_NS(IIO_AD7606);
+MODULE_IMPORT_NS(IIO_BACKEND);
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
` (6 preceding siblings ...)
2024-10-09 9:19 ` [PATCH v4 7/8] iio: adc: ad7606: Add iio-backend support Guillaume Stols
@ 2024-10-09 9:19 ` Guillaume Stols
2024-10-09 14:45 ` Nuno Sá
7 siblings, 1 reply; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 9:19 UTC (permalink / raw)
To: Uwe Kleine-König, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, Michael Hennerich, linux-fbdev,
linux-iio, devicetree, linux-doc, aardelean, dlechner, jstephan,
Jonathan Cameron, Guillaume Stols
Since the pwm was introduced before backend, there was a mock use, with
a GPIO emulation. Now that iio backend is introduced, the mock use can
be removed.
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
---
drivers/iio/adc/ad7606.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index 1313b5cbb0aa..a117206e5256 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -473,8 +473,6 @@ static int ad7606_pwm_set_high(struct ad7606_state *st)
cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period;
ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
- /* sleep 2 µS to let finish the current pulse */
- fsleep(2);
return ret;
}
@@ -492,8 +490,6 @@ static int ad7606_pwm_set_low(struct ad7606_state *st)
cnvst_pwm_state.duty_cycle = 0;
ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
- /* sleep 2 µS to let finish the current pulse */
- fsleep(2);
return ret;
}
@@ -576,7 +572,6 @@ static irqreturn_t ad7606_trigger_handler(int irq, void *p)
iio_trigger_notify_done(indio_dev->trig);
/* The rising edge of the CONVST signal starts a new conversion. */
gpiod_set_value(st->gpio_convst, 1);
- ad7606_pwm_set_high(st);
return IRQ_HANDLED;
}
@@ -899,7 +894,6 @@ static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
struct ad7606_state *st = iio_priv(indio_dev);
gpiod_set_value(st->gpio_convst, 1);
- ad7606_pwm_set_high(st);
return 0;
}
@@ -909,7 +903,6 @@ static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
struct ad7606_state *st = iio_priv(indio_dev);
gpiod_set_value(st->gpio_convst, 0);
- ad7606_pwm_set_low(st);
return 0;
}
@@ -1204,6 +1197,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
indio_dev->setup_ops = &ad7606_pwm_buffer_ops;
} else {
+
+ /* Reserve the PWM use only for backend (force gpio_convst definition) */
+ if (!st->gpio_convst)
+ return dev_err_probe(dev, -EINVAL,
+ "No backend, connect convst to a GPIO");
+
init_completion(&st->completion);
st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
indio_dev->name,
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v4 4/8] iio: adc: ad7606: Add PWM support for conversion trigger
2024-10-09 9:19 ` [PATCH v4 4/8] iio: adc: ad7606: Add PWM support for conversion trigger Guillaume Stols
@ 2024-10-09 14:29 ` Nuno Sá
0 siblings, 0 replies; 17+ messages in thread
From: Nuno Sá @ 2024-10-09 14:29 UTC (permalink / raw)
To: Guillaume Stols, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Greg Kroah-Hartman,
Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, linux-fbdev, linux-iio, devicetree,
linux-doc, aardelean, dlechner, jstephan, Jonathan Cameron
On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
> Until now, the conversion were triggered by setting high the GPIO
> connected to the convst pin. This commit gives the possibility to
> connect the convst pin to a PWM.
> Connecting a PWM allows to have a better control on the samplerate,
> but it must be handled with care, as it is completely decorrelated of
> the driver's busy pin handling.
> Hence it is not recommended to be used "as is" but must be exploited
> in conjunction with IIO backend, and for now only a mock functionality
> is enabled, i.e PWM never swings, but is used as a GPIO, i.e duty_cycle
> == period equals high state, duty_cycle == 0 equals low state.
>
> This mock functionality will be disabled after the IIO backend usecase
> is introduced.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> ---
Hi Guillaume,
Looks overall good, just some minor stuff
> drivers/iio/adc/ad7606.c | 143 +++++++++++++++++++++++++++++++++++++++++++----
> drivers/iio/adc/ad7606.h | 2 +
> 2 files changed, 135 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index 71362eafe838..5b276d087ec3 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -13,10 +13,12 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/property.h>
> +#include <linux/pwm.h>
> #include <linux/regulator/consumer.h>
> #include <linux/sched.h>
> #include <linux/slab.h>
> #include <linux/sysfs.h>
> +#include <linux/units.h>
> #include <linux/util_macros.h>
>
> #include <linux/iio/buffer.h>
> @@ -299,6 +301,82 @@ static int ad7606_reg_access(struct iio_dev *indio_dev,
> }
> }
>
> +static int ad7606_pwm_set_high(struct ad7606_state *st)
> +{
> + struct pwm_state cnvst_pwm_state;
> + int ret;
> +
> + if (!st->cnvst_pwm)
> + return -EINVAL;
> +
Maybe consider doing the check before calling the API (for the cases that need it)?
It seems at least that in a couple of cases you actually already know that the PWM
must be here (since you check for the gpio presence)...
> + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
> + cnvst_pwm_state.enabled = true;
> + cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period;
> +
> + ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
> + /* sleep 2 µS to let finish the current pulse */
> + fsleep(2);
> +
> + return ret;
> +}
> +
> +static int ad7606_pwm_set_low(struct ad7606_state *st)
> +{
> + struct pwm_state cnvst_pwm_state;
> + int ret;
> +
> + if (!st->cnvst_pwm)
> + return -EINVAL;
> +
Same deal...
> + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
> + cnvst_pwm_state.enabled = true;
> + cnvst_pwm_state.duty_cycle = 0;
> +
> + ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
> + /* sleep 2 µS to let finish the current pulse */
> + fsleep(2);
> +
> + return ret;
> +}
> +
> +static bool ad7606_pwm_is_swinging(struct ad7606_state *st)
> +{
> + struct pwm_state cnvst_pwm_state;
> +
> + if (!st->cnvst_pwm)
> + return false;
> +
This one also seems to be redundant? ad7606_set_sampling_freq() should be only called
from a context where the PWM exists right?
> + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
> +
> + return cnvst_pwm_state.duty_cycle != cnvst_pwm_state.period &&
> + cnvst_pwm_state.duty_cycle != 0;
> +}
> +
> +static int ad7606_set_sampling_freq(struct ad7606_state *st, unsigned long freq)
> +{
> + struct pwm_state cnvst_pwm_state;
> + bool is_swinging = ad7606_pwm_is_swinging(st);
> + bool is_high;
> +
> + if (freq == 0)
> + return -EINVAL;
> +
> + /* Retrieve the previous state. */
> + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
> + is_high = cnvst_pwm_state.duty_cycle == cnvst_pwm_state.period;
> +
> + cnvst_pwm_state.period = DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq);
> + cnvst_pwm_state.polarity = PWM_POLARITY_NORMAL;
> + if (is_high)
> + cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period;
> + else if (is_swinging)
> + cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period / 2;
> + else
> + cnvst_pwm_state.duty_cycle = 0;
> +
> + return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
> +}
> +
> static int ad7606_read_samples(struct ad7606_state *st)
> {
> unsigned int num = st->chip_info->num_channels - 1;
> @@ -325,6 +403,7 @@ static irqreturn_t ad7606_trigger_handler(int irq, void *p)
> iio_trigger_notify_done(indio_dev->trig);
> /* The rising edge of the CONVST signal starts a new conversion. */
> gpiod_set_value(st->gpio_convst, 1);
> + ad7606_pwm_set_high(st);
>
> return IRQ_HANDLED;
> }
> @@ -337,7 +416,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev,
> unsigned int ch,
> const struct iio_chan_spec *chan;
> int ret;
>
> - gpiod_set_value(st->gpio_convst, 1);
> + if (st->gpio_convst) {
> + gpiod_set_value(st->gpio_convst, 1);
> + } else {
> + ret = ad7606_pwm_set_high(st);
> + if (ret < 0)
> + return ret;
> + }
> ret = wait_for_completion_timeout(&st->completion,
> msecs_to_jiffies(1000));
> if (!ret) {
> @@ -363,6 +448,11 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev,
> unsigned int ch,
> }
>
> error_ret:
> + if (!st->gpio_convst) {
> + ret = ad7606_pwm_set_low(st);
> + if (ret < 0)
> + return ret;
> + }
> gpiod_set_value(st->gpio_convst, 0);
>
> return ret;
> @@ -662,8 +752,9 @@ static int ad7606_request_gpios(struct ad7606_state *st)
> {
> struct device *dev = st->dev;
>
> - st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start",
> - GPIOD_OUT_LOW);
> + st->gpio_convst = devm_gpiod_get_optional(dev, "adi,conversion-start",
> + GPIOD_OUT_LOW);
> +
> if (IS_ERR(st->gpio_convst))
> return PTR_ERR(st->gpio_convst);
>
> @@ -708,6 +799,7 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
>
> if (iio_buffer_enabled(indio_dev)) {
> gpiod_set_value(st->gpio_convst, 0);
> + ad7606_pwm_set_low(st);
> iio_trigger_poll_nested(st->trig);
> } else {
> complete(&st->completion);
> @@ -732,6 +824,7 @@ static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
> struct ad7606_state *st = iio_priv(indio_dev);
>
> gpiod_set_value(st->gpio_convst, 1);
> + ad7606_pwm_set_high(st);
error handling?
>
> return 0;
> }
> @@ -741,6 +834,7 @@ static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
> struct ad7606_state *st = iio_priv(indio_dev);
>
> gpiod_set_value(st->gpio_convst, 0);
> + ad7606_pwm_set_low(st);
>
error handling?
> return 0;
> }
> @@ -874,6 +968,11 @@ static int ad7606_chan_scales_setup(struct iio_dev *indio_dev)
> return 0;
> }
>
> +static void ad7606_pwm_disable(void *data)
> +{
> + pwm_disable(data);
> +}
> +
> int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
> const char *name, unsigned int id,
> const struct ad7606_bus_ops *bops)
> @@ -950,6 +1049,31 @@ int ad7606_probe(struct device *dev, int irq, void __iomem
> *base_address,
> if (ret)
> return ret;
>
> + /* If convst pin is not defined, setup PWM. */
> + if (!st->gpio_convst) {
> + st->cnvst_pwm = devm_pwm_get(dev, NULL);
> + if (IS_ERR(st->cnvst_pwm))
> + return PTR_ERR(st->cnvst_pwm);
> +
> + /* The PWM is initialized at 1MHz to have a fast enough GPIO
> emulation. */
> + ret = ad7606_set_sampling_freq(st, 1 * MEGA);
> + if (ret)
> + return ret;
> +
> + ret = ad7606_pwm_set_low(st);
> + if (ret)
> + return ret;
> +
> + /*
> + * PWM is not disabled when sampling stops, but instead its duty
> cycle is set
> + * to 0% to be sure we have a "low" state. After we unload the
> driver, let's
> + * disable the PWM.
> + */
> + ret = devm_add_action_or_reset(dev, ad7606_pwm_disable,
> + st->cnvst_pwm);
> + if (ret)
> + return ret;
> + }
> st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> indio_dev->name,
> iio_device_id(indio_dev));
> @@ -963,6 +1087,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem
> *base_address,
> return ret;
>
> indio_dev->trig = iio_trigger_get(st->trig);
> + ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> + &iio_pollfunc_store_time,
> + &ad7606_trigger_handler,
> + &ad7606_buffer_ops);
> + if (ret)
> + return ret;
>
The above change seems unrelated?
- Nuno Sá
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes
2024-10-09 9:19 ` [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes Guillaume Stols
@ 2024-10-09 14:39 ` Nuno Sá
2024-10-09 14:53 ` Guillaume Stols
0 siblings, 1 reply; 17+ messages in thread
From: Nuno Sá @ 2024-10-09 14:39 UTC (permalink / raw)
To: Guillaume Stols, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Greg Kroah-Hartman,
Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, linux-fbdev, linux-iio, devicetree,
linux-doc, aardelean, dlechner, jstephan, Jonathan Cameron
On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
> On the parallel version, the current implementation is only compatible
> with id tables and won't work with fw_nodes, this commit intends to fix
> it.
>
> Doing so required to declare ad7606_chip_info structures in the .h file
> so to make them accessible to all the driver files that can set a
> pointer to the corresponding chip as the driver data.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> ---
> drivers/iio/adc/ad7606.c | 283 ++++++++++++++++++++++++-------------------
> drivers/iio/adc/ad7606.h | 32 +++--
> drivers/iio/adc/ad7606_par.c | 30 +++--
> drivers/iio/adc/ad7606_spi.c | 96 +++++++++------
> 4 files changed, 254 insertions(+), 187 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index 5b276d087ec3..dfbdea8c28ba 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -78,6 +78,155 @@ static const unsigned int ad7616_oversampling_avail[8] = {
>
...
> +const struct ad7606_chip_info ad7616_info = {
> + .channels = ad7616_channels,
> + .init_delay_ms = 15,
> + .name = "ad7616",
> + .num_channels = 17,
> + .oversampling_avail = ad7616_oversampling_avail,
> + .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
> + .os_req_reset = true,
> + .scale_setup_cb = ad7606_16bit_chan_scale_setup,
> +};
> +EXPORT_SYMBOL_NS_GPL(ad7616_info, IIO_AD7606);
>
Maybe my eyes are tricking me but I'm not seeing any MODULE_IMPORT_NS() in the
drivers?
- Nuno Sá
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 6/8] iio: adc: ad7606: Introduce num_adc_channels
2024-10-09 9:19 ` [PATCH v4 6/8] iio: adc: ad7606: Introduce num_adc_channels Guillaume Stols
@ 2024-10-09 14:40 ` Nuno Sá
0 siblings, 0 replies; 17+ messages in thread
From: Nuno Sá @ 2024-10-09 14:40 UTC (permalink / raw)
To: Guillaume Stols, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Greg Kroah-Hartman,
Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, linux-fbdev, linux-iio, devicetree,
linux-doc, aardelean, dlechner, jstephan, Jonathan Cameron
On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
> This variable determines how many hardware channels has the chip,
> oppositely to the num_channels that can contain more channels, e.g a
> timestamp channel in our case. Introducing this variable avoids
> decreasing the former num_channels variable when reading the ADC's
> channels, and clarifies a bit the code.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> ---
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> drivers/iio/adc/ad7606.c | 10 +++++++++-
> drivers/iio/adc/ad7606.h | 2 ++
> 2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index dfbdea8c28ba..ec902b268388 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -150,6 +150,7 @@ static int ad7606_16bit_chan_scale_setup(struct ad7606_state
> *st,
> const struct ad7606_chip_info ad7605_4_info = {
> .channels = ad7605_channels,
> .name = "ad7605-4",
> + .num_adc_channels = 4,
> .num_channels = 5,
> .scale_setup_cb = ad7606_16bit_chan_scale_setup,
> };
> @@ -158,6 +159,7 @@ EXPORT_SYMBOL_NS_GPL(ad7605_4_info, IIO_AD7606);
> const struct ad7606_chip_info ad7606_8_info = {
> .channels = ad7606_channels_16bit,
> .name = "ad7606-8",
> + .num_adc_channels = 8,
> .num_channels = 9,
> .oversampling_avail = ad7606_oversampling_avail,
> .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> @@ -168,6 +170,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_8_info, IIO_AD7606);
> const struct ad7606_chip_info ad7606_6_info = {
> .channels = ad7606_channels_16bit,
> .name = "ad7606-6",
> + .num_adc_channels = 6,
> .num_channels = 7,
> .oversampling_avail = ad7606_oversampling_avail,
> .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> @@ -178,6 +181,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_6_info, IIO_AD7606);
> const struct ad7606_chip_info ad7606_4_info = {
> .channels = ad7606_channels_16bit,
> .name = "ad7606-4",
> + .num_adc_channels = 4,
> .num_channels = 5,
> .oversampling_avail = ad7606_oversampling_avail,
> .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> @@ -188,6 +192,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606);
> const struct ad7606_chip_info ad7606b_info = {
> .channels = ad7606_channels_16bit,
> .name = "ad7606b",
> + .num_adc_channels = 8,
> .num_channels = 9,
> .oversampling_avail = ad7606_oversampling_avail,
> .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> @@ -198,6 +203,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606b_info, IIO_AD7606);
> const struct ad7606_chip_info ad7606c_16_info = {
> .channels = ad7606_channels_16bit,
> .name = "ad7606c16",
> + .num_adc_channels = 8,
> .num_channels = 9,
> .oversampling_avail = ad7606_oversampling_avail,
> .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> @@ -208,6 +214,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606);
> const struct ad7606_chip_info ad7606c_18_info = {
> .channels = ad7606_channels_18bit,
> .name = "ad7606c18",
> + .num_adc_channels = 8,
> .num_channels = 9,
> .oversampling_avail = ad7606_oversampling_avail,
> .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> @@ -219,6 +226,7 @@ const struct ad7606_chip_info ad7616_info = {
> .channels = ad7616_channels,
> .init_delay_ms = 15,
> .name = "ad7616",
> + .num_adc_channels = 16,
> .num_channels = 17,
> .oversampling_avail = ad7616_oversampling_avail,
> .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
> @@ -528,7 +536,7 @@ static int ad7606_set_sampling_freq(struct ad7606_state *st,
> unsigned long freq)
>
> static int ad7606_read_samples(struct ad7606_state *st)
> {
> - unsigned int num = st->chip_info->num_channels - 1;
> + unsigned int num = st->chip_info->num_adc_channels;
>
> return st->bops->read_block(st->dev, num, &st->data);
> }
> diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
> index d401d3ab37e0..b26a11b2eba1 100644
> --- a/drivers/iio/adc/ad7606.h
> +++ b/drivers/iio/adc/ad7606.h
> @@ -71,6 +71,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
> * @channels: channel specification
> * @name device name
> * @num_channels: number of channels
> + * @num_adc_channels the number of channels the ADC actually inputs.
> * @scale_setup_cb: callback to setup the scales for each channel
> * @oversampling_avail pointer to the array which stores the available
> * oversampling ratios.
> @@ -82,6 +83,7 @@ typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
> struct ad7606_chip_info {
> const struct iio_chan_spec *channels;
> const char *name;
> + unsigned int num_adc_channels;
> unsigned int num_channels;
> ad7606_scale_setup_cb_t scale_setup_cb;
> const unsigned int *oversampling_avail;
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version
2024-10-09 9:19 ` [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version Guillaume Stols
@ 2024-10-09 14:45 ` Nuno Sá
2024-10-12 12:48 ` Jonathan Cameron
0 siblings, 1 reply; 17+ messages in thread
From: Nuno Sá @ 2024-10-09 14:45 UTC (permalink / raw)
To: Guillaume Stols, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Greg Kroah-Hartman,
Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, linux-fbdev, linux-iio, devicetree,
linux-doc, aardelean, dlechner, jstephan, Jonathan Cameron
On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
> Since the pwm was introduced before backend, there was a mock use, with
> a GPIO emulation. Now that iio backend is introduced, the mock use can
> be removed.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> ---
Maybe this was agreed on the previous iterations but I wonder if we shouldn't just
bring PWM support in the same patch as backend support is added...
- Nuno Sá
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes
2024-10-09 14:39 ` Nuno Sá
@ 2024-10-09 14:53 ` Guillaume Stols
2024-10-09 14:59 ` Nuno Sá
0 siblings, 1 reply; 17+ messages in thread
From: Guillaume Stols @ 2024-10-09 14:53 UTC (permalink / raw)
To: Nuno Sá, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Greg Kroah-Hartman,
Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, linux-fbdev, linux-iio, devicetree,
linux-doc, aardelean, dlechner, jstephan, Jonathan Cameron
On 10/9/24 16:39, Nuno Sá wrote:
> On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
>> On the parallel version, the current implementation is only compatible
>> with id tables and won't work with fw_nodes, this commit intends to fix
>> it.
>>
>> Doing so required to declare ad7606_chip_info structures in the .h file
>> so to make them accessible to all the driver files that can set a
>> pointer to the corresponding chip as the driver data.
>>
>> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
>> ---
>> drivers/iio/adc/ad7606.c | 283 ++++++++++++++++++++++++-------------------
>> drivers/iio/adc/ad7606.h | 32 +++--
>> drivers/iio/adc/ad7606_par.c | 30 +++--
>> drivers/iio/adc/ad7606_spi.c | 96 +++++++++------
>> 4 files changed, 254 insertions(+), 187 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
>> index 5b276d087ec3..dfbdea8c28ba 100644
>> --- a/drivers/iio/adc/ad7606.c
>> +++ b/drivers/iio/adc/ad7606.c
>> @@ -78,6 +78,155 @@ static const unsigned int ad7616_oversampling_avail[8] = {
>>
> ...
>
>> +const struct ad7606_chip_info ad7616_info = {
>> + .channels = ad7616_channels,
>> + .init_delay_ms = 15,
>> + .name = "ad7616",
>> + .num_channels = 17,
>> + .oversampling_avail = ad7616_oversampling_avail,
>> + .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
>> + .os_req_reset = true,
>> + .scale_setup_cb = ad7606_16bit_chan_scale_setup,
>> +};
>> +EXPORT_SYMBOL_NS_GPL(ad7616_info, IIO_AD7606);
>>
> Maybe my eyes are tricking me but I'm not seeing any MODULE_IMPORT_NS() in the
> drivers?
Hi Nuno,
The ad7606_spi.c and ad7606_par.c use MODULE_IMPORT_NS(IIO_AD7606).
Chip infos are used in the "coupling" structures, e.g:
static const struct ad7606_bus_info ad7616_bus_info = {
.chip_info = &ad7616_info,¬
.bops = &ad7616_spi_bops,¬
};¬
Guillaume
> - Nuno Sá
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 7/8] iio: adc: ad7606: Add iio-backend support
2024-10-09 9:19 ` [PATCH v4 7/8] iio: adc: ad7606: Add iio-backend support Guillaume Stols
@ 2024-10-09 14:55 ` Nuno Sá
0 siblings, 0 replies; 17+ messages in thread
From: Nuno Sá @ 2024-10-09 14:55 UTC (permalink / raw)
To: Guillaume Stols, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Greg Kroah-Hartman,
Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, linux-fbdev, linux-iio, devicetree,
linux-doc, aardelean, dlechner, jstephan, Jonathan Cameron
On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
> - Basic support for iio backend.
> - Supports IIO_CHAN_INFO_SAMP_FREQ R/W.
> - Only hardware mode is available, and that IIO_CHAN_INFO_RAW is not
> supported if iio-backend mode is selected.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> ---
Just minor stuff...
> drivers/iio/adc/Kconfig | 2 +
> drivers/iio/adc/ad7606.c | 156 ++++++++++++++++++++++++++++++++++---------
> drivers/iio/adc/ad7606.h | 15 +++++
> drivers/iio/adc/ad7606_par.c | 93 +++++++++++++++++++++++++-
> 4 files changed, 234 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 85b82a708c36..9f7e9fc4b1fe 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -224,9 +224,11 @@ config AD7606_IFACE_PARALLEL
> tristate "Analog Devices AD7606 ADC driver with parallel interface
> support"
> depends on HAS_IOPORT
> select AD7606
> + select IIO_BACKEND
> help
> Say yes here to build parallel interface support for Analog Devices:
> ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
> + It also support iio_backended devices for AD7606B.
>
> To compile this driver as a module, choose M here: the
> module will be called ad7606_par.
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index ec902b268388..1313b5cbb0aa 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -21,6 +21,7 @@
> #include <linux/units.h>
> #include <linux/util_macros.h>
>
> +#include <linux/iio/backend.h>
> #include <linux/iio/buffer.h>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -191,6 +192,7 @@ EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606);
> const struct ad7606_chip_info ad7606b_info = {
> .channels = ad7606_channels_16bit,
> + .max_samplerate = 800 * KILO,
> .name = "ad7606b",
> .num_adc_channels = 8,
> .num_channels = 9,
> @@ -496,6 +498,20 @@ static int ad7606_pwm_set_low(struct ad7606_state *st)
> return ret;
> }
>
> +static int ad7606_pwm_set_swing(struct ad7606_state *st)
> +{
> + struct pwm_state cnvst_pwm_state;
> +
> + if (!st->cnvst_pwm)
> + return -EINVAL;
> +
Can we get into this function without knowing cnvst_pwm must be present? IOW, do we
really need the above check?
...
> @@ -96,9 +170,23 @@ static int ad7606_par_probe(struct platform_device *pdev)
> void __iomem *addr;
> resource_size_t remap_size;
> int irq;
> + struct iio_backend *back;
>
> + /*
> + * If a firmware node is available (ACPI or DT), platform_device_id is
> null
> + * and we must use get_match_data.
> + */
> if (dev_fwnode(&pdev->dev)) {
> chip_info = device_get_match_data(&pdev->dev);
> + back = devm_iio_backend_get(&pdev->dev, NULL);
Can't we use device_property_present()?
- Nuno Sá
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes
2024-10-09 14:53 ` Guillaume Stols
@ 2024-10-09 14:59 ` Nuno Sá
0 siblings, 0 replies; 17+ messages in thread
From: Nuno Sá @ 2024-10-09 14:59 UTC (permalink / raw)
To: Guillaume Stols, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Greg Kroah-Hartman,
Rafael J. Wysocki, Jonathan Corbet
Cc: linux-pwm, linux-kernel, linux-fbdev, linux-iio, devicetree,
linux-doc, aardelean, dlechner, jstephan, Jonathan Cameron
On Wed, 2024-10-09 at 16:53 +0200, Guillaume Stols wrote:
>
> On 10/9/24 16:39, Nuno Sá wrote:
> > On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
> > > On the parallel version, the current implementation is only compatible
> > > with id tables and won't work with fw_nodes, this commit intends to fix
> > > it.
> > >
> > > Doing so required to declare ad7606_chip_info structures in the .h file
> > > so to make them accessible to all the driver files that can set a
> > > pointer to the corresponding chip as the driver data.
> > >
> > > Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> > > ---
> > > drivers/iio/adc/ad7606.c | 283 ++++++++++++++++++++++++------------------
> > > -
> > > drivers/iio/adc/ad7606.h | 32 +++--
> > > drivers/iio/adc/ad7606_par.c | 30 +++--
> > > drivers/iio/adc/ad7606_spi.c | 96 +++++++++------
> > > 4 files changed, 254 insertions(+), 187 deletions(-)
> > >
> > > diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> > > index 5b276d087ec3..dfbdea8c28ba 100644
> > > --- a/drivers/iio/adc/ad7606.c
> > > +++ b/drivers/iio/adc/ad7606.c
> > > @@ -78,6 +78,155 @@ static const unsigned int ad7616_oversampling_avail[8] = {
> > >
> > ...
> >
> > > +const struct ad7606_chip_info ad7616_info = {
> > > + .channels = ad7616_channels,
> > > + .init_delay_ms = 15,
> > > + .name = "ad7616",
> > > + .num_channels = 17,
> > > + .oversampling_avail = ad7616_oversampling_avail,
> > > + .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
> > > + .os_req_reset = true,
> > > + .scale_setup_cb = ad7606_16bit_chan_scale_setup,
> > > +};
> > > +EXPORT_SYMBOL_NS_GPL(ad7616_info, IIO_AD7606);
> > >
> > Maybe my eyes are tricking me but I'm not seeing any MODULE_IMPORT_NS() in the
> > drivers?
>
> Hi Nuno,
>
> The ad7606_spi.c and ad7606_par.c use MODULE_IMPORT_NS(IIO_AD7606).
>
> Chip infos are used in the "coupling" structures, e.g:
>
> static const struct ad7606_bus_info ad7616_bus_info = {
> .chip_info = &ad7616_info,¬
> .bops = &ad7616_spi_bops,¬
> };¬
>
You were faster than me. I just realized that code is only in the testing branch of
IIO and was going to reply to disregard my comment :).
- Nuno Sá
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version
2024-10-09 14:45 ` Nuno Sá
@ 2024-10-12 12:48 ` Jonathan Cameron
0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2024-10-12 12:48 UTC (permalink / raw)
To: Nuno Sá
Cc: Guillaume Stols, Uwe Kleine-König, Lars-Peter Clausen,
Michael Hennerich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Rafael J. Wysocki, Jonathan Corbet, linux-pwm,
linux-kernel, linux-fbdev, linux-iio, devicetree, linux-doc,
aardelean, dlechner, jstephan, Jonathan Cameron
On Wed, 09 Oct 2024 16:45:40 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:
> On Wed, 2024-10-09 at 09:19 +0000, Guillaume Stols wrote:
> > Since the pwm was introduced before backend, there was a mock use, with
> > a GPIO emulation. Now that iio backend is introduced, the mock use can
> > be removed.
> >
> > Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> > ---
>
> Maybe this was agreed on the previous iterations but I wonder if we shouldn't just
> bring PWM support in the same patch as backend support is added...
>
I can't remember why we ended up in this position (might have been me
who asked for it!) but I'm fine with the logical steps we have in the
series, and it will all merge together. So probably not worth rethinking
now!
I took another look and other than the stuff Nuno has raised this series
looks good to me.
Figures crossed for v5 :)
Jonathan
> - Nuno Sá
>
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2024-10-12 12:48 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 9:19 [PATCH v4 0/8] Add iio backend compatibility for ad7606 Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 1/8] dt-bindings: iio: adc: ad7606: Remove spi-cpha from required Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 2/8] dt-bindings: iio: adc: ad7606: Add iio backend bindings Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 3/8] Documentation: iio: Document ad7606 driver Guillaume Stols
2024-10-09 9:19 ` [PATCH v4 4/8] iio: adc: ad7606: Add PWM support for conversion trigger Guillaume Stols
2024-10-09 14:29 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 5/8] iio: adc: ad7606: Add compatibility to fw_nodes Guillaume Stols
2024-10-09 14:39 ` Nuno Sá
2024-10-09 14:53 ` Guillaume Stols
2024-10-09 14:59 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 6/8] iio: adc: ad7606: Introduce num_adc_channels Guillaume Stols
2024-10-09 14:40 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 7/8] iio: adc: ad7606: Add iio-backend support Guillaume Stols
2024-10-09 14:55 ` Nuno Sá
2024-10-09 9:19 ` [PATCH v4 8/8] iio: adc: ad7606: Disable PWM usage for non backend version Guillaume Stols
2024-10-09 14:45 ` Nuno Sá
2024-10-12 12:48 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).