Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal/drivers/tegra: Add Tegra114 specific SOCTHERM driver

Add Tegra114 specific SOCTHERM driver.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>
Link: https://lore.kernel.org/r/20250828055104.8073-6-clamor95@gmail.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Svyatoslav Ryhel and committed by
Daniel Lezcano
9d522a87 10e1dcb6

+227
+1
drivers/thermal/tegra/Makefile
··· 4 4 obj-$(CONFIG_TEGRA30_TSENSOR) += tegra30-tsensor.o 5 5 6 6 tegra-soctherm-y := soctherm.o soctherm-fuse.o 7 + tegra-soctherm-$(CONFIG_ARCH_TEGRA_114_SOC) += tegra114-soctherm.o 7 8 tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-soctherm.o 8 9 tegra-soctherm-$(CONFIG_ARCH_TEGRA_132_SOC) += tegra132-soctherm.o 9 10 tegra-soctherm-$(CONFIG_ARCH_TEGRA_210_SOC) += tegra210-soctherm.o
+13
drivers/thermal/tegra/soctherm.c
··· 31 31 #include <linux/reset.h> 32 32 #include <linux/thermal.h> 33 33 34 + #include <dt-bindings/thermal/tegra114-soctherm.h> 34 35 #include <dt-bindings/thermal/tegra124-soctherm.h> 35 36 36 37 #include "../thermal_core.h" ··· 357 356 }; 358 357 359 358 static struct soctherm_oc_irq_chip_data soc_irq_cdata; 359 + 360 + /* Ensure that TEGRA114_* and TEGRA124_* counterparts are equal */ 361 + static_assert(TEGRA114_SOCTHERM_SENSOR_CPU == TEGRA124_SOCTHERM_SENSOR_CPU); 362 + static_assert(TEGRA114_SOCTHERM_SENSOR_MEM == TEGRA124_SOCTHERM_SENSOR_MEM); 363 + static_assert(TEGRA114_SOCTHERM_SENSOR_GPU == TEGRA124_SOCTHERM_SENSOR_GPU); 364 + static_assert(TEGRA114_SOCTHERM_SENSOR_PLLX == TEGRA124_SOCTHERM_SENSOR_PLLX); 360 365 361 366 /** 362 367 * ccroc_writel() - writes a value to a CCROC register ··· 2052 2045 } 2053 2046 2054 2047 static const struct of_device_id tegra_soctherm_of_match[] = { 2048 + #ifdef CONFIG_ARCH_TEGRA_114_SOC 2049 + { 2050 + .compatible = "nvidia,tegra114-soctherm", 2051 + .data = &tegra114_soctherm, 2052 + }, 2053 + #endif 2055 2054 #ifdef CONFIG_ARCH_TEGRA_124_SOC 2056 2055 { 2057 2056 .compatible = "nvidia,tegra124-soctherm",
+4
drivers/thermal/tegra/soctherm.h
··· 142 142 const struct tsensor_shared_calib *shared, 143 143 u32 *calib); 144 144 145 + #ifdef CONFIG_ARCH_TEGRA_114_SOC 146 + extern const struct tegra_soctherm_soc tegra114_soctherm; 147 + #endif 148 + 145 149 #ifdef CONFIG_ARCH_TEGRA_124_SOC 146 150 extern const struct tegra_soctherm_soc tegra124_soctherm; 147 151 #endif
+209
drivers/thermal/tegra/tegra114-soctherm.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved. 4 + * Copyright (c) 2024, Svyatoslav Ryhel <clamor95@gmail.com> 5 + */ 6 + 7 + #include <linux/module.h> 8 + #include <linux/platform_device.h> 9 + 10 + #include <dt-bindings/thermal/tegra114-soctherm.h> 11 + 12 + #include "soctherm.h" 13 + 14 + #define TEGRA114_THERMTRIP_ANY_EN_MASK (0x1 << 28) 15 + #define TEGRA114_THERMTRIP_MEM_EN_MASK (0x1 << 27) 16 + #define TEGRA114_THERMTRIP_GPU_EN_MASK (0x1 << 26) 17 + #define TEGRA114_THERMTRIP_CPU_EN_MASK (0x1 << 25) 18 + #define TEGRA114_THERMTRIP_TSENSE_EN_MASK (0x1 << 24) 19 + #define TEGRA114_THERMTRIP_GPUMEM_THRESH_MASK (0xff << 16) 20 + #define TEGRA114_THERMTRIP_CPU_THRESH_MASK (0xff << 8) 21 + #define TEGRA114_THERMTRIP_TSENSE_THRESH_MASK 0xff 22 + 23 + #define TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK (0xff << 17) 24 + #define TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK (0xff << 9) 25 + 26 + #define TEGRA114_THRESH_GRAIN 1000 27 + #define TEGRA114_BPTT 8 28 + 29 + static const struct tegra_tsensor_configuration tegra114_tsensor_config = { 30 + .tall = 16300, 31 + .tiddq_en = 1, 32 + .ten_count = 1, 33 + .tsample = 163, 34 + .tsample_ate = 655, 35 + }; 36 + 37 + static const struct tegra_tsensor_group tegra114_tsensor_group_cpu = { 38 + .id = TEGRA114_SOCTHERM_SENSOR_CPU, 39 + .name = "cpu", 40 + .sensor_temp_offset = SENSOR_TEMP1, 41 + .sensor_temp_mask = SENSOR_TEMP1_CPU_TEMP_MASK, 42 + .pdiv = 10, 43 + .pdiv_ate = 10, 44 + .pdiv_mask = SENSOR_PDIV_CPU_MASK, 45 + .pllx_hotspot_diff = 6, 46 + .pllx_hotspot_mask = SENSOR_HOTSPOT_CPU_MASK, 47 + .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK, 48 + .thermtrip_enable_mask = TEGRA114_THERMTRIP_CPU_EN_MASK, 49 + .thermtrip_threshold_mask = TEGRA114_THERMTRIP_CPU_THRESH_MASK, 50 + .thermctl_isr_mask = THERM_IRQ_CPU_MASK, 51 + .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_CPU, 52 + .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK, 53 + .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK, 54 + }; 55 + 56 + static const struct tegra_tsensor_group tegra114_tsensor_group_gpu = { 57 + .id = TEGRA114_SOCTHERM_SENSOR_GPU, 58 + .name = "gpu", 59 + .sensor_temp_offset = SENSOR_TEMP1, 60 + .sensor_temp_mask = SENSOR_TEMP1_GPU_TEMP_MASK, 61 + .pdiv = 10, 62 + .pdiv_ate = 10, 63 + .pdiv_mask = SENSOR_PDIV_GPU_MASK, 64 + .pllx_hotspot_diff = 6, 65 + .pllx_hotspot_mask = SENSOR_HOTSPOT_GPU_MASK, 66 + .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK, 67 + .thermtrip_enable_mask = TEGRA114_THERMTRIP_GPU_EN_MASK, 68 + .thermtrip_threshold_mask = TEGRA114_THERMTRIP_GPUMEM_THRESH_MASK, 69 + .thermctl_isr_mask = THERM_IRQ_GPU_MASK, 70 + .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_GPU, 71 + .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK, 72 + .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK, 73 + }; 74 + 75 + static const struct tegra_tsensor_group tegra114_tsensor_group_pll = { 76 + .id = TEGRA114_SOCTHERM_SENSOR_PLLX, 77 + .name = "pll", 78 + .sensor_temp_offset = SENSOR_TEMP2, 79 + .sensor_temp_mask = SENSOR_TEMP2_PLLX_TEMP_MASK, 80 + .pdiv = 10, 81 + .pdiv_ate = 10, 82 + .pdiv_mask = SENSOR_PDIV_PLLX_MASK, 83 + .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK, 84 + .thermtrip_enable_mask = TEGRA114_THERMTRIP_TSENSE_EN_MASK, 85 + .thermtrip_threshold_mask = TEGRA114_THERMTRIP_TSENSE_THRESH_MASK, 86 + .thermctl_isr_mask = THERM_IRQ_TSENSE_MASK, 87 + .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_TSENSE, 88 + .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK, 89 + .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK, 90 + }; 91 + 92 + static const struct tegra_tsensor_group tegra114_tsensor_group_mem = { 93 + .id = TEGRA114_SOCTHERM_SENSOR_MEM, 94 + .name = "mem", 95 + .sensor_temp_offset = SENSOR_TEMP2, 96 + .sensor_temp_mask = SENSOR_TEMP2_MEM_TEMP_MASK, 97 + .pdiv = 10, 98 + .pdiv_ate = 10, 99 + .pdiv_mask = SENSOR_PDIV_MEM_MASK, 100 + .pllx_hotspot_diff = 0, 101 + .pllx_hotspot_mask = SENSOR_HOTSPOT_MEM_MASK, 102 + .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK, 103 + .thermtrip_enable_mask = TEGRA114_THERMTRIP_MEM_EN_MASK, 104 + .thermtrip_threshold_mask = TEGRA114_THERMTRIP_GPUMEM_THRESH_MASK, 105 + .thermctl_isr_mask = THERM_IRQ_MEM_MASK, 106 + .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_MEM, 107 + .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK, 108 + .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK, 109 + }; 110 + 111 + static const struct tegra_tsensor_group *tegra114_tsensor_groups[] = { 112 + &tegra114_tsensor_group_cpu, 113 + &tegra114_tsensor_group_gpu, 114 + &tegra114_tsensor_group_pll, 115 + &tegra114_tsensor_group_mem, 116 + }; 117 + 118 + static const struct tegra_tsensor tegra114_tsensors[] = { 119 + { 120 + .name = "cpu0", 121 + .base = 0xc0, 122 + .config = &tegra114_tsensor_config, 123 + .calib_fuse_offset = 0x098, 124 + .fuse_corr_alpha = 1196400, 125 + .fuse_corr_beta = -13600000, 126 + .group = &tegra114_tsensor_group_cpu, 127 + }, { 128 + .name = "cpu1", 129 + .base = 0xe0, 130 + .config = &tegra114_tsensor_config, 131 + .calib_fuse_offset = 0x084, 132 + .fuse_corr_alpha = 1196400, 133 + .fuse_corr_beta = -13600000, 134 + .group = &tegra114_tsensor_group_cpu, 135 + }, { 136 + .name = "cpu2", 137 + .base = 0x100, 138 + .config = &tegra114_tsensor_config, 139 + .calib_fuse_offset = 0x088, 140 + .fuse_corr_alpha = 1196400, 141 + .fuse_corr_beta = -13600000, 142 + .group = &tegra114_tsensor_group_cpu, 143 + }, { 144 + .name = "cpu3", 145 + .base = 0x120, 146 + .config = &tegra114_tsensor_config, 147 + .calib_fuse_offset = 0x12c, 148 + .fuse_corr_alpha = 1196400, 149 + .fuse_corr_beta = -13600000, 150 + .group = &tegra114_tsensor_group_cpu, 151 + }, { 152 + .name = "mem0", 153 + .base = 0x140, 154 + .config = &tegra114_tsensor_config, 155 + .calib_fuse_offset = 0x158, 156 + .fuse_corr_alpha = 1000000, 157 + .fuse_corr_beta = 0, 158 + .group = &tegra114_tsensor_group_mem, 159 + }, { 160 + .name = "mem1", 161 + .base = 0x160, 162 + .config = &tegra114_tsensor_config, 163 + .calib_fuse_offset = 0x15c, 164 + .fuse_corr_alpha = 1000000, 165 + .fuse_corr_beta = 0, 166 + .group = &tegra114_tsensor_group_mem, 167 + }, { 168 + .name = "gpu", 169 + .base = 0x180, 170 + .config = &tegra114_tsensor_config, 171 + .calib_fuse_offset = 0x154, 172 + .fuse_corr_alpha = 1124500, 173 + .fuse_corr_beta = -9793100, 174 + .group = &tegra114_tsensor_group_gpu, 175 + }, { 176 + .name = "pllx", 177 + .base = 0x1a0, 178 + .config = &tegra114_tsensor_config, 179 + .calib_fuse_offset = 0x160, 180 + .fuse_corr_alpha = 1224200, 181 + .fuse_corr_beta = -14665000, 182 + .group = &tegra114_tsensor_group_pll, 183 + }, 184 + }; 185 + 186 + static const struct tegra_soctherm_fuse tegra114_soctherm_fuse = { 187 + .fuse_base_cp_mask = 0x3ff, 188 + .fuse_base_cp_shift = 0, 189 + .fuse_shift_cp_mask = 0x3f << 10, 190 + .fuse_shift_cp_shift = 10, 191 + .fuse_base_ft_mask = 0x7ff << 16, 192 + .fuse_base_ft_shift = 16, 193 + .fuse_shift_ft_mask = 0x1f << 27, 194 + .fuse_shift_ft_shift = 27, 195 + .fuse_common_reg = FUSE_VSENSOR_CALIB, 196 + .fuse_spare_realignment = 0, 197 + .nominal_calib_ft = 90, 198 + }; 199 + 200 + const struct tegra_soctherm_soc tegra114_soctherm = { 201 + .tsensors = tegra114_tsensors, 202 + .num_tsensors = ARRAY_SIZE(tegra114_tsensors), 203 + .ttgs = tegra114_tsensor_groups, 204 + .num_ttgs = ARRAY_SIZE(tegra114_tsensor_groups), 205 + .tfuse = &tegra114_soctherm_fuse, 206 + .thresh_grain = TEGRA114_THRESH_GRAIN, 207 + .bptt = TEGRA114_BPTT, 208 + .use_ccroc = false, 209 + };