nouveau_temp.c 7.6 KB

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