2 * IMX6 Clock Control Module
4 * Copyright (c) 2015 Jean-Christophe Dubois <jcd@tribudubois.net>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
9 * To get the timer frequencies right, we need to emulate at least part of
13 #include "qemu/osdep.h"
14 #include "hw/misc/imx6_ccm.h"
15 #include "migration/vmstate.h"
17 #include "qemu/module.h"
19 #ifndef DEBUG_IMX6_CCM
20 #define DEBUG_IMX6_CCM 0
23 #define DPRINTF(fmt, args...) \
25 if (DEBUG_IMX6_CCM) { \
26 fprintf(stderr, "[%s]%s: " fmt , TYPE_IMX6_CCM, \
31 static const char *imx6_ccm_reg_name(uint32_t reg
)
33 static char unknown
[20];
99 sprintf(unknown
, "%u ?", reg
);
104 static const char *imx6_analog_reg_name(uint32_t reg
)
106 static char unknown
[20];
109 case CCM_ANALOG_PLL_ARM
:
111 case CCM_ANALOG_PLL_ARM_SET
:
112 return "PLL_ARM_SET";
113 case CCM_ANALOG_PLL_ARM_CLR
:
114 return "PLL_ARM_CLR";
115 case CCM_ANALOG_PLL_ARM_TOG
:
116 return "PLL_ARM_TOG";
117 case CCM_ANALOG_PLL_USB1
:
119 case CCM_ANALOG_PLL_USB1_SET
:
120 return "PLL_USB1_SET";
121 case CCM_ANALOG_PLL_USB1_CLR
:
122 return "PLL_USB1_CLR";
123 case CCM_ANALOG_PLL_USB1_TOG
:
124 return "PLL_USB1_TOG";
125 case CCM_ANALOG_PLL_USB2
:
127 case CCM_ANALOG_PLL_USB2_SET
:
128 return "PLL_USB2_SET";
129 case CCM_ANALOG_PLL_USB2_CLR
:
130 return "PLL_USB2_CLR";
131 case CCM_ANALOG_PLL_USB2_TOG
:
132 return "PLL_USB2_TOG";
133 case CCM_ANALOG_PLL_SYS
:
135 case CCM_ANALOG_PLL_SYS_SET
:
136 return "PLL_SYS_SET";
137 case CCM_ANALOG_PLL_SYS_CLR
:
138 return "PLL_SYS_CLR";
139 case CCM_ANALOG_PLL_SYS_TOG
:
140 return "PLL_SYS_TOG";
141 case CCM_ANALOG_PLL_SYS_SS
:
143 case CCM_ANALOG_PLL_SYS_NUM
:
144 return "PLL_SYS_NUM";
145 case CCM_ANALOG_PLL_SYS_DENOM
:
146 return "PLL_SYS_DENOM";
147 case CCM_ANALOG_PLL_AUDIO
:
149 case CCM_ANALOG_PLL_AUDIO_SET
:
150 return "PLL_AUDIO_SET";
151 case CCM_ANALOG_PLL_AUDIO_CLR
:
152 return "PLL_AUDIO_CLR";
153 case CCM_ANALOG_PLL_AUDIO_TOG
:
154 return "PLL_AUDIO_TOG";
155 case CCM_ANALOG_PLL_AUDIO_NUM
:
156 return "PLL_AUDIO_NUM";
157 case CCM_ANALOG_PLL_AUDIO_DENOM
:
158 return "PLL_AUDIO_DENOM";
159 case CCM_ANALOG_PLL_VIDEO
:
161 case CCM_ANALOG_PLL_VIDEO_SET
:
162 return "PLL_VIDEO_SET";
163 case CCM_ANALOG_PLL_VIDEO_CLR
:
164 return "PLL_VIDEO_CLR";
165 case CCM_ANALOG_PLL_VIDEO_TOG
:
166 return "PLL_VIDEO_TOG";
167 case CCM_ANALOG_PLL_VIDEO_NUM
:
168 return "PLL_VIDEO_NUM";
169 case CCM_ANALOG_PLL_VIDEO_DENOM
:
170 return "PLL_VIDEO_DENOM";
171 case CCM_ANALOG_PLL_MLB
:
173 case CCM_ANALOG_PLL_MLB_SET
:
174 return "PLL_MLB_SET";
175 case CCM_ANALOG_PLL_MLB_CLR
:
176 return "PLL_MLB_CLR";
177 case CCM_ANALOG_PLL_MLB_TOG
:
178 return "PLL_MLB_TOG";
179 case CCM_ANALOG_PLL_ENET
:
181 case CCM_ANALOG_PLL_ENET_SET
:
182 return "PLL_ENET_SET";
183 case CCM_ANALOG_PLL_ENET_CLR
:
184 return "PLL_ENET_CLR";
185 case CCM_ANALOG_PLL_ENET_TOG
:
186 return "PLL_ENET_TOG";
187 case CCM_ANALOG_PFD_480
:
189 case CCM_ANALOG_PFD_480_SET
:
190 return "PFD_480_SET";
191 case CCM_ANALOG_PFD_480_CLR
:
192 return "PFD_480_CLR";
193 case CCM_ANALOG_PFD_480_TOG
:
194 return "PFD_480_TOG";
195 case CCM_ANALOG_PFD_528
:
197 case CCM_ANALOG_PFD_528_SET
:
198 return "PFD_528_SET";
199 case CCM_ANALOG_PFD_528_CLR
:
200 return "PFD_528_CLR";
201 case CCM_ANALOG_PFD_528_TOG
:
202 return "PFD_528_TOG";
203 case CCM_ANALOG_MISC0
:
205 case CCM_ANALOG_MISC0_SET
:
207 case CCM_ANALOG_MISC0_CLR
:
209 case CCM_ANALOG_MISC0_TOG
:
211 case CCM_ANALOG_MISC2
:
213 case CCM_ANALOG_MISC2_SET
:
215 case CCM_ANALOG_MISC2_CLR
:
217 case CCM_ANALOG_MISC2_TOG
:
220 return "PMU_REG_1P1";
222 return "PMU_REG_3P0";
224 return "PMU_REG_2P5";
226 return "PMU_REG_CORE";
230 return "PMU_MISC1_SET";
232 return "PMU_MISC1_CLR";
234 return "PMU_MISC1_TOG";
235 case USB_ANALOG_DIGPROG
:
236 return "USB_ANALOG_DIGPROG";
238 sprintf(unknown
, "%u ?", reg
);
243 #define CKIH_FREQ 24000000 /* 24MHz crystal input */
245 static const VMStateDescription vmstate_imx6_ccm
= {
246 .name
= TYPE_IMX6_CCM
,
248 .minimum_version_id
= 1,
249 .fields
= (VMStateField
[]) {
250 VMSTATE_UINT32_ARRAY(ccm
, IMX6CCMState
, CCM_MAX
),
251 VMSTATE_UINT32_ARRAY(analog
, IMX6CCMState
, CCM_ANALOG_MAX
),
252 VMSTATE_END_OF_LIST()
256 static uint64_t imx6_analog_get_pll2_clk(IMX6CCMState
*dev
)
258 uint64_t freq
= 24000000;
260 if (EXTRACT(dev
->analog
[CCM_ANALOG_PLL_SYS
], DIV_SELECT
)) {
266 DPRINTF("freq = %u\n", (uint32_t)freq
);
271 static uint64_t imx6_analog_get_pll2_pfd0_clk(IMX6CCMState
*dev
)
275 freq
= imx6_analog_get_pll2_clk(dev
) * 18
276 / EXTRACT(dev
->analog
[CCM_ANALOG_PFD_528
], PFD0_FRAC
);
278 DPRINTF("freq = %u\n", (uint32_t)freq
);
283 static uint64_t imx6_analog_get_pll2_pfd2_clk(IMX6CCMState
*dev
)
287 freq
= imx6_analog_get_pll2_clk(dev
) * 18
288 / EXTRACT(dev
->analog
[CCM_ANALOG_PFD_528
], PFD2_FRAC
);
290 DPRINTF("freq = %u\n", (uint32_t)freq
);
295 static uint64_t imx6_analog_get_periph_clk(IMX6CCMState
*dev
)
299 switch (EXTRACT(dev
->ccm
[CCM_CBCMR
], PRE_PERIPH_CLK_SEL
)) {
301 freq
= imx6_analog_get_pll2_clk(dev
);
304 freq
= imx6_analog_get_pll2_pfd2_clk(dev
);
307 freq
= imx6_analog_get_pll2_pfd0_clk(dev
);
310 freq
= imx6_analog_get_pll2_pfd2_clk(dev
) / 2;
313 /* We should never get there */
314 g_assert_not_reached();
318 DPRINTF("freq = %u\n", (uint32_t)freq
);
323 static uint64_t imx6_ccm_get_ahb_clk(IMX6CCMState
*dev
)
327 freq
= imx6_analog_get_periph_clk(dev
)
328 / (1 + EXTRACT(dev
->ccm
[CCM_CBCDR
], AHB_PODF
));
330 DPRINTF("freq = %u\n", (uint32_t)freq
);
335 static uint64_t imx6_ccm_get_ipg_clk(IMX6CCMState
*dev
)
339 freq
= imx6_ccm_get_ahb_clk(dev
)
340 / (1 + EXTRACT(dev
->ccm
[CCM_CBCDR
], IPG_PODF
));
342 DPRINTF("freq = %u\n", (uint32_t)freq
);
347 static uint64_t imx6_ccm_get_per_clk(IMX6CCMState
*dev
)
351 freq
= imx6_ccm_get_ipg_clk(dev
)
352 / (1 + EXTRACT(dev
->ccm
[CCM_CSCMR1
], PERCLK_PODF
));
354 DPRINTF("freq = %u\n", (uint32_t)freq
);
359 static uint32_t imx6_ccm_get_clock_frequency(IMXCCMState
*dev
, IMXClk clock
)
362 IMX6CCMState
*s
= IMX6_CCM(dev
);
368 freq
= imx6_ccm_get_ipg_clk(s
);
371 freq
= imx6_ccm_get_per_clk(s
);
383 qemu_log_mask(LOG_GUEST_ERROR
, "[%s]%s: unsupported clock %d\n",
384 TYPE_IMX6_CCM
, __func__
, clock
);
388 DPRINTF("Clock = %d) = %u\n", clock
, freq
);
393 static void imx6_ccm_reset(DeviceState
*dev
)
395 IMX6CCMState
*s
= IMX6_CCM(dev
);
399 s
->ccm
[CCM_CCR
] = 0x040116FF;
400 s
->ccm
[CCM_CCDR
] = 0x00000000;
401 s
->ccm
[CCM_CSR
] = 0x00000010;
402 s
->ccm
[CCM_CCSR
] = 0x00000100;
403 s
->ccm
[CCM_CACRR
] = 0x00000000;
404 s
->ccm
[CCM_CBCDR
] = 0x00018D40;
405 s
->ccm
[CCM_CBCMR
] = 0x00022324;
406 s
->ccm
[CCM_CSCMR1
] = 0x00F00000;
407 s
->ccm
[CCM_CSCMR2
] = 0x02B92F06;
408 s
->ccm
[CCM_CSCDR1
] = 0x00490B00;
409 s
->ccm
[CCM_CS1CDR
] = 0x0EC102C1;
410 s
->ccm
[CCM_CS2CDR
] = 0x000736C1;
411 s
->ccm
[CCM_CDCDR
] = 0x33F71F92;
412 s
->ccm
[CCM_CHSCCDR
] = 0x0002A150;
413 s
->ccm
[CCM_CSCDR2
] = 0x0002A150;
414 s
->ccm
[CCM_CSCDR3
] = 0x00014841;
415 s
->ccm
[CCM_CDHIPR
] = 0x00000000;
416 s
->ccm
[CCM_CTOR
] = 0x00000000;
417 s
->ccm
[CCM_CLPCR
] = 0x00000079;
418 s
->ccm
[CCM_CISR
] = 0x00000000;
419 s
->ccm
[CCM_CIMR
] = 0xFFFFFFFF;
420 s
->ccm
[CCM_CCOSR
] = 0x000A0001;
421 s
->ccm
[CCM_CGPR
] = 0x0000FE62;
422 s
->ccm
[CCM_CCGR0
] = 0xFFFFFFFF;
423 s
->ccm
[CCM_CCGR1
] = 0xFFFFFFFF;
424 s
->ccm
[CCM_CCGR2
] = 0xFC3FFFFF;
425 s
->ccm
[CCM_CCGR3
] = 0xFFFFFFFF;
426 s
->ccm
[CCM_CCGR4
] = 0xFFFFFFFF;
427 s
->ccm
[CCM_CCGR5
] = 0xFFFFFFFF;
428 s
->ccm
[CCM_CCGR6
] = 0xFFFFFFFF;
429 s
->ccm
[CCM_CMEOR
] = 0xFFFFFFFF;
431 s
->analog
[CCM_ANALOG_PLL_ARM
] = 0x00013042;
432 s
->analog
[CCM_ANALOG_PLL_USB1
] = 0x00012000;
433 s
->analog
[CCM_ANALOG_PLL_USB2
] = 0x00012000;
434 s
->analog
[CCM_ANALOG_PLL_SYS
] = 0x00013001;
435 s
->analog
[CCM_ANALOG_PLL_SYS_SS
] = 0x00000000;
436 s
->analog
[CCM_ANALOG_PLL_SYS_NUM
] = 0x00000000;
437 s
->analog
[CCM_ANALOG_PLL_SYS_DENOM
] = 0x00000012;
438 s
->analog
[CCM_ANALOG_PLL_AUDIO
] = 0x00011006;
439 s
->analog
[CCM_ANALOG_PLL_AUDIO_NUM
] = 0x05F5E100;
440 s
->analog
[CCM_ANALOG_PLL_AUDIO_DENOM
] = 0x2964619C;
441 s
->analog
[CCM_ANALOG_PLL_VIDEO
] = 0x0001100C;
442 s
->analog
[CCM_ANALOG_PLL_VIDEO_NUM
] = 0x05F5E100;
443 s
->analog
[CCM_ANALOG_PLL_VIDEO_DENOM
] = 0x10A24447;
444 s
->analog
[CCM_ANALOG_PLL_MLB
] = 0x00010000;
445 s
->analog
[CCM_ANALOG_PLL_ENET
] = 0x00011001;
446 s
->analog
[CCM_ANALOG_PFD_480
] = 0x1311100C;
447 s
->analog
[CCM_ANALOG_PFD_528
] = 0x1018101B;
449 s
->analog
[PMU_REG_1P1
] = 0x00001073;
450 s
->analog
[PMU_REG_3P0
] = 0x00000F74;
451 s
->analog
[PMU_REG_2P5
] = 0x00005071;
452 s
->analog
[PMU_REG_CORE
] = 0x00402010;
453 s
->analog
[PMU_MISC0
] = 0x04000080;
454 s
->analog
[PMU_MISC1
] = 0x00000000;
455 s
->analog
[PMU_MISC2
] = 0x00272727;
457 s
->analog
[USB_ANALOG_USB1_VBUS_DETECT
] = 0x00000004;
458 s
->analog
[USB_ANALOG_USB1_CHRG_DETECT
] = 0x00000000;
459 s
->analog
[USB_ANALOG_USB1_VBUS_DETECT_STAT
] = 0x00000000;
460 s
->analog
[USB_ANALOG_USB1_CHRG_DETECT_STAT
] = 0x00000000;
461 s
->analog
[USB_ANALOG_USB1_MISC
] = 0x00000002;
462 s
->analog
[USB_ANALOG_USB2_VBUS_DETECT
] = 0x00000004;
463 s
->analog
[USB_ANALOG_USB2_CHRG_DETECT
] = 0x00000000;
464 s
->analog
[USB_ANALOG_USB2_MISC
] = 0x00000002;
465 s
->analog
[USB_ANALOG_DIGPROG
] = 0x00630000;
467 /* all PLLs need to be locked */
468 s
->analog
[CCM_ANALOG_PLL_ARM
] |= CCM_ANALOG_PLL_LOCK
;
469 s
->analog
[CCM_ANALOG_PLL_USB1
] |= CCM_ANALOG_PLL_LOCK
;
470 s
->analog
[CCM_ANALOG_PLL_USB2
] |= CCM_ANALOG_PLL_LOCK
;
471 s
->analog
[CCM_ANALOG_PLL_SYS
] |= CCM_ANALOG_PLL_LOCK
;
472 s
->analog
[CCM_ANALOG_PLL_AUDIO
] |= CCM_ANALOG_PLL_LOCK
;
473 s
->analog
[CCM_ANALOG_PLL_VIDEO
] |= CCM_ANALOG_PLL_LOCK
;
474 s
->analog
[CCM_ANALOG_PLL_MLB
] |= CCM_ANALOG_PLL_LOCK
;
475 s
->analog
[CCM_ANALOG_PLL_ENET
] |= CCM_ANALOG_PLL_LOCK
;
478 static uint64_t imx6_ccm_read(void *opaque
, hwaddr offset
, unsigned size
)
481 uint32_t index
= offset
>> 2;
482 IMX6CCMState
*s
= (IMX6CCMState
*)opaque
;
484 value
= s
->ccm
[index
];
486 DPRINTF("reg[%s] => 0x%" PRIx32
"\n", imx6_ccm_reg_name(index
), value
);
488 return (uint64_t)value
;
491 static void imx6_ccm_write(void *opaque
, hwaddr offset
, uint64_t value
,
494 uint32_t index
= offset
>> 2;
495 IMX6CCMState
*s
= (IMX6CCMState
*)opaque
;
497 DPRINTF("reg[%s] <= 0x%" PRIx32
"\n", imx6_ccm_reg_name(index
),
501 * We will do a better implementation later. In particular some bits
502 * cannot be written to.
504 s
->ccm
[index
] = (uint32_t)value
;
507 static uint64_t imx6_analog_read(void *opaque
, hwaddr offset
, unsigned size
)
510 uint32_t index
= offset
>> 2;
511 IMX6CCMState
*s
= (IMX6CCMState
*)opaque
;
514 case CCM_ANALOG_PLL_ARM_SET
:
515 case CCM_ANALOG_PLL_USB1_SET
:
516 case CCM_ANALOG_PLL_USB2_SET
:
517 case CCM_ANALOG_PLL_SYS_SET
:
518 case CCM_ANALOG_PLL_AUDIO_SET
:
519 case CCM_ANALOG_PLL_VIDEO_SET
:
520 case CCM_ANALOG_PLL_MLB_SET
:
521 case CCM_ANALOG_PLL_ENET_SET
:
522 case CCM_ANALOG_PFD_480_SET
:
523 case CCM_ANALOG_PFD_528_SET
:
524 case CCM_ANALOG_MISC0_SET
:
526 case CCM_ANALOG_MISC2_SET
:
527 case USB_ANALOG_USB1_VBUS_DETECT_SET
:
528 case USB_ANALOG_USB1_CHRG_DETECT_SET
:
529 case USB_ANALOG_USB1_MISC_SET
:
530 case USB_ANALOG_USB2_VBUS_DETECT_SET
:
531 case USB_ANALOG_USB2_CHRG_DETECT_SET
:
532 case USB_ANALOG_USB2_MISC_SET
:
534 * All REG_NAME_SET register access are in fact targeting the
535 * the REG_NAME register.
537 value
= s
->analog
[index
- 1];
539 case CCM_ANALOG_PLL_ARM_CLR
:
540 case CCM_ANALOG_PLL_USB1_CLR
:
541 case CCM_ANALOG_PLL_USB2_CLR
:
542 case CCM_ANALOG_PLL_SYS_CLR
:
543 case CCM_ANALOG_PLL_AUDIO_CLR
:
544 case CCM_ANALOG_PLL_VIDEO_CLR
:
545 case CCM_ANALOG_PLL_MLB_CLR
:
546 case CCM_ANALOG_PLL_ENET_CLR
:
547 case CCM_ANALOG_PFD_480_CLR
:
548 case CCM_ANALOG_PFD_528_CLR
:
549 case CCM_ANALOG_MISC0_CLR
:
551 case CCM_ANALOG_MISC2_CLR
:
552 case USB_ANALOG_USB1_VBUS_DETECT_CLR
:
553 case USB_ANALOG_USB1_CHRG_DETECT_CLR
:
554 case USB_ANALOG_USB1_MISC_CLR
:
555 case USB_ANALOG_USB2_VBUS_DETECT_CLR
:
556 case USB_ANALOG_USB2_CHRG_DETECT_CLR
:
557 case USB_ANALOG_USB2_MISC_CLR
:
559 * All REG_NAME_CLR register access are in fact targeting the
560 * the REG_NAME register.
562 value
= s
->analog
[index
- 2];
564 case CCM_ANALOG_PLL_ARM_TOG
:
565 case CCM_ANALOG_PLL_USB1_TOG
:
566 case CCM_ANALOG_PLL_USB2_TOG
:
567 case CCM_ANALOG_PLL_SYS_TOG
:
568 case CCM_ANALOG_PLL_AUDIO_TOG
:
569 case CCM_ANALOG_PLL_VIDEO_TOG
:
570 case CCM_ANALOG_PLL_MLB_TOG
:
571 case CCM_ANALOG_PLL_ENET_TOG
:
572 case CCM_ANALOG_PFD_480_TOG
:
573 case CCM_ANALOG_PFD_528_TOG
:
574 case CCM_ANALOG_MISC0_TOG
:
576 case CCM_ANALOG_MISC2_TOG
:
577 case USB_ANALOG_USB1_VBUS_DETECT_TOG
:
578 case USB_ANALOG_USB1_CHRG_DETECT_TOG
:
579 case USB_ANALOG_USB1_MISC_TOG
:
580 case USB_ANALOG_USB2_VBUS_DETECT_TOG
:
581 case USB_ANALOG_USB2_CHRG_DETECT_TOG
:
582 case USB_ANALOG_USB2_MISC_TOG
:
584 * All REG_NAME_TOG register access are in fact targeting the
585 * the REG_NAME register.
587 value
= s
->analog
[index
- 3];
590 value
= s
->analog
[index
];
594 DPRINTF("reg[%s] => 0x%" PRIx32
"\n", imx6_analog_reg_name(index
), value
);
596 return (uint64_t)value
;
599 static void imx6_analog_write(void *opaque
, hwaddr offset
, uint64_t value
,
602 uint32_t index
= offset
>> 2;
603 IMX6CCMState
*s
= (IMX6CCMState
*)opaque
;
605 DPRINTF("reg[%s] <= 0x%" PRIx32
"\n", imx6_analog_reg_name(index
),
609 case CCM_ANALOG_PLL_ARM_SET
:
610 case CCM_ANALOG_PLL_USB1_SET
:
611 case CCM_ANALOG_PLL_USB2_SET
:
612 case CCM_ANALOG_PLL_SYS_SET
:
613 case CCM_ANALOG_PLL_AUDIO_SET
:
614 case CCM_ANALOG_PLL_VIDEO_SET
:
615 case CCM_ANALOG_PLL_MLB_SET
:
616 case CCM_ANALOG_PLL_ENET_SET
:
617 case CCM_ANALOG_PFD_480_SET
:
618 case CCM_ANALOG_PFD_528_SET
:
619 case CCM_ANALOG_MISC0_SET
:
621 case CCM_ANALOG_MISC2_SET
:
622 case USB_ANALOG_USB1_VBUS_DETECT_SET
:
623 case USB_ANALOG_USB1_CHRG_DETECT_SET
:
624 case USB_ANALOG_USB1_MISC_SET
:
625 case USB_ANALOG_USB2_VBUS_DETECT_SET
:
626 case USB_ANALOG_USB2_CHRG_DETECT_SET
:
627 case USB_ANALOG_USB2_MISC_SET
:
629 * All REG_NAME_SET register access are in fact targeting the
630 * the REG_NAME register. So we change the value of the
631 * REG_NAME register, setting bits passed in the value.
633 s
->analog
[index
- 1] |= value
;
635 case CCM_ANALOG_PLL_ARM_CLR
:
636 case CCM_ANALOG_PLL_USB1_CLR
:
637 case CCM_ANALOG_PLL_USB2_CLR
:
638 case CCM_ANALOG_PLL_SYS_CLR
:
639 case CCM_ANALOG_PLL_AUDIO_CLR
:
640 case CCM_ANALOG_PLL_VIDEO_CLR
:
641 case CCM_ANALOG_PLL_MLB_CLR
:
642 case CCM_ANALOG_PLL_ENET_CLR
:
643 case CCM_ANALOG_PFD_480_CLR
:
644 case CCM_ANALOG_PFD_528_CLR
:
645 case CCM_ANALOG_MISC0_CLR
:
647 case CCM_ANALOG_MISC2_CLR
:
648 case USB_ANALOG_USB1_VBUS_DETECT_CLR
:
649 case USB_ANALOG_USB1_CHRG_DETECT_CLR
:
650 case USB_ANALOG_USB1_MISC_CLR
:
651 case USB_ANALOG_USB2_VBUS_DETECT_CLR
:
652 case USB_ANALOG_USB2_CHRG_DETECT_CLR
:
653 case USB_ANALOG_USB2_MISC_CLR
:
655 * All REG_NAME_CLR register access are in fact targeting the
656 * the REG_NAME register. So we change the value of the
657 * REG_NAME register, unsetting bits passed in the value.
659 s
->analog
[index
- 2] &= ~value
;
661 case CCM_ANALOG_PLL_ARM_TOG
:
662 case CCM_ANALOG_PLL_USB1_TOG
:
663 case CCM_ANALOG_PLL_USB2_TOG
:
664 case CCM_ANALOG_PLL_SYS_TOG
:
665 case CCM_ANALOG_PLL_AUDIO_TOG
:
666 case CCM_ANALOG_PLL_VIDEO_TOG
:
667 case CCM_ANALOG_PLL_MLB_TOG
:
668 case CCM_ANALOG_PLL_ENET_TOG
:
669 case CCM_ANALOG_PFD_480_TOG
:
670 case CCM_ANALOG_PFD_528_TOG
:
671 case CCM_ANALOG_MISC0_TOG
:
673 case CCM_ANALOG_MISC2_TOG
:
674 case USB_ANALOG_USB1_VBUS_DETECT_TOG
:
675 case USB_ANALOG_USB1_CHRG_DETECT_TOG
:
676 case USB_ANALOG_USB1_MISC_TOG
:
677 case USB_ANALOG_USB2_VBUS_DETECT_TOG
:
678 case USB_ANALOG_USB2_CHRG_DETECT_TOG
:
679 case USB_ANALOG_USB2_MISC_TOG
:
681 * All REG_NAME_TOG register access are in fact targeting the
682 * the REG_NAME register. So we change the value of the
683 * REG_NAME register, toggling bits passed in the value.
685 s
->analog
[index
- 3] ^= value
;
689 * We will do a better implementation later. In particular some bits
690 * cannot be written to.
692 s
->analog
[index
] = value
;
697 static const struct MemoryRegionOps imx6_ccm_ops
= {
698 .read
= imx6_ccm_read
,
699 .write
= imx6_ccm_write
,
700 .endianness
= DEVICE_NATIVE_ENDIAN
,
703 * Our device would not work correctly if the guest was doing
704 * unaligned access. This might not be a limitation on the real
705 * device but in practice there is no reason for a guest to access
706 * this device unaligned.
708 .min_access_size
= 4,
709 .max_access_size
= 4,
714 static const struct MemoryRegionOps imx6_analog_ops
= {
715 .read
= imx6_analog_read
,
716 .write
= imx6_analog_write
,
717 .endianness
= DEVICE_NATIVE_ENDIAN
,
720 * Our device would not work correctly if the guest was doing
721 * unaligned access. This might not be a limitation on the real
722 * device but in practice there is no reason for a guest to access
723 * this device unaligned.
725 .min_access_size
= 4,
726 .max_access_size
= 4,
731 static void imx6_ccm_init(Object
*obj
)
733 DeviceState
*dev
= DEVICE(obj
);
734 SysBusDevice
*sd
= SYS_BUS_DEVICE(obj
);
735 IMX6CCMState
*s
= IMX6_CCM(obj
);
737 /* initialize a container for the all memory range */
738 memory_region_init(&s
->container
, OBJECT(dev
), TYPE_IMX6_CCM
, 0x5000);
740 /* We initialize an IO memory region for the CCM part */
741 memory_region_init_io(&s
->ioccm
, OBJECT(dev
), &imx6_ccm_ops
, s
,
742 TYPE_IMX6_CCM
".ccm", CCM_MAX
* sizeof(uint32_t));
744 /* Add the CCM as a subregion at offset 0 */
745 memory_region_add_subregion(&s
->container
, 0, &s
->ioccm
);
747 /* We initialize an IO memory region for the ANALOG part */
748 memory_region_init_io(&s
->ioanalog
, OBJECT(dev
), &imx6_analog_ops
, s
,
749 TYPE_IMX6_CCM
".analog",
750 CCM_ANALOG_MAX
* sizeof(uint32_t));
752 /* Add the ANALOG as a subregion at offset 0x4000 */
753 memory_region_add_subregion(&s
->container
, 0x4000, &s
->ioanalog
);
755 sysbus_init_mmio(sd
, &s
->container
);
758 static void imx6_ccm_class_init(ObjectClass
*klass
, void *data
)
760 DeviceClass
*dc
= DEVICE_CLASS(klass
);
761 IMXCCMClass
*ccm
= IMX_CCM_CLASS(klass
);
763 dc
->reset
= imx6_ccm_reset
;
764 dc
->vmsd
= &vmstate_imx6_ccm
;
765 dc
->desc
= "i.MX6 Clock Control Module";
767 ccm
->get_clock_frequency
= imx6_ccm_get_clock_frequency
;
770 static const TypeInfo imx6_ccm_info
= {
771 .name
= TYPE_IMX6_CCM
,
772 .parent
= TYPE_IMX_CCM
,
773 .instance_size
= sizeof(IMX6CCMState
),
774 .instance_init
= imx6_ccm_init
,
775 .class_init
= imx6_ccm_class_init
,
778 static void imx6_ccm_register_types(void)
780 type_register_static(&imx6_ccm_info
);
783 type_init(imx6_ccm_register_types
)