nouveau_temp.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. static int
  31. nv40_sensor_setup(struct drm_device *dev)
  32. {
  33. struct nouveau_device *device = nouveau_dev(dev);
  34. struct nouveau_drm *drm = nouveau_drm(dev);
  35. /* enable ADC readout and disable the ALARM threshold */
  36. if (nv_device(drm->device)->chipset >= 0x46) {
  37. nv_mask(device, 0x15b8, 0x80000000, 0);
  38. nv_wr32(device, 0x15b0, 0x80003fff);
  39. return nv_rd32(device, 0x15b4) & 0x3fff;
  40. } else {
  41. nv_wr32(device, 0x15b0, 0xff);
  42. return nv_rd32(device, 0x15b4) & 0xff;
  43. }
  44. }
  45. int
  46. nv40_temp_get(struct drm_device *dev)
  47. {
  48. struct nouveau_device *device = nouveau_dev(dev);
  49. struct nouveau_drm *drm = nouveau_drm(dev);
  50. struct nouveau_pm *pm = nouveau_pm(dev);
  51. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  52. int core_temp;
  53. if (nv_device(drm->device)->chipset >= 0x46) {
  54. nv_wr32(device, 0x15b0, 0x80003fff);
  55. core_temp = nv_rd32(device, 0x15b4) & 0x3fff;
  56. } else {
  57. nv_wr32(device, 0x15b0, 0xff);
  58. core_temp = nv_rd32(device, 0x15b4) & 0xff;
  59. }
  60. /* Setup the sensor if the temperature is 0 */
  61. if (core_temp == 0)
  62. core_temp = nv40_sensor_setup(dev);
  63. if (sensor->slope_div == 0)
  64. sensor->slope_div = 1;
  65. if (sensor->offset_div == 0)
  66. sensor->offset_div = 1;
  67. if (sensor->slope_mult < 1)
  68. sensor->slope_mult = 1;
  69. core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
  70. core_temp = core_temp + sensor->offset_mult / sensor->offset_div;
  71. core_temp = core_temp + sensor->offset_constant - 8;
  72. return core_temp;
  73. }
  74. int
  75. nv84_temp_get(struct drm_device *dev)
  76. {
  77. struct nouveau_device *device = nouveau_dev(dev);
  78. return nv_rd32(device, 0x20400);
  79. }
  80. void
  81. nouveau_temp_safety_checks(struct drm_device *dev)
  82. {
  83. struct nouveau_pm *pm = nouveau_pm(dev);
  84. struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
  85. if (temps->critical > 120)
  86. temps->critical = 120;
  87. else if (temps->critical < 80)
  88. temps->critical = 80;
  89. if (temps->down_clock > 110)
  90. temps->down_clock = 110;
  91. else if (temps->down_clock < 60)
  92. temps->down_clock = 60;
  93. }
  94. static bool
  95. probe_monitoring_device(struct nouveau_i2c_port *i2c,
  96. struct i2c_board_info *info)
  97. {
  98. struct i2c_client *client;
  99. request_module("%s%s", I2C_MODULE_PREFIX, info->type);
  100. client = i2c_new_device(&i2c->adapter, info);
  101. if (!client)
  102. return false;
  103. if (!client->driver || client->driver->detect(client, info)) {
  104. i2c_unregister_device(client);
  105. return false;
  106. }
  107. return true;
  108. }
  109. static void
  110. nouveau_temp_probe_i2c(struct drm_device *dev)
  111. {
  112. struct nouveau_device *device = nouveau_dev(dev);
  113. struct nouveau_i2c *i2c = nouveau_i2c(device);
  114. struct i2c_board_info info[] = {
  115. { I2C_BOARD_INFO("w83l785ts", 0x2d) },
  116. { I2C_BOARD_INFO("w83781d", 0x2d) },
  117. { I2C_BOARD_INFO("adt7473", 0x2e) },
  118. { I2C_BOARD_INFO("f75375", 0x2e) },
  119. { I2C_BOARD_INFO("lm99", 0x4c) },
  120. { }
  121. };
  122. i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device", info,
  123. probe_monitoring_device);
  124. }
  125. void
  126. nouveau_temp_init(struct drm_device *dev)
  127. {
  128. struct nouveau_drm *drm = nouveau_drm(dev);
  129. struct nouveau_device *device = nv_device(drm->device);
  130. struct nouveau_bios *bios = nouveau_bios(device);
  131. struct nouveau_pm *pm = nouveau_pm(dev);
  132. struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
  133. struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
  134. struct nvbios_therm_sensor bios_sensor;
  135. struct nvbios_therm_fan bios_fan;
  136. /* store some safe defaults */
  137. sensor->offset_constant = 0;
  138. sensor->offset_mult = 0;
  139. sensor->offset_div = 1;
  140. sensor->slope_mult = 1;
  141. sensor->slope_div = 1;
  142. if (!nvbios_therm_sensor_parse(bios, NVBIOS_THERM_DOMAIN_CORE,
  143. &bios_sensor)) {
  144. sensor->slope_mult = bios_sensor.slope_mult;
  145. sensor->slope_div = bios_sensor.slope_div;
  146. sensor->offset_mult = bios_sensor.offset_num;
  147. sensor->offset_div = bios_sensor.offset_den;
  148. sensor->offset_constant = bios_sensor.offset_constant;
  149. temps->down_clock = bios_sensor.thrs_down_clock.temp;
  150. temps->critical = bios_sensor.thrs_critical.temp;
  151. }
  152. if (nvbios_therm_fan_parse(bios, &bios_fan)) {
  153. pm->fan.min_duty = bios_fan.min_duty;
  154. pm->fan.max_duty = bios_fan.max_duty;
  155. pm->fan.pwm_freq = bios_fan.pwm_freq;
  156. }
  157. nouveau_temp_safety_checks(dev);
  158. nouveau_temp_probe_i2c(dev);
  159. }
  160. void
  161. nouveau_temp_fini(struct drm_device *dev)
  162. {
  163. }