1781182e1SJean-Christophe Dubois /*
2781182e1SJean-Christophe Dubois * IMX6UL Clock Control Module
3781182e1SJean-Christophe Dubois *
4781182e1SJean-Christophe Dubois * Copyright (c) 2018 Jean-Christophe Dubois <jcd@tribudubois.net>
5781182e1SJean-Christophe Dubois *
6781182e1SJean-Christophe Dubois * This work is licensed under the terms of the GNU GPL, version 2 or later.
7781182e1SJean-Christophe Dubois * See the COPYING file in the top-level directory.
8781182e1SJean-Christophe Dubois *
9781182e1SJean-Christophe Dubois * To get the timer frequencies right, we need to emulate at least part of
10781182e1SJean-Christophe Dubois * the CCM.
11781182e1SJean-Christophe Dubois */
12781182e1SJean-Christophe Dubois
13781182e1SJean-Christophe Dubois #include "qemu/osdep.h"
14781182e1SJean-Christophe Dubois #include "hw/registerfields.h"
15d6454270SMarkus Armbruster #include "migration/vmstate.h"
16781182e1SJean-Christophe Dubois #include "hw/misc/imx6ul_ccm.h"
17781182e1SJean-Christophe Dubois #include "qemu/log.h"
180b8fa32fSMarkus Armbruster #include "qemu/module.h"
19781182e1SJean-Christophe Dubois
20781182e1SJean-Christophe Dubois #include "trace.h"
21781182e1SJean-Christophe Dubois
223d26d7d6SJean-Christophe Dubois static const uint32_t ccm_mask[CCM_MAX] = {
233d26d7d6SJean-Christophe Dubois [CCM_CCR] = 0xf01fef80,
243d26d7d6SJean-Christophe Dubois [CCM_CCDR] = 0xfffeffff,
253d26d7d6SJean-Christophe Dubois [CCM_CSR] = 0xffffffff,
263d26d7d6SJean-Christophe Dubois [CCM_CCSR] = 0xfffffef2,
273d26d7d6SJean-Christophe Dubois [CCM_CACRR] = 0xfffffff8,
283d26d7d6SJean-Christophe Dubois [CCM_CBCDR] = 0xc1f8e000,
293d26d7d6SJean-Christophe Dubois [CCM_CBCMR] = 0xfc03cfff,
303d26d7d6SJean-Christophe Dubois [CCM_CSCMR1] = 0x80700000,
313d26d7d6SJean-Christophe Dubois [CCM_CSCMR2] = 0xe01ff003,
323d26d7d6SJean-Christophe Dubois [CCM_CSCDR1] = 0xfe00c780,
333d26d7d6SJean-Christophe Dubois [CCM_CS1CDR] = 0xfe00fe00,
343d26d7d6SJean-Christophe Dubois [CCM_CS2CDR] = 0xf8007000,
353d26d7d6SJean-Christophe Dubois [CCM_CDCDR] = 0xf00fffff,
363d26d7d6SJean-Christophe Dubois [CCM_CHSCCDR] = 0xfffc01ff,
373d26d7d6SJean-Christophe Dubois [CCM_CSCDR2] = 0xfe0001ff,
383d26d7d6SJean-Christophe Dubois [CCM_CSCDR3] = 0xffffc1ff,
393d26d7d6SJean-Christophe Dubois [CCM_CDHIPR] = 0xffffffff,
403d26d7d6SJean-Christophe Dubois [CCM_CTOR] = 0x00000000,
413d26d7d6SJean-Christophe Dubois [CCM_CLPCR] = 0xf39ff01c,
423d26d7d6SJean-Christophe Dubois [CCM_CISR] = 0xfb85ffbe,
433d26d7d6SJean-Christophe Dubois [CCM_CIMR] = 0xfb85ffbf,
443d26d7d6SJean-Christophe Dubois [CCM_CCOSR] = 0xfe00fe00,
453d26d7d6SJean-Christophe Dubois [CCM_CGPR] = 0xfffc3fea,
463d26d7d6SJean-Christophe Dubois [CCM_CCGR0] = 0x00000000,
473d26d7d6SJean-Christophe Dubois [CCM_CCGR1] = 0x00000000,
483d26d7d6SJean-Christophe Dubois [CCM_CCGR2] = 0x00000000,
493d26d7d6SJean-Christophe Dubois [CCM_CCGR3] = 0x00000000,
503d26d7d6SJean-Christophe Dubois [CCM_CCGR4] = 0x00000000,
513d26d7d6SJean-Christophe Dubois [CCM_CCGR5] = 0x00000000,
523d26d7d6SJean-Christophe Dubois [CCM_CCGR6] = 0x00000000,
533d26d7d6SJean-Christophe Dubois [CCM_CMEOR] = 0xafffff1f,
543d26d7d6SJean-Christophe Dubois };
553d26d7d6SJean-Christophe Dubois
563d26d7d6SJean-Christophe Dubois static const uint32_t analog_mask[CCM_ANALOG_MAX] = {
573d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_ARM] = 0xfff60f80,
583d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_USB1] = 0xfffe0fbc,
593d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_USB2] = 0xfffe0fbc,
603d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_SYS] = 0xfffa0ffe,
613d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_SYS_SS] = 0x00000000,
623d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_SYS_NUM] = 0xc0000000,
633d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_SYS_DENOM] = 0xc0000000,
643d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_AUDIO] = 0xffe20f80,
653d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_AUDIO_NUM] = 0xc0000000,
663d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_AUDIO_DENOM] = 0xc0000000,
673d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_VIDEO] = 0xffe20f80,
683d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_VIDEO_NUM] = 0xc0000000,
693d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_VIDEO_DENOM] = 0xc0000000,
703d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PLL_ENET] = 0xffc20ff0,
713d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PFD_480] = 0x40404040,
723d26d7d6SJean-Christophe Dubois [CCM_ANALOG_PFD_528] = 0x40404040,
733d26d7d6SJean-Christophe Dubois [PMU_MISC0] = 0x01fe8306,
743d26d7d6SJean-Christophe Dubois [PMU_MISC1] = 0x07fcede0,
753d26d7d6SJean-Christophe Dubois [PMU_MISC2] = 0x005f5f5f,
763d26d7d6SJean-Christophe Dubois };
773d26d7d6SJean-Christophe Dubois
imx6ul_ccm_reg_name(uint32_t reg)78781182e1SJean-Christophe Dubois static const char *imx6ul_ccm_reg_name(uint32_t reg)
79781182e1SJean-Christophe Dubois {
80781182e1SJean-Christophe Dubois static char unknown[20];
81781182e1SJean-Christophe Dubois
82781182e1SJean-Christophe Dubois switch (reg) {
83781182e1SJean-Christophe Dubois case CCM_CCR:
84781182e1SJean-Christophe Dubois return "CCR";
85781182e1SJean-Christophe Dubois case CCM_CCDR:
86781182e1SJean-Christophe Dubois return "CCDR";
87781182e1SJean-Christophe Dubois case CCM_CSR:
88781182e1SJean-Christophe Dubois return "CSR";
89781182e1SJean-Christophe Dubois case CCM_CCSR:
90781182e1SJean-Christophe Dubois return "CCSR";
91781182e1SJean-Christophe Dubois case CCM_CACRR:
92781182e1SJean-Christophe Dubois return "CACRR";
93781182e1SJean-Christophe Dubois case CCM_CBCDR:
94781182e1SJean-Christophe Dubois return "CBCDR";
95781182e1SJean-Christophe Dubois case CCM_CBCMR:
96781182e1SJean-Christophe Dubois return "CBCMR";
97781182e1SJean-Christophe Dubois case CCM_CSCMR1:
98781182e1SJean-Christophe Dubois return "CSCMR1";
99781182e1SJean-Christophe Dubois case CCM_CSCMR2:
100781182e1SJean-Christophe Dubois return "CSCMR2";
101781182e1SJean-Christophe Dubois case CCM_CSCDR1:
102781182e1SJean-Christophe Dubois return "CSCDR1";
103781182e1SJean-Christophe Dubois case CCM_CS1CDR:
104781182e1SJean-Christophe Dubois return "CS1CDR";
105781182e1SJean-Christophe Dubois case CCM_CS2CDR:
106781182e1SJean-Christophe Dubois return "CS2CDR";
107781182e1SJean-Christophe Dubois case CCM_CDCDR:
108781182e1SJean-Christophe Dubois return "CDCDR";
109781182e1SJean-Christophe Dubois case CCM_CHSCCDR:
110781182e1SJean-Christophe Dubois return "CHSCCDR";
111781182e1SJean-Christophe Dubois case CCM_CSCDR2:
112781182e1SJean-Christophe Dubois return "CSCDR2";
113781182e1SJean-Christophe Dubois case CCM_CSCDR3:
114781182e1SJean-Christophe Dubois return "CSCDR3";
115781182e1SJean-Christophe Dubois case CCM_CDHIPR:
116781182e1SJean-Christophe Dubois return "CDHIPR";
117781182e1SJean-Christophe Dubois case CCM_CTOR:
118781182e1SJean-Christophe Dubois return "CTOR";
119781182e1SJean-Christophe Dubois case CCM_CLPCR:
120781182e1SJean-Christophe Dubois return "CLPCR";
121781182e1SJean-Christophe Dubois case CCM_CISR:
122781182e1SJean-Christophe Dubois return "CISR";
123781182e1SJean-Christophe Dubois case CCM_CIMR:
124781182e1SJean-Christophe Dubois return "CIMR";
125781182e1SJean-Christophe Dubois case CCM_CCOSR:
126781182e1SJean-Christophe Dubois return "CCOSR";
127781182e1SJean-Christophe Dubois case CCM_CGPR:
128781182e1SJean-Christophe Dubois return "CGPR";
129781182e1SJean-Christophe Dubois case CCM_CCGR0:
130781182e1SJean-Christophe Dubois return "CCGR0";
131781182e1SJean-Christophe Dubois case CCM_CCGR1:
132781182e1SJean-Christophe Dubois return "CCGR1";
133781182e1SJean-Christophe Dubois case CCM_CCGR2:
134781182e1SJean-Christophe Dubois return "CCGR2";
135781182e1SJean-Christophe Dubois case CCM_CCGR3:
136781182e1SJean-Christophe Dubois return "CCGR3";
137781182e1SJean-Christophe Dubois case CCM_CCGR4:
138781182e1SJean-Christophe Dubois return "CCGR4";
139781182e1SJean-Christophe Dubois case CCM_CCGR5:
140781182e1SJean-Christophe Dubois return "CCGR5";
141781182e1SJean-Christophe Dubois case CCM_CCGR6:
142781182e1SJean-Christophe Dubois return "CCGR6";
143781182e1SJean-Christophe Dubois case CCM_CMEOR:
144781182e1SJean-Christophe Dubois return "CMEOR";
145781182e1SJean-Christophe Dubois default:
146ca4af17cSPhilippe Mathieu-Daudé snprintf(unknown, sizeof(unknown), "%u ?", reg);
147781182e1SJean-Christophe Dubois return unknown;
148781182e1SJean-Christophe Dubois }
149781182e1SJean-Christophe Dubois }
150781182e1SJean-Christophe Dubois
imx6ul_analog_reg_name(uint32_t reg)151781182e1SJean-Christophe Dubois static const char *imx6ul_analog_reg_name(uint32_t reg)
152781182e1SJean-Christophe Dubois {
153781182e1SJean-Christophe Dubois static char unknown[20];
154781182e1SJean-Christophe Dubois
155781182e1SJean-Christophe Dubois switch (reg) {
156781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM:
157781182e1SJean-Christophe Dubois return "PLL_ARM";
158781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_SET:
159781182e1SJean-Christophe Dubois return "PLL_ARM_SET";
160781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_CLR:
161781182e1SJean-Christophe Dubois return "PLL_ARM_CLR";
162781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_TOG:
163781182e1SJean-Christophe Dubois return "PLL_ARM_TOG";
164781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1:
165781182e1SJean-Christophe Dubois return "PLL_USB1";
166781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_SET:
167781182e1SJean-Christophe Dubois return "PLL_USB1_SET";
168781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_CLR:
169781182e1SJean-Christophe Dubois return "PLL_USB1_CLR";
170781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_TOG:
171781182e1SJean-Christophe Dubois return "PLL_USB1_TOG";
172781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2:
173781182e1SJean-Christophe Dubois return "PLL_USB2";
174781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_SET:
175781182e1SJean-Christophe Dubois return "PLL_USB2_SET";
176781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_CLR:
177781182e1SJean-Christophe Dubois return "PLL_USB2_CLR";
178781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_TOG:
179781182e1SJean-Christophe Dubois return "PLL_USB2_TOG";
180781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS:
181781182e1SJean-Christophe Dubois return "PLL_SYS";
182781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_SET:
183781182e1SJean-Christophe Dubois return "PLL_SYS_SET";
184781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_CLR:
185781182e1SJean-Christophe Dubois return "PLL_SYS_CLR";
186781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_TOG:
187781182e1SJean-Christophe Dubois return "PLL_SYS_TOG";
188781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_SS:
189781182e1SJean-Christophe Dubois return "PLL_SYS_SS";
190781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_NUM:
191781182e1SJean-Christophe Dubois return "PLL_SYS_NUM";
192781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_DENOM:
193781182e1SJean-Christophe Dubois return "PLL_SYS_DENOM";
194781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO:
195781182e1SJean-Christophe Dubois return "PLL_AUDIO";
196781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_SET:
197781182e1SJean-Christophe Dubois return "PLL_AUDIO_SET";
198781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_CLR:
199781182e1SJean-Christophe Dubois return "PLL_AUDIO_CLR";
200781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_TOG:
201781182e1SJean-Christophe Dubois return "PLL_AUDIO_TOG";
202781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_NUM:
203781182e1SJean-Christophe Dubois return "PLL_AUDIO_NUM";
204781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_DENOM:
205781182e1SJean-Christophe Dubois return "PLL_AUDIO_DENOM";
206781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO:
207781182e1SJean-Christophe Dubois return "PLL_VIDEO";
208781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_SET:
209781182e1SJean-Christophe Dubois return "PLL_VIDEO_SET";
210781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_CLR:
211781182e1SJean-Christophe Dubois return "PLL_VIDEO_CLR";
212781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_TOG:
213781182e1SJean-Christophe Dubois return "PLL_VIDEO_TOG";
214781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_NUM:
215781182e1SJean-Christophe Dubois return "PLL_VIDEO_NUM";
216781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_DENOM:
217781182e1SJean-Christophe Dubois return "PLL_VIDEO_DENOM";
218781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET:
219781182e1SJean-Christophe Dubois return "PLL_ENET";
220781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_SET:
221781182e1SJean-Christophe Dubois return "PLL_ENET_SET";
222781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_CLR:
223781182e1SJean-Christophe Dubois return "PLL_ENET_CLR";
224781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_TOG:
225781182e1SJean-Christophe Dubois return "PLL_ENET_TOG";
226781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480:
227781182e1SJean-Christophe Dubois return "PFD_480";
228781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_SET:
229781182e1SJean-Christophe Dubois return "PFD_480_SET";
230781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_CLR:
231781182e1SJean-Christophe Dubois return "PFD_480_CLR";
232781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_TOG:
233781182e1SJean-Christophe Dubois return "PFD_480_TOG";
234781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528:
235781182e1SJean-Christophe Dubois return "PFD_528";
236781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_SET:
237781182e1SJean-Christophe Dubois return "PFD_528_SET";
238781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_CLR:
239781182e1SJean-Christophe Dubois return "PFD_528_CLR";
240781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_TOG:
241781182e1SJean-Christophe Dubois return "PFD_528_TOG";
242781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0:
243781182e1SJean-Christophe Dubois return "MISC0";
244781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_SET:
245781182e1SJean-Christophe Dubois return "MISC0_SET";
246781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_CLR:
247781182e1SJean-Christophe Dubois return "MISC0_CLR";
248781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_TOG:
249781182e1SJean-Christophe Dubois return "MISC0_TOG";
250781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2:
251781182e1SJean-Christophe Dubois return "MISC2";
252781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_SET:
253781182e1SJean-Christophe Dubois return "MISC2_SET";
254781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_CLR:
255781182e1SJean-Christophe Dubois return "MISC2_CLR";
256781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_TOG:
257781182e1SJean-Christophe Dubois return "MISC2_TOG";
258781182e1SJean-Christophe Dubois case PMU_REG_1P1:
259781182e1SJean-Christophe Dubois return "PMU_REG_1P1";
260781182e1SJean-Christophe Dubois case PMU_REG_3P0:
261781182e1SJean-Christophe Dubois return "PMU_REG_3P0";
262781182e1SJean-Christophe Dubois case PMU_REG_2P5:
263781182e1SJean-Christophe Dubois return "PMU_REG_2P5";
264781182e1SJean-Christophe Dubois case PMU_REG_CORE:
265781182e1SJean-Christophe Dubois return "PMU_REG_CORE";
266781182e1SJean-Christophe Dubois case PMU_MISC1:
267781182e1SJean-Christophe Dubois return "PMU_MISC1";
268781182e1SJean-Christophe Dubois case PMU_MISC1_SET:
269781182e1SJean-Christophe Dubois return "PMU_MISC1_SET";
270781182e1SJean-Christophe Dubois case PMU_MISC1_CLR:
271781182e1SJean-Christophe Dubois return "PMU_MISC1_CLR";
272781182e1SJean-Christophe Dubois case PMU_MISC1_TOG:
273781182e1SJean-Christophe Dubois return "PMU_MISC1_TOG";
274781182e1SJean-Christophe Dubois case USB_ANALOG_DIGPROG:
275781182e1SJean-Christophe Dubois return "USB_ANALOG_DIGPROG";
276781182e1SJean-Christophe Dubois default:
277ca4af17cSPhilippe Mathieu-Daudé snprintf(unknown, sizeof(unknown), "%u ?", reg);
278781182e1SJean-Christophe Dubois return unknown;
279781182e1SJean-Christophe Dubois }
280781182e1SJean-Christophe Dubois }
281781182e1SJean-Christophe Dubois
282781182e1SJean-Christophe Dubois #define CKIH_FREQ 24000000 /* 24MHz crystal input */
283781182e1SJean-Christophe Dubois
284781182e1SJean-Christophe Dubois static const VMStateDescription vmstate_imx6ul_ccm = {
285781182e1SJean-Christophe Dubois .name = TYPE_IMX6UL_CCM,
286781182e1SJean-Christophe Dubois .version_id = 1,
287781182e1SJean-Christophe Dubois .minimum_version_id = 1,
288e4ea952fSRichard Henderson .fields = (const VMStateField[]) {
289781182e1SJean-Christophe Dubois VMSTATE_UINT32_ARRAY(ccm, IMX6ULCCMState, CCM_MAX),
290781182e1SJean-Christophe Dubois VMSTATE_UINT32_ARRAY(analog, IMX6ULCCMState, CCM_ANALOG_MAX),
291781182e1SJean-Christophe Dubois VMSTATE_END_OF_LIST()
292781182e1SJean-Christophe Dubois },
293781182e1SJean-Christophe Dubois };
294781182e1SJean-Christophe Dubois
imx6ul_analog_get_osc_clk(IMX6ULCCMState * dev)295781182e1SJean-Christophe Dubois static uint64_t imx6ul_analog_get_osc_clk(IMX6ULCCMState *dev)
296781182e1SJean-Christophe Dubois {
297781182e1SJean-Christophe Dubois uint64_t freq = CKIH_FREQ;
298781182e1SJean-Christophe Dubois
299781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
300781182e1SJean-Christophe Dubois
301781182e1SJean-Christophe Dubois return freq;
302781182e1SJean-Christophe Dubois }
303781182e1SJean-Christophe Dubois
imx6ul_analog_get_pll2_clk(IMX6ULCCMState * dev)304781182e1SJean-Christophe Dubois static uint64_t imx6ul_analog_get_pll2_clk(IMX6ULCCMState *dev)
305781182e1SJean-Christophe Dubois {
306781182e1SJean-Christophe Dubois uint64_t freq = imx6ul_analog_get_osc_clk(dev);
307781182e1SJean-Christophe Dubois
308781182e1SJean-Christophe Dubois if (FIELD_EX32(dev->analog[CCM_ANALOG_PLL_SYS],
309781182e1SJean-Christophe Dubois ANALOG_PLL_SYS, DIV_SELECT)) {
310781182e1SJean-Christophe Dubois freq *= 22;
311781182e1SJean-Christophe Dubois } else {
312781182e1SJean-Christophe Dubois freq *= 20;
313781182e1SJean-Christophe Dubois }
314781182e1SJean-Christophe Dubois
315781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
316781182e1SJean-Christophe Dubois
317781182e1SJean-Christophe Dubois return freq;
318781182e1SJean-Christophe Dubois }
319781182e1SJean-Christophe Dubois
imx6ul_analog_get_pll3_clk(IMX6ULCCMState * dev)320781182e1SJean-Christophe Dubois static uint64_t imx6ul_analog_get_pll3_clk(IMX6ULCCMState *dev)
321781182e1SJean-Christophe Dubois {
322781182e1SJean-Christophe Dubois uint64_t freq = imx6ul_analog_get_osc_clk(dev) * 20;
323781182e1SJean-Christophe Dubois
324781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
325781182e1SJean-Christophe Dubois
326781182e1SJean-Christophe Dubois return freq;
327781182e1SJean-Christophe Dubois }
328781182e1SJean-Christophe Dubois
imx6ul_analog_get_pll2_pfd0_clk(IMX6ULCCMState * dev)329781182e1SJean-Christophe Dubois static uint64_t imx6ul_analog_get_pll2_pfd0_clk(IMX6ULCCMState *dev)
330781182e1SJean-Christophe Dubois {
331781182e1SJean-Christophe Dubois uint64_t freq = 0;
332781182e1SJean-Christophe Dubois
333781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_pll2_clk(dev) * 18
334781182e1SJean-Christophe Dubois / FIELD_EX32(dev->analog[CCM_ANALOG_PFD_528],
335781182e1SJean-Christophe Dubois ANALOG_PFD_528, PFD0_FRAC);
336781182e1SJean-Christophe Dubois
337781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
338781182e1SJean-Christophe Dubois
339781182e1SJean-Christophe Dubois return freq;
340781182e1SJean-Christophe Dubois }
341781182e1SJean-Christophe Dubois
imx6ul_analog_get_pll2_pfd2_clk(IMX6ULCCMState * dev)342781182e1SJean-Christophe Dubois static uint64_t imx6ul_analog_get_pll2_pfd2_clk(IMX6ULCCMState *dev)
343781182e1SJean-Christophe Dubois {
344781182e1SJean-Christophe Dubois uint64_t freq = 0;
345781182e1SJean-Christophe Dubois
346781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_pll2_clk(dev) * 18
347781182e1SJean-Christophe Dubois / FIELD_EX32(dev->analog[CCM_ANALOG_PFD_528],
348781182e1SJean-Christophe Dubois ANALOG_PFD_528, PFD2_FRAC);
349781182e1SJean-Christophe Dubois
350781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
351781182e1SJean-Christophe Dubois
352781182e1SJean-Christophe Dubois return freq;
353781182e1SJean-Christophe Dubois }
354781182e1SJean-Christophe Dubois
imx6ul_analog_pll2_bypass_clk(IMX6ULCCMState * dev)355781182e1SJean-Christophe Dubois static uint64_t imx6ul_analog_pll2_bypass_clk(IMX6ULCCMState *dev)
356781182e1SJean-Christophe Dubois {
357781182e1SJean-Christophe Dubois uint64_t freq = 0;
358781182e1SJean-Christophe Dubois
359781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
360781182e1SJean-Christophe Dubois
361781182e1SJean-Christophe Dubois return freq;
362781182e1SJean-Christophe Dubois }
363781182e1SJean-Christophe Dubois
imx6ul_ccm_get_periph_clk2_sel_clk(IMX6ULCCMState * dev)364781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_periph_clk2_sel_clk(IMX6ULCCMState *dev)
365781182e1SJean-Christophe Dubois {
366781182e1SJean-Christophe Dubois uint64_t freq = 0;
367781182e1SJean-Christophe Dubois
368781182e1SJean-Christophe Dubois switch (FIELD_EX32(dev->ccm[CCM_CBCMR], CBCMR, PERIPH_CLK2_SEL)) {
369781182e1SJean-Christophe Dubois case 0:
370781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_pll3_clk(dev);
371781182e1SJean-Christophe Dubois break;
372781182e1SJean-Christophe Dubois case 1:
373781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_osc_clk(dev);
374781182e1SJean-Christophe Dubois break;
375781182e1SJean-Christophe Dubois case 2:
376781182e1SJean-Christophe Dubois freq = imx6ul_analog_pll2_bypass_clk(dev);
377781182e1SJean-Christophe Dubois break;
378781182e1SJean-Christophe Dubois case 3:
379781182e1SJean-Christophe Dubois /* We should never get there as 3 is a reserved value */
380781182e1SJean-Christophe Dubois qemu_log_mask(LOG_GUEST_ERROR,
381781182e1SJean-Christophe Dubois "[%s]%s: unsupported PERIPH_CLK2_SEL value 3\n",
382781182e1SJean-Christophe Dubois TYPE_IMX6UL_CCM, __func__);
383781182e1SJean-Christophe Dubois /* freq is set to 0 as we don't know what it should be */
384781182e1SJean-Christophe Dubois break;
385781182e1SJean-Christophe Dubois default:
386781182e1SJean-Christophe Dubois g_assert_not_reached();
387781182e1SJean-Christophe Dubois }
388781182e1SJean-Christophe Dubois
389781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
390781182e1SJean-Christophe Dubois
391781182e1SJean-Christophe Dubois return freq;
392781182e1SJean-Christophe Dubois }
393781182e1SJean-Christophe Dubois
imx6ul_ccm_get_periph_clk_sel_clk(IMX6ULCCMState * dev)394781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_periph_clk_sel_clk(IMX6ULCCMState *dev)
395781182e1SJean-Christophe Dubois {
396781182e1SJean-Christophe Dubois uint64_t freq = 0;
397781182e1SJean-Christophe Dubois
398781182e1SJean-Christophe Dubois switch (FIELD_EX32(dev->ccm[CCM_CBCMR], CBCMR, PRE_PERIPH_CLK_SEL)) {
399781182e1SJean-Christophe Dubois case 0:
400781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_pll2_clk(dev);
401781182e1SJean-Christophe Dubois break;
402781182e1SJean-Christophe Dubois case 1:
403781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_pll2_pfd2_clk(dev);
404781182e1SJean-Christophe Dubois break;
405781182e1SJean-Christophe Dubois case 2:
406781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_pll2_pfd0_clk(dev);
407781182e1SJean-Christophe Dubois break;
408781182e1SJean-Christophe Dubois case 3:
409781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_pll2_pfd2_clk(dev) / 2;
410781182e1SJean-Christophe Dubois break;
411781182e1SJean-Christophe Dubois default:
412781182e1SJean-Christophe Dubois g_assert_not_reached();
413781182e1SJean-Christophe Dubois }
414781182e1SJean-Christophe Dubois
415781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
416781182e1SJean-Christophe Dubois
417781182e1SJean-Christophe Dubois return freq;
418781182e1SJean-Christophe Dubois }
419781182e1SJean-Christophe Dubois
imx6ul_ccm_get_periph_clk2_clk(IMX6ULCCMState * dev)420781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_periph_clk2_clk(IMX6ULCCMState *dev)
421781182e1SJean-Christophe Dubois {
422781182e1SJean-Christophe Dubois uint64_t freq = 0;
423781182e1SJean-Christophe Dubois
424781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_periph_clk2_sel_clk(dev)
425781182e1SJean-Christophe Dubois / (1 + FIELD_EX32(dev->ccm[CCM_CBCDR], CBCDR, PERIPH_CLK2_PODF));
426781182e1SJean-Christophe Dubois
427781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
428781182e1SJean-Christophe Dubois
429781182e1SJean-Christophe Dubois return freq;
430781182e1SJean-Christophe Dubois }
431781182e1SJean-Christophe Dubois
imx6ul_ccm_get_periph_sel_clk(IMX6ULCCMState * dev)432781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_periph_sel_clk(IMX6ULCCMState *dev)
433781182e1SJean-Christophe Dubois {
434781182e1SJean-Christophe Dubois uint64_t freq = 0;
435781182e1SJean-Christophe Dubois
436781182e1SJean-Christophe Dubois switch (FIELD_EX32(dev->ccm[CCM_CBCDR], CBCDR, PERIPH_CLK_SEL)) {
437781182e1SJean-Christophe Dubois case 0:
438781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_periph_clk_sel_clk(dev);
439781182e1SJean-Christophe Dubois break;
440781182e1SJean-Christophe Dubois case 1:
441781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_periph_clk2_clk(dev);
442781182e1SJean-Christophe Dubois break;
443781182e1SJean-Christophe Dubois default:
444781182e1SJean-Christophe Dubois g_assert_not_reached();
445781182e1SJean-Christophe Dubois }
446781182e1SJean-Christophe Dubois
447781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
448781182e1SJean-Christophe Dubois
449781182e1SJean-Christophe Dubois return freq;
450781182e1SJean-Christophe Dubois }
451781182e1SJean-Christophe Dubois
imx6ul_ccm_get_ahb_clk(IMX6ULCCMState * dev)452781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_ahb_clk(IMX6ULCCMState *dev)
453781182e1SJean-Christophe Dubois {
454781182e1SJean-Christophe Dubois uint64_t freq = 0;
455781182e1SJean-Christophe Dubois
456781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_periph_sel_clk(dev)
457781182e1SJean-Christophe Dubois / (1 + FIELD_EX32(dev->ccm[CCM_CBCDR], CBCDR, AHB_PODF));
458781182e1SJean-Christophe Dubois
459781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
460781182e1SJean-Christophe Dubois
461781182e1SJean-Christophe Dubois return freq;
462781182e1SJean-Christophe Dubois }
463781182e1SJean-Christophe Dubois
imx6ul_ccm_get_ipg_clk(IMX6ULCCMState * dev)464781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_ipg_clk(IMX6ULCCMState *dev)
465781182e1SJean-Christophe Dubois {
466781182e1SJean-Christophe Dubois uint64_t freq = 0;
467781182e1SJean-Christophe Dubois
468781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_ahb_clk(dev)
469781182e1SJean-Christophe Dubois / (1 + FIELD_EX32(dev->ccm[CCM_CBCDR], CBCDR, IPG_PODF));
470781182e1SJean-Christophe Dubois
471781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
472781182e1SJean-Christophe Dubois
473781182e1SJean-Christophe Dubois return freq;
474781182e1SJean-Christophe Dubois }
475781182e1SJean-Christophe Dubois
imx6ul_ccm_get_per_sel_clk(IMX6ULCCMState * dev)476781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_per_sel_clk(IMX6ULCCMState *dev)
477781182e1SJean-Christophe Dubois {
478781182e1SJean-Christophe Dubois uint64_t freq = 0;
479781182e1SJean-Christophe Dubois
480781182e1SJean-Christophe Dubois switch (FIELD_EX32(dev->ccm[CCM_CSCMR1], CSCMR1, PERCLK_CLK_SEL)) {
481781182e1SJean-Christophe Dubois case 0:
482781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_ipg_clk(dev);
483781182e1SJean-Christophe Dubois break;
484781182e1SJean-Christophe Dubois case 1:
485781182e1SJean-Christophe Dubois freq = imx6ul_analog_get_osc_clk(dev);
486781182e1SJean-Christophe Dubois break;
487781182e1SJean-Christophe Dubois default:
488781182e1SJean-Christophe Dubois g_assert_not_reached();
489781182e1SJean-Christophe Dubois }
490781182e1SJean-Christophe Dubois
491781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
492781182e1SJean-Christophe Dubois
493781182e1SJean-Christophe Dubois return freq;
494781182e1SJean-Christophe Dubois }
495781182e1SJean-Christophe Dubois
imx6ul_ccm_get_per_clk(IMX6ULCCMState * dev)496781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_get_per_clk(IMX6ULCCMState *dev)
497781182e1SJean-Christophe Dubois {
498781182e1SJean-Christophe Dubois uint64_t freq = 0;
499781182e1SJean-Christophe Dubois
500781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_per_sel_clk(dev)
501781182e1SJean-Christophe Dubois / (1 + FIELD_EX32(dev->ccm[CCM_CSCMR1], CSCMR1, PERCLK_PODF));
502781182e1SJean-Christophe Dubois
503781182e1SJean-Christophe Dubois trace_ccm_freq((uint32_t)freq);
504781182e1SJean-Christophe Dubois
505781182e1SJean-Christophe Dubois return freq;
506781182e1SJean-Christophe Dubois }
507781182e1SJean-Christophe Dubois
imx6ul_ccm_get_clock_frequency(IMXCCMState * dev,IMXClk clock)508781182e1SJean-Christophe Dubois static uint32_t imx6ul_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
509781182e1SJean-Christophe Dubois {
510781182e1SJean-Christophe Dubois uint32_t freq = 0;
511781182e1SJean-Christophe Dubois IMX6ULCCMState *s = IMX6UL_CCM(dev);
512781182e1SJean-Christophe Dubois
513781182e1SJean-Christophe Dubois switch (clock) {
514781182e1SJean-Christophe Dubois case CLK_NONE:
515781182e1SJean-Christophe Dubois break;
516781182e1SJean-Christophe Dubois case CLK_IPG:
517781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_ipg_clk(s);
518781182e1SJean-Christophe Dubois break;
519781182e1SJean-Christophe Dubois case CLK_IPG_HIGH:
520781182e1SJean-Christophe Dubois freq = imx6ul_ccm_get_per_clk(s);
521781182e1SJean-Christophe Dubois break;
522781182e1SJean-Christophe Dubois case CLK_32k:
523781182e1SJean-Christophe Dubois freq = CKIL_FREQ;
524781182e1SJean-Christophe Dubois break;
525781182e1SJean-Christophe Dubois default:
526781182e1SJean-Christophe Dubois qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: unsupported clock %d\n",
527781182e1SJean-Christophe Dubois TYPE_IMX6UL_CCM, __func__, clock);
528781182e1SJean-Christophe Dubois break;
529781182e1SJean-Christophe Dubois }
530781182e1SJean-Christophe Dubois
531781182e1SJean-Christophe Dubois trace_ccm_clock_freq(clock, freq);
532781182e1SJean-Christophe Dubois
533781182e1SJean-Christophe Dubois return freq;
534781182e1SJean-Christophe Dubois }
535781182e1SJean-Christophe Dubois
imx6ul_ccm_reset(DeviceState * dev)536781182e1SJean-Christophe Dubois static void imx6ul_ccm_reset(DeviceState *dev)
537781182e1SJean-Christophe Dubois {
538781182e1SJean-Christophe Dubois IMX6ULCCMState *s = IMX6UL_CCM(dev);
539781182e1SJean-Christophe Dubois
540781182e1SJean-Christophe Dubois trace_ccm_entry();
541781182e1SJean-Christophe Dubois
542781182e1SJean-Christophe Dubois s->ccm[CCM_CCR] = 0x0401167F;
543781182e1SJean-Christophe Dubois s->ccm[CCM_CCDR] = 0x00000000;
544781182e1SJean-Christophe Dubois s->ccm[CCM_CSR] = 0x00000010;
545781182e1SJean-Christophe Dubois s->ccm[CCM_CCSR] = 0x00000100;
546781182e1SJean-Christophe Dubois s->ccm[CCM_CACRR] = 0x00000000;
547781182e1SJean-Christophe Dubois s->ccm[CCM_CBCDR] = 0x00018D00;
548781182e1SJean-Christophe Dubois s->ccm[CCM_CBCMR] = 0x24860324;
549781182e1SJean-Christophe Dubois s->ccm[CCM_CSCMR1] = 0x04900080;
550781182e1SJean-Christophe Dubois s->ccm[CCM_CSCMR2] = 0x03192F06;
551781182e1SJean-Christophe Dubois s->ccm[CCM_CSCDR1] = 0x00490B00;
552781182e1SJean-Christophe Dubois s->ccm[CCM_CS1CDR] = 0x0EC102C1;
553781182e1SJean-Christophe Dubois s->ccm[CCM_CS2CDR] = 0x000336C1;
554781182e1SJean-Christophe Dubois s->ccm[CCM_CDCDR] = 0x33F71F92;
555781182e1SJean-Christophe Dubois s->ccm[CCM_CHSCCDR] = 0x000248A4;
556781182e1SJean-Christophe Dubois s->ccm[CCM_CSCDR2] = 0x00029B48;
557781182e1SJean-Christophe Dubois s->ccm[CCM_CSCDR3] = 0x00014841;
558781182e1SJean-Christophe Dubois s->ccm[CCM_CDHIPR] = 0x00000000;
559781182e1SJean-Christophe Dubois s->ccm[CCM_CTOR] = 0x00000000;
560781182e1SJean-Christophe Dubois s->ccm[CCM_CLPCR] = 0x00000079;
561781182e1SJean-Christophe Dubois s->ccm[CCM_CISR] = 0x00000000;
562781182e1SJean-Christophe Dubois s->ccm[CCM_CIMR] = 0xFFFFFFFF;
563781182e1SJean-Christophe Dubois s->ccm[CCM_CCOSR] = 0x000A0001;
564781182e1SJean-Christophe Dubois s->ccm[CCM_CGPR] = 0x0000FE62;
565781182e1SJean-Christophe Dubois s->ccm[CCM_CCGR0] = 0xFFFFFFFF;
566781182e1SJean-Christophe Dubois s->ccm[CCM_CCGR1] = 0xFFFFFFFF;
567781182e1SJean-Christophe Dubois s->ccm[CCM_CCGR2] = 0xFC3FFFFF;
568781182e1SJean-Christophe Dubois s->ccm[CCM_CCGR3] = 0xFFFFFFFF;
569781182e1SJean-Christophe Dubois s->ccm[CCM_CCGR4] = 0xFFFFFFFF;
570781182e1SJean-Christophe Dubois s->ccm[CCM_CCGR5] = 0xFFFFFFFF;
571781182e1SJean-Christophe Dubois s->ccm[CCM_CCGR6] = 0xFFFFFFFF;
572781182e1SJean-Christophe Dubois s->ccm[CCM_CMEOR] = 0xFFFFFFFF;
573781182e1SJean-Christophe Dubois
574781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_ARM] = 0x00013063;
575781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_USB1] = 0x00012000;
576781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_USB2] = 0x00012000;
577781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_SYS] = 0x00013001;
578781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_SYS_SS] = 0x00000000;
579781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_SYS_NUM] = 0x00000000;
580781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_SYS_DENOM] = 0x00000012;
581781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_AUDIO] = 0x00011006;
582781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_AUDIO_NUM] = 0x05F5E100;
583781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_AUDIO_DENOM] = 0x2964619C;
584781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_VIDEO] = 0x0001100C;
585781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_VIDEO_NUM] = 0x05F5E100;
586781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_VIDEO_DENOM] = 0x10A24447;
587781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_ENET] = 0x00011001;
588781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PFD_480] = 0x1311100C;
589781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PFD_528] = 0x1018101B;
590781182e1SJean-Christophe Dubois
591781182e1SJean-Christophe Dubois s->analog[PMU_REG_1P1] = 0x00001073;
592781182e1SJean-Christophe Dubois s->analog[PMU_REG_3P0] = 0x00000F74;
593781182e1SJean-Christophe Dubois s->analog[PMU_REG_2P5] = 0x00001073;
594781182e1SJean-Christophe Dubois s->analog[PMU_REG_CORE] = 0x00482012;
595781182e1SJean-Christophe Dubois s->analog[PMU_MISC0] = 0x04000000;
596781182e1SJean-Christophe Dubois s->analog[PMU_MISC1] = 0x00000000;
597781182e1SJean-Christophe Dubois s->analog[PMU_MISC2] = 0x00272727;
598781182e1SJean-Christophe Dubois s->analog[PMU_LOWPWR_CTRL] = 0x00004009;
599781182e1SJean-Christophe Dubois
600781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB1_VBUS_DETECT] = 0x01000004;
601781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB1_CHRG_DETECT] = 0x00000000;
602781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB1_VBUS_DETECT_STAT] = 0x00000000;
603781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB1_CHRG_DETECT_STAT] = 0x00000000;
604781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB1_MISC] = 0x00000002;
605781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB2_VBUS_DETECT] = 0x01000004;
606781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB2_CHRG_DETECT] = 0x00000000;
607781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_USB2_MISC] = 0x00000002;
608781182e1SJean-Christophe Dubois s->analog[USB_ANALOG_DIGPROG] = 0x00640000;
609781182e1SJean-Christophe Dubois
610781182e1SJean-Christophe Dubois /* all PLLs need to be locked */
611781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_ARM] |= CCM_ANALOG_PLL_LOCK;
612781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_USB1] |= CCM_ANALOG_PLL_LOCK;
613781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_USB2] |= CCM_ANALOG_PLL_LOCK;
614781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_SYS] |= CCM_ANALOG_PLL_LOCK;
615781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_AUDIO] |= CCM_ANALOG_PLL_LOCK;
616781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_VIDEO] |= CCM_ANALOG_PLL_LOCK;
617781182e1SJean-Christophe Dubois s->analog[CCM_ANALOG_PLL_ENET] |= CCM_ANALOG_PLL_LOCK;
618781182e1SJean-Christophe Dubois
619781182e1SJean-Christophe Dubois s->analog[TEMPMON_TEMPSENSE0] = 0x00000001;
620781182e1SJean-Christophe Dubois s->analog[TEMPMON_TEMPSENSE1] = 0x00000001;
621781182e1SJean-Christophe Dubois s->analog[TEMPMON_TEMPSENSE2] = 0x00000000;
622781182e1SJean-Christophe Dubois }
623781182e1SJean-Christophe Dubois
imx6ul_ccm_read(void * opaque,hwaddr offset,unsigned size)624781182e1SJean-Christophe Dubois static uint64_t imx6ul_ccm_read(void *opaque, hwaddr offset, unsigned size)
625781182e1SJean-Christophe Dubois {
626781182e1SJean-Christophe Dubois uint32_t value = 0;
627781182e1SJean-Christophe Dubois uint32_t index = offset >> 2;
628781182e1SJean-Christophe Dubois IMX6ULCCMState *s = (IMX6ULCCMState *)opaque;
629781182e1SJean-Christophe Dubois
630781182e1SJean-Christophe Dubois assert(index < CCM_MAX);
631781182e1SJean-Christophe Dubois
632781182e1SJean-Christophe Dubois value = s->ccm[index];
633781182e1SJean-Christophe Dubois
634781182e1SJean-Christophe Dubois trace_ccm_read_reg(imx6ul_ccm_reg_name(index), (uint32_t)value);
635781182e1SJean-Christophe Dubois
636781182e1SJean-Christophe Dubois return (uint64_t)value;
637781182e1SJean-Christophe Dubois }
638781182e1SJean-Christophe Dubois
imx6ul_ccm_write(void * opaque,hwaddr offset,uint64_t value,unsigned size)639781182e1SJean-Christophe Dubois static void imx6ul_ccm_write(void *opaque, hwaddr offset, uint64_t value,
640781182e1SJean-Christophe Dubois unsigned size)
641781182e1SJean-Christophe Dubois {
642781182e1SJean-Christophe Dubois uint32_t index = offset >> 2;
643781182e1SJean-Christophe Dubois IMX6ULCCMState *s = (IMX6ULCCMState *)opaque;
644781182e1SJean-Christophe Dubois
645781182e1SJean-Christophe Dubois assert(index < CCM_MAX);
646781182e1SJean-Christophe Dubois
647781182e1SJean-Christophe Dubois trace_ccm_write_reg(imx6ul_ccm_reg_name(index), (uint32_t)value);
648781182e1SJean-Christophe Dubois
6493d26d7d6SJean-Christophe Dubois s->ccm[index] = (s->ccm[index] & ccm_mask[index]) |
6503d26d7d6SJean-Christophe Dubois ((uint32_t)value & ~ccm_mask[index]);
651781182e1SJean-Christophe Dubois }
652781182e1SJean-Christophe Dubois
imx6ul_analog_read(void * opaque,hwaddr offset,unsigned size)653781182e1SJean-Christophe Dubois static uint64_t imx6ul_analog_read(void *opaque, hwaddr offset, unsigned size)
654781182e1SJean-Christophe Dubois {
655781182e1SJean-Christophe Dubois uint32_t value;
656781182e1SJean-Christophe Dubois uint32_t index = offset >> 2;
657781182e1SJean-Christophe Dubois IMX6ULCCMState *s = (IMX6ULCCMState *)opaque;
658781182e1SJean-Christophe Dubois
659781182e1SJean-Christophe Dubois assert(index < CCM_ANALOG_MAX);
660781182e1SJean-Christophe Dubois
661781182e1SJean-Christophe Dubois switch (index) {
662781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_SET:
663781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_SET:
664781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_SET:
665781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_SET:
666781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_SET:
667781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_SET:
668781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_SET:
669781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_SET:
670781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_SET:
671781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_SET:
672781182e1SJean-Christophe Dubois case PMU_MISC1_SET:
673781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_SET:
674781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_VBUS_DETECT_SET:
675781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_CHRG_DETECT_SET:
676781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_MISC_SET:
677781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_VBUS_DETECT_SET:
678781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_CHRG_DETECT_SET:
679781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_MISC_SET:
680781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE0_SET:
681781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE1_SET:
682781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE2_SET:
683781182e1SJean-Christophe Dubois /*
684781182e1SJean-Christophe Dubois * All REG_NAME_SET register access are in fact targeting
685781182e1SJean-Christophe Dubois * the REG_NAME register.
686781182e1SJean-Christophe Dubois */
687781182e1SJean-Christophe Dubois value = s->analog[index - 1];
688781182e1SJean-Christophe Dubois break;
689781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_CLR:
690781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_CLR:
691781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_CLR:
692781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_CLR:
693781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_CLR:
694781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_CLR:
695781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_CLR:
696781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_CLR:
697781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_CLR:
698781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_CLR:
699781182e1SJean-Christophe Dubois case PMU_MISC1_CLR:
700781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_CLR:
701781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_VBUS_DETECT_CLR:
702781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_CHRG_DETECT_CLR:
703781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_MISC_CLR:
704781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_VBUS_DETECT_CLR:
705781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_CHRG_DETECT_CLR:
706781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_MISC_CLR:
707781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE0_CLR:
708781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE1_CLR:
709781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE2_CLR:
710781182e1SJean-Christophe Dubois /*
711781182e1SJean-Christophe Dubois * All REG_NAME_CLR register access are in fact targeting
712781182e1SJean-Christophe Dubois * the REG_NAME register.
713781182e1SJean-Christophe Dubois */
714781182e1SJean-Christophe Dubois value = s->analog[index - 2];
715781182e1SJean-Christophe Dubois break;
716781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_TOG:
717781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_TOG:
718781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_TOG:
719781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_TOG:
720781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_TOG:
721781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_TOG:
722781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_TOG:
723781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_TOG:
724781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_TOG:
725781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_TOG:
726781182e1SJean-Christophe Dubois case PMU_MISC1_TOG:
727781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_TOG:
728781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_VBUS_DETECT_TOG:
729781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_CHRG_DETECT_TOG:
730781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_MISC_TOG:
731781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_VBUS_DETECT_TOG:
732781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_CHRG_DETECT_TOG:
733781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_MISC_TOG:
734781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE0_TOG:
735781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE1_TOG:
736781182e1SJean-Christophe Dubois case TEMPMON_TEMPSENSE2_TOG:
737781182e1SJean-Christophe Dubois /*
738781182e1SJean-Christophe Dubois * All REG_NAME_TOG register access are in fact targeting
739781182e1SJean-Christophe Dubois * the REG_NAME register.
740781182e1SJean-Christophe Dubois */
741781182e1SJean-Christophe Dubois value = s->analog[index - 3];
742781182e1SJean-Christophe Dubois break;
743781182e1SJean-Christophe Dubois default:
744781182e1SJean-Christophe Dubois value = s->analog[index];
745781182e1SJean-Christophe Dubois break;
746781182e1SJean-Christophe Dubois }
747781182e1SJean-Christophe Dubois
748781182e1SJean-Christophe Dubois trace_ccm_read_reg(imx6ul_analog_reg_name(index), (uint32_t)value);
749781182e1SJean-Christophe Dubois
750781182e1SJean-Christophe Dubois return (uint64_t)value;
751781182e1SJean-Christophe Dubois }
752781182e1SJean-Christophe Dubois
imx6ul_analog_write(void * opaque,hwaddr offset,uint64_t value,unsigned size)753781182e1SJean-Christophe Dubois static void imx6ul_analog_write(void *opaque, hwaddr offset, uint64_t value,
754781182e1SJean-Christophe Dubois unsigned size)
755781182e1SJean-Christophe Dubois {
756781182e1SJean-Christophe Dubois uint32_t index = offset >> 2;
757781182e1SJean-Christophe Dubois IMX6ULCCMState *s = (IMX6ULCCMState *)opaque;
758781182e1SJean-Christophe Dubois
759781182e1SJean-Christophe Dubois assert(index < CCM_ANALOG_MAX);
760781182e1SJean-Christophe Dubois
761781182e1SJean-Christophe Dubois trace_ccm_write_reg(imx6ul_analog_reg_name(index), (uint32_t)value);
762781182e1SJean-Christophe Dubois
763781182e1SJean-Christophe Dubois switch (index) {
764781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_SET:
765781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_SET:
766781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_SET:
767781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_SET:
768781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_SET:
769781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_SET:
770781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_SET:
771781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_SET:
772781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_SET:
773781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_SET:
774781182e1SJean-Christophe Dubois case PMU_MISC1_SET:
775781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_SET:
776781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_VBUS_DETECT_SET:
777781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_CHRG_DETECT_SET:
778781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_MISC_SET:
779781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_VBUS_DETECT_SET:
780781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_CHRG_DETECT_SET:
781781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_MISC_SET:
782781182e1SJean-Christophe Dubois /*
783781182e1SJean-Christophe Dubois * All REG_NAME_SET register access are in fact targeting
784781182e1SJean-Christophe Dubois * the REG_NAME register. So we change the value of the
785781182e1SJean-Christophe Dubois * REG_NAME register, setting bits passed in the value.
786781182e1SJean-Christophe Dubois */
7873d26d7d6SJean-Christophe Dubois s->analog[index - 1] |= (value & ~analog_mask[index - 1]);
788781182e1SJean-Christophe Dubois break;
789781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_CLR:
790781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_CLR:
791781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_CLR:
792781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_CLR:
793781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_CLR:
794781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_CLR:
795781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_CLR:
796781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_CLR:
797781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_CLR:
798781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_CLR:
799781182e1SJean-Christophe Dubois case PMU_MISC1_CLR:
800781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_CLR:
801781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_VBUS_DETECT_CLR:
802781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_CHRG_DETECT_CLR:
803781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_MISC_CLR:
804781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_VBUS_DETECT_CLR:
805781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_CHRG_DETECT_CLR:
806781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_MISC_CLR:
807781182e1SJean-Christophe Dubois /*
808781182e1SJean-Christophe Dubois * All REG_NAME_CLR register access are in fact targeting
809781182e1SJean-Christophe Dubois * the REG_NAME register. So we change the value of the
810781182e1SJean-Christophe Dubois * REG_NAME register, unsetting bits passed in the value.
811781182e1SJean-Christophe Dubois */
8123d26d7d6SJean-Christophe Dubois s->analog[index - 2] &= ~(value & ~analog_mask[index - 2]);
813781182e1SJean-Christophe Dubois break;
814781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ARM_TOG:
815781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB1_TOG:
816781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_USB2_TOG:
817781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_SYS_TOG:
818781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_AUDIO_TOG:
819781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_VIDEO_TOG:
820781182e1SJean-Christophe Dubois case CCM_ANALOG_PLL_ENET_TOG:
821781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_480_TOG:
822781182e1SJean-Christophe Dubois case CCM_ANALOG_PFD_528_TOG:
823781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC0_TOG:
824781182e1SJean-Christophe Dubois case PMU_MISC1_TOG:
825781182e1SJean-Christophe Dubois case CCM_ANALOG_MISC2_TOG:
826781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_VBUS_DETECT_TOG:
827781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_CHRG_DETECT_TOG:
828781182e1SJean-Christophe Dubois case USB_ANALOG_USB1_MISC_TOG:
829781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_VBUS_DETECT_TOG:
830781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_CHRG_DETECT_TOG:
831781182e1SJean-Christophe Dubois case USB_ANALOG_USB2_MISC_TOG:
832781182e1SJean-Christophe Dubois /*
833781182e1SJean-Christophe Dubois * All REG_NAME_TOG register access are in fact targeting
834781182e1SJean-Christophe Dubois * the REG_NAME register. So we change the value of the
835781182e1SJean-Christophe Dubois * REG_NAME register, toggling bits passed in the value.
836781182e1SJean-Christophe Dubois */
8373d26d7d6SJean-Christophe Dubois s->analog[index - 3] ^= (value & ~analog_mask[index - 3]);
838781182e1SJean-Christophe Dubois break;
839781182e1SJean-Christophe Dubois default:
8403d26d7d6SJean-Christophe Dubois s->analog[index] = (s->analog[index] & analog_mask[index]) |
8413d26d7d6SJean-Christophe Dubois (value & ~analog_mask[index]);
842781182e1SJean-Christophe Dubois break;
843781182e1SJean-Christophe Dubois }
844781182e1SJean-Christophe Dubois }
845781182e1SJean-Christophe Dubois
846781182e1SJean-Christophe Dubois static const struct MemoryRegionOps imx6ul_ccm_ops = {
847781182e1SJean-Christophe Dubois .read = imx6ul_ccm_read,
848781182e1SJean-Christophe Dubois .write = imx6ul_ccm_write,
849781182e1SJean-Christophe Dubois .endianness = DEVICE_NATIVE_ENDIAN,
850781182e1SJean-Christophe Dubois .valid = {
851781182e1SJean-Christophe Dubois /*
852781182e1SJean-Christophe Dubois * Our device would not work correctly if the guest was doing
853781182e1SJean-Christophe Dubois * unaligned access. This might not be a limitation on the real
854781182e1SJean-Christophe Dubois * device but in practice there is no reason for a guest to access
855781182e1SJean-Christophe Dubois * this device unaligned.
856781182e1SJean-Christophe Dubois */
857781182e1SJean-Christophe Dubois .min_access_size = 4,
858781182e1SJean-Christophe Dubois .max_access_size = 4,
859781182e1SJean-Christophe Dubois .unaligned = false,
860781182e1SJean-Christophe Dubois },
861781182e1SJean-Christophe Dubois };
862781182e1SJean-Christophe Dubois
863781182e1SJean-Christophe Dubois static const struct MemoryRegionOps imx6ul_analog_ops = {
864781182e1SJean-Christophe Dubois .read = imx6ul_analog_read,
865781182e1SJean-Christophe Dubois .write = imx6ul_analog_write,
866781182e1SJean-Christophe Dubois .endianness = DEVICE_NATIVE_ENDIAN,
867781182e1SJean-Christophe Dubois .valid = {
868781182e1SJean-Christophe Dubois /*
869781182e1SJean-Christophe Dubois * Our device would not work correctly if the guest was doing
870781182e1SJean-Christophe Dubois * unaligned access. This might not be a limitation on the real
871781182e1SJean-Christophe Dubois * device but in practice there is no reason for a guest to access
872781182e1SJean-Christophe Dubois * this device unaligned.
873781182e1SJean-Christophe Dubois */
874781182e1SJean-Christophe Dubois .min_access_size = 4,
875781182e1SJean-Christophe Dubois .max_access_size = 4,
876781182e1SJean-Christophe Dubois .unaligned = false,
877781182e1SJean-Christophe Dubois },
878781182e1SJean-Christophe Dubois };
879781182e1SJean-Christophe Dubois
imx6ul_ccm_init(Object * obj)880781182e1SJean-Christophe Dubois static void imx6ul_ccm_init(Object *obj)
881781182e1SJean-Christophe Dubois {
882781182e1SJean-Christophe Dubois DeviceState *dev = DEVICE(obj);
883781182e1SJean-Christophe Dubois SysBusDevice *sd = SYS_BUS_DEVICE(obj);
884781182e1SJean-Christophe Dubois IMX6ULCCMState *s = IMX6UL_CCM(obj);
885781182e1SJean-Christophe Dubois
886781182e1SJean-Christophe Dubois /* initialize a container for the all memory range */
887781182e1SJean-Christophe Dubois memory_region_init(&s->container, OBJECT(dev), TYPE_IMX6UL_CCM, 0x8000);
888781182e1SJean-Christophe Dubois
889781182e1SJean-Christophe Dubois /* We initialize an IO memory region for the CCM part */
890781182e1SJean-Christophe Dubois memory_region_init_io(&s->ioccm, OBJECT(dev), &imx6ul_ccm_ops, s,
891781182e1SJean-Christophe Dubois TYPE_IMX6UL_CCM ".ccm", CCM_MAX * sizeof(uint32_t));
892781182e1SJean-Christophe Dubois
893781182e1SJean-Christophe Dubois /* Add the CCM as a subregion at offset 0 */
894781182e1SJean-Christophe Dubois memory_region_add_subregion(&s->container, 0, &s->ioccm);
895781182e1SJean-Christophe Dubois
896781182e1SJean-Christophe Dubois /* We initialize an IO memory region for the ANALOG part */
897781182e1SJean-Christophe Dubois memory_region_init_io(&s->ioanalog, OBJECT(dev), &imx6ul_analog_ops, s,
898781182e1SJean-Christophe Dubois TYPE_IMX6UL_CCM ".analog",
899781182e1SJean-Christophe Dubois CCM_ANALOG_MAX * sizeof(uint32_t));
900781182e1SJean-Christophe Dubois
901781182e1SJean-Christophe Dubois /* Add the ANALOG as a subregion at offset 0x4000 */
902781182e1SJean-Christophe Dubois memory_region_add_subregion(&s->container, 0x4000, &s->ioanalog);
903781182e1SJean-Christophe Dubois
904781182e1SJean-Christophe Dubois sysbus_init_mmio(sd, &s->container);
905781182e1SJean-Christophe Dubois }
906781182e1SJean-Christophe Dubois
imx6ul_ccm_class_init(ObjectClass * klass,void * data)907781182e1SJean-Christophe Dubois static void imx6ul_ccm_class_init(ObjectClass *klass, void *data)
908781182e1SJean-Christophe Dubois {
909781182e1SJean-Christophe Dubois DeviceClass *dc = DEVICE_CLASS(klass);
910781182e1SJean-Christophe Dubois IMXCCMClass *ccm = IMX_CCM_CLASS(klass);
911781182e1SJean-Christophe Dubois
912*e3d08143SPeter Maydell device_class_set_legacy_reset(dc, imx6ul_ccm_reset);
913781182e1SJean-Christophe Dubois dc->vmsd = &vmstate_imx6ul_ccm;
914781182e1SJean-Christophe Dubois dc->desc = "i.MX6UL Clock Control Module";
915781182e1SJean-Christophe Dubois
916781182e1SJean-Christophe Dubois ccm->get_clock_frequency = imx6ul_ccm_get_clock_frequency;
917781182e1SJean-Christophe Dubois }
918781182e1SJean-Christophe Dubois
919781182e1SJean-Christophe Dubois static const TypeInfo imx6ul_ccm_info = {
920781182e1SJean-Christophe Dubois .name = TYPE_IMX6UL_CCM,
921781182e1SJean-Christophe Dubois .parent = TYPE_IMX_CCM,
922781182e1SJean-Christophe Dubois .instance_size = sizeof(IMX6ULCCMState),
923781182e1SJean-Christophe Dubois .instance_init = imx6ul_ccm_init,
924781182e1SJean-Christophe Dubois .class_init = imx6ul_ccm_class_init,
925781182e1SJean-Christophe Dubois };
926781182e1SJean-Christophe Dubois
imx6ul_ccm_register_types(void)927781182e1SJean-Christophe Dubois static void imx6ul_ccm_register_types(void)
928781182e1SJean-Christophe Dubois {
929781182e1SJean-Christophe Dubois type_register_static(&imx6ul_ccm_info);
930781182e1SJean-Christophe Dubois }
931781182e1SJean-Christophe Dubois
932781182e1SJean-Christophe Dubois type_init(imx6ul_ccm_register_types)
933