andes_plmt.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2019, Rick Chen <rick@andestech.com>
  4. *
  5. * U-Boot syscon driver for Andes's Platform Level Machine Timer (PLMT).
  6. * The PLMT block holds memory-mapped mtime register
  7. * associated with timer tick.
  8. */
  9. #include <common.h>
  10. #include <dm.h>
  11. #include <regmap.h>
  12. #include <syscon.h>
  13. #include <asm/io.h>
  14. #include <asm/syscon.h>
  15. #include <linux/err.h>
  16. /* mtime register */
  17. #define MTIME_REG(base) ((ulong)(base))
  18. DECLARE_GLOBAL_DATA_PTR;
  19. #define PLMT_BASE_GET(void) \
  20. do { \
  21. long *ret; \
  22. \
  23. if (!gd->arch.plmt) { \
  24. ret = syscon_get_first_range(RISCV_SYSCON_PLMT); \
  25. if (IS_ERR(ret)) \
  26. return PTR_ERR(ret); \
  27. gd->arch.plmt = ret; \
  28. } \
  29. } while (0)
  30. int riscv_get_time(u64 *time)
  31. {
  32. PLMT_BASE_GET();
  33. *time = readq((void __iomem *)MTIME_REG(gd->arch.plmt));
  34. return 0;
  35. }
  36. static const struct udevice_id andes_plmt_ids[] = {
  37. { .compatible = "riscv,plmt0", .data = RISCV_SYSCON_PLMT },
  38. { }
  39. };
  40. U_BOOT_DRIVER(andes_plmt) = {
  41. .name = "andes_plmt",
  42. .id = UCLASS_SYSCON,
  43. .of_match = andes_plmt_ids,
  44. .flags = DM_FLAG_PRE_RELOC,
  45. };