sp805.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <drivers/arm/sp805.h>
  8. #include <lib/mmio.h>
  9. /* Inline register access functions */
  10. static inline void sp805_write_wdog_load(uintptr_t base, uint32_t value)
  11. {
  12. mmio_write_32(base + SP805_WDOG_LOAD_OFF, value);
  13. }
  14. static inline void sp805_write_wdog_ctrl(uintptr_t base, uint32_t value)
  15. {
  16. mmio_write_32(base + SP805_WDOG_CTR_OFF, value);
  17. }
  18. static inline void sp805_write_wdog_lock(uintptr_t base, uint32_t value)
  19. {
  20. mmio_write_32(base + SP805_WDOG_LOCK_OFF, value);
  21. }
  22. /* Public API implementation */
  23. void sp805_start(uintptr_t base, unsigned int ticks)
  24. {
  25. sp805_write_wdog_load(base, ticks);
  26. sp805_write_wdog_ctrl(base, SP805_CTR_RESEN | SP805_CTR_INTEN);
  27. /* Lock registers access */
  28. sp805_write_wdog_lock(base, 0U);
  29. }
  30. void sp805_stop(uintptr_t base)
  31. {
  32. sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
  33. sp805_write_wdog_ctrl(base, 0U);
  34. }
  35. void sp805_refresh(uintptr_t base, unsigned int ticks)
  36. {
  37. sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
  38. sp805_write_wdog_load(base, ticks);
  39. sp805_write_wdog_lock(base, 0U);
  40. }