ti-bandgap.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * TI Bandgap temperature sensor driver
  3. *
  4. * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * Taken from Linux v4.9 (drivers/thermal/ti-soc-thermal/ti-bandgap.c)
  16. * and ported to uboot.
  17. *
  18. */
  19. #include <asm/io.h>
  20. #include <dm.h>
  21. #include <thermal.h>
  22. #define CTRL_CORE_TEMP_SENSOR_MPU 0
  23. #define DRA752_ADC_START_VALUE 540
  24. struct ti_bandgap {
  25. ulong base;
  26. uint adc_val;
  27. };
  28. /*
  29. * DRA752 : Temperature values in milli degree celsius
  30. * ADC code values from 540 to 945
  31. */
  32. static int dra752_adc_to_temp[] = {
  33. /* Index 540 - 549 */
  34. -40000, -40000, -40000, -40000, -39800, -39400, -39000, -38600, -38200,
  35. -37800,
  36. /* Index 550 - 559 */
  37. -37400, -37000, -36600, -36200, -35800, -35300, -34700, -34200, -33800,
  38. -33400,
  39. /* Index 560 - 569 */
  40. -33000, -32600, -32200, -31800, -31400, -31000, -30600, -30200, -29800,
  41. -29400,
  42. /* Index 570 - 579 */
  43. -29000, -28600, -28200, -27700, -27100, -26600, -26200, -25800, -25400,
  44. -25000,
  45. /* Index 580 - 589 */
  46. -24600, -24200, -23800, -23400, -23000, -22600, -22200, -21800, -21400,
  47. -21000,
  48. /* Index 590 - 599 */
  49. -20500, -19900, -19400, -19000, -18600, -18200, -17800, -17400, -17000,
  50. -16600,
  51. /* Index 600 - 609 */
  52. -16200, -15800, -15400, -15000, -14600, -14200, -13800, -13400, -13000,
  53. -12500,
  54. /* Index 610 - 619 */
  55. -11900, -11400, -11000, -10600, -10200, -9800, -9400, -9000, -8600,
  56. -8200,
  57. /* Index 620 - 629 */
  58. -7800, -7400, -7000, -6600, -6200, -5800, -5400, -5000, -4500,
  59. -3900,
  60. /* Index 630 - 639 */
  61. -3400, -3000, -2600, -2200, -1800, -1400, -1000, -600, -200,
  62. 200,
  63. /* Index 640 - 649 */
  64. 600, 1000, 1400, 1800, 2200, 2600, 3000, 3400, 3900,
  65. 4500,
  66. /* Index 650 - 659 */
  67. 5000, 5400, 5800, 6200, 6600, 7000, 7400, 7800, 8200,
  68. 8600,
  69. /* Index 660 - 669 */
  70. 9000, 9400, 9800, 10200, 10600, 11000, 11400, 11800, 12200,
  71. 12700,
  72. /* Index 670 - 679 */
  73. 13300, 13800, 14200, 14600, 15000, 15400, 15800, 16200, 16600,
  74. 17000,
  75. /* Index 680 - 689 */
  76. 17400, 17800, 18200, 18600, 19000, 19400, 19800, 20200, 20600,
  77. 21000,
  78. /* Index 690 - 699 */
  79. 21400, 21900, 22500, 23000, 23400, 23800, 24200, 24600, 25000,
  80. 25400,
  81. /* Index 700 - 709 */
  82. 25800, 26200, 26600, 27000, 27400, 27800, 28200, 28600, 29000,
  83. 29400,
  84. /* Index 710 - 719 */
  85. 29800, 30200, 30600, 31000, 31400, 31900, 32500, 33000, 33400,
  86. 33800,
  87. /* Index 720 - 729 */
  88. 34200, 34600, 35000, 35400, 35800, 36200, 36600, 37000, 37400,
  89. 37800,
  90. /* Index 730 - 739 */
  91. 38200, 38600, 39000, 39400, 39800, 40200, 40600, 41000, 41400,
  92. 41800,
  93. /* Index 740 - 749 */
  94. 42200, 42600, 43100, 43700, 44200, 44600, 45000, 45400, 45800,
  95. 46200,
  96. /* Index 750 - 759 */
  97. 46600, 47000, 47400, 47800, 48200, 48600, 49000, 49400, 49800,
  98. 50200,
  99. /* Index 760 - 769 */
  100. 50600, 51000, 51400, 51800, 52200, 52600, 53000, 53400, 53800,
  101. 54200,
  102. /* Index 770 - 779 */
  103. 54600, 55000, 55400, 55900, 56500, 57000, 57400, 57800, 58200,
  104. 58600,
  105. /* Index 780 - 789 */
  106. 59000, 59400, 59800, 60200, 60600, 61000, 61400, 61800, 62200,
  107. 62600,
  108. /* Index 790 - 799 */
  109. 63000, 63400, 63800, 64200, 64600, 65000, 65400, 65800, 66200,
  110. 66600,
  111. /* Index 800 - 809 */
  112. 67000, 67400, 67800, 68200, 68600, 69000, 69400, 69800, 70200,
  113. 70600,
  114. /* Index 810 - 819 */
  115. 71000, 71500, 72100, 72600, 73000, 73400, 73800, 74200, 74600,
  116. 75000,
  117. /* Index 820 - 829 */
  118. 75400, 75800, 76200, 76600, 77000, 77400, 77800, 78200, 78600,
  119. 79000,
  120. /* Index 830 - 839 */
  121. 79400, 79800, 80200, 80600, 81000, 81400, 81800, 82200, 82600,
  122. 83000,
  123. /* Index 840 - 849 */
  124. 83400, 83800, 84200, 84600, 85000, 85400, 85800, 86200, 86600,
  125. 87000,
  126. /* Index 850 - 859 */
  127. 87400, 87800, 88200, 88600, 89000, 89400, 89800, 90200, 90600,
  128. 91000,
  129. /* Index 860 - 869 */
  130. 91400, 91800, 92200, 92600, 93000, 93400, 93800, 94200, 94600,
  131. 95000,
  132. /* Index 870 - 879 */
  133. 95400, 95800, 96200, 96600, 97000, 97500, 98100, 98600, 99000,
  134. 99400,
  135. /* Index 880 - 889 */
  136. 99800, 100200, 100600, 101000, 101400, 101800, 102200, 102600, 103000,
  137. 103400,
  138. /* Index 890 - 899 */
  139. 103800, 104200, 104600, 105000, 105400, 105800, 106200, 106600, 107000,
  140. 107400,
  141. /* Index 900 - 909 */
  142. 107800, 108200, 108600, 109000, 109400, 109800, 110200, 110600, 111000,
  143. 111400,
  144. /* Index 910 - 919 */
  145. 111800, 112200, 112600, 113000, 113400, 113800, 114200, 114600, 115000,
  146. 115400,
  147. /* Index 920 - 929 */
  148. 115800, 116200, 116600, 117000, 117400, 117800, 118200, 118600, 119000,
  149. 119400,
  150. /* Index 930 - 939 */
  151. 119800, 120200, 120600, 121000, 121400, 121800, 122200, 122600, 123000,
  152. 123400,
  153. /* Index 940 - 945 */
  154. 123800, 124200, 124600, 124900, 125000, 125000,
  155. };
  156. static int ti_bandgap_get_temp(struct udevice *dev, int *temp)
  157. {
  158. struct ti_bandgap *bgp = dev_get_priv(dev);
  159. bgp->adc_val = 0x3ff & readl(bgp->base + CTRL_CORE_TEMP_SENSOR_MPU);
  160. *temp = dra752_adc_to_temp[bgp->adc_val - DRA752_ADC_START_VALUE];
  161. return 0;
  162. }
  163. static struct dm_thermal_ops ti_thermal_ops = {
  164. .get_temp = ti_bandgap_get_temp,
  165. };
  166. static int ti_bandgap_probe(struct udevice *dev)
  167. {
  168. struct ti_bandgap *bgp = dev_get_priv(dev);
  169. bgp->base = devfdt_get_addr_index(dev, 1);
  170. return 0;
  171. }
  172. static const struct udevice_id of_ti_bandgap_match[] = {
  173. {
  174. .compatible = "ti,dra752-bandgap",
  175. },
  176. {},
  177. };
  178. U_BOOT_DRIVER(ti_bandgap_thermal) = {
  179. .name = "ti_bandgap_thermal",
  180. .id = UCLASS_THERMAL,
  181. .ops = &ti_thermal_ops,
  182. .probe = ti_bandgap_probe,
  183. .of_match = of_ti_bandgap_match,
  184. .priv_auto = sizeof(struct ti_bandgap),
  185. };