162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * This software is licensed under the terms of the GNU General Public 662306a36Sopenharmony_ci * License version 2, as published by the Free Software Foundation, and 762306a36Sopenharmony_ci * may be copied, distributed, and modified under those terms. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, 1062306a36Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 1162306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1262306a36Sopenharmony_ci * GNU General Public License for more details. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci */ 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#include <linux/module.h> 1762306a36Sopenharmony_ci#include <linux/platform_device.h> 1862306a36Sopenharmony_ci#include <soc/tegra/fuse.h> 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#include <dt-bindings/thermal/tegra124-soctherm.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#include "soctherm.h" 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_ANY_EN_MASK (0x1 << 31) 2562306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_MEM_EN_MASK (0x1 << 30) 2662306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_GPU_EN_MASK (0x1 << 29) 2762306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_CPU_EN_MASK (0x1 << 28) 2862306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_TSENSE_EN_MASK (0x1 << 27) 2962306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_GPUMEM_THRESH_MASK (0x1ff << 18) 3062306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_CPU_THRESH_MASK (0x1ff << 9) 3162306a36Sopenharmony_ci#define TEGRA210_THERMTRIP_TSENSE_THRESH_MASK 0x1ff 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK (0x1ff << 18) 3462306a36Sopenharmony_ci#define TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK (0x1ff << 9) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#define TEGRA210_THRESH_GRAIN 500 3762306a36Sopenharmony_ci#define TEGRA210_BPTT 9 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_cistatic const struct tegra_tsensor_configuration tegra210_tsensor_config = { 4062306a36Sopenharmony_ci .tall = 16300, 4162306a36Sopenharmony_ci .tiddq_en = 1, 4262306a36Sopenharmony_ci .ten_count = 1, 4362306a36Sopenharmony_ci .tsample = 120, 4462306a36Sopenharmony_ci .tsample_ate = 480, 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra210_tsensor_group_cpu = { 4862306a36Sopenharmony_ci .id = TEGRA124_SOCTHERM_SENSOR_CPU, 4962306a36Sopenharmony_ci .name = "cpu", 5062306a36Sopenharmony_ci .sensor_temp_offset = SENSOR_TEMP1, 5162306a36Sopenharmony_ci .sensor_temp_mask = SENSOR_TEMP1_CPU_TEMP_MASK, 5262306a36Sopenharmony_ci .pdiv = 8, 5362306a36Sopenharmony_ci .pdiv_ate = 8, 5462306a36Sopenharmony_ci .pdiv_mask = SENSOR_PDIV_CPU_MASK, 5562306a36Sopenharmony_ci .pllx_hotspot_diff = 10, 5662306a36Sopenharmony_ci .pllx_hotspot_mask = SENSOR_HOTSPOT_CPU_MASK, 5762306a36Sopenharmony_ci .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK, 5862306a36Sopenharmony_ci .thermtrip_enable_mask = TEGRA210_THERMTRIP_CPU_EN_MASK, 5962306a36Sopenharmony_ci .thermtrip_threshold_mask = TEGRA210_THERMTRIP_CPU_THRESH_MASK, 6062306a36Sopenharmony_ci .thermctl_isr_mask = THERM_IRQ_CPU_MASK, 6162306a36Sopenharmony_ci .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_CPU, 6262306a36Sopenharmony_ci .thermctl_lvl0_up_thresh_mask = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK, 6362306a36Sopenharmony_ci .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK, 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra210_tsensor_group_gpu = { 6762306a36Sopenharmony_ci .id = TEGRA124_SOCTHERM_SENSOR_GPU, 6862306a36Sopenharmony_ci .name = "gpu", 6962306a36Sopenharmony_ci .sensor_temp_offset = SENSOR_TEMP1, 7062306a36Sopenharmony_ci .sensor_temp_mask = SENSOR_TEMP1_GPU_TEMP_MASK, 7162306a36Sopenharmony_ci .pdiv = 8, 7262306a36Sopenharmony_ci .pdiv_ate = 8, 7362306a36Sopenharmony_ci .pdiv_mask = SENSOR_PDIV_GPU_MASK, 7462306a36Sopenharmony_ci .pllx_hotspot_diff = 5, 7562306a36Sopenharmony_ci .pllx_hotspot_mask = SENSOR_HOTSPOT_GPU_MASK, 7662306a36Sopenharmony_ci .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK, 7762306a36Sopenharmony_ci .thermtrip_enable_mask = TEGRA210_THERMTRIP_GPU_EN_MASK, 7862306a36Sopenharmony_ci .thermtrip_threshold_mask = TEGRA210_THERMTRIP_GPUMEM_THRESH_MASK, 7962306a36Sopenharmony_ci .thermctl_isr_mask = THERM_IRQ_GPU_MASK, 8062306a36Sopenharmony_ci .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_GPU, 8162306a36Sopenharmony_ci .thermctl_lvl0_up_thresh_mask = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK, 8262306a36Sopenharmony_ci .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK, 8362306a36Sopenharmony_ci}; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra210_tsensor_group_pll = { 8662306a36Sopenharmony_ci .id = TEGRA124_SOCTHERM_SENSOR_PLLX, 8762306a36Sopenharmony_ci .name = "pll", 8862306a36Sopenharmony_ci .sensor_temp_offset = SENSOR_TEMP2, 8962306a36Sopenharmony_ci .sensor_temp_mask = SENSOR_TEMP2_PLLX_TEMP_MASK, 9062306a36Sopenharmony_ci .pdiv = 8, 9162306a36Sopenharmony_ci .pdiv_ate = 8, 9262306a36Sopenharmony_ci .pdiv_mask = SENSOR_PDIV_PLLX_MASK, 9362306a36Sopenharmony_ci .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK, 9462306a36Sopenharmony_ci .thermtrip_enable_mask = TEGRA210_THERMTRIP_TSENSE_EN_MASK, 9562306a36Sopenharmony_ci .thermtrip_threshold_mask = TEGRA210_THERMTRIP_TSENSE_THRESH_MASK, 9662306a36Sopenharmony_ci .thermctl_isr_mask = THERM_IRQ_TSENSE_MASK, 9762306a36Sopenharmony_ci .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_TSENSE, 9862306a36Sopenharmony_ci .thermctl_lvl0_up_thresh_mask = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK, 9962306a36Sopenharmony_ci .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK, 10062306a36Sopenharmony_ci}; 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_cistatic const struct tegra_tsensor_group tegra210_tsensor_group_mem = { 10362306a36Sopenharmony_ci .id = TEGRA124_SOCTHERM_SENSOR_MEM, 10462306a36Sopenharmony_ci .name = "mem", 10562306a36Sopenharmony_ci .sensor_temp_offset = SENSOR_TEMP2, 10662306a36Sopenharmony_ci .sensor_temp_mask = SENSOR_TEMP2_MEM_TEMP_MASK, 10762306a36Sopenharmony_ci .pdiv = 8, 10862306a36Sopenharmony_ci .pdiv_ate = 8, 10962306a36Sopenharmony_ci .pdiv_mask = SENSOR_PDIV_MEM_MASK, 11062306a36Sopenharmony_ci .pllx_hotspot_diff = 0, 11162306a36Sopenharmony_ci .pllx_hotspot_mask = SENSOR_HOTSPOT_MEM_MASK, 11262306a36Sopenharmony_ci .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK, 11362306a36Sopenharmony_ci .thermtrip_enable_mask = TEGRA210_THERMTRIP_MEM_EN_MASK, 11462306a36Sopenharmony_ci .thermtrip_threshold_mask = TEGRA210_THERMTRIP_GPUMEM_THRESH_MASK, 11562306a36Sopenharmony_ci .thermctl_isr_mask = THERM_IRQ_MEM_MASK, 11662306a36Sopenharmony_ci .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_MEM, 11762306a36Sopenharmony_ci .thermctl_lvl0_up_thresh_mask = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK, 11862306a36Sopenharmony_ci .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK, 11962306a36Sopenharmony_ci}; 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cistatic const struct tegra_tsensor_group *tegra210_tsensor_groups[] = { 12262306a36Sopenharmony_ci &tegra210_tsensor_group_cpu, 12362306a36Sopenharmony_ci &tegra210_tsensor_group_gpu, 12462306a36Sopenharmony_ci &tegra210_tsensor_group_pll, 12562306a36Sopenharmony_ci &tegra210_tsensor_group_mem, 12662306a36Sopenharmony_ci}; 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_cistatic const struct tegra_tsensor tegra210_tsensors[] = { 12962306a36Sopenharmony_ci { 13062306a36Sopenharmony_ci .name = "cpu0", 13162306a36Sopenharmony_ci .base = 0xc0, 13262306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 13362306a36Sopenharmony_ci .calib_fuse_offset = 0x098, 13462306a36Sopenharmony_ci .fuse_corr_alpha = 1085000, 13562306a36Sopenharmony_ci .fuse_corr_beta = 3244200, 13662306a36Sopenharmony_ci .group = &tegra210_tsensor_group_cpu, 13762306a36Sopenharmony_ci }, { 13862306a36Sopenharmony_ci .name = "cpu1", 13962306a36Sopenharmony_ci .base = 0xe0, 14062306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 14162306a36Sopenharmony_ci .calib_fuse_offset = 0x084, 14262306a36Sopenharmony_ci .fuse_corr_alpha = 1126200, 14362306a36Sopenharmony_ci .fuse_corr_beta = -67500, 14462306a36Sopenharmony_ci .group = &tegra210_tsensor_group_cpu, 14562306a36Sopenharmony_ci }, { 14662306a36Sopenharmony_ci .name = "cpu2", 14762306a36Sopenharmony_ci .base = 0x100, 14862306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 14962306a36Sopenharmony_ci .calib_fuse_offset = 0x088, 15062306a36Sopenharmony_ci .fuse_corr_alpha = 1098400, 15162306a36Sopenharmony_ci .fuse_corr_beta = 2251100, 15262306a36Sopenharmony_ci .group = &tegra210_tsensor_group_cpu, 15362306a36Sopenharmony_ci }, { 15462306a36Sopenharmony_ci .name = "cpu3", 15562306a36Sopenharmony_ci .base = 0x120, 15662306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 15762306a36Sopenharmony_ci .calib_fuse_offset = 0x12c, 15862306a36Sopenharmony_ci .fuse_corr_alpha = 1108000, 15962306a36Sopenharmony_ci .fuse_corr_beta = 602700, 16062306a36Sopenharmony_ci .group = &tegra210_tsensor_group_cpu, 16162306a36Sopenharmony_ci }, { 16262306a36Sopenharmony_ci .name = "mem0", 16362306a36Sopenharmony_ci .base = 0x140, 16462306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 16562306a36Sopenharmony_ci .calib_fuse_offset = 0x158, 16662306a36Sopenharmony_ci .fuse_corr_alpha = 1069200, 16762306a36Sopenharmony_ci .fuse_corr_beta = 3549900, 16862306a36Sopenharmony_ci .group = &tegra210_tsensor_group_mem, 16962306a36Sopenharmony_ci }, { 17062306a36Sopenharmony_ci .name = "mem1", 17162306a36Sopenharmony_ci .base = 0x160, 17262306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 17362306a36Sopenharmony_ci .calib_fuse_offset = 0x15c, 17462306a36Sopenharmony_ci .fuse_corr_alpha = 1173700, 17562306a36Sopenharmony_ci .fuse_corr_beta = -6263600, 17662306a36Sopenharmony_ci .group = &tegra210_tsensor_group_mem, 17762306a36Sopenharmony_ci }, { 17862306a36Sopenharmony_ci .name = "gpu", 17962306a36Sopenharmony_ci .base = 0x180, 18062306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 18162306a36Sopenharmony_ci .calib_fuse_offset = 0x154, 18262306a36Sopenharmony_ci .fuse_corr_alpha = 1074300, 18362306a36Sopenharmony_ci .fuse_corr_beta = 2734900, 18462306a36Sopenharmony_ci .group = &tegra210_tsensor_group_gpu, 18562306a36Sopenharmony_ci }, { 18662306a36Sopenharmony_ci .name = "pllx", 18762306a36Sopenharmony_ci .base = 0x1a0, 18862306a36Sopenharmony_ci .config = &tegra210_tsensor_config, 18962306a36Sopenharmony_ci .calib_fuse_offset = 0x160, 19062306a36Sopenharmony_ci .fuse_corr_alpha = 1039700, 19162306a36Sopenharmony_ci .fuse_corr_beta = 6829100, 19262306a36Sopenharmony_ci .group = &tegra210_tsensor_group_pll, 19362306a36Sopenharmony_ci }, 19462306a36Sopenharmony_ci}; 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci/* 19762306a36Sopenharmony_ci * Mask/shift bits in FUSE_TSENSOR_COMMON and 19862306a36Sopenharmony_ci * FUSE_TSENSOR_COMMON, which are described in 19962306a36Sopenharmony_ci * tegra_soctherm_fuse.c 20062306a36Sopenharmony_ci */ 20162306a36Sopenharmony_cistatic const struct tegra_soctherm_fuse tegra210_soctherm_fuse = { 20262306a36Sopenharmony_ci .fuse_base_cp_mask = 0x3ff << 11, 20362306a36Sopenharmony_ci .fuse_base_cp_shift = 11, 20462306a36Sopenharmony_ci .fuse_base_ft_mask = 0x7ff << 21, 20562306a36Sopenharmony_ci .fuse_base_ft_shift = 21, 20662306a36Sopenharmony_ci .fuse_shift_ft_mask = 0x1f << 6, 20762306a36Sopenharmony_ci .fuse_shift_ft_shift = 6, 20862306a36Sopenharmony_ci .fuse_spare_realignment = 0, 20962306a36Sopenharmony_ci}; 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_cistatic struct tsensor_group_thermtrips tegra210_tsensor_thermtrips[] = { 21262306a36Sopenharmony_ci {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, 21362306a36Sopenharmony_ci {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, 21462306a36Sopenharmony_ci {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, 21562306a36Sopenharmony_ci {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, 21662306a36Sopenharmony_ci}; 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ciconst struct tegra_soctherm_soc tegra210_soctherm = { 21962306a36Sopenharmony_ci .tsensors = tegra210_tsensors, 22062306a36Sopenharmony_ci .num_tsensors = ARRAY_SIZE(tegra210_tsensors), 22162306a36Sopenharmony_ci .ttgs = tegra210_tsensor_groups, 22262306a36Sopenharmony_ci .num_ttgs = ARRAY_SIZE(tegra210_tsensor_groups), 22362306a36Sopenharmony_ci .tfuse = &tegra210_soctherm_fuse, 22462306a36Sopenharmony_ci .thresh_grain = TEGRA210_THRESH_GRAIN, 22562306a36Sopenharmony_ci .bptt = TEGRA210_BPTT, 22662306a36Sopenharmony_ci .use_ccroc = false, 22762306a36Sopenharmony_ci .thermtrips = tegra210_tsensor_thermtrips, 22862306a36Sopenharmony_ci}; 229