QEMU v11.1.0 added a virtio RTC device (virtio-rtc-pci and
virtio-rtc-device), but U-Boot has no driver for it. This series adds
one: it finds the first UTC clock on the device and reads it through
the RTC uclass, so "date" and anything else using dm_rtc_get() work on
any virtio-capable QEMU target, not only on machines that also have a
goldfish or PL031 RTC.

Patch 1 adds the driver, patch 2 updates the virtio documentation, and
patch 3 adds a MAINTAINERS entry.

Tested on QEMU v11.1.2 with qemu-riscv64_defconfig:

- With -device virtio-rtc-pci and with -device virtio-rtc-device, the
  driver probes. As "date" uses the first RTC, which is the goldfish
  RTC on this machine, I also built with RTC_GOLDFISH disabled: "date"
  then read the host time from the virtio RTC, advancing between reads.
- Setting the time fails with -ENOSYS, as the clocks are read-only.
- With RTC_GOLDFISH disabled and no virtio RTC device, "date" fails
  cleanly with err=-19.

qemu-riscv32_defconfig also builds the driver without libgcc helpers
for the 64-bit division. On sandbox, where VIRTIO_RTC now defaults to y,
"ut dm rtc*" and "ut dm virtio*" pass.

The alarm feature is not supported. I have not added a pytest because
the CI Docker image builds QEMU v10.1.2, which does not have the
device yet.

Hung-Chun Tseng (3):
  virtio: rtc: Add virtio RTC driver
  doc: virtio: Mention the RTC device
  MAINTAINERS: Add entry for virtio RTC

 MAINTAINERS                         |   5 +
 doc/develop/driver-model/virtio.rst |   4 +-
 drivers/virtio/Kconfig              |   9 ++
 drivers/virtio/Makefile             |   1 +
 drivers/virtio/virtio-uclass.c      |   1 +
 drivers/virtio/virtio_rtc.c         | 206 ++++++++++++++++++++++++++++
 include/virtio.h                    |   4 +-
 7 files changed, 228 insertions(+), 2 deletions(-)
 create mode 100644 drivers/virtio/virtio_rtc.c

-- 
2.43.0

Reply via email to