···11+/*22+ * Copyright (c) 2013-2015, NVIDIA CORPORATION. All rights reserved.33+ *44+ * This program is free software; you can redistribute it and/or modify it55+ * under the terms and conditions of the GNU General Public License,66+ * version 2, as published by the Free Software Foundation.77+ *88+ * This program is distributed in the hope it will be useful, but WITHOUT99+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1010+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1111+ * more details.1212+ *1313+ * You should have received a copy of the GNU General Public License1414+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1515+ */1616+1717+#include <linux/device.h>1818+#include <linux/kernel.h>1919+#include <linux/bug.h>2020+2121+#include <soc/tegra/fuse.h>2222+2323+#include "fuse.h"2424+2525+#define CPU_PROCESS_CORNERS 22626+#define GPU_PROCESS_CORNERS 22727+#define SOC_PROCESS_CORNERS 32828+2929+#define FUSE_CPU_SPEEDO_0 0x0143030+#define FUSE_CPU_SPEEDO_1 0x02c3131+#define FUSE_CPU_SPEEDO_2 0x0303232+#define FUSE_SOC_SPEEDO_0 0x0343333+#define FUSE_SOC_SPEEDO_1 0x0383434+#define FUSE_SOC_SPEEDO_2 0x03c3535+#define FUSE_CPU_IDDQ 0x0183636+#define FUSE_SOC_IDDQ 0x0403737+#define FUSE_GPU_IDDQ 0x1283838+#define FUSE_FT_REV 0x0283939+4040+enum {4141+ THRESHOLD_INDEX_0,4242+ THRESHOLD_INDEX_1,4343+ THRESHOLD_INDEX_COUNT,4444+};4545+4646+static const u32 __initconst cpu_process_speedos[][CPU_PROCESS_CORNERS] = {4747+ { 2119, UINT_MAX },4848+ { 2119, UINT_MAX },4949+};5050+5151+static const u32 __initconst gpu_process_speedos[][GPU_PROCESS_CORNERS] = {5252+ { UINT_MAX, UINT_MAX },5353+ { UINT_MAX, UINT_MAX },5454+};5555+5656+static const u32 __initconst soc_process_speedos[][SOC_PROCESS_CORNERS] = {5757+ { 1950, 2100, UINT_MAX },5858+ { 1950, 2100, UINT_MAX },5959+};6060+6161+static u8 __init get_speedo_revision(void)6262+{6363+ return tegra_fuse_read_spare(4) << 2 |6464+ tegra_fuse_read_spare(3) << 1 |6565+ tegra_fuse_read_spare(2) << 0;6666+}6767+6868+static void __init rev_sku_to_speedo_ids(struct tegra_sku_info *sku_info,6969+ u8 speedo_rev, int *threshold)7070+{7171+ int sku = sku_info->sku_id;7272+7373+ /* Assign to default */7474+ sku_info->cpu_speedo_id = 0;7575+ sku_info->soc_speedo_id = 0;7676+ sku_info->gpu_speedo_id = 0;7777+ *threshold = THRESHOLD_INDEX_0;7878+7979+ switch (sku) {8080+ case 0x00: /* Engineering SKU */8181+ case 0x01: /* Engineering SKU */8282+ case 0x07:8383+ case 0x17:8484+ case 0x27:8585+ if (speedo_rev >= 2)8686+ sku_info->gpu_speedo_id = 1;8787+ break;8888+8989+ case 0x13:9090+ if (speedo_rev >= 2)9191+ sku_info->gpu_speedo_id = 1;9292+9393+ sku_info->cpu_speedo_id = 1;9494+ break;9595+9696+ default:9797+ pr_err("Tegra210: unknown SKU %#04x\n", sku);9898+ /* Using the default for the error case */9999+ break;100100+ }101101+}102102+103103+static int get_process_id(int value, const u32 *speedos, unsigned int num)104104+{105105+ unsigned int i;106106+107107+ for (i = 0; i < num; i++)108108+ if (value < speedos[num])109109+ return i;110110+111111+ return -EINVAL;112112+}113113+114114+void __init tegra210_init_speedo_data(struct tegra_sku_info *sku_info)115115+{116116+ int cpu_speedo[3], soc_speedo[3], cpu_iddq, gpu_iddq, soc_iddq;117117+ unsigned int index;118118+ u8 speedo_revision;119119+120120+ BUILD_BUG_ON(ARRAY_SIZE(cpu_process_speedos) !=121121+ THRESHOLD_INDEX_COUNT);122122+ BUILD_BUG_ON(ARRAY_SIZE(gpu_process_speedos) !=123123+ THRESHOLD_INDEX_COUNT);124124+ BUILD_BUG_ON(ARRAY_SIZE(soc_process_speedos) !=125125+ THRESHOLD_INDEX_COUNT);126126+127127+ /* Read speedo/IDDQ fuses */128128+ cpu_speedo[0] = tegra_fuse_read_early(FUSE_CPU_SPEEDO_0);129129+ cpu_speedo[1] = tegra_fuse_read_early(FUSE_CPU_SPEEDO_1);130130+ cpu_speedo[2] = tegra_fuse_read_early(FUSE_CPU_SPEEDO_2);131131+132132+ soc_speedo[0] = tegra_fuse_read_early(FUSE_SOC_SPEEDO_0);133133+ soc_speedo[1] = tegra_fuse_read_early(FUSE_SOC_SPEEDO_1);134134+ soc_speedo[2] = tegra_fuse_read_early(FUSE_CPU_SPEEDO_2);135135+136136+ cpu_iddq = tegra_fuse_read_early(FUSE_CPU_IDDQ) * 4;137137+ soc_iddq = tegra_fuse_read_early(FUSE_SOC_IDDQ) * 4;138138+ gpu_iddq = tegra_fuse_read_early(FUSE_GPU_IDDQ) * 5;139139+140140+ /*141141+ * Determine CPU, GPU and SoC speedo values depending on speedo fusing142142+ * revision. Note that GPU speedo value is fused in CPU_SPEEDO_2.143143+ */144144+ speedo_revision = get_speedo_revision();145145+ pr_info("Speedo Revision %u\n", speedo_revision);146146+147147+ if (speedo_revision >= 3) {148148+ sku_info->cpu_speedo_value = cpu_speedo[0];149149+ sku_info->gpu_speedo_value = cpu_speedo[2];150150+ sku_info->soc_speedo_value = soc_speedo[0];151151+ } else if (speedo_revision == 2) {152152+ sku_info->cpu_speedo_value = (-1938 + (1095 * cpu_speedo[0] / 100)) / 10;153153+ sku_info->gpu_speedo_value = (-1662 + (1082 * cpu_speedo[2] / 100)) / 10;154154+ sku_info->soc_speedo_value = ( -705 + (1037 * soc_speedo[0] / 100)) / 10;155155+ } else {156156+ sku_info->cpu_speedo_value = 2100;157157+ sku_info->gpu_speedo_value = cpu_speedo[2] - 75;158158+ sku_info->soc_speedo_value = 1900;159159+ }160160+161161+ if ((sku_info->cpu_speedo_value <= 0) ||162162+ (sku_info->gpu_speedo_value <= 0) ||163163+ (sku_info->soc_speedo_value <= 0)) {164164+ WARN(1, "speedo value not fused\n");165165+ return;166166+ }167167+168168+ rev_sku_to_speedo_ids(sku_info, speedo_revision, &index);169169+170170+ sku_info->gpu_process_id = get_process_id(sku_info->gpu_speedo_value,171171+ gpu_process_speedos[index],172172+ GPU_PROCESS_CORNERS);173173+174174+ sku_info->cpu_process_id = get_process_id(sku_info->cpu_speedo_value,175175+ cpu_process_speedos[index],176176+ CPU_PROCESS_CORNERS);177177+178178+ sku_info->soc_process_id = get_process_id(sku_info->soc_speedo_value,179179+ soc_process_speedos[index],180180+ SOC_PROCESS_CORNERS);181181+182182+ pr_debug("Tegra GPU Speedo ID=%d, Speedo Value=%d\n",183183+ sku_info->gpu_speedo_id, sku_info->gpu_speedo_value);184184+}
+3-1
include/soc/tegra/fuse.h
···2222#define TEGRA114 0x352323#define TEGRA124 0x402424#define TEGRA132 0x132525+#define TEGRA210 0x2125262627#define TEGRA_FUSE_SKU_CALIB_0 0xf02728#define TEGRA30_FUSE_SATA_CALIB 0x124···5049 int cpu_iddq_value;5150 int core_process_id;5251 int soc_speedo_id;5353- int gpu_speedo_id;5252+ int soc_speedo_value;5453 int gpu_process_id;5454+ int gpu_speedo_id;5555 int gpu_speedo_value;5656 enum tegra_revision revision;5757};