Skip to content

AD7768 upstream - #3146

Open
jansunil wants to merge 14 commits into
mirror_ci/jic23/iio/testingfrom
ad7768-upstream
Open

AD7768 upstream#3146
jansunil wants to merge 14 commits into
mirror_ci/jic23/iio/testingfrom
ad7768-upstream

Conversation

@jansunil

@jansunil jansunil commented Feb 23, 2026

Copy link
Copy Markdown
Collaborator

PR Description

  • Please replace this comment with a summary of your changes, and add any context
    necessary to understand them. List any dependencies required for this change.
  • To check the checkboxes below, insert a 'x' between square brackets (without
    any space), or simply check them after publishing the PR.
  • If you changes include a breaking change, please specify dependent PRs in the
    description and try to push all related PRs simultaneously.

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have compiled my changes, including the documentation
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly
  • I have provided links for the relevant upstream lore

@jansunil jansunil changed the title Ad7768 upstream AD7768 upstream Feb 23, 2026
@jansunil
jansunil force-pushed the ad7768-upstream branch 9 times, most recently from fec0c1a to 5b36ef0 Compare February 23, 2026 15:28
@github-actions
github-actions Bot force-pushed the mirror_ci/jic23/iio/testing branch from f9b6ebc to ca4d3a2 Compare February 24, 2026 00:00
@jansunil
jansunil force-pushed the ad7768-upstream branch 5 times, most recently from 0041a58 to efef9aa Compare February 24, 2026 13:34
@jansunil
jansunil marked this pull request as ready for review February 24, 2026 14:50
@ahmetalincak

Copy link
Copy Markdown
Collaborator

Hey @nunojsa - could you please have a look this one?

@nunojsa

nunojsa commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Hey @nunojsa - could you please have a look this one?

Sure. I asked first for llm-review. Let's see what comes out after that.

@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

LLM review

This series adds support for the AD7768/AD7768-4 8/4-channel simultaneous-sampling
Sigma-Delta ADC, along with CRC enable/disable support in the IIO backend infrastructure
and the ADI AXI ADC backend.

run: 25312690089


3f48a628c21e - drivers: iio: adc: AD7768 Driver support

Bug 1 — GPIO reset pulse broken (critical)

gpiod_set_value_cansleep() is called with GPIOD_OUT_HIGH and GPIOD_OUT_LOW
enum values. These are flags for devm_gpiod_get(), not integer values for
gpiod_set_value_cansleep(). Their actual integer values are 7 and 3
respectively — both non-zero. Since gpiod_set_raw_value_commit() takes a
bool, both evaluate to true, so the GPIO is never driven low and the
hardware reset pulse is never asserted. The device is left uninitialized.

// drivers/iio/adc/ad7768.c:1172
gpiod_set_value_cansleep(st->reset_gpio, GPIOD_OUT_HIGH); // passes 7
gpiod_set_value_cansleep(st->reset_gpio, GPIOD_OUT_LOW);  // passes 3 — still HIGH!

Fix: use integer literals 1 and 0.

Bug 2 — Missing IS_ERR check on reset_ctrl

devm_reset_control_get_optional_exclusive() can return ERR_PTR on error.
The driver only checks !st->reset_ctrl (NULL check), so an ERR_PTR passes
through and is later dereferenced in reset_control_assert(), causing a crash.

// drivers/iio/adc/ad7768.c:1213-1214
st->reset_ctrl = devm_reset_control_get_optional_exclusive(dev, NULL);
if (!st->reset_ctrl) {  // missing IS_ERR() check

Bug 3 — CRC never actually enabled (critical)

AD7768_INTERFACE_CFG_CRC_SELECT is defined as 0x01, but the CRC_SELECT
field occupies bits [3:2] (GENMASK(3,2) = 0x0C). The call:

regmap_update_bits(regmap, INTERFACE_CFG, GENMASK(3,2), 0x01);
// Effective write: (current & ~0x0C) | (0x01 & 0x0C) = (current & ~0x0C) | 0x00
// Result: CRC DISABLED

Per the AD7768 datasheet Table 45 (Register 0x07), CRC_SELECT = 0b01 (every 4
samples) requires bits [3:2] = 0b01, i.e. value 0x04.

Fix: #define AD7768_INTERFACE_CFG_CRC_SELECT FIELD_PREP(GENMASK(3, 2), 0x01)

Bug 4 — Power mode settings erased on resume

ad7768_runtime_suspend() and ad7768_runtime_resume() use regmap_write()
to set/clear the SLEEP_MODE bit (bit 7), which overwrites the entire
POWER_MODE register. This destroys the POWER_MODE[5:4] and MCLK_DIV[1:0]
fields configured at probe time, leaving the device in the wrong power mode
after resume.

Fix: replace regmap_write() with regmap_update_bits(..., AD7768_SLEEP_MODE_MSK, val).

Warning — Kconfig hard-dependency on ADI_AXI_ADC

The driver uses the generic IIO backend API and should not depend on a specific
backend implementation. Use select IIO_BACKEND instead of depends on ADI_AXI_ADC,
following the pattern of AD7779.

Warning — MAINTAINERS file patterns out of alphabetical order (checkpatch)

include/ entry appears before drivers/; correct order is
Documentation/drivers/include/.


d40fe7709397 - Documentation: iio: Add AD7768 Documentation

Warning — index.rst insertion out of alphabetical order

ad7768 is inserted between ad7380 and ad7606, but numerically 7768 > 7606 > 7625.
Correct position: between ad7625 and ad7944.


CI Warnings

checkpatch.pl --strict on 3f48a628c21e reports:

WARNING: Misordered MAINTAINERS entry - list file patterns in alphabetic order
CHECK: Macro argument reuse 'ch' - possible side-effects? (__AD7768_4_REG_MAP)
CHECK: Alignment should match open parenthesis (4 occurrences)

Verification data

The AD7768/AD7768-4 datasheet (ad7768-ad7768-4.pdf) was fetched from the Analog
Devices docling mirror and used to verify:

  • Register 0x04 (POWER_MODE): POWER_MODE[5:4] encoding (00=LP, 10=Median, 11=Fast)
    and MCLK_DIV[1:0] (00=/32, 10=/8, 11=/4) — driver mapping is correct.
  • Register 0x07 (Interface Configuration): CRC_SELECT[3:2] field — confirmed
    the 0x01 value bug (should be 0x04).
  • RESET pin: active-LOW with internal pull-up to IOVDD, minimum low pulse
    width = 2×tMCLK — confirms the GPIO reset sequence direction is correct once
    the value bug is fixed.

Driver built clean (no errors, no warnings) with gcc_aarch64 and gcc_arm compilers
after enabling COMPILE_TEST, SPI_MASTER, ADI_AXI_ADC=m, AD7768=m.


Suggested patches

Apply the suggested patches with:

cd path/to/repository
export GITHUB_TOKEN=ghp_***
apply-patches --repo=analogdevicesinc/linux 25312690089
Install instructions

The following one-liner installs the script if not present already:

grep "/apply-patches.sh" ~/.bashrc ||  { curl "https://raw.githubusercontent.com/analogdevicesinc/doctools/refs/heads/main/ci/scripts/apply-patches.sh"    -o ~/.local/bin/apply-patches.sh &&  echo "source ~/.local/bin/apply-patches.sh" >> ~/.bashrc ; source ~/.bashrc ; }

More information at AI Usage.

@jansunil

jansunil commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

Changelog after LLM Review fixes:

  1. Fix issue with CRC select configuration
  2. Changed to regmap_update_bits() to only modify SLEEP_MODE bit [7]
  3. Removed dependency in kconfig on the ADI_AXI_ADC and added IIO_BACKEND select
  4. Fixed alignment of function with respect to open paranthesis
  5. Fixed checkpatch warnings on MAINTAINERS file reg. alphabetical order of entries
  6. Alphabetically ordered entries in the index.rst
  7. Added 1, 0 as states for GPIO set and reset

@nunojsa nunojsa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! Plenty of comments already :). Will also trigger a llm review

maxItems: 1
description: |
GPIO reset pin.
Either resets or reset-gpios should be specified, not both.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing blank line. And why the two resets?

Comment thread Documentation/devicetree/bindings/iio/adc/adi,ad7768.yaml Outdated
Power mode selection:
0 - Low power mode
1 - Median mode
2 - Fast mode

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can support the above with linux PM subsystem. What comes to mind:

runtime PM: Toggle between median and fast mode
system PM: toggle between low and median mode.

Something to have in mind

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are still using this, use strings and then drop the bindings header. I'm not 100% sure but I think they are not encouraged that much

Comment thread Documentation/devicetree/bindings/iio/adc/adi,ad7768.yaml Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my comments, we might not need this header

Comment thread drivers/iio/adc/ad7768.c Outdated
Comment thread drivers/iio/adc/ad7768.c Outdated
Comment thread drivers/iio/adc/ad7768.c
Comment thread drivers/iio/adc/ad7768.c Outdated
Comment thread drivers/iio/adc/ad7768.c Outdated
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

LLM review

This series adds support for the AD7768 (8-channel) and AD7768-4 (4-channel) simultaneous-sampling 24-bit Sigma-Delta ADCs, with IIO backend CRC support for the AXI ADC.

run: 27197818159


c439de25 - drivers: iio: adc: AD7768 Driver support

Build failure — missing GPIOLIB dependency:
The driver calls gpiochip_get_data() and devm_gpiochip_add_data() from <linux/gpio/driver.h> but the Kconfig entry has no depends on GPIOLIB || COMPILE_TEST. Builds without GPIOLIB fail at link time with undefined references. Reproduced on gcc_arm and gcc_aarch64 defconfigs.

Crash — reset_ctrl IS_ERR not checked:

st->reset_ctrl = devm_reset_control_get_optional_exclusive(dev, NULL);
if (!st->reset_ctrl) {   // misses ERR_PTR case

devm_reset_control_get_optional_exclusive() returns ERR_PTR on error, not NULL. The invalid pointer then reaches reset_control_assert() in ad7768_hw_reset(). Fix: add if (IS_ERR(st->reset_ctrl)) return dev_err_probe(...) before the NULL check.

Bug — wrong CH_STANDBY initialization for 8-channel device:

regmap_write(st->regmap, AD7768_REG_CH_STANDBY, 0x0F);

0x0F only puts channels 0–3 into standby. For the 8-channel AD7768, channels 4–7 remain active. Fix: use GENMASK(st->chip_info->num_channels - 1, 0) which gives 0xFF for 8-ch and 0x0F for 4-ch.

Bug — precharge buffer loop iterates count, not channel numbers:
st->precharge_cfg[] is indexed by actual channel number (e.g. precharge_cfg[5] for channel 5), but ad7768_configure_precharge_buffers() iterates ch from 0..num_en_channels. For non-sequential DT channels (e.g. channels 3, 5, 7), the wrong array slots are read and no precharge buffers are programmed. Fix: change loop bound to st->chip_info->num_channels.

Missing MODULE_DEVICE_TABLE(of, ad7768_of_match):
Without this, the module cannot be autoloaded from a device tree adi,ad7768 compatible string.


763238f1 - dt-bindings: iio: adc: Add AD7768

Wrong schema for io-backends:

io-backends:
  $ref: /schemas/types.yaml#/definitions/phandle   # wrong

All other ADC bindings with io-backends use maxItems: 1 (see adi,ad9467.yaml, adi,ad7625.yaml, adi,ad7779.yaml). Fix: replace $ref with maxItems: 1.


CI warnings

The checkpatch warning for duplicate Signed-off-by appears in all patches. Also, the DT binding, the dt-bindings header, and MAINTAINERS changes are mixed into a single patch (763238f1) but should be a separate patch per Documentation/devicetree/bindings/submitting-patches.rst.


Suggested patches

Apply the suggested patches with:

cd path/to/repository
export GITHUB_TOKEN=ghp_***
apply-patches --repo=analogdevicesinc/linux 27197818159
Install instructions

The following one-liner installs the script if not present already:

curl -fSsL "https://raw.githubusercontent.com/analogdevicesinc/doctools/refs/heads/main/ci/scripts/apply-patches.sh" \
     -o ~/.local/bin/apply-patches.sh && \
  grep -q "/apply-patches.sh" ~/.bashrc || echo "source ~/.local/bin/apply-patches.sh" >> $_ ; . $_

More information at AI Usage.

@jansunil

Copy link
Copy Markdown
Collaborator Author

Changelog:

dt-bindings: iio: adc: Add AD7768

  • adi,common-mode-output changed from uint32 enum (0–3) to string enum ("avdd-avss-half", "1.65V", "2.5V", "2.14V")
  • Reset binding reworked: removed reset-gpios + reset-names
  • GPIO controller support added
  • io-backends: replaced verbose $ref: phandle + description with maxItems: 1
  • Cleaned up multiline | descriptions to inline where appropriate
  • Examples updated to reflect all the above (new reset-controller node, string VCM values, gpio-controller properties)

include/dt-bindings/iio/adc/adi,ad7768.h

  • Removed VCM numeric macros (AD7768_AVDD1_AVSS_HALF_VOLT_V, AD7768_1P65_V, AD7768_2P5_V, AD7768_2P14_V) — no longer needed since adi,common-mode-output is now string-based

drivers/iio/adc/Kconfig

  • Added CONFIG_AD7768_GPIO — new tristate entry for the split-out GPIO auxiliary driver (ad7768-gpio)

MAINTAINERS

  • Added drivers/iio/adc/ad7768-gpio.c to the AD7768 entry and correct the sequence of .rst entry to the right commit

drivers/iio/adc/ad7768.c

  • GPIO subsystem split out to auxiliary bus, remove unused includes
  • Removed reset_gpio and reset_ctrl from ad7768_state
  • Rename ad7768_hw_reset() → ad7768_reset(st, reset_ctrl), as software fallback is added now
  • Startup delay moved inside ad7768_reset() and fixed to fsleep(2000) with datasheet reference comment (was fsleep(3000) after reset in probe)
  • reset_ctrl acquisition moved to after regmap init; uses scoped declaration in probe
  • Removed id field and enum ad7768_device_ids
  • Added available_datalines pointer and num_datalines directly into chip_info — eliminates the switch(chip_info->id) in ad7768_parse_config()
  • Removed num_en_channels, precharge_cfg[], reset_gpio, reset_ctrl, gpiochip from structure
  • precharge_cfg is now a stack-local array in ad7768_parse_config()
  • d16 gains __aligned(IIO_DMA_MINALIGN)
  • All scoped_guard(mutex, &st->lock) replaced with guard(mutex)(&st->lock) throughout
  • Added lockdep_assert_held(&st->lock) in ad7768_sync()
  • ad7768_runtime_suspend/resume no longer hold the lock (PM callbacks)
  • ad7768_regmap_write() now calls spi_write(spi, data, count) directly — removed manual 16-bit word construction
  • ad7768_regmap_read() uses ((u8 *)&st->d16)[1] instead of be16_to_cpu() & 0xFF
  • Removed size validation guards
  • Added ad7768_init_chan() helper to deduplicate channel template initialization
  • ad7768_set_filter_mode/get_filter_mode: use st->chn_mode[chan->address] directly, removed ad7768_get_channel_mode() indirection
  • Channel standby mask: GENMASK(num_channels - 1, 0) instead of hardcoded 0x0F
  • rename SAMPLE_SIZE → AD7768_SAMPLE_SIZE
  • Inline validation in ad7768_parse_config(): now rejects zero channels (!num_channels || ...)
  • dev_err() + bare return → dev_err_probe() for rev ID check
  • Removed unused helpers: ad7768_map_regval_to_power_mode, ad7768_4_precharge_refbuf1_msk, ad7768_4_precharge_refbuf2_msk, ad7768_get_ch_mode_4ch
  • Removed crc_enable / crc_disable ops from adi_ad485x_ops
  • Changed commit message for CRC commit

@jansunil

Copy link
Copy Markdown
Collaborator Author

Changelog:
Rebase and update with recent commit

@github-actions

Copy link
Copy Markdown
Contributor

LLM review

This series adds support for the Analog Devices AD7768 and AD7768-4 simultaneous sampling ADC devices with complete driver implementation, device tree bindings, documentation, and CRC backend support.

run: 27742069075

Series Overview

The 5-commit series implements:

  1. Device tree bindings with schema validation for AD7768 and AD7768-4 variants
  2. Generic IIO backend CRC enable/disable operations
  3. AXI ADC backend CRC implementation
  4. Complete AD7768 SPI driver with GPIO auxiliary support
  5. Comprehensive driver documentation

Compilation Status

Successfully compiled for x86_64 and arm64 without errors. Generated modules: ad7768.o (29.7 KB), ad7768-gpio.o (9.7 KB).

Design Highlights

  • Power Modes: Three configurable modes (Low Power, Median, Fast)
  • Data Output: 1, 2, 8 lines for AD7768; 1, 4 lines for AD7768-4
  • CRC Support: Data integrity via backend interface
  • GPIO Controller: 5-pin auxiliary GPIO interface
  • Calibration: Per-channel offset, gain, and phase calibration

Checkpatch Issues

All commits have checkpatch warnings that are false positives in git diff/format-patch mode:

  • "Do not use whitespace before Signed-off-by" - appears in context lines
  • "Missing Signed-off-by" - artifact of git format-patch

These do not affect functionality.

Minor Issues Found

  1. Commit message typos (cosmetic):

    • Commit b13cc3dc: "simulataneous" should be "simultaneous"
    • Commit a37f982: Missing space after comma "4/8 channel,simultaneous"
  2. Device tree binding note: The AD7768-4 conditional schema could be clearer about inherited required properties, though functionality is correct.

Verification Data

Compilation testing:

x86_64: Full kernel build successful
arm64:  Full kernel build successful
Module size: ad7768.o 29,688 bytes, ad7768-gpio.o 9,728 bytes

Code analysis:

  • Proper mutex protection for register access
  • Correct IIO backend API usage
  • Clean resource management with devm
  • SPI protocol implementation verified

Code Quality

  • Follows Linux kernel coding standards
  • Proper error handling with dev_err_probe()
  • Comprehensive register definitions
  • Auxiliary driver pattern correctly implemented
  • Documentation complete and accurate

Recommendation: Ready for acceptance. Commit message typos are optional cosmetic fixes.

@jansunil

Copy link
Copy Markdown
Collaborator Author

Changelog:

  1. ad7768_reg_access() — Runtime PM wrap for debugfs
    Added pm_runtime_resume_and_get() / pm_runtime_put() around register reads and writes so debugfs access works correctly when the device is suspended.
  2. Buffer setup ops — PM hold during buffered capture
    Added ad7768_buffer_preenable() and ad7768_buffer_postdisable() callbacks that acquire/release a PM runtime reference for the entire duration of a DMA capture, preventing the device from sleeping mid-stream.
  3. ad7768_runtime_resume() — Filter settling delay
  4. Fixed ad7768_configure_precharge_buffers() to index by indio_dev->channels[ch].channel instead of the loop variable ch, so non-contiguous DT channel definitions apply buffers to the correct physical channels.
  5. ad7768_set_available_sampl_freq() moved to ad7768_parse_config()
  6. MODULE_DEVICE_TABLE(of, ad7768_of_match) added for DT-based module autoloading.
  7. GPIO #ifdef restructure
  8. Added "^channel@[4-7]$": false in the AD7768-4 if-then block to explicitly reject channels 4–7 for the 4-channel variant.

@nunojsa nunojsa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it goes another round. I guess it's plenty already

Power mode selection:
0 - Low power mode
1 - Median mode
2 - Fast mode

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are still using this, use strings and then drop the bindings header. I'm not 100% sure but I think they are not encouraged that much

enum: [1, 2, 4, 8]
description:
Number of data output lines used for serial interface.
AD7768 supports 1, 2, or 8 lines. AD7768-4 supports 1 or 4 lines.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not missing nothing, you can have the above as 1,2 and 8 and then no need for the else branch in the allof condition

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dtbs check fails with this structure..

adc@1 (adi,ad7768-4): adi,data-lines-number: 4 is not one of [1, 2, 8]

Comment thread drivers/iio/adc/ad7768-gpio.c Outdated

MODULE_AUTHOR("Janani Sunil <janani.sunil@analog.com>");
MODULE_DESCRIPTION("Analog Devices AD7768 GPIO auxiliary driver");
MODULE_LICENSE("GPL");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not belong in here... See this series:

https://lore.kernel.org/linux-hwmon/20260502-ltc4283-support-v13-0-1c206542e652@analog.com/

Also needs to be in it's own patch

Comment thread drivers/iio/adc/ad7768-gpio.c Outdated
ret = regmap_update_bits(st->data->regmap, AD7768_REG_GPIO_CONTROL,
AD7768_GPIO_UGPIO_ENABLE,
AD7768_GPIO_UGPIO_ENABLE);
mutex_unlock(st->data->lock);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lock here is not needed

Comment thread drivers/iio/adc/ad7768-gpio.c Outdated
{
pm_runtime_mark_last_busy(st->data->dev);
pm_runtime_put_autosuspend(st->data->dev);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally this kind of helpers are not really needed. Up to you

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helper was added because there were 7 instances of such a usage

Comment thread drivers/iio/adc/ad7768.c Outdated
{
struct ad7768_state *st = iio_priv(indio_dev);

pm_runtime_put(&st->spi->dev);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No autosuspend()? Any particular reason?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, just an oversight. Will add pm_runtime_set_autosuspend_delay() and switch all pm_runtime_put() paths to pm_runtime_put_autosuspend().

Comment thread drivers/iio/adc/ad7768.c Outdated
ret = -EINVAL;
}

pm_runtime_put(&st->spi->dev);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the cleanup macros you can return in place

Comment thread drivers/iio/adc/ad7768.c Outdated
{
int ret;

lockdep_assert_held(&st->lock);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit too much to have this annotation for a driver that is not overly complicated. That said, up to you to keep or not

Comment thread drivers/iio/adc/ad7768.c

ret = regmap_read(st->regmap, base_reg + 2, &lsb);
if (ret)
return ret;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do a bulk read?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized now that configuring use_single_read=true can enable bulk reading in this case, which I overlooked earlier.
Using bulk read now.

Comment thread drivers/iio/adc/ad7768.c Outdated
if (ret < 0)
return ret;

*(u8 *)val_buf = ((u8 *)&st->d16)[1];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as in other series. I suspect the above can be simplified a lot. Use the arguments you get from regmap and make sure to have endianism right and read mask.

@nunojsa nunojsa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it goes. I think this is already in an "upstreamable shape". Take my latest comments and take it upstream. The only think I would think a bit more is the regmap custom functions.

Comment thread drivers/iio/adc/ad7768.c Outdated
Comment thread drivers/iio/adc/ad7768.c
Comment thread drivers/iio/adc/ad7768.c Outdated
Comment thread drivers/iio/adc/ad7768.c
Comment thread drivers/iio/adc/ad7768.c Outdated
Comment thread drivers/iio/adc/ad7768.c

st->d16 = cpu_to_be16(AD7768_SPI_READ_CMD |
FIELD_PREP(AD7768_SPI_REG_MASK, reg));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have commented on this one already. Can't we have regmap dealing with endianism and setting up the read mask? So the above is not needed? And the below be16_to_cpu()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part follows an off-frame SPI protocol (with two separate CS assertions) and the custom bus cannot be avoided in this case.. hence the cpu_to_be16()

Comment thread drivers/gpio/gpio-ad7768.c Outdated
Comment thread drivers/gpio/gpio-ad7768.c Outdated
Comment thread drivers/gpio/gpio-ad7768.c Outdated
Comment thread drivers/gpio/gpio-ad7768.c Outdated
if (ret)
return ret;

guard(mutex)(&st->lock);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure. None of the gpio registers overlap with the ones we deal with in the IIO driver? Otherwise we would need to share the lock.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that the IIO driver doesn't apply any regmap_read/write calls on any GPIO registers. It is only listed in the readable_reg. Since that access goes through regmap's own internal lock, there wouldn't be any overlapsin this case.

@jansunil

jansunil commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Changelog:

  • dev_err_probe(-ENODEV) to dev_warn() for product ID check
  • Add fsleep(2000) between RESET assert and deassert
  • Fix auxiliary GPIO device name collision by using __devm_auxiliary_device_create() with an ID derived from SPI bus number and chip select
  • Simplify ad7768_reg_access() , ad7768_read_raw() by directly returning from the last function call
  • Remove unnecessary mutex lock in ad7768_gpio_direction_input() and ad7768_gpio_get_direction()
  • Remove redundant dev_get_regmap() NULL check

@jansunil

jansunil commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Rebase with mirror_ci/jic23/iio/testing. No code changes

@jansunil

jansunil commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Changelog:

  • Remove misleading comment in ad7768_reset() placed before
    reset_control_deassert(); the 1.66 ms startup delay applies after
    deassert, which is already handled by the fsleep() that follows.
  • Replace per-channel channel_freq[] tracking with per-mode mode_freq[]
    in ad7768_set_sampling_freq(). The previous approach updated
    channel_freq[ch] before hardware writes succeeded, leaving stale state
    on error. The new approach introduces ad7768_get_max_mode_freq() to
    speculatively compute the required clock without modifying state, then
    updates mode_freq[mode] only after all hardware writes succeed.
  • Add adi,ch-mode range check in ad7768_parse_config() to reject values
    outside [0, AD7768_NUM_CHANNEL_MODES) before calling
    ad7768_set_channel_mode().
  • Add driver documentation under Documentation/iio/ad7768.rst.

Devicetree Bindings for AD7768-4 (4 channel) and AD7768 (8 channel)
simultaneous sampling ADCs.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Add a backend operation to enable or disable Cyclic Redundancy Check
processing for data integrity verification. When enabled, the backend
will generate, verify, or process CRC information for data samples
transmitted over the interface, allowing the host to detect corrupted
samples.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
The AXI ADC register access paths serialize transactions with st->lock,
but probe does not initialize it. Initialize the mutex before registering
the backend.

Fixes: 7ecb8ee ("iio: adc: adi-axi-adc: support digital interface calibration")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Add support for enabling and disabling Cyclic Redundancy Check (CRC)
processing in the AXI ADC backend. CRC provides data integrity verification
for high-speed ADC data streams, ensuring reliable data transfer between
the ADC frontend and backend processing systems.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Add core support for the AD7768 and AD7768-4 simultaneous sampling ADCs.
Configure supplies, clock and reset, use a custom regmap bus for the SPI
protocol, and parse the enabled channels and input buffer settings from
devicetree.

Connect the converter to an IIO backend for buffered capture with CRC,
provide a fixed safe wideband sampling configuration and add runtime
power management.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Derive the available output data rates from MCLK and expose per-channel
sampling frequency and filter controls.

Select the fastest compatible power mode for the enabled channels and
map matching sampling frequency and filter combinations onto the two
hardware channel profiles. Configure the data clock divider and wait for
the selected filters to settle before capture.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Expose the per-channel offset and gain calibration registers through the
IIO calibbias and calibscale attributes.

Use bulk regmap operations and unaligned big-endian helpers to transfer
the three register bytes.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Expose the per-channel synchronization phase offset through the IIO
conversion-delay attribute.

Derive the delay resolution from MCLK, power mode and decimation rate.
Validate the requested delay and program the corresponding phase
register when applying the active channel configuration.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Expose the on-chip common mode voltage output through the regulator
framework. Support the three fixed output levels and the
supply-dependent AVDD1/2 setting.

Keep the ADC runtime active while VCM is enabled and release the runtime
PM reference when the output is disabled.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Register an auxiliary device when the AD7768 is described as a GPIO
controller. This allows the GPIO driver to share the parent regmap and
runtime power-management state.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Use regmap_test_bits() when reading a single GPIO value from a normal
register and when reading the direction bit.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Some gpio-regmap consumers share their regmap with a parent device that
may be runtime suspended. GPIO register accesses must resume that device
first.

Add an optional pm_dev field and acquire it before register translation
or access. Release it using runtime autosuspend after each operation.
Keep the device active across the complete direction-output sequence and
propagate failure when setting the initial output value.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
The AD7768 provides five GPIOs controlled through registers shared
with the parent IIO device. Register an auxiliary gpio-regmap driver
and use the parent device for runtime PM.

The device has separate input-state and output-latch registers. Add a
reg_mask_xlate() callback that checks the line direction and reads the
programmed output latch for output lines while retaining input-state
reads for input lines.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
Add driver documentation for AD7768.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
@jansunil

Copy link
Copy Markdown
Collaborator Author

Changelog:

  • Split the IIO driver into core support and focused patches for sampling
    modes, calibration, conversion delay, VCM, and GPIO registration.
  • Split AXI ADC mutex initialization into a separate preparatory patch.
  • Use PSEC_PER_SEC, explicit frequency units, unsigned frequency storage,
    regmap_test_bits(), endian helpers, and bulk calibration transfers.
  • Remove redundant SPI device state and avoid a forward declaration.
  • Use 32-bit divider arithmetic and rounddown_pow_of_two().
  • Move regulators additionalProperties and drop redundant GPIO
    dependencies from the devicetree binding.
  • Split the gpio-regmap changes and add regmap_test_bits() conversion as a
    separate cleanup.
  • Limit the generic gpio-regmap extension to optional runtime PM support.
  • Use an AD7768 reg_mask_xlate() callback to select the output latch for
    output GPIOs and document why it is required.
  • Use descriptive runtime PM cleanup labels and verify structure layout
    with pahole.
  • Set the VCM regulator's regulators_node so constraints from the nested
    vcm-output node are parsed.
  • Mark gpio-regmap GPIO chips as sleep-capable when a runtime PM device
    is configured.
  • Reword convdelay and buffered capture section in documentation to
    clarify the intended operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm review Request a review from a LLM Reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants