tegra114-soctherm.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. #include <linux/module.h>
  7. #include <linux/platform_device.h>
  8. #include <dt-bindings/thermal/tegra114-soctherm.h>
  9. #include "soctherm.h"
  10. #define TEGRA114_THERMTRIP_ANY_EN_MASK (0x1 << 28)
  11. #define TEGRA114_THERMTRIP_MEM_EN_MASK (0x1 << 27)
  12. #define TEGRA114_THERMTRIP_GPU_EN_MASK (0x1 << 26)
  13. #define TEGRA114_THERMTRIP_CPU_EN_MASK (0x1 << 25)
  14. #define TEGRA114_THERMTRIP_TSENSE_EN_MASK (0x1 << 24)
  15. #define TEGRA114_THERMTRIP_GPUMEM_THRESH_MASK (0xff << 16)
  16. #define TEGRA114_THERMTRIP_CPU_THRESH_MASK (0xff << 8)
  17. #define TEGRA114_THERMTRIP_TSENSE_THRESH_MASK 0xff
  18. #define TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK (0xff << 17)
  19. #define TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK (0xff << 9)
  20. #define TEGRA114_THRESH_GRAIN 1000
  21. #define TEGRA114_BPTT 8
  22. static const struct tegra_tsensor_configuration tegra114_tsensor_config = {
  23. .tall = 16300,
  24. .tiddq_en = 1,
  25. .ten_count = 1,
  26. .tsample = 163,
  27. .tsample_ate = 655,
  28. };
  29. static const struct tegra_tsensor_group tegra114_tsensor_group_cpu = {
  30. .id = TEGRA114_SOCTHERM_SENSOR_CPU,
  31. .name = "cpu",
  32. .sensor_temp_offset = SENSOR_TEMP1,
  33. .sensor_temp_mask = SENSOR_TEMP1_CPU_TEMP_MASK,
  34. .pdiv = 10,
  35. .pdiv_ate = 10,
  36. .pdiv_mask = SENSOR_PDIV_CPU_MASK,
  37. .pllx_hotspot_diff = 6,
  38. .pllx_hotspot_mask = SENSOR_HOTSPOT_CPU_MASK,
  39. .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK,
  40. .thermtrip_enable_mask = TEGRA114_THERMTRIP_CPU_EN_MASK,
  41. .thermtrip_threshold_mask = TEGRA114_THERMTRIP_CPU_THRESH_MASK,
  42. .thermctl_isr_mask = THERM_IRQ_CPU_MASK,
  43. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_CPU,
  44. .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK,
  45. .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK,
  46. };
  47. static const struct tegra_tsensor_group tegra114_tsensor_group_gpu = {
  48. .id = TEGRA114_SOCTHERM_SENSOR_GPU,
  49. .name = "gpu",
  50. .sensor_temp_offset = SENSOR_TEMP1,
  51. .sensor_temp_mask = SENSOR_TEMP1_GPU_TEMP_MASK,
  52. .pdiv = 10,
  53. .pdiv_ate = 10,
  54. .pdiv_mask = SENSOR_PDIV_GPU_MASK,
  55. .pllx_hotspot_diff = 6,
  56. .pllx_hotspot_mask = SENSOR_HOTSPOT_GPU_MASK,
  57. .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK,
  58. .thermtrip_enable_mask = TEGRA114_THERMTRIP_GPU_EN_MASK,
  59. .thermtrip_threshold_mask = TEGRA114_THERMTRIP_GPUMEM_THRESH_MASK,
  60. .thermctl_isr_mask = THERM_IRQ_GPU_MASK,
  61. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_GPU,
  62. .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK,
  63. .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK,
  64. };
  65. static const struct tegra_tsensor_group tegra114_tsensor_group_pll = {
  66. .id = TEGRA114_SOCTHERM_SENSOR_PLLX,
  67. .name = "pll",
  68. .sensor_temp_offset = SENSOR_TEMP2,
  69. .sensor_temp_mask = SENSOR_TEMP2_PLLX_TEMP_MASK,
  70. .pdiv = 10,
  71. .pdiv_ate = 10,
  72. .pdiv_mask = SENSOR_PDIV_PLLX_MASK,
  73. .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK,
  74. .thermtrip_enable_mask = TEGRA114_THERMTRIP_TSENSE_EN_MASK,
  75. .thermtrip_threshold_mask = TEGRA114_THERMTRIP_TSENSE_THRESH_MASK,
  76. .thermctl_isr_mask = THERM_IRQ_TSENSE_MASK,
  77. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_TSENSE,
  78. .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK,
  79. .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK,
  80. };
  81. static const struct tegra_tsensor_group tegra114_tsensor_group_mem = {
  82. .id = TEGRA114_SOCTHERM_SENSOR_MEM,
  83. .name = "mem",
  84. .sensor_temp_offset = SENSOR_TEMP2,
  85. .sensor_temp_mask = SENSOR_TEMP2_MEM_TEMP_MASK,
  86. .pdiv = 10,
  87. .pdiv_ate = 10,
  88. .pdiv_mask = SENSOR_PDIV_MEM_MASK,
  89. .pllx_hotspot_diff = 0,
  90. .pllx_hotspot_mask = SENSOR_HOTSPOT_MEM_MASK,
  91. .thermtrip_any_en_mask = TEGRA114_THERMTRIP_ANY_EN_MASK,
  92. .thermtrip_enable_mask = TEGRA114_THERMTRIP_MEM_EN_MASK,
  93. .thermtrip_threshold_mask = TEGRA114_THERMTRIP_GPUMEM_THRESH_MASK,
  94. .thermctl_isr_mask = THERM_IRQ_MEM_MASK,
  95. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_MEM,
  96. .thermctl_lvl0_up_thresh_mask = TEGRA114_THERMCTL_LVL0_UP_THRESH_MASK,
  97. .thermctl_lvl0_dn_thresh_mask = TEGRA114_THERMCTL_LVL0_DN_THRESH_MASK,
  98. };
  99. static const struct tegra_tsensor_group *tegra114_tsensor_groups[] = {
  100. &tegra114_tsensor_group_cpu,
  101. &tegra114_tsensor_group_gpu,
  102. &tegra114_tsensor_group_pll,
  103. &tegra114_tsensor_group_mem,
  104. };
  105. static const struct tegra_tsensor tegra114_tsensors[] = {
  106. {
  107. .name = "cpu0",
  108. .base = 0xc0,
  109. .config = &tegra114_tsensor_config,
  110. .calib_fuse_offset = 0x098,
  111. .fuse_corr_alpha = 1196400,
  112. .fuse_corr_beta = -13600000,
  113. .group = &tegra114_tsensor_group_cpu,
  114. }, {
  115. .name = "cpu1",
  116. .base = 0xe0,
  117. .config = &tegra114_tsensor_config,
  118. .calib_fuse_offset = 0x084,
  119. .fuse_corr_alpha = 1196400,
  120. .fuse_corr_beta = -13600000,
  121. .group = &tegra114_tsensor_group_cpu,
  122. }, {
  123. .name = "cpu2",
  124. .base = 0x100,
  125. .config = &tegra114_tsensor_config,
  126. .calib_fuse_offset = 0x088,
  127. .fuse_corr_alpha = 1196400,
  128. .fuse_corr_beta = -13600000,
  129. .group = &tegra114_tsensor_group_cpu,
  130. }, {
  131. .name = "cpu3",
  132. .base = 0x120,
  133. .config = &tegra114_tsensor_config,
  134. .calib_fuse_offset = 0x12c,
  135. .fuse_corr_alpha = 1196400,
  136. .fuse_corr_beta = -13600000,
  137. .group = &tegra114_tsensor_group_cpu,
  138. }, {
  139. .name = "mem0",
  140. .base = 0x140,
  141. .config = &tegra114_tsensor_config,
  142. .calib_fuse_offset = 0x158,
  143. .fuse_corr_alpha = 1000000,
  144. .fuse_corr_beta = 0,
  145. .group = &tegra114_tsensor_group_mem,
  146. }, {
  147. .name = "mem1",
  148. .base = 0x160,
  149. .config = &tegra114_tsensor_config,
  150. .calib_fuse_offset = 0x15c,
  151. .fuse_corr_alpha = 1000000,
  152. .fuse_corr_beta = 0,
  153. .group = &tegra114_tsensor_group_mem,
  154. }, {
  155. .name = "gpu",
  156. .base = 0x180,
  157. .config = &tegra114_tsensor_config,
  158. .calib_fuse_offset = 0x154,
  159. .fuse_corr_alpha = 1124500,
  160. .fuse_corr_beta = -9793100,
  161. .group = &tegra114_tsensor_group_gpu,
  162. }, {
  163. .name = "pllx",
  164. .base = 0x1a0,
  165. .config = &tegra114_tsensor_config,
  166. .calib_fuse_offset = 0x160,
  167. .fuse_corr_alpha = 1224200,
  168. .fuse_corr_beta = -14665000,
  169. .group = &tegra114_tsensor_group_pll,
  170. },
  171. };
  172. static const struct tegra_soctherm_fuse tegra114_soctherm_fuse = {
  173. .fuse_base_cp_mask = 0x3ff,
  174. .fuse_base_cp_shift = 0,
  175. .fuse_shift_cp_mask = 0x3f << 10,
  176. .fuse_shift_cp_shift = 10,
  177. .fuse_base_ft_mask = 0x7ff << 16,
  178. .fuse_base_ft_shift = 16,
  179. .fuse_shift_ft_mask = 0x1f << 27,
  180. .fuse_shift_ft_shift = 27,
  181. .fuse_common_reg = FUSE_VSENSOR_CALIB,
  182. .fuse_spare_realignment = 0,
  183. .nominal_calib_ft = 90,
  184. };
  185. const struct tegra_soctherm_soc tegra114_soctherm = {
  186. .tsensors = tegra114_tsensors,
  187. .num_tsensors = ARRAY_SIZE(tegra114_tsensors),
  188. .ttgs = tegra114_tsensor_groups,
  189. .num_ttgs = ARRAY_SIZE(tegra114_tsensor_groups),
  190. .tfuse = &tegra114_soctherm_fuse,
  191. .thresh_grain = TEGRA114_THRESH_GRAIN,
  192. .bptt = TEGRA114_BPTT,
  193. .use_ccroc = false,
  194. };