imx_gpt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * i.MX GPT Timer
  3. *
  4. * Copyright (c) 2008 OK Labs
  5. * Copyright (c) 2011 NICTA Pty Ltd
  6. * Originally written by Hans Jiang
  7. * Updated by Peter Chubb
  8. * Updated by Jean-Christophe Dubois <jcd@tribudubois.net>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. * THE SOFTWARE.
  27. */
  28. #ifndef IMX_GPT_H
  29. #define IMX_GPT_H
  30. #include "hw/sysbus.h"
  31. #include "hw/ptimer.h"
  32. #include "hw/misc/imx_ccm.h"
  33. #include "qom/object.h"
  34. /*
  35. * GPT : General purpose timer
  36. *
  37. * This timer counts up continuously while it is enabled, resetting itself
  38. * to 0 when it reaches GPT_TIMER_MAX (in freerun mode) or when it
  39. * reaches the value of one of the ocrX (in periodic mode).
  40. */
  41. #define GPT_TIMER_MAX 0XFFFFFFFFUL
  42. /* Control register. Not all of these bits have any effect (yet) */
  43. #define GPT_CR_EN (1 << 0) /* GPT Enable */
  44. #define GPT_CR_ENMOD (1 << 1) /* GPT Enable Mode */
  45. #define GPT_CR_DBGEN (1 << 2) /* GPT Debug mode enable */
  46. #define GPT_CR_WAITEN (1 << 3) /* GPT Wait Mode Enable */
  47. #define GPT_CR_DOZEN (1 << 4) /* GPT Doze mode enable */
  48. #define GPT_CR_STOPEN (1 << 5) /* GPT Stop Mode Enable */
  49. #define GPT_CR_CLKSRC_SHIFT (6)
  50. #define GPT_CR_CLKSRC_MASK (0x7)
  51. #define GPT_CR_FRR (1 << 9) /* Freerun or Restart */
  52. #define GPT_CR_SWR (1 << 15) /* Software Reset */
  53. #define GPT_CR_IM1 (3 << 16) /* Input capture channel 1 mode (2 bits) */
  54. #define GPT_CR_IM2 (3 << 18) /* Input capture channel 2 mode (2 bits) */
  55. #define GPT_CR_OM1 (7 << 20) /* Output Compare Channel 1 Mode (3 bits) */
  56. #define GPT_CR_OM2 (7 << 23) /* Output Compare Channel 2 Mode (3 bits) */
  57. #define GPT_CR_OM3 (7 << 26) /* Output Compare Channel 3 Mode (3 bits) */
  58. #define GPT_CR_FO1 (1 << 29) /* Force Output Compare Channel 1 */
  59. #define GPT_CR_FO2 (1 << 30) /* Force Output Compare Channel 2 */
  60. #define GPT_CR_FO3 (1 << 31) /* Force Output Compare Channel 3 */
  61. #define GPT_SR_OF1 (1 << 0)
  62. #define GPT_SR_OF2 (1 << 1)
  63. #define GPT_SR_OF3 (1 << 2)
  64. #define GPT_SR_ROV (1 << 5)
  65. #define GPT_IR_OF1IE (1 << 0)
  66. #define GPT_IR_OF2IE (1 << 1)
  67. #define GPT_IR_OF3IE (1 << 2)
  68. #define GPT_IR_ROVIE (1 << 5)
  69. #define TYPE_IMX25_GPT "imx25.gpt"
  70. #define TYPE_IMX31_GPT "imx31.gpt"
  71. #define TYPE_IMX6_GPT "imx6.gpt"
  72. #define TYPE_IMX6UL_GPT "imx6ul.gpt"
  73. #define TYPE_IMX7_GPT "imx7.gpt"
  74. #define TYPE_IMX8MP_GPT "imx8mp.gpt"
  75. #define TYPE_IMX_GPT TYPE_IMX25_GPT
  76. typedef struct IMXGPTState IMXGPTState;
  77. DECLARE_INSTANCE_CHECKER(IMXGPTState, IMX_GPT,
  78. TYPE_IMX_GPT)
  79. struct IMXGPTState {
  80. /*< private >*/
  81. SysBusDevice parent_obj;
  82. /*< public >*/
  83. ptimer_state *timer;
  84. MemoryRegion iomem;
  85. IMXCCMState *ccm;
  86. uint32_t cr;
  87. uint32_t pr;
  88. uint32_t sr;
  89. uint32_t ir;
  90. uint32_t ocr1;
  91. uint32_t ocr2;
  92. uint32_t ocr3;
  93. uint32_t icr1;
  94. uint32_t icr2;
  95. uint32_t cnt;
  96. uint32_t next_timeout;
  97. uint32_t next_int;
  98. uint32_t freq;
  99. qemu_irq irq;
  100. const IMXClk *clocks;
  101. };
  102. #endif /* IMX_GPT_H */