From patchwork Mon Aug 13 13:36:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 10564249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CBB413B4 for ; Mon, 13 Aug 2018 13:52:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A7CD2928B for ; Mon, 13 Aug 2018 13:52:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DEEB29299; Mon, 13 Aug 2018 13:52:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CF6AE2928B for ; Mon, 13 Aug 2018 13:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=iysFgdnAEOZWacUvyUzlc+tFlvoI7lbSX7igmB1nHh0=; b=pn/R4YneiwDKUwqWIivwFCE6fG 8O956sUD7A2G62m8xMextHqGe9nzs9xciWHX6J/GaAs6lzY+LxKcqnp9D5rK7H1n7C4JiHM3ZtEy3 KofBqUrkVUxTpXclRUedb9HVceVyzXCO1B9OKAhsKxhc6Nxubjb6Mp3REKCCo88KsWuniSiVWofEJ cFCL06f4TAkmRe07Fb+D39WOK/p1xrBIQx/d9tzwGkVSJ4AYmd92FQ/U/UfPo3gUkkwoBTU8Iy4i9 biZJOh7mjzQ8xlOkf1x6NwdU72q4u9gJ81Ns02mD3Cay3kza7jee3p7yOZx9EHMdofHnuWgdXXR98 4gOiRgNw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fpDGy-0005yt-15; Mon, 13 Aug 2018 13:52:40 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fpDGv-0005qg-Sk for linux-arm-kernel@bombadil.infradead.org; Mon, 13 Aug 2018 13:52:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZPy2KqXBiCY8Wk/iQqhV4AY7+anAZ66XA1TNbFFEM2s=; b=tt1zrg7YaYBSdd95W4fE3KSJH KSOCewEFV6wWAaPCMmUvUx5LitPTB95Sf5ckK1Jju/uEOsdFJojXXm454yqNkkbAvUJHlib50S0mp H6IG76QHhLd4iqlcbKVgn1usaa5d/pv63pL+AR8w0A83xG11ynuBNfZ8dvHWZqtb3JtU5B59bK3IP cGz/3TjasSHY20EhdmAkIvH6uoJfAoJwjnVVoEqv1TEjlgwV8+eljFgWhzMz3dNlXdob9kZ3pCylx hyZ9iNNhe7B6fkJVonhYxt+rDeksZaRIJ7sn1sMznTBJhDZSMLimn6syUfwGS6OdfEOLQ3y1wU+G1 +6dMVDgCw==; Received: from smtp.codeaurora.org ([198.145.29.96]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fpD3x-0001tz-2B for linux-arm-kernel@lists.infradead.org; Mon, 13 Aug 2018 13:39:15 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3D7F460F6C; Mon, 13 Aug 2018 13:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1534167541; bh=VVxwKf1cco6x8XK+5qP5LarmbCM4HrE/QtHzh5v3a54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lSYoEQnr8Uwq9kprG4MSLiXICmwGROxvj2U4fTlpQ+JMAsi5dd9p9LMdnpVOFgba/ d23DxlPuGz+7/Y/05ZSYYOK7nVmy4hBd30H+3QLEO7gEYvN3A8C8+7H4GYHAV6hUwm RrkMPGX1eCUT0ly4ufMwsxOEYsLccqJGSeo0o/rw= Received: from srichara-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sricharan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 98A8560F3D; Mon, 13 Aug 2018 13:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1534167482; bh=VVxwKf1cco6x8XK+5qP5LarmbCM4HrE/QtHzh5v3a54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CieFppYjF0azhhAb0TkibUJjqpDQmcpxwSE8zWxiNUIecgbj3w9AIsS2YEfJxsulv DxQ7IUPAVouLPBZrl7tu8XRMdFS3XpNokRhds7xzpcGK5pdDPjSOs6N05mI4qrTQi3 yBVeR8BWctlwoRWJVICqTx/VdQasNHSvbszcCwTM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 98A8560F3D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sricharan@codeaurora.org From: Sricharan R To: mark.rutland@arm.com, robh@kernel.org, sudeep.holla@arm.com, linux@arm.linux.org.uk, ctatlor97@gmail.com, rjw@rjwysocki.net, viresh.kumar@linaro.org, mturquette@baylibre.com, linux-pm@vger.kernel.org, sboyd@codeaurora.org, linux@armlinux.org.uk, thierry.escande@linaro.org, linux-kernel@vger.kernel.org, david.brown@linaro.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, andy.gross@linaro.org, linux-soc@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, niklas.cassel@linaro.org Subject: [PATCH 14/14] cpufreq: qcom: Add support for krait based socs Date: Mon, 13 Aug 2018 19:06:07 +0530 Message-Id: <1534167367-17545-15-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1534167367-17545-1-git-send-email-sricharan@codeaurora.org> References: <1534167367-17545-1-git-send-email-sricharan@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180813_143913_465599_4E6F9DDF X-CRM114-Status: GOOD ( 26.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sricharan@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In Certain QCOM SoCs like ipq8064, apq8064, msm8960, msm8974 that has KRAIT processors the voltage/current value of each OPP varies based on the silicon variant in use. The required OPP related data is determined based on the efuse value. This is similar to the existing code for kryo cores. So adding support for krait cores here. Signed-off-by: Sricharan R --- .../devicetree/bindings/opp/qcom-nvmem-cpufreq.txt | 3 +- drivers/cpufreq/Kconfig.arm | 2 +- drivers/cpufreq/cpufreq-dt-platdev.c | 5 + drivers/cpufreq/qcom-cpufreq-nvmem.c | 151 +++++++++++++++++++-- 4 files changed, 149 insertions(+), 12 deletions(-) diff --git a/Documentation/devicetree/bindings/opp/qcom-nvmem-cpufreq.txt b/Documentation/devicetree/bindings/opp/qcom-nvmem-cpufreq.txt index 6dcdfcd..7bc0f1a 100644 --- a/Documentation/devicetree/bindings/opp/qcom-nvmem-cpufreq.txt +++ b/Documentation/devicetree/bindings/opp/qcom-nvmem-cpufreq.txt @@ -19,7 +19,8 @@ In 'cpus' nodes: In 'operating-points-v2' table: - compatible: Should be - - 'operating-points-v2-qcom-cpu' for apq8096 and msm8996. + - 'operating-points-v2-qcom-cpu' for apq8096, msm8996, msm8974, + apq8064, msm8960 and ipq8074. - nvmem-cells: A phandle pointing to a nvmem-cells node representing the efuse registers that has information about the speedbin that is used to select the right frequency/voltage diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm index 13fbd97..497ae89 100644 --- a/drivers/cpufreq/Kconfig.arm +++ b/drivers/cpufreq/Kconfig.arm @@ -126,7 +126,7 @@ config ARM_OMAP2PLUS_CPUFREQ config ARM_QCOM_CPUFREQ_NVMEM tristate "Qualcomm nvmem based CPUFreq" - depends on ARM64 + depends on ARCH_QCOM depends on QCOM_QFPROM depends on QCOM_SMEM select PM_OPP diff --git a/drivers/cpufreq/cpufreq-dt-platdev.c b/drivers/cpufreq/cpufreq-dt-platdev.c index fe14c57..917cdc2 100644 --- a/drivers/cpufreq/cpufreq-dt-platdev.c +++ b/drivers/cpufreq/cpufreq-dt-platdev.c @@ -128,6 +128,11 @@ { .compatible = "ti,am43", }, { .compatible = "ti,dra7", }, + { .compatible = "qcom,ipq8064", }, + { .compatible = "qcom,apq8064", }, + { .compatible = "qcom,msm8974", }, + { .compatible = "qcom,msm8960", }, + { } }; diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c index 0ad8e5b..5f2add0 100644 --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c @@ -45,6 +45,82 @@ enum _msm8996_version { static struct platform_device *cpufreq_dt_pdev, *cpufreq_pdev; +static void __init get_krait_bin_format_a(int *speed, int *pvs, int *pvs_ver, + struct nvmem_cell *pvs_nvmem, u8 *buf) +{ + u32 pte_efuse; + + pte_efuse = *((u32 *)buf); + + *speed = pte_efuse & 0xf; + if (*speed == 0xf) + *speed = (pte_efuse >> 4) & 0xf; + + if (*speed == 0xf) { + *speed = 0; + pr_warn("Speed bin: Defaulting to %d\n", *speed); + } else { + pr_info("Speed bin: %d\n", *speed); + } + + *pvs = (pte_efuse >> 10) & 0x7; + if (*pvs == 0x7) + *pvs = (pte_efuse >> 13) & 0x7; + + if (*pvs == 0x7) { + *pvs = 0; + pr_warn("PVS bin: Defaulting to %d\n", *pvs); + } else { + pr_info("PVS bin: %d\n", *pvs); + } + + kfree(buf); +} + +static void __init get_krait_bin_format_b(int *speed, int *pvs, int *pvs_ver, + struct nvmem_cell *pvs_nvmem, u8 *buf) +{ + u32 pte_efuse, redundant_sel; + + pte_efuse = *((u32 *)buf); + redundant_sel = (pte_efuse >> 24) & 0x7; + *speed = pte_efuse & 0x7; + + /* 4 bits of PVS are in efuse register bits 31, 8-6. */ + *pvs = ((pte_efuse >> 28) & 0x8) | ((pte_efuse >> 6) & 0x7); + *pvs_ver = (pte_efuse >> 4) & 0x3; + + switch (redundant_sel) { + case 1: + *speed = (pte_efuse >> 27) & 0xf; + break; + case 2: + *pvs = (pte_efuse >> 27) & 0xf; + break; + } + + /* Check SPEED_BIN_BLOW_STATUS */ + if (pte_efuse & BIT(3)) { + pr_info("Speed bin: %d\n", *speed); + } else { + pr_warn("Speed bin not set. Defaulting to 0!\n"); + *speed = 0; + } + + /* Check PVS_BLOW_STATUS */ + pte_efuse = *(((u32 *)buf) + 4); + pte_efuse &= BIT(21); + if (pte_efuse) { + pr_info("PVS bin: %d\n", *pvs); + } else { + pr_warn("PVS bin not set. Defaulting to 0!\n"); + *pvs = 0; + } + + pr_info("PVS version: %d\n", *pvs_ver); + kfree(buf); +} + static enum _msm8996_version __init qcom_cpufreq_get_msm_id(void) { size_t len; @@ -74,6 +150,35 @@ static enum _msm8996_version __init qcom_cpufreq_get_msm_id(void) return version; } +static int qcom_cpufreq_krait_name_version(struct device *cpu_dev, + struct nvmem_cell *speedbin_nvmem, + char **name, + u32 *versions) +{ + int speed = 0, pvs = 0, pvs_ver = 0; + u8 *buf; + size_t len; + + buf = nvmem_cell_read(speedbin_nvmem, &len); + if (len == 4) { + get_krait_bin_format_a(&speed, &pvs, &pvs_ver, + speedbin_nvmem, buf); + } else if (len == 8) { + get_krait_bin_format_b(&speed, &pvs, &pvs_ver, + speedbin_nvmem, buf); + } else { + dev_err(cpu_dev, "Unable to read nvmem data. Defaulting to 0!\n"); + return -ENODEV; + } + + snprintf(*name, sizeof("speedXX-pvsXX-vXX"), "speed%d-pvs%d-v%d", + speed, pvs, pvs_ver); + + *versions = (1 << speed); + + return 0; +} + static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev, struct nvmem_cell *speedbin_nvmem, char **pvs_name, @@ -83,6 +188,7 @@ static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev, u8 *speedbin; enum _msm8996_version msm8996_version; + *pvs_name = NULL; msm8996_version = qcom_cpufreq_get_msm_id(); if (NUM_OF_MSM8996_VERSIONS == msm8996_version) { dev_err(cpu_dev, "Not Snapdragon 820/821!"); @@ -111,7 +217,7 @@ static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev, static int qcom_cpufreq_probe(struct platform_device *pdev) { - struct opp_table *opp_tables[NR_CPUS] = { NULL }; + struct opp_table *tbl1[NR_CPUS] = { NULL }, *tbl2[NR_CPUS] = { NULL }; int (*get_version)(struct device *cpu_dev, struct nvmem_cell *speedbin_nvmem, char **name, int *versions); @@ -120,8 +226,8 @@ static int qcom_cpufreq_probe(struct platform_device *pdev) struct device *cpu_dev; unsigned cpu; u32 versions; - char *pvs_name = NULL; const struct of_device_id *match; + char *pvs_name = "speedXX-pvsXX-vXX"; int ret; cpu_dev = get_cpu_device(0); @@ -163,10 +269,19 @@ static int qcom_cpufreq_probe(struct platform_device *pdev) goto free_opp; } - opp_tables[cpu] = dev_pm_opp_set_supported_hw(cpu_dev, - &versions, 1); - if (IS_ERR(opp_tables[cpu])) { - ret = PTR_ERR(opp_tables[cpu]); + if (pvs_name) { + tbl1[cpu] = dev_pm_opp_set_prop_name(cpu_dev, pvs_name); + if (IS_ERR(tbl1[cpu])) { + ret = PTR_ERR(tbl1[cpu]); + dev_err(cpu_dev, "Failed to add OPP name %s\n", + pvs_name); + goto free_opp; + } + } + + tbl2[cpu] = dev_pm_opp_set_supported_hw(cpu_dev, &versions, 1); + if (IS_ERR(tbl2[cpu])) { + ret = PTR_ERR(tbl2[cpu]); dev_err(cpu_dev, "Failed to set supported hardware\n"); goto free_opp; } @@ -182,9 +297,15 @@ static int qcom_cpufreq_probe(struct platform_device *pdev) free_opp: for_each_possible_cpu(cpu) { - if (IS_ERR_OR_NULL(opp_tables[cpu])) + if (IS_ERR_OR_NULL(tbl1[cpu])) + break; + dev_pm_opp_put_prop_name(tbl1[cpu]); + } + + for_each_possible_cpu(cpu) { + if (IS_ERR_OR_NULL(tbl2[cpu])) break; - dev_pm_opp_put_supported_hw(opp_tables[cpu]); + dev_pm_opp_put_supported_hw(tbl2[cpu]); } return ret; @@ -205,8 +326,18 @@ static int qcom_cpufreq_remove(struct platform_device *pdev) }; static const struct of_device_id qcom_cpufreq_match_list[] __initconst = { - { .compatible = "qcom,apq8096", .data = qcom_cpufreq_kryo_name_version}, - { .compatible = "qcom,msm8996", .data = qcom_cpufreq_kryo_name_version}, + { .compatible = "qcom,apq8096", + .data = qcom_cpufreq_kryo_name_version}, + { .compatible = "qcom,msm8996", + .data = qcom_cpufreq_kryo_name_version}, + { .compatible = "qcom,ipq8064", + .data = qcom_cpufreq_krait_name_version }, + { .compatible = "qcom,apq8064", + .data = qcom_cpufreq_krait_name_version }, + { .compatible = "qcom,msm8974", + .data = qcom_cpufreq_krait_name_version }, + { .compatible = "qcom,msm8960", + .data = qcom_cpufreq_krait_name_version }, {}, };