nouveau_temp.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #include <subdev/bios/therm.h>
  30. #include <subdev/bios/extdev.h>
  31. static int
  32. nv40_sensor_setup(struct drm_device *dev)
  33. {
  34. struct nouveau_device *device = nouveau_dev(dev);
  35. struct nouveau_drm *drm = nouveau_drm(dev);
  36. /* enable ADC readout and disable the ALARM threshold */
  37. if (nv_device(drm->device)->chipset >= 0x46) {
  38. nv_mask(device, 0x15b8, 0x80000000, 0);
  39. nv_wr32(device, 0x15b0, 0x80003fff);
  40. return nv_rd32(device, 0x15b4) & 0x3fff;
  41. } else {
  42. nv_wr32(device, 0x15b0, 0xff);
  43. return nv_rd32(device, 0x15b4) & 0xff;
  44. }
  45. }
  46. int
  47. nv40_temp_get(struct drm_device *dev)
  48. {
  49. struct nouveau_device *device = nouveau_dev(dev);
  50. struct nouveau_drm *drm = nouveau_drm(dev);
  51. struct nouveau_pm *pm = nouveau_pm(dev);
  52. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  53. int core_temp;
  54. if (nv_device(drm->device)->chipset >= 0x46) {
  55. nv_wr32(device, 0x15b0, 0x80003fff);
  56. core_temp = nv_rd32(device, 0x15b4) & 0x3fff;
  57. } else {
  58. nv_wr32(device, 0x15b0, 0xff);
  59. core_temp = nv_rd32(device, 0x15b4) & 0xff;
  60. }
  61. /* Setup the sensor if the temperature is 0 */
  62. if (core_temp == 0)
  63. core_temp = nv40_sensor_setup(dev);
  64. if (sensor->slope_div == 0)
  65. sensor->slope_div = 1;
  66. if (sensor->offset_div == 0)
  67. sensor->offset_div = 1;
  68. if (sensor->slope_mult < 1)
  69. sensor->slope_mult = 1;
  70. core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
  71. core_temp = core_temp + sensor->offset_mult / sensor->offset_div;
  72. core_temp = core_temp + sensor->offset_constant - 8;
  73. return core_temp;
  74. }
  75. int
  76. nv84_temp_get(struct drm_device *dev)
  77. {
  78. struct nouveau_device *device = nouveau_dev(dev);
  79. return nv_rd32(device, 0x20400);
  80. }
  81. void
  82. nouveau_temp_safety_checks(struct drm_device *dev)
  83. {
  84. struct nouveau_pm *pm = nouveau_pm(dev);
  85. struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
  86. if (temps->critical > 120)
  87. temps->critical = 120;
  88. else if (temps->critical < 80)
  89. temps->critical = 80;
  90. if (temps->down_clock > 110)
  91. temps->down_clock = 110;
  92. else if (temps->down_clock < 60)
  93. temps->down_clock = 60;
  94. }
  95. static bool
  96. probe_monitoring_device(struct nouveau_i2c_port *i2c,
  97. struct i2c_board_info *info)
  98. {
  99. struct i2c_client *client;
  100. request_module("%s%s", I2C_MODULE_PREFIX, info->type);
  101. client = i2c_new_device(&i2c->adapter, info);
  102. if (!client)
  103. return false;
  104. if (!client->driver || client->driver->detect(client, info)) {
  105. i2c_unregister_device(client);
  106. return false;
  107. }
  108. return true;
  109. }
  110. static void
  111. nouveau_temp_probe_i2c(struct drm_device *dev)
  112. {
  113. struct nouveau_device *device = nouveau_dev(dev);
  114. struct nouveau_bios *bios = nouveau_bios(device);
  115. struct nouveau_i2c *i2c = nouveau_i2c(device);
  116. struct nvbios_extdev_func extdev_entry;
  117. struct i2c_board_info info[] = {
  118. { I2C_BOARD_INFO("w83l785ts", 0x2d) },
  119. { I2C_BOARD_INFO("w83781d", 0x2d) },
  120. { I2C_BOARD_INFO("adt7473", 0x2e) },
  121. { I2C_BOARD_INFO("adt7473", 0x2d) },
  122. { I2C_BOARD_INFO("adt7473", 0x2c) },
  123. { I2C_BOARD_INFO("f75375", 0x2e) },
  124. { I2C_BOARD_INFO("lm99", 0x4c) },
  125. { I2C_BOARD_INFO("lm90", 0x4c) },
  126. { I2C_BOARD_INFO("lm90", 0x4d) },
  127. { I2C_BOARD_INFO("adm1021", 0x18) },
  128. { I2C_BOARD_INFO("adm1021", 0x19) },
  129. { I2C_BOARD_INFO("adm1021", 0x1a) },
  130. { I2C_BOARD_INFO("adm1021", 0x29) },
  131. { I2C_BOARD_INFO("adm1021", 0x2a) },
  132. { I2C_BOARD_INFO("adm1021", 0x2b) },
  133. { I2C_BOARD_INFO("adm1021", 0x4c) },
  134. { I2C_BOARD_INFO("adm1021", 0x4d) },
  135. { I2C_BOARD_INFO("adm1021", 0x4e) },
  136. { I2C_BOARD_INFO("lm63", 0x18) },
  137. { I2C_BOARD_INFO("lm63", 0x4e) },
  138. { }
  139. };
  140. if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_LM89, &extdev_entry)) {
  141. struct i2c_board_info board[] = {
  142. { I2C_BOARD_INFO("lm90", extdev_entry.addr >> 1) },
  143. { }
  144. };
  145. if (i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
  146. board, probe_monitoring_device))
  147. return;
  148. }
  149. if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_ADT7473, &extdev_entry)) {
  150. struct i2c_board_info board[] = {
  151. { I2C_BOARD_INFO("adt7473", extdev_entry.addr >> 1) },
  152. { }
  153. };
  154. if (i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
  155. board, probe_monitoring_device))
  156. return;
  157. }
  158. /* The vbios doesn't provide the address of an exisiting monitoring
  159. device. Let's try our static list.
  160. */
  161. i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device", info,
  162. probe_monitoring_device);
  163. }
  164. void
  165. nouveau_temp_init(struct drm_device *dev)
  166. {
  167. struct nouveau_drm *drm = nouveau_drm(dev);
  168. struct nouveau_device *device = nv_device(drm->device);
  169. struct nouveau_bios *bios = nouveau_bios(device);
  170. struct nouveau_pm *pm = nouveau_pm(dev);
  171. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  172. struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
  173. struct nvbios_therm_sensor bios_sensor;
  174. struct nvbios_therm_fan bios_fan;
  175. /* store some safe defaults */
  176. sensor->offset_constant = 0;
  177. sensor->offset_mult = 0;
  178. sensor->offset_div = 1;
  179. sensor->slope_mult = 1;
  180. sensor->slope_div = 1;
  181. if (!nvbios_therm_sensor_parse(bios, NVBIOS_THERM_DOMAIN_CORE,
  182. &bios_sensor)) {
  183. sensor->slope_mult = bios_sensor.slope_mult;
  184. sensor->slope_div = bios_sensor.slope_div;
  185. sensor->offset_mult = bios_sensor.offset_num;
  186. sensor->offset_div = bios_sensor.offset_den;
  187. sensor->offset_constant = bios_sensor.offset_constant;
  188. temps->down_clock = bios_sensor.thrs_down_clock.temp;
  189. temps->critical = bios_sensor.thrs_critical.temp;
  190. }
  191. if (nvbios_therm_fan_parse(bios, &bios_fan)) {
  192. pm->fan.min_duty = bios_fan.min_duty;
  193. pm->fan.max_duty = bios_fan.max_duty;
  194. pm->fan.pwm_freq = bios_fan.pwm_freq;
  195. }
  196. nouveau_temp_safety_checks(dev);
  197. nouveau_temp_probe_i2c(dev);
  198. }
  199. void
  200. nouveau_temp_fini(struct drm_device *dev)
  201. {
  202. }