npcm7xx_timer.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Nuvoton NPCM7xx Timer Controller
  3. *
  4. * Copyright 2020 Google LLC
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. */
  16. #ifndef NPCM7XX_TIMER_H
  17. #define NPCM7XX_TIMER_H
  18. #include "exec/memory.h"
  19. #include "hw/sysbus.h"
  20. #include "qemu/timer.h"
  21. /* Each Timer Module (TIM) instance holds five 25 MHz timers. */
  22. #define NPCM7XX_TIMERS_PER_CTRL (5)
  23. /*
  24. * Number of registers in our device state structure. Don't change this without
  25. * incrementing the version_id in the vmstate.
  26. */
  27. #define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t))
  28. /* The basic watchdog timer period is 2^14 clock cycles. */
  29. #define NPCM7XX_WATCHDOG_BASETIME_SHIFT 14
  30. #define NPCM7XX_WATCHDOG_RESET_GPIO_OUT "npcm7xx-clk-watchdog-reset-gpio-out"
  31. typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState;
  32. /**
  33. * struct NPCM7xxBaseTimer - Basic functionality that both regular timer and
  34. * watchdog timer use.
  35. * @qtimer: QEMU timer that notifies us on expiration.
  36. * @expires_ns: Absolute virtual expiration time.
  37. * @remaining_ns: Remaining time until expiration if timer is paused.
  38. */
  39. typedef struct NPCM7xxBaseTimer {
  40. QEMUTimer qtimer;
  41. int64_t expires_ns;
  42. int64_t remaining_ns;
  43. } NPCM7xxBaseTimer;
  44. /**
  45. * struct NPCM7xxTimer - Individual timer state.
  46. * @ctrl: The timer module that owns this timer.
  47. * @irq: GIC interrupt line to fire on expiration (if enabled).
  48. * @base_timer: The basic timer functionality for this timer.
  49. * @tcsr: The Timer Control and Status Register.
  50. * @ticr: The Timer Initial Count Register.
  51. */
  52. typedef struct NPCM7xxTimer {
  53. NPCM7xxTimerCtrlState *ctrl;
  54. qemu_irq irq;
  55. NPCM7xxBaseTimer base_timer;
  56. uint32_t tcsr;
  57. uint32_t ticr;
  58. } NPCM7xxTimer;
  59. /**
  60. * struct NPCM7xxWatchdogTimer - The watchdog timer state.
  61. * @ctrl: The timer module that owns this timer.
  62. * @irq: GIC interrupt line to fire on expiration (if enabled).
  63. * @reset_signal: The GPIO used to send a reset signal.
  64. * @base_timer: The basic timer functionality for this timer.
  65. * @wtcr: The Watchdog Timer Control Register.
  66. */
  67. typedef struct NPCM7xxWatchdogTimer {
  68. NPCM7xxTimerCtrlState *ctrl;
  69. qemu_irq irq;
  70. qemu_irq reset_signal;
  71. NPCM7xxBaseTimer base_timer;
  72. uint32_t wtcr;
  73. } NPCM7xxWatchdogTimer;
  74. /**
  75. * struct NPCM7xxTimerCtrlState - Timer Module device state.
  76. * @parent: System bus device.
  77. * @iomem: Memory region through which registers are accessed.
  78. * @index: The index of this timer module.
  79. * @tisr: The Timer Interrupt Status Register.
  80. * @timer: The five individual timers managed by this module.
  81. * @watchdog_timer: The watchdog timer managed by this module.
  82. */
  83. struct NPCM7xxTimerCtrlState {
  84. SysBusDevice parent;
  85. MemoryRegion iomem;
  86. uint32_t tisr;
  87. Clock *clock;
  88. NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL];
  89. NPCM7xxWatchdogTimer watchdog_timer;
  90. };
  91. #define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
  92. #define NPCM7XX_TIMER(obj) \
  93. OBJECT_CHECK(NPCM7xxTimerCtrlState, (obj), TYPE_NPCM7XX_TIMER)
  94. #endif /* NPCM7XX_TIMER_H */