2012-07-04 12:43:33 +02:00
|
|
|
/*
|
|
|
|
* IMX31 Clock Control Module
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 NICTA
|
2015-08-13 12:26:20 +02:00
|
|
|
* Updated by Jean-Christophe Dubois <jcd@tribudubois.net>
|
2012-07-04 12:43:33 +02: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 14:37:15 +01: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 12:43:33 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
2015-08-13 12:26:20 +02:00
|
|
|
#include "hw/misc/imx_ccm.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2012-07-04 12:43:33 +02:00
|
|
|
|
2015-10-25 15:16:19 +01:00
|
|
|
#ifndef DEBUG_IMX_CCM
|
|
|
|
#define DEBUG_IMX_CCM 0
|
2012-07-04 12:43:33 +02:00
|
|
|
#endif
|
|
|
|
|
2015-10-25 15:16:19 +01: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 12:43:33 +02:00
|
|
|
|
2015-12-17 14:37:15 +01:00
|
|
|
uint32_t imx_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
|
2012-07-04 12:43:33 +02:00
|
|
|
{
|
2015-12-17 14:37:15 +01:00
|
|
|
uint32_t freq = 0;
|
2020-08-25 21:20:40 +02:00
|
|
|
IMXCCMClass *klass = IMX_CCM_GET_CLASS(dev);
|
2012-07-04 12:43:33 +02:00
|
|
|
|
2015-12-17 14:37:15 +01:00
|
|
|
if (klass->get_clock_frequency) {
|
|
|
|
freq = klass->get_clock_frequency(dev, clock);
|
2012-07-04 12:43:33 +02:00
|
|
|
}
|
2015-12-17 14:37:15 +01:00
|
|
|
|
2020-11-26 12:11:06 +01:00
|
|
|
DPRINTF("(clock = %d) = %u\n", clock, freq);
|
2015-12-17 14:37:15 +01:00
|
|
|
|
|
|
|
return freq;
|
2012-07-04 12:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate PLL output frequency
|
|
|
|
*/
|
2015-12-17 14:37:15 +01:00
|
|
|
uint32_t imx_ccm_calc_pll(uint32_t pllreg, uint32_t base_freq)
|
2012-07-04 12:43:33 +02:00
|
|
|
{
|
2015-12-17 14:37:15 +01:00
|
|
|
int32_t freq;
|
2012-07-04 12:43:33 +02: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 14:37:15 +01:00
|
|
|
|
2012-07-04 12:43:33 +02:00
|
|
|
/* mfn is 10-bit signed twos-complement */
|
|
|
|
mfn <<= 32 - 10;
|
|
|
|
mfn >>= 32 - 10;
|
|
|
|
|
2015-12-17 14:37:15 +01:00
|
|
|
freq = ((2 * (base_freq >> 10) * (mfi * mfd + mfn)) /
|
2012-07-04 12:43:33 +02:00
|
|
|
(mfd * pd)) << 10;
|
|
|
|
|
2020-11-26 12:11:06 +01:00
|
|
|
DPRINTF("(pllreg = 0x%08x, base_freq = %u) = %d\n", pllreg, base_freq,
|
2015-12-17 14:37:15 +01:00
|
|
|
freq);
|
2012-07-04 12:43:33 +02:00
|
|
|
|
2015-12-17 14:37:15 +01:00
|
|
|
return freq;
|
2012-07-04 12:43:33 +02:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo imx_ccm_info = {
|
2015-12-17 14:37:15 +01:00
|
|
|
.name = TYPE_IMX_CCM,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2012-07-04 12:43:33 +02:00
|
|
|
.instance_size = sizeof(IMXCCMState),
|
2015-12-17 14:37:15 +01:00
|
|
|
.class_size = sizeof(IMXCCMClass),
|
|
|
|
.abstract = true,
|
2012-07-04 12:43:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void imx_ccm_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&imx_ccm_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(imx_ccm_register_types)
|