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