Path: blob/master/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c
10817 views
/*1* OMAP2xxx DVFS virtual clock functions2*3* Copyright (C) 2005-2008 Texas Instruments, Inc.4* Copyright (C) 2004-2010 Nokia Corporation5*6* Contacts:7* Richard Woodruff <[email protected]>8* Paul Walmsley9*10* Based on earlier work by Tuukka Tikkanen, Tony Lindgren,11* Gordon McNutt and RidgeRun, Inc.12*13* This program is free software; you can redistribute it and/or modify14* it under the terms of the GNU General Public License version 2 as15* published by the Free Software Foundation.16*17* XXX Some of this code should be replaceable by the upcoming OPP layer18* code. However, some notion of "rate set" is probably still necessary19* for OMAP2xxx at least. Rate sets should be generalized so they can be20* used for any OMAP chip, not just OMAP2xxx. In particular, Richard Woodruff21* has in the past expressed a preference to use rate sets for OPP changes,22* rather than dynamically recalculating the clock tree, so if someone wants23* this badly enough to write the code to handle it, we should support it24* as an option.25*/26#undef DEBUG2728#include <linux/kernel.h>29#include <linux/errno.h>30#include <linux/clk.h>31#include <linux/io.h>32#include <linux/cpufreq.h>33#include <linux/slab.h>3435#include <plat/clock.h>36#include <plat/sram.h>37#include <plat/sdrc.h>3839#include "clock.h"40#include "clock2xxx.h"41#include "opp2xxx.h"42#include "cm2xxx_3xxx.h"43#include "cm-regbits-24xx.h"4445const struct prcm_config *curr_prcm_set;46const struct prcm_config *rate_table;4748/**49* omap2_table_mpu_recalc - just return the MPU speed50* @clk: virt_prcm_set struct clk51*52* Set virt_prcm_set's rate to the mpu_speed field of the current PRCM set.53*/54unsigned long omap2_table_mpu_recalc(struct clk *clk)55{56return curr_prcm_set->mpu_speed;57}5859/*60* Look for a rate equal or less than the target rate given a configuration set.61*62* What's not entirely clear is "which" field represents the key field.63* Some might argue L3-DDR, others ARM, others IVA. This code is simple and64* just uses the ARM rates.65*/66long omap2_round_to_table_rate(struct clk *clk, unsigned long rate)67{68const struct prcm_config *ptr;69long highest_rate;7071highest_rate = -EINVAL;7273for (ptr = rate_table; ptr->mpu_speed; ptr++) {74if (!(ptr->flags & cpu_mask))75continue;76if (ptr->xtal_speed != sclk->rate)77continue;7879highest_rate = ptr->mpu_speed;8081/* Can check only after xtal frequency check */82if (ptr->mpu_speed <= rate)83break;84}85return highest_rate;86}8788/* Sets basic clocks based on the specified rate */89int omap2_select_table_rate(struct clk *clk, unsigned long rate)90{91u32 cur_rate, done_rate, bypass = 0, tmp;92const struct prcm_config *prcm;93unsigned long found_speed = 0;94unsigned long flags;9596for (prcm = rate_table; prcm->mpu_speed; prcm++) {97if (!(prcm->flags & cpu_mask))98continue;99100if (prcm->xtal_speed != sclk->rate)101continue;102103if (prcm->mpu_speed <= rate) {104found_speed = prcm->mpu_speed;105break;106}107}108109if (!found_speed) {110printk(KERN_INFO "Could not set MPU rate to %luMHz\n",111rate / 1000000);112return -EINVAL;113}114115curr_prcm_set = prcm;116cur_rate = omap2xxx_clk_get_core_rate(dclk);117118if (prcm->dpll_speed == cur_rate / 2) {119omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL, 1);120} else if (prcm->dpll_speed == cur_rate * 2) {121omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);122} else if (prcm->dpll_speed != cur_rate) {123local_irq_save(flags);124125if (prcm->dpll_speed == prcm->xtal_speed)126bypass = 1;127128if ((prcm->cm_clksel2_pll & OMAP24XX_CORE_CLK_SRC_MASK) ==129CORE_CLK_SRC_DPLL_X2)130done_rate = CORE_CLK_SRC_DPLL_X2;131else132done_rate = CORE_CLK_SRC_DPLL;133134/* MPU divider */135omap2_cm_write_mod_reg(prcm->cm_clksel_mpu, MPU_MOD, CM_CLKSEL);136137/* dsp + iva1 div(2420), iva2.1(2430) */138omap2_cm_write_mod_reg(prcm->cm_clksel_dsp,139OMAP24XX_DSP_MOD, CM_CLKSEL);140141omap2_cm_write_mod_reg(prcm->cm_clksel_gfx, GFX_MOD, CM_CLKSEL);142143/* Major subsystem dividers */144tmp = omap2_cm_read_mod_reg(CORE_MOD, CM_CLKSEL1) & OMAP24XX_CLKSEL_DSS2_MASK;145omap2_cm_write_mod_reg(prcm->cm_clksel1_core | tmp, CORE_MOD,146CM_CLKSEL1);147148if (cpu_is_omap2430())149omap2_cm_write_mod_reg(prcm->cm_clksel_mdm,150OMAP2430_MDM_MOD, CM_CLKSEL);151152/* x2 to enter omap2xxx_sdrc_init_params() */153omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);154155omap2_set_prcm(prcm->cm_clksel1_pll, prcm->base_sdrc_rfr,156bypass);157158omap2xxx_sdrc_init_params(omap2xxx_sdrc_dll_is_unlocked());159omap2xxx_sdrc_reprogram(done_rate, 0);160161local_irq_restore(flags);162}163164return 0;165}166167#ifdef CONFIG_CPU_FREQ168/*169* Walk PRCM rate table and fillout cpufreq freq_table170* XXX This should be replaced by an OPP layer in the near future171*/172static struct cpufreq_frequency_table *freq_table;173174void omap2_clk_init_cpufreq_table(struct cpufreq_frequency_table **table)175{176const struct prcm_config *prcm;177int i = 0;178int tbl_sz = 0;179180if (!cpu_is_omap24xx())181return;182183for (prcm = rate_table; prcm->mpu_speed; prcm++) {184if (!(prcm->flags & cpu_mask))185continue;186if (prcm->xtal_speed != sclk->rate)187continue;188189/* don't put bypass rates in table */190if (prcm->dpll_speed == prcm->xtal_speed)191continue;192193tbl_sz++;194}195196/*197* XXX Ensure that we're doing what CPUFreq expects for this error198* case and the following one199*/200if (tbl_sz == 0) {201pr_warning("%s: no matching entries in rate_table\n",202__func__);203return;204}205206/* Include the CPUFREQ_TABLE_END terminator entry */207tbl_sz++;208209freq_table = kzalloc(sizeof(struct cpufreq_frequency_table) * tbl_sz,210GFP_ATOMIC);211if (!freq_table) {212pr_err("%s: could not kzalloc frequency table\n", __func__);213return;214}215216for (prcm = rate_table; prcm->mpu_speed; prcm++) {217if (!(prcm->flags & cpu_mask))218continue;219if (prcm->xtal_speed != sclk->rate)220continue;221222/* don't put bypass rates in table */223if (prcm->dpll_speed == prcm->xtal_speed)224continue;225226freq_table[i].index = i;227freq_table[i].frequency = prcm->mpu_speed / 1000;228i++;229}230231freq_table[i].index = i;232freq_table[i].frequency = CPUFREQ_TABLE_END;233234*table = &freq_table[0];235}236237void omap2_clk_exit_cpufreq_table(struct cpufreq_frequency_table **table)238{239if (!cpu_is_omap24xx())240return;241242kfree(freq_table);243}244245#endif246247248