nouveau_temp.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Copyright 2010 PathScale inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Martin Peres
  23. */
  24. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_pm.h"
  27. void
  28. nouveau_temp_vbios_parse(struct drm_device *dev, u8 *temp)
  29. {
  30. struct drm_nouveau_private *dev_priv = dev->dev_private;
  31. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  32. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  33. struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
  34. int i, headerlen, recordlen, entries;
  35. if (!temp) {
  36. NV_DEBUG(dev, "temperature table pointer invalid\n");
  37. return;
  38. }
  39. /* Set the default sensor's contants */
  40. sensor->offset_constant = 0;
  41. sensor->offset_mult = 1;
  42. sensor->offset_div = 1;
  43. sensor->slope_mult = 1;
  44. sensor->slope_div = 1;
  45. /* Set the default temperature thresholds */
  46. temps->critical = 110;
  47. temps->down_clock = 100;
  48. temps->fan_boost = 90;
  49. /* Set the known default values to setup the temperature sensor */
  50. if (dev_priv->card_type >= NV_40) {
  51. switch (dev_priv->chipset) {
  52. case 0x43:
  53. sensor->offset_mult = 32060;
  54. sensor->offset_div = 1000;
  55. sensor->slope_mult = 792;
  56. sensor->slope_div = 1000;
  57. break;
  58. case 0x44:
  59. case 0x47:
  60. sensor->offset_mult = 27839;
  61. sensor->offset_div = 1000;
  62. sensor->slope_mult = 780;
  63. sensor->slope_div = 1000;
  64. break;
  65. case 0x46:
  66. sensor->offset_mult = -24775;
  67. sensor->offset_div = 100;
  68. sensor->slope_mult = 467;
  69. sensor->slope_div = 10000;
  70. break;
  71. case 0x49:
  72. sensor->offset_mult = -25051;
  73. sensor->offset_div = 100;
  74. sensor->slope_mult = 458;
  75. sensor->slope_div = 10000;
  76. break;
  77. case 0x4b:
  78. sensor->offset_mult = -24088;
  79. sensor->offset_div = 100;
  80. sensor->slope_mult = 442;
  81. sensor->slope_div = 10000;
  82. break;
  83. case 0x50:
  84. sensor->offset_mult = -22749;
  85. sensor->offset_div = 100;
  86. sensor->slope_mult = 431;
  87. sensor->slope_div = 10000;
  88. break;
  89. }
  90. }
  91. headerlen = temp[1];
  92. recordlen = temp[2];
  93. entries = temp[3];
  94. temp = temp + headerlen;
  95. /* Read the entries from the table */
  96. for (i = 0; i < entries; i++) {
  97. u16 value = ROM16(temp[1]);
  98. switch (temp[0]) {
  99. case 0x01:
  100. value = (value&0x8f) == 0 ? (value >> 9) & 0x7f : 0;
  101. sensor->offset_constant = value;
  102. break;
  103. case 0x04:
  104. if ((value & 0xf00f) == 0xa000) /* core */
  105. temps->critical = (value&0x0ff0) >> 4;
  106. break;
  107. case 0x07:
  108. if ((value & 0xf00f) == 0xa000) /* core */
  109. temps->down_clock = (value&0x0ff0) >> 4;
  110. break;
  111. case 0x08:
  112. if ((value & 0xf00f) == 0xa000) /* core */
  113. temps->fan_boost = (value&0x0ff0) >> 4;
  114. break;
  115. case 0x10:
  116. sensor->offset_mult = value;
  117. break;
  118. case 0x11:
  119. sensor->offset_div = value;
  120. break;
  121. case 0x12:
  122. sensor->slope_mult = value;
  123. break;
  124. case 0x13:
  125. sensor->slope_div = value;
  126. break;
  127. }
  128. temp += recordlen;
  129. }
  130. nouveau_temp_safety_checks(dev);
  131. }
  132. static s16
  133. nouveau_nv40_sensor_setup(struct drm_device *dev)
  134. {
  135. struct drm_nouveau_private *dev_priv = dev->dev_private;
  136. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  137. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  138. u32 offset = sensor->offset_mult / sensor->offset_div;
  139. u32 sensor_calibration;
  140. /* set up the sensors */
  141. sensor_calibration = 120 - offset - sensor->offset_constant;
  142. sensor_calibration = sensor_calibration * sensor->slope_div /
  143. sensor->slope_mult;
  144. if (dev_priv->chipset >= 0x46)
  145. sensor_calibration |= 0x80000000;
  146. else
  147. sensor_calibration |= 0x10000000;
  148. nv_wr32(dev, 0x0015b0, sensor_calibration);
  149. /* Wait for the sensor to update */
  150. msleep(5);
  151. /* read */
  152. return nv_rd32(dev, 0x0015b4) & 0x1fff;
  153. }
  154. s16
  155. nouveau_temp_get(struct drm_device *dev)
  156. {
  157. struct drm_nouveau_private *dev_priv = dev->dev_private;
  158. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  159. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  160. if (dev_priv->chipset >= 0x84) {
  161. return nv_rd32(dev, 0x20400);
  162. } else if (dev_priv->chipset >= 0x40) {
  163. u32 offset = sensor->offset_mult / sensor->offset_div;
  164. u32 core_temp;
  165. if (dev_priv->chipset >= 0x50) {
  166. core_temp = nv_rd32(dev, 0x20008);
  167. } else {
  168. core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
  169. /* Setup the sensor if the temperature is 0 */
  170. if (core_temp == 0)
  171. core_temp = nouveau_nv40_sensor_setup(dev);
  172. }
  173. core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
  174. core_temp = core_temp + offset + sensor->offset_constant;
  175. return core_temp;
  176. } else {
  177. NV_ERROR(dev,
  178. "Temperature cannot be retrieved from an nv%x card\n",
  179. dev_priv->chipset);
  180. return 0;
  181. }
  182. return 0;
  183. }
  184. void
  185. nouveau_temp_safety_checks(struct drm_device *dev)
  186. {
  187. struct drm_nouveau_private *dev_priv = dev->dev_private;
  188. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  189. struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
  190. if (temps->critical > 120)
  191. temps->critical = 120;
  192. else if (temps->critical < 80)
  193. temps->critical = 80;
  194. if (temps->down_clock > 110)
  195. temps->down_clock = 110;
  196. else if (temps->down_clock < 60)
  197. temps->down_clock = 60;
  198. if (temps->fan_boost > 100)
  199. temps->fan_boost = 100;
  200. else if (temps->fan_boost < 40)
  201. temps->fan_boost = 40;
  202. }
  203. void
  204. nouveau_temp_init(struct drm_device *dev)
  205. {
  206. struct drm_nouveau_private *dev_priv = dev->dev_private;
  207. struct nvbios *bios = &dev_priv->vbios;
  208. struct bit_entry P;
  209. u8 *temp = NULL;
  210. if (bios->type == NVBIOS_BIT) {
  211. if (bit_table(dev, 'P', &P))
  212. return;
  213. if (P.version == 1)
  214. temp = ROMPTR(bios, P.data[12]);
  215. else if (P.version == 2)
  216. temp = ROMPTR(bios, P.data[16]);
  217. else
  218. NV_WARN(dev, "unknown temp for BIT P %d\n", P.version);
  219. } else {
  220. NV_WARN(dev, "BMP entry unknown for temperature table.\n");
  221. }
  222. nouveau_temp_vbios_parse(dev, temp);
  223. }
  224. void
  225. nouveau_temp_fini(struct drm_device *dev)
  226. {
  227. }