drivers: counter: add calibration API and Xilinx ZynqMP RTC driver#107684
drivers: counter: add calibration API and Xilinx ZynqMP RTC driver#107684Harini-T wants to merge 3 commits intozephyrproject-rtos:mainfrom
Conversation
bjarki-andreasen
left a comment
There was a problem hiding this comment.
Looks pretty spot on. Please implement this API in a driver or two as part of this PR to provide a good foundation for its inclusion.
@bjarki-andreasen Would referencing these stacked PRs work, or would you prefer the driver folded into this PR? |
|
Doesn't it belong to clock_control API? Counter is just a client of a certain clock source and it seems to me that this is a calibration of that clock source. |
The calibration is not of the clock itself, its part of the RTC (a low power counter in this case) which applies calibration to its internal tick value. There is usually some hardware which can take the 1Hz output from the RTC and use that as an input, but the RTC is an actual counter with capture compare registers etc. |
If you could include this commit 34615be#diff-ebb7d630d71df3f66af55e47f382a70d29179d45fb00f33e10ba7c2626950306 in this PR, that would be really helpful, APIs require atleast one in tree user to be approved. |
Add optional set_calibration/get_calibration operations to the counter driver API. Calibration is specified in parts per billion (ppb). The operations are gated behind CONFIG_COUNTER_CALIBRATION and return -ENOSYS if not implemented by the driver. Signed-off-by: Harini T <harini.t@amd.com>
Add devicetree binding for the Xilinx Zynq Ultrascale+ MPSoC Real Time Clock (xlnx,zynqmp-rtc) as a counter device. The binding describes the RTC hardware block which provides a seconds counter with alarm and seconds-tick interrupts. Signed-off-by: Harini T <harini.t@amd.com>
Add a counter driver for the Xilinx Zynq Ultrascale+ MPSoC Real Time Clock. The hardware provides a 32-bit seconds counter driven by an external crystal oscillator, one alarm channel, and a calibration register with integer and fractional tick adjustment. The driver implements the Zephyr counter API and is intended to be used with the rtc_counter wrapper to expose the standard RTC API. The RTC oscillator runs continuously so start() and stop() return -ENOTSUP. Calibration support is gated by CONFIG_COUNTER_CALIBRATION. Signed-off-by: Harini T <harini.t@amd.com>
3aa6f95 to
576b51a
Compare
|



Summary
Add optional
set_calibration/get_calibrationoperations to the counter driver API, enabling counter drivers to expose hardware clock calibration through a generic interface, and implement them in a new Xilinx ZynqMP RTC driver.Context
The
rtc_counterwrapper (zephyr,rtc-counter) bridges the counter API to the RTC API, allowing a hardware counter to be used as an RTC device. The RTC API already supports calibration viartc_set_calibration()/rtc_get_calibration()(in ppb), but the counter API has no equivalent operations. As a result, the wrapper currently stubs out calibration with-ENOTSUP, and any hardware calibration capability is lost. This was identified during the Xilinx ZynqMP RTC upstreaming effort (#96720), where the maintainer directed that the hardware be implemented as a counter driver with thertc_counterwrapper, and that calibration support be added to the counter API first:This PR adds the counter-side calibration API and includes the Xilinx ZynqMP RTC driver as the first in-tree implementation.
Commits
Commit 1:
drivers: counter: add calibration APIcounter_api_set_calibration/counter_api_get_calibrationtypedefs and fields tocounter_driver_api(gated byCONFIG_COUNTER_CALIBRATION)CONFIG_COUNTER_CALIBRATIONKconfig optionCommit 2:
dts: bindings: counter: add Xilinx ZynqMP RTC bindingxlnx,zynqmp-rtcunderdts/bindings/counter/Commit 3:
drivers: counter: add Xilinx ZynqMP RTC driverdrivers/counter/counter_xlnx_zynqmp_rtc.cCONFIG_COUNTER_CALIBRATION)start()/stop()return-ENOTSUPDEVICE_MMIO_NAMEDfor portable MMIO accessCOUNTER_XLNX_ZYNQMP_RTCDesign Decisions
rtc_counterwrapper can be a trivial passthrough with zero unit conversion.NULLand the syscalls return-ENOSYS.CONFIG_COUNTER_CALIBRATIONcontrols inclusion of the struct fields, matching the pattern used byCONFIG_RTC_CALIBRATIONandCONFIG_COUNTER_64BITS_TICKS.Testing
tests/drivers/counter/counter_basic_api/onnative_sim/native/64withCONFIG_COUNTER_CALIBRATION=n(default) — verifies no regression to existing counter functionality.CONFIG_COUNTER_CALIBRATION=y— verifies the new API compiles and existing tests pass with the extended struct.tests/drivers/rtc/rtc_api/onnative_sim/native/64— verifiesrtc_counter.c(which includescounter.h) still compiles with the header changes.checkpatch.plandclang-formatpass with no warnings.Related
rtc_counterwrapper (merged)rtc_counterwrapper enhancements (calibration passthrough,counter_set_value()usage,counter_stop()tolerance)