andes_plmt_timer.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2019, Rick Chen <rick@andestech.com>
  4. * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
  5. *
  6. * U-Boot syscon driver for Andes's Platform Level Machine Timer (PLMT).
  7. * The PLMT block holds memory-mapped mtime register
  8. * associated with timer tick.
  9. */
  10. #include <common.h>
  11. #include <dm.h>
  12. #include <timer.h>
  13. #include <asm/io.h>
  14. #include <linux/err.h>
  15. /* mtime register */
  16. #define MTIME_REG(base) ((ulong)(base))
  17. static u64 andes_plmt_get_count(struct udevice *dev)
  18. {
  19. return readq((void __iomem *)MTIME_REG(dev->priv));
  20. }
  21. static const struct timer_ops andes_plmt_ops = {
  22. .get_count = andes_plmt_get_count,
  23. };
  24. static int andes_plmt_probe(struct udevice *dev)
  25. {
  26. dev->priv = dev_read_addr_ptr(dev);
  27. if (!dev->priv)
  28. return -EINVAL;
  29. return timer_timebase_fallback(dev);
  30. }
  31. static const struct udevice_id andes_plmt_ids[] = {
  32. { .compatible = "riscv,plmt0" },
  33. { }
  34. };
  35. U_BOOT_DRIVER(andes_plmt) = {
  36. .name = "andes_plmt",
  37. .id = UCLASS_TIMER,
  38. .of_match = andes_plmt_ids,
  39. .ops = &andes_plmt_ops,
  40. .probe = andes_plmt_probe,
  41. .flags = DM_FLAG_PRE_RELOC,
  42. };