Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2254409pxu; Mon, 7 Dec 2020 01:22:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJySzbAb8tROV3eztDIA9xp1/dXSbrL2qsXEJSnpWuCXCpxdLJPkZkUFXX/gvae0+oZfJ1qy X-Received: by 2002:aa7:cf8f:: with SMTP id z15mr15695922edx.17.1607332921121; Mon, 07 Dec 2020 01:22:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607332921; cv=none; d=google.com; s=arc-20160816; b=qhZZ7fnLEtC753fdx2X1skOViiiE/pEPbu1m/2bL9Zdhuk3ZJj4Ap947nwpiqjV9ew D3whRmK9PkTkDc2q2ZzzRI8c/I54xt8au6a2vXVp8DVgf6CHxt0oQpcywVMOzDs5xSFf gJgy0FpYC0FbsBmMgX4KVR1RuqMJ2emcXnSzi9DZgF82kaTm2yJHRMDVDBEsEW2N1qEx HLmk95oAP5JQGmCZ8BY0nyaSl4nc7OGCYIjgo/sS5uCTLmtQ72DmwXMBhOLTZF6otT1q S7yHtv3M+nXNnB4ZNfIpiyXljIidGgksUl8SHoBB85YkBV8sVWc5MX/Vo7YnHPshSCVz kaog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=upJlPfFB5pFmvFKLw+1+y/cf0+P8V3ROhO7auX0cm5g=; b=qGu9h7fkstAaK6enhzPILT4IFr5lEw0vmNhGE1iYNvTbnzOKmq8o3/GR4APf5Sq2Qs nd2j9kebvQNhD4ipi8KUW/W1jE6mt0Cg9RQ58SrYTbCY3I5PsWW6JvcCJtiWWYSdK4dV XvfEKwFNEBfdI4S/lS/2dfyRyDnpFHmzotyZ097fV1iTPM5/JVhMTcZyzmmHYXoZ6bSd E3Qw6VpV/2aKr0TXRruCQOqSdLg0JvUvCsVax8q0o+tdrtQnc6oCBvL+ok4pFMblHm9Z QwwW0/j5pHO/vYDeAIr1vz/ltZW1RgTS7P/3/O4qZ1JKnKEw3V9gSjWoKWpofVusokc5 PYiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si7785187edx.591.2020.12.07.01.21.38; Mon, 07 Dec 2020 01:22:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726853AbgLGJSI (ORCPT + 99 others); Mon, 7 Dec 2020 04:18:08 -0500 Received: from smtp2207-205.mail.aliyun.com ([121.197.207.205]:40085 "EHLO smtp2207-205.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbgLGJSH (ORCPT ); Mon, 7 Dec 2020 04:18:07 -0500 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07437193|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.0217741-0.00249463-0.975731;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047206;MF=huangshuosheng@allwinnertech.com;NM=1;PH=DS;RN=10;RT=10;SR=0;TI=SMTPD_---.J42KvvE_1607332641; Received: from allwinnertech.com(mailfrom:huangshuosheng@allwinnertech.com fp:SMTPD_---.J42KvvE_1607332641) by smtp.aliyun-inc.com(10.147.43.230); Mon, 07 Dec 2020 17:17:25 +0800 From: Shuosheng Huang To: tiny.windzz@gmail.com, rjw@rjwysocki.net, viresh.kumar@linaro.org, mripard@kernel.org, wens@csie.org, jernej.skrabec@siol.net Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Shuosheng Huang Subject: [PATCH V2 1/3] cpufreq: sun50i: add efuse_xlate to get efuse version. Date: Mon, 7 Dec 2020 17:17:16 +0800 Message-Id: <20201207091716.17492-1-huangshuosheng@allwinnertech.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's better to use efuse_xlate to extract the differentiated part regarding different SoC. Signed-off-by: Shuosheng Huang --- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 72 +++++++++++++++++--------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c index 9907a165135b..da23d581a4b4 100644 --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c @@ -22,21 +22,52 @@ #define NVMEM_MASK 0x7 #define NVMEM_SHIFT 5 +#define SUN50I_H6_NVMEM_MASK 0x7 +#define SUN50I_H6_NVMEM_SHIFT 5 + +struct sunxi_cpufreq_soc_data { + u32 (*efuse_xlate)(void *efuse); +}; + static struct platform_device *cpufreq_dt_pdev, *sun50i_cpufreq_pdev; +static u32 sun50i_h6_efuse_xlate(struct nvmem_cell *speedbin_nvmem) +{ + size_t len; + u32 *speedbin; + u32 efuse_value; + + speedbin = nvmem_cell_read(speedbin_nvmem, &len); + if (IS_ERR(speedbin)) + return PTR_ERR(speedbin); + + efuse_value = (*(u32 *)speedbin >> SUN50I_H6_NVMEM_SHIFT) & + SUN50I_H6_NVMEM_MASK; + kfree(speedbin); + /* + * We treat unexpected efuse values as if the SoC was from + * the slowest bin. Expected efuse values are 1-3, slowest + * to fastest. + */ + if (efuse_value >= 1 && efuse_value <= 3) + return efuse_value - 1; + else + return 0; +} + /** * sun50i_cpufreq_get_efuse() - Determine speed grade from efuse value + * @soc_data: pointer to sunxi_cpufreq_soc_data context * @versions: Set to the value parsed from efuse * * Returns 0 if success. */ -static int sun50i_cpufreq_get_efuse(u32 *versions) +static int sun50i_cpufreq_get_efuse(const struct sunxi_cpufreq_soc_data *soc_data, + u32 *versions) { struct nvmem_cell *speedbin_nvmem; struct device_node *np; struct device *cpu_dev; - u32 *speedbin, efuse_value; - size_t len; int ret; cpu_dev = get_cpu_device(0); @@ -63,41 +94,31 @@ static int sun50i_cpufreq_get_efuse(u32 *versions) return PTR_ERR(speedbin_nvmem); } - speedbin = nvmem_cell_read(speedbin_nvmem, &len); + *versions = soc_data->efuse_xlate(speedbin_nvmem); nvmem_cell_put(speedbin_nvmem); - if (IS_ERR(speedbin)) - return PTR_ERR(speedbin); - - efuse_value = (*speedbin >> NVMEM_SHIFT) & NVMEM_MASK; - - /* - * We treat unexpected efuse values as if the SoC was from - * the slowest bin. Expected efuse values are 1-3, slowest - * to fastest. - */ - if (efuse_value >= 1 && efuse_value <= 3) - *versions = efuse_value - 1; - else - *versions = 0; - kfree(speedbin); return 0; }; static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev) { + const struct of_device_id *match; struct opp_table **opp_tables; char name[MAX_NAME_LEN]; unsigned int cpu; u32 speed = 0; int ret; + match = dev_get_platdata(&pdev->dev); + if (!match) + return -EINVAL; + opp_tables = kcalloc(num_possible_cpus(), sizeof(*opp_tables), GFP_KERNEL); if (!opp_tables) return -ENOMEM; - ret = sun50i_cpufreq_get_efuse(&speed); + ret = sun50i_cpufreq_get_efuse(match->data, &speed); if (ret) return ret; @@ -163,8 +184,12 @@ static struct platform_driver sun50i_cpufreq_driver = { }, }; +static const struct sunxi_cpufreq_soc_data sun50i_h6_data = { + .efuse_xlate = sun50i_h6_efuse_xlate, +}; + static const struct of_device_id sun50i_cpufreq_match_list[] = { - { .compatible = "allwinner,sun50i-h6" }, + { .compatible = "allwinner,sun50i-h6", .data = &sun50i_h6_data }, {} }; @@ -198,9 +223,8 @@ static int __init sun50i_cpufreq_init(void) if (unlikely(ret < 0)) return ret; - sun50i_cpufreq_pdev = - platform_device_register_simple("sun50i-cpufreq-nvmem", - -1, NULL, 0); + sun50i_cpufreq_pdev = platform_device_register_data(NULL, + "sun50i-cpufreq-nvmem", -1, match, sizeof(*match)); ret = PTR_ERR_OR_ZERO(sun50i_cpufreq_pdev); if (ret == 0) return 0; -- 2.28.0