2012-07-04 14:43:33 +04:00
|
|
|
/*
|
|
|
|
* IMX31 Clock Control Module
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 NICTA
|
2015-08-13 13:26:20 +03:00
|
|
|
* Updated by Jean-Christophe Dubois <jcd@tribudubois.net>
|
2012-07-04 14:43:33 +04:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
2015-12-17 16:37:15 +03:00
|
|
|
* This is an abstract base class used to get a common interface to
|
|
|
|
* retrieve the CCM frequencies from the various i.MX SOC.
|
2012-07-04 14:43:33 +04:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:05 +03:00
|
|
|
#include "qemu/osdep.h"
|
2015-08-13 13:26:20 +03:00
|
|
|
#include "hw/misc/imx_ccm.h"
|
2015-12-15 15:16:16 +03:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2015-10-25 17:16:19 +03:00
|
|
|
#ifndef DEBUG_IMX_CCM
|
|
|
|
#define DEBUG_IMX_CCM 0
|
2012-07-04 14:43:33 +04:00
|
|
|
#endif
|
|
|
|
|
2015-10-25 17:16:19 +03:00
|
|
|
#define DPRINTF(fmt, args...) \
|
|
|
|
do { \
|
|
|
|
if (DEBUG_IMX_CCM) { \
|
|
|
|
fprintf(stderr, "[%s]%s: " fmt , TYPE_IMX_CCM, \
|
|
|
|
__func__, ##args); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2015-12-17 16:37:15 +03:00
|
|
|
uint32_t imx_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
|
2012-07-04 14:43:33 +04:00
|
|
|
{
|
2015-12-17 16:37:15 +03:00
|
|
|
uint32_t freq = 0;
|
|
|
|
IMXCCMClass *klass = IMX_GET_CLASS(dev);
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2015-12-17 16:37:15 +03:00
|
|
|
if (klass->get_clock_frequency) {
|
|
|
|
freq = klass->get_clock_frequency(dev, clock);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
2015-12-17 16:37:15 +03:00
|
|
|
|
|
|
|
DPRINTF("(clock = %d) = %d\n", clock, freq);
|
|
|
|
|
|
|
|
return freq;
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate PLL output frequency
|
|
|
|
*/
|
2015-12-17 16:37:15 +03:00
|
|
|
uint32_t imx_ccm_calc_pll(uint32_t pllreg, uint32_t base_freq)
|
2012-07-04 14:43:33 +04:00
|
|
|
{
|
2015-12-17 16:37:15 +03:00
|
|
|
int32_t freq;
|
2012-07-04 14:43:33 +04:00
|
|
|
int32_t mfn = MFN(pllreg); /* Numerator */
|
|
|
|
uint32_t mfi = MFI(pllreg); /* Integer part */
|
|
|
|
uint32_t mfd = 1 + MFD(pllreg); /* Denominator */
|
|
|
|
uint32_t pd = 1 + PD(pllreg); /* Pre-divider */
|
|
|
|
|
|
|
|
if (mfi < 5) {
|
|
|
|
mfi = 5;
|
|
|
|
}
|
2015-12-17 16:37:15 +03:00
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
/* mfn is 10-bit signed twos-complement */
|
|
|
|
mfn <<= 32 - 10;
|
|
|
|
mfn >>= 32 - 10;
|
|
|
|
|
2015-12-17 16:37:15 +03:00
|
|
|
freq = ((2 * (base_freq >> 10) * (mfi * mfd + mfn)) /
|
2012-07-04 14:43:33 +04:00
|
|
|
(mfd * pd)) << 10;
|
|
|
|
|
2015-12-17 16:37:15 +03:00
|
|
|
DPRINTF("(pllreg = 0x%08x, base_freq = %d) = %d\n", pllreg, base_freq,
|
|
|
|
freq);
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2015-12-17 16:37:15 +03:00
|
|
|
return freq;
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo imx_ccm_info = {
|
2015-12-17 16:37:15 +03:00
|
|
|
.name = TYPE_IMX_CCM,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2012-07-04 14:43:33 +04:00
|
|
|
.instance_size = sizeof(IMXCCMState),
|
2015-12-17 16:37:15 +03:00
|
|
|
.class_size = sizeof(IMXCCMClass),
|
|
|
|
.abstract = true,
|
2012-07-04 14:43:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void imx_ccm_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&imx_ccm_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(imx_ccm_register_types)
|