]> Git Repo - qemu.git/blame - hw/misc/imx_ccm.c
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[qemu.git] / hw / misc / imx_ccm.c
CommitLineData
bcc181b0
PC
1/*
2 * IMX31 Clock Control Module
3 *
4 * Copyright (C) 2012 NICTA
282e74c8 5 * Updated by Jean-Christophe Dubois <[email protected]>
bcc181b0
PC
6 *
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.
9 *
cb54d868
JCD
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.
bcc181b0
PC
12 */
13
8ef94f0b 14#include "qemu/osdep.h"
282e74c8 15#include "hw/misc/imx_ccm.h"
03dd024f 16#include "qemu/log.h"
bcc181b0 17
4a6aa0af
JCD
18#ifndef DEBUG_IMX_CCM
19#define DEBUG_IMX_CCM 0
bcc181b0
PC
20#endif
21
4a6aa0af
JCD
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
bcc181b0 30
cb54d868 31uint32_t imx_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
bcc181b0 32{
cb54d868
JCD
33 uint32_t freq = 0;
34 IMXCCMClass *klass = IMX_GET_CLASS(dev);
bcc181b0 35
cb54d868
JCD
36 if (klass->get_clock_frequency) {
37 freq = klass->get_clock_frequency(dev, clock);
bcc181b0 38 }
cb54d868
JCD
39
40 DPRINTF("(clock = %d) = %d\n", clock, freq);
41
42 return freq;
bcc181b0
PC
43}
44
45/*
46 * Calculate PLL output frequency
47 */
cb54d868 48uint32_t imx_ccm_calc_pll(uint32_t pllreg, uint32_t base_freq)
bcc181b0 49{
cb54d868 50 int32_t freq;
bcc181b0
PC
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 */
55
56 if (mfi < 5) {
57 mfi = 5;
58 }
cb54d868 59
bcc181b0
PC
60 /* mfn is 10-bit signed twos-complement */
61 mfn <<= 32 - 10;
62 mfn >>= 32 - 10;
63
cb54d868 64 freq = ((2 * (base_freq >> 10) * (mfi * mfd + mfn)) /
bcc181b0 65 (mfd * pd)) << 10;
bcc181b0 66
cb54d868
JCD
67 DPRINTF("(pllreg = 0x%08x, base_freq = %d) = %d\n", pllreg, base_freq,
68 freq);
bcc181b0 69
cb54d868 70 return freq;
bcc181b0
PC
71}
72
8c43a6f0 73static const TypeInfo imx_ccm_info = {
cb54d868
JCD
74 .name = TYPE_IMX_CCM,
75 .parent = TYPE_SYS_BUS_DEVICE,
bcc181b0 76 .instance_size = sizeof(IMXCCMState),
cb54d868
JCD
77 .class_size = sizeof(IMXCCMClass),
78 .abstract = true,
bcc181b0
PC
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)
This page took 0.258157 seconds and 4 git commands to generate.