nouveau_temp.c 7.9 KB

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