// SPDX-License-Identifier: GPL-2.0+ /* * CPU frequency scaling support for Armada 37xx platform. * * Copyright (C) 2017 Marvell * * Gregory CLEMENT <gregory.clement@free-electrons.com>
*/
/* * On Armada 37xx the Power management manages 4 level of CPU load, * each level can be associated with a CPU clock source, a CPU * divider, a VDD level, etc...
*/ #define LOAD_LEVEL_NR 4
staticstruct armada_37xx_dvfs *armada_37xx_cpu_freq_info_get(u32 freq)
{ int i;
for (i = 0; i < ARRAY_SIZE(armada_37xx_dvfs); i++) { if (freq == armada_37xx_dvfs[i].cpu_freq_max) return &armada_37xx_dvfs[i];
}
pr_err("Unsupported CPU frequency %d MHz\n", freq/1000000); return NULL;
}
/* * Setup the four level managed by the hardware. Once the four level * will be configured then the DVFS will be enabled.
*/ staticvoid __init armada37xx_cpufreq_dvfs_setup(struct regmap *base, struct regmap *clk_base, u8 *divider)
{
u32 cpu_tbg_sel; int load_lvl;
/* Determine to which TBG clock is CPU connected */
regmap_read(clk_base, ARMADA_37XX_CLK_TBG_SEL, &cpu_tbg_sel);
cpu_tbg_sel >>= ARMADA_37XX_CLK_TBG_SEL_CPU_OFF;
cpu_tbg_sel &= ARMADA_37XX_NB_TBG_SEL_MASK;
/* Set cpu clock source, for all the level we use TBG */
val = ARMADA_37XX_NB_CLK_SEL_TBG << ARMADA_37XX_NB_CLK_SEL_OFF;
mask = (ARMADA_37XX_NB_CLK_SEL_MASK
<< ARMADA_37XX_NB_CLK_SEL_OFF);
/* Set TBG index, for all levels we use the same TBG */
val = cpu_tbg_sel << ARMADA_37XX_NB_TBG_SEL_OFF;
mask = (ARMADA_37XX_NB_TBG_SEL_MASK
<< ARMADA_37XX_NB_TBG_SEL_OFF);
/* * Set cpu divider based on the pre-computed array in * order to have balanced step.
*/
val |= divider[load_lvl] << ARMADA_37XX_NB_TBG_DIV_OFF;
mask |= (ARMADA_37XX_NB_TBG_DIV_MASK
<< ARMADA_37XX_NB_TBG_DIV_OFF);
/* Set VDD divider which is actually the load level. */
val |= load_lvl << ARMADA_37XX_NB_VDD_SEL_OFF;
mask |= (ARMADA_37XX_NB_VDD_SEL_MASK
<< ARMADA_37XX_NB_VDD_SEL_OFF);
val <<= offset;
mask <<= offset;
regmap_update_bits(base, reg, mask, val);
}
}
/* * Find out the armada 37x supported AVS value whose voltage value is * the round-up closest to the target voltage value.
*/ static u32 armada_37xx_avs_val_match(int target_vm)
{
u32 avs;
/* Find out the round-up closest supported voltage value */ for (avs = 0; avs < ARRAY_SIZE(avs_map); avs++) if (avs_map[avs] >= target_vm) break;
/* * If all supported voltages are smaller than target one, * choose the largest supported voltage
*/ if (avs == ARRAY_SIZE(avs_map))
avs = ARRAY_SIZE(avs_map) - 1;
return avs;
}
/* * For Armada 37xx soc, L0(VSET0) VDD AVS value is set to SVC revision * value or a default value when SVC is not supported. * - L0 can be read out from the register of AVS_CTRL_0 and L0 voltage * can be got from the mapping table of avs_map. * - L1 voltage should be about 100mv smaller than L0 voltage * - L2 & L3 voltage should be about 150mv smaller than L0 voltage. * This function calculates L1 & L2 & L3 AVS values dynamically based * on L0 voltage and fill all AVS values to the AVS value table. * When base CPU frequency is 1000 or 1200 MHz then there is additional * minimal avs value for load L1.
*/ staticvoid __init armada37xx_cpufreq_avs_configure(struct regmap *base, struct armada_37xx_dvfs *dvfs)
{ unsignedint target_vm; int load_level = 0;
u32 l0_vdd_min;
if (base == NULL) return;
/* Get L0 VDD min value */
regmap_read(base, ARMADA_37XX_AVS_CTL0, &l0_vdd_min);
l0_vdd_min = (l0_vdd_min >> ARMADA_37XX_AVS_LOW_VDD_LIMIT) &
ARMADA_37XX_AVS_VDD_MASK; if (l0_vdd_min >= ARRAY_SIZE(avs_map)) {
pr_err("L0 VDD MIN %d is not correct.\n", l0_vdd_min); return;
}
dvfs->avs[0] = l0_vdd_min;
if (avs_map[l0_vdd_min] <= MIN_VOLT_MV) { /* * If L0 voltage is smaller than 1000mv, then all VDD sets * use L0 voltage;
*/
u32 avs_min = armada_37xx_avs_val_match(MIN_VOLT_MV);
/* * Set the avs values for load L0 and L1 when base CPU frequency * is 1000/1200 MHz to its typical initial values according to * the Armada 3700 Hardware Specifications.
*/ if (dvfs->cpu_freq_max >= 1000*1000*1000) { if (dvfs->cpu_freq_max >= 1200*1000*1000)
avs_min = armada_37xx_avs_val_match(MIN_VOLT_MV_FOR_L1_1200MHZ); else
avs_min = armada_37xx_avs_val_match(MIN_VOLT_MV_FOR_L1_1000MHZ);
dvfs->avs[0] = dvfs->avs[1] = avs_min;
}
return;
}
/* * L1 voltage is equal to L0 voltage - 100mv and it must be * larger than 1000mv
*/
/* * L2 & L3 voltage is equal to L0 voltage - 150mv and it must * be larger than 1000mv
*/
target_vm = avs_map[l0_vdd_min] - 150;
target_vm = target_vm > MIN_VOLT_MV ? target_vm : MIN_VOLT_MV;
dvfs->avs[2] = dvfs->avs[3] = armada_37xx_avs_val_match(target_vm);
/* * Fix the avs value for load L1 when base CPU frequency is 1000/1200 MHz, * otherwise the CPU gets stuck when switching from load L1 to load L0. * Also ensure that avs value for load L1 is not higher than for L0.
*/ if (dvfs->cpu_freq_max >= 1000*1000*1000) {
u32 avs_min_l1;
/* * NB_DYN_MOD register is the one that actually enable back DVFS if it * was enabled before the suspend operation. This must be done last * otherwise other registers are not writable.
*/
regmap_write(state->regmap, ARMADA_37XX_NB_DYN_MOD, state->nb_dyn_mod);
/* if AVS is not present don't use it but still try to setup dvfs */ if (IS_ERR(avs_base)) {
pr_info("Syscon failed for Adapting Voltage Scaling: skip it\n");
avs_base = NULL;
} /* Before doing any configuration on the DVFS first, disable it */
armada37xx_cpufreq_disable_dvfs(nb_pm_base);
/* * On CPU 0 register the operating points supported (which are * the nominal CPU frequency and full integer divisions of * it).
*/
cpu_dev = get_cpu_device(0); if (!cpu_dev) {
dev_err(cpu_dev, "Cannot get CPU\n"); return -ENODEV;
}
clk = clk_get(cpu_dev, NULL); if (IS_ERR(clk)) {
dev_err(cpu_dev, "Cannot get clock for CPU0\n"); return PTR_ERR(clk);
}
parent = clk_get_parent(clk); if (IS_ERR(parent)) {
dev_err(cpu_dev, "Cannot get parent clock for CPU0\n");
clk_put(clk); return PTR_ERR(parent);
}
/* Get parent CPU frequency */
base_frequency = clk_get_rate(parent);
if (!base_frequency) {
dev_err(cpu_dev, "Failed to get parent clock rate for CPU\n");
clk_put(clk); return -EINVAL;
}
dvfs = armada_37xx_cpu_freq_info_get(base_frequency); if (!dvfs) {
clk_put(clk); return -EINVAL;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.