PageRenderTime 83ms CodeModel.GetById 18ms RepoModel.GetById 2ms app.codeStats 0ms

/drivers/gpu/drm/nouveau/nouveau_temp.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 307 lines | 224 code | 52 blank | 31 comment | 38 complexity | d33715487bccdd7719823e1a63e14e56 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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. struct i2c_client *client;
  204. request_module("%s%s", I2C_MODULE_PREFIX, info->type);
  205. client = i2c_new_device(&i2c->adapter, info);
  206. if (!client)
  207. return false;
  208. if (!client->driver || client->driver->detect(client, info)) {
  209. i2c_unregister_device(client);
  210. return false;
  211. }
  212. return true;
  213. }
  214. static void
  215. nouveau_temp_probe_i2c(struct drm_device *dev)
  216. {
  217. struct drm_nouveau_private *dev_priv = dev->dev_private;
  218. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  219. struct i2c_board_info info[] = {
  220. { I2C_BOARD_INFO("w83l785ts", 0x2d) },
  221. { I2C_BOARD_INFO("w83781d", 0x2d) },
  222. { I2C_BOARD_INFO("adt7473", 0x2e) },
  223. { I2C_BOARD_INFO("f75375", 0x2e) },
  224. { I2C_BOARD_INFO("lm99", 0x4c) },
  225. { }
  226. };
  227. int idx = (dcb->version >= 0x40 ?
  228. dcb->i2c_default_indices & 0xf : 2);
  229. nouveau_i2c_identify(dev, "monitoring device", info,
  230. probe_monitoring_device, idx);
  231. }
  232. void
  233. nouveau_temp_init(struct drm_device *dev)
  234. {
  235. struct drm_nouveau_private *dev_priv = dev->dev_private;
  236. struct nvbios *bios = &dev_priv->vbios;
  237. struct bit_entry P;
  238. u8 *temp = NULL;
  239. if (bios->type == NVBIOS_BIT) {
  240. if (bit_table(dev, 'P', &P))
  241. return;
  242. if (P.version == 1)
  243. temp = ROMPTR(bios, P.data[12]);
  244. else if (P.version == 2)
  245. temp = ROMPTR(bios, P.data[16]);
  246. else
  247. NV_WARN(dev, "unknown temp for BIT P %d\n", P.version);
  248. nouveau_temp_vbios_parse(dev, temp);
  249. }
  250. nouveau_temp_probe_i2c(dev);
  251. }
  252. void
  253. nouveau_temp_fini(struct drm_device *dev)
  254. {
  255. }