From nobody Sun Sep 22 07:49:01 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C23C0C4332F for ; Fri, 15 Apr 2022 06:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350610AbiDOGCv (ORCPT ); Fri, 15 Apr 2022 02:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350291AbiDOGCD (ORCPT ); Fri, 15 Apr 2022 02:02:03 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5400CBF56; Thu, 14 Apr 2022 22:59:35 -0700 (PDT) X-UUID: 99b527f1244e4c57b7dd1375de76be7d-20220415 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.4,REQID:634c03d8-e3c5-4ef5-b9b4-080a8bd8c246,OB:0,LO B:0,IP:0,URL:0,TC:0,Content:0,EDM:0,RT:0,SF:100,FILE:0,RULE:Release_Ham,AC TION:release,TS:100 X-CID-INFO: VERSION:1.1.4,REQID:634c03d8-e3c5-4ef5-b9b4-080a8bd8c246,OB:0,LOB: 0,IP:0,URL:0,TC:0,Content:0,EDM:0,RT:0,SF:100,FILE:0,RULE:Spam_GS981B3D,AC TION:quarantine,TS:100 X-CID-META: VersionHash:faefae9,CLOUDID:9d987678-0afa-4dca-bdec-ca54c998425a,C OID:FAIL,Recheck:0,SF:13|15|28|17|19|48,TC:nil,Content:0,EDM:-3,File:nil,Q S:0,BEC:nil X-UUID: 99b527f1244e4c57b7dd1375de76be7d-20220415 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 269884715; Fri, 15 Apr 2022 13:59:21 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 15 Apr 2022 13:59:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 15 Apr 2022 13:59:19 +0800 From: Rex-BC Chen To: , , , , CC: , , , , , , , , , , , Rex-BC Chen Subject: [PATCH V3 09/15] cpufreq: mediatek: Refine mtk_cpufreq_voltage_tracking() Date: Fri, 15 Apr 2022 13:59:10 +0800 Message-ID: <20220415055916.28350-10-rex-bc.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220415055916.28350-1-rex-bc.chen@mediatek.com> References: <20220415055916.28350-1-rex-bc.chen@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jia-Wei Chang Because the difference of sram and proc should in a range of min_volt_shift and max_volt_shift. We need to adjust the sram and proc step by step. We replace VOLT_TOL (voltage tolerance) with the platform data and update t= he logic to determine the voltage boundary and invoking regulator_set_voltage. - Use 'sram_min_volt' and 'sram_max_volt' to determine the voltage boundary of sram regulator. - Use (sram_min_volt - min_volt_shift) and 'proc_max_volt' to determine the voltage boundary of vproc regulator. Signed-off-by: Jia-Wei Chang Signed-off-by: Rex-BC Chen --- drivers/cpufreq/mediatek-cpufreq.c | 130 ++++++++--------------------- 1 file changed, 34 insertions(+), 96 deletions(-) diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-= cpufreq.c index 559f4a383d30..cc44a7a9427a 100644 --- a/drivers/cpufreq/mediatek-cpufreq.c +++ b/drivers/cpufreq/mediatek-cpufreq.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -15,8 +16,6 @@ #include #include =20 -#define VOLT_TOL (10000) - struct mtk_cpufreq_platform_data { int min_volt_shift; int max_volt_shift; @@ -94,91 +93,44 @@ static int mtk_cpufreq_voltage_tracking(struct mtk_cpu_= dvfs_info *info, "invalid Vproc value: %d\n", pre_vproc); return pre_vproc; } - /* Vsram should not exceed the maximum allowed voltage of SoC. */ - new_vsram =3D min(new_vproc + soc_data->min_volt_shift, - soc_data->sram_max_volt); - - if (pre_vproc < new_vproc) { - /* - * When scaling up voltages, Vsram and Vproc scale up step - * by step. At each step, set Vsram to (Vproc + 200mV) first, - * then set Vproc to (Vsram - 100mV). - * Keep doing it until Vsram and Vproc hit target voltages. - */ - do { - pre_vsram =3D regulator_get_voltage(sram_reg); - if (pre_vsram < 0) { - dev_err(info->cpu_dev, - "invalid Vsram value: %d\n", pre_vsram); - return pre_vsram; - } - pre_vproc =3D regulator_get_voltage(proc_reg); - if (pre_vproc < 0) { - dev_err(info->cpu_dev, - "invalid Vproc value: %d\n", pre_vproc); - return pre_vproc; - } - - vsram =3D min(new_vsram, - pre_vproc + soc_data->min_volt_shift); =20 - if (vsram + VOLT_TOL >=3D soc_data->sram_max_volt) { - vsram =3D soc_data->sram_max_volt; + pre_vsram =3D regulator_get_voltage(sram_reg); + if (pre_vsram < 0) { + dev_err(info->cpu_dev, "invalid Vsram value: %d\n", pre_vsram); + return pre_vsram; + } =20 - /* - * If the target Vsram hits the maximum voltage, - * try to set the exact voltage value first. - */ - ret =3D regulator_set_voltage(sram_reg, vsram, - vsram); - if (ret) - ret =3D regulator_set_voltage(sram_reg, - vsram - VOLT_TOL, - vsram); + new_vsram =3D clamp(new_vproc + soc_data->min_volt_shift, + soc_data->sram_min_volt, soc_data->sram_max_volt); =20 - vproc =3D new_vproc; - } else { - ret =3D regulator_set_voltage(sram_reg, vsram, - vsram + VOLT_TOL); + do { + if (pre_vproc <=3D new_vproc) { + vsram =3D clamp(pre_vproc + soc_data->max_volt_shift, + soc_data->sram_min_volt, new_vsram); + ret =3D regulator_set_voltage(sram_reg, vsram, + soc_data->sram_max_volt); =20 - vproc =3D vsram - soc_data->min_volt_shift; - } if (ret) return ret; =20 + if (vsram =3D=3D soc_data->sram_max_volt || + new_vsram =3D=3D soc_data->sram_min_volt) + vproc =3D new_vproc; + else + vproc =3D vsram - soc_data->min_volt_shift; + ret =3D regulator_set_voltage(proc_reg, vproc, - vproc + VOLT_TOL); + soc_data->proc_max_volt); if (ret) { regulator_set_voltage(sram_reg, pre_vsram, - pre_vsram); + soc_data->sram_max_volt); return ret; } - } while (vproc < new_vproc || vsram < new_vsram); - } else if (pre_vproc > new_vproc) { - /* - * When scaling down voltages, Vsram and Vproc scale down step - * by step. At each step, set Vproc to (Vsram - 200mV) first, - * then set Vproc to (Vproc + 100mV). - * Keep doing it until Vsram and Vproc hit target voltages. - */ - do { - pre_vproc =3D regulator_get_voltage(proc_reg); - if (pre_vproc < 0) { - dev_err(info->cpu_dev, - "invalid Vproc value: %d\n", pre_vproc); - return pre_vproc; - } - pre_vsram =3D regulator_get_voltage(sram_reg); - if (pre_vsram < 0) { - dev_err(info->cpu_dev, - "invalid Vsram value: %d\n", pre_vsram); - return pre_vsram; - } - + } else if (pre_vproc > new_vproc) { vproc =3D max(new_vproc, pre_vsram - soc_data->max_volt_shift); ret =3D regulator_set_voltage(proc_reg, vproc, - vproc + VOLT_TOL); + soc_data->proc_max_volt); if (ret) return ret; =20 @@ -188,32 +140,18 @@ static int mtk_cpufreq_voltage_tracking(struct mtk_cp= u_dvfs_info *info, vsram =3D max(new_vsram, vproc + soc_data->min_volt_shift); =20 - if (vsram + VOLT_TOL >=3D soc_data->sram_max_volt) { - vsram =3D soc_data->sram_max_volt; - - /* - * If the target Vsram hits the maximum voltage, - * try to set the exact voltage value first. - */ - ret =3D regulator_set_voltage(sram_reg, vsram, - vsram); - if (ret) - ret =3D regulator_set_voltage(sram_reg, - vsram - VOLT_TOL, - vsram); - } else { - ret =3D regulator_set_voltage(sram_reg, vsram, - vsram + VOLT_TOL); - } - + ret =3D regulator_set_voltage(sram_reg, vsram, + soc_data->sram_max_volt); if (ret) { regulator_set_voltage(proc_reg, pre_vproc, - pre_vproc); + soc_data->proc_max_volt); return ret; } - } while (vproc > new_vproc + VOLT_TOL || - vsram > new_vsram + VOLT_TOL); - } + } + + pre_vproc =3D vproc; + pre_vsram =3D vsram; + } while (vproc !=3D new_vproc || vsram !=3D new_vsram); =20 return 0; } @@ -275,8 +213,8 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy= *policy, * If the new voltage or the intermediate voltage is higher than the * current voltage, scale up voltage first. */ - target_vproc =3D (inter_vproc > vproc) ? inter_vproc : vproc; - if (pre_vproc < target_vproc) { + target_vproc =3D max(inter_vproc, vproc); + if (pre_vproc <=3D target_vproc) { ret =3D mtk_cpufreq_set_voltage(info, target_vproc); if (ret) { dev_err(cpu_dev, --=20 2.18.0