xref: /openbmc/linux/sound/soc/sof/intel/hda-loader.c (revision 38bf0780)
1e149ca29SPierre-Louis Bossart // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2d16046ffSLiam Girdwood //
3d16046ffSLiam Girdwood // This file is provided under a dual BSD/GPLv2 license.  When using or
4d16046ffSLiam Girdwood // redistributing this file, you may do so under either license.
5d16046ffSLiam Girdwood //
6d16046ffSLiam Girdwood // Copyright(c) 2018 Intel Corporation. All rights reserved.
7d16046ffSLiam Girdwood //
8d16046ffSLiam Girdwood // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9d16046ffSLiam Girdwood //	    Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
10d16046ffSLiam Girdwood //	    Rander Wang <rander.wang@intel.com>
11d16046ffSLiam Girdwood //          Keyon Jie <yang.jie@linux.intel.com>
12d16046ffSLiam Girdwood //
13d16046ffSLiam Girdwood 
14d16046ffSLiam Girdwood /*
15d16046ffSLiam Girdwood  * Hardware interface for HDA DSP code loader
16d16046ffSLiam Girdwood  */
17d16046ffSLiam Girdwood 
18d16046ffSLiam Girdwood #include <linux/firmware.h>
19d16046ffSLiam Girdwood #include <sound/hdaudio_ext.h>
20acf705a4SRanjani Sridharan #include <sound/hda_register.h>
21d16046ffSLiam Girdwood #include <sound/sof.h>
223ab2c21eSPeter Ujfalusi #include <sound/sof/ipc4/header.h>
23edbaaadaSFred Oh #include "ext_manifest.h"
243ab2c21eSPeter Ujfalusi #include "../ipc4-priv.h"
25d16046ffSLiam Girdwood #include "../ops.h"
26d7a8fbd1SKeyon Jie #include "../sof-priv.h"
27d16046ffSLiam Girdwood #include "hda.h"
28d16046ffSLiam Girdwood 
29a749d744SKeyon Jie static void hda_ssp_set_cbp_cfp(struct snd_sof_dev *sdev)
30a749d744SKeyon Jie {
31a749d744SKeyon Jie 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
32a749d744SKeyon Jie 	const struct sof_intel_dsp_desc *chip = hda->desc;
33a749d744SKeyon Jie 	int i;
34a749d744SKeyon Jie 
35a749d744SKeyon Jie 	/* DSP is powered up, set all SSPs to clock consumer/codec provider mode */
36a749d744SKeyon Jie 	for (i = 0; i < chip->ssp_count; i++) {
37a749d744SKeyon Jie 		snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR,
38a749d744SKeyon Jie 						 chip->ssp_base_offset
39a749d744SKeyon Jie 						 + i * SSP_DEV_MEM_SIZE
40a749d744SKeyon Jie 						 + SSP_SSC1_OFFSET,
41a749d744SKeyon Jie 						 SSP_SET_CBP_CFP,
42a749d744SKeyon Jie 						 SSP_SET_CBP_CFP);
43a749d744SKeyon Jie 	}
44a749d744SKeyon Jie }
45a749d744SKeyon Jie 
46b4e4c0b9SRanjani Sridharan struct hdac_ext_stream *hda_cl_stream_prepare(struct snd_sof_dev *sdev, unsigned int format,
47d16046ffSLiam Girdwood 					      unsigned int size, struct snd_dma_buffer *dmab,
48d16046ffSLiam Girdwood 					      int direction)
49d16046ffSLiam Girdwood {
507d88b960SPierre-Louis Bossart 	struct hdac_ext_stream *hext_stream;
51d16046ffSLiam Girdwood 	struct hdac_stream *hstream;
52d16046ffSLiam Girdwood 	struct pci_dev *pci = to_pci_dev(sdev->dev);
53d16046ffSLiam Girdwood 	int ret;
54d16046ffSLiam Girdwood 
557d88b960SPierre-Louis Bossart 	hext_stream = hda_dsp_stream_get(sdev, direction, 0);
56d16046ffSLiam Girdwood 
577d88b960SPierre-Louis Bossart 	if (!hext_stream) {
58d16046ffSLiam Girdwood 		dev_err(sdev->dev, "error: no stream available\n");
5901d42d5aSRanjani Sridharan 		return ERR_PTR(-ENODEV);
60d16046ffSLiam Girdwood 	}
617d88b960SPierre-Louis Bossart 	hstream = &hext_stream->hstream;
624ff5f643SKai Vehmanen 	hstream->substream = NULL;
63d16046ffSLiam Girdwood 
64d16046ffSLiam Girdwood 	/* allocate DMA buffer */
65d16046ffSLiam Girdwood 	ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, &pci->dev, size, dmab);
66d16046ffSLiam Girdwood 	if (ret < 0) {
67ce1f55baSCurtis Malainey 		dev_err(sdev->dev, "error: memory alloc failed: %d\n", ret);
68b7fb0ae0SAmmar Faizi 		goto out_put;
69d16046ffSLiam Girdwood 	}
70d16046ffSLiam Girdwood 
71d16046ffSLiam Girdwood 	hstream->period_bytes = 0;/* initialize period_bytes */
72d16046ffSLiam Girdwood 	hstream->format_val = format;
73d16046ffSLiam Girdwood 	hstream->bufsize = size;
74d16046ffSLiam Girdwood 
75acf705a4SRanjani Sridharan 	if (direction == SNDRV_PCM_STREAM_CAPTURE) {
767d88b960SPierre-Louis Bossart 		ret = hda_dsp_iccmax_stream_hw_params(sdev, hext_stream, dmab, NULL);
77acf705a4SRanjani Sridharan 		if (ret < 0) {
78ce1f55baSCurtis Malainey 			dev_err(sdev->dev, "error: iccmax stream prepare failed: %d\n", ret);
79b7fb0ae0SAmmar Faizi 			goto out_free;
80acf705a4SRanjani Sridharan 		}
81acf705a4SRanjani Sridharan 	} else {
827d88b960SPierre-Louis Bossart 		ret = hda_dsp_stream_hw_params(sdev, hext_stream, dmab, NULL);
83d16046ffSLiam Girdwood 		if (ret < 0) {
84ce1f55baSCurtis Malainey 			dev_err(sdev->dev, "error: hdac prepare failed: %d\n", ret);
85b7fb0ae0SAmmar Faizi 			goto out_free;
86d16046ffSLiam Girdwood 		}
877d88b960SPierre-Louis Bossart 		hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_ENABLE, size);
88acf705a4SRanjani Sridharan 	}
89d16046ffSLiam Girdwood 
907d88b960SPierre-Louis Bossart 	return hext_stream;
91d16046ffSLiam Girdwood 
92b7fb0ae0SAmmar Faizi out_free:
93d16046ffSLiam Girdwood 	snd_dma_free_pages(dmab);
94b7fb0ae0SAmmar Faizi out_put:
95b7fb0ae0SAmmar Faizi 	hda_dsp_stream_put(sdev, direction, hstream->stream_tag);
9601d42d5aSRanjani Sridharan 	return ERR_PTR(ret);
97d16046ffSLiam Girdwood }
98d16046ffSLiam Girdwood 
99d16046ffSLiam Girdwood /*
1004643e10aSPeter Ujfalusi  * first boot sequence has some extra steps.
1014643e10aSPeter Ujfalusi  * power on all host managed cores and only unstall/run the boot core to boot the
1024643e10aSPeter Ujfalusi  * DSP then turn off all non boot cores (if any) is powered on.
103d16046ffSLiam Girdwood  */
104ab222a4aSBard Liao int cl_dsp_init(struct snd_sof_dev *sdev, int stream_tag, bool imr_boot)
105d16046ffSLiam Girdwood {
106d16046ffSLiam Girdwood 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
107d16046ffSLiam Girdwood 	const struct sof_intel_dsp_desc *chip = hda->desc;
1082a68ff84SPeter Ujfalusi 	unsigned int status, target_status;
1092a68ff84SPeter Ujfalusi 	u32 flags, ipc_hdr, j;
110d4165199SRanjani Sridharan 	unsigned long mask;
1112f148430SPeter Ujfalusi 	char *dump_msg;
112d16046ffSLiam Girdwood 	int ret;
113d16046ffSLiam Girdwood 
114d16046ffSLiam Girdwood 	/* step 1: power up corex */
115fcb3c775SPeter Ujfalusi 	ret = hda_dsp_core_power_up(sdev, chip->host_managed_cores_mask);
116d16046ffSLiam Girdwood 	if (ret < 0) {
117776100a4SPierre-Louis Bossart 		if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
118d16046ffSLiam Girdwood 			dev_err(sdev->dev, "error: dsp core 0/1 power up failed\n");
119d16046ffSLiam Girdwood 		goto err;
120d16046ffSLiam Girdwood 	}
121d16046ffSLiam Girdwood 
122a749d744SKeyon Jie 	hda_ssp_set_cbp_cfp(sdev);
12374ed4097SZhu Yingjiang 
1242a68ff84SPeter Ujfalusi 	/* step 2: Send ROM_CONTROL command (stream_tag is ignored for IMR boot) */
1252a68ff84SPeter Ujfalusi 	ipc_hdr = chip->ipc_req_mask | HDA_DSP_ROM_IPC_CONTROL;
1262a68ff84SPeter Ujfalusi 	if (!imr_boot)
1272a68ff84SPeter Ujfalusi 		ipc_hdr |= HDA_DSP_ROM_IPC_PURGE_FW | ((stream_tag - 1) << 9);
1282a68ff84SPeter Ujfalusi 
1292a68ff84SPeter Ujfalusi 	snd_sof_dsp_write(sdev, HDA_DSP_BAR, chip->ipc_req, ipc_hdr);
130d16046ffSLiam Girdwood 
131d16046ffSLiam Girdwood 	/* step 3: unset core 0 reset state & unstall/run core 0 */
1324643e10aSPeter Ujfalusi 	ret = hda_dsp_core_run(sdev, chip->init_core_mask);
133d16046ffSLiam Girdwood 	if (ret < 0) {
134776100a4SPierre-Louis Bossart 		if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
13553ec7531SRanjani Sridharan 			dev_err(sdev->dev,
13653ec7531SRanjani Sridharan 				"error: dsp core start failed %d\n", ret);
137d16046ffSLiam Girdwood 		ret = -EIO;
138d16046ffSLiam Girdwood 		goto err;
139d16046ffSLiam Girdwood 	}
140d16046ffSLiam Girdwood 
141d16046ffSLiam Girdwood 	/* step 4: wait for IPC DONE bit from ROM */
142d16046ffSLiam Girdwood 	ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR,
143d16046ffSLiam Girdwood 					    chip->ipc_ack, status,
144d16046ffSLiam Girdwood 					    ((status & chip->ipc_ack_mask)
145d16046ffSLiam Girdwood 						    == chip->ipc_ack_mask),
146d16046ffSLiam Girdwood 					    HDA_DSP_REG_POLL_INTERVAL_US,
147d16046ffSLiam Girdwood 					    HDA_DSP_INIT_TIMEOUT_US);
148d16046ffSLiam Girdwood 
149d16046ffSLiam Girdwood 	if (ret < 0) {
150776100a4SPierre-Louis Bossart 		if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
15153ec7531SRanjani Sridharan 			dev_err(sdev->dev,
15253ec7531SRanjani Sridharan 				"error: %s: timeout for HIPCIE done\n",
1536a414489SPierre-Louis Bossart 				__func__);
154d16046ffSLiam Girdwood 		goto err;
155d16046ffSLiam Girdwood 	}
156d16046ffSLiam Girdwood 
1578354d9b4SKeyon Jie 	/* set DONE bit to clear the reply IPC message */
1588354d9b4SKeyon Jie 	snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR,
1598354d9b4SKeyon Jie 				       chip->ipc_ack,
1608354d9b4SKeyon Jie 				       chip->ipc_ack_mask,
1618354d9b4SKeyon Jie 				       chip->ipc_ack_mask);
1628354d9b4SKeyon Jie 
163cedd502dSBard Liao 	/* step 5: power down cores that are no longer needed */
164d4165199SRanjani Sridharan 	ret = hda_dsp_core_reset_power_down(sdev, chip->host_managed_cores_mask &
165cedd502dSBard Liao 					   ~(chip->init_core_mask));
166d16046ffSLiam Girdwood 	if (ret < 0) {
167776100a4SPierre-Louis Bossart 		if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
16853ec7531SRanjani Sridharan 			dev_err(sdev->dev,
16953ec7531SRanjani Sridharan 				"error: dsp core x power down failed\n");
170d16046ffSLiam Girdwood 		goto err;
171d16046ffSLiam Girdwood 	}
172d16046ffSLiam Girdwood 
173d16046ffSLiam Girdwood 	/* step 6: enable IPC interrupts */
174d16046ffSLiam Girdwood 	hda_dsp_ipc_int_enable(sdev);
175d16046ffSLiam Girdwood 
1762a68ff84SPeter Ujfalusi 	/*
1772a68ff84SPeter Ujfalusi 	 * step 7:
1782a68ff84SPeter Ujfalusi 	 * - Cold/Full boot: wait for ROM init to proceed to download the firmware
1792a68ff84SPeter Ujfalusi 	 * - IMR boot: wait for ROM firmware entered (firmware booted up from IMR)
1802a68ff84SPeter Ujfalusi 	 */
1812a68ff84SPeter Ujfalusi 	if (imr_boot)
18243a03d24SPeter Ujfalusi 		target_status = FSR_STATE_FW_ENTERED;
1832a68ff84SPeter Ujfalusi 	else
18443a03d24SPeter Ujfalusi 		target_status = FSR_STATE_INIT_DONE;
1852a68ff84SPeter Ujfalusi 
186d16046ffSLiam Girdwood 	ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR,
18771778f79SRanjani Sridharan 					chip->rom_status_reg, status,
18843a03d24SPeter Ujfalusi 					(FSR_TO_STATE_CODE(status) == target_status),
189d16046ffSLiam Girdwood 					HDA_DSP_REG_POLL_INTERVAL_US,
190d16046ffSLiam Girdwood 					chip->rom_init_timeout *
191d16046ffSLiam Girdwood 					USEC_PER_MSEC);
192d4165199SRanjani Sridharan 	if (!ret) {
193d4165199SRanjani Sridharan 		/* set enabled cores mask and increment ref count for cores in init_core_mask */
194d4165199SRanjani Sridharan 		sdev->enabled_cores_mask |= chip->init_core_mask;
195d4165199SRanjani Sridharan 		mask = sdev->enabled_cores_mask;
196d4165199SRanjani Sridharan 		for_each_set_bit(j, &mask, SOF_MAX_DSP_NUM_CORES)
197d4165199SRanjani Sridharan 			sdev->dsp_core_ref_count[j]++;
198d16046ffSLiam Girdwood 		return 0;
199d4165199SRanjani Sridharan 	}
200d16046ffSLiam Girdwood 
201776100a4SPierre-Louis Bossart 	if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
2026a414489SPierre-Louis Bossart 		dev_err(sdev->dev,
20371778f79SRanjani Sridharan 			"%s: timeout with rom_status_reg (%#x) read\n",
20471778f79SRanjani Sridharan 			__func__, chip->rom_status_reg);
2056a414489SPierre-Louis Bossart 
206d16046ffSLiam Girdwood err:
2077511b0edSPeter Ujfalusi 	flags = SOF_DBG_DUMP_PCI | SOF_DBG_DUMP_MBOX | SOF_DBG_DUMP_OPTIONAL;
2088f7ef6fcSRanjani Sridharan 
20923013335SPeter Ujfalusi 	/* after max boot attempts make sure that the dump is printed */
21023013335SPeter Ujfalusi 	if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS)
2110ecaa2ffSPeter Ujfalusi 		flags &= ~SOF_DBG_DUMP_OPTIONAL;
2128f7ef6fcSRanjani Sridharan 
2132f148430SPeter Ujfalusi 	dump_msg = kasprintf(GFP_KERNEL, "Boot iteration failed: %d/%d",
2142f148430SPeter Ujfalusi 			     hda->boot_iteration, HDA_FW_BOOT_ATTEMPTS);
2152f148430SPeter Ujfalusi 	snd_sof_dsp_dbg_dump(sdev, dump_msg, flags);
216d4165199SRanjani Sridharan 	hda_dsp_core_reset_power_down(sdev, chip->host_managed_cores_mask);
217d16046ffSLiam Girdwood 
2182f148430SPeter Ujfalusi 	kfree(dump_msg);
219d16046ffSLiam Girdwood 	return ret;
220d16046ffSLiam Girdwood }
221d16046ffSLiam Girdwood 
222d16046ffSLiam Girdwood static int cl_trigger(struct snd_sof_dev *sdev,
2237d88b960SPierre-Louis Bossart 		      struct hdac_ext_stream *hext_stream, int cmd)
224d16046ffSLiam Girdwood {
2257d88b960SPierre-Louis Bossart 	struct hdac_stream *hstream = &hext_stream->hstream;
226d16046ffSLiam Girdwood 	int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
227d16046ffSLiam Girdwood 
228d16046ffSLiam Girdwood 	/* code loader is special case that reuses stream ops */
229d16046ffSLiam Girdwood 	switch (cmd) {
230d16046ffSLiam Girdwood 	case SNDRV_PCM_TRIGGER_START:
231d16046ffSLiam Girdwood 		snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
232d16046ffSLiam Girdwood 					1 << hstream->index,
233d16046ffSLiam Girdwood 					1 << hstream->index);
234d16046ffSLiam Girdwood 
235d16046ffSLiam Girdwood 		snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
236d16046ffSLiam Girdwood 					sd_offset,
237d16046ffSLiam Girdwood 					SOF_HDA_SD_CTL_DMA_START |
238d16046ffSLiam Girdwood 					SOF_HDA_CL_DMA_SD_INT_MASK,
239d16046ffSLiam Girdwood 					SOF_HDA_SD_CTL_DMA_START |
240d16046ffSLiam Girdwood 					SOF_HDA_CL_DMA_SD_INT_MASK);
241d16046ffSLiam Girdwood 
242d16046ffSLiam Girdwood 		hstream->running = true;
243d16046ffSLiam Girdwood 		return 0;
244d16046ffSLiam Girdwood 	default:
2457d88b960SPierre-Louis Bossart 		return hda_dsp_stream_trigger(sdev, hext_stream, cmd);
246d16046ffSLiam Girdwood 	}
247d16046ffSLiam Girdwood }
248d16046ffSLiam Girdwood 
249b4e4c0b9SRanjani Sridharan int hda_cl_cleanup(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
2507d88b960SPierre-Louis Bossart 		   struct hdac_ext_stream *hext_stream)
251d16046ffSLiam Girdwood {
2527d88b960SPierre-Louis Bossart 	struct hdac_stream *hstream = &hext_stream->hstream;
253d16046ffSLiam Girdwood 	int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
254acf705a4SRanjani Sridharan 	int ret = 0;
255d16046ffSLiam Girdwood 
256acf705a4SRanjani Sridharan 	if (hstream->direction == SNDRV_PCM_STREAM_PLAYBACK)
2577d88b960SPierre-Louis Bossart 		ret = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
258acf705a4SRanjani Sridharan 	else
259acf705a4SRanjani Sridharan 		snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, sd_offset,
260acf705a4SRanjani Sridharan 					SOF_HDA_SD_CTL_DMA_START, 0);
261d16046ffSLiam Girdwood 
262acf705a4SRanjani Sridharan 	hda_dsp_stream_put(sdev, hstream->direction, hstream->stream_tag);
263d16046ffSLiam Girdwood 	hstream->running = 0;
264d16046ffSLiam Girdwood 	hstream->substream = NULL;
265d16046ffSLiam Girdwood 
266d16046ffSLiam Girdwood 	/* reset BDL address */
267d16046ffSLiam Girdwood 	snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
268*38bf0780SPierre-Louis Bossart 			  sd_offset + SOF_HDA_ADSP_REG_SD_BDLPL, 0);
269d16046ffSLiam Girdwood 	snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
270*38bf0780SPierre-Louis Bossart 			  sd_offset + SOF_HDA_ADSP_REG_SD_BDLPU, 0);
271d16046ffSLiam Girdwood 
272d16046ffSLiam Girdwood 	snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, sd_offset, 0);
273d16046ffSLiam Girdwood 	snd_dma_free_pages(dmab);
274d16046ffSLiam Girdwood 	dmab->area = NULL;
275d16046ffSLiam Girdwood 	hstream->bufsize = 0;
276d16046ffSLiam Girdwood 	hstream->format_val = 0;
277d16046ffSLiam Girdwood 
278d16046ffSLiam Girdwood 	return ret;
279d16046ffSLiam Girdwood }
280d16046ffSLiam Girdwood 
281b4e4c0b9SRanjani Sridharan int hda_cl_copy_fw(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream)
282d16046ffSLiam Girdwood {
28371778f79SRanjani Sridharan 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
28471778f79SRanjani Sridharan 	const struct sof_intel_dsp_desc *chip = hda->desc;
285d16046ffSLiam Girdwood 	unsigned int reg;
286d16046ffSLiam Girdwood 	int ret, status;
287d16046ffSLiam Girdwood 
2887d88b960SPierre-Louis Bossart 	ret = cl_trigger(sdev, hext_stream, SNDRV_PCM_TRIGGER_START);
289d16046ffSLiam Girdwood 	if (ret < 0) {
290d16046ffSLiam Girdwood 		dev_err(sdev->dev, "error: DMA trigger start failed\n");
291d16046ffSLiam Girdwood 		return ret;
292d16046ffSLiam Girdwood 	}
293d16046ffSLiam Girdwood 
294d16046ffSLiam Girdwood 	status = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR,
29571778f79SRanjani Sridharan 					chip->rom_status_reg, reg,
29643a03d24SPeter Ujfalusi 					(FSR_TO_STATE_CODE(reg) == FSR_STATE_FW_ENTERED),
297d16046ffSLiam Girdwood 					HDA_DSP_REG_POLL_INTERVAL_US,
298d16046ffSLiam Girdwood 					HDA_DSP_BASEFW_TIMEOUT_US);
299d16046ffSLiam Girdwood 
30076dc6a2bSPierre-Louis Bossart 	/*
30176dc6a2bSPierre-Louis Bossart 	 * even in case of errors we still need to stop the DMAs,
30276dc6a2bSPierre-Louis Bossart 	 * but we return the initial error should the DMA stop also fail
30376dc6a2bSPierre-Louis Bossart 	 */
30476dc6a2bSPierre-Louis Bossart 
3056a414489SPierre-Louis Bossart 	if (status < 0) {
3066a414489SPierre-Louis Bossart 		dev_err(sdev->dev,
30771778f79SRanjani Sridharan 			"%s: timeout with rom_status_reg (%#x) read\n",
30871778f79SRanjani Sridharan 			__func__, chip->rom_status_reg);
3096a414489SPierre-Louis Bossart 	}
3106a414489SPierre-Louis Bossart 
3117d88b960SPierre-Louis Bossart 	ret = cl_trigger(sdev, hext_stream, SNDRV_PCM_TRIGGER_STOP);
312d16046ffSLiam Girdwood 	if (ret < 0) {
313d16046ffSLiam Girdwood 		dev_err(sdev->dev, "error: DMA trigger stop failed\n");
31476dc6a2bSPierre-Louis Bossart 		if (!status)
31576dc6a2bSPierre-Louis Bossart 			status = ret;
316d16046ffSLiam Girdwood 	}
317d16046ffSLiam Girdwood 
318d16046ffSLiam Girdwood 	return status;
319d16046ffSLiam Girdwood }
320d16046ffSLiam Girdwood 
321acf705a4SRanjani Sridharan int hda_dsp_cl_boot_firmware_iccmax(struct snd_sof_dev *sdev)
322acf705a4SRanjani Sridharan {
323acf705a4SRanjani Sridharan 	struct hdac_ext_stream *iccmax_stream;
324acf705a4SRanjani Sridharan 	struct hdac_bus *bus = sof_to_bus(sdev);
325acf705a4SRanjani Sridharan 	struct firmware stripped_firmware;
326ea5ffef0SPeter Ujfalusi 	struct snd_dma_buffer dmab_bdl;
327acf705a4SRanjani Sridharan 	int ret, ret1;
328acf705a4SRanjani Sridharan 	u8 original_gb;
329acf705a4SRanjani Sridharan 
330acf705a4SRanjani Sridharan 	/* save the original LTRP guardband value */
331acf705a4SRanjani Sridharan 	original_gb = snd_hdac_chip_readb(bus, VS_LTRP) & HDA_VS_INTEL_LTRP_GB_MASK;
332acf705a4SRanjani Sridharan 
333410a321cSPeter Ujfalusi 	if (sdev->basefw.fw->size <= sdev->basefw.payload_offset) {
334acf705a4SRanjani Sridharan 		dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n");
335acf705a4SRanjani Sridharan 		return -EINVAL;
336acf705a4SRanjani Sridharan 	}
337acf705a4SRanjani Sridharan 
338410a321cSPeter Ujfalusi 	stripped_firmware.size = sdev->basefw.fw->size - sdev->basefw.payload_offset;
339acf705a4SRanjani Sridharan 
340acf705a4SRanjani Sridharan 	/* prepare capture stream for ICCMAX */
341b4e4c0b9SRanjani Sridharan 	iccmax_stream = hda_cl_stream_prepare(sdev, HDA_CL_STREAM_FORMAT, stripped_firmware.size,
342ea5ffef0SPeter Ujfalusi 					      &dmab_bdl, SNDRV_PCM_STREAM_CAPTURE);
34301d42d5aSRanjani Sridharan 	if (IS_ERR(iccmax_stream)) {
34401d42d5aSRanjani Sridharan 		dev_err(sdev->dev, "error: dma prepare for ICCMAX stream failed\n");
34501d42d5aSRanjani Sridharan 		return PTR_ERR(iccmax_stream);
346acf705a4SRanjani Sridharan 	}
347acf705a4SRanjani Sridharan 
348acf705a4SRanjani Sridharan 	ret = hda_dsp_cl_boot_firmware(sdev);
349acf705a4SRanjani Sridharan 
350acf705a4SRanjani Sridharan 	/*
351acf705a4SRanjani Sridharan 	 * Perform iccmax stream cleanup. This should be done even if firmware loading fails.
352acf705a4SRanjani Sridharan 	 * If the cleanup also fails, we return the initial error
353acf705a4SRanjani Sridharan 	 */
354b4e4c0b9SRanjani Sridharan 	ret1 = hda_cl_cleanup(sdev, &dmab_bdl, iccmax_stream);
355acf705a4SRanjani Sridharan 	if (ret1 < 0) {
356acf705a4SRanjani Sridharan 		dev_err(sdev->dev, "error: ICCMAX stream cleanup failed\n");
357acf705a4SRanjani Sridharan 
358acf705a4SRanjani Sridharan 		/* set return value to indicate cleanup failure */
359acf705a4SRanjani Sridharan 		if (!ret)
360acf705a4SRanjani Sridharan 			ret = ret1;
361acf705a4SRanjani Sridharan 	}
362acf705a4SRanjani Sridharan 
363acf705a4SRanjani Sridharan 	/* restore the original guardband value after FW boot */
364acf705a4SRanjani Sridharan 	snd_hdac_chip_updateb(bus, VS_LTRP, HDA_VS_INTEL_LTRP_GB_MASK, original_gb);
365acf705a4SRanjani Sridharan 
366acf705a4SRanjani Sridharan 	return ret;
367acf705a4SRanjani Sridharan }
368acf705a4SRanjani Sridharan 
3695fb5f511SKeyon Jie static int hda_dsp_boot_imr(struct snd_sof_dev *sdev)
3705fb5f511SKeyon Jie {
371ab222a4aSBard Liao 	const struct sof_intel_dsp_desc *chip_info;
3725fb5f511SKeyon Jie 	int ret;
3735fb5f511SKeyon Jie 
374ab222a4aSBard Liao 	chip_info = get_chip_info(sdev->pdata);
375ab222a4aSBard Liao 	if (chip_info->cl_init)
376ab222a4aSBard Liao 		ret = chip_info->cl_init(sdev, 0, true);
377ab222a4aSBard Liao 	else
378ab222a4aSBard Liao 		ret = -EINVAL;
379ab222a4aSBard Liao 
380fd2cea16SPeter Ujfalusi 	if (!ret)
3815fb5f511SKeyon Jie 		hda_sdw_process_wakeen(sdev);
3825fb5f511SKeyon Jie 
3835fb5f511SKeyon Jie 	return ret;
3845fb5f511SKeyon Jie }
3855fb5f511SKeyon Jie 
386d16046ffSLiam Girdwood int hda_dsp_cl_boot_firmware(struct snd_sof_dev *sdev)
387d16046ffSLiam Girdwood {
388776100a4SPierre-Louis Bossart 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
389d16046ffSLiam Girdwood 	struct snd_sof_pdata *plat_data = sdev->pdata;
390d16046ffSLiam Girdwood 	const struct sof_dev_desc *desc = plat_data->desc;
391d16046ffSLiam Girdwood 	const struct sof_intel_dsp_desc *chip_info;
3927d88b960SPierre-Louis Bossart 	struct hdac_ext_stream *hext_stream;
393d16046ffSLiam Girdwood 	struct firmware stripped_firmware;
394ea5ffef0SPeter Ujfalusi 	struct snd_dma_buffer dmab;
39501d42d5aSRanjani Sridharan 	int ret, ret1, i;
396d16046ffSLiam Girdwood 
39757724db1SPeter Ujfalusi 	if (hda->imrboot_supported && !sdev->first_boot && !hda->skip_imr_boot) {
3985fb5f511SKeyon Jie 		dev_dbg(sdev->dev, "IMR restore supported, booting from IMR directly\n");
3992a68ff84SPeter Ujfalusi 		hda->boot_iteration = 0;
4002a68ff84SPeter Ujfalusi 		ret = hda_dsp_boot_imr(sdev);
4015d5d915bSPeter Ujfalusi 		if (!ret) {
4025d5d915bSPeter Ujfalusi 			hda->booted_from_imr = true;
403fd2cea16SPeter Ujfalusi 			return 0;
4045d5d915bSPeter Ujfalusi 		}
4052a68ff84SPeter Ujfalusi 
4062a68ff84SPeter Ujfalusi 		dev_warn(sdev->dev, "IMR restore failed, trying to cold boot\n");
4075fb5f511SKeyon Jie 	}
4085fb5f511SKeyon Jie 
4095d5d915bSPeter Ujfalusi 	hda->booted_from_imr = false;
4105d5d915bSPeter Ujfalusi 
411d16046ffSLiam Girdwood 	chip_info = desc->chip_info;
412d16046ffSLiam Girdwood 
413410a321cSPeter Ujfalusi 	if (sdev->basefw.fw->size <= sdev->basefw.payload_offset) {
41492be17a5SKarol Trzcinski 		dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n");
41592be17a5SKarol Trzcinski 		return -EINVAL;
41692be17a5SKarol Trzcinski 	}
41792be17a5SKarol Trzcinski 
418410a321cSPeter Ujfalusi 	stripped_firmware.data = sdev->basefw.fw->data + sdev->basefw.payload_offset;
419410a321cSPeter Ujfalusi 	stripped_firmware.size = sdev->basefw.fw->size - sdev->basefw.payload_offset;
420d16046ffSLiam Girdwood 
421d16046ffSLiam Girdwood 	/* init for booting wait */
422d16046ffSLiam Girdwood 	init_waitqueue_head(&sdev->boot_wait);
423d16046ffSLiam Girdwood 
424d16046ffSLiam Girdwood 	/* prepare DMA for code loader stream */
425b4e4c0b9SRanjani Sridharan 	hext_stream = hda_cl_stream_prepare(sdev, HDA_CL_STREAM_FORMAT,
426b4e4c0b9SRanjani Sridharan 					    stripped_firmware.size,
427ea5ffef0SPeter Ujfalusi 					    &dmab, SNDRV_PCM_STREAM_PLAYBACK);
4287d88b960SPierre-Louis Bossart 	if (IS_ERR(hext_stream)) {
42901d42d5aSRanjani Sridharan 		dev_err(sdev->dev, "error: dma prepare for fw loading failed\n");
4307d88b960SPierre-Louis Bossart 		return PTR_ERR(hext_stream);
431d16046ffSLiam Girdwood 	}
432d16046ffSLiam Girdwood 
433ea5ffef0SPeter Ujfalusi 	memcpy(dmab.area, stripped_firmware.data,
434d16046ffSLiam Girdwood 	       stripped_firmware.size);
435d16046ffSLiam Girdwood 
436d16046ffSLiam Girdwood 	/* try ROM init a few times before giving up */
437d16046ffSLiam Girdwood 	for (i = 0; i < HDA_FW_BOOT_ATTEMPTS; i++) {
43853ec7531SRanjani Sridharan 		dev_dbg(sdev->dev,
43953ec7531SRanjani Sridharan 			"Attempting iteration %d of Core En/ROM load...\n", i);
44053ec7531SRanjani Sridharan 
441776100a4SPierre-Louis Bossart 		hda->boot_iteration = i + 1;
442ab222a4aSBard Liao 		if (chip_info->cl_init)
443ab222a4aSBard Liao 			ret = chip_info->cl_init(sdev, hext_stream->hstream.stream_tag, false);
444ab222a4aSBard Liao 		else
445ab222a4aSBard Liao 			ret = -EINVAL;
446d16046ffSLiam Girdwood 
447d16046ffSLiam Girdwood 		/* don't retry anymore if successful */
448d16046ffSLiam Girdwood 		if (!ret)
449d16046ffSLiam Girdwood 			break;
450d16046ffSLiam Girdwood 	}
451d16046ffSLiam Girdwood 
452d16046ffSLiam Girdwood 	if (i == HDA_FW_BOOT_ATTEMPTS) {
453d16046ffSLiam Girdwood 		dev_err(sdev->dev, "error: dsp init failed after %d attempts with err: %d\n",
454d16046ffSLiam Girdwood 			i, ret);
455d16046ffSLiam Girdwood 		goto cleanup;
456d16046ffSLiam Girdwood 	}
457d16046ffSLiam Girdwood 
458d16046ffSLiam Girdwood 	/*
459bbd19cdcSRander Wang 	 * When a SoundWire link is in clock stop state, a Slave
460bbd19cdcSRander Wang 	 * device may trigger in-band wakes for events such as jack
461bbd19cdcSRander Wang 	 * insertion or acoustic event detection. This event will lead
462bbd19cdcSRander Wang 	 * to a WAKEEN interrupt, handled by the PCI device and routed
463bbd19cdcSRander Wang 	 * to PME if the PCI device is in D3. The resume function in
464bbd19cdcSRander Wang 	 * audio PCI driver will be invoked by ACPI for PME event and
465bbd19cdcSRander Wang 	 * initialize the device and process WAKEEN interrupt.
466bbd19cdcSRander Wang 	 *
467bbd19cdcSRander Wang 	 * The WAKEEN interrupt should be processed ASAP to prevent an
468bbd19cdcSRander Wang 	 * interrupt flood, otherwise other interrupts, such IPC,
469bbd19cdcSRander Wang 	 * cannot work normally.  The WAKEEN is handled after the ROM
470bbd19cdcSRander Wang 	 * is initialized successfully, which ensures power rails are
471bbd19cdcSRander Wang 	 * enabled before accessing the SoundWire SHIM registers
472bbd19cdcSRander Wang 	 */
473bbd19cdcSRander Wang 	if (!sdev->first_boot)
474bbd19cdcSRander Wang 		hda_sdw_process_wakeen(sdev);
475bbd19cdcSRander Wang 
476bbd19cdcSRander Wang 	/*
477b2b10aa7SPeter Ujfalusi 	 * Set the boot_iteration to the last attempt, indicating that the
478b2b10aa7SPeter Ujfalusi 	 * DSP ROM has been initialized and from this point there will be no
479b2b10aa7SPeter Ujfalusi 	 * retry done to boot.
480b2b10aa7SPeter Ujfalusi 	 *
481b2b10aa7SPeter Ujfalusi 	 * Continue with code loading and firmware boot
482d16046ffSLiam Girdwood 	 */
483b2b10aa7SPeter Ujfalusi 	hda->boot_iteration = HDA_FW_BOOT_ATTEMPTS;
484b4e4c0b9SRanjani Sridharan 	ret = hda_cl_copy_fw(sdev, hext_stream);
48557724db1SPeter Ujfalusi 	if (!ret) {
486d16046ffSLiam Girdwood 		dev_dbg(sdev->dev, "Firmware download successful, booting...\n");
48757724db1SPeter Ujfalusi 		hda->skip_imr_boot = false;
48857724db1SPeter Ujfalusi 	} else {
4892f148430SPeter Ujfalusi 		snd_sof_dsp_dbg_dump(sdev, "Firmware download failed",
4902f148430SPeter Ujfalusi 				     SOF_DBG_DUMP_PCI | SOF_DBG_DUMP_MBOX);
49157724db1SPeter Ujfalusi 		hda->skip_imr_boot = true;
49257724db1SPeter Ujfalusi 	}
493d16046ffSLiam Girdwood 
494d16046ffSLiam Girdwood cleanup:
495d16046ffSLiam Girdwood 	/*
496d16046ffSLiam Girdwood 	 * Perform codeloader stream cleanup.
497d16046ffSLiam Girdwood 	 * This should be done even if firmware loading fails.
49876dc6a2bSPierre-Louis Bossart 	 * If the cleanup also fails, we return the initial error
499d16046ffSLiam Girdwood 	 */
500b4e4c0b9SRanjani Sridharan 	ret1 = hda_cl_cleanup(sdev, &dmab, hext_stream);
501d16046ffSLiam Girdwood 	if (ret1 < 0) {
502d16046ffSLiam Girdwood 		dev_err(sdev->dev, "error: Code loader DSP cleanup failed\n");
503d16046ffSLiam Girdwood 
504d16046ffSLiam Girdwood 		/* set return value to indicate cleanup failure */
50576dc6a2bSPierre-Louis Bossart 		if (!ret)
506d16046ffSLiam Girdwood 			ret = ret1;
507d16046ffSLiam Girdwood 	}
508d16046ffSLiam Girdwood 
509d16046ffSLiam Girdwood 	/*
51052e4d0aeSPierre-Louis Bossart 	 * return primary core id if both fw copy
511d16046ffSLiam Girdwood 	 * and stream clean up are successful
512d16046ffSLiam Girdwood 	 */
513d16046ffSLiam Girdwood 	if (!ret)
514d16046ffSLiam Girdwood 		return chip_info->init_core_mask;
515d16046ffSLiam Girdwood 
516d16046ffSLiam Girdwood 	/* disable DSP */
517d16046ffSLiam Girdwood 	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR,
518d16046ffSLiam Girdwood 				SOF_HDA_REG_PP_PPCTL,
519d16046ffSLiam Girdwood 				SOF_HDA_PPCTL_GPROCEN, 0);
520d16046ffSLiam Girdwood 	return ret;
521d16046ffSLiam Girdwood }
522d16046ffSLiam Girdwood 
5233ab2c21eSPeter Ujfalusi int hda_dsp_ipc4_load_library(struct snd_sof_dev *sdev,
5243ab2c21eSPeter Ujfalusi 			      struct sof_ipc4_fw_library *fw_lib, bool reload)
5253ab2c21eSPeter Ujfalusi {
5263ab2c21eSPeter Ujfalusi 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
5273ab2c21eSPeter Ujfalusi 	struct hdac_ext_stream *hext_stream;
5283ab2c21eSPeter Ujfalusi 	struct firmware stripped_firmware;
5293ab2c21eSPeter Ujfalusi 	struct sof_ipc4_msg msg = {};
5303ab2c21eSPeter Ujfalusi 	struct snd_dma_buffer dmab;
5313ab2c21eSPeter Ujfalusi 	int ret, ret1;
5323ab2c21eSPeter Ujfalusi 
5333ab2c21eSPeter Ujfalusi 	/* IMR booting will restore the libraries as well, skip the loading */
5343ab2c21eSPeter Ujfalusi 	if (reload && hda->booted_from_imr)
5353ab2c21eSPeter Ujfalusi 		return 0;
5363ab2c21eSPeter Ujfalusi 
5373ab2c21eSPeter Ujfalusi 	/* the fw_lib has been verified during loading, we can trust the validity here */
5383ab2c21eSPeter Ujfalusi 	stripped_firmware.data = fw_lib->sof_fw.fw->data + fw_lib->sof_fw.payload_offset;
5393ab2c21eSPeter Ujfalusi 	stripped_firmware.size = fw_lib->sof_fw.fw->size - fw_lib->sof_fw.payload_offset;
5403ab2c21eSPeter Ujfalusi 
5413ab2c21eSPeter Ujfalusi 	/* prepare DMA for code loader stream */
5423ab2c21eSPeter Ujfalusi 	hext_stream = hda_cl_stream_prepare(sdev, HDA_CL_STREAM_FORMAT,
5433ab2c21eSPeter Ujfalusi 					    stripped_firmware.size,
5443ab2c21eSPeter Ujfalusi 					    &dmab, SNDRV_PCM_STREAM_PLAYBACK);
5453ab2c21eSPeter Ujfalusi 	if (IS_ERR(hext_stream)) {
5463ab2c21eSPeter Ujfalusi 		dev_err(sdev->dev, "%s: DMA prepare failed\n", __func__);
5473ab2c21eSPeter Ujfalusi 		return PTR_ERR(hext_stream);
5483ab2c21eSPeter Ujfalusi 	}
5493ab2c21eSPeter Ujfalusi 
5503ab2c21eSPeter Ujfalusi 	memcpy(dmab.area, stripped_firmware.data, stripped_firmware.size);
5513ab2c21eSPeter Ujfalusi 
5523ab2c21eSPeter Ujfalusi 	msg.primary = hext_stream->hstream.stream_tag - 1;
5533ab2c21eSPeter Ujfalusi 	msg.primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_GLB_LOAD_LIBRARY);
5543ab2c21eSPeter Ujfalusi 	msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
5553ab2c21eSPeter Ujfalusi 	msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_FW_GEN_MSG);
5563ab2c21eSPeter Ujfalusi 	msg.primary |= SOF_IPC4_GLB_LOAD_LIBRARY_LIB_ID(fw_lib->id);
5573ab2c21eSPeter Ujfalusi 
5583ab2c21eSPeter Ujfalusi 	ret = cl_trigger(sdev, hext_stream, SNDRV_PCM_TRIGGER_START);
5593ab2c21eSPeter Ujfalusi 	if (ret < 0) {
5603ab2c21eSPeter Ujfalusi 		dev_err(sdev->dev, "%s: DMA trigger start failed\n", __func__);
5613ab2c21eSPeter Ujfalusi 		goto cleanup;
5623ab2c21eSPeter Ujfalusi 	}
5633ab2c21eSPeter Ujfalusi 
5643ab2c21eSPeter Ujfalusi 	ret = sof_ipc_tx_message(sdev->ipc, &msg, 0, NULL, 0);
5653ab2c21eSPeter Ujfalusi 
5663ab2c21eSPeter Ujfalusi 	ret1 = cl_trigger(sdev, hext_stream, SNDRV_PCM_TRIGGER_STOP);
5673ab2c21eSPeter Ujfalusi 	if (ret1 < 0) {
5683ab2c21eSPeter Ujfalusi 		dev_err(sdev->dev, "%s: DMA trigger stop failed\n", __func__);
5693ab2c21eSPeter Ujfalusi 		if (!ret)
5703ab2c21eSPeter Ujfalusi 			ret = ret1;
5713ab2c21eSPeter Ujfalusi 	}
5723ab2c21eSPeter Ujfalusi 
5733ab2c21eSPeter Ujfalusi cleanup:
5743ab2c21eSPeter Ujfalusi 	/* clean up even in case of error and return the first error */
5753ab2c21eSPeter Ujfalusi 	ret1 = hda_cl_cleanup(sdev, &dmab, hext_stream);
5763ab2c21eSPeter Ujfalusi 	if (ret1 < 0) {
5773ab2c21eSPeter Ujfalusi 		dev_err(sdev->dev, "%s: Code loader DSP cleanup failed\n", __func__);
5783ab2c21eSPeter Ujfalusi 
5793ab2c21eSPeter Ujfalusi 		/* set return value to indicate cleanup failure */
5803ab2c21eSPeter Ujfalusi 		if (!ret)
5813ab2c21eSPeter Ujfalusi 			ret = ret1;
5823ab2c21eSPeter Ujfalusi 	}
5833ab2c21eSPeter Ujfalusi 
5843ab2c21eSPeter Ujfalusi 	return ret;
5853ab2c21eSPeter Ujfalusi }
5863ab2c21eSPeter Ujfalusi 
587d16046ffSLiam Girdwood /* pre fw run operations */
588d16046ffSLiam Girdwood int hda_dsp_pre_fw_run(struct snd_sof_dev *sdev)
589d16046ffSLiam Girdwood {
590d16046ffSLiam Girdwood 	/* disable clock gating and power gating */
591d16046ffSLiam Girdwood 	return hda_dsp_ctrl_clock_power_gating(sdev, false);
592d16046ffSLiam Girdwood }
593d16046ffSLiam Girdwood 
594d16046ffSLiam Girdwood /* post fw run operations */
595d16046ffSLiam Girdwood int hda_dsp_post_fw_run(struct snd_sof_dev *sdev)
596d16046ffSLiam Girdwood {
59751dfed1eSPierre-Louis Bossart 	int ret;
59851dfed1eSPierre-Louis Bossart 
59951dfed1eSPierre-Louis Bossart 	if (sdev->first_boot) {
6002a68ff84SPeter Ujfalusi 		struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
6012a68ff84SPeter Ujfalusi 
60251dfed1eSPierre-Louis Bossart 		ret = hda_sdw_startup(sdev);
60351dfed1eSPierre-Louis Bossart 		if (ret < 0) {
60451dfed1eSPierre-Louis Bossart 			dev_err(sdev->dev,
60551dfed1eSPierre-Louis Bossart 				"error: could not startup SoundWire links\n");
60651dfed1eSPierre-Louis Bossart 			return ret;
60751dfed1eSPierre-Louis Bossart 		}
6082a68ff84SPeter Ujfalusi 
6092a68ff84SPeter Ujfalusi 		/* Check if IMR boot is usable */
6102a68ff84SPeter Ujfalusi 		if (!sof_debug_check_flag(SOF_DBG_IGNORE_D3_PERSISTENT) &&
6112964e31cSPeter Ujfalusi 		    (sdev->fw_ready.flags & SOF_IPC_INFO_D3_PERSISTENT ||
6122964e31cSPeter Ujfalusi 		     sdev->pdata->ipc_type == SOF_INTEL_IPC4))
6132a68ff84SPeter Ujfalusi 			hdev->imrboot_supported = true;
61451dfed1eSPierre-Louis Bossart 	}
61551dfed1eSPierre-Louis Bossart 
61651dfed1eSPierre-Louis Bossart 	hda_sdw_int_enable(sdev, true);
61751dfed1eSPierre-Louis Bossart 
618d16046ffSLiam Girdwood 	/* re-enable clock gating and power gating */
619d16046ffSLiam Girdwood 	return hda_dsp_ctrl_clock_power_gating(sdev, true);
620d16046ffSLiam Girdwood }
621edbaaadaSFred Oh 
622edbaaadaSFred Oh int hda_dsp_ext_man_get_cavs_config_data(struct snd_sof_dev *sdev,
623edbaaadaSFred Oh 					 const struct sof_ext_man_elem_header *hdr)
624edbaaadaSFred Oh {
625edbaaadaSFred Oh 	const struct sof_ext_man_cavs_config_data *config_data =
626edbaaadaSFred Oh 		container_of(hdr, struct sof_ext_man_cavs_config_data, hdr);
627edbaaadaSFred Oh 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
628edbaaadaSFred Oh 	int i, elem_num;
629edbaaadaSFred Oh 
630edbaaadaSFred Oh 	/* calculate total number of config data elements */
631edbaaadaSFred Oh 	elem_num = (hdr->size - sizeof(struct sof_ext_man_elem_header))
632edbaaadaSFred Oh 		   / sizeof(struct sof_config_elem);
633edbaaadaSFred Oh 	if (elem_num <= 0) {
634edbaaadaSFred Oh 		dev_err(sdev->dev, "cavs config data is inconsistent: %d\n", elem_num);
635edbaaadaSFred Oh 		return -EINVAL;
636edbaaadaSFred Oh 	}
637edbaaadaSFred Oh 
638edbaaadaSFred Oh 	for (i = 0; i < elem_num; i++)
639edbaaadaSFred Oh 		switch (config_data->elems[i].token) {
640edbaaadaSFred Oh 		case SOF_EXT_MAN_CAVS_CONFIG_EMPTY:
641edbaaadaSFred Oh 			/* skip empty token */
642edbaaadaSFred Oh 			break;
643edbaaadaSFred Oh 		case SOF_EXT_MAN_CAVS_CONFIG_CAVS_LPRO:
644edbaaadaSFred Oh 			hda->clk_config_lpro = config_data->elems[i].value;
645edbaaadaSFred Oh 			dev_dbg(sdev->dev, "FW clock config: %s\n",
646edbaaadaSFred Oh 				hda->clk_config_lpro ? "LPRO" : "HPRO");
647edbaaadaSFred Oh 			break;
648e3a85dbeSFred Oh 		case SOF_EXT_MAN_CAVS_CONFIG_OUTBOX_SIZE:
649e3a85dbeSFred Oh 		case SOF_EXT_MAN_CAVS_CONFIG_INBOX_SIZE:
650e3a85dbeSFred Oh 			/* These elements are defined but not being used yet. No warn is required */
651e3a85dbeSFred Oh 			break;
652edbaaadaSFred Oh 		default:
653e3a85dbeSFred Oh 			dev_info(sdev->dev, "unsupported token type: %d\n",
654edbaaadaSFred Oh 				 config_data->elems[i].token);
655edbaaadaSFred Oh 		}
656edbaaadaSFred Oh 
657edbaaadaSFred Oh 	return 0;
658edbaaadaSFred Oh }
659