This patch adds PM device support to the siwx91x ADC driver. It allows
the ADC to be reconfigured after waking from deep sleep. Without this
patch, the ADC peripheral fails to return valid values after the system
resumes from deep sleep.
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
Invalidate the DMA buffer after a DMA transfer so the CPU
reads the freshly captured samples instead of stale cache
lines.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Expose the M5PM1 on-chip ADC as a Zephyr ADC controller child of the MFD
device.
The driver supports rail monitoring channels (VREF, VBAT, VIN, 5VOUT),
GPIO1/GPIO2 inputs via the ADC mux, and an internal temperature channel
at 12-bit resolution.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-4.7
Updated pse84 autanalog sar to support muxed inputs.
This implementation uses the autonomous controller (MFD).
The autonomous controller (AC) a programmable state machine. The AC
is shared across all autonomous analog peripherals including the
SAR, PRB, PTComp, CTB, and CTDAC.
The device supports 8 direct GPIO inputs and 16 muxed inputs.
The muxed inputs can be sourced from pins or from interal signals
from other autanalog blocks. Muxed inputs can be chosen by assigning
channels 8 and above. Only 2 muxed channels are allowed per sequencer
when operating in high-speed mode. 1 muxed channel is permitted per
sequencer when operating in low power mode.
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Richard Mc Sweeney <Richard.McSweeney@infineon.com>
The DMA path enabled the SARADC bus clock directly with
adc_ll_enable_bus_clock() and adc_ll_reset_register(), which
skips the function clock on chips where reset and clock control
are independent and also skips the temperature sensor register
preservation. On ESP32-C3 this left the SAR analog block in a
state where writing the digital controller timer enable bit
stalled the bus and hung the driver on the first DMA read.
Replace the manual sequence with adc_apb_periph_claim() and add
sar_periph_ctrl_adc_reset() at the start of every DMA read.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Add MEC175x SoC series support to the Microchip XEC ADC driver.
Refactor the driver to use DTS-encoded GIRQ and PCR properties
instead of series-specific ifdefs, enabling a unified driver
across MEC150x, MEC172x, and MEC175x.
Update mec_adc.h register definitions to support all three SoC
series with proper Kconfig guards for 16-channel ADC variants.
Signed-off-by: Srinivas Edireswarapu <srinivas.edireswarapu@microchip.com>
Add configurable timeout(forever by default) for waiting on
data valid interrupt to prevent blocking forever if the
interrupt is unexpectedly disabled.
If k_sem_take() times out, disable adc interrupt and then
read adc value if the data is valid as fallback path.
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
The LL_ADC_GetChannelSingleDiff function to know whether an ADC channel
is configured as differential or single-ended was not used correctly.
This lead to systematically disabling the ADC to reconfigure it, even if
the configuration was already the correct one.
Instead of returning the mode, LL_ADC_GetChannelSingleDiff returns the
channel if it is configured as differential, or 0 if it is single-ended.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
If the channel setup function is called while an ADC conversion is
on-going, it can lead the system to hang indefinitely. Prevent this by
adding a locking mechanism on the setup function, similar to what is
done for the read function.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
set BUF21 mode after enabling regulator, to ensure the buffered
output is available for the LPADC's VREFI reference.
This fixes an issue where the LPADC would produce inaccurate
conversion results due to BUF21 being left disabled.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Add temperature sensor (TSEN) support to the BFLB ADC driver.
When input_positive is set to the TSEN channel (14), the driver
automatically configures CONFIG2 for TSEN mode: enables TS_EN,
sets VREF to 2.0V, CHOP_MODE to Vref AZ, and clears test/debug
bits. ADC calibration is skipped for TSEN channels since the
temperature formula uses raw values.
A new adc_bflb_tsen_read_phase() function is exposed for the TSEN
sensor driver to perform the two-phase measurement (TSVBE_LOW
toggle) needed for temperature calculation.
Also makes efuse calibration failure non-fatal (warning instead
of error) since some chips lack programmed trim data.
Signed-off-by: William Markezana <william.markezana@gmail.com>
Add driver support for TI MSPM0 ADC module.
Add a configurable reference voltage support with vref.
Add this driver in shell.
Signed-off-by: Jackson Farley <j-farley@ti.com>
Signed-off-by: Alexpandi Muniyandi <alexpandi@linumiz.com>
ad405x_reg_update_bits() performs a raw read-modify-write without
shifting the value into the field position. The sample rate field
in TIMER_CONFIG occupies bits [7:4] (AD405X_FS_BURST_AUTO_MSK =
GENMASK(7, 4)), but ad405x_set_sample_rate() passes the raw enum
value (0-15) without shifting it.
This causes the rate value to be written into bits [3:0] instead
of bits [7:4], corrupting unrelated fields and setting the wrong
sample rate.
Shift the value by 4 to place it into the correct bit position,
consistent with how other callers handle non-zero-based fields
(e.g., ad405x_set_gp_mode() manually shifts for GP1_MODE_MSK).
Fixes: 4a9d1473d3 ("drivers: adc: ad405x: Add AD405X driver")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
The status variable is used in the while loop condition before
ad4114_read_reg() has a chance to populate it. If the uninitialized
stack value happens to have bit 7 set, the loop is skipped entirely
and the driver proceeds to read ADC data before the conversion is
ready, returning stale or invalid results.
Initialize status to 0 so the loop always executes at least once.
Fixes: 8250cc68b7 ("drivers: adc: ad4114: add driver support")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Use logical AND (&&) instead of bitwise AND (&) when checking the
product ID during initialization. The intent is to verify that the
product ID matches neither AD4052 nor AD4050, which requires a
logical operation.
Fixes: 4a9d1473d3 ("drivers: adc: ad405x: Add AD405X driver")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
On STM32H5, the bit 0 of the Option register of ADC1 controls the channel 0
switch control. It has to be set if either ADC1 or ADC2 wants to use this
channel. Until now, it was enabled only if ADC1 requested channel 0. This
commit fixes this by setting the option bit if channel 0 is used, with no
consideration of the ADC instance.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Correct the IFX_HPPASS_SAR_CH_EXISTS macro to correctly match devicetree
nodes using a hex address.
Assisted-by: Github Copilot:claude-opus-4.6
Signed-off-by: John Batch <john.batch@infineon.com>
- Added autanalog MFD support in PSE84 DTS files
- Refactored autanalog ADC in PSE84 to use a common
MFD for handling the global AC configuration
- Constructed AC to use phandle in the overlay
for a better the user experience.
- Added support for a basic and advanced mode
with custom AC
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Richard Mc Sweeney <Richard.McSweeney@infineon.com>
LPADC_DoOffsetCalibration() triggers offset calibration but returns
immediately without waiting for it to complete. If gain calibration
is requested before offset calibration finishes, the hardware silently
rejects it and GCC[RDY] never asserts, causing
LPADC_FinishAutoCalibration() to spin forever at boot (~50% of the
time on affected boards like FRDM-MCXA266).
Fix by replacing LPADC_DoAutoCalibration() with the split HAL API:
LPADC_PrepareAutoCalibration() + k_busy_wait(1U) +
LPADC_FinishAutoCalibration()
The 1us busy-wait gives offset calibration sufficient time to complete
on all LPADC platforms before the gain calibration request is issued.
Only the HAS_CTRL_CALOFS path is affected (the path that also calls
DoOffsetCalibration); the HAS_CFG_CALOFS path has no preceding offset
calibration and is left unchanged.
Fixes#105652
Signed-off-by: Jjateen Gundesha <jjateen97@gmail.com>
Since `a78cd34` the ADC driver did not correctly configure
its internal divisor. The responsibility was moved from the
clock control driver to the ADC driver and the `init` function
of the ADC driver was updated accordingly. But the driver
continued calling the clock control API from the `configure`
function, leading to `-EINVAL` being returned.
Correctly configure the internal divisor in the ADC driver by
calling the HAL API directly.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Move buffer size validation into `start_read()` to prevent adc
context from getting stuck. This issue is revealed by
`tests/drivers/adc/adc_error_cases` test.
Also, this patch adds check for unsupoorted options, including
oversampling and invalid resolution and adds support for higher
channel range. (8 and above).
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
STM32H72x/73x ADC have a PCSEL_RES0 register instead of PCSEL for other
series.
Make a special case to prevent a compilation error.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within:
- `drivers/adc`
- `drivers/audio`
- `drivers/bluetooth`
- `drivers/can`
- `drivers/charger`
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Fix a dangling pointer warning in adc_shell.c by placing the
help text in a static variable instead of returning a pointer
to a local variable.
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Change format specifier to %zu for size_t. While at it, also change
required_size to size_t, for better compatibility. This prevents
compilation warnings.
Signed-off-by: Amneesh Singh <amneesh@ti.com>
To prevent missing calibration when adding new series, add an error
message if no calibration is done.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Migrate ADC shell command help strings to use the SHELL_HELP
macro for consistent formatting and improved maintainability.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Use the new has-injected-support property in the Kconfig instead of
filtering on series directly, and use it also in the driver to return an
error if a specific instance doesn't support injected (this is the case
for STM32U5 where ADC1 and 2 support injected, but not ADC4).
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
In order to write into some ADC registers, it is necessary to have no
on-going conversions (either regular, injected, or both). Until now, each
time such a write was needed, the ADC was disabled unconditionally,
stopping any potential on-going conversion.
With the introduction of the injected mode, this could lead to problems
if for example an injected is configured differently than a running
regular one. In that case it would stop the regular conversion. If the
application is waiting the result before starting another one, it will be
stuck waiting forever.
To avoid cases like this, return an error rather than stopping conversion
and disabling the ADC. This reworks many functions to return an error in
case it was not possible to safely disable the ADC.
It stays possible to force an ADC disable even though a conversion is
running, this is useful at init where we don't want this to fail.
This also creates a dedicated function for the preselection register to
avoid duplication.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Add injected mode support for STM32 ADC driver. To avoid potential
conflicts when configuring the ADC registers, some settings (like presel)
are moved into the channel_setup function when injected is enabled.
Also configures an ISR when DMA and injected mode are enabled. The reason
is that DMA is not available for injected sequence, so an ISR is still
necessary in this case.
Factorizes the "start_read_xxx" functions to avoid needless duplication
between sync/async and regular/injected mode.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Add sequence priority support in the ADC API.
The priority assigned to a sequence reflects how time-sensitive it is
compared to other sequences. The number of priority levels supported
and the exact behavior obtained by assigning a specific priority to a
sequence are hardware-specific.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
It is unnecessary since it is never set to continuous (and single is the
default value), and causes issues on STM32F1 by starting conversions out
of turn (setting ADON bit while it is already set, without changing
any other bit in the register start a conversion).
Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
Adapt all Espressif SoC and driver code to the updated
hal_espressif module synced with IDF master branch.
Main changes:
- clock control: delegate peripheral clock gating to HAL
layer using new clock/reset APIs
- SPI/GDMA: adapt to restructured DMA HAL with new channel
allocation and configuration interfaces
- ethernet: add RMII clock configuration and PHY management
- GPIO: simplify using direct HAL function calls
- flash: adapt to updated SPI flash HAL interfaces
- linker scripts: update IRAM/DRAM mappings for new HAL
object files
- DTS: fix ESP32-S2 PSRAM dcache1 address to match actual
MMU mapping region (0x3f800000 DRAM1 instead of 0x3f500000
DPORT which lacks 8-bit access capability)
- west.yml: update hal_espressif revision
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Add support for PM policy device constraints to the MCUX LPADC driver.
This allows the driver to specify that certain power states should be
disabled when the device is active, which can help ensure proper operation
and reduce power consumption.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Add shell commands for the ADC emulator driver (zephyr,adc-emul) to
allow runtime configuration of emulated ADC values during testing and
development.
The new shell commands support:
- Setting constant raw ADC codes for a channel
- Setting constant input voltage in millivolts for a channel
Commands are dynamically populated with available ADC emulator devices
from the devicetree. This enables interactive testing of ADC-dependent
code without requiring physical hardware or signal generators.
Example usage:
adc_emul <device> raw <channel> <value>
adc_emul <device> mv <channel> <millivolts>
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Change the ADC emulator driver to accept differential mode configuration
instead of rejecting it with -ENOTSUP. When differential mode is requested,
the driver now logs a warning that samples are provided as raw codes and
continues operation.
This allows testing of ADC configurations that use differential mode
without requiring the emulator to implement full differential conversion
logic. The raw code values can still be set via shell commands or API
calls for testing purposes.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Add explicit clock configuration and enable calls during driver
initialization.
Note: -ENOSYS is temporarily ignored as not all clock control
drivers currently implement the configure API. This handling
should be removed once all clock drivers support configure.
Signed-off-by: Albort Xue <yao.xue@nxp.com>