7 #include <soc/periph.h>
11 #define CONF_SYS_CLK_FREQ 24000000
23 .pclk_dbg_ratio = 0x1,
38 .pclk_dbg_ratio = 0x1,
53 .pclk_dbg_ratio = 0x1,
68 .pclk_dbg_ratio = 0x1,
83 .pclk_dbg_ratio = 0x1,
98 .pclk_dbg_ratio = 0x1,
146 { 192000000, 0, 48, 3, 1, 0 },
147 { 180000000, 0, 45, 3, 1, 0 },
148 { 73728000, 1, 73, 3, 3, 47710 },
149 { 67737600, 1, 90, 4, 3, 20762 },
150 { 49152000, 0, 49, 3, 3, 9961 },
151 { 45158400, 0, 45, 3, 3, 10381 },
152 { 180633600, 0, 45, 3, 1, 10381 }
158 unsigned long r,
m, p,
s, k = 0,
mask, fout;
195 m = (r >> 16) &
mask;
204 if (pllreg ==
EPLL) {
207 fout = (
m + k / 65536) * (
freq / (p * (1 <<
s)));
208 }
else if (pllreg ==
VPLL) {
211 fout = (
m + k / 1024) * (
freq / (p * (1 <<
s)));
214 fout =
m * (
freq / (p * (1 <<
s)));
223 unsigned long sclk, sub_clk;
224 unsigned int src, div, sub_div;
226 switch (peripheral) {
277 >> bit_info->
div_bit) & 0x7) + 1;
280 return (sclk / sub_div) / div;
303 sub_div = (div >> bit_info->
div_bit) & 0xf;
304 sub_clk = sclk / (sub_div + 1);
308 return sub_clk / (div + 1);
318 unsigned long armclk;
319 unsigned int arm_ratio;
320 unsigned int arm2_ratio;
325 arm_ratio = (div >> 0) & 0x7;
326 arm2_ratio = (div >> 28) & 0x7;
329 armclk /= (arm2_ratio + 1);
337 unsigned long arm_freq = 1700;
369 val &= ~(0xff << ((dev_index << 4) + 8));
370 val |= (div & 0xff) << ((dev_index << 4) + 8);
377 unsigned int mask = 0xff;
420 unsigned int mask = 0xff;
468 unsigned int fine_scalar_bits,
unsigned int input_rate,
469 unsigned int target_rate,
unsigned int *best_fine_scalar)
472 int best_main_scalar = -1;
473 unsigned int best_error = target_rate;
474 const unsigned int cap = (1 << fine_scalar_bits) - 1;
475 const unsigned int loops = 1 << main_scaler_bits;
477 printk(
BIOS_DEBUG,
"Input Rate is %u, Target is %u, Cap is %u\n", input_rate,
481 ASSERT(main_scaler_bits <= fine_scalar_bits);
483 *best_fine_scalar = 1;
485 if (input_rate == 0 || target_rate == 0)
488 if (target_rate >= input_rate)
491 for (i = 1; i <= loops; i++) {
492 const unsigned int effective_div =
MAX(
MIN(input_rate / i /
493 target_rate, cap), 1);
494 const unsigned int effective_rate = input_rate / i /
496 const int error = target_rate - effective_rate;
498 printk(
BIOS_DEBUG,
"%d|effdiv:%u, effrate:%u, error:%d\n", i, effective_div,
499 effective_rate, error);
501 if (error >= 0 && error <= best_error) {
503 best_main_scalar = i;
504 *best_fine_scalar = effective_div;
508 return best_main_scalar;
523 if (main_scalar < 0) {
556 switch (peripheral) {
568 for (i = 0; i <= 0xf; i++) {
569 if ((clock / (i + 1)) <= 400) {
579 unsigned int epll_con, epll_con_k;
581 unsigned int lockcnt;
622 "%s: Timeout waiting for EPLL lock\n",
641 if ((dst_frq == 0) || (src_frq == 0)) {
642 printk(
BIOS_DEBUG,
"%s: Invalid frequency input for prescaler\n", __func__);
647 div = (src_frq / dst_frq);
static void write32(void *addr, uint32_t val)
static uint32_t read32(const void *addr)
#define printk(level,...)
#define EPLL_CON0_LOCK_DET_EN_SHIFT
#define EXYNOS5_EPLLCON0_LOCKED_SHIFT
#define EPLL_CON0_SDIV_SHIFT
#define EPLL_CON0_MDIV_SHIFT
#define EPLL_CON0_SDIV_MASK
#define EPLL_CON0_PDIV_MASK
#define CLK_SRC_SCLK_EPLL
#define EPLL_CON0_MDIV_MASK
#define AUDIO_1_RATIO_MASK
#define EPLL_CON0_LOCK_DET_EN_MASK
#define EPLL_CON0_PDIV_SHIFT
static struct exynos5_clock *const exynos_clock
#define TIMEOUT_EPLL_LOCK
#define clrsetbits32(addr, clear, set)
static int stopwatch_expired(struct stopwatch *sw)
static void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
void clock_ll_set_ratio(enum periph_id periph_id, unsigned int divisor)
Low-level function to set the clock ratio for a peripheral.
void clock_ll_set_pre_ratio(enum periph_id periph_id, unsigned int divisor)
Low-level function to set the clock pre-ratio for a peripheral.
struct arm_clk_ratios * get_arm_clk_ratios(void)
Get the clock ratios for CPU configuration.
void clock_select_i2s_clk_source(void)
unsigned long get_arm_clk(void)
unsigned long clock_get_periph_rate(enum periph_id peripheral)
get the clk frequency of the required peripheral
#define CONF_SYS_CLK_FREQ
int clock_set_i2s_clk_prescaler(unsigned int src_frq, unsigned int dst_frq)
int clock_set_rate(enum periph_id periph_id, unsigned int rate)
Low-level function that selects the best clock scalars for a given rate and sets up the given periphe...
unsigned long get_pll_clk(int pllreg)
static int clock_calc_best_scalar(unsigned int main_scaler_bits, unsigned int fine_scalar_bits, unsigned int input_rate, unsigned int target_rate, unsigned int *best_fine_scalar)
Linearly searches for the most accurate main and fine stage clock scalars (divisors) for a specified ...
void set_mmc_clk(int dev_index, unsigned int div)
int clock_set_mshci(enum periph_id peripheral)
int clock_epll_set_rate(unsigned long rate)
static struct st_epll_con_val epll_div[]
unsigned int arm_freq_mhz
unsigned int sclk_div_isp
unsigned int sclk_src_isp
#define s(param, src_bits, pmcreg, dst_bits)
#define m(clkreg, src_bits, pmcreg, dst_bits)