nouveau_temp.c 7.5 KB

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