2 * IMX31 Clock Control Module
4 * Copyright (C) 2012 NICTA
5 * Updated by Jean-Christophe Dubois <jcd@tribudubois.net>
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
10 * This is an abstract base class used to get a common interface to
11 * retrieve the CCM frequencies from the various i.MX SOC.
14 #include "qemu/osdep.h"
15 #include "hw/misc/imx_ccm.h"
16 #include "qemu/module.h"
19 #define DEBUG_IMX_CCM 0
22 #define DPRINTF(fmt, args...) \
24 if (DEBUG_IMX_CCM) { \
25 fprintf(stderr, "[%s]%s: " fmt , TYPE_IMX_CCM, \
31 uint32_t imx_ccm_get_clock_frequency(IMXCCMState
*dev
, IMXClk clock
)
34 IMXCCMClass
*klass
= IMX_CCM_GET_CLASS(dev
);
36 if (klass
->get_clock_frequency
) {
37 freq
= klass
->get_clock_frequency(dev
, clock
);
40 DPRINTF("(clock = %d) = %u\n", clock
, freq
);
46 * Calculate PLL output frequency
48 uint32_t imx_ccm_calc_pll(uint32_t pllreg
, uint32_t base_freq
)
51 int32_t mfn
= MFN(pllreg
); /* Numerator */
52 uint32_t mfi
= MFI(pllreg
); /* Integer part */
53 uint32_t mfd
= 1 + MFD(pllreg
); /* Denominator */
54 uint32_t pd
= 1 + PD(pllreg
); /* Pre-divider */
60 /* mfn is 10-bit signed twos-complement */
64 freq
= ((2 * (base_freq
>> 10) * (mfi
* mfd
+ mfn
)) /
67 DPRINTF("(pllreg = 0x%08x, base_freq = %u) = %d\n", pllreg
, base_freq
,
73 static const TypeInfo imx_ccm_info
= {
75 .parent
= TYPE_SYS_BUS_DEVICE
,
76 .instance_size
= sizeof(IMXCCMState
),
77 .class_size
= sizeof(IMXCCMClass
),
81 static void imx_ccm_register_types(void)
83 type_register_static(&imx_ccm_info
);
86 type_init(imx_ccm_register_types
)