Extend device support for AD5686 driver #3232
Open
rodrigo455 wants to merge 103 commits intomirror_ci/jic23/iio/testingfrom
Open
Extend device support for AD5686 driver #3232rodrigo455 wants to merge 103 commits intomirror_ci/jic23/iio/testingfrom
rodrigo455 wants to merge 103 commits intomirror_ci/jic23/iio/testingfrom
Conversation
5da2875 to
71cdaf3
Compare
9e516c8 to
9f44ff1
Compare
nunojsa
reviewed
Apr 2, 2026
Collaborator
nunojsa
left a comment
There was a problem hiding this comment.
Looks mostly good! Some things more relevant to change but I would say it's mostly upstream ready.
Thanks for taking care of this and bringing one more driver up to date!
|
|
||
| ret = spi_sync(spi, &bus_data->msg); | ||
| if (ret) | ||
| return ret; |
Collaborator
There was a problem hiding this comment.
nit: new line
I also wonder if this does not need locking?
3469c5e to
4c5c47c
Compare
59be8ec to
58a740e
Compare
8ccfdb1 to
5d18d61
Compare
Check return value of iio_compute_scan_bytes() as it can return an error. The result is moved to an output parameter while we are touching this as we will need to add a second output parameter in a later change. The return type of iio_buffer_update_bytes_per_datum() also had to be changed to propagate the error. Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This series adds support for multiple nanoDAC parts, adding triggered buffer and gain control support to the ad5686 DAC driver family, along with a number of driver cleanups and fixes. Initial patches update the device-tree bindings: - Add compatible entries for missing and new parts; - Add GPIO properties for RESET, GAIN and LDAC pins; - Add missing power supplies properties. Driver cleanups and fixes: - Refactor include headers (IWYU); - Switch to device managed mutex initialization; - Drop enum chip id in favor of per-device chip_info structs; - Fix voltage reference control on single-channel devices; - Fix powerdown control on dual-channel devices; - Introduce bus ops struct with a sync() operation for batching bus transfers. New functionality: - Device support for: AD5316R, AD5675, AD5697R, AD5313R, AD5317R, AD5674, AD5679, AD5687, AD5687R, AD5689 and AD5689R; - Consume optional reset and new power supplies; - LDAC GPIO handling (active-low, held low when unused); - SPI bus sync() implementation for batching multiple transfers; - Triggered buffer support, leveraging LDAC and sync() to flush all channel writes atomically; - Gain control support through the scale property. # Describe the purpose of this series. The information you put here # will be used by the project maintainer to make a decision whether # your patches should be reviewed, and in what priority order. Please be # very detailed and link to any relevant discussions or sites that the # maintainer can review to better understand your proposed changes. If you # only have a single patch in your series, the contents of the cover # letter will be appended to the "under-the-cut" portion of the patch. # Lines starting with # will be removed from the cover letter. You can # use them to add notes or reminders to yourself. If you want to use # markdown headers in your cover letter, start the line with ">#". # You can add trailers to the cover letter. Any email addresses found in # these trailers will be added to the addresses specified/generated # during the b4 send stage. You can also run "b4 prep --auto-to-cc" to # auto-populate the To: and Cc: trailers based on the code being # modified. To: Michael Hennerich <michael.hennerich@analog.com> To: Jonathan Cameron <jic23@kernel.org> To: linux-iio@vger.kernel.org To: devicetree@vger.kernel.org To: linux-kernel@vger.kernel.org To: Michael Auchter <michael.auchter@ni.com> To: linux-hardening@vger.kernel.org Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Michael Hennerich <Michael.Hennerich@analog.com> Cc: David Lechner <dlechner@baylibre.com> Cc: Nuno Sá <nuno.sa@analog.com> Cc: Andy Shevchenko <andy@kernel.org> Cc: Rob Herring <robh@kernel.org> Cc: Krzysztof Kozlowski <krzk+dt@kernel.org> Cc: Conor Dooley <conor+dt@kernel.org> Cc: Kees Cook <kees@kernel.org> Cc: Gustavo A. R. Silva <gustavoars@kernel.org> Cc: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com> --- Changes in v2: - EDITME: describe what is new in this series revision. - EDITME: use bulletpoints and terse descriptions. - Link to v1: https://lore.kernel.org/r/20260422-ad5313r-iio-support-v1-0-ed7dca001d1b@analog.com --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 2, "change-id": "20260325-ad5313r-iio-support-882ad39356e1", "prefixes": [], "history": { "v1": [ "20260422-ad5313r-iio-support-v1-0-ed7dca001d1b@analog.com" ] } } }
ad7922a to
23b0ee7
Compare
Apply IWYU principle, replacing unused/generic headers for specific/missing headers. The resulting include directive list is sorted accordingly. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
AD5683_REGMAP and AD5693_REGMAP behave the same way in the common code, and that is because they target single channel devices from the same sub-family. There is no reason to separate them and it will make things simpler when refactoring the chip info table. Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Split chip info table into separate structs and expose them to the spi i2c drivers. That is the preferrable approach and allows for the drivers to have knowledge of the device info before the common probe function gets called. Those chip info structs may be shared by SPI and I2C driver variants. Channel declaration definitions are grouped according to channel count and DECLARE_AD5693_CHANNELS() macro is renamed to DECLARE_AD5683_CHANNELS() to match the regmap_type enum. Use spi_get_device_match_data() and i2c_get_match_data() to get chip info struct reference, passing it as parameter to the common probe function. Also, missing entries (AD5673R/AD5677R) are added to the i2c of_match table. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add of_match table for the SPI device variants to be consistent with the AD5696 I2C driver. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
For single-channel parts the control register is used to enable the internal voltage reference and perform powerdown control. The reference enable bit position was ignored when writing the register at the probe function (!!val was used). This patch adds a control_sync() function that properly consumes the mask definitions with FIELD_PREP(). As further cleanup, the created functions and definitions are also used in ad5686_write_dac_powerdown(). Some local variables ended up being unused (so removed) and st->use_internal_vref is initialized earlier in probe, because it is also applicable to the AD5686_REGMAP case. Fixes: be1b24d ("iio:dac:ad5686: Add AD5691R/AD5692R/AD5693/AD5693R support") Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Protect access of pwr_down_mode and pwr_down_mask fields with existing mutex. This issue exists since the ad5686 driver was first introduced. Fixes: c2f37c8 ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Digital to analog converters") Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Fix powerdown control by using a proper bit shift for the powerdown mask values. During initialization, powerdown bits are initialized so that unused bits are set to 1 and the correct bit shift is used. Dual-channel devices use one-hot encondig in the address and that reflects on the position of the powerdown bits, which are not channel-index based for that case. Quad-channel devices also use one-hot encondig for the channel address but the result of log2(address) coincides with the channel index value. This patch also reviews local variable declarations under ad5686_write_dac_powerdown() and ad5686_probe(). The issue was introduced when first adding support for dual-channel devices, which overlooked powerdown control differences. Fixes: 7dc8fae ("iio: dac: ad5686: add support for AD5338R") Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Use in_range() to fix range check for input raw value, which is off by one, i.e., for a 10-bit DAC the max valid value is 1023, but 1 << 10 equals 1024, which passes the previous check, allowing an out-of-range write. The issue exists since the ad5686 driver was first introduced. Fixes: c2f37c8 ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Digital to analog converters") Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add GPIO property for RESET, LDAC and GAIN pin. RESET is active-low, LDAC is used to load DAC channels with values from input registers and GAIN can double the voltage in output channels. The gain-gpios property is not available to all supported parts. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add supplies for VDD, VLOGIC and VREF input voltage pins. The vcc-supply property is deprecated. Certain devices require vref-supply to be available once an internal reference voltage is absent. Still, this patch does not add those as 'required' so that the ABI is not broken. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add GPIO property for RESET, LDAC and GAIN pin. RESET is active-low, LDAC is used to load DAC channels with values from input registers and GAIN can double the voltage in output channels. The gain-gpios property is not available to all supported parts. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add supplies for VDD, VLOGIC and VREF input voltage pins. The vcc-supply property is deprecated. Certain devices require vref-supply to be available once an internal reference voltage is absent. Still, this patch does not add those as 'required' so that the ABI is not broken. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Get optional regulators for vdd, vlogic and vref input power pins. vdd is the input power supply, while vlogic powers the digital side. vref is replacing vcc, which is being deprecated, but still supported. The value of vref_mv is checked so that a device without internal voltage reference cannot proceed without an explicit supply. Error report uses dev_err_probe(), which helps debugging an init issue. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Create struct with bus operations, including a sync() operation that will be used to flush multiple channel writes at once. Auxiliary functions ad5686_write() and ad5686_read() are created and ad5686_probe() now receives an ops struct pointer rather than individual read and write functions. Documentation header of ad5686_state struct is updated accordingly (adjusting renamed fields and formatting). Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add RESET pin GPIO support through an optional reset controller, which is local to the probe function and deasserted by default. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
If wired LADC, should be held low when unused (pin is active-low), which allows for synchronous DAC updates. This will be used to update all the channels at the same time when adding buffer support. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Use of local SPI bus data to manage a collection of SPI transfers and flush them to the SPI platform driver with the sync() operation. This allows for faster handling of multiple channel DAC writes, avoiding kernel overhead per spi_sync() call, which will be helpful when enabling triggered buffer support. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Implement trigger handler by leveraging the LDAC gpio to update all DAC channels at once when it is available. Also, the multiple channel writes can be flushed at once with the sync() operation. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Most of the supported devices rely on a GAIN pin to control a 2x multiplier applied to the output voltage. Other devices, e.g. the single-channel ones, provides a gain control through a bit field in the control register. Some designs might have the GAIN pin hardwired to VDD/VLOGIC or GND, which would still be fine for this patch, that allows the scale property to be configurable with two available options. In read_raw() and write_raw() implementations mutex guards are used to allow early returns. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Support for AD5316R, AD5673R, AD5675, AD5677R and AD5697R missing from the device-tree bindings documentation. These devices have different bit resolutions or different number of channels so no fallback compatibles are used. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add compatible entries for AD5313R, AD5317R, AD5674, AD5679, AD5687, AD5687R, AD5689, AD5689R. These devices have unique combination of channel count, bit resolution and supported command set, so that fallback compatibles are not used. Also, a small copy-and-paste error is fixed to the title field. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add support for AD5313R, AD5317R, AD5674, AD5679, AD5687, AD5687R, AD5689, AD5689R to the AD5686 SPI driver. Also adding support for AD5316R, AD5675, AD5697R to the AD5696 I2C driver. This includes the creation of seven chip info struct instances and reuse of existing ones. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Update device list entries in Kconfig and remove device description from file headers. One can rely on the ID table(s) to check for supported devices. Adjust comment header accordingly and update update Copyright notice in comment file headers with the current year. Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
2474435 to
ad5f1d1
Compare
4674362 to
78b10cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
This series adds support for multiple nanoDAC parts, adding triggered
buffer and gain control support to the ad5686 DAC driver family, along
with a number of driver cleanups and fixes.
Initial patches update the device-tree bindings:
Driver cleanups and fixes:
bus transfers.
New functionality:
AD5674, AD5679, AD5687, AD5687R, AD5689 and AD5689R;
all channel writes atomically;
PR Type
PR Checklist