omap5-thermal-data.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. * OMAP5 thermal driver.
  3. *
  4. * Copyright (C) 2011-2012 Texas Instruments Inc.
  5. * Contact:
  6. * Eduardo Valentin <eduardo.valentin@ti.com>
  7. *
  8. * This software is licensed under the terms of the GNU General Public
  9. * License version 2, as published by the Free Software Foundation, and
  10. * may be copied, distributed, and modified under those terms.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #include "ti-thermal.h"
  19. #include "ti-bandgap.h"
  20. #include "omap5xxx-bandgap.h"
  21. /*
  22. * OMAP5430 has three instances of thermal sensor for MPU, GPU & CORE,
  23. * need to describe the individual registers and bit fields.
  24. */
  25. /*
  26. * OMAP5430 MPU thermal sensor register offset and bit-fields
  27. */
  28. static struct temp_sensor_registers
  29. omap5430_mpu_temp_sensor_registers = {
  30. .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_MPU_OFFSET,
  31. .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
  32. .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
  33. .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
  34. .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
  35. .mask_hot_mask = OMAP5430_MASK_HOT_MPU_MASK,
  36. .mask_cold_mask = OMAP5430_MASK_COLD_MPU_MASK,
  37. .mask_sidlemode_mask = OMAP5430_MASK_SIDLEMODE_MASK,
  38. .mask_counter_delay_mask = OMAP5430_MASK_COUNTER_DELAY_MASK,
  39. .mask_freeze_mask = OMAP5430_MASK_FREEZE_MPU_MASK,
  40. .mask_clear_mask = OMAP5430_MASK_CLEAR_MPU_MASK,
  41. .mask_clear_accum_mask = OMAP5430_MASK_CLEAR_ACCUM_MPU_MASK,
  42. .bgap_counter = OMAP5430_BGAP_CTRL_OFFSET,
  43. .counter_mask = OMAP5430_COUNTER_MASK,
  44. .bgap_threshold = OMAP5430_BGAP_THRESHOLD_MPU_OFFSET,
  45. .threshold_thot_mask = OMAP5430_T_HOT_MASK,
  46. .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
  47. .tshut_threshold = OMAP5430_BGAP_TSHUT_MPU_OFFSET,
  48. .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
  49. .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
  50. .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
  51. .status_clean_stop_mask = 0x0,
  52. .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
  53. .status_hot_mask = OMAP5430_HOT_MPU_FLAG_MASK,
  54. .status_cold_mask = OMAP5430_COLD_MPU_FLAG_MASK,
  55. .bgap_cumul_dtemp = OMAP5430_BGAP_CUMUL_DTEMP_MPU_OFFSET,
  56. .ctrl_dtemp_0 = OMAP5430_BGAP_DTEMP_MPU_0_OFFSET,
  57. .ctrl_dtemp_1 = OMAP5430_BGAP_DTEMP_MPU_1_OFFSET,
  58. .ctrl_dtemp_2 = OMAP5430_BGAP_DTEMP_MPU_2_OFFSET,
  59. .ctrl_dtemp_3 = OMAP5430_BGAP_DTEMP_MPU_3_OFFSET,
  60. .ctrl_dtemp_4 = OMAP5430_BGAP_DTEMP_MPU_4_OFFSET,
  61. .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_MPU,
  62. };
  63. /*
  64. * OMAP5430 GPU thermal sensor register offset and bit-fields
  65. */
  66. static struct temp_sensor_registers
  67. omap5430_gpu_temp_sensor_registers = {
  68. .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_GPU_OFFSET,
  69. .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
  70. .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
  71. .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
  72. .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
  73. .mask_hot_mask = OMAP5430_MASK_HOT_GPU_MASK,
  74. .mask_cold_mask = OMAP5430_MASK_COLD_GPU_MASK,
  75. .mask_sidlemode_mask = OMAP5430_MASK_SIDLEMODE_MASK,
  76. .mask_counter_delay_mask = OMAP5430_MASK_COUNTER_DELAY_MASK,
  77. .mask_freeze_mask = OMAP5430_MASK_FREEZE_GPU_MASK,
  78. .mask_clear_mask = OMAP5430_MASK_CLEAR_GPU_MASK,
  79. .mask_clear_accum_mask = OMAP5430_MASK_CLEAR_ACCUM_GPU_MASK,
  80. .bgap_counter = OMAP5430_BGAP_CTRL_OFFSET,
  81. .counter_mask = OMAP5430_COUNTER_MASK,
  82. .bgap_threshold = OMAP5430_BGAP_THRESHOLD_GPU_OFFSET,
  83. .threshold_thot_mask = OMAP5430_T_HOT_MASK,
  84. .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
  85. .tshut_threshold = OMAP5430_BGAP_TSHUT_GPU_OFFSET,
  86. .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
  87. .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
  88. .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
  89. .status_clean_stop_mask = 0x0,
  90. .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
  91. .status_hot_mask = OMAP5430_HOT_GPU_FLAG_MASK,
  92. .status_cold_mask = OMAP5430_COLD_GPU_FLAG_MASK,
  93. .bgap_cumul_dtemp = OMAP5430_BGAP_CUMUL_DTEMP_GPU_OFFSET,
  94. .ctrl_dtemp_0 = OMAP5430_BGAP_DTEMP_GPU_0_OFFSET,
  95. .ctrl_dtemp_1 = OMAP5430_BGAP_DTEMP_GPU_1_OFFSET,
  96. .ctrl_dtemp_2 = OMAP5430_BGAP_DTEMP_GPU_2_OFFSET,
  97. .ctrl_dtemp_3 = OMAP5430_BGAP_DTEMP_GPU_3_OFFSET,
  98. .ctrl_dtemp_4 = OMAP5430_BGAP_DTEMP_GPU_4_OFFSET,
  99. .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_GPU,
  100. };
  101. /*
  102. * OMAP5430 CORE thermal sensor register offset and bit-fields
  103. */
  104. static struct temp_sensor_registers
  105. omap5430_core_temp_sensor_registers = {
  106. .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_CORE_OFFSET,
  107. .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
  108. .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
  109. .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
  110. .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
  111. .mask_hot_mask = OMAP5430_MASK_HOT_CORE_MASK,
  112. .mask_cold_mask = OMAP5430_MASK_COLD_CORE_MASK,
  113. .mask_sidlemode_mask = OMAP5430_MASK_SIDLEMODE_MASK,
  114. .mask_counter_delay_mask = OMAP5430_MASK_COUNTER_DELAY_MASK,
  115. .mask_freeze_mask = OMAP5430_MASK_FREEZE_CORE_MASK,
  116. .mask_clear_mask = OMAP5430_MASK_CLEAR_CORE_MASK,
  117. .mask_clear_accum_mask = OMAP5430_MASK_CLEAR_ACCUM_CORE_MASK,
  118. .bgap_counter = OMAP5430_BGAP_CTRL_OFFSET,
  119. .counter_mask = OMAP5430_COUNTER_MASK,
  120. .bgap_threshold = OMAP5430_BGAP_THRESHOLD_CORE_OFFSET,
  121. .threshold_thot_mask = OMAP5430_T_HOT_MASK,
  122. .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
  123. .tshut_threshold = OMAP5430_BGAP_TSHUT_CORE_OFFSET,
  124. .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
  125. .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
  126. .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
  127. .status_clean_stop_mask = 0x0,
  128. .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
  129. .status_hot_mask = OMAP5430_HOT_CORE_FLAG_MASK,
  130. .status_cold_mask = OMAP5430_COLD_CORE_FLAG_MASK,
  131. .bgap_cumul_dtemp = OMAP5430_BGAP_CUMUL_DTEMP_CORE_OFFSET,
  132. .ctrl_dtemp_0 = OMAP5430_BGAP_DTEMP_CORE_0_OFFSET,
  133. .ctrl_dtemp_1 = OMAP5430_BGAP_DTEMP_CORE_1_OFFSET,
  134. .ctrl_dtemp_2 = OMAP5430_BGAP_DTEMP_CORE_2_OFFSET,
  135. .ctrl_dtemp_3 = OMAP5430_BGAP_DTEMP_CORE_3_OFFSET,
  136. .ctrl_dtemp_4 = OMAP5430_BGAP_DTEMP_CORE_4_OFFSET,
  137. .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_CORE,
  138. };
  139. /* Thresholds and limits for OMAP5430 MPU temperature sensor */
  140. static struct temp_sensor_data omap5430_mpu_temp_sensor_data = {
  141. .tshut_hot = OMAP5430_MPU_TSHUT_HOT,
  142. .tshut_cold = OMAP5430_MPU_TSHUT_COLD,
  143. .t_hot = OMAP5430_MPU_T_HOT,
  144. .t_cold = OMAP5430_MPU_T_COLD,
  145. .min_freq = OMAP5430_MPU_MIN_FREQ,
  146. .max_freq = OMAP5430_MPU_MAX_FREQ,
  147. .max_temp = OMAP5430_MPU_MAX_TEMP,
  148. .min_temp = OMAP5430_MPU_MIN_TEMP,
  149. .hyst_val = OMAP5430_MPU_HYST_VAL,
  150. .update_int1 = 1000,
  151. .update_int2 = 2000,
  152. };
  153. /* Thresholds and limits for OMAP5430 GPU temperature sensor */
  154. static struct temp_sensor_data omap5430_gpu_temp_sensor_data = {
  155. .tshut_hot = OMAP5430_GPU_TSHUT_HOT,
  156. .tshut_cold = OMAP5430_GPU_TSHUT_COLD,
  157. .t_hot = OMAP5430_GPU_T_HOT,
  158. .t_cold = OMAP5430_GPU_T_COLD,
  159. .min_freq = OMAP5430_GPU_MIN_FREQ,
  160. .max_freq = OMAP5430_GPU_MAX_FREQ,
  161. .max_temp = OMAP5430_GPU_MAX_TEMP,
  162. .min_temp = OMAP5430_GPU_MIN_TEMP,
  163. .hyst_val = OMAP5430_GPU_HYST_VAL,
  164. .update_int1 = 1000,
  165. .update_int2 = 2000,
  166. };
  167. /* Thresholds and limits for OMAP5430 CORE temperature sensor */
  168. static struct temp_sensor_data omap5430_core_temp_sensor_data = {
  169. .tshut_hot = OMAP5430_CORE_TSHUT_HOT,
  170. .tshut_cold = OMAP5430_CORE_TSHUT_COLD,
  171. .t_hot = OMAP5430_CORE_T_HOT,
  172. .t_cold = OMAP5430_CORE_T_COLD,
  173. .min_freq = OMAP5430_CORE_MIN_FREQ,
  174. .max_freq = OMAP5430_CORE_MAX_FREQ,
  175. .max_temp = OMAP5430_CORE_MAX_TEMP,
  176. .min_temp = OMAP5430_CORE_MIN_TEMP,
  177. .hyst_val = OMAP5430_CORE_HYST_VAL,
  178. .update_int1 = 1000,
  179. .update_int2 = 2000,
  180. };
  181. /*
  182. * OMAP54xx ES2.0 : Temperature values in milli degree celsius
  183. * ADC code values from 540 to 945
  184. */
  185. static int
  186. omap5430_adc_to_temp[
  187. OMAP5430_ADC_END_VALUE - OMAP5430_ADC_START_VALUE + 1] = {
  188. /* Index 540 - 549 */
  189. -40000, -40000, -40000, -40000, -39800, -39400, -39000, -38600, -38200,
  190. -37800,
  191. /* Index 550 - 559 */
  192. -37400, -37000, -36600, -36200, -35800, -35300, -34700, -34200, -33800,
  193. -33400,
  194. /* Index 560 - 569 */
  195. -33000, -32600, -32200, -31800, -31400, -31000, -30600, -30200, -29800,
  196. -29400,
  197. /* Index 570 - 579 */
  198. -29000, -28600, -28200, -27700, -27100, -26600, -26200, -25800, -25400,
  199. -25000,
  200. /* Index 580 - 589 */
  201. -24600, -24200, -23800, -23400, -23000, -22600, -22200, -21600, -21400,
  202. -21000,
  203. /* Index 590 - 599 */
  204. -20500, -19900, -19400, -19000, -18600, -18200, -17800, -17400, -17000,
  205. -16600,
  206. /* Index 600 - 609 */
  207. -16200, -15800, -15400, -15000, -14600, -14200, -13800, -13400, -13000,
  208. -12500,
  209. /* Index 610 - 619 */
  210. -11900, -11400, -11000, -10600, -10200, -9800, -9400, -9000, -8600,
  211. -8200,
  212. /* Index 620 - 629 */
  213. -7800, -7400, -7000, -6600, -6200, -5800, -5400, -5000, -4500, -3900,
  214. /* Index 630 - 639 */
  215. -3400, -3000, -2600, -2200, -1800, -1400, -1000, -600, -200, 200,
  216. /* Index 640 - 649 */
  217. 600, 1000, 1400, 1800, 2200, 2600, 3000, 3400, 3900, 4500,
  218. /* Index 650 - 659 */
  219. 5000, 5400, 5800, 6200, 6600, 7000, 7400, 7800, 8200, 8600,
  220. /* Index 660 - 669 */
  221. 9000, 9400, 9800, 10200, 10600, 11000, 11400, 11800, 12200, 12700,
  222. /* Index 670 - 679 */
  223. 13300, 13800, 14200, 14600, 15000, 15400, 15800, 16200, 16600, 17000,
  224. /* Index 680 - 689 */
  225. 17400, 17800, 18200, 18600, 19000, 19400, 19800, 20200, 20600, 21100,
  226. /* Index 690 - 699 */
  227. 21400, 21900, 22500, 23000, 23400, 23800, 24200, 24600, 25000, 25400,
  228. /* Index 700 - 709 */
  229. 25800, 26200, 26600, 27000, 27400, 27800, 28200, 28600, 29000, 29400,
  230. /* Index 710 - 719 */
  231. 29800, 30200, 30600, 31000, 31400, 31900, 32500, 33000, 33400, 33800,
  232. /* Index 720 - 729 */
  233. 34200, 34600, 35000, 35400, 35800, 36200, 36600, 37000, 37400, 37800,
  234. /* Index 730 - 739 */
  235. 38200, 38600, 39000, 39400, 39800, 40200, 40600, 41000, 41400, 41800,
  236. /* Index 740 - 749 */
  237. 42200, 42600, 43100, 43700, 44200, 44600, 45000, 45400, 45800, 46200,
  238. /* Index 750 - 759 */
  239. 46600, 47000, 47400, 47800, 48200, 48600, 49000, 49400, 49800, 50200,
  240. /* Index 760 - 769 */
  241. 50600, 51000, 51400, 51800, 52200, 52600, 53000, 53400, 53800, 54200,
  242. /* Index 770 - 779 */
  243. 54600, 55000, 55400, 55900, 56500, 57000, 57400, 57800, 58200, 58600,
  244. /* Index 780 - 789 */
  245. 59000, 59400, 59800, 60200, 60600, 61000, 61400, 61800, 62200, 62600,
  246. /* Index 790 - 799 */
  247. 63000, 63400, 63800, 64200, 64600, 65000, 65400, 65800, 66200, 66600,
  248. /* Index 800 - 809 */
  249. 67000, 67400, 67800, 68200, 68600, 69000, 69400, 69800, 70200, 70600,
  250. /* Index 810 - 819 */
  251. 71000, 71500, 72100, 72600, 73000, 73400, 73800, 74200, 74600, 75000,
  252. /* Index 820 - 829 */
  253. 75400, 75800, 76200, 76600, 77000, 77400, 77800, 78200, 78600, 79000,
  254. /* Index 830 - 839 */
  255. 79400, 79800, 80200, 80600, 81000, 81400, 81800, 82200, 82600, 83000,
  256. /* Index 840 - 849 */
  257. 83400, 83800, 84200, 84600, 85000, 85400, 85800, 86200, 86600, 87000,
  258. /* Index 850 - 859 */
  259. 87400, 87800, 88200, 88600, 89000, 89400, 89800, 90200, 90600, 91000,
  260. /* Index 860 - 869 */
  261. 91400, 91800, 92200, 92600, 93000, 93400, 93800, 94200, 94600, 95000,
  262. /* Index 870 - 879 */
  263. 95400, 95800, 96200, 96600, 97000, 97500, 98100, 98600, 99000, 99400,
  264. /* Index 880 - 889 */
  265. 99800, 100200, 100600, 101000, 101400, 101800, 102200, 102600, 103000,
  266. 103400,
  267. /* Index 890 - 899 */
  268. 103800, 104200, 104600, 105000, 105400, 105800, 106200, 106600, 107000,
  269. 107400,
  270. /* Index 900 - 909 */
  271. 107800, 108200, 108600, 109000, 109400, 109800, 110200, 110600, 111000,
  272. 111400,
  273. /* Index 910 - 919 */
  274. 111800, 112200, 112600, 113000, 113400, 113800, 114200, 114600, 115000,
  275. 115400,
  276. /* Index 920 - 929 */
  277. 115800, 116200, 116600, 117000, 117400, 117800, 118200, 118600, 119000,
  278. 119400,
  279. /* Index 930 - 939 */
  280. 119800, 120200, 120600, 121000, 121400, 121800, 122400, 122600, 123000,
  281. 123400,
  282. /* Index 940 - 945 */
  283. 123800, 1242000, 124600, 124900, 125000, 125000,
  284. };
  285. /* OMAP54xx ES2.0 data */
  286. const struct ti_bandgap_data omap5430_data = {
  287. .features = TI_BANDGAP_FEATURE_TSHUT_CONFIG |
  288. TI_BANDGAP_FEATURE_FREEZE_BIT |
  289. TI_BANDGAP_FEATURE_TALERT |
  290. TI_BANDGAP_FEATURE_COUNTER_DELAY |
  291. TI_BANDGAP_FEATURE_HISTORY_BUFFER |
  292. TI_BANDGAP_FEATURE_ERRATA_813,
  293. .fclock_name = "l3instr_ts_gclk_div",
  294. .div_ck_name = "l3instr_ts_gclk_div",
  295. .conv_table = omap5430_adc_to_temp,
  296. .adc_start_val = OMAP5430_ADC_START_VALUE,
  297. .adc_end_val = OMAP5430_ADC_END_VALUE,
  298. .expose_sensor = ti_thermal_expose_sensor,
  299. .remove_sensor = ti_thermal_remove_sensor,
  300. .report_temperature = ti_thermal_report_sensor_temperature,
  301. .sensors = {
  302. {
  303. .registers = &omap5430_mpu_temp_sensor_registers,
  304. .ts_data = &omap5430_mpu_temp_sensor_data,
  305. .domain = "cpu",
  306. .register_cooling = ti_thermal_register_cpu_cooling,
  307. .unregister_cooling = ti_thermal_unregister_cpu_cooling,
  308. .slope = OMAP_GRADIENT_SLOPE_5430_CPU,
  309. .constant = OMAP_GRADIENT_CONST_5430_CPU,
  310. .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_5430_CPU,
  311. .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_5430_CPU,
  312. },
  313. {
  314. .registers = &omap5430_gpu_temp_sensor_registers,
  315. .ts_data = &omap5430_gpu_temp_sensor_data,
  316. .domain = "gpu",
  317. .slope = OMAP_GRADIENT_SLOPE_5430_GPU,
  318. .constant = OMAP_GRADIENT_CONST_5430_GPU,
  319. .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_5430_GPU,
  320. .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_5430_GPU,
  321. },
  322. {
  323. .registers = &omap5430_core_temp_sensor_registers,
  324. .ts_data = &omap5430_core_temp_sensor_data,
  325. .domain = "core",
  326. },
  327. },
  328. .sensor_count = 3,
  329. };