hda-loader.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // This file is provided under a dual BSD/GPLv2 license. When using or
  4. // redistributing this file, you may do so under either license.
  5. //
  6. // Copyright(c) 2018 Intel Corporation. All rights reserved.
  7. //
  8. // Authors: Liam Girdwood <[email protected]>
  9. // Ranjani Sridharan <[email protected]>
  10. // Rander Wang <[email protected]>
  11. // Keyon Jie <[email protected]>
  12. //
  13. /*
  14. * Hardware interface for HDA DSP code loader
  15. */
  16. #include <linux/firmware.h>
  17. #include <sound/hdaudio_ext.h>
  18. #include <sound/hda_register.h>
  19. #include <sound/sof.h>
  20. #include "ext_manifest.h"
  21. #include "../ops.h"
  22. #include "../sof-priv.h"
  23. #include "hda.h"
  24. static void hda_ssp_set_cbp_cfp(struct snd_sof_dev *sdev)
  25. {
  26. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  27. const struct sof_intel_dsp_desc *chip = hda->desc;
  28. int i;
  29. /* DSP is powered up, set all SSPs to clock consumer/codec provider mode */
  30. for (i = 0; i < chip->ssp_count; i++) {
  31. snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR,
  32. chip->ssp_base_offset
  33. + i * SSP_DEV_MEM_SIZE
  34. + SSP_SSC1_OFFSET,
  35. SSP_SET_CBP_CFP,
  36. SSP_SET_CBP_CFP);
  37. }
  38. }
  39. struct hdac_ext_stream *hda_cl_stream_prepare(struct snd_sof_dev *sdev, unsigned int format,
  40. unsigned int size, struct snd_dma_buffer *dmab,
  41. int direction)
  42. {
  43. struct hdac_ext_stream *hext_stream;
  44. struct hdac_stream *hstream;
  45. struct pci_dev *pci = to_pci_dev(sdev->dev);
  46. int ret;
  47. hext_stream = hda_dsp_stream_get(sdev, direction, 0);
  48. if (!hext_stream) {
  49. dev_err(sdev->dev, "error: no stream available\n");
  50. return ERR_PTR(-ENODEV);
  51. }
  52. hstream = &hext_stream->hstream;
  53. hstream->substream = NULL;
  54. /* allocate DMA buffer */
  55. ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, &pci->dev, size, dmab);
  56. if (ret < 0) {
  57. dev_err(sdev->dev, "error: memory alloc failed: %d\n", ret);
  58. goto out_put;
  59. }
  60. hstream->period_bytes = 0;/* initialize period_bytes */
  61. hstream->format_val = format;
  62. hstream->bufsize = size;
  63. if (direction == SNDRV_PCM_STREAM_CAPTURE) {
  64. ret = hda_dsp_iccmax_stream_hw_params(sdev, hext_stream, dmab, NULL);
  65. if (ret < 0) {
  66. dev_err(sdev->dev, "error: iccmax stream prepare failed: %d\n", ret);
  67. goto out_free;
  68. }
  69. } else {
  70. ret = hda_dsp_stream_hw_params(sdev, hext_stream, dmab, NULL);
  71. if (ret < 0) {
  72. dev_err(sdev->dev, "error: hdac prepare failed: %d\n", ret);
  73. goto out_free;
  74. }
  75. hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_ENABLE, size);
  76. }
  77. return hext_stream;
  78. out_free:
  79. snd_dma_free_pages(dmab);
  80. out_put:
  81. hda_dsp_stream_put(sdev, direction, hstream->stream_tag);
  82. return ERR_PTR(ret);
  83. }
  84. /*
  85. * first boot sequence has some extra steps.
  86. * power on all host managed cores and only unstall/run the boot core to boot the
  87. * DSP then turn off all non boot cores (if any) is powered on.
  88. */
  89. int cl_dsp_init(struct snd_sof_dev *sdev, int stream_tag, bool imr_boot)
  90. {
  91. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  92. const struct sof_intel_dsp_desc *chip = hda->desc;
  93. unsigned int status, target_status;
  94. u32 flags, ipc_hdr, j;
  95. unsigned long mask;
  96. char *dump_msg;
  97. int ret;
  98. /* step 1: power up corex */
  99. ret = hda_dsp_core_power_up(sdev, chip->host_managed_cores_mask);
  100. if (ret < 0) {
  101. if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
  102. dev_err(sdev->dev, "error: dsp core 0/1 power up failed\n");
  103. goto err;
  104. }
  105. hda_ssp_set_cbp_cfp(sdev);
  106. /* step 2: Send ROM_CONTROL command (stream_tag is ignored for IMR boot) */
  107. ipc_hdr = chip->ipc_req_mask | HDA_DSP_ROM_IPC_CONTROL;
  108. if (!imr_boot)
  109. ipc_hdr |= HDA_DSP_ROM_IPC_PURGE_FW | ((stream_tag - 1) << 9);
  110. snd_sof_dsp_write(sdev, HDA_DSP_BAR, chip->ipc_req, ipc_hdr);
  111. /* step 3: unset core 0 reset state & unstall/run core 0 */
  112. ret = hda_dsp_core_run(sdev, chip->init_core_mask);
  113. if (ret < 0) {
  114. if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
  115. dev_err(sdev->dev,
  116. "error: dsp core start failed %d\n", ret);
  117. ret = -EIO;
  118. goto err;
  119. }
  120. /* step 4: wait for IPC DONE bit from ROM */
  121. ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR,
  122. chip->ipc_ack, status,
  123. ((status & chip->ipc_ack_mask)
  124. == chip->ipc_ack_mask),
  125. HDA_DSP_REG_POLL_INTERVAL_US,
  126. HDA_DSP_INIT_TIMEOUT_US);
  127. if (ret < 0) {
  128. if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
  129. dev_err(sdev->dev,
  130. "error: %s: timeout for HIPCIE done\n",
  131. __func__);
  132. goto err;
  133. }
  134. /* set DONE bit to clear the reply IPC message */
  135. snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR,
  136. chip->ipc_ack,
  137. chip->ipc_ack_mask,
  138. chip->ipc_ack_mask);
  139. /* step 5: power down cores that are no longer needed */
  140. ret = hda_dsp_core_reset_power_down(sdev, chip->host_managed_cores_mask &
  141. ~(chip->init_core_mask));
  142. if (ret < 0) {
  143. if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
  144. dev_err(sdev->dev,
  145. "error: dsp core x power down failed\n");
  146. goto err;
  147. }
  148. /* step 6: enable IPC interrupts */
  149. hda_dsp_ipc_int_enable(sdev);
  150. /*
  151. * step 7:
  152. * - Cold/Full boot: wait for ROM init to proceed to download the firmware
  153. * - IMR boot: wait for ROM firmware entered (firmware booted up from IMR)
  154. */
  155. if (imr_boot)
  156. target_status = FSR_STATE_FW_ENTERED;
  157. else
  158. target_status = FSR_STATE_INIT_DONE;
  159. ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR,
  160. chip->rom_status_reg, status,
  161. (FSR_TO_STATE_CODE(status) == target_status),
  162. HDA_DSP_REG_POLL_INTERVAL_US,
  163. chip->rom_init_timeout *
  164. USEC_PER_MSEC);
  165. if (!ret) {
  166. /* set enabled cores mask and increment ref count for cores in init_core_mask */
  167. sdev->enabled_cores_mask |= chip->init_core_mask;
  168. mask = sdev->enabled_cores_mask;
  169. for_each_set_bit(j, &mask, SOF_MAX_DSP_NUM_CORES)
  170. sdev->dsp_core_ref_count[j]++;
  171. return 0;
  172. }
  173. if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
  174. dev_err(sdev->dev,
  175. "%s: timeout with rom_status_reg (%#x) read\n",
  176. __func__, chip->rom_status_reg);
  177. err:
  178. flags = SOF_DBG_DUMP_PCI | SOF_DBG_DUMP_MBOX | SOF_DBG_DUMP_OPTIONAL;
  179. /* after max boot attempts make sure that the dump is printed */
  180. if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
  181. flags &= ~SOF_DBG_DUMP_OPTIONAL;
  182. dump_msg = kasprintf(GFP_KERNEL, "Boot iteration failed: %d/%d",
  183. hda->boot_iteration, HDA_FW_BOOT_ATTEMPTS);
  184. snd_sof_dsp_dbg_dump(sdev, dump_msg, flags);
  185. hda_dsp_core_reset_power_down(sdev, chip->host_managed_cores_mask);
  186. kfree(dump_msg);
  187. return ret;
  188. }
  189. static int cl_trigger(struct snd_sof_dev *sdev,
  190. struct hdac_ext_stream *hext_stream, int cmd)
  191. {
  192. struct hdac_stream *hstream = &hext_stream->hstream;
  193. int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
  194. /* code loader is special case that reuses stream ops */
  195. switch (cmd) {
  196. case SNDRV_PCM_TRIGGER_START:
  197. snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
  198. 1 << hstream->index,
  199. 1 << hstream->index);
  200. snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
  201. sd_offset,
  202. SOF_HDA_SD_CTL_DMA_START |
  203. SOF_HDA_CL_DMA_SD_INT_MASK,
  204. SOF_HDA_SD_CTL_DMA_START |
  205. SOF_HDA_CL_DMA_SD_INT_MASK);
  206. hstream->running = true;
  207. return 0;
  208. default:
  209. return hda_dsp_stream_trigger(sdev, hext_stream, cmd);
  210. }
  211. }
  212. int hda_cl_cleanup(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
  213. struct hdac_ext_stream *hext_stream)
  214. {
  215. struct hdac_stream *hstream = &hext_stream->hstream;
  216. int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
  217. int ret = 0;
  218. if (hstream->direction == SNDRV_PCM_STREAM_PLAYBACK)
  219. ret = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
  220. else
  221. snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, sd_offset,
  222. SOF_HDA_SD_CTL_DMA_START, 0);
  223. hda_dsp_stream_put(sdev, hstream->direction, hstream->stream_tag);
  224. hstream->running = 0;
  225. hstream->substream = NULL;
  226. /* reset BDL address */
  227. snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
  228. sd_offset + SOF_HDA_ADSP_REG_CL_SD_BDLPL, 0);
  229. snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
  230. sd_offset + SOF_HDA_ADSP_REG_CL_SD_BDLPU, 0);
  231. snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, sd_offset, 0);
  232. snd_dma_free_pages(dmab);
  233. dmab->area = NULL;
  234. hstream->bufsize = 0;
  235. hstream->format_val = 0;
  236. return ret;
  237. }
  238. int hda_cl_copy_fw(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream)
  239. {
  240. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  241. const struct sof_intel_dsp_desc *chip = hda->desc;
  242. unsigned int reg;
  243. int ret, status;
  244. ret = cl_trigger(sdev, hext_stream, SNDRV_PCM_TRIGGER_START);
  245. if (ret < 0) {
  246. dev_err(sdev->dev, "error: DMA trigger start failed\n");
  247. return ret;
  248. }
  249. status = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR,
  250. chip->rom_status_reg, reg,
  251. (FSR_TO_STATE_CODE(reg) == FSR_STATE_FW_ENTERED),
  252. HDA_DSP_REG_POLL_INTERVAL_US,
  253. HDA_DSP_BASEFW_TIMEOUT_US);
  254. /*
  255. * even in case of errors we still need to stop the DMAs,
  256. * but we return the initial error should the DMA stop also fail
  257. */
  258. if (status < 0) {
  259. dev_err(sdev->dev,
  260. "%s: timeout with rom_status_reg (%#x) read\n",
  261. __func__, chip->rom_status_reg);
  262. }
  263. ret = cl_trigger(sdev, hext_stream, SNDRV_PCM_TRIGGER_STOP);
  264. if (ret < 0) {
  265. dev_err(sdev->dev, "error: DMA trigger stop failed\n");
  266. if (!status)
  267. status = ret;
  268. }
  269. return status;
  270. }
  271. int hda_dsp_cl_boot_firmware_iccmax(struct snd_sof_dev *sdev)
  272. {
  273. struct snd_sof_pdata *plat_data = sdev->pdata;
  274. struct hdac_ext_stream *iccmax_stream;
  275. struct hdac_bus *bus = sof_to_bus(sdev);
  276. struct firmware stripped_firmware;
  277. struct snd_dma_buffer dmab_bdl;
  278. int ret, ret1;
  279. u8 original_gb;
  280. /* save the original LTRP guardband value */
  281. original_gb = snd_hdac_chip_readb(bus, VS_LTRP) & HDA_VS_INTEL_LTRP_GB_MASK;
  282. if (plat_data->fw->size <= plat_data->fw_offset) {
  283. dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n");
  284. return -EINVAL;
  285. }
  286. stripped_firmware.size = plat_data->fw->size - plat_data->fw_offset;
  287. /* prepare capture stream for ICCMAX */
  288. iccmax_stream = hda_cl_stream_prepare(sdev, HDA_CL_STREAM_FORMAT, stripped_firmware.size,
  289. &dmab_bdl, SNDRV_PCM_STREAM_CAPTURE);
  290. if (IS_ERR(iccmax_stream)) {
  291. dev_err(sdev->dev, "error: dma prepare for ICCMAX stream failed\n");
  292. return PTR_ERR(iccmax_stream);
  293. }
  294. ret = hda_dsp_cl_boot_firmware(sdev);
  295. /*
  296. * Perform iccmax stream cleanup. This should be done even if firmware loading fails.
  297. * If the cleanup also fails, we return the initial error
  298. */
  299. ret1 = hda_cl_cleanup(sdev, &dmab_bdl, iccmax_stream);
  300. if (ret1 < 0) {
  301. dev_err(sdev->dev, "error: ICCMAX stream cleanup failed\n");
  302. /* set return value to indicate cleanup failure */
  303. if (!ret)
  304. ret = ret1;
  305. }
  306. /* restore the original guardband value after FW boot */
  307. snd_hdac_chip_updateb(bus, VS_LTRP, HDA_VS_INTEL_LTRP_GB_MASK, original_gb);
  308. return ret;
  309. }
  310. static int hda_dsp_boot_imr(struct snd_sof_dev *sdev)
  311. {
  312. const struct sof_intel_dsp_desc *chip_info;
  313. int ret;
  314. chip_info = get_chip_info(sdev->pdata);
  315. if (chip_info->cl_init)
  316. ret = chip_info->cl_init(sdev, 0, true);
  317. else
  318. ret = -EINVAL;
  319. if (!ret)
  320. hda_sdw_process_wakeen(sdev);
  321. return ret;
  322. }
  323. int hda_dsp_cl_boot_firmware(struct snd_sof_dev *sdev)
  324. {
  325. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  326. struct snd_sof_pdata *plat_data = sdev->pdata;
  327. const struct sof_dev_desc *desc = plat_data->desc;
  328. const struct sof_intel_dsp_desc *chip_info;
  329. struct hdac_ext_stream *hext_stream;
  330. struct firmware stripped_firmware;
  331. struct snd_dma_buffer dmab;
  332. int ret, ret1, i;
  333. if (hda->imrboot_supported && !sdev->first_boot && !hda->skip_imr_boot) {
  334. dev_dbg(sdev->dev, "IMR restore supported, booting from IMR directly\n");
  335. hda->boot_iteration = 0;
  336. ret = hda_dsp_boot_imr(sdev);
  337. if (!ret)
  338. return 0;
  339. dev_warn(sdev->dev, "IMR restore failed, trying to cold boot\n");
  340. }
  341. chip_info = desc->chip_info;
  342. if (plat_data->fw->size <= plat_data->fw_offset) {
  343. dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n");
  344. return -EINVAL;
  345. }
  346. stripped_firmware.data = plat_data->fw->data + plat_data->fw_offset;
  347. stripped_firmware.size = plat_data->fw->size - plat_data->fw_offset;
  348. /* init for booting wait */
  349. init_waitqueue_head(&sdev->boot_wait);
  350. /* prepare DMA for code loader stream */
  351. hext_stream = hda_cl_stream_prepare(sdev, HDA_CL_STREAM_FORMAT,
  352. stripped_firmware.size,
  353. &dmab, SNDRV_PCM_STREAM_PLAYBACK);
  354. if (IS_ERR(hext_stream)) {
  355. dev_err(sdev->dev, "error: dma prepare for fw loading failed\n");
  356. return PTR_ERR(hext_stream);
  357. }
  358. memcpy(dmab.area, stripped_firmware.data,
  359. stripped_firmware.size);
  360. /* try ROM init a few times before giving up */
  361. for (i = 0; i < HDA_FW_BOOT_ATTEMPTS; i++) {
  362. dev_dbg(sdev->dev,
  363. "Attempting iteration %d of Core En/ROM load...\n", i);
  364. hda->boot_iteration = i + 1;
  365. if (chip_info->cl_init)
  366. ret = chip_info->cl_init(sdev, hext_stream->hstream.stream_tag, false);
  367. else
  368. ret = -EINVAL;
  369. /* don't retry anymore if successful */
  370. if (!ret)
  371. break;
  372. }
  373. if (i == HDA_FW_BOOT_ATTEMPTS) {
  374. dev_err(sdev->dev, "error: dsp init failed after %d attempts with err: %d\n",
  375. i, ret);
  376. goto cleanup;
  377. }
  378. /*
  379. * When a SoundWire link is in clock stop state, a Slave
  380. * device may trigger in-band wakes for events such as jack
  381. * insertion or acoustic event detection. This event will lead
  382. * to a WAKEEN interrupt, handled by the PCI device and routed
  383. * to PME if the PCI device is in D3. The resume function in
  384. * audio PCI driver will be invoked by ACPI for PME event and
  385. * initialize the device and process WAKEEN interrupt.
  386. *
  387. * The WAKEEN interrupt should be processed ASAP to prevent an
  388. * interrupt flood, otherwise other interrupts, such IPC,
  389. * cannot work normally. The WAKEEN is handled after the ROM
  390. * is initialized successfully, which ensures power rails are
  391. * enabled before accessing the SoundWire SHIM registers
  392. */
  393. if (!sdev->first_boot)
  394. hda_sdw_process_wakeen(sdev);
  395. /*
  396. * Set the boot_iteration to the last attempt, indicating that the
  397. * DSP ROM has been initialized and from this point there will be no
  398. * retry done to boot.
  399. *
  400. * Continue with code loading and firmware boot
  401. */
  402. hda->boot_iteration = HDA_FW_BOOT_ATTEMPTS;
  403. ret = hda_cl_copy_fw(sdev, hext_stream);
  404. if (!ret) {
  405. dev_dbg(sdev->dev, "Firmware download successful, booting...\n");
  406. hda->skip_imr_boot = false;
  407. } else {
  408. snd_sof_dsp_dbg_dump(sdev, "Firmware download failed",
  409. SOF_DBG_DUMP_PCI | SOF_DBG_DUMP_MBOX);
  410. hda->skip_imr_boot = true;
  411. }
  412. cleanup:
  413. /*
  414. * Perform codeloader stream cleanup.
  415. * This should be done even if firmware loading fails.
  416. * If the cleanup also fails, we return the initial error
  417. */
  418. ret1 = hda_cl_cleanup(sdev, &dmab, hext_stream);
  419. if (ret1 < 0) {
  420. dev_err(sdev->dev, "error: Code loader DSP cleanup failed\n");
  421. /* set return value to indicate cleanup failure */
  422. if (!ret)
  423. ret = ret1;
  424. }
  425. /*
  426. * return primary core id if both fw copy
  427. * and stream clean up are successful
  428. */
  429. if (!ret)
  430. return chip_info->init_core_mask;
  431. /* disable DSP */
  432. snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR,
  433. SOF_HDA_REG_PP_PPCTL,
  434. SOF_HDA_PPCTL_GPROCEN, 0);
  435. return ret;
  436. }
  437. /* pre fw run operations */
  438. int hda_dsp_pre_fw_run(struct snd_sof_dev *sdev)
  439. {
  440. /* disable clock gating and power gating */
  441. return hda_dsp_ctrl_clock_power_gating(sdev, false);
  442. }
  443. /* post fw run operations */
  444. int hda_dsp_post_fw_run(struct snd_sof_dev *sdev)
  445. {
  446. int ret;
  447. if (sdev->first_boot) {
  448. struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
  449. ret = hda_sdw_startup(sdev);
  450. if (ret < 0) {
  451. dev_err(sdev->dev,
  452. "error: could not startup SoundWire links\n");
  453. return ret;
  454. }
  455. /* Check if IMR boot is usable */
  456. if (!sof_debug_check_flag(SOF_DBG_IGNORE_D3_PERSISTENT) &&
  457. (sdev->fw_ready.flags & SOF_IPC_INFO_D3_PERSISTENT ||
  458. sdev->pdata->ipc_type == SOF_INTEL_IPC4))
  459. hdev->imrboot_supported = true;
  460. }
  461. hda_sdw_int_enable(sdev, true);
  462. /* re-enable clock gating and power gating */
  463. return hda_dsp_ctrl_clock_power_gating(sdev, true);
  464. }
  465. int hda_dsp_ext_man_get_cavs_config_data(struct snd_sof_dev *sdev,
  466. const struct sof_ext_man_elem_header *hdr)
  467. {
  468. const struct sof_ext_man_cavs_config_data *config_data =
  469. container_of(hdr, struct sof_ext_man_cavs_config_data, hdr);
  470. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  471. int i, elem_num;
  472. /* calculate total number of config data elements */
  473. elem_num = (hdr->size - sizeof(struct sof_ext_man_elem_header))
  474. / sizeof(struct sof_config_elem);
  475. if (elem_num <= 0) {
  476. dev_err(sdev->dev, "cavs config data is inconsistent: %d\n", elem_num);
  477. return -EINVAL;
  478. }
  479. for (i = 0; i < elem_num; i++)
  480. switch (config_data->elems[i].token) {
  481. case SOF_EXT_MAN_CAVS_CONFIG_EMPTY:
  482. /* skip empty token */
  483. break;
  484. case SOF_EXT_MAN_CAVS_CONFIG_CAVS_LPRO:
  485. hda->clk_config_lpro = config_data->elems[i].value;
  486. dev_dbg(sdev->dev, "FW clock config: %s\n",
  487. hda->clk_config_lpro ? "LPRO" : "HPRO");
  488. break;
  489. case SOF_EXT_MAN_CAVS_CONFIG_OUTBOX_SIZE:
  490. case SOF_EXT_MAN_CAVS_CONFIG_INBOX_SIZE:
  491. /* These elements are defined but not being used yet. No warn is required */
  492. break;
  493. default:
  494. dev_info(sdev->dev, "unsupported token type: %d\n",
  495. config_data->elems[i].token);
  496. }
  497. return 0;
  498. }