nouveau_temp.c 8.1 KB

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