tegra124-soctherm.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <dt-bindings/thermal/tegra124-soctherm.h>
  17. #include "soctherm.h"
  18. #define TEGRA124_THERMTRIP_ANY_EN_MASK (0x1 << 28)
  19. #define TEGRA124_THERMTRIP_MEM_EN_MASK (0x1 << 27)
  20. #define TEGRA124_THERMTRIP_GPU_EN_MASK (0x1 << 26)
  21. #define TEGRA124_THERMTRIP_CPU_EN_MASK (0x1 << 25)
  22. #define TEGRA124_THERMTRIP_TSENSE_EN_MASK (0x1 << 24)
  23. #define TEGRA124_THERMTRIP_GPUMEM_THRESH_MASK (0xff << 16)
  24. #define TEGRA124_THERMTRIP_CPU_THRESH_MASK (0xff << 8)
  25. #define TEGRA124_THERMTRIP_TSENSE_THRESH_MASK 0xff
  26. #define TEGRA124_THERMCTL_LVL0_UP_THRESH_MASK (0xff << 17)
  27. #define TEGRA124_THERMCTL_LVL0_DN_THRESH_MASK (0xff << 9)
  28. #define TEGRA124_THRESH_GRAIN 1000
  29. #define TEGRA124_BPTT 8
  30. static const struct tegra_tsensor_configuration tegra124_tsensor_config = {
  31. .tall = 16300,
  32. .tiddq_en = 1,
  33. .ten_count = 1,
  34. .tsample = 120,
  35. .tsample_ate = 480,
  36. };
  37. static const struct tegra_tsensor_group tegra124_tsensor_group_cpu = {
  38. .id = TEGRA124_SOCTHERM_SENSOR_CPU,
  39. .name = "cpu",
  40. .sensor_temp_offset = SENSOR_TEMP1,
  41. .sensor_temp_mask = SENSOR_TEMP1_CPU_TEMP_MASK,
  42. .pdiv = 8,
  43. .pdiv_ate = 8,
  44. .pdiv_mask = SENSOR_PDIV_CPU_MASK,
  45. .pllx_hotspot_diff = 10,
  46. .pllx_hotspot_mask = SENSOR_HOTSPOT_CPU_MASK,
  47. .thermtrip_any_en_mask = TEGRA124_THERMTRIP_ANY_EN_MASK,
  48. .thermtrip_enable_mask = TEGRA124_THERMTRIP_CPU_EN_MASK,
  49. .thermtrip_threshold_mask = TEGRA124_THERMTRIP_CPU_THRESH_MASK,
  50. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_CPU,
  51. .thermctl_lvl0_up_thresh_mask = TEGRA124_THERMCTL_LVL0_UP_THRESH_MASK,
  52. .thermctl_lvl0_dn_thresh_mask = TEGRA124_THERMCTL_LVL0_DN_THRESH_MASK,
  53. };
  54. static const struct tegra_tsensor_group tegra124_tsensor_group_gpu = {
  55. .id = TEGRA124_SOCTHERM_SENSOR_GPU,
  56. .name = "gpu",
  57. .sensor_temp_offset = SENSOR_TEMP1,
  58. .sensor_temp_mask = SENSOR_TEMP1_GPU_TEMP_MASK,
  59. .pdiv = 8,
  60. .pdiv_ate = 8,
  61. .pdiv_mask = SENSOR_PDIV_GPU_MASK,
  62. .pllx_hotspot_diff = 5,
  63. .pllx_hotspot_mask = SENSOR_HOTSPOT_GPU_MASK,
  64. .thermtrip_any_en_mask = TEGRA124_THERMTRIP_ANY_EN_MASK,
  65. .thermtrip_enable_mask = TEGRA124_THERMTRIP_GPU_EN_MASK,
  66. .thermtrip_threshold_mask = TEGRA124_THERMTRIP_GPUMEM_THRESH_MASK,
  67. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_GPU,
  68. .thermctl_lvl0_up_thresh_mask = TEGRA124_THERMCTL_LVL0_UP_THRESH_MASK,
  69. .thermctl_lvl0_dn_thresh_mask = TEGRA124_THERMCTL_LVL0_DN_THRESH_MASK,
  70. };
  71. static const struct tegra_tsensor_group tegra124_tsensor_group_pll = {
  72. .id = TEGRA124_SOCTHERM_SENSOR_PLLX,
  73. .name = "pll",
  74. .sensor_temp_offset = SENSOR_TEMP2,
  75. .sensor_temp_mask = SENSOR_TEMP2_PLLX_TEMP_MASK,
  76. .pdiv = 8,
  77. .pdiv_ate = 8,
  78. .pdiv_mask = SENSOR_PDIV_PLLX_MASK,
  79. .thermtrip_any_en_mask = TEGRA124_THERMTRIP_ANY_EN_MASK,
  80. .thermtrip_enable_mask = TEGRA124_THERMTRIP_TSENSE_EN_MASK,
  81. .thermtrip_threshold_mask = TEGRA124_THERMTRIP_TSENSE_THRESH_MASK,
  82. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_TSENSE,
  83. .thermctl_lvl0_up_thresh_mask = TEGRA124_THERMCTL_LVL0_UP_THRESH_MASK,
  84. .thermctl_lvl0_dn_thresh_mask = TEGRA124_THERMCTL_LVL0_DN_THRESH_MASK,
  85. };
  86. static const struct tegra_tsensor_group tegra124_tsensor_group_mem = {
  87. .id = TEGRA124_SOCTHERM_SENSOR_MEM,
  88. .name = "mem",
  89. .sensor_temp_offset = SENSOR_TEMP2,
  90. .sensor_temp_mask = SENSOR_TEMP2_MEM_TEMP_MASK,
  91. .pdiv = 8,
  92. .pdiv_ate = 8,
  93. .pdiv_mask = SENSOR_PDIV_MEM_MASK,
  94. .pllx_hotspot_diff = 0,
  95. .pllx_hotspot_mask = SENSOR_HOTSPOT_MEM_MASK,
  96. .thermtrip_any_en_mask = TEGRA124_THERMTRIP_ANY_EN_MASK,
  97. .thermtrip_enable_mask = TEGRA124_THERMTRIP_MEM_EN_MASK,
  98. .thermtrip_threshold_mask = TEGRA124_THERMTRIP_GPUMEM_THRESH_MASK,
  99. .thermctl_lvl0_offset = THERMCTL_LEVEL0_GROUP_MEM,
  100. .thermctl_lvl0_up_thresh_mask = TEGRA124_THERMCTL_LVL0_UP_THRESH_MASK,
  101. .thermctl_lvl0_dn_thresh_mask = TEGRA124_THERMCTL_LVL0_DN_THRESH_MASK,
  102. };
  103. static const struct tegra_tsensor_group *tegra124_tsensor_groups[] = {
  104. &tegra124_tsensor_group_cpu,
  105. &tegra124_tsensor_group_gpu,
  106. &tegra124_tsensor_group_pll,
  107. &tegra124_tsensor_group_mem,
  108. };
  109. static const struct tegra_tsensor tegra124_tsensors[] = {
  110. {
  111. .name = "cpu0",
  112. .base = 0xc0,
  113. .config = &tegra124_tsensor_config,
  114. .calib_fuse_offset = 0x098,
  115. .fuse_corr_alpha = 1135400,
  116. .fuse_corr_beta = -6266900,
  117. .group = &tegra124_tsensor_group_cpu,
  118. }, {
  119. .name = "cpu1",
  120. .base = 0xe0,
  121. .config = &tegra124_tsensor_config,
  122. .calib_fuse_offset = 0x084,
  123. .fuse_corr_alpha = 1122220,
  124. .fuse_corr_beta = -5700700,
  125. .group = &tegra124_tsensor_group_cpu,
  126. }, {
  127. .name = "cpu2",
  128. .base = 0x100,
  129. .config = &tegra124_tsensor_config,
  130. .calib_fuse_offset = 0x088,
  131. .fuse_corr_alpha = 1127000,
  132. .fuse_corr_beta = -6768200,
  133. .group = &tegra124_tsensor_group_cpu,
  134. }, {
  135. .name = "cpu3",
  136. .base = 0x120,
  137. .config = &tegra124_tsensor_config,
  138. .calib_fuse_offset = 0x12c,
  139. .fuse_corr_alpha = 1110900,
  140. .fuse_corr_beta = -6232000,
  141. .group = &tegra124_tsensor_group_cpu,
  142. }, {
  143. .name = "mem0",
  144. .base = 0x140,
  145. .config = &tegra124_tsensor_config,
  146. .calib_fuse_offset = 0x158,
  147. .fuse_corr_alpha = 1122300,
  148. .fuse_corr_beta = -5936400,
  149. .group = &tegra124_tsensor_group_mem,
  150. }, {
  151. .name = "mem1",
  152. .base = 0x160,
  153. .config = &tegra124_tsensor_config,
  154. .calib_fuse_offset = 0x15c,
  155. .fuse_corr_alpha = 1145700,
  156. .fuse_corr_beta = -7124600,
  157. .group = &tegra124_tsensor_group_mem,
  158. }, {
  159. .name = "gpu",
  160. .base = 0x180,
  161. .config = &tegra124_tsensor_config,
  162. .calib_fuse_offset = 0x154,
  163. .fuse_corr_alpha = 1120100,
  164. .fuse_corr_beta = -6000500,
  165. .group = &tegra124_tsensor_group_gpu,
  166. }, {
  167. .name = "pllx",
  168. .base = 0x1a0,
  169. .config = &tegra124_tsensor_config,
  170. .calib_fuse_offset = 0x160,
  171. .fuse_corr_alpha = 1106500,
  172. .fuse_corr_beta = -6729300,
  173. .group = &tegra124_tsensor_group_pll,
  174. },
  175. };
  176. /*
  177. * Mask/shift bits in FUSE_TSENSOR_COMMON and
  178. * FUSE_TSENSOR_COMMON, which are described in
  179. * tegra_soctherm_fuse.c
  180. */
  181. static const struct tegra_soctherm_fuse tegra124_soctherm_fuse = {
  182. .fuse_base_cp_mask = 0x3ff,
  183. .fuse_base_cp_shift = 0,
  184. .fuse_base_ft_mask = 0x7ff << 10,
  185. .fuse_base_ft_shift = 10,
  186. .fuse_shift_ft_mask = 0x1f << 21,
  187. .fuse_shift_ft_shift = 21,
  188. .fuse_spare_realignment = 0x1fc,
  189. };
  190. const struct tegra_soctherm_soc tegra124_soctherm = {
  191. .tsensors = tegra124_tsensors,
  192. .num_tsensors = ARRAY_SIZE(tegra124_tsensors),
  193. .ttgs = tegra124_tsensor_groups,
  194. .num_ttgs = ARRAY_SIZE(tegra124_tsensor_groups),
  195. .tfuse = &tegra124_soctherm_fuse,
  196. .thresh_grain = TEGRA124_THRESH_GRAIN,
  197. .bptt = TEGRA124_BPTT,
  198. .use_ccroc = false,
  199. };