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