2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2009-05-15 21:47:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Texas Instruments.
|
|
|
|
* Copyright (C) 2009 David Brownell
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2021-12-14 18:36:40 +00:00
|
|
|
#include <clock_legacy.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2009-05-15 21:47:12 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2009-11-12 16:07:22 +00:00
|
|
|
#include <asm/io.h>
|
2009-05-15 21:47:12 +00:00
|
|
|
|
2012-02-06 00:30:44 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2009-05-15 21:47:12 +00:00
|
|
|
/* offsets from PLL controller base */
|
|
|
|
#define PLLC_PLLCTL 0x100
|
|
|
|
#define PLLC_PLLM 0x110
|
|
|
|
#define PLLC_PREDIV 0x114
|
|
|
|
#define PLLC_PLLDIV1 0x118
|
|
|
|
#define PLLC_PLLDIV2 0x11c
|
|
|
|
#define PLLC_PLLDIV3 0x120
|
|
|
|
#define PLLC_POSTDIV 0x128
|
|
|
|
#define PLLC_BPDIV 0x12c
|
|
|
|
#define PLLC_PLLDIV4 0x160
|
|
|
|
#define PLLC_PLLDIV5 0x164
|
|
|
|
#define PLLC_PLLDIV6 0x168
|
2011-09-04 02:18:04 +00:00
|
|
|
#define PLLC_PLLDIV7 0x16c
|
2009-05-15 21:47:12 +00:00
|
|
|
#define PLLC_PLLDIV8 0x170
|
|
|
|
#define PLLC_PLLDIV9 0x174
|
|
|
|
|
2011-09-04 02:18:04 +00:00
|
|
|
unsigned int sysdiv[9] = {
|
|
|
|
PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
|
|
|
|
PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
|
2009-11-12 16:07:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int clk_get(enum davinci_clk_ids id)
|
|
|
|
{
|
|
|
|
int pre_div;
|
|
|
|
int pllm;
|
|
|
|
int post_div;
|
|
|
|
int pll_out;
|
2011-09-04 02:18:04 +00:00
|
|
|
unsigned int pll_base;
|
2009-11-12 16:07:22 +00:00
|
|
|
|
|
|
|
pll_out = CONFIG_SYS_OSCIN_FREQ;
|
|
|
|
|
|
|
|
if (id == DAVINCI_AUXCLK_CLKID)
|
|
|
|
goto out;
|
|
|
|
|
2011-09-04 02:18:04 +00:00
|
|
|
if ((id >> 16) == 1)
|
|
|
|
pll_base = (unsigned int)davinci_pllc1_regs;
|
|
|
|
else
|
|
|
|
pll_base = (unsigned int)davinci_pllc0_regs;
|
|
|
|
|
|
|
|
id &= 0xFFFF;
|
|
|
|
|
2009-11-12 16:07:22 +00:00
|
|
|
/*
|
|
|
|
* Lets keep this simple. Combining operations can result in
|
|
|
|
* unexpected approximations
|
|
|
|
*/
|
2011-09-04 02:18:04 +00:00
|
|
|
pre_div = (readl(pll_base + PLLC_PREDIV) &
|
|
|
|
DAVINCI_PLLC_DIV_MASK) + 1;
|
|
|
|
pllm = readl(pll_base + PLLC_PLLM) + 1;
|
2009-11-12 16:07:22 +00:00
|
|
|
|
|
|
|
pll_out /= pre_div;
|
|
|
|
pll_out *= pllm;
|
|
|
|
|
|
|
|
if (id == DAVINCI_PLLM_CLKID)
|
|
|
|
goto out;
|
|
|
|
|
2011-09-04 02:18:04 +00:00
|
|
|
post_div = (readl(pll_base + PLLC_POSTDIV) &
|
|
|
|
DAVINCI_PLLC_DIV_MASK) + 1;
|
2009-11-12 16:07:22 +00:00
|
|
|
|
|
|
|
pll_out /= post_div;
|
|
|
|
|
|
|
|
if (id == DAVINCI_PLLC_CLKID)
|
|
|
|
goto out;
|
|
|
|
|
2011-09-04 02:18:04 +00:00
|
|
|
pll_out /= (readl(pll_base + sysdiv[id - 1]) &
|
|
|
|
DAVINCI_PLLC_DIV_MASK) + 1;
|
2009-11-12 16:07:22 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
return pll_out;
|
|
|
|
}
|
2012-07-30 23:30:37 +00:00
|
|
|
|
|
|
|
int set_cpu_clk_info(void)
|
|
|
|
{
|
|
|
|
gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000;
|
|
|
|
/* DDR PHY uses an x2 input clock */
|
|
|
|
gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
|
|
|
|
(clk_get(DAVINCI_DDR_CLKID) / 1000000);
|
|
|
|
gd->bd->bi_dsp_freq = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-12-14 18:36:39 +00:00
|
|
|
|
|
|
|
unsigned long get_board_sys_clk(void)
|
|
|
|
{
|
|
|
|
return clk_get(DAVINCI_ARM_CLKID);
|
|
|
|
}
|