From patchwork Thu Oct 8 12:13:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Yuan X-Patchwork-Id: 268716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 410C3C43467 for ; Thu, 8 Oct 2020 12:13:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 03753215A4 for ; Thu, 8 Oct 2020 12:13:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="GyW6TsgX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729587AbgJHMNm (ORCPT ); Thu, 8 Oct 2020 08:13:42 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:43457 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725871AbgJHMNm (ORCPT ); Thu, 8 Oct 2020 08:13:42 -0400 X-UUID: 678ba5023dff4fa3be6c744151ed7245-20201008 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=3MSsqoh1JwjXfyI5saR12zhZgmKR4OSbtoJozpp9kpc=; b=GyW6TsgXr4WBE4vWeF+mAqjVdhuazzUYat8H/qp6KuEzZYFBCYYUap7mQ5X+pTz9GIL8CuhQAmIQUhvDzPXe1m4USxq4O/LYsGUxJG2QExK0mcxHfM0nTVD/s2l44q6IsLDmtXXTqP7LOD+p10xnRz7fjeD7owvOnh/mH7PF05Y=; X-UUID: 678ba5023dff4fa3be6c744151ed7245-20201008 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 620526542; Thu, 08 Oct 2020 20:13:37 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 8 Oct 2020 20:13:34 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 8 Oct 2020 20:13:34 +0800 From: Hector Yuan To: , , , "Rafael J. Wysocki" , Viresh Kumar CC: , , Subject: [PATCH v1 1/1] cpufreq: mediatek-hw: Register EM power table Date: Thu, 8 Oct 2020 20:13:24 +0800 Message-ID: <1602159204-13756-2-git-send-email-hector.yuan@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1602159204-13756-1-git-send-email-hector.yuan@mediatek.com> References: <1602159204-13756-1-git-send-email-hector.yuan@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: F6F2F17101A6B232DE0515C059CB03673413A6D7CCAE1BF62441835C41AF8EBC2000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: "Hector.Yuan" Register CPU power table to energy model framework Signed-off-by: Hector.Yuan --- drivers/cpufreq/mediatek-cpufreq-hw.c | 50 +++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 12 deletions(-) -- 1.7.9.5 diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediatek-cpufreq-hw.c index 8fa12e5..3808ea0 100644 --- a/drivers/cpufreq/mediatek-cpufreq-hw.c +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -17,9 +18,10 @@ #define LUT_ROW_SIZE 0x4 enum { - REG_LUT_TABLE, - REG_ENABLE, - REG_PERF_STATE, + REG_FREQ_LUT_TABLE, + REG_FREQ_ENABLE, + REG_FREQ_PERF_STATE, + REG_EM_POWER_TBL, REG_ARRAY_SIZE, }; @@ -27,23 +29,44 @@ enum { struct cpufreq_mtk { struct cpufreq_frequency_table *table; void __iomem *reg_bases[REG_ARRAY_SIZE]; + int nr_opp; cpumask_t related_cpus; }; static const u16 cpufreq_mtk_offsets[REG_ARRAY_SIZE] = { - [REG_LUT_TABLE] = 0x0, - [REG_ENABLE] = 0x84, - [REG_PERF_STATE] = 0x88, + [REG_FREQ_LUT_TABLE] = 0x0, + [REG_FREQ_ENABLE] = 0x84, + [REG_FREQ_PERF_STATE] = 0x88, + [REG_EM_POWER_TBL] = 0x3D0, }; static struct cpufreq_mtk *mtk_freq_domain_map[NR_CPUS]; +static int mtk_cpufreq_get_cpu_power(unsigned long *mW, + unsigned long *KHz, int cpu) +{ + struct cpufreq_mtk *c = mtk_freq_domain_map[cpu]; + int i; + + for (i = 0; i < c->nr_opp; i++) { + if (c->table[i].frequency < *KHz) + break; + } + i--; + + *KHz = c->table[i].frequency; + *mW = readl_relaxed(c->reg_bases[REG_EM_POWER_TBL] + + i * LUT_ROW_SIZE) / 1000; + + return 0; +} + static int mtk_cpufreq_hw_target_index(struct cpufreq_policy *policy, unsigned int index) { struct cpufreq_mtk *c = policy->driver_data; - writel_relaxed(index, c->reg_bases[REG_PERF_STATE]); + writel_relaxed(index, c->reg_bases[REG_FREQ_PERF_STATE]); return 0; } @@ -55,7 +78,7 @@ static unsigned int mtk_cpufreq_hw_get(unsigned int cpu) c = mtk_freq_domain_map[cpu]; - index = readl_relaxed(c->reg_bases[REG_PERF_STATE]); + index = readl_relaxed(c->reg_bases[REG_FREQ_PERF_STATE]); index = min(index, LUT_MAX_ENTRIES - 1); return c->table[index].frequency; @@ -64,6 +87,7 @@ static unsigned int mtk_cpufreq_hw_get(unsigned int cpu) static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy) { struct cpufreq_mtk *c; + struct em_data_callback em_cb = EM_DATA_CB(mtk_cpufreq_get_cpu_power); c = mtk_freq_domain_map[policy->cpu]; if (!c) { @@ -77,7 +101,8 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy) policy->driver_data = c; /* HW should be in enabled state to proceed now */ - writel_relaxed(0x1, c->reg_bases[REG_ENABLE]); + writel_relaxed(0x1, c->reg_bases[REG_FREQ_ENABLE]); + em_register_perf_domain(policy->cpus, c->nr_opp, &em_cb); return 0; } @@ -93,7 +118,7 @@ static int mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) } /* HW should be in paused state now */ - writel_relaxed(0x0, c->reg_bases[REG_ENABLE]); + writel_relaxed(0x0, c->reg_bases[REG_FREQ_ENABLE]); return 0; } @@ -122,7 +147,7 @@ static int mtk_cpu_create_freq_table(struct platform_device *pdev, if (!c->table) return -ENOMEM; - base_table = c->reg_bases[REG_LUT_TABLE]; + base_table = c->reg_bases[REG_FREQ_LUT_TABLE]; for (i = 0; i < LUT_MAX_ENTRIES; i++) { data = readl_relaxed(base_table + (i * LUT_ROW_SIZE)); @@ -140,6 +165,7 @@ static int mtk_cpu_create_freq_table(struct platform_device *pdev, } c->table[i].frequency = CPUFREQ_TABLE_END; + c->nr_opp = i; return 0; } @@ -192,7 +218,7 @@ static int mtk_cpu_resources_init(struct platform_device *pdev, if (IS_ERR(base)) return PTR_ERR(base); - for (i = REG_LUT_TABLE; i < REG_ARRAY_SIZE; i++) + for (i = REG_FREQ_LUT_TABLE; i < REG_ARRAY_SIZE; i++) c->reg_bases[i] = base + offsets[i]; ret = mtk_get_related_cpus(index, c);