tonga_dpm.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, 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. */
  23. #include <linux/firmware.h>
  24. #include "drmP.h"
  25. #include "amdgpu.h"
  26. #include "tonga_smumgr.h"
  27. MODULE_FIRMWARE("amdgpu/tonga_smc.bin");
  28. static void tonga_dpm_set_funcs(struct amdgpu_device *adev);
  29. static int tonga_dpm_early_init(struct amdgpu_device *adev)
  30. {
  31. tonga_dpm_set_funcs(adev);
  32. return 0;
  33. }
  34. static int tonga_dpm_init_microcode(struct amdgpu_device *adev)
  35. {
  36. char fw_name[30] = "amdgpu/tonga_smc.bin";
  37. int err;
  38. err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
  39. if (err)
  40. goto out;
  41. err = amdgpu_ucode_validate(adev->pm.fw);
  42. out:
  43. if (err) {
  44. DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
  45. release_firmware(adev->pm.fw);
  46. adev->pm.fw = NULL;
  47. }
  48. return err;
  49. }
  50. static int tonga_dpm_sw_init(struct amdgpu_device *adev)
  51. {
  52. int ret;
  53. ret = tonga_dpm_init_microcode(adev);
  54. if (ret)
  55. return ret;
  56. return 0;
  57. }
  58. static int tonga_dpm_sw_fini(struct amdgpu_device *adev)
  59. {
  60. return 0;
  61. }
  62. static int tonga_dpm_hw_init(struct amdgpu_device *adev)
  63. {
  64. int ret;
  65. mutex_lock(&adev->pm.mutex);
  66. ret = tonga_smu_init(adev);
  67. if (ret) {
  68. DRM_ERROR("SMU initialization failed\n");
  69. goto fail;
  70. }
  71. ret = tonga_smu_start(adev);
  72. if (ret) {
  73. DRM_ERROR("SMU start failed\n");
  74. goto fail;
  75. }
  76. mutex_unlock(&adev->pm.mutex);
  77. return 0;
  78. fail:
  79. adev->firmware.smu_load = false;
  80. mutex_unlock(&adev->pm.mutex);
  81. return -EINVAL;
  82. }
  83. static int tonga_dpm_hw_fini(struct amdgpu_device *adev)
  84. {
  85. mutex_lock(&adev->pm.mutex);
  86. tonga_smu_fini(adev);
  87. mutex_unlock(&adev->pm.mutex);
  88. return 0;
  89. }
  90. static int tonga_dpm_suspend(struct amdgpu_device *adev)
  91. {
  92. tonga_dpm_hw_fini(adev);
  93. return 0;
  94. }
  95. static int tonga_dpm_resume(struct amdgpu_device *adev)
  96. {
  97. tonga_dpm_hw_init(adev);
  98. return 0;
  99. }
  100. static int tonga_dpm_set_clockgating_state(struct amdgpu_device *adev,
  101. enum amdgpu_clockgating_state state)
  102. {
  103. return 0;
  104. }
  105. static int tonga_dpm_set_powergating_state(struct amdgpu_device *adev,
  106. enum amdgpu_powergating_state state)
  107. {
  108. return 0;
  109. }
  110. const struct amdgpu_ip_funcs tonga_dpm_ip_funcs = {
  111. .early_init = tonga_dpm_early_init,
  112. .late_init = NULL,
  113. .sw_init = tonga_dpm_sw_init,
  114. .sw_fini = tonga_dpm_sw_fini,
  115. .hw_init = tonga_dpm_hw_init,
  116. .hw_fini = tonga_dpm_hw_fini,
  117. .suspend = tonga_dpm_suspend,
  118. .resume = tonga_dpm_resume,
  119. .is_idle = NULL,
  120. .wait_for_idle = NULL,
  121. .soft_reset = NULL,
  122. .print_status = NULL,
  123. .set_clockgating_state = tonga_dpm_set_clockgating_state,
  124. .set_powergating_state = tonga_dpm_set_powergating_state,
  125. };
  126. static const struct amdgpu_dpm_funcs tonga_dpm_funcs = {
  127. .get_temperature = NULL,
  128. .pre_set_power_state = NULL,
  129. .set_power_state = NULL,
  130. .post_set_power_state = NULL,
  131. .display_configuration_changed = NULL,
  132. .get_sclk = NULL,
  133. .get_mclk = NULL,
  134. .print_power_state = NULL,
  135. .debugfs_print_current_performance_level = NULL,
  136. .force_performance_level = NULL,
  137. .vblank_too_short = NULL,
  138. .powergate_uvd = NULL,
  139. };
  140. static void tonga_dpm_set_funcs(struct amdgpu_device *adev)
  141. {
  142. if (NULL == adev->pm.funcs)
  143. adev->pm.funcs = &tonga_dpm_funcs;
  144. }