Report every touch point the controller returns as its own multitouch
slot and track the touch IDs across scans to generate release events,
following the gt911 driver. CONFIG_INPUT_FT5336_MAX_TOUCH_POINTS caps
the number of points and defaults to 1, preserving the previous single
touch behavior.
Built for native_sim, not tested on hardware.
Assisted-by: Claude:opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The track ID sits in bits 7:4 of REG_Pn_YH, but the mask handed to
FIELD_GET() selected bits 3:0, so the high nibble of the Y coordinate
was read as the touch ID.
Assisted-by: Claude:opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
close() sent its vendor-specific reset command with
bt_hci_cmd_send_sync(), that is, through the Bluetooth Host. The Host
is only one possible user of the driver, which therefore cannot rely on
it, and close() was for that reason compiled only into builds with a
Host, leaving a controller-only build with a transport it could open
but not close. It did not work with the Host either: bt_disable() marks
the transport closed before it calls close(), after which the Host
refuses the command with -EHOSTDOWN, so bt_disable() failed.
Send the command with the HCI lockstep helper over the driver's own
transport instead, as open() does for its commands. The receive thread
is still running at that point and feeds the response to the helper; it
is stopped afterwards, as before. With that the driver calls no Host
API any more, and close() is part of every build.
Build-tested on nucleo_wb55rg with the peripheral_hr and hci_uart
samples. Not run on hardware.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Send the two vendor-specific initialization commands, the public
address derived from the device UID and the transmit power level, from
within open(), through the HCI lockstep helper and the driver's own
send path, instead of implementing the setup() driver API op on top of
the Host's bt_hci_cmd_send_sync(). The responses are consumed in the
driver's receive thread by feeding received packets to the lockstep
helper before delivering them to the host.
The commands no longer depend on the Host, so they now also run in
controller-only builds, where they were both compiled out and never
reached, bt_enable_raw() opening the driver without calling setup(), so
the controller kept its default address and transmit power. The driver
no longer selects BT_HCI_SETUP. A failing or unanswered command fails
open() with an error instead of failing the Host's HCI initialization
later, and is logged by the helper.
A failed address command fails open(), as it has failed setup() since
commit 19c58a5a3b ("Bluetooth: ipm_stm32wb: Fail setup when the
address write fails"). open() aborts the receive thread it started when
the vendor initialization fails, so that a second bt_enable() does not
create a thread that is still running.
When open() restarts the coprocessor after a close(), it also restores
the helper's initial command allowance with bt_hci_lockstep_reset():
the restarted coprocessor allows one command again without announcing
it.
The raw send path is factored out of send() and takes the device, so
that it serves both the send() op and the helper.
close() still sends its reset command through the Host and stays behind
CONFIG_BT_HCI_HOST.
Build-tested on nucleo_wb55rg with the peripheral_hr sample. Not run on
hardware.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
This context register's content is preserved on resets. Add functions to
read and write it.
Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
Everything the reference needs beyond its output being enabled -- the
clock, the compensation and chopping settings, the internal regulator, the
trim -- is written once from init and then only lost to a reset of the
block. A power domain that goes down resets it, and the suspend-to-RAM
resume path does not re-run driver init, so the consumers came back to a
reference whose registers were at their reset values while the driver
believed it had configured them.
Register a PM action and run the same configuration sequence from TURN_ON.
Whether the output is on stays with the consumers through the regulator
reference count and not with the SoC power state, so SUSPEND and RESUME
have nothing to do: a consumer that keeps converting in a low-power state
needs its reference to keep running.
The trim needs one more thing to survive. A value asked for through
set_voltage() is the consumer's choice of output voltage and nothing else
puts it back, so remember it and restore it instead of the reset value.
Where the reset value is a factory trim, leaving the register alone is what
the driver already did, so name that condition rather than deriving it
twice from the same SDK feature macro.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
The reference is configured in one sequence from init: the clock gate, the
compensation and chopping settings, the internal regulator and the trim.
None of it is touched again for the lifetime of the driver.
Move that sequence into a helper and leave init with the regulator
bookkeeping around it, so the configuration can be run again on its own.
No functional change.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
A Cortex-M system timer that stops in a low-power state hands timekeeping
to the counter named by /chosen/zephyr,system-timer-companion, and the
companion hooks arm that counter through counter_set_channel_alarm().
Without alarm support this driver answers -ENOTSUP, so the sleep is entered
with nothing scheduled to end it: on every MCXA and MCXN board, where
LPTMR0 is that companion, a build with CONFIG_PM never comes back from its
first deep state.
Default the option on when this timer is the chosen companion. The
top-value operation it gives up is not usable in that role anyway.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
The PORT pin-mux registers only answer while the block is clocked, and a
power domain that goes down takes the clock gate with it: it comes back
closed. Every driver that re-applies its pinctrl state on the way back up
writes through those registers, so it faults on an unclocked block, and a
board whose pads are not restored has no console to report it with.
Give the driver a PM handler that re-opens the gate from TURN_ON. The pad
configuration itself is state and not activity -- it has to hold for as
long as the block is powered, whatever the rest of the SoC is doing -- so
SUSPEND, RESUME and TURN_OFF have nothing to do.
Init keeps enabling the clock itself rather than leaving it to TURN_ON.
Drivers apply their pin state from their own initialisation and none of
them claims this device first, so the gate has to be open before any of
them runs, while a device sitting in a power domain is only handed TURN_ON
once something resumes the domain -- which for a domain that only tracks
SoC power states may be much later, or never.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
The block's clock gate is opened from one place, initialisation, and is
about to be opened from a second. Lift it into a function of its own so
both callers share the error handling instead of repeating it.
No functional change.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
The build warning caused twister error on stm32h5 boards
It can now be removed as all the stm32h5 boards have the MSPI
controller compatible.
Simply add a comment in the flash xspi driver to notify that
the flash stm32 xspi driver will be deprecated v4.5.0
Signed-off-by: Francois Ramu <francois.ramu@st.com>
Before NPCX4, two deep sleep sub-states have to be listed in
cpu-power-states because the 'Instant' wake-up path is only valid for
a residency shorter than 200 ms:
- suspend_to_idle0: Deep Sleep with 'Instant' wake-up
- suspend_to_idle1: Deep Sleep with 'Standard' wake-up
The PM policy picks between them from the min-residency-us property,
so a sleep the kernel expects to last longer than 200 ms falls back to
the standard wake-up sub-state.
NPCX4 and later lift that restriction with PMCSR bit 4, reserved on
earlier series, so 'Instant' wake-up can be used for an unlimited
residency. Describe the capability with a new
"nuvoton,npcx-power-state" binding that extends "zephyr,power-state"
with an "unlimited-instant-wakeup" property, and pass it down to the
clock controller.
suspend_to_idle0 alone would therefore give the best power figures on
NPCX4.
However, erratum 2.21 prevents that when eSPI is in use: two eSPI
transactions issued shortly after the EC entered Deep Sleep with
instant wake-up can produce a CRC error. Boards with eSPI enabled
must select one of
- suspend_to_idle1: Deep Sleep with 'Standard' wake-up
- suspend_to_idle2: Sleep, added here, which keeps HFCLK running
so npcx4.dtsi keeps cpu-power-states at suspend_to_idle1 and leaves
the other two sub-states for boards to opt into.
Assisted-by: Copilot:claude-opus-5
Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
- Add DMA support for SPI on RZ/A3UL since the previously supported
had not supported DMA.
Signed-off-by: Quang Le <quang.le.eb@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
Add new LIN controller API and LIN skeleton driver.
This device driver complies with the LIN CiA Specification rev2.1
and implement the physical layer and a part of the data link layer.
The LIN skeleton code is also included as the starting point for
LIN driver development
Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
Two-line copyright notices were wrapped in the SPDX "<text>...</text>"
construct, which is only valid in an SPDX document, not a file header.
Some notices did not have SPDX tags.
Remove the markers and tag the continuation line. Holder, year and
e-mail are left unchanged; only the syntax is fixed.
Signed-off-by: Wheeler Keith (ES ICW SW MTP EE) <Keith.Wheeler@infineon.com>
The new SDHC API driver for the STM32 SDMMC IP does not work across the
entire family portfolio, as some series (STM32F1/F2/F4/F7/L1) and lines
(STM32L4; but not STM32L4+!) use a different IP from the one which this
driver was tested against. Prevent enabling the driver on such series
since it will not work properly, or in fact build at all, because the
peripheral is called "SDIO" instead of "SDMMC" on most of these series
and the HAL/LL namings follow suit.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
irq_rx_enable() took the lock for as long as the receiver was armed.
A shell enables RX once and never disables it, so light sleep never
runs.
Take the lock only for an async RX transfer. Bytes that arrive while
the SoC sleeps are dropped; the UART is not a wake source.
Assisted-by: Grok:4.6
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
uart_irq_tx_disable() dropped the lock as soon as the driver stopped
asking for more data. Bytes can still be in the FIFO at that point,
so the SoC could enter light sleep mid-frame.
Wait for TX_DONE instead, which poll_out() already does. Rename
TX_POLL to TX_DRAIN and share it, as both paths wait for the same
event: the transmitter going empty. If TX is already idle, mask
TX_DONE and drop the lock now: the interrupt will not fire, and
leaving it enabled would keep a stale mask across the next transfer.
Assisted-by: Grok:4.6
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
this commit adds HEAP_MEM_POOL_ADD_SIZE_SDHC_STM32_SDMMC with
a default value of 2048 bytes for sdhc driver.
Signed-off-by: Sara Touqan <zephyr@exalt.ps>
virtq_create() only checked split virtqueue size constraints with
assertions. Builds with assertions disabled therefore accepted
non-power-of-two sizes, even though ring indexing relies on that
invariant, and did not report oversized queues consistently.
Reject invalid sizes with -EINVAL before allocating memory. Keep
zero-sized unused queues supported, exercise multiple invalid boundary
cases with assertions enabled, and cover representative native and QEMU
platforms.
Assisted-by: ChatGPT:GPT-5.6 Sol
Signed-off-by: Alejandro Sánchez <alesangreat@gmail.com>
Implement the initialization hook of the Low-Power Counter Companion
Interface in the Counter API-based implementation. From this hook, we
assert that the device was configured as a potential wake-up source in
DTS and enable it as wake-up source at runtime. While we cannot prevent
an external caller from disabling the counter as wake-up source, we can
detect this and panic the kernel via an __ASSERT() to help developers
figure out their application has an error.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Update relevant drivers to invoke the newly defined hook of the
Low-Power Companion Interface during initialization.
Only two drivers currently support the Low-Power Companion:
- cortex_m_systick
- mcux_os
In the Cortex-M SysTick case, the initialization hook is called from the
"system_timer_generic" code used by that driver so that all driver based
on this shared code will also invoke the init hook appropriately if they
are ever updated to implement Low-Power Companion support.
In the MCUX OS timer case, the "system_timer_generic" code is not used
so the initialization hook is called directly from the driver.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Add a new hook to the System Timer Low-Power Companion Interface that
must be called by the System Timer driver during its initialization.
This can be used to perform one-shot configuration that may be required
by the platform implementation.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Remove dependency of CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE (and the
associated choice) on SYSTEM_TIMER_HAS_LPM_COMPANION_SUPPORT. This makes
the option visible in every build, regardless of whether the companion
timer is supported or not, which allows using the option as an indicator
of whether or not a companion timer is used:
- CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE=y: companion timer not used
(either unsupported by systimer driver, or not available/enabled)
- CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE=n: companion timer used
This change will allow simplifications in common code since it is no
longer necessary to check for HAS_COMPANION_SUPPORT before looking at
CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE.
While at it, update the relevant header to make this explicit: the API
is not available when there is no low-power companion configured, which
is now when CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE=y.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
An auto-reload 32-bit down-counter: a RELOAD backend. The driver keeps
its synthesized cycle count and the reprogram that recovers the cycles
passing between reading the counter and rewriting it, the val1/val2
drift compensation, now named timer_driver_cycle_get() and
timer_driver_set_reload(). The core takes over the tick accounting:
announced_cycles and last_elapsed leave the device data, and with them
the deadline-to-cycles math, the range clamp and the announce.
The counter is not free-running, it counts one programmed interval at a
time, so the synthesized read is not atomic against the ISR and the
reprogram path. TIMER_CORE_COUNTER_NONATOMIC has the core serialise
sys_clock_cycle_get_32() under the clock lock.
The arm range narrows to the core default, half the synthesized count's
span, from the full 32-bit interval the hardware can hold: a full-span
interval wraps that count.
The driver states no cycles-per-tick of its own: MIN_DELAY_CYCLES and
the one-tick interval at init both read the core's
TIMER_CORE_CYC_PER_TICK.
The special case for CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE goes away. It armed
the longest interval the hardware could hold on SYS_CLOCK_MAX_WAIT,
which is also an ordinary capped timeout, so a far deadline was treated
as no deadline. The core arms the longest interval it allows once
nothing is pending, through the weak sys_clock_no_timeout().
Tested on mps2/an385, which needs a devicetree overlay pointing
/chosen/zephyr,system-timer at the arm,cmsdk-timer node plus
CONFIG_CORTEX_M_SYSTICK=n: timer_api passes. The sloppy-idle variant
hangs in test_timeout_abs, which reproduces without this commit, so the
platform is not added to that variant.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The block read and block process call transfers in the STM32 SMBus
driver let the peripheral choose how many bytes it sends. The count
byte is read into the length field of the following i2c_msg, and that
message then reads straight into the buffer the caller supplies, so a
peripheral reporting up to 255 bytes writes past the end of a buffer
the API documents as holding at most SMBUS_BLOCK_BYTES_MAX (32)
bytes.
There is no point between the two reads at which the driver can
intervene, since both are messages of a single i2c_transfer(), so
receive the data into a driver-local buffer large enough for any
count a peripheral can report and copy it out only once the count is
known to fit. An over-long count returns -ENODATA without touching
the caller's buffer, matching what the PCH driver does in the same
situation.
This costs 255 bytes of stack while a block read is in flight. The
alternative, splitting the length byte and the data into two
transfers, is cheaper but gives up the bus in between and so changes
what appears on the wire.
The PEC helpers are unaffected: they walk the message array and see
the same address, count byte and data bytes as before.
Assisted-By: Claude:opus-5
Signed-off-by: David Brown <david.brown@linaro.org>
The syscall verifiers for smbus_block_read() and smbus_block_pcall()
check the count arguments they are handed but never check the receive
buffer those calls fill in. A user mode caller can therefore pass any
pointer as buf or rcv_buf and the driver writes through it in
supervisor mode without anything having proved the memory is writable
by that thread.
Unlike smbus_block_write(), which sizes its read check from the
caller supplied count, the read side has no caller supplied length to
size a check from: the peripheral decides how many bytes it sends, so
the length is not known when the verifier runs. Check the documented
worst case instead, SMBUS_BLOCK_BYTES_MAX, which is what the API
already requires the buffer to be. A fixed size check is the usual
shape in this situation (see the flash and hwinfo handlers).
This tightens the contract for user mode callers, deliberately. A
user thread that passes a receive buffer shorter than
SMBUS_BLOCK_BYTES_MAX, in a region that is not writable past the end
of that buffer, now takes a K_OOPS instead of silently having memory
written past the buffer. Supervisor callers do not go through the
verifiers and are unaffected.
Assisted-By: Claude:opus-5
Signed-off-by: David Brown <david.brown@linaro.org>
This property is now defined on the parent MFD device. Having
it in the GPIO driver means that other MFD children may inadvertently
be reset.
Signed-off-by: James Bennion-Pedley <James.Bennion-Pedley@thinksmartbox.com>
This is an 8-bit linear current source LED dimmer that
is built into the AW9523B I2C IO Expander.
This is the other mfd function alongside the GPIO_AW9523B
driver. This one also supports runtime power management (so can be
placed on a power domain).
Signed-off-by: James Bennion-Pedley <James.Bennion-Pedley@thinksmartbox.com>
Adds reset GPIO to the MFD parent (as having reset on gpio/led nodes
will reset each other). Also adds PM support so device can be on
a power domain.
Signed-off-by: James Bennion-Pedley <James.Bennion-Pedley@thinksmartbox.com>
The XEC central DMA channel has no block-chain hardware: completion is
just MEM_ADDR reaching MEM_ADDR_END. Cache the dma_block_config chain
from configure() into a per-channel array (dma_xec_block[]) and program
only one block into hardware at a time. On each DONE, the ISR decides
whether to chain to the next cached block or terminate; cyclic wraps
back to block 0 instead of terminating after the last block.
Chaining reprograms the address registers from the ISR without tearing
down IENABLE/ACTV/GIRQ state, but per HW guidance for erratum
SCG_MR_22NM-131, a still-pending peripheral request can spontaneously
restart the channel the instant a raw reprogram makes MSA < MEA true
again, so dma_xec_chan_reprogram() forces the channel to HW idle via
ABORT (bounded to one unit-size AHB transfer) before rewriting
addresses.
Add DMA_MCHP_XEC_MAX_BLOCKS_PER_CHAN (default 1) to size the cached
block array; the default preserves today's single-block behavior and
RAM footprint bit-for-bit. reload() always re-arms a single buffer, so
it resets num_blocks/cur_block/cyclic to drop any chain left over from
a prior multi-block configure().
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Assisted-by: Claude:claude-opus-4-8
Introduce dma_xec_chan_reset() and use it from configure, reload and
stop to remove duplicated abort/clear sequences. Move channel
activation and interrupt enable from configure() to start(), so a
channel is armed only when a transfer actually begins.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Derive pending_length from the memory end/start registers,
report total_copied as 0, and drop the now-unused counters.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Assisted-by: Claude:claude-opus-4-7
Make the DMA driver API entry points follow the Zephyr contract and
validate input:
- config/reload/start: add xec_dma_chan_is_busy(), which requires both
the BUSY bit and a HW/SW flow-control run bit (BUSY alone can be set
without a transfer running), and route the -EBUSY guards through it.
- config: also reject zero-size blocks, half-complete callbacks,
mismatched handshake modes and invalid data sizes; drop the unused
block head/curr pointers.
- get_status: return -EIO on a latched bus error (hw_status is volatile).
- get_attribute: also report buffer address/size and copy alignment and
NULL-check the output.
- chan_filter: use enum dma_channel_filter and bounds-check the channel.
- stop: clear the GIRQ source latch to avoid a spurious pending interrupt.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Assisted-by: Claude:claude-opus-4-8
Generate the per-channel ISRs and IRQ_CONNECT calls by iterating the
interrupt-names property instead of girqs, so the loop index aligns 1:1
with the interrupts entries, and look up the GIRQ enable from the config
by channel index. Mark interrupt-names required and name the mec172x DMA
channels chan0..chan15.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
The generic timer core already extends this driver's 32-bit count from its
announce baseline, so sys_clock_cycle_get_64() works. Without the select,
k_cycle_get_64() returns 0.
Assisted-by: Claude:opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Commit ed7dd4f011 ("drivers: serial: stm32: split cyclic RX wrap into two
contiguous events") fixed some issues with cyclic wraparound,
but left a race condition where if the timeout arrives before COMPLETE,
data is emitted twice.
Simplify handling by ignoring the status and always using
`dma_get_status` to determine how much data to emit.
Return an error when trying to enable cyclic DMA with a 1-byte buffer.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Kamil Krzyżanowski <kamnxt@kamnxt.com>
The STM32MP13 DMA_InitTypeDef structure does not contain the Channel
member used by STM32 DMA V1 devices. It provides a Request member,
similar to the STM32H7 DMA HAL implementation.
Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
z_isr_install() is reached with the isr table index, which on a
SoC that reserves table entries sits above the line the enabled
mask uses, so the shift ran past the end of the mask and reported
an unrelated line. Subtract the reserved offset before the
lookup.
The offset symbol depends on GEN_ISR_TABLES, which the low power
cores turn off, so guard the subtraction the same way the rest of
the driver does.
Enable and disable are called with the line itself and are left
alone.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
clock_check_subsys() bounds the GCLK peripheral channel of a subsystem
by GCLK_PH_MAX, which is 47. PIC32CZ CA has 64 PCHCTRL channels: the
ATDF gives PCHCTRL a count of 64 on every CA80, CA90 and CA91 part,
the HAL defines GCLK_NUM as 64, and the dt-bindings header assigns
channels up to 63.
Every GCLKPERIPH subsystem above channel 47 is therefore rejected:
CAN2 to CAN5, GMAC_TX, GMAC_TSU, SQI0, SQI1, SDHC0, SDHC1, MLB and
CM7_TRACE. For those, clock_control_on(), clock_control_off(),
clock_control_get_rate() and clock_control_configure() return
-ENOTSUP, and clock_control_get_status() reports
CLOCK_CONTROL_STATUS_UNKNOWN. Found on a PIC32CZ CA90 Curiosity Ultra,
where the CAN3 and CAN4 drivers failed to initialize with -ENOTSUP
from clock_control_on().
Derive the bound from GCLK_NUM so it follows the hardware.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
With DMA no IADC interrupt is enabled, so the error flags are never
looked at: reading a channel whose analog bus is not allocated to the
IADC returns 0 with a meaningless sample. iadc_start_scan() also
ignores a failure of iadc_dma_start(), which leaves the reader blocked
forever, and the DMA callback neither stops the channel nor the scan
when a transfer fails.
Enable the error interrupts, with and without DMA, and check the error
flags in the DMA callback as well. As the interrupt handler and the DMA
callback can now both end a sampling, let iadc_sampling_end() decide
which of them does: it masks the IADC interrupts and stops the scan and
the DMA channel, so that an error that persists cannot interrupt again
for the same sampling, and it lets only the first caller complete it.
The interrupt handler ends the sampling before it clears the error
flags, as the DMA callback may preempt it and looks at them too. A
failed sampling stops the interval timer on every path now.
Tested on an EFR32MG24 (BRD4186B) with and without DMA, with immediate
and with deferred logging: a channel on an unallocated analog bus,
alone, with extra samplings and as one entry of a scan at 1024x
oversampling, and in a sequence with an interval, fails with -EIO and
one logged error, and the reads that follow are correct. Interrupt
priorities that let the DMA callback preempt the IADC handler were not
tested.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Without DMA the scan FIFO is read out in the SCANTABLEDONE interrupt,
but it holds only 8 results (4 on xG21, xG22, xG27 and xG29) while a
sequence may name up to 16 channels. A longer sequence overflows the
FIFO: the first results are delivered, the rest is lost and the read
fails with -EIO.
Reading the FIFO out on its data valid level interrupt instead would
depend on interrupt latency, with a conversion taking as little as a
few microseconds. Convert the channels of a sampling in parts that fit
the FIFO instead, starting the next part from the interrupt that read
out the previous one. The DMA path is unchanged.
Tested on an EFR32MG24 (BRD4186B): sequences of 9 and 16 channels,
300 reads of 16 channels with four distinct inputs checked sample by
sample, a 9 channel subset with extra samplings, and 9 channels at 20-bit
resolution.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
When a scan ends with an error flag set, iadc_isr() first calls
adc_context_on_sampling_done(), which completes the sequence, and then
adc_context_complete() with -EIO. The first completion wakes the
reader, the second one leaves the context's semaphore signaled. Every
following adc_read() then takes that stale signal, returns 0 before its
own conversion has run and gets its buffer filled by the ISR after the
call has returned, which leaves the semaphore signaled once more. Later
errors are reported as success for the same reason, and a sequence with
extra samplings keeps sampling after the error.
Handle the error first and return, so that a sequence is completed
exactly once. adc_context_complete() does not stop the timer of a
sequence with an interval the way adc_context_on_sampling_done() does,
so stop it here: left running, it makes later reads fail with -EBUSY.
Seen on an EFR32MG24 (BRD4186B) with a scan FIFO overflow and with a
channel whose analog bus is not allocated to the IADC: the reads after
the failing one returned 0 with their buffers untouched. With this
change every failing read returns -EIO and the following reads are
correct.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>