tonga_dpm.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_smum.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(void *handle)
  30. {
  31. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  32. tonga_dpm_set_funcs(adev);
  33. return 0;
  34. }
  35. static int tonga_dpm_init_microcode(struct amdgpu_device *adev)
  36. {
  37. char fw_name[30] = "amdgpu/tonga_smc.bin";
  38. int err;
  39. err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
  40. if (err)
  41. goto out;
  42. err = amdgpu_ucode_validate(adev->pm.fw);
  43. out:
  44. if (err) {
  45. DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
  46. release_firmware(adev->pm.fw);
  47. adev->pm.fw = NULL;
  48. }
  49. return err;
  50. }
  51. static int tonga_dpm_sw_init(void *handle)
  52. {
  53. int ret;
  54. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  55. ret = tonga_dpm_init_microcode(adev);
  56. if (ret)
  57. return ret;
  58. return 0;
  59. }
  60. static int tonga_dpm_sw_fini(void *handle)
  61. {
  62. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  63. release_firmware(adev->pm.fw);
  64. adev->pm.fw = NULL;
  65. return 0;
  66. }
  67. static int tonga_dpm_hw_init(void *handle)
  68. {
  69. int ret;
  70. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  71. mutex_lock(&adev->pm.mutex);
  72. /* smu init only needs to be called at startup, not resume.
  73. * It should be in sw_init, but requires the fw info gathered
  74. * in sw_init from other IP modules.
  75. */
  76. ret = tonga_smu_init(adev);
  77. if (ret) {
  78. DRM_ERROR("SMU initialization failed\n");
  79. goto fail;
  80. }
  81. ret = tonga_smu_start(adev);
  82. if (ret) {
  83. DRM_ERROR("SMU start failed\n");
  84. goto fail;
  85. }
  86. mutex_unlock(&adev->pm.mutex);
  87. return 0;
  88. fail:
  89. adev->firmware.smu_load = false;
  90. mutex_unlock(&adev->pm.mutex);
  91. return -EINVAL;
  92. }
  93. static int tonga_dpm_hw_fini(void *handle)
  94. {
  95. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  96. mutex_lock(&adev->pm.mutex);
  97. /* smu fini only needs to be called at teardown, not suspend.
  98. * It should be in sw_fini, but we put it here for symmetry
  99. * with smu init.
  100. */
  101. tonga_smu_fini(adev);
  102. mutex_unlock(&adev->pm.mutex);
  103. return 0;
  104. }
  105. static int tonga_dpm_suspend(void *handle)
  106. {
  107. return tonga_dpm_hw_fini(handle);
  108. }
  109. static int tonga_dpm_resume(void *handle)
  110. {
  111. return tonga_dpm_hw_init(handle);
  112. }
  113. static int tonga_dpm_set_clockgating_state(void *handle,
  114. enum amd_clockgating_state state)
  115. {
  116. return 0;
  117. }
  118. static int tonga_dpm_set_powergating_state(void *handle,
  119. enum amd_powergating_state state)
  120. {
  121. return 0;
  122. }
  123. const struct amd_ip_funcs tonga_dpm_ip_funcs = {
  124. .name = "tonga_dpm",
  125. .early_init = tonga_dpm_early_init,
  126. .late_init = NULL,
  127. .sw_init = tonga_dpm_sw_init,
  128. .sw_fini = tonga_dpm_sw_fini,
  129. .hw_init = tonga_dpm_hw_init,
  130. .hw_fini = tonga_dpm_hw_fini,
  131. .suspend = tonga_dpm_suspend,
  132. .resume = tonga_dpm_resume,
  133. .is_idle = NULL,
  134. .wait_for_idle = NULL,
  135. .soft_reset = NULL,
  136. .set_clockgating_state = tonga_dpm_set_clockgating_state,
  137. .set_powergating_state = tonga_dpm_set_powergating_state,
  138. };
  139. static const struct amdgpu_dpm_funcs tonga_dpm_funcs = {
  140. .get_temperature = NULL,
  141. .pre_set_power_state = NULL,
  142. .set_power_state = NULL,
  143. .post_set_power_state = NULL,
  144. .display_configuration_changed = NULL,
  145. .get_sclk = NULL,
  146. .get_mclk = NULL,
  147. .print_power_state = NULL,
  148. .debugfs_print_current_performance_level = NULL,
  149. .force_performance_level = NULL,
  150. .vblank_too_short = NULL,
  151. .powergate_uvd = NULL,
  152. };
  153. static void tonga_dpm_set_funcs(struct amdgpu_device *adev)
  154. {
  155. if (NULL == adev->pm.funcs)
  156. adev->pm.funcs = &tonga_dpm_funcs;
  157. }