gxp-timer.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * GXP timer driver
  4. *
  5. * (C) Copyright 2022 Hewlett Packard Enterprise Development LP.
  6. * Author: Nick Hawkins <nick.hawkins@hpe.com>
  7. * Author: Jean-Marie Verdun <verdun@hpe.com>
  8. */
  9. #include <clk.h>
  10. #include <dm.h>
  11. #include <timer.h>
  12. #include <asm/io.h>
  13. #define USTIMELO 0x18
  14. #define USTIMEHI 0x1C
  15. struct gxp_timer_priv {
  16. void __iomem *base;
  17. };
  18. static u64 gxp_timer_get_count(struct udevice *dev)
  19. {
  20. struct gxp_timer_priv *priv = dev_get_priv(dev);
  21. u64 val;
  22. val = readl(priv->base + USTIMEHI);
  23. val = (val << 32) | readl(priv->base + USTIMELO);
  24. return val;
  25. }
  26. static int gxp_timer_probe(struct udevice *dev)
  27. {
  28. struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
  29. struct gxp_timer_priv *priv = dev_get_priv(dev);
  30. priv->base = dev_read_addr_ptr(dev);
  31. if (!priv->base)
  32. return -ENOENT;
  33. uc_priv->clock_rate = 1000000;
  34. return 0;
  35. }
  36. static const struct timer_ops gxp_timer_ops = {
  37. .get_count = gxp_timer_get_count,
  38. };
  39. static const struct udevice_id gxp_timer_ids[] = {
  40. { .compatible = "hpe,gxp-timer" },
  41. {}
  42. };
  43. U_BOOT_DRIVER(gxp_timer) = {
  44. .name = "gxp-timer",
  45. .id = UCLASS_TIMER,
  46. .of_match = gxp_timer_ids,
  47. .priv_auto = sizeof(struct gxp_timer_priv),
  48. .probe = gxp_timer_probe,
  49. .ops = &gxp_timer_ops,
  50. .flags = DM_FLAG_PRE_RELOC,
  51. };