iceland_dpm.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 "iceland_smumgr.h"
  27. MODULE_FIRMWARE("amdgpu/topaz_smc.bin");
  28. static void iceland_dpm_set_funcs(struct amdgpu_device *adev);
  29. static int iceland_dpm_early_init(void *handle)
  30. {
  31. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  32. iceland_dpm_set_funcs(adev);
  33. return 0;
  34. }
  35. static int iceland_dpm_init_microcode(struct amdgpu_device *adev)
  36. {
  37. char fw_name[30] = "amdgpu/topaz_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 iceland_dpm_sw_init(void *handle)
  52. {
  53. int ret;
  54. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  55. ret = iceland_dpm_init_microcode(adev);
  56. if (ret)
  57. return ret;
  58. return 0;
  59. }
  60. static int iceland_dpm_sw_fini(void *handle)
  61. {
  62. return 0;
  63. }
  64. static int iceland_dpm_hw_init(void *handle)
  65. {
  66. int ret;
  67. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  68. mutex_lock(&adev->pm.mutex);
  69. /* smu init only needs to be called at startup, not resume.
  70. * It should be in sw_init, but requires the fw info gathered
  71. * in sw_init from other IP modules.
  72. */
  73. ret = iceland_smu_init(adev);
  74. if (ret) {
  75. DRM_ERROR("SMU initialization failed\n");
  76. goto fail;
  77. }
  78. ret = iceland_smu_start(adev);
  79. if (ret) {
  80. DRM_ERROR("SMU start failed\n");
  81. goto fail;
  82. }
  83. mutex_unlock(&adev->pm.mutex);
  84. return 0;
  85. fail:
  86. adev->firmware.smu_load = false;
  87. mutex_unlock(&adev->pm.mutex);
  88. return -EINVAL;
  89. }
  90. static int iceland_dpm_hw_fini(void *handle)
  91. {
  92. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  93. mutex_lock(&adev->pm.mutex);
  94. /* smu fini only needs to be called at teardown, not suspend.
  95. * It should be in sw_fini, but we put it here for symmetry
  96. * with smu init.
  97. */
  98. iceland_smu_fini(adev);
  99. mutex_unlock(&adev->pm.mutex);
  100. return 0;
  101. }
  102. static int iceland_dpm_suspend(void *handle)
  103. {
  104. return 0;
  105. }
  106. static int iceland_dpm_resume(void *handle)
  107. {
  108. int ret;
  109. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  110. mutex_lock(&adev->pm.mutex);
  111. ret = iceland_smu_start(adev);
  112. if (ret) {
  113. DRM_ERROR("SMU start failed\n");
  114. goto fail;
  115. }
  116. fail:
  117. mutex_unlock(&adev->pm.mutex);
  118. return ret;
  119. }
  120. static int iceland_dpm_set_clockgating_state(void *handle,
  121. enum amd_clockgating_state state)
  122. {
  123. return 0;
  124. }
  125. static int iceland_dpm_set_powergating_state(void *handle,
  126. enum amd_powergating_state state)
  127. {
  128. return 0;
  129. }
  130. const struct amd_ip_funcs iceland_dpm_ip_funcs = {
  131. .early_init = iceland_dpm_early_init,
  132. .late_init = NULL,
  133. .sw_init = iceland_dpm_sw_init,
  134. .sw_fini = iceland_dpm_sw_fini,
  135. .hw_init = iceland_dpm_hw_init,
  136. .hw_fini = iceland_dpm_hw_fini,
  137. .suspend = iceland_dpm_suspend,
  138. .resume = iceland_dpm_resume,
  139. .is_idle = NULL,
  140. .wait_for_idle = NULL,
  141. .soft_reset = NULL,
  142. .print_status = NULL,
  143. .set_clockgating_state = iceland_dpm_set_clockgating_state,
  144. .set_powergating_state = iceland_dpm_set_powergating_state,
  145. };
  146. static const struct amdgpu_dpm_funcs iceland_dpm_funcs = {
  147. .get_temperature = NULL,
  148. .pre_set_power_state = NULL,
  149. .set_power_state = NULL,
  150. .post_set_power_state = NULL,
  151. .display_configuration_changed = NULL,
  152. .get_sclk = NULL,
  153. .get_mclk = NULL,
  154. .print_power_state = NULL,
  155. .debugfs_print_current_performance_level = NULL,
  156. .force_performance_level = NULL,
  157. .vblank_too_short = NULL,
  158. .powergate_uvd = NULL,
  159. };
  160. static void iceland_dpm_set_funcs(struct amdgpu_device *adev)
  161. {
  162. if (NULL == adev->pm.funcs)
  163. adev->pm.funcs = &iceland_dpm_funcs;
  164. }