2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-06-23 22:15:54 +00:00
|
|
|
/*
|
2015-10-26 11:47:50 +00:00
|
|
|
* Copyright 2014-2015, Freescale Semiconductor, Inc.
|
armv8: lx2162a: Add Soc changes to support LX2162A
LX2162 is LX2160 based SoC, it has same die as of LX2160
with different packaging.
LX2162A support 64-bit 2.9GT/s DDR4 memory, i2c, micro-click module,
microSD card, eMMC support, serial console, qspi nor flash, qsgmii,
sgmii, 25g, 40g, 50g network interface, one usb 3.0 and serdes
interface to support three PCIe gen3 interface.
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
[Fixed whitespace errors]
Signed-off-by: Priyanka Jain <priyanka.jain@nxp.com>
2020-10-29 13:46:16 +00:00
|
|
|
* Copyright 2019-2020 NXP
|
2014-06-23 22:15:54 +00:00
|
|
|
*
|
|
|
|
* Derived from arch/power/cpu/mpc85xx/speed.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2014-06-23 22:15:54 +00:00
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <fsl_ifc.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/io.h>
|
2015-11-09 11:12:07 +00:00
|
|
|
#include <asm/arch-fsl-layerscape/immap_lsch3.h>
|
2014-06-23 22:15:54 +00:00
|
|
|
#include <asm/arch/clock.h>
|
2015-10-26 11:47:50 +00:00
|
|
|
#include <asm/arch/soc.h>
|
2014-06-23 22:15:54 +00:00
|
|
|
#include "cpu.h"
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYS_FSL_NUM_CC_PLLS
|
|
|
|
#define CONFIG_SYS_FSL_NUM_CC_PLLS 6
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void get_sys_info(struct sys_info *sys_info)
|
|
|
|
{
|
|
|
|
struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
|
|
|
|
struct ccsr_clk_cluster_group __iomem *clk_grp[2] = {
|
|
|
|
(void *)(CONFIG_SYS_FSL_CH3_CLK_GRPA_ADDR),
|
|
|
|
(void *)(CONFIG_SYS_FSL_CH3_CLK_GRPB_ADDR)
|
|
|
|
};
|
|
|
|
struct ccsr_clk_ctrl __iomem *clk_ctrl =
|
|
|
|
(void *)(CONFIG_SYS_FSL_CH3_CLK_CTRL_ADDR);
|
|
|
|
unsigned int cpu;
|
|
|
|
const u8 core_cplx_pll[16] = {
|
|
|
|
[0] = 0, /* CC1 PPL / 1 */
|
|
|
|
[1] = 0, /* CC1 PPL / 2 */
|
|
|
|
[2] = 0, /* CC1 PPL / 4 */
|
|
|
|
[4] = 1, /* CC2 PPL / 1 */
|
|
|
|
[5] = 1, /* CC2 PPL / 2 */
|
|
|
|
[6] = 1, /* CC2 PPL / 4 */
|
|
|
|
[8] = 2, /* CC3 PPL / 1 */
|
|
|
|
[9] = 2, /* CC3 PPL / 2 */
|
|
|
|
[10] = 2, /* CC3 PPL / 4 */
|
|
|
|
[12] = 3, /* CC4 PPL / 1 */
|
|
|
|
[13] = 3, /* CC4 PPL / 2 */
|
|
|
|
[14] = 3, /* CC4 PPL / 4 */
|
|
|
|
};
|
|
|
|
|
|
|
|
const u8 core_cplx_pll_div[16] = {
|
|
|
|
[0] = 1, /* CC1 PPL / 1 */
|
|
|
|
[1] = 2, /* CC1 PPL / 2 */
|
|
|
|
[2] = 4, /* CC1 PPL / 4 */
|
|
|
|
[4] = 1, /* CC2 PPL / 1 */
|
|
|
|
[5] = 2, /* CC2 PPL / 2 */
|
|
|
|
[6] = 4, /* CC2 PPL / 4 */
|
|
|
|
[8] = 1, /* CC3 PPL / 1 */
|
|
|
|
[9] = 2, /* CC3 PPL / 2 */
|
|
|
|
[10] = 4, /* CC3 PPL / 4 */
|
|
|
|
[12] = 1, /* CC4 PPL / 1 */
|
|
|
|
[13] = 2, /* CC4 PPL / 2 */
|
|
|
|
[14] = 4, /* CC4 PPL / 4 */
|
|
|
|
};
|
|
|
|
|
|
|
|
uint i, cluster;
|
2019-10-21 23:10:57 +00:00
|
|
|
#if defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LS1088A)
|
2019-07-16 07:09:06 +00:00
|
|
|
uint rcw_tmp;
|
|
|
|
#endif
|
2014-06-23 22:15:54 +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();
|
2014-06-23 22:15:54 +00:00
|
|
|
int cc_group[12] = CONFIG_SYS_FSL_CLUSTER_CLOCKS;
|
|
|
|
u32 c_pll_sel, cplx_pll;
|
|
|
|
void *offset;
|
|
|
|
|
|
|
|
sys_info->freq_systembus = sysclk;
|
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-11-09 11:12:07 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
|
2021-08-21 17:50:17 +00:00
|
|
|
sys_info->freq_ddrbus2 = get_board_ddr_clk();
|
2015-11-09 11:12:07 +00:00
|
|
|
#endif
|
2014-06-23 22:15:54 +00:00
|
|
|
#else
|
|
|
|
sys_info->freq_ddrbus = sysclk;
|
2015-11-09 11:12:07 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
|
2015-01-06 21:18:49 +00:00
|
|
|
sys_info->freq_ddrbus2 = sysclk;
|
2015-11-09 11:12:07 +00:00
|
|
|
#endif
|
2014-06-23 22:15:54 +00:00
|
|
|
#endif
|
|
|
|
|
2017-01-10 08:44:16 +00:00
|
|
|
/* The freq_systembus is used to record frequency of platform PLL */
|
2015-10-26 11:47:50 +00:00
|
|
|
sys_info->freq_systembus *= (gur_in32(&gur->rcwsr[0]) >>
|
2014-06-23 22:15:54 +00:00
|
|
|
FSL_CHASSIS3_RCWSR0_SYS_PLL_RAT_SHIFT) &
|
|
|
|
FSL_CHASSIS3_RCWSR0_SYS_PLL_RAT_MASK;
|
2015-10-26 11:47:50 +00:00
|
|
|
sys_info->freq_ddrbus *= (gur_in32(&gur->rcwsr[0]) >>
|
2014-06-23 22:15:54 +00:00
|
|
|
FSL_CHASSIS3_RCWSR0_MEM_PLL_RAT_SHIFT) &
|
|
|
|
FSL_CHASSIS3_RCWSR0_MEM_PLL_RAT_MASK;
|
2015-11-09 11:12:07 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
|
2016-04-04 18:41:26 +00:00
|
|
|
if (soc_has_dp_ddr()) {
|
|
|
|
sys_info->freq_ddrbus2 *= (gur_in32(&gur->rcwsr[0]) >>
|
2015-01-06 21:18:49 +00:00
|
|
|
FSL_CHASSIS3_RCWSR0_MEM2_PLL_RAT_SHIFT) &
|
|
|
|
FSL_CHASSIS3_RCWSR0_MEM2_PLL_RAT_MASK;
|
2016-04-04 18:41:26 +00:00
|
|
|
} else {
|
|
|
|
sys_info->freq_ddrbus2 = 0;
|
|
|
|
}
|
2015-11-09 11:12:07 +00:00
|
|
|
#endif
|
2014-06-23 22:15:54 +00:00
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_SYS_FSL_NUM_CC_PLLS; i++) {
|
|
|
|
/*
|
|
|
|
* fixme: prefer to combine the following into one line, but
|
|
|
|
* cannot pass compiling without warning about in_le32.
|
|
|
|
*/
|
|
|
|
offset = (void *)((size_t)clk_grp[i/3] +
|
|
|
|
offsetof(struct ccsr_clk_cluster_group,
|
|
|
|
pllngsr[i%3].gsr));
|
|
|
|
ratio[i] = (in_le32(offset) >> 1) & 0x3f;
|
2015-03-21 02:28:07 +00:00
|
|
|
freq_c_pll[i] = sysclk * ratio[i];
|
2014-06-23 22:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
|
|
|
|
cluster = fsl_qoriq_core_to_cluster(cpu);
|
|
|
|
c_pll_sel = (in_le32(&clk_ctrl->clkcncsr[cluster].csr) >> 27)
|
|
|
|
& 0xf;
|
|
|
|
cplx_pll = core_cplx_pll[c_pll_sel];
|
|
|
|
cplx_pll += cc_group[cluster] - 1;
|
|
|
|
sys_info->freq_processor[cpu] =
|
|
|
|
freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
|
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
2014-06-23 22:15:54 +00:00
|
|
|
#endif
|
|
|
|
|
2019-10-21 23:10:57 +00:00
|
|
|
#if defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LS1088A)
|
2019-07-16 07:09:06 +00:00
|
|
|
#define HWA_CGA_M2_CLK_SEL 0x00380000
|
|
|
|
#define HWA_CGA_M2_CLK_SHIFT 19
|
|
|
|
rcw_tmp = in_le32(&gur->rcwsr[5]);
|
|
|
|
switch ((rcw_tmp & HWA_CGA_M2_CLK_SEL) >> HWA_CGA_M2_CLK_SHIFT) {
|
|
|
|
case 1:
|
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[1];
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[1] / 2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[1] / 3;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[1] / 4;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[0] / 2;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
sys_info->freq_cga_m2 = freq_c_pll[0] / 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Error: Unknown peripheral clock select!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2014-06-23 22:15:54 +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
|
2014-06-23 22:15:54 +00:00
|
|
|
get_sys_info(&sys_info);
|
|
|
|
gd->cpu_clk = sys_info.freq_processor[0];
|
2017-01-10 08:44:16 +00:00
|
|
|
gd->bus_clk = sys_info.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV;
|
2014-06-23 22:15:54 +00:00
|
|
|
gd->mem_clk = sys_info.freq_ddrbus;
|
2015-11-09 11:12:07 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
|
2015-01-06 21:18:49 +00:00
|
|
|
gd->arch.mem2_clk = sys_info.freq_ddrbus2;
|
2015-11-09 11:12:07 +00:00
|
|
|
#endif
|
2019-12-19 10:59:30 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_FSL_ESDHC
|
|
|
|
#if defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LS1088A)
|
|
|
|
clock = sys_info.freq_cga_m2;
|
armv8: lx2162a: Add Soc changes to support LX2162A
LX2162 is LX2160 based SoC, it has same die as of LX2160
with different packaging.
LX2162A support 64-bit 2.9GT/s DDR4 memory, i2c, micro-click module,
microSD card, eMMC support, serial console, qspi nor flash, qsgmii,
sgmii, 25g, 40g, 50g network interface, one usb 3.0 and serdes
interface to support three PCIe gen3 interface.
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
[Fixed whitespace errors]
Signed-off-by: Priyanka Jain <priyanka.jain@nxp.com>
2020-10-29 13:46:16 +00:00
|
|
|
#elif defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2162A)
|
2019-12-19 10:59:30 +00:00
|
|
|
clock = sys_info.freq_systembus;
|
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;
|
2017-01-10 08:44:16 +00:00
|
|
|
gd->arch.sdhc_clk = gd->bus_clk / CONFIG_SYS_FSL_SDHC_CLK_DIV;
|
2019-07-16 07:09:06 +00:00
|
|
|
#endif
|
2014-06-23 22:15:54 +00:00
|
|
|
|
|
|
|
if (gd->cpu_clk != 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* get_bus_freq
|
2017-01-10 08:44:16 +00:00
|
|
|
* return platform clock in Hz
|
2014-06-23 22:15:54 +00:00
|
|
|
*********************************************/
|
|
|
|
ulong get_bus_freq(ulong dummy)
|
|
|
|
{
|
|
|
|
if (!gd->bus_clk)
|
|
|
|
get_clocks();
|
|
|
|
|
|
|
|
return gd->bus_clk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* get_ddr_freq
|
|
|
|
* return ddr bus freq in Hz
|
|
|
|
*********************************************/
|
2015-01-06 21:18:49 +00:00
|
|
|
ulong get_ddr_freq(ulong ctrl_num)
|
2014-06-23 22:15:54 +00:00
|
|
|
{
|
|
|
|
if (!gd->mem_clk)
|
|
|
|
get_clocks();
|
|
|
|
|
2015-01-06 21:18:49 +00:00
|
|
|
/*
|
|
|
|
* DDR controller 0 & 1 are on memory complex 0
|
2016-05-04 08:47:31 +00:00
|
|
|
* DDR controller 2 is on memory complext 1
|
2015-01-06 21:18:49 +00:00
|
|
|
*/
|
2015-11-09 11:12:07 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
|
2015-01-06 21:18:49 +00:00
|
|
|
if (ctrl_num >= 2)
|
|
|
|
return gd->arch.mem2_clk;
|
2015-11-09 11:12:07 +00:00
|
|
|
#endif
|
2015-01-06 21:18:49 +00:00
|
|
|
|
2014-06-23 22:15:54 +00:00
|
|
|
return gd->mem_clk;
|
|
|
|
}
|
|
|
|
|
2017-01-10 08:44:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_serial_clock(void)
|
|
|
|
{
|
|
|
|
return get_bus_freq(0) / CONFIG_SYS_FSL_DUART_CLK_DIV;
|
|
|
|
}
|
|
|
|
|
2014-06-23 22:15:54 +00:00
|
|
|
unsigned int mxc_get_clock(enum mxc_clock clk)
|
|
|
|
{
|
|
|
|
switch (clk) {
|
|
|
|
case MXC_I2C_CLK:
|
2017-01-10 08:44:16 +00:00
|
|
|
return get_i2c_freq(0);
|
2015-06-26 11:56:11 +00:00
|
|
|
case MXC_DSPI_CLK:
|
2017-01-10 08:44:16 +00:00
|
|
|
return get_dspi_freq(0);
|
2014-06-23 22:15:54 +00:00
|
|
|
default:
|
|
|
|
printf("Unsupported clock\n");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|