Convert the RISC-V machine timer to system_timer_generic.h. The mtime
counter with its absolute mtimecmp compare is a COMPARE backend: the
driver keeps only z_clock_cycle_get() (mtime) and z_clock_set_compare()
(set_mtimecmp), and the core takes over the cycle-to-tick accounting, the
deadline math, the range clamp and the announce. smp_timer_init() primes
the per-hart comparator through z_clock_smp_prime() rather than reaching
into the core's baseline.
The public cycle counter applies the DT clock divider to raw mtime, so it
overrides the core's default sys_clock_cycle_get_32/64() via
Z_CLOCK_HAVE_CYCLE_GET_32/64. Behaviour is unchanged; timer_api and
context pass on qemu_riscv64.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Every tickless system-timer driver reimplements the same tick accounting
by hand: the cycle-to-tick division, the announce baseline
(last_cycle/last_tick/last_elapsed), the tick-aligned deadline
computation and the range clamp. The logic is identical across the
free-running-compare drivers (arm_arch_timer, riscv_machine_timer, hpet,
...) down to the copied overflow-guard constant, and the small
divergences between the hand-rolled copies are a recurring source of
timer bugs.
Add system_timer_generic.h, an implementation header a driver includes
to get that accounting for free. It emits the tick-facing contract the
kernel calls (sys_clock_set_timeout(), sys_clock_elapsed(),
sys_clock_cycle_get_32/64()) and owns the baseline state, so the driver
is left with only cycle-domain primitives: read the counter, arm the
comparator (or program a relative reload), acknowledge the interrupt.
The header is included, not linked: the driver defines its constants and
static-inline primitives first, so the core inlines and constant-folds
against them (the per-tick divide becomes a multiply-shift, an unused
backend path is eliminated) on a plain -Os build with no LTO. Because
the header defines the global sys_clock_* symbols, a build that pulls in
two system timers fails at link time, which is the correct outcome. It
lives beside the drivers rather than under include/, as it is private to
them.
The core is complete on its own; the conversions that follow only use
it, they do not extend it:
- Two backends: COMPARE (free-running counter plus an absolute compare
register) and RELOAD (a relative down-counter, assumed to auto-reload
so a non-tickless kernel needs no per-tick re-arm).
- Counter width is a CYCLES_WIDTH knob: the core masks every delta to
that width, so a counter narrower than 64 bits is used as-is, without
software extension. The default is the native register width.
- CYCLES_MAX bounds how far ahead a deadline is armed: half the counter
span by default (the upper half is IRQ-latency headroom), a quarter
span with Z_CLOCK_COUNTER_NONMONOTONIC, where the upper half instead
flags a counter that momentarily reads backwards (a global timer seen
from another CPU under QEMU SMP), so such a read is reported as no
elapse rather than a huge forward jump.
- The cycle rate is a CYCLES_PER_SEC knob (default the kernel system
clock rate), from which the core derives the cycles per tick: a
build-time-constant rate folds the division; a run-time rate
(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) is precomputed once in
z_clock_init() and refreshed by z_clock_rescale() on a frequency
change, so the driver never states cycles-per-tick itself.
- Init and SMP bring-up helpers (z_clock_init(), z_clock_smp_prime()),
and a z_clock_announce_from() entry for a driver that must keep work
atomic with the announce.
No driver includes the header yet; conversions follow.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
With low-power idle handoff now going through sys_clock_idle_enter(),
nothing passes idle == true to sys_clock_set_timeout() any more, so the
argument is dead. Drop it: sys_clock_set_timeout(uint32_t ticks) now
means exactly "program the next tick, N ticks out", nothing else.
This updates the prototype, the weak default, every in-tree timer driver
definition (including the out-of-tree-style board timer under boards/),
and the core call sites. For the five drivers with low-power behaviour
this only removes the now-unused idle argument that the previous change
left on set_timeout(); the handling itself stays in their
sys_clock_idle_enter().
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The idle argument of sys_clock_set_timeout() carries a distinct signal:
the CPU is entering low-power idle, here is its wakeup. Only the PM and
SoC power paths produce it (the timeout core always passes false), and
only a few drivers act on it to hand off to a low-power wakeup timer.
Introduce a dedicated sys_clock_idle_enter() hook for that, so the two
idle==true callers (subsys/pm and soc/nxp/rw) call it instead of
sys_clock_set_timeout(). Its weak default just programs the wakeup via
sys_clock_set_timeout(), so a driver with no low-power handling needs
nothing.
The five drivers that acted on idle (cortex_m_systick, esp32, xtensa,
mcux_os, stm32_lptim) move that handling into their own
sys_clock_idle_enter(), keeping their exact behaviour. Where the idle
path was self-contained it moves wholesale (cortex_m_systick, mcux_os,
stm32_lptim); where it shares the timeout programming, idle_enter()
calls set_timeout() first and then does its idle work (esp32), or shares
a small private helper (xtensa). set_timeout() keeps its now-unused idle
argument for the moment; nobody passes idle==true to it any more, which
lets the next change drop the argument entirely.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
mcux_os keeps a wait_forever flag (consumed by the counter-overflow wakeup
path) that it set when sys_clock_set_timeout() was called with the
SYS_CLOCK_MAX_WAIT sentinel. The kernel no longer passes that value; the
no-deadline case now arrives via sys_clock_unused(). Set the flag there and
program the match as far out as the hardware allows; clear it on a real
sys_clock_set_timeout().
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The kernel now signals "no timeout pending, uptime may drift" by
calling sys_clock_unused() instead of passing the SYS_CLOCK_MAX_WAIT
sentinel to sys_clock_set_timeout(). Move each driver's sloppy-idle
handling out of sys_clock_set_timeout() and into a sys_clock_unused()
implementation, and drop the ticks == SYS_CLOCK_MAX_WAIT comparisons.
Drivers that actively stop the counter (cortex_m_systick, arcv2, hpet,
mcux_sysctr, mcux_lptmr, sam0, ite, infineon, mchp_xec, realtek,
stm32_lptim) do so in sys_clock_unused(). The free-running compare
timers (nrf_rtc, mcux_rtc_jdp, max32_rv32) instead follow the renesas
model and simply stop reprogramming: the last compare still catches the
counter wrap and the next real timeout re-arms them, so an explicit
maximum-length wait would only add a needless periodic wakeup. nrf_rtc
keeps a one-line sys_clock_unused() that clears the flag consumed by its
overflow-trigger path; mcux_rtc_jdp and max32_rv32 need no override at
all, like the renesas drivers.
cmsdk_apb is the exception: it is an auto-reload down-counter, so not
reprogramming would keep firing at the previous (possibly short)
interval. It programs the maximum reload instead, matching what
non-sloppy idle already does, with a note that stopping the counter
would be the better but riskier improvement.
Resume is unchanged: the next sys_clock_set_timeout() restarts the
driver.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The "no timeout pending, stop the clock" decision under
CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE was expressed by next_timeout()
returning SYS_CLOCK_MAX_WAIT verbatim as a magic sentinel, which every
timer driver then had to recognise. Move the decision into the core and
give it an explicit, resumable interface.
Add a weak sys_clock_unused() hook (no-op default): the kernel calls it
when the timeout list is empty and sloppy idle allows uptime to drift,
in place of programming a wait. A driver may override it to actively
halt its counter; one that does not simply stops being reprogrammed and
quiesces on its own, so sloppy idle now works for every driver. Resume
is the next sys_clock_set_timeout(), exactly as before; the core keeps
no paused state.
next_timeout() no longer special-cases sloppy idle, so its empty-list
and far-timeout arms collapse to the same capped budget and
SYS_CLOCK_MAX_WAIT loses its sentinel meaning. The decision lives in
reprogram_next(), used only at the two sites where the list can drain
(abort, end of announce); the add path always has a pending timeout and
calls sys_clock_set_timeout() directly.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The driver kept a private spinlock and used the legacy sys_clock_announce()
even though the kernel already holds its timer lock across the driver's
sys_clock_set_timeout() and sys_clock_elapsed() callbacks. Take that same
lock instead: the ISR and sys_clock_idle_exit() now use sys_clock_lock()
with sys_clock_announce_locked(), and set_timeout()/elapsed() simply assert
the lock is held rather than acquiring one of their own.
This drops a redundant lock and lets the upcoming low-power idle handling
avoid any locking of its own.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The driver hardcodes DT_NODELABEL(cpuapp_mram) which does not exist
when building for cpuflpr since the node is deleted in the cpuflpr
dtsi. Use DT_INST(0, soc_nv_flash) to resolve whichever soc-nv-flash
child is present under the controller, matching the RRAM driver.
Signed-off-by: Dhanoo Surasarang <dhanoo.surasarang@nordicsemi.no>
Read dev_data->rx_frag_list[tail] once into a local when preparing
each RX DMA descriptor instead of dereferencing it twice.
Assisted-by: Claude:opus-4.8
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The motion work handler already caches data->dev in a local, so reuse it
in both input_report_rel() calls instead of dereferencing data->dev
again.
Assisted-by: Claude:opus-4.8
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The get_time() and get_alarm_time() APIs left tm_yday, tm_isdst,
and tm_nsec uninitialized after populating the rtc_time structure.
Initialize tm_yday and tm_isdst to -1 (unsupported/unknown) and
tm_nsec to 0, matching the convention used by other RTC drivers
in Zephyr.
Signed-off-by: Farsin Nasar V A <farsin.nasarva@microchip.com>
Add NXP_WIFI_EXT_ANT_GAIN Kconfig option to enable runtime
configuration of net antenna gain per sub-band via host command
API.
This kconfig is only applicable to RW61x.
Signed-off-by: Gang Li <gang.li_1@nxp.com>
Accept extra `OK` responses after `AT+KSELACQ?` and `AT+KSRAT?`
during HL78xx initialization. This keeps the chat script aligned
on firmware versions that return an additional `OK` for these queries.
Signed-off-by: Zafer SEN <zafersn93@gmail.com>
Treat AutoRAT operation the same as GSM when determining whether
band configuration should be skipped on HL7812 devices.
Do not attempt to configure band selection when GSM is enabled.
This includes AutoRAT mode, since the modem may fall back to 2G if the
other configured RATs are unavailable. Because GSM band configuration
is not supported in this context, band programming should be skipped
whenever GSM can be selected by the modem.
This avoids sending unsupported band configuration commands and aligns
the band configuration logic with the modem's RAT capabilities.
Signed-off-by: Zafer SEN <zafersn93@gmail.com>
Even though HFXO24M automatically starts HFXO, it is much easier to
manage if HFXO is managed by software. Add requesting of HFXO when
HFXO24M is started.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The driver reads the rate of the configured clock source and
calculates the timing divider against it, but never programs
the hardware mux that selects that source. The mux keeps its
reset value, so the peripheral runs from XTAL while the
divider assumes a PLL rate.
On esp32p4 the default source is the 480 MHz SPLL and the
reset value selects the 40 MHz XTAL, making every transfer 12
times slower than requested: a 1 MHz request measures 83 kHz.
Program the mux at init so it matches the rate the divider is
calculated from.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Unifies documentation for haptic drivers. Previously, CS40L26/27
showed up under "Files" in Haptics documentation while the other
three drivers showed up under "Topics".
Signed-off-by: Liam Ogletree <liam.ogletree@cirrus.com>
Adopt gptimer retention API and attach sleep retention modules
to effectively enable TOP PD power down.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Adopt mcpwm retention API and attach sleep retention modules to
effectively enable TOP PD power down.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Without ATTR_ATTACH and sleep_retention_module_attach(), GDMA channels
are created but not retained, so peripheral_domain_pd_allowed() stays
false and TOP never powers down in light sleep. Fix lowers light sleep
current when GDMA and peripheral power down are enabled.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Recent HAL update moved GDMA sleep-retention definitions from
hal/gdma_periph.h into the esp_driver_dma component. Include gdma_priv.h
and use the new gdma_retention_desc_t / gdma_retention_infos names in
place of the removed gdma_chx_reg_ctx_link_t / gdma_chx_regs_retention.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Replace explicit == true/false comparisons with idiomatic boolean
expressions in pwm_siwx91x_set_cycles().
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
This patch adds PM runtime management for the PWM peripheral. It allows
to block CPU from entering the sleep state when PWM is active.
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
This patch ensure that clock_control_get_rate function returns the
correct clock rate for the PWM peripheral. PWM is clocked from M4
processor clock.
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
Use the MCXL WWDT clock gate and clock frequency helper when
handling MCUX_WWDT0_CLK.
MCXL uses kCLOCK_GateWWDT0 and CLOCK_GetWwdtClkFreq(), unlike some
other LPC-style platforms that use kCLOCK_Wwdt0 and CLOCK_GetWdtClkFreq().
Signed-off-by: Samuel Slesar <samuel.slesar@nxp.com>
Add PM support for HCI ESP32 driver. Update sleep retention
config for BLE power management.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Add the ability to run cameras in a logical
snapshot mode instead of always running
in video mode. In particular, the camera
starts when you ask for an image to be dequeued
and stops when it receives an image.
There are two ways to setup to run in this mode:
a) Tell it to do so in the overlay by giving the DCMI object
the property: snapshot-mode
b) At run time: I added a video control: VIDEO_CID_SNAPSHOT_MODE
Which can have the values
0 - normal - continuous video mode
1 - snapshot - snapshot mode enabled.
As mentioned in the snapshot modes, the HAL DMA is stopped after each
image and restarted when the user asks for another image. I added a
timeout default to 1 second, that handles the case where sometimes
the HAL is silently not successful in retrieving an image.
Signed-off-by: Kurt Eckhardt <kurte@rockisland.com>
When HAL_DCM_Stop return an error code, their failure does not
appear to be a real failure, but instead it is more like it
simply did not have to do anything. As such changed from reporting
it from LOG_WRN to LOG_DBG
Signed-off-by: Kurt Eckhardt <kurte@rockisland.com>
So it is only built when needed, and we avoid a compiler warning:
bmp581.c:59:19: error: unused function 'bmp581_pm_busy_check'
The issue was there since c68a25e4d5
but only became apparent in CI when its test was added in
f0802b645b
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
TX path: build a dma_block_config chain from net_pkt->frags and pass it
directly to dma_config(), eliminating net_pkt_read() into a static
buffer.
RX path: reserve one networking-stack net_buf per RX DMA descriptor via
net_pkt_get_reserve_rx_data(); on completion link the buf into a net_pkt
via net_pkt_frag_add() and pass it to net_recv_data() without memcpy.
Signed-off-by: Venkatesh Odela <venkatesh.odela@amd.com>
Two issues fixed for multi-fragment scatter-gather TX support:
- Completion callback was fired per descriptor; now fires only on the
EOF descriptor so the ethernet driver unrefs net_pkt once per packet.
- Ring reset (memset, index reset, CURDESC write) is skipped when the
DMA is not halted to avoid corrupting an active ring.
Signed-off-by: Venkatesh Odela <venkatesh.odela@amd.com>
Replace the fixed I2C_TRANSFER_TIMEOUT constant with a per-instance
k_timeout_t field stored in the driver config struct. The field is
k_timeout_t transfer_timeout, initialized at compile time using
I2C_DT_INST_TRANSFER_TIMEOUT() which resolves the timeout with the
following priority:
1. zephyr,transfer-timeout-ms DT property on the controller node
2. CONFIG_I2C_TRANSFER_TIMEOUT_MS (Kconfig default)
3. K_FOREVER when the resolved value is 0
All k_sem_take() and sys_timepoint_calc() call sites in v1 and v2
use cfg->transfer_timeout directly -- no helper function needed.
Boards that omit the zephyr,transfer-timeout-ms DT property see no
behavioural change; falls back to CONFIG_I2C_TRANSFER_TIMEOUT_MS.
Signed-off-by: BhuvanChandra DV <bhuvanchandra.dv@rapyuta-robotics.com>
channel_max holds the channel count, so accepting a channel equal
to it read one past the irq_sources array and let callers index
the callback arrays out of bounds.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The async-prescaler default referenced _HSE_ASYNC_PRESCALER, a
truncated spelling of RTC_HSE_ASYNC_PRESCALER that is defined
nowhere, breaking the build for HSE-clocked RTC configurations
without the async-prescaler property.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The channel_info pointer was formed before the channel == -1 check,
creating an out-of-bounds pointer for every unmapped channel. Move
the lookup after the guard.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The I2C_SPEED_FAST_PLUS case fell through into the unsupported
I2C_SPEED_HIGH case and returned -EIO. Add the missing break.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
DT_INST_NODE_HAS_PROP was spelled with hyphens in the sda_hold_tx
initializer, so the i2c-sda-hold-time-ns property was silently
ignored.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
DT_INST_NODE_HAS_PROP() reports whether a property is defined, not
the value of a boolean property. Binding-defined boolean properties
remain defined with value zero when absent, so the existing guards
still compile the SIRC paths on MCXW72.
Use DT_INST_PROP() for every sirc-supported guard. This excludes the
SIRC SDK calls on MCXW72 while preserving them on MCXW70 and MCXW71.
Verified with the three MCXW72 OpenThread configurations that failed
in Twister and with cpp.main.minimal on MCXW71.
Assisted-by: Codex:gpt-5
Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
For ADCs that use a common register for sampling times, improve the error
message when the common registers are already set and can't accept a new
value.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Implement counter capture callbacks for MCUX QTMR timer channels. Each
Zephyr counter device maps to one QTMR channel, so the API accepts
channel 0 and uses the DT secondary-source property as the capture
input.
Reject capture in modes that already consume the secondary source and
keep alarm and capture ownership exclusive on the channel. Add reset
support so generic counter capture tests can prepare the timer state.
Signed-off-by: Holt Sun <holt.sun@nxp.com>