tegra210-soctherm.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <soc/tegra/fuse.h>
  18. #include <dt-bindings/thermal/tegra124-soctherm.h>
  19. #include "soctherm.h"
  20. #define TEGRA210_THERMTRIP_ANY_EN_MASK (0x1 << 31)
  21. #define TEGRA210_THERMTRIP_MEM_EN_MASK (0x1 << 30)
  22. #define TEGRA210_THERMTRIP_GPU_EN_MASK (0x1 << 29)
  23. #define TEGRA210_THERMTRIP_CPU_EN_MASK (0x1 << 28)
  24. #define TEGRA210_THERMTRIP_TSENSE_EN_MASK (0x1 << 27)
  25. #define TEGRA210_THERMTRIP_GPUMEM_THRESH_MASK (0x1ff << 18)
  26. #define TEGRA210_THERMTRIP_CPU_THRESH_MASK (0x1ff << 9)
  27. #define TEGRA210_THERMTRIP_TSENSE_THRESH_MASK 0x1ff
  28. #define TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK (0x1ff << 18)
  29. #define TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK (0x1ff << 9)
  30. #define TEGRA210_THRESH_GRAIN 500
  31. #define TEGRA210_BPTT 9
  32. static const struct tegra_tsensor_configuration tegra210_tsensor_config = {
  33. .tall = 16300,
  34. .tiddq_en = 1,
  35. .ten_count = 1,
  36. .tsample = 120,
  37. .tsample_ate = 480,
  38. };
  39. static const struct tegra_tsensor_group tegra210_tsensor_group_cpu = {
  40. .id = TEGRA124_SOCTHERM_SENSOR_CPU,
  41. .name = "cpu",
  42. .sensor_temp_offset = SENSOR_TEMP1,
  43. .sensor_temp_mask = SENSOR_TEMP1_CPU_TEMP_MASK,
  44. .pdiv = 8,
  45. .pdiv_ate = 8,
  46. .pdiv_mask = SENSOR_PDIV_CPU_MASK,
  47. .pllx_hotspot_diff = 10,
  48. .pllx_hotspot_mask = SENSOR_HOTSPOT_CPU_MASK,
  49. .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK,
  50. .thermtrip_enable_mask = TEGRA210_THERMTRIP_CPU_EN_MASK,
  51. .thermtrip_threshold_mask = TEGRA210_THERMTRIP_CPU_THRESH_MASK,
  52. .thermctl_isr_mask = THERM_IRQ_CPU_MASK,
  53. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_CPU,
  54. .thermctl_lvl0_up_thresh_mask = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK,
  55. .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK,
  56. };
  57. static const struct tegra_tsensor_group tegra210_tsensor_group_gpu = {
  58. .id = TEGRA124_SOCTHERM_SENSOR_GPU,
  59. .name = "gpu",
  60. .sensor_temp_offset = SENSOR_TEMP1,
  61. .sensor_temp_mask = SENSOR_TEMP1_GPU_TEMP_MASK,
  62. .pdiv = 8,
  63. .pdiv_ate = 8,
  64. .pdiv_mask = SENSOR_PDIV_GPU_MASK,
  65. .pllx_hotspot_diff = 5,
  66. .pllx_hotspot_mask = SENSOR_HOTSPOT_GPU_MASK,
  67. .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK,
  68. .thermtrip_enable_mask = TEGRA210_THERMTRIP_GPU_EN_MASK,
  69. .thermtrip_threshold_mask = TEGRA210_THERMTRIP_GPUMEM_THRESH_MASK,
  70. .thermctl_isr_mask = THERM_IRQ_GPU_MASK,
  71. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_GPU,
  72. .thermctl_lvl0_up_thresh_mask = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK,
  73. .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK,
  74. };
  75. static const struct tegra_tsensor_group tegra210_tsensor_group_pll = {
  76. .id = TEGRA124_SOCTHERM_SENSOR_PLLX,
  77. .name = "pll",
  78. .sensor_temp_offset = SENSOR_TEMP2,
  79. .sensor_temp_mask = SENSOR_TEMP2_PLLX_TEMP_MASK,
  80. .pdiv = 8,
  81. .pdiv_ate = 8,
  82. .pdiv_mask = SENSOR_PDIV_PLLX_MASK,
  83. .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK,
  84. .thermtrip_enable_mask = TEGRA210_THERMTRIP_TSENSE_EN_MASK,
  85. .thermtrip_threshold_mask = TEGRA210_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 = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK,
  89. .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK,
  90. };
  91. static const struct tegra_tsensor_group tegra210_tsensor_group_mem = {
  92. .id = TEGRA124_SOCTHERM_SENSOR_MEM,
  93. .name = "mem",
  94. .sensor_temp_offset = SENSOR_TEMP2,
  95. .sensor_temp_mask = SENSOR_TEMP2_MEM_TEMP_MASK,
  96. .pdiv = 8,
  97. .pdiv_ate = 8,
  98. .pdiv_mask = SENSOR_PDIV_MEM_MASK,
  99. .pllx_hotspot_diff = 0,
  100. .pllx_hotspot_mask = SENSOR_HOTSPOT_MEM_MASK,
  101. .thermtrip_any_en_mask = TEGRA210_THERMTRIP_ANY_EN_MASK,
  102. .thermtrip_enable_mask = TEGRA210_THERMTRIP_MEM_EN_MASK,
  103. .thermtrip_threshold_mask = TEGRA210_THERMTRIP_GPUMEM_THRESH_MASK,
  104. .thermctl_isr_mask = THERM_IRQ_MEM_MASK,
  105. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_MEM,
  106. .thermctl_lvl0_up_thresh_mask = TEGRA210_THERMCTL_LVL0_UP_THRESH_MASK,
  107. .thermctl_lvl0_dn_thresh_mask = TEGRA210_THERMCTL_LVL0_DN_THRESH_MASK,
  108. };
  109. static const struct tegra_tsensor_group *tegra210_tsensor_groups[] = {
  110. &tegra210_tsensor_group_cpu,
  111. &tegra210_tsensor_group_gpu,
  112. &tegra210_tsensor_group_pll,
  113. &tegra210_tsensor_group_mem,
  114. };
  115. static const struct tegra_tsensor tegra210_tsensors[] = {
  116. {
  117. .name = "cpu0",
  118. .base = 0xc0,
  119. .config = &tegra210_tsensor_config,
  120. .calib_fuse_offset = 0x098,
  121. .fuse_corr_alpha = 1085000,
  122. .fuse_corr_beta = 3244200,
  123. .group = &tegra210_tsensor_group_cpu,
  124. }, {
  125. .name = "cpu1",
  126. .base = 0xe0,
  127. .config = &tegra210_tsensor_config,
  128. .calib_fuse_offset = 0x084,
  129. .fuse_corr_alpha = 1126200,
  130. .fuse_corr_beta = -67500,
  131. .group = &tegra210_tsensor_group_cpu,
  132. }, {
  133. .name = "cpu2",
  134. .base = 0x100,
  135. .config = &tegra210_tsensor_config,
  136. .calib_fuse_offset = 0x088,
  137. .fuse_corr_alpha = 1098400,
  138. .fuse_corr_beta = 2251100,
  139. .group = &tegra210_tsensor_group_cpu,
  140. }, {
  141. .name = "cpu3",
  142. .base = 0x120,
  143. .config = &tegra210_tsensor_config,
  144. .calib_fuse_offset = 0x12c,
  145. .fuse_corr_alpha = 1108000,
  146. .fuse_corr_beta = 602700,
  147. .group = &tegra210_tsensor_group_cpu,
  148. }, {
  149. .name = "mem0",
  150. .base = 0x140,
  151. .config = &tegra210_tsensor_config,
  152. .calib_fuse_offset = 0x158,
  153. .fuse_corr_alpha = 1069200,
  154. .fuse_corr_beta = 3549900,
  155. .group = &tegra210_tsensor_group_mem,
  156. }, {
  157. .name = "mem1",
  158. .base = 0x160,
  159. .config = &tegra210_tsensor_config,
  160. .calib_fuse_offset = 0x15c,
  161. .fuse_corr_alpha = 1173700,
  162. .fuse_corr_beta = -6263600,
  163. .group = &tegra210_tsensor_group_mem,
  164. }, {
  165. .name = "gpu",
  166. .base = 0x180,
  167. .config = &tegra210_tsensor_config,
  168. .calib_fuse_offset = 0x154,
  169. .fuse_corr_alpha = 1074300,
  170. .fuse_corr_beta = 2734900,
  171. .group = &tegra210_tsensor_group_gpu,
  172. }, {
  173. .name = "pllx",
  174. .base = 0x1a0,
  175. .config = &tegra210_tsensor_config,
  176. .calib_fuse_offset = 0x160,
  177. .fuse_corr_alpha = 1039700,
  178. .fuse_corr_beta = 6829100,
  179. .group = &tegra210_tsensor_group_pll,
  180. },
  181. };
  182. /*
  183. * Mask/shift bits in FUSE_TSENSOR_COMMON and
  184. * FUSE_TSENSOR_COMMON, which are described in
  185. * tegra_soctherm_fuse.c
  186. */
  187. static const struct tegra_soctherm_fuse tegra210_soctherm_fuse = {
  188. .fuse_base_cp_mask = 0x3ff << 11,
  189. .fuse_base_cp_shift = 11,
  190. .fuse_base_ft_mask = 0x7ff << 21,
  191. .fuse_base_ft_shift = 21,
  192. .fuse_shift_ft_mask = 0x1f << 6,
  193. .fuse_shift_ft_shift = 6,
  194. .fuse_spare_realignment = 0,
  195. };
  196. static struct tsensor_group_thermtrips tegra210_tsensor_thermtrips[] = {
  197. {.id = TEGRA124_SOCTHERM_SENSOR_NUM},
  198. {.id = TEGRA124_SOCTHERM_SENSOR_NUM},
  199. {.id = TEGRA124_SOCTHERM_SENSOR_NUM},
  200. {.id = TEGRA124_SOCTHERM_SENSOR_NUM},
  201. };
  202. const struct tegra_soctherm_soc tegra210_soctherm = {
  203. .tsensors = tegra210_tsensors,
  204. .num_tsensors = ARRAY_SIZE(tegra210_tsensors),
  205. .ttgs = tegra210_tsensor_groups,
  206. .num_ttgs = ARRAY_SIZE(tegra210_tsensor_groups),
  207. .tfuse = &tegra210_soctherm_fuse,
  208. .thresh_grain = TEGRA210_THRESH_GRAIN,
  209. .bptt = TEGRA210_BPTT,
  210. .use_ccroc = false,
  211. .thermtrips = tegra210_tsensor_thermtrips,
  212. };