gt215.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2012 Red Hat 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: Ben Skeggs
  23. */
  24. #include "priv.h"
  25. #include <subdev/gpio.h>
  26. int
  27. gt215_therm_fan_sense(struct nvkm_therm *therm)
  28. {
  29. struct nvkm_device *device = therm->subdev.device;
  30. u32 tach = nvkm_rd32(device, 0x00e728) & 0x0000ffff;
  31. u32 ctrl = nvkm_rd32(device, 0x00e720);
  32. if (ctrl & 0x00000001)
  33. return tach * 60 / 2;
  34. return -ENODEV;
  35. }
  36. static void
  37. gt215_therm_init(struct nvkm_therm *therm)
  38. {
  39. struct nvkm_device *device = therm->subdev.device;
  40. struct dcb_gpio_func *tach = &therm->fan->tach;
  41. g84_sensor_setup(therm);
  42. /* enable fan tach, count revolutions per-second */
  43. nvkm_mask(device, 0x00e720, 0x00000003, 0x00000002);
  44. if (tach->func != DCB_GPIO_UNUSED) {
  45. nvkm_wr32(device, 0x00e724, device->crystal * 1000);
  46. nvkm_mask(device, 0x00e720, 0x001f0000, tach->line << 16);
  47. nvkm_mask(device, 0x00e720, 0x00000001, 0x00000001);
  48. }
  49. nvkm_mask(device, 0x00e720, 0x00000002, 0x00000000);
  50. }
  51. static const struct nvkm_therm_func
  52. gt215_therm = {
  53. .init = gt215_therm_init,
  54. .fini = g84_therm_fini,
  55. .pwm_ctrl = nv50_fan_pwm_ctrl,
  56. .pwm_get = nv50_fan_pwm_get,
  57. .pwm_set = nv50_fan_pwm_set,
  58. .pwm_clock = nv50_fan_pwm_clock,
  59. .temp_get = g84_temp_get,
  60. .fan_sense = gt215_therm_fan_sense,
  61. .program_alarms = nvkm_therm_program_alarms_polling,
  62. };
  63. int
  64. gt215_therm_new(struct nvkm_device *device, int index,
  65. struct nvkm_therm **ptherm)
  66. {
  67. return nvkm_therm_new_(&gt215_therm, device, index, ptherm);
  68. }