audio_acts_utils.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*
  2. * Copyright (c) 2020 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Common utils for in/out audio drivers
  9. */
  10. #include <kernel.h>
  11. #include <device.h>
  12. #include <string.h>
  13. #include <errno.h>
  14. #include <soc.h>
  15. #include "audio_acts_utils.h"
  16. #include "../phy_audio_common.h"
  17. #include <logging/log.h>
  18. LOG_MODULE_REGISTER(autils, CONFIG_LOG_DEFAULT_LEVEL);
  19. /*
  20. * @brief AUDIO PLL clock selection
  21. */
  22. #define CMU_AUDIOPLL0_LOCK (8)
  23. #define CMU_AUDIOPLL0_CTL_EN (7)
  24. #define CMU_AUDIOPLL0_CTL_APS0_SHIFT (0)
  25. #define CMU_AUDIOPLL0_CTL_APS0(x) ((x) << CMU_AUDIOPLL0_CTL_APS0_SHIFT)
  26. #define CMU_AUDIOPLL0_CTL_APS0_MASK CMU_AUDIOPLL0_CTL_APS0(0x3F)
  27. /* 48ksr serials */
  28. #define PLL_65536 (65536000)
  29. #define PLL_49152 (49152000)
  30. #define PLL_24576 (24576000)
  31. #define PLL_16384 (16384000)
  32. #define PLL_12288 (12288000)
  33. #define PLL_8192 (8192000)
  34. #define PLL_6144 (6144000)
  35. #define PLL_4096 (4096000)
  36. #define PLL_3072 (3072000)
  37. #define PLL_2048 (2048000)
  38. #define PLL_1024 (1024000)
  39. /* 44.1ksr serials */
  40. #define PLL_602112 (60211200)
  41. #define PLL_451584 (45158400)
  42. #define PLL_225792 (22579200)
  43. #define PLL_112896 (11289600)
  44. #define PLL_56448 (5644800)
  45. #define PLL_28224 (2822400)
  46. /*
  47. * struct audio_dac_pll_t
  48. * @brief The structure includes the dac pll clock and its setting parameters
  49. */
  50. typedef struct {
  51. audio_sr_sel_e sr_khz; /* audio sr_khz clock */
  52. uint8_t div;
  53. uint8_t fir_div;
  54. uint8_t fir2x_div;
  55. uint8_t cic_div;
  56. } audio_dac_pll_t;
  57. static const audio_dac_pll_t audio_dac_pll_selections[] = {
  58. {SAMPLE_RATE_96KHZ, 0, 0, 0, 1}, /* 48ksr series */
  59. {SAMPLE_RATE_48KHZ, 0, 0, 1, 1}, /* 48ksr series */
  60. {SAMPLE_RATE_32KHZ, 0, 0, 2, 1}, /* 48ksr series */
  61. {SAMPLE_RATE_24KHZ, 1, 0, 1, 0}, /* 48ksr series */
  62. {SAMPLE_RATE_16KHZ, 1, 0, 2, 0}, /* 48ksr series */
  63. {SAMPLE_RATE_12KHZ, 1, 1, 1, 0}, /* 48ksr series */
  64. {SAMPLE_RATE_8KHZ, 1, 1, 2, 0}, /* 48ksr series */
  65. {SAMPLE_RATE_88KHZ, 0, 0, 0, 1}, /* 44.1ksr series */
  66. {SAMPLE_RATE_44KHZ, 0, 0, 1, 1}, /* 44.1ksr series */
  67. {SAMPLE_RATE_22KHZ, 1, 0, 1, 0}, /* 44.1ksr series */
  68. {SAMPLE_RATE_11KHZ, 1, 1, 1, 0}, /* 44.1ksr series */
  69. };
  70. /*
  71. * struct audio_pll_t
  72. * @brief The structure includes the pll clock and its setting parameters
  73. */
  74. typedef struct {
  75. uint32_t pll_clk; /* audio pll clock */
  76. uint8_t pre_div; /* clock pre-divisor */
  77. uint8_t clk_div; /* clock divisor */
  78. } audio_pll_t;
  79. static const audio_pll_t audio_pll_selections[] = {
  80. {PLL_49152, 0, 0}, /* 48ksr series */
  81. {PLL_24576, 0, 1}, /* 48ksr series */
  82. {PLL_16384, 0, 2}, /* 48ksr series */
  83. {PLL_12288, 0, 3}, /* 48ksr series */
  84. {PLL_8192, 0, 4}, /* 48ksr series */
  85. {PLL_6144, 0, 5}, /* 48ksr series */
  86. {PLL_4096, 0, 6}, /* 48ksr series */
  87. {PLL_3072, 1, 5}, /* 48ksr series */
  88. {PLL_2048, 1, 6}, /* 48ksr series */
  89. {PLL_451584, 0, 0}, /* 44.1ksr series */
  90. {PLL_225792, 0, 1}, /* 44.1ksr series */
  91. {PLL_112896, 0, 3}, /* 44.1ksr series */
  92. {PLL_56448, 0, 5}, /* 44.1ksr series */
  93. {PLL_28224, 1, 5} /* 44.1ksr series */
  94. };
  95. /*
  96. * struct audio_i2s_pll_t
  97. * @brief The structure includes the pll clock and its setting parameters version2 for i2s
  98. */
  99. typedef struct {
  100. uint32_t pll_clk; /* audio pll clock */
  101. uint8_t clk_div; /* divison */
  102. } audio_i2s_pll_t;
  103. static const audio_i2s_pll_t audio_i2s_pll_selections[] = {
  104. {PLL_65536, 0}, /* 48ksr series */
  105. {PLL_49152, 1}, /* 48ksr series */
  106. {PLL_24576, 3}, /* 48ksr series */
  107. {PLL_16384, 4}, /* 48ksr series */
  108. {PLL_12288, 5}, /* 48ksr series */
  109. {PLL_8192, 6}, /* 48ksr series */
  110. {PLL_6144, 7}, /* 48ksr series */
  111. {PLL_4096, 8}, /* 48ksr series */
  112. {PLL_3072, 9}, /* 48ksr series */
  113. {PLL_2048, 10}, /* 48ksr series */
  114. {PLL_1024, 11}, /* 48ksr series */
  115. {PLL_602112, 0}, /* 44.1ksr series */
  116. {PLL_451584, 1}, /* 44.1ksr series */
  117. {PLL_225792, 3}, /* 44.1ksr series */
  118. {PLL_112896, 5}, /* 44.1ksr series */
  119. {PLL_56448, 7}, /* 44.1ksr series */
  120. {PLL_28224, 9} /* 44.1ksr series */
  121. };
  122. #ifdef CONFIG_AUDIO_DEBUG_TRACE
  123. /* audio debug trace global object */
  124. struct audio_debug_trace_t audio_debug_trace;
  125. #endif
  126. static uint8_t audiopll0_refcount;
  127. // static uint8_t audiopll1_refcount;
  128. int8_t adc_reset_count = 0;
  129. void adc_reset_control(bool enable)
  130. {
  131. #if CONFIG_MIC_PIN_GPIO
  132. return;
  133. #else
  134. uint32_t key = irq_lock();
  135. if (enable == 1)
  136. adc_reset_count++;
  137. else
  138. adc_reset_count--;
  139. if (adc_reset_count < 0) {
  140. LOG_WRN("adc_reset_count < 0\n");
  141. adc_reset_count = 0;
  142. }
  143. irq_unlock(key);
  144. LOG_DBG("adc_reset_count:==%d\n", adc_reset_count);
  145. if (adc_reset_count != 0) {
  146. acts_reset_peripheral_deassert(RESET_ID_ADC);
  147. LOG_DBG("reset ADC\n");
  148. } else {
  149. acts_reset_peripheral_assert(RESET_ID_ADC);
  150. LOG_DBG("reset_assert ADC\n");
  151. }
  152. return;
  153. #endif
  154. }
  155. /* @brief Translate the sample rate from KHz to Hz */
  156. uint32_t audio_sr_khz_to_hz(audio_sr_sel_e sr_khz)
  157. {
  158. uint32_t ret_sample_hz;
  159. if (!(sr_khz % SAMPLE_RATE_11KHZ)) {
  160. /* 44.1KHz serials */
  161. ret_sample_hz = (sr_khz / SAMPLE_RATE_11KHZ) * 11025;
  162. } else {
  163. /* 48KHz serials */
  164. ret_sample_hz = sr_khz * 1000;
  165. }
  166. return ret_sample_hz;
  167. }
  168. /* @brief Translate the sample rate from Hz to KHz */
  169. audio_sr_sel_e audio_sr_hz_to_Khz(uint32_t sr_hz)
  170. {
  171. uint32_t sr_khz;
  172. if (!(sr_hz % 11025)) {
  173. sr_khz = (sr_hz / 11025) * SAMPLE_RATE_11KHZ;
  174. } else {
  175. sr_khz = sr_hz / 1000;
  176. }
  177. return (audio_sr_sel_e)sr_khz;
  178. }
  179. /* @brief Get the audio pll setting by specified sample rate and mclk*/
  180. int audio_get_pll_setting(audio_sr_sel_e sr_khz, a_mclk_type_e mclk,
  181. uint8_t *pre_div, uint8_t *clk_div, uint8_t *series)
  182. {
  183. uint32_t sr_hz;
  184. int i;
  185. /* FPGA audio_pll main clock is 24Mhz, but the formal chipset is 98.304Mhz */
  186. #ifdef CONFIG_SOC_SERIES_LEOPARD_FPGA
  187. sr_khz *= 4;
  188. #endif
  189. sr_hz = audio_sr_khz_to_hz(sr_khz);
  190. /* calculate the constant clock */
  191. sr_hz *= mclk;
  192. for (i = 0; i < ARRAY_SIZE(audio_pll_selections); i++) {
  193. if (sr_hz == audio_pll_selections[i].pll_clk) {
  194. *pre_div = audio_pll_selections[i].pre_div;
  195. *clk_div = audio_pll_selections[i].clk_div;
  196. if (i > 8)
  197. *series = AUDIOPLL_44KSR;
  198. else
  199. *series = AUDIOPLL_48KSR;
  200. break;
  201. }
  202. }
  203. /* Can not find the corresponding PLL setting */
  204. if (i == ARRAY_SIZE(audio_pll_selections)) {
  205. LOG_ERR("Failed to find audio pll setting sr:%d", sr_khz);
  206. *pre_div = 0xFF;
  207. *pre_div = 0xFF;
  208. *series = 0xFF;
  209. return -ENOEXEC;
  210. }
  211. LOG_DBG("sr_khz %d sr_hz %d, pre_div %d, clk_div %d", sr_khz, sr_hz, *pre_div, *clk_div);
  212. return 0;
  213. }
  214. /* @brief Get the audio pll setting by specified sample rate and mclk for i2s*/
  215. int audio_get_pll_setting_i2s(uint16_t sr_khz, a_mclk_type_e mclk,
  216. uint8_t *div, uint8_t *series)
  217. {
  218. uint32_t sr_hz=0;
  219. int i;
  220. /* FPGA audio_pll main clock is 24Mhz, but the formal chipset is 98.304Mhz */
  221. #ifdef CONFIG_SOC_SERIES_LARK_FPGA
  222. sr_khz *= 4;
  223. #endif
  224. #ifdef CONFIG_SOC_SERIES_LEOPARD_FPGA
  225. sr_khz *= 4;
  226. #endif
  227. /* in case of MCLK from internal in slave mode */
  228. if (384 == sr_khz) { /* MCLK = 192fs x 2 */
  229. *series = AUDIOPLL_48KSR;
  230. *div = 0;
  231. } else if (352 == sr_khz) { /* MCLK = 176fs x 2 */
  232. *series = AUDIOPLL_44KSR;
  233. *div = 0;
  234. } else {
  235. sr_hz = audio_sr_khz_to_hz(sr_khz);
  236. /* calculate the constant clock */
  237. sr_hz *= mclk;
  238. for (i = 0; i < ARRAY_SIZE(audio_i2s_pll_selections); i++) {
  239. if (sr_hz == audio_i2s_pll_selections[i].pll_clk) {
  240. *div = audio_i2s_pll_selections[i].clk_div;
  241. if (i > 10)
  242. *series = AUDIOPLL_44KSR;
  243. else
  244. *series = AUDIOPLL_48KSR;
  245. break;
  246. }
  247. }
  248. /* Can not find the corresponding PLL setting */
  249. if (i == ARRAY_SIZE(audio_i2s_pll_selections)) {
  250. LOG_ERR("Failed to find audio pll setting sr:%d mclk:%d", sr_khz, mclk);
  251. *div = 0xFF;
  252. *series = 0xFF;
  253. return -ENOEXEC;
  254. }
  255. }
  256. LOG_INF("sr_khz %d sr_hz %d, div %d", sr_khz, sr_hz, *div);
  257. return 0;
  258. }
  259. /* @brief Get the audio pll usage info by the pll index */
  260. static int audio_pll_get_usage(a_pll_type_e index, uint8_t *series)
  261. {
  262. /* AUDIO_PLL0 */
  263. if (AUDIOPLL_TYPE_0 == index) {
  264. /* check AUDIO_PLL0 enable or not */
  265. if ((sys_read32(AUDIO_PLL0_CTL) & (1 << CMU_AUDIOPLL0_CTL_EN)) == 0) {
  266. /* AUDIO_PLL0 disable */
  267. *series = 0xFF;
  268. } else if((sys_read32(AUDIO_PLL0_CTL) & CMU_AUDIOPLL0_CTL_APS0_MASK) >= 8) {
  269. /* AUDIO_PLL0 is 48k series */
  270. *series = AUDIOPLL_48KSR;
  271. } else {
  272. /* AUDIO_PLL0 is 44.1k series */
  273. *series = AUDIOPLL_44KSR;
  274. }
  275. } else {
  276. LOG_ERR("Invalid AUDIO_PLL type %d", index);
  277. return -EINVAL;
  278. }
  279. LOG_INF("use AUDIO_PLL@%d => series:0x%x", index, *series);
  280. return 0;
  281. }
  282. /* @brief Get the audio pll aps by specified pll index */
  283. int audio_pll_get_aps(a_pll_type_e index)
  284. {
  285. uint32_t reg = -1;
  286. if (AUDIOPLL_TYPE_0 == index) {
  287. if ((sys_read32(AUDIO_PLL0_CTL) & (1 << CMU_AUDIOPLL0_CTL_EN)) == 0) {
  288. LOG_ERR("AUDIO_PLL0 is not enable yet");
  289. return -EPERM;
  290. }
  291. reg = sys_read32(AUDIO_PLL0_CTL) & CMU_AUDIOPLL0_CTL_APS0_MASK;
  292. if (reg >= 8) {
  293. /* 48KHz sample rate seires */
  294. reg -= 8;
  295. }
  296. } else {
  297. LOG_ERR("Invalid AUDIO_PLL type %d", index);
  298. return -EINVAL;
  299. }
  300. return reg;
  301. }
  302. /* @brief Set the audio pll aps by specified pll index */
  303. int audio_pll_set_aps(a_pll_type_e index, audio_aps_level_e level)
  304. {
  305. uint32_t reg;
  306. if (level > APS_LEVEL_8) {
  307. LOG_ERR("Invalid APS level setting %d", level);
  308. return -EINVAL;
  309. }
  310. if (AUDIOPLL_TYPE_0 == index) {
  311. if ((sys_read32(AUDIO_PLL0_CTL) & (1 << CMU_AUDIOPLL0_CTL_EN)) == 0) {
  312. LOG_INF("AUDIO_PLL0 is not enable");
  313. return -EPERM;
  314. }
  315. reg = sys_read32(AUDIO_PLL0_CTL);
  316. if ((reg & CMU_AUDIOPLL0_CTL_APS0_MASK) >= 8) /* 48KHz sample rate seires */
  317. level += 8;
  318. reg &= ~CMU_AUDIOPLL0_CTL_APS0_MASK;
  319. sys_write32(reg | CMU_AUDIOPLL0_CTL_APS0(level), AUDIO_PLL0_CTL);
  320. } else {
  321. LOG_ERR("Invalid AUDIO_PLL type %d", index);
  322. return -EINVAL;
  323. }
  324. return 0;
  325. }
  326. /* @brief Get the src clock in HZ for the sample rate translation */
  327. int audio_get_pll_sample_rate_dac(uint8_t div, uint8_t fir_div,
  328. uint8_t fir2x_div, uint8_t cic_div, a_pll_type_e index)
  329. {
  330. uint8_t series, start, end;
  331. int ret, i;
  332. ret = audio_pll_get_usage(index, &series);
  333. if (ret)
  334. return ret;
  335. if (AUDIOPLL_48KSR == series) {
  336. start = 0;
  337. end = 7;
  338. } else if (AUDIOPLL_44KSR == series) {
  339. start = 7;
  340. end = ARRAY_SIZE(audio_dac_pll_selections);
  341. } else {
  342. LOG_ERR("Error series %d", series);
  343. return -EPERM;
  344. }
  345. for (i = start; i < end; i++) {
  346. if ((audio_dac_pll_selections[i].div == div)
  347. && ((audio_dac_pll_selections[i].fir_div) == fir_div)
  348. && ((audio_dac_pll_selections[i].fir2x_div) == fir2x_div)
  349. && ((audio_dac_pll_selections[i].cic_div) == cic_div)) {
  350. ret = audio_dac_pll_selections[i].sr_khz;
  351. ret = (int)audio_sr_hz_to_Khz(ret);
  352. break;
  353. }
  354. }
  355. if (i == end) {
  356. LOG_ERR("Failed to translate sr div:%d fir_div%d fir2x_div:%d cic_div:%d index %d"
  357. ,div, fir_div, fir2x_div, cic_div, index);
  358. ret = -EFAULT;
  359. }
  360. return ret;
  361. }
  362. /* @brief Get the dac pll setting by specified sample rate */
  363. int audio_get_pll_setting_dac(audio_sr_sel_e sr_khz,uint8_t *div,
  364. uint8_t *fir_div,uint8_t *fir2x_div, uint8_t *cic_div,uint8_t *series)
  365. {
  366. int i;
  367. /* FPGA audio_pll main clock is 24Mhz, but the formal chipset is 98.304Mhz */
  368. #ifdef CONFIG_SOC_SERIES_LEOPARD_FPGA
  369. sr_khz *= 4;
  370. #endif
  371. for (i = 0; i < ARRAY_SIZE(audio_dac_pll_selections); i++) {
  372. if (sr_khz == audio_dac_pll_selections[i].sr_khz) {
  373. *div = audio_dac_pll_selections[i].div;
  374. *fir_div = audio_dac_pll_selections[i].fir_div;
  375. *fir2x_div = audio_dac_pll_selections[i].fir2x_div;
  376. *cic_div = audio_dac_pll_selections[i].cic_div;
  377. if (i > 6)
  378. *series = AUDIOPLL_44KSR;
  379. else
  380. *series = AUDIOPLL_48KSR;
  381. break;
  382. }
  383. }
  384. /* Can not find the corresponding PLL setting */
  385. if (i == ARRAY_SIZE(audio_dac_pll_selections)) {
  386. LOG_ERR("Failed to find audio pll setting sr:%d", sr_khz);
  387. *series = 0xFF;
  388. return -ENOEXEC;
  389. }
  390. LOG_DBG("sr_khz:%d div:%d, fir_div:%d, fir2x_div:%d, cic_div:%d, series:%d",
  391. sr_khz, *div,*fir_div, *fir2x_div, *cic_div, *series);
  392. return 0;
  393. }
  394. /* @brief Get the pll clock in HZ for the sample rate translation */
  395. int audio_get_pll_sample_rate(a_mclk_type_e mclk, uint8_t pre_div, uint8_t clk_div, a_pll_type_e index)
  396. {
  397. uint8_t series, start, end;
  398. int ret, i;
  399. ret = audio_pll_get_usage(index, &series);
  400. if (ret)
  401. return ret;
  402. if (AUDIOPLL_48KSR == series) {
  403. start = 0;
  404. end = 9;
  405. } else if (AUDIOPLL_44KSR == series) {
  406. start = 9;
  407. end = ARRAY_SIZE(audio_pll_selections);
  408. } else {
  409. LOG_ERR("Error series %d", series);
  410. return -EPERM;
  411. }
  412. for (i = start; i < end; i++) {
  413. if ((audio_pll_selections[i].pre_div == pre_div)
  414. && (audio_pll_selections[i].clk_div) == clk_div) {
  415. ret = audio_pll_selections[i].pll_clk / mclk;
  416. ret = (int)audio_sr_hz_to_Khz(ret);
  417. break;
  418. }
  419. }
  420. if (i == end) {
  421. LOG_ERR("Failed to translate sr pre_div:%d clk_div%d pll_index:%d",
  422. pre_div, clk_div, index);
  423. ret = -EFAULT;
  424. }
  425. return ret;
  426. }
  427. /* @brief Get the pll clock in HZ for the sample rate translation for i2s */
  428. int audio_get_pll_sample_rate_i2s(a_mclk_type_e mclk, uint8_t clk_div, a_pll_type_e index)
  429. {
  430. uint8_t series, start, end;
  431. int ret, i;
  432. ret = audio_pll_get_usage(index, &series);
  433. if (ret)
  434. return ret;
  435. if (AUDIOPLL_48KSR == series) {
  436. start = 0;
  437. end = 11;
  438. } else if (AUDIOPLL_44KSR == series) {
  439. start = 11;
  440. end = ARRAY_SIZE(audio_i2s_pll_selections);
  441. } else {
  442. LOG_ERR("Error series %d", series);
  443. return -EPERM;
  444. }
  445. for (i = start; i < end; i++) {
  446. if (audio_i2s_pll_selections[i].clk_div == clk_div) {
  447. ret = audio_i2s_pll_selections[i].pll_clk / mclk;
  448. /* 235.2kfs is not divisible by 11025 */
  449. if (235200 == ret)
  450. ret = 235;
  451. else
  452. ret = (int)audio_sr_hz_to_Khz(ret);
  453. break;
  454. }
  455. }
  456. if (i == end) {
  457. LOG_ERR("Failed to translate sr clk_div%d pll_index:%d",
  458. clk_div, index);
  459. ret = -EFAULT;
  460. }
  461. return ret;
  462. }
  463. /* @brief audio pll set */
  464. void audio_pll_set(a_pll_type_e index, a_pll_series_e series)
  465. {
  466. uint32_t reg;
  467. /* Enable AUDIO_PLL */
  468. reg = sys_read32(AUDIO_PLL0_CTL) & (~CMU_AUDIOPLL0_CTL_APS0_MASK);
  469. reg |= (1 << CMU_AUDIOPLL0_CTL_EN);
  470. if (AUDIOPLL_44KSR == series)
  471. reg |= (0x04 << CMU_AUDIOPLL0_CTL_APS0_SHIFT);
  472. else
  473. reg |= (0x0c << CMU_AUDIOPLL0_CTL_APS0_SHIFT);
  474. sys_write32(reg, AUDIO_PLL0_CTL);
  475. ++audiopll0_refcount;
  476. LOG_DBG("audio_pll_set_AUDIO_PLL0_CTL - 0x%x", sys_read32(AUDIO_PLL0_CTL));
  477. }
  478. /* @brief unset audio pll */
  479. void audio_pll_unset(a_pll_type_e index)
  480. {
  481. --audiopll0_refcount;
  482. if (!audiopll0_refcount)
  483. sys_write32(0, AUDIO_PLL0_CTL);
  484. }
  485. /* @brief Check and config the audio pll */
  486. int audio_pll_check_config(a_pll_series_e series, uint8_t *index)
  487. {
  488. int ret;
  489. uint8_t get_series, pll_index = 0xFF;
  490. ret = audio_pll_get_usage(AUDIOPLL_TYPE_0, &get_series);
  491. if (ret) {
  492. LOG_ERR("Get AUDIO_PLL0 error %d", ret);
  493. return ret;
  494. }
  495. pll_index = AUDIOPLL_TYPE_0;
  496. if (0xFF == pll_index) {
  497. LOG_ERR("Failed to find the available pll %d", series);
  498. LOG_INF("AUDIO_PLL0: 0x%x", sys_read32(AUDIO_PLL0_CTL));
  499. LOG_INF("AUDIO_PLL1: 0x%x", sys_read32(AUDIO_PLL1_CTL));
  500. *index = 0xFF;
  501. return -ENOENT;
  502. }
  503. *index = pll_index;
  504. audio_pll_set(pll_index, series);
  505. return 0;
  506. }