1
2
3
4
5
6
7
8
9
10
11
12
13
14#include "qemu/osdep.h"
15#include "hw/misc/imx_ccm.h"
16#include "qemu/log.h"
17
18#ifndef DEBUG_IMX_CCM
19#define DEBUG_IMX_CCM 0
20#endif
21
22#define DPRINTF(fmt, args...) \
23 do { \
24 if (DEBUG_IMX_CCM) { \
25 fprintf(stderr, "[%s]%s: " fmt , TYPE_IMX_CCM, \
26 __func__, ##args); \
27 } \
28 } while (0)
29
30
31uint32_t imx_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
32{
33 uint32_t freq = 0;
34 IMXCCMClass *klass = IMX_GET_CLASS(dev);
35
36 if (klass->get_clock_frequency) {
37 freq = klass->get_clock_frequency(dev, clock);
38 }
39
40 DPRINTF("(clock = %d) = %d\n", clock, freq);
41
42 return freq;
43}
44
45
46
47
48uint32_t imx_ccm_calc_pll(uint32_t pllreg, uint32_t base_freq)
49{
50 int32_t freq;
51 int32_t mfn = MFN(pllreg);
52 uint32_t mfi = MFI(pllreg);
53 uint32_t mfd = 1 + MFD(pllreg);
54 uint32_t pd = 1 + PD(pllreg);
55
56 if (mfi < 5) {
57 mfi = 5;
58 }
59
60
61 mfn <<= 32 - 10;
62 mfn >>= 32 - 10;
63
64 freq = ((2 * (base_freq >> 10) * (mfi * mfd + mfn)) /
65 (mfd * pd)) << 10;
66
67 DPRINTF("(pllreg = 0x%08x, base_freq = %d) = %d\n", pllreg, base_freq,
68 freq);
69
70 return freq;
71}
72
73static const TypeInfo imx_ccm_info = {
74 .name = TYPE_IMX_CCM,
75 .parent = TYPE_SYS_BUS_DEVICE,
76 .instance_size = sizeof(IMXCCMState),
77 .class_size = sizeof(IMXCCMClass),
78 .abstract = true,
79};
80
81static void imx_ccm_register_types(void)
82{
83 type_register_static(&imx_ccm_info);
84}
85
86type_init(imx_ccm_register_types)
87