tegra210-soctherm.c 6.8 KB

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