Path: blob/master/arch/arm/mach-omap2/clkt34xx_dpll3m2.c
10817 views
/*1* OMAP34xx M2 divider clock code2*3* Copyright (C) 2007-2008 Texas Instruments, Inc.4* Copyright (C) 2007-2010 Nokia Corporation5*6* Paul Walmsley7* Jouni Högander8*9* Parts of this code are based on code written by10* Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu11*12* This program is free software; you can redistribute it and/or modify13* it under the terms of the GNU General Public License version 2 as14* published by the Free Software Foundation.15*/16#undef DEBUG1718#include <linux/kernel.h>19#include <linux/errno.h>20#include <linux/clk.h>21#include <linux/io.h>2223#include <plat/clock.h>24#include <plat/sram.h>25#include <plat/sdrc.h>2627#include "clock.h"28#include "clock3xxx.h"29#include "clock34xx.h"30#include "sdrc.h"3132#define CYCLES_PER_MHZ 10000003334/*35* CORE DPLL (DPLL3) M2 divider rate programming functions36*37* These call into SRAM code to do the actual CM writes, since the SDRAM38* is clocked from DPLL3.39*/4041/**42* omap3_core_dpll_m2_set_rate - set CORE DPLL M2 divider43* @clk: struct clk * of DPLL to set44* @rate: rounded target rate45*46* Program the DPLL M2 divider with the rounded target rate. Returns47* -EINVAL upon error, or 0 upon success.48*/49int omap3_core_dpll_m2_set_rate(struct clk *clk, unsigned long rate)50{51u32 new_div = 0;52u32 unlock_dll = 0;53u32 c;54unsigned long validrate, sdrcrate, _mpurate;55struct omap_sdrc_params *sdrc_cs0;56struct omap_sdrc_params *sdrc_cs1;57int ret;5859if (!clk || !rate)60return -EINVAL;6162validrate = omap2_clksel_round_rate_div(clk, rate, &new_div);63if (validrate != rate)64return -EINVAL;6566sdrcrate = sdrc_ick_p->rate;67if (rate > clk->rate)68sdrcrate <<= ((rate / clk->rate) >> 1);69else70sdrcrate >>= ((clk->rate / rate) >> 1);7172ret = omap2_sdrc_get_params(sdrcrate, &sdrc_cs0, &sdrc_cs1);73if (ret)74return -EINVAL;7576if (sdrcrate < MIN_SDRC_DLL_LOCK_FREQ) {77pr_debug("clock: will unlock SDRC DLL\n");78unlock_dll = 1;79}8081/*82* XXX This only needs to be done when the CPU frequency changes83*/84_mpurate = arm_fck_p->rate / CYCLES_PER_MHZ;85c = (_mpurate << SDRC_MPURATE_SCALE) >> SDRC_MPURATE_BASE_SHIFT;86c += 1; /* for safety */87c *= SDRC_MPURATE_LOOPS;88c >>= SDRC_MPURATE_SCALE;89if (c == 0)90c = 1;9192pr_debug("clock: changing CORE DPLL rate from %lu to %lu\n", clk->rate,93validrate);94pr_debug("clock: SDRC CS0 timing params used:"95" RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",96sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,97sdrc_cs0->actim_ctrlb, sdrc_cs0->mr);98if (sdrc_cs1)99pr_debug("clock: SDRC CS1 timing params used: "100" RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",101sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,102sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);103104if (sdrc_cs1)105omap3_configure_core_dpll(106new_div, unlock_dll, c, rate > clk->rate,107sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,108sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,109sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,110sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);111else112omap3_configure_core_dpll(113new_div, unlock_dll, c, rate > clk->rate,114sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,115sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,1160, 0, 0, 0);117clk->rate = rate;118119return 0;120}121122123124