nouveau_temp.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. static 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 = 0;
  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. case 0x4a:
  61. sensor->offset_mult = 27839;
  62. sensor->offset_div = 1000;
  63. sensor->slope_mult = 780;
  64. sensor->slope_div = 1000;
  65. break;
  66. case 0x46:
  67. sensor->offset_mult = -24775;
  68. sensor->offset_div = 100;
  69. sensor->slope_mult = 467;
  70. sensor->slope_div = 10000;
  71. break;
  72. case 0x49:
  73. sensor->offset_mult = -25051;
  74. sensor->offset_div = 100;
  75. sensor->slope_mult = 458;
  76. sensor->slope_div = 10000;
  77. break;
  78. case 0x4b:
  79. sensor->offset_mult = -24088;
  80. sensor->offset_div = 100;
  81. sensor->slope_mult = 442;
  82. sensor->slope_div = 10000;
  83. break;
  84. case 0x50:
  85. sensor->offset_mult = -22749;
  86. sensor->offset_div = 100;
  87. sensor->slope_mult = 431;
  88. sensor->slope_div = 10000;
  89. break;
  90. case 0x67:
  91. sensor->offset_mult = -26149;
  92. sensor->offset_div = 100;
  93. sensor->slope_mult = 484;
  94. sensor->slope_div = 10000;
  95. break;
  96. }
  97. }
  98. headerlen = temp[1];
  99. recordlen = temp[2];
  100. entries = temp[3];
  101. temp = temp + headerlen;
  102. /* Read the entries from the table */
  103. for (i = 0; i < entries; i++) {
  104. s16 value = ROM16(temp[1]);
  105. switch (temp[0]) {
  106. case 0x01:
  107. if ((value & 0x8f) == 0)
  108. sensor->offset_constant = (value >> 9) & 0x7f;
  109. break;
  110. case 0x04:
  111. if ((value & 0xf00f) == 0xa000) /* core */
  112. temps->critical = (value&0x0ff0) >> 4;
  113. break;
  114. case 0x07:
  115. if ((value & 0xf00f) == 0xa000) /* core */
  116. temps->down_clock = (value&0x0ff0) >> 4;
  117. break;
  118. case 0x08:
  119. if ((value & 0xf00f) == 0xa000) /* core */
  120. temps->fan_boost = (value&0x0ff0) >> 4;
  121. break;
  122. case 0x10:
  123. sensor->offset_mult = value;
  124. break;
  125. case 0x11:
  126. sensor->offset_div = value;
  127. break;
  128. case 0x12:
  129. sensor->slope_mult = value;
  130. break;
  131. case 0x13:
  132. sensor->slope_div = value;
  133. break;
  134. }
  135. temp += recordlen;
  136. }
  137. nouveau_temp_safety_checks(dev);
  138. }
  139. static int
  140. nv40_sensor_setup(struct drm_device *dev)
  141. {
  142. struct drm_nouveau_private *dev_priv = dev->dev_private;
  143. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  144. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  145. s32 offset = sensor->offset_mult / sensor->offset_div;
  146. s32 sensor_calibration;
  147. /* set up the sensors */
  148. sensor_calibration = 120 - offset - sensor->offset_constant;
  149. sensor_calibration = sensor_calibration * sensor->slope_div /
  150. sensor->slope_mult;
  151. if (dev_priv->chipset >= 0x46)
  152. sensor_calibration |= 0x80000000;
  153. else
  154. sensor_calibration |= 0x10000000;
  155. nv_wr32(dev, 0x0015b0, sensor_calibration);
  156. /* Wait for the sensor to update */
  157. msleep(5);
  158. /* read */
  159. return nv_rd32(dev, 0x0015b4) & 0x1fff;
  160. }
  161. int
  162. nv40_temp_get(struct drm_device *dev)
  163. {
  164. struct drm_nouveau_private *dev_priv = dev->dev_private;
  165. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  166. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  167. int offset = sensor->offset_mult / sensor->offset_div;
  168. int core_temp;
  169. if (dev_priv->card_type >= NV_50) {
  170. core_temp = nv_rd32(dev, 0x20008);
  171. } else {
  172. core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
  173. /* Setup the sensor if the temperature is 0 */
  174. if (core_temp == 0)
  175. core_temp = nv40_sensor_setup(dev);
  176. }
  177. core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
  178. core_temp = core_temp + offset + sensor->offset_constant;
  179. return core_temp;
  180. }
  181. int
  182. nv84_temp_get(struct drm_device *dev)
  183. {
  184. return nv_rd32(dev, 0x20400);
  185. }
  186. void
  187. nouveau_temp_safety_checks(struct drm_device *dev)
  188. {
  189. struct drm_nouveau_private *dev_priv = dev->dev_private;
  190. struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
  191. struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
  192. if (temps->critical > 120)
  193. temps->critical = 120;
  194. else if (temps->critical < 80)
  195. temps->critical = 80;
  196. if (temps->down_clock > 110)
  197. temps->down_clock = 110;
  198. else if (temps->down_clock < 60)
  199. temps->down_clock = 60;
  200. if (temps->fan_boost > 100)
  201. temps->fan_boost = 100;
  202. else if (temps->fan_boost < 40)
  203. temps->fan_boost = 40;
  204. }
  205. static bool
  206. probe_monitoring_device(struct nouveau_i2c_chan *i2c,
  207. struct i2c_board_info *info)
  208. {
  209. struct i2c_client *client;
  210. request_module("%s%s", I2C_MODULE_PREFIX, info->type);
  211. client = i2c_new_device(&i2c->adapter, info);
  212. if (!client)
  213. return false;
  214. if (!client->driver || client->driver->detect(client, info)) {
  215. i2c_unregister_device(client);
  216. return false;
  217. }
  218. return true;
  219. }
  220. static void
  221. nouveau_temp_probe_i2c(struct drm_device *dev)
  222. {
  223. struct drm_nouveau_private *dev_priv = dev->dev_private;
  224. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  225. struct i2c_board_info info[] = {
  226. { I2C_BOARD_INFO("w83l785ts", 0x2d) },
  227. { I2C_BOARD_INFO("w83781d", 0x2d) },
  228. { I2C_BOARD_INFO("adt7473", 0x2e) },
  229. { I2C_BOARD_INFO("f75375", 0x2e) },
  230. { I2C_BOARD_INFO("lm99", 0x4c) },
  231. { }
  232. };
  233. int idx = (dcb->version >= 0x40 ?
  234. dcb->i2c_default_indices & 0xf : 2);
  235. nouveau_i2c_identify(dev, "monitoring device", info,
  236. probe_monitoring_device, idx);
  237. }
  238. void
  239. nouveau_temp_init(struct drm_device *dev)
  240. {
  241. struct drm_nouveau_private *dev_priv = dev->dev_private;
  242. struct nvbios *bios = &dev_priv->vbios;
  243. struct bit_entry P;
  244. u8 *temp = NULL;
  245. if (bios->type == NVBIOS_BIT) {
  246. if (bit_table(dev, 'P', &P))
  247. return;
  248. if (P.version == 1)
  249. temp = ROMPTR(bios, P.data[12]);
  250. else if (P.version == 2)
  251. temp = ROMPTR(bios, P.data[16]);
  252. else
  253. NV_WARN(dev, "unknown temp for BIT P %d\n", P.version);
  254. nouveau_temp_vbios_parse(dev, temp);
  255. }
  256. nouveau_temp_probe_i2c(dev);
  257. }
  258. void
  259. nouveau_temp_fini(struct drm_device *dev)
  260. {
  261. }