2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-10-26 11:47:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Freescale Semiconductor, Inc.
|
2019-06-03 11:24:23 +00:00
|
|
|
* Copyright 2019 NXP.
|
2015-10-26 11:47:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:44:58 +00:00
|
|
|
#include <clock_legacy.h>
|
2019-11-14 19:57:32 +00:00
|
|
|
#include <cpu_func.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2015-10-26 11:47:51 +00:00
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#include <asm/arch/soc.h>
|
|
|
|
#include <fsl_ifc.h>
|
2016-06-12 06:42:04 +00:00
|
|
|
#include "cpu.h"
|
2015-10-26 11:47:51 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
void get_sys_info(struct sys_info *sys_info)
|
|
|
|
{
|
|
|
|
struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
|
2019-07-16 07:09:06 +00:00
|
|
|
/* rcw_tmp is needed to get FMAN clock, or to get cluster group A
|
|
|
|
* mux 2 clock for LS1043A/LS1046A.
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_SYS_DPAA_FMAN) || \
|
2022-04-26 18:31:49 +00:00
|
|
|
defined(CONFIG_ARCH_LS1046A) || \
|
|
|
|
defined(CONFIG_ARCH_LS1043A)
|
2015-10-26 11:47:54 +00:00
|
|
|
u32 rcw_tmp;
|
2015-10-26 11:47:51 +00:00
|
|
|
#endif
|
|
|
|
struct ccsr_clk *clk = (void *)(CONFIG_SYS_FSL_CLK_ADDR);
|
|
|
|
unsigned int cpu;
|
|
|
|
const u8 core_cplx_pll[8] = {
|
|
|
|
[0] = 0, /* CC1 PPL / 1 */
|
|
|
|
[1] = 0, /* CC1 PPL / 2 */
|
|
|
|
[4] = 1, /* CC2 PPL / 1 */
|
|
|
|
[5] = 1, /* CC2 PPL / 2 */
|
|
|
|
};
|
|
|
|
|
|
|
|
const u8 core_cplx_pll_div[8] = {
|
|
|
|
[0] = 1, /* CC1 PPL / 1 */
|
|
|
|
[1] = 2, /* CC1 PPL / 2 */
|
|
|
|
[4] = 1, /* CC2 PPL / 1 */
|
|
|
|
[5] = 2, /* CC2 PPL / 2 */
|
|
|
|
};
|
|
|
|
|
2016-06-12 06:42:04 +00:00
|
|
|
uint i, cluster;
|
2015-10-26 11:47:51 +00:00
|
|
|
uint freq_c_pll[CONFIG_SYS_FSL_NUM_CC_PLLS];
|
|
|
|
uint ratio[CONFIG_SYS_FSL_NUM_CC_PLLS];
|
2021-12-14 18:36:40 +00:00
|
|
|
unsigned long sysclk = get_board_sys_clk();
|
2017-01-10 08:44:15 +00:00
|
|
|
unsigned long cluster_clk;
|
2015-10-26 11:47:51 +00:00
|
|
|
|
|
|
|
sys_info->freq_systembus = sysclk;
|
2017-01-10 08:44:15 +00:00
|
|
|
#ifndef CONFIG_CLUSTER_CLK_FREQ
|
2021-12-14 18:36:40 +00:00
|
|
|
#define CONFIG_CLUSTER_CLK_FREQ get_board_sys_clk()
|
2017-01-10 08:44:15 +00:00
|
|
|
#endif
|
|
|
|
cluster_clk = CONFIG_CLUSTER_CLK_FREQ;
|
|
|
|
|
2021-08-21 17:50:17 +00:00
|
|
|
#if defined(CONFIG_DYNAMIC_DDR_CLK_FREQ) || defined(CONFIG_STATIC_DDR_CLK_FREQ)
|
|
|
|
sys_info->freq_ddrbus = get_board_ddr_clk();
|
2015-10-26 11:47:51 +00:00
|
|
|
#else
|
|
|
|
sys_info->freq_ddrbus = sysclk;
|
|
|
|
#endif
|
|
|
|
|
2017-01-10 08:44:15 +00:00
|
|
|
/* The freq_systembus is used to record frequency of platform PLL */
|
2015-10-26 11:47:51 +00:00
|
|
|
sys_info->freq_systembus *= (gur_in32(&gur->rcwsr[0]) >>
|
|
|
|
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT) &
|
|
|
|
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK;
|
2017-01-10 08:44:15 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_LS1012A
|
|
|
|
sys_info->freq_ddrbus = 2 * sys_info->freq_systembus;
|
|
|
|
#else
|
2015-10-26 11:47:51 +00:00
|
|
|
sys_info->freq_ddrbus *= (gur_in32(&gur->rcwsr[0]) >>
|
|
|
|
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) &
|
|
|
|
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
|
2016-06-03 13:11:31 +00:00
|
|
|
#endif
|
2015-10-26 11:47:51 +00:00
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_SYS_FSL_NUM_CC_PLLS; i++) {
|
|
|
|
ratio[i] = (in_be32(&clk->pllcgsr[i].pllcngsr) >> 1) & 0xff;
|
|
|
|
if (ratio[i] > 4)
|
2017-01-10 08:44:15 +00:00
|
|
|
freq_c_pll[i] = cluster_clk * ratio[i];
|
2015-10-26 11:47:51 +00:00
|
|
|
else
|
|
|
|
freq_c_pll[i] = sys_info->freq_systembus * ratio[i];
|
|
|
|
}
|
|
|
|
|
2016-06-12 06:42:04 +00:00
|
|
|
for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
|
|
|
|
cluster = fsl_qoriq_core_to_cluster(cpu);
|
|
|
|
u32 c_pll_sel = (in_be32(&clk->clkcsr[cluster].clkcncsr) >> 27)
|
2015-10-26 11:47:51 +00:00
|
|
|
& 0xf;
|
|
|
|
u32 cplx_pll = core_cplx_pll[c_pll_sel];
|
|
|
|
|
|
|
|
sys_info->freq_processor[cpu] =
|
|
|
|
freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HWA_CGA_M1_CLK_SEL 0xe0000000
|
|
|
|
#define HWA_CGA_M1_CLK_SHIFT 29
|
2015-10-26 11:47:54 +00:00
|
|
|
#ifdef CONFIG_SYS_DPAA_FMAN
|
|
|
|
rcw_tmp = in_be32(&gur->rcwsr[7]);
|
|
|
|
switch ((rcw_tmp & HWA_CGA_M1_CLK_SEL) >> HWA_CGA_M1_CLK_SHIFT) {
|
|
|
|
case 2:
|
|
|
|
sys_info->freq_fman[0] = freq_c_pll[0] / 2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sys_info->freq_fman[0] = freq_c_pll[0] / 3;
|
|
|
|
break;
|
2016-07-05 08:01:55 +00:00
|
|
|
case 4:
|
|
|
|
sys_info->freq_fman[0] = freq_c_pll[0] / 4;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
sys_info->freq_fman[0] = sys_info->freq_systembus;
|
|
|
|
break;
|
2015-10-26 11:47:54 +00:00
|
|
|
case 6:
|
|
|
|
sys_info->freq_fman[0] = freq_c_pll[1] / 2;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
sys_info->freq_fman[0] = freq_c_pll[1] / 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Error: Unknown FMan1 clock select!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2015-10-26 11:47:51 +00:00
|
|
|
|
|
|
|
#define HWA_CGA_M2_CLK_SEL 0x00000007
|
|
|
|
#define HWA_CGA_M2_CLK_SHIFT 0
|
2022-04-26 18:31:49 +00:00
|
|
|
#if defined(CONFIG_ARCH_LS1046A) || defined(CONFIG_ARCH_LS1043A)
|
2015-10-26 11:47:55 +00:00
|
|
|
rcw_tmp = in_be32(&gur->rcwsr[15]);
|
2016-07-05 08:01:55 +00:00
|
|
|
switch ((rcw_tmp & HWA_CGA_M2_CLK_SEL) >> HWA_CGA_M2_CLK_SHIFT) {
|
|
|
|
case 1:
|
2019-07-16 07:09:06 +00:00
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[1];
|
2016-07-05 08:01:55 +00:00
|
|
|
break;
|
2022-04-26 18:31:49 +00:00
|
|
|
#if defined(CONFIG_ARCH_LS1046A)
|
2016-07-05 08:01:55 +00:00
|
|
|
case 2:
|
2019-07-16 07:09:06 +00:00
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[1] / 2;
|
2016-07-05 08:01:55 +00:00
|
|
|
break;
|
2019-07-16 07:09:06 +00:00
|
|
|
#endif
|
2016-07-05 08:01:55 +00:00
|
|
|
case 3:
|
2019-07-16 07:09:06 +00:00
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[1] / 3;
|
2016-07-05 08:01:55 +00:00
|
|
|
break;
|
2022-04-26 18:31:49 +00:00
|
|
|
#if defined(CONFIG_ARCH_LS1046A)
|
2016-07-05 08:01:55 +00:00
|
|
|
case 6:
|
2019-07-16 07:09:06 +00:00
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[0] / 2;
|
2016-07-05 08:01:55 +00:00
|
|
|
break;
|
2019-07-16 07:09:06 +00:00
|
|
|
#endif
|
2016-07-05 08:01:55 +00:00
|
|
|
default:
|
2019-12-19 10:59:30 +00:00
|
|
|
printf("Error: Unknown cluster group A mux 2 clock select!\n");
|
2016-07-05 08:01:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-02-16 02:54:41 +00:00
|
|
|
#endif
|
2015-10-26 11:47:51 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_FSL_IFC)
|
2017-02-02 09:31:37 +00:00
|
|
|
sys_info->freq_localbus = sys_info->freq_systembus /
|
|
|
|
CONFIG_SYS_FSL_IFC_CLK_DIV;
|
2015-10-26 11:47:51 +00:00
|
|
|
#endif
|
2017-12-15 21:01:00 +00:00
|
|
|
#ifdef CONFIG_SYS_DPAA_QBMAN
|
2018-04-25 08:28:44 +00:00
|
|
|
sys_info->freq_qman = (sys_info->freq_systembus /
|
|
|
|
CONFIG_SYS_FSL_PCLK_DIV) /
|
|
|
|
CONFIG_SYS_FSL_QMAN_CLK_DIV;
|
2017-12-15 21:01:00 +00:00
|
|
|
#endif
|
2015-10-26 11:47:51 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 21:01:00 +00:00
|
|
|
#ifdef CONFIG_SYS_DPAA_QBMAN
|
|
|
|
unsigned long get_qman_freq(void)
|
|
|
|
{
|
|
|
|
struct sys_info sys_info;
|
|
|
|
|
|
|
|
get_sys_info(&sys_info);
|
|
|
|
|
|
|
|
return sys_info.freq_qman;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-26 11:47:51 +00:00
|
|
|
int get_clocks(void)
|
|
|
|
{
|
|
|
|
struct sys_info sys_info;
|
2019-12-19 10:59:30 +00:00
|
|
|
#ifdef CONFIG_FSL_ESDHC
|
|
|
|
u32 clock = 0;
|
|
|
|
#endif
|
2015-10-26 11:47:51 +00:00
|
|
|
get_sys_info(&sys_info);
|
|
|
|
gd->cpu_clk = sys_info.freq_processor[0];
|
2017-01-10 08:44:15 +00:00
|
|
|
gd->bus_clk = sys_info.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV;
|
2015-10-26 11:47:51 +00:00
|
|
|
gd->mem_clk = sys_info.freq_ddrbus;
|
2015-10-26 11:47:55 +00:00
|
|
|
#ifdef CONFIG_FSL_ESDHC
|
2019-12-19 10:59:30 +00:00
|
|
|
#if defined(CONFIG_ARCH_LS1012A)
|
|
|
|
clock = sys_info.freq_systembus;
|
|
|
|
#elif defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
|
|
|
|
clock = sys_info.freq_cga_m2;
|
2019-07-16 07:09:06 +00:00
|
|
|
#endif
|
2019-12-19 10:59:30 +00:00
|
|
|
gd->arch.sdhc_per_clk = clock / CONFIG_SYS_FSL_SDHC_CLK_DIV;
|
|
|
|
gd->arch.sdhc_clk = gd->bus_clk / CONFIG_SYS_FSL_SDHC_CLK_DIV;
|
2015-10-26 11:47:55 +00:00
|
|
|
#endif
|
2015-10-26 11:47:51 +00:00
|
|
|
if (gd->cpu_clk != 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-01-10 08:44:15 +00:00
|
|
|
/********************************************
|
|
|
|
* get_bus_freq
|
|
|
|
* return platform clock in Hz
|
|
|
|
*********************************************/
|
2015-10-26 11:47:51 +00:00
|
|
|
ulong get_bus_freq(ulong dummy)
|
|
|
|
{
|
2017-01-10 08:44:15 +00:00
|
|
|
if (!gd->bus_clk)
|
|
|
|
get_clocks();
|
|
|
|
|
2015-10-26 11:47:51 +00:00
|
|
|
return gd->bus_clk;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong get_ddr_freq(ulong dummy)
|
|
|
|
{
|
2017-01-10 08:44:15 +00:00
|
|
|
if (!gd->mem_clk)
|
|
|
|
get_clocks();
|
|
|
|
|
2015-10-26 11:47:51 +00:00
|
|
|
return gd->mem_clk;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_serial_clock(void)
|
|
|
|
{
|
2017-01-10 08:44:15 +00:00
|
|
|
return get_bus_freq(0) / CONFIG_SYS_FSL_DUART_CLK_DIV;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_i2c_freq(ulong dummy)
|
|
|
|
{
|
|
|
|
return get_bus_freq(0) / CONFIG_SYS_FSL_I2C_CLK_DIV;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_dspi_freq(ulong dummy)
|
|
|
|
{
|
|
|
|
return get_bus_freq(0) / CONFIG_SYS_FSL_DSPI_CLK_DIV;
|
2015-10-26 11:47:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 08:44:15 +00:00
|
|
|
#ifdef CONFIG_FSL_LPUART
|
|
|
|
int get_uart_freq(ulong dummy)
|
|
|
|
{
|
|
|
|
return get_bus_freq(0) / CONFIG_SYS_FSL_LPUART_CLK_DIV;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-26 11:47:51 +00:00
|
|
|
unsigned int mxc_get_clock(enum mxc_clock clk)
|
|
|
|
{
|
|
|
|
switch (clk) {
|
|
|
|
case MXC_I2C_CLK:
|
2017-01-10 08:44:15 +00:00
|
|
|
return get_i2c_freq(0);
|
2015-10-26 11:47:51 +00:00
|
|
|
case MXC_DSPI_CLK:
|
2017-01-10 08:44:15 +00:00
|
|
|
return get_dspi_freq(0);
|
|
|
|
#ifdef CONFIG_FSL_LPUART
|
2015-10-26 11:47:51 +00:00
|
|
|
case MXC_UART_CLK:
|
2017-01-10 08:44:15 +00:00
|
|
|
return get_uart_freq(0);
|
|
|
|
#endif
|
2015-10-26 11:47:51 +00:00
|
|
|
default:
|
|
|
|
printf("Unsupported clock\n");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|