soc_anc.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Copyright (c) 1997-2015, Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef SOC_ANC_H_
  7. #define SOC_ANC_H_
  8. #include <os_common_api.h>
  9. #include <stdint.h>
  10. #include <soc_regs.h>
  11. #include <soc_irq.h>
  12. #include <rbuf/rbuf_mem.h>
  13. /* if set, the user can externally shut down the ANC root clock (gated by CMU) */
  14. #define PSU_ANC_IDLE BIT(25)
  15. /* if set, only the ANC Internal core clock is gated */
  16. #define PSU_ANC_CORE_IDLE BIT(24)
  17. #define ANC_STATUS_EXT_CTL_ANC_WAIT_EN (1 << 0)
  18. #define ANC_STATUS_EXT_CTL_ANC_EXTERNAL_WAIT (1 << 1)
  19. #define DTCM_AND_PTCM 0
  20. #define ALL_EXT_MEM 1
  21. #define CODE_ADDR 1
  22. #define DATA_ADDR 0
  23. #define ANC_DTCM_SIZE 0x8000
  24. #define CPU_ANC_DTCM_BASE 0x01070000
  25. #define ANC_ANC_DTCM_BASE 0
  26. #define ANC_PTCM_SIZE 0x4000
  27. #define CPU_ANC_PTCM_BASE 0x01078000
  28. #define ANC_ANC_PTCM_BASE 0
  29. #define ANC_EXTMEM_SIZE 0x2400
  30. #define CPU_ANC_EXTMEM_BASE 0x0107c000
  31. #define ANC_ANC_EXTMEM_BASE 0x00010000
  32. #define ANC_SHARE_MEM_SIZE 0x7FFF
  33. #define CPU_SHARE_BASE 0x1068000
  34. #define ANC_SHARE_BASE 0x20000
  35. static inline unsigned int mcu_to_anc_address(unsigned int mcu_addr, uint8_t addr_type)
  36. {
  37. int anc_addr = 0;
  38. /** ptcm */
  39. if (mcu_addr >= CPU_ANC_PTCM_BASE && mcu_addr <= CPU_ANC_PTCM_BASE + ANC_PTCM_SIZE && addr_type == CODE_ADDR) {
  40. anc_addr = ANC_ANC_PTCM_BASE + (mcu_addr - CPU_ANC_PTCM_BASE) / 2;
  41. } else
  42. /** dtcm */
  43. if(mcu_addr >= CPU_ANC_DTCM_BASE && mcu_addr <= CPU_ANC_DTCM_BASE + ANC_DTCM_SIZE && addr_type == DATA_ADDR) {
  44. anc_addr = ANC_ANC_DTCM_BASE + (mcu_addr - CPU_ANC_DTCM_BASE) / 2;
  45. } else
  46. /** ext mem */
  47. if(mcu_addr >= CPU_ANC_EXTMEM_BASE && mcu_addr <= CPU_ANC_EXTMEM_BASE + ANC_EXTMEM_SIZE) {
  48. anc_addr = ANC_ANC_EXTMEM_BASE + (mcu_addr - CPU_ANC_EXTMEM_BASE) / 2;
  49. }
  50. /*share mem*/
  51. if(mcu_addr >= CPU_SHARE_BASE && mcu_addr <= CPU_SHARE_BASE + ANC_SHARE_MEM_SIZE){
  52. anc_addr = ANC_SHARE_BASE + (mcu_addr - CPU_SHARE_BASE) / 2;
  53. }
  54. //printk("mcu_addr %x anc_addr %x addr_type %d \n",mcu_addr,ANC_addr,addr_type);
  55. return anc_addr;
  56. }
  57. static inline unsigned int anc_to_mcu_address(unsigned int anc_addr, uint8_t addr_type)
  58. {
  59. int mcu_addr = -1;
  60. /** ptcm */
  61. if (anc_addr >= ANC_ANC_PTCM_BASE && anc_addr <= ANC_ANC_PTCM_BASE + ANC_PTCM_SIZE && addr_type == CODE_ADDR) {
  62. mcu_addr = CPU_ANC_PTCM_BASE + (anc_addr - ANC_ANC_PTCM_BASE) * 2;
  63. } else
  64. /** dtcm */
  65. if(anc_addr >= ANC_ANC_DTCM_BASE && anc_addr <= ANC_ANC_DTCM_BASE + ANC_DTCM_SIZE && addr_type == DATA_ADDR) {
  66. mcu_addr = CPU_ANC_DTCM_BASE + (anc_addr - ANC_ANC_DTCM_BASE) * 2;
  67. } else
  68. /** ext mem */
  69. if(anc_addr >= ANC_ANC_EXTMEM_BASE && anc_addr <= ANC_ANC_EXTMEM_BASE + ANC_EXTMEM_SIZE) {
  70. mcu_addr = CPU_ANC_EXTMEM_BASE + (anc_addr - ANC_ANC_EXTMEM_BASE) * 2;
  71. }
  72. //printk("anc_addr %x mcu_addr %x addr_type %d \n",anc_addr,mcu_addr,addr_type);
  73. return mcu_addr;
  74. }
  75. static inline unsigned int mcu_to_anc_data_address(unsigned int mcu_addr)
  76. {
  77. return mcu_to_anc_address(mcu_addr, DATA_ADDR);
  78. }
  79. static inline int get_hw_idle(void)
  80. {
  81. return sys_read32(ANC_STATUS_EXT_CTL) & PSU_ANC_IDLE;
  82. }
  83. static inline void anc_do_wait(void)
  84. {
  85. sys_write32(sys_read32(ANC_STATUS_EXT_CTL)
  86. | BIT(ANC_STATUS_EXT_CTL_ANC_WAIT_EN)
  87. | BIT(ANC_STATUS_EXT_CTL_ANC_EXTERNAL_WAIT),
  88. ANC_STATUS_EXT_CTL);
  89. }
  90. static inline void anc_undo_wait(void)
  91. {
  92. sys_write32(sys_read32(ANC_STATUS_EXT_CTL)
  93. & ~(BIT(ANC_STATUS_EXT_CTL_ANC_WAIT_EN)
  94. | BIT(ANC_STATUS_EXT_CTL_ANC_EXTERNAL_WAIT)),
  95. ANC_STATUS_EXT_CTL);
  96. }
  97. static inline void anc_init_clk(void)
  98. {
  99. /*
  100. bit20:ANCDSPDMACLK
  101. bit14:ANCDSPTIMERCLKEN
  102. bit13:ANCDSPCLKEN
  103. bit12:ANCFFIIRCLKEN
  104. bit11:ANCDSCLKEN
  105. bit10:ANCUSCLKEN
  106. */
  107. sys_write32(sys_read32(CMU_DEVCLKEN1) | ((1<<20) | (0x1f<<10)), CMU_DEVCLKEN1);
  108. //enable anc clk, pll0
  109. sys_write32(0xf0000, CMU_ANCCLK);
  110. //enable anc clk, pll1
  111. //sys_write32(0xf0100, CMU_ANCCLK);
  112. //enable ancdsp clk
  113. sys_write32(0x32, CMU_ANCDSPCLK);
  114. sys_write32(sys_read32(AUDIO_PLL0_CTL) | 0x10, AUDIO_PLL0_CTL);
  115. }
  116. static int anc_check_hw_idle(void)
  117. {
  118. return sys_read32(ANC_STATUS_EXT_CTL) & PSU_ANC_IDLE;
  119. }
  120. static inline int anc_soc_request_mem(void)
  121. {
  122. /*ptcm dtcm ram switch to anc*/
  123. sys_write32(sys_read32(CMU_MEMCLKSRC1) | 0x00000001, CMU_MEMCLKSRC1);
  124. return 0;
  125. }
  126. static inline int anc_soc_release_mem(void)
  127. {
  128. /*ptcm dtcm ram switch to mcu*/
  129. sys_write32(sys_read32(CMU_MEMCLKSRC1) & (~0x00000001), CMU_MEMCLKSRC1);
  130. return 0;
  131. }
  132. static inline void anc_soc_request_reg(void)
  133. {
  134. sys_write32(0x01, ALL_REG_ACCESS_SEL);
  135. }
  136. static inline void anc_soc_release_reg(void)
  137. {
  138. sys_write32(0x00, ALL_REG_ACCESS_SEL);
  139. }
  140. static void inline set_anc_vector_addr(unsigned int anc_addr)
  141. {
  142. sys_write32(anc_addr, ANC_VCT_ADDR);
  143. }
  144. static inline void clear_anc_irq_pending(unsigned int irq)
  145. {
  146. sys_write32(0x3, PENDING_FROM_ANC_DSP);
  147. }
  148. static inline void clear_anc_all_irq_pending(void)
  149. {
  150. sys_write32(0x3, PENDING_FROM_ANC_DSP);
  151. }
  152. static inline int do_request_anc(int in_user)
  153. {
  154. //clear info
  155. sys_write32(in_user, INFO_TO_ANC_DSP);
  156. // info
  157. sys_write32(1, INT_TO_ANC_DSP);
  158. return 0;
  159. }
  160. static inline void mcu_trigger_irq_to_anc(void)
  161. {
  162. // info
  163. sys_write32(0, INT_TO_ANC_DSP);
  164. for (int i = 0; i < 10; i ++) {
  165. ;
  166. }
  167. sys_write32(1, INT_TO_ANC_DSP);
  168. }
  169. static inline void mcu_untrigger_irq_to_anc(void)
  170. {
  171. // info
  172. // sys_write32(0, INT_TO_ANC_DSP);
  173. }
  174. static inline void anc_reset_enable(void)
  175. {
  176. int i;
  177. sys_write32(sys_read32(RMU_MRCR1) & ~((1<<30) | (1<<13) | (1<<11) | (1<<10)),RMU_MRCR1);
  178. for(i=0;i<20;i++);
  179. sys_write32(sys_read32(RMU_MRCR1) | ((1<<30) | (1<<13) | (1<<11) | (1<<10)),RMU_MRCR1);
  180. for(i=0;i<20;i++);
  181. }
  182. static inline int anc_dump_info(void)
  183. {
  184. printk("0x%x: ANC_VCT_ADDR 0x%x \n",ANC_VCT_ADDR, sys_read32(ANC_VCT_ADDR));
  185. printk("0x%x: PENDING_FROM_ANC 0x%x \n",PENDING_FROM_ANC_DSP, sys_read32(PENDING_FROM_ANC_DSP));
  186. printk("0x%x: INFO_TO_ANC 0x%x \n",INFO_TO_ANC_DSP, sys_read32(INFO_TO_ANC_DSP));
  187. printk("0x%x: ANC_VCT_ADDR 0x%x \n",ANC_VCT_ADDR, sys_read32(ANC_VCT_ADDR));
  188. printk("0x%x: RMU_MRCR1 0x%x \n",RMU_MRCR1, sys_read32(RMU_MRCR1));
  189. printk("0x%x: CMU_DEVCLKEN1 0x%x \n",CMU_DEVCLKEN1, sys_read32(CMU_DEVCLKEN1));
  190. printk("0x%x: CMU_MEMCLKSRC0 0x%x \n",CMU_MEMCLKSRC0, sys_read32(CMU_MEMCLKSRC0));
  191. printk("0x%x: CMU_MEMCLKSRC1 0x%x \n",CMU_MEMCLKSRC1, sys_read32(CMU_MEMCLKSRC1));
  192. printk("0x%x: CMU_MEMCLKSRC2 0x%x \n",CMU_MEMCLKSRC2, sys_read32(CMU_MEMCLKSRC2));
  193. printk("0x%x: MEMORYCTL 0x%x \n",MEMORY_CTL, sys_read32(MEMORY_CTL));
  194. printk("0x%x: PWRGATE_DIG 0x%x \n",PWRGATE_DIG, sys_read32(PWRGATE_DIG));
  195. printk("0x%x: CMU_ANCDSPCLK 0x%x \n",CMU_ANCDSPCLK, sys_read32(CMU_ANCDSPCLK));
  196. printk("0x%x: COREPLL_CTL 0x%x \n",COREPLL_CTL, sys_read32(COREPLL_CTL));
  197. printk("0x%x: CMU_SYSCLK 0x%x \n",CMU_SYSCLK, sys_read32(CMU_SYSCLK));
  198. printk("0x%x: CMU_ADCCLK 0x%x \n",CMU_ADCCLK, sys_read32(CMU_ADCCLK));
  199. printk("0x%x: AUDIOLDO_CTL 0x%x \n",AUDIOLDO_CTL, sys_read32(AUDIOLDO_CTL));
  200. printk("0x%x: AUDIO_PLL0_CTL 0x%x \n",AUDIO_PLL0_CTL, sys_read32(AUDIO_PLL0_CTL));
  201. printk("0x%x: AUDIO_PLL1_CTL 0x%x \n",AUDIO_PLL1_CTL, sys_read32(AUDIO_PLL1_CTL));
  202. printk("0x%x: CMU_ANCCLK 0x%x \n",CMU_ANCCLK, sys_read32(CMU_ANCCLK));
  203. printk("0x%x: ALL_REG_ACCESS_SEL 0x%x \n",ALL_REG_ACCESS_SEL, sys_read32(ALL_REG_ACCESS_SEL));
  204. return 0;
  205. }
  206. #endif /* SOC_ANC_H_ */