amdgpu_acp.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * Copyright 2015 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. * Authors: AMD
  23. *
  24. */
  25. #include <linux/irqdomain.h>
  26. #include <linux/platform_device.h>
  27. #include <sound/designware_i2s.h>
  28. #include <sound/pcm.h>
  29. #include "amdgpu.h"
  30. #include "atom.h"
  31. #include "amdgpu_acp.h"
  32. #include "acp_gfx_if.h"
  33. #define ACP_TILE_ON_MASK 0x03
  34. #define ACP_TILE_OFF_MASK 0x02
  35. #define ACP_TILE_ON_RETAIN_REG_MASK 0x1f
  36. #define ACP_TILE_OFF_RETAIN_REG_MASK 0x20
  37. #define ACP_TILE_P1_MASK 0x3e
  38. #define ACP_TILE_P2_MASK 0x3d
  39. #define ACP_TILE_DSP0_MASK 0x3b
  40. #define ACP_TILE_DSP1_MASK 0x37
  41. #define ACP_TILE_DSP2_MASK 0x2f
  42. #define ACP_DMA_REGS_END 0x146c0
  43. #define ACP_I2S_PLAY_REGS_START 0x14840
  44. #define ACP_I2S_PLAY_REGS_END 0x148b4
  45. #define ACP_I2S_CAP_REGS_START 0x148b8
  46. #define ACP_I2S_CAP_REGS_END 0x1496c
  47. #define ACP_I2S_COMP1_CAP_REG_OFFSET 0xac
  48. #define ACP_I2S_COMP2_CAP_REG_OFFSET 0xa8
  49. #define ACP_I2S_COMP1_PLAY_REG_OFFSET 0x6c
  50. #define ACP_I2S_COMP2_PLAY_REG_OFFSET 0x68
  51. #define mmACP_PGFSM_RETAIN_REG 0x51c9
  52. #define mmACP_PGFSM_CONFIG_REG 0x51ca
  53. #define mmACP_PGFSM_READ_REG_0 0x51cc
  54. #define mmACP_MEM_SHUT_DOWN_REQ_LO 0x51f8
  55. #define mmACP_MEM_SHUT_DOWN_REQ_HI 0x51f9
  56. #define mmACP_MEM_SHUT_DOWN_STS_LO 0x51fa
  57. #define mmACP_MEM_SHUT_DOWN_STS_HI 0x51fb
  58. #define ACP_TIMEOUT_LOOP 0x000000FF
  59. #define ACP_DEVS 3
  60. #define ACP_SRC_ID 162
  61. enum {
  62. ACP_TILE_P1 = 0,
  63. ACP_TILE_P2,
  64. ACP_TILE_DSP0,
  65. ACP_TILE_DSP1,
  66. ACP_TILE_DSP2,
  67. };
  68. static int acp_sw_init(void *handle)
  69. {
  70. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  71. adev->acp.parent = adev->dev;
  72. adev->acp.cgs_device =
  73. amdgpu_cgs_create_device(adev);
  74. if (!adev->acp.cgs_device)
  75. return -EINVAL;
  76. return 0;
  77. }
  78. static int acp_sw_fini(void *handle)
  79. {
  80. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  81. if (adev->acp.cgs_device)
  82. amdgpu_cgs_destroy_device(adev->acp.cgs_device);
  83. return 0;
  84. }
  85. /**
  86. * acp_hw_init - start and test ACP block
  87. *
  88. * @adev: amdgpu_device pointer
  89. *
  90. */
  91. static int acp_hw_init(void *handle)
  92. {
  93. int r;
  94. uint64_t acp_base;
  95. struct i2s_platform_data *i2s_pdata;
  96. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  97. const struct amdgpu_ip_block_version *ip_version =
  98. amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_ACP);
  99. if (!ip_version)
  100. return -EINVAL;
  101. r = amd_acp_hw_init(adev->acp.cgs_device,
  102. ip_version->major, ip_version->minor);
  103. /* -ENODEV means board uses AZ rather than ACP */
  104. if (r == -ENODEV)
  105. return 0;
  106. else if (r)
  107. return r;
  108. r = cgs_get_pci_resource(adev->acp.cgs_device, CGS_RESOURCE_TYPE_MMIO,
  109. 0x5289, 0, &acp_base);
  110. if (r == -ENODEV)
  111. return 0;
  112. else if (r)
  113. return r;
  114. adev->acp.acp_cell = kzalloc(sizeof(struct mfd_cell) * ACP_DEVS,
  115. GFP_KERNEL);
  116. if (adev->acp.acp_cell == NULL)
  117. return -ENOMEM;
  118. adev->acp.acp_res = kzalloc(sizeof(struct resource) * 4, GFP_KERNEL);
  119. if (adev->acp.acp_res == NULL) {
  120. kfree(adev->acp.acp_cell);
  121. return -ENOMEM;
  122. }
  123. i2s_pdata = kzalloc(sizeof(struct i2s_platform_data) * 2, GFP_KERNEL);
  124. if (i2s_pdata == NULL) {
  125. kfree(adev->acp.acp_res);
  126. kfree(adev->acp.acp_cell);
  127. return -ENOMEM;
  128. }
  129. i2s_pdata[0].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET;
  130. i2s_pdata[0].cap = DWC_I2S_PLAY;
  131. i2s_pdata[0].snd_rates = SNDRV_PCM_RATE_8000_96000;
  132. i2s_pdata[0].i2s_reg_comp1 = ACP_I2S_COMP1_PLAY_REG_OFFSET;
  133. i2s_pdata[0].i2s_reg_comp2 = ACP_I2S_COMP2_PLAY_REG_OFFSET;
  134. i2s_pdata[1].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET |
  135. DW_I2S_QUIRK_COMP_PARAM1;
  136. i2s_pdata[1].cap = DWC_I2S_RECORD;
  137. i2s_pdata[1].snd_rates = SNDRV_PCM_RATE_8000_96000;
  138. i2s_pdata[1].i2s_reg_comp1 = ACP_I2S_COMP1_CAP_REG_OFFSET;
  139. i2s_pdata[1].i2s_reg_comp2 = ACP_I2S_COMP2_CAP_REG_OFFSET;
  140. adev->acp.acp_res[0].name = "acp2x_dma";
  141. adev->acp.acp_res[0].flags = IORESOURCE_MEM;
  142. adev->acp.acp_res[0].start = acp_base;
  143. adev->acp.acp_res[0].end = acp_base + ACP_DMA_REGS_END;
  144. adev->acp.acp_res[1].name = "acp2x_dw_i2s_play";
  145. adev->acp.acp_res[1].flags = IORESOURCE_MEM;
  146. adev->acp.acp_res[1].start = acp_base + ACP_I2S_PLAY_REGS_START;
  147. adev->acp.acp_res[1].end = acp_base + ACP_I2S_PLAY_REGS_END;
  148. adev->acp.acp_res[2].name = "acp2x_dw_i2s_cap";
  149. adev->acp.acp_res[2].flags = IORESOURCE_MEM;
  150. adev->acp.acp_res[2].start = acp_base + ACP_I2S_CAP_REGS_START;
  151. adev->acp.acp_res[2].end = acp_base + ACP_I2S_CAP_REGS_END;
  152. adev->acp.acp_res[3].name = "acp2x_dma_irq";
  153. adev->acp.acp_res[3].flags = IORESOURCE_IRQ;
  154. adev->acp.acp_res[3].start = amdgpu_irq_create_mapping(adev, 162);
  155. adev->acp.acp_res[3].end = adev->acp.acp_res[3].start;
  156. adev->acp.acp_cell[0].name = "acp_audio_dma";
  157. adev->acp.acp_cell[0].num_resources = 4;
  158. adev->acp.acp_cell[0].resources = &adev->acp.acp_res[0];
  159. adev->acp.acp_cell[1].name = "designware-i2s";
  160. adev->acp.acp_cell[1].num_resources = 1;
  161. adev->acp.acp_cell[1].resources = &adev->acp.acp_res[1];
  162. adev->acp.acp_cell[1].platform_data = &i2s_pdata[0];
  163. adev->acp.acp_cell[1].pdata_size = sizeof(struct i2s_platform_data);
  164. adev->acp.acp_cell[2].name = "designware-i2s";
  165. adev->acp.acp_cell[2].num_resources = 1;
  166. adev->acp.acp_cell[2].resources = &adev->acp.acp_res[2];
  167. adev->acp.acp_cell[2].platform_data = &i2s_pdata[1];
  168. adev->acp.acp_cell[2].pdata_size = sizeof(struct i2s_platform_data);
  169. r = mfd_add_hotplug_devices(adev->acp.parent, adev->acp.acp_cell,
  170. ACP_DEVS);
  171. if (r)
  172. return r;
  173. return 0;
  174. }
  175. /**
  176. * acp_hw_fini - stop the hardware block
  177. *
  178. * @adev: amdgpu_device pointer
  179. *
  180. */
  181. static int acp_hw_fini(void *handle)
  182. {
  183. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  184. mfd_remove_devices(adev->acp.parent);
  185. kfree(adev->acp.acp_res);
  186. kfree(adev->acp.acp_cell);
  187. return 0;
  188. }
  189. static int acp_suspend(void *handle)
  190. {
  191. return 0;
  192. }
  193. static int acp_resume(void *handle)
  194. {
  195. return 0;
  196. }
  197. static int acp_early_init(void *handle)
  198. {
  199. return 0;
  200. }
  201. static bool acp_is_idle(void *handle)
  202. {
  203. return true;
  204. }
  205. static int acp_wait_for_idle(void *handle)
  206. {
  207. return 0;
  208. }
  209. static int acp_soft_reset(void *handle)
  210. {
  211. return 0;
  212. }
  213. static void acp_print_status(void *handle)
  214. {
  215. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  216. dev_info(adev->dev, "ACP STATUS\n");
  217. }
  218. static int acp_set_clockgating_state(void *handle,
  219. enum amd_clockgating_state state)
  220. {
  221. return 0;
  222. }
  223. static int acp_set_powergating_state(void *handle,
  224. enum amd_powergating_state state)
  225. {
  226. return 0;
  227. }
  228. const struct amd_ip_funcs acp_ip_funcs = {
  229. .early_init = acp_early_init,
  230. .late_init = NULL,
  231. .sw_init = acp_sw_init,
  232. .sw_fini = acp_sw_fini,
  233. .hw_init = acp_hw_init,
  234. .hw_fini = acp_hw_fini,
  235. .suspend = acp_suspend,
  236. .resume = acp_resume,
  237. .is_idle = acp_is_idle,
  238. .wait_for_idle = acp_wait_for_idle,
  239. .soft_reset = acp_soft_reset,
  240. .print_status = acp_print_status,
  241. .set_clockgating_state = acp_set_clockgating_state,
  242. .set_powergating_state = acp_set_powergating_state,
  243. };