xref: /linux-6.15/sound/soc/sof/intel/hda-ctrl.c (revision e149ca29)
1*e149ca29SPierre-Louis Bossart // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
28a300c8fSLiam Girdwood //
38a300c8fSLiam Girdwood // This file is provided under a dual BSD/GPLv2 license.  When using or
48a300c8fSLiam Girdwood // redistributing this file, you may do so under either license.
58a300c8fSLiam Girdwood //
68a300c8fSLiam Girdwood // Copyright(c) 2018 Intel Corporation. All rights reserved.
78a300c8fSLiam Girdwood //
88a300c8fSLiam Girdwood // Authors: Liam Girdwood <[email protected]>
98a300c8fSLiam Girdwood //	    Ranjani Sridharan <[email protected]>
108a300c8fSLiam Girdwood //	    Rander Wang <[email protected]>
118a300c8fSLiam Girdwood //          Keyon Jie <[email protected]>
128a300c8fSLiam Girdwood //
138a300c8fSLiam Girdwood 
148a300c8fSLiam Girdwood /*
158a300c8fSLiam Girdwood  * Hardware interface for generic Intel audio DSP HDA IP
168a300c8fSLiam Girdwood  */
178a300c8fSLiam Girdwood 
184f6250b8SKai Vehmanen #include <linux/module.h>
198a300c8fSLiam Girdwood #include <sound/hdaudio_ext.h>
208a300c8fSLiam Girdwood #include <sound/hda_register.h>
217e26df0cSKai Vehmanen #include <sound/hda_component.h>
228a300c8fSLiam Girdwood #include "../ops.h"
238a300c8fSLiam Girdwood #include "hda.h"
248a300c8fSLiam Girdwood 
254f6250b8SKai Vehmanen #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
264f6250b8SKai Vehmanen static int hda_codec_mask = -1;
274f6250b8SKai Vehmanen module_param_named(codec_mask, hda_codec_mask, int, 0444);
284f6250b8SKai Vehmanen MODULE_PARM_DESC(codec_mask, "SOF HDA codec mask for probing");
294f6250b8SKai Vehmanen #endif
304f6250b8SKai Vehmanen 
318a300c8fSLiam Girdwood /*
328a300c8fSLiam Girdwood  * HDA Operations.
338a300c8fSLiam Girdwood  */
348a300c8fSLiam Girdwood 
358a300c8fSLiam Girdwood int hda_dsp_ctrl_link_reset(struct snd_sof_dev *sdev, bool reset)
368a300c8fSLiam Girdwood {
378a300c8fSLiam Girdwood 	unsigned long timeout;
388a300c8fSLiam Girdwood 	u32 gctl = 0;
398a300c8fSLiam Girdwood 	u32 val;
408a300c8fSLiam Girdwood 
418a300c8fSLiam Girdwood 	/* 0 to enter reset and 1 to exit reset */
428a300c8fSLiam Girdwood 	val = reset ? 0 : SOF_HDA_GCTL_RESET;
438a300c8fSLiam Girdwood 
448a300c8fSLiam Girdwood 	/* enter/exit HDA controller reset */
458a300c8fSLiam Girdwood 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_GCTL,
468a300c8fSLiam Girdwood 				SOF_HDA_GCTL_RESET, val);
478a300c8fSLiam Girdwood 
488a300c8fSLiam Girdwood 	/* wait to enter/exit reset */
498a300c8fSLiam Girdwood 	timeout = jiffies + msecs_to_jiffies(HDA_DSP_CTRL_RESET_TIMEOUT);
508a300c8fSLiam Girdwood 	while (time_before(jiffies, timeout)) {
518a300c8fSLiam Girdwood 		gctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_GCTL);
528a300c8fSLiam Girdwood 		if ((gctl & SOF_HDA_GCTL_RESET) == val)
538a300c8fSLiam Girdwood 			return 0;
548a300c8fSLiam Girdwood 		usleep_range(500, 1000);
558a300c8fSLiam Girdwood 	}
568a300c8fSLiam Girdwood 
578a300c8fSLiam Girdwood 	/* enter/exit reset failed */
588a300c8fSLiam Girdwood 	dev_err(sdev->dev, "error: failed to %s HDA controller gctl 0x%x\n",
598a300c8fSLiam Girdwood 		reset ? "reset" : "ready", gctl);
608a300c8fSLiam Girdwood 	return -EIO;
618a300c8fSLiam Girdwood }
628a300c8fSLiam Girdwood 
638a300c8fSLiam Girdwood int hda_dsp_ctrl_get_caps(struct snd_sof_dev *sdev)
648a300c8fSLiam Girdwood {
658a300c8fSLiam Girdwood 	struct hdac_bus *bus = sof_to_bus(sdev);
668a300c8fSLiam Girdwood 	u32 cap, offset, feature;
678a300c8fSLiam Girdwood 	int count = 0;
68f09e9c7fSPierre-Louis Bossart 	int ret;
69f09e9c7fSPierre-Louis Bossart 
70f09e9c7fSPierre-Louis Bossart 	/*
71f09e9c7fSPierre-Louis Bossart 	 * On some devices, one reset cycle is necessary before reading
72f09e9c7fSPierre-Louis Bossart 	 * capabilities
73f09e9c7fSPierre-Louis Bossart 	 */
74f09e9c7fSPierre-Louis Bossart 	ret = hda_dsp_ctrl_link_reset(sdev, true);
75f09e9c7fSPierre-Louis Bossart 	if (ret < 0)
76f09e9c7fSPierre-Louis Bossart 		return ret;
77f09e9c7fSPierre-Louis Bossart 	ret = hda_dsp_ctrl_link_reset(sdev, false);
78f09e9c7fSPierre-Louis Bossart 	if (ret < 0)
79f09e9c7fSPierre-Louis Bossart 		return ret;
808a300c8fSLiam Girdwood 
818a300c8fSLiam Girdwood 	offset = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_LLCH);
828a300c8fSLiam Girdwood 
838a300c8fSLiam Girdwood 	do {
848a300c8fSLiam Girdwood 		dev_dbg(sdev->dev, "checking for capabilities at offset 0x%x\n",
858a300c8fSLiam Girdwood 			offset & SOF_HDA_CAP_NEXT_MASK);
868a300c8fSLiam Girdwood 
87f09e9c7fSPierre-Louis Bossart 		cap = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, offset);
88f09e9c7fSPierre-Louis Bossart 
89f09e9c7fSPierre-Louis Bossart 		if (cap == -1) {
90f09e9c7fSPierre-Louis Bossart 			dev_dbg(bus->dev, "Invalid capability reg read\n");
91f09e9c7fSPierre-Louis Bossart 			break;
92f09e9c7fSPierre-Louis Bossart 		}
93f09e9c7fSPierre-Louis Bossart 
948a300c8fSLiam Girdwood 		feature = (cap & SOF_HDA_CAP_ID_MASK) >> SOF_HDA_CAP_ID_OFF;
958a300c8fSLiam Girdwood 
968a300c8fSLiam Girdwood 		switch (feature) {
978a300c8fSLiam Girdwood 		case SOF_HDA_PP_CAP_ID:
988a300c8fSLiam Girdwood 			dev_dbg(sdev->dev, "found DSP capability at 0x%x\n",
998a300c8fSLiam Girdwood 				offset);
1008a300c8fSLiam Girdwood 			bus->ppcap = bus->remap_addr + offset;
1018a300c8fSLiam Girdwood 			sdev->bar[HDA_DSP_PP_BAR] = bus->ppcap;
1028a300c8fSLiam Girdwood 			break;
1038a300c8fSLiam Girdwood 		case SOF_HDA_SPIB_CAP_ID:
1048a300c8fSLiam Girdwood 			dev_dbg(sdev->dev, "found SPIB capability at 0x%x\n",
1058a300c8fSLiam Girdwood 				offset);
1068a300c8fSLiam Girdwood 			bus->spbcap = bus->remap_addr + offset;
1078a300c8fSLiam Girdwood 			sdev->bar[HDA_DSP_SPIB_BAR] = bus->spbcap;
1088a300c8fSLiam Girdwood 			break;
1098a300c8fSLiam Girdwood 		case SOF_HDA_DRSM_CAP_ID:
1108a300c8fSLiam Girdwood 			dev_dbg(sdev->dev, "found DRSM capability at 0x%x\n",
1118a300c8fSLiam Girdwood 				offset);
1128a300c8fSLiam Girdwood 			bus->drsmcap = bus->remap_addr + offset;
1138a300c8fSLiam Girdwood 			sdev->bar[HDA_DSP_DRSM_BAR] = bus->drsmcap;
1148a300c8fSLiam Girdwood 			break;
1158a300c8fSLiam Girdwood 		case SOF_HDA_GTS_CAP_ID:
1168a300c8fSLiam Girdwood 			dev_dbg(sdev->dev, "found GTS capability at 0x%x\n",
1178a300c8fSLiam Girdwood 				offset);
1188a300c8fSLiam Girdwood 			bus->gtscap = bus->remap_addr + offset;
1198a300c8fSLiam Girdwood 			break;
1208a300c8fSLiam Girdwood 		case SOF_HDA_ML_CAP_ID:
1218a300c8fSLiam Girdwood 			dev_dbg(sdev->dev, "found ML capability at 0x%x\n",
1228a300c8fSLiam Girdwood 				offset);
1238a300c8fSLiam Girdwood 			bus->mlcap = bus->remap_addr + offset;
1248a300c8fSLiam Girdwood 			break;
1258a300c8fSLiam Girdwood 		default:
126f09e9c7fSPierre-Louis Bossart 			dev_dbg(sdev->dev, "found capability %d at 0x%x\n",
1278a300c8fSLiam Girdwood 				feature, offset);
1288a300c8fSLiam Girdwood 			break;
1298a300c8fSLiam Girdwood 		}
1308a300c8fSLiam Girdwood 
1318a300c8fSLiam Girdwood 		offset = cap & SOF_HDA_CAP_NEXT_MASK;
1328a300c8fSLiam Girdwood 	} while (count++ <= SOF_HDA_MAX_CAPS && offset);
1338a300c8fSLiam Girdwood 
1348a300c8fSLiam Girdwood 	return 0;
1358a300c8fSLiam Girdwood }
1368a300c8fSLiam Girdwood 
1378a300c8fSLiam Girdwood void hda_dsp_ctrl_ppcap_enable(struct snd_sof_dev *sdev, bool enable)
1388a300c8fSLiam Girdwood {
1398a300c8fSLiam Girdwood 	u32 val = enable ? SOF_HDA_PPCTL_GPROCEN : 0;
1408a300c8fSLiam Girdwood 
1418a300c8fSLiam Girdwood 	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1428a300c8fSLiam Girdwood 				SOF_HDA_PPCTL_GPROCEN, val);
1438a300c8fSLiam Girdwood }
1448a300c8fSLiam Girdwood 
1458a300c8fSLiam Girdwood void hda_dsp_ctrl_ppcap_int_enable(struct snd_sof_dev *sdev, bool enable)
1468a300c8fSLiam Girdwood {
1478a300c8fSLiam Girdwood 	u32 val	= enable ? SOF_HDA_PPCTL_PIE : 0;
1488a300c8fSLiam Girdwood 
1498a300c8fSLiam Girdwood 	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1508a300c8fSLiam Girdwood 				SOF_HDA_PPCTL_PIE, val);
1518a300c8fSLiam Girdwood }
1528a300c8fSLiam Girdwood 
1538a300c8fSLiam Girdwood void hda_dsp_ctrl_misc_clock_gating(struct snd_sof_dev *sdev, bool enable)
1548a300c8fSLiam Girdwood {
1558a300c8fSLiam Girdwood 	u32 val = enable ? PCI_CGCTL_MISCBDCGE_MASK : 0;
1568a300c8fSLiam Girdwood 
1578a300c8fSLiam Girdwood 	snd_sof_pci_update_bits(sdev, PCI_CGCTL, PCI_CGCTL_MISCBDCGE_MASK, val);
1588a300c8fSLiam Girdwood }
1598a300c8fSLiam Girdwood 
1608a300c8fSLiam Girdwood /*
1618a300c8fSLiam Girdwood  * enable/disable audio dsp clock gating and power gating bits.
1628a300c8fSLiam Girdwood  * This allows the HW to opportunistically power and clock gate
1638a300c8fSLiam Girdwood  * the audio dsp when it is idle
1648a300c8fSLiam Girdwood  */
1658a300c8fSLiam Girdwood int hda_dsp_ctrl_clock_power_gating(struct snd_sof_dev *sdev, bool enable)
1668a300c8fSLiam Girdwood {
1678a300c8fSLiam Girdwood 	u32 val;
1688a300c8fSLiam Girdwood 
1698a300c8fSLiam Girdwood 	/* enable/disable audio dsp clock gating */
1708a300c8fSLiam Girdwood 	val = enable ? PCI_CGCTL_ADSPDCGE : 0;
1718a300c8fSLiam Girdwood 	snd_sof_pci_update_bits(sdev, PCI_CGCTL, PCI_CGCTL_ADSPDCGE, val);
1728a300c8fSLiam Girdwood 
17343b2ab90SRanjani Sridharan 	/* enable/disable DMI Link L1 support */
17443b2ab90SRanjani Sridharan 	val = enable ? HDA_VS_INTEL_EM2_L1SEN : 0;
17543b2ab90SRanjani Sridharan 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, HDA_VS_INTEL_EM2,
17643b2ab90SRanjani Sridharan 				HDA_VS_INTEL_EM2_L1SEN, val);
1778a300c8fSLiam Girdwood 
1788a300c8fSLiam Girdwood 	/* enable/disable audio dsp power gating */
1798a300c8fSLiam Girdwood 	val = enable ? 0 : PCI_PGCTL_ADSPPGD;
1808a300c8fSLiam Girdwood 	snd_sof_pci_update_bits(sdev, PCI_PGCTL, PCI_PGCTL_ADSPPGD, val);
1818a300c8fSLiam Girdwood 
1828a300c8fSLiam Girdwood 	return 0;
1838a300c8fSLiam Girdwood }
1848a300c8fSLiam Girdwood 
1858a300c8fSLiam Girdwood int hda_dsp_ctrl_init_chip(struct snd_sof_dev *sdev, bool full_reset)
1868a300c8fSLiam Girdwood {
1878a300c8fSLiam Girdwood 	struct hdac_bus *bus = sof_to_bus(sdev);
188d0697351SZhu Yingjiang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
189d0697351SZhu Yingjiang 	struct hdac_ext_link *hlink;
190d0697351SZhu Yingjiang #endif
191be1b577dSZhu Yingjiang 	struct hdac_stream *stream;
192be1b577dSZhu Yingjiang 	int sd_offset, ret = 0;
193be1b577dSZhu Yingjiang 
194be1b577dSZhu Yingjiang 	if (bus->chip_init)
195be1b577dSZhu Yingjiang 		return 0;
1968a300c8fSLiam Girdwood 
1977e26df0cSKai Vehmanen #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1987e26df0cSKai Vehmanen 	snd_hdac_set_codec_wakeup(bus, true);
1997e26df0cSKai Vehmanen #endif
2008a300c8fSLiam Girdwood 	hda_dsp_ctrl_misc_clock_gating(sdev, false);
201be1b577dSZhu Yingjiang 
202be1b577dSZhu Yingjiang 	if (full_reset) {
203be1b577dSZhu Yingjiang 		/* reset HDA controller */
204be1b577dSZhu Yingjiang 		ret = hda_dsp_ctrl_link_reset(sdev, true);
205be1b577dSZhu Yingjiang 		if (ret < 0) {
206be1b577dSZhu Yingjiang 			dev_err(sdev->dev, "error: failed to reset HDA controller\n");
207aae5a6e9SKai Vehmanen 			goto err;
208be1b577dSZhu Yingjiang 		}
209be1b577dSZhu Yingjiang 
210be1b577dSZhu Yingjiang 		usleep_range(500, 1000);
211be1b577dSZhu Yingjiang 
212be1b577dSZhu Yingjiang 		/* exit HDA controller reset */
213be1b577dSZhu Yingjiang 		ret = hda_dsp_ctrl_link_reset(sdev, false);
214be1b577dSZhu Yingjiang 		if (ret < 0) {
215be1b577dSZhu Yingjiang 			dev_err(sdev->dev, "error: failed to exit HDA controller reset\n");
216aae5a6e9SKai Vehmanen 			goto err;
217be1b577dSZhu Yingjiang 		}
218be1b577dSZhu Yingjiang 
219be1b577dSZhu Yingjiang 		usleep_range(1000, 1200);
220be1b577dSZhu Yingjiang 	}
221be1b577dSZhu Yingjiang 
222be1b577dSZhu Yingjiang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
223be1b577dSZhu Yingjiang 	/* check to see if controller is ready */
224be1b577dSZhu Yingjiang 	if (!snd_hdac_chip_readb(bus, GCTL)) {
225be1b577dSZhu Yingjiang 		dev_dbg(bus->dev, "controller not ready!\n");
226aae5a6e9SKai Vehmanen 		ret = -EBUSY;
227aae5a6e9SKai Vehmanen 		goto err;
228be1b577dSZhu Yingjiang 	}
229be1b577dSZhu Yingjiang 
230be1b577dSZhu Yingjiang 	/* Accept unsolicited responses */
231be1b577dSZhu Yingjiang 	snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, AZX_GCTL_UNSOL);
232be1b577dSZhu Yingjiang 
233be1b577dSZhu Yingjiang 	/* detect codecs */
234be1b577dSZhu Yingjiang 	if (!bus->codec_mask) {
235be1b577dSZhu Yingjiang 		bus->codec_mask = snd_hdac_chip_readw(bus, STATESTS);
236be1b577dSZhu Yingjiang 		dev_dbg(bus->dev, "codec_mask = 0x%lx\n", bus->codec_mask);
237be1b577dSZhu Yingjiang 	}
2384f6250b8SKai Vehmanen 
2394f6250b8SKai Vehmanen 	if (hda_codec_mask != -1) {
2404f6250b8SKai Vehmanen 		bus->codec_mask &= hda_codec_mask;
2414f6250b8SKai Vehmanen 		dev_dbg(bus->dev, "filtered codec_mask = 0x%lx\n",
2424f6250b8SKai Vehmanen 			bus->codec_mask);
2434f6250b8SKai Vehmanen 	}
244be1b577dSZhu Yingjiang #endif
245be1b577dSZhu Yingjiang 
246be1b577dSZhu Yingjiang 	/* clear stream status */
247be1b577dSZhu Yingjiang 	list_for_each_entry(stream, &bus->stream_list, list) {
248be1b577dSZhu Yingjiang 		sd_offset = SOF_STREAM_SD_OFFSET(stream);
2493a39e0eaSRanjani Sridharan 		snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
2503a39e0eaSRanjani Sridharan 				  sd_offset + SOF_HDA_ADSP_REG_CL_SD_STS,
251be1b577dSZhu Yingjiang 				  SOF_HDA_CL_DMA_SD_INT_MASK);
252be1b577dSZhu Yingjiang 	}
253be1b577dSZhu Yingjiang 
254be1b577dSZhu Yingjiang 	/* clear WAKESTS */
2553a39e0eaSRanjani Sridharan 	snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, SOF_HDA_WAKESTS,
256be1b577dSZhu Yingjiang 			  SOF_HDA_WAKESTS_INT_MASK);
257be1b577dSZhu Yingjiang 
258be1b577dSZhu Yingjiang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
259be1b577dSZhu Yingjiang 	/* clear rirb status */
260be1b577dSZhu Yingjiang 	snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
261be1b577dSZhu Yingjiang #endif
262be1b577dSZhu Yingjiang 
263be1b577dSZhu Yingjiang 	/* clear interrupt status register */
264be1b577dSZhu Yingjiang 	snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS,
265be1b577dSZhu Yingjiang 			  SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_ALL_STREAM);
266be1b577dSZhu Yingjiang 
267be1b577dSZhu Yingjiang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
268be1b577dSZhu Yingjiang 	/* initialize the codec command I/O */
269be1b577dSZhu Yingjiang 	snd_hdac_bus_init_cmd_io(bus);
270be1b577dSZhu Yingjiang #endif
271be1b577dSZhu Yingjiang 
272be1b577dSZhu Yingjiang 	/* enable CIE and GIE interrupts */
273be1b577dSZhu Yingjiang 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
274be1b577dSZhu Yingjiang 				SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN,
275be1b577dSZhu Yingjiang 				SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN);
276be1b577dSZhu Yingjiang 
277be1b577dSZhu Yingjiang 	/* program the position buffer */
278be1b577dSZhu Yingjiang 	if (bus->use_posbuf && bus->posbuf.addr) {
279061edb23SZhu Yingjiang 		snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, SOF_HDA_ADSP_DPLBASE,
280061edb23SZhu Yingjiang 				  (u32)bus->posbuf.addr);
281061edb23SZhu Yingjiang 		snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, SOF_HDA_ADSP_DPUBASE,
282be1b577dSZhu Yingjiang 				  upper_32_bits(bus->posbuf.addr));
283be1b577dSZhu Yingjiang 	}
284be1b577dSZhu Yingjiang 
285d0697351SZhu Yingjiang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
286d0697351SZhu Yingjiang 	/* Reset stream-to-link mapping */
287d0697351SZhu Yingjiang 	list_for_each_entry(hlink, &bus->hlink_list, list)
2889c6c417dSPierre-Louis Bossart 		writel(0, hlink->ml_addr + AZX_REG_ML_LOSIDV);
289d0697351SZhu Yingjiang #endif
290d0697351SZhu Yingjiang 
291be1b577dSZhu Yingjiang 	bus->chip_init = true;
292be1b577dSZhu Yingjiang 
293aae5a6e9SKai Vehmanen err:
2948a300c8fSLiam Girdwood 	hda_dsp_ctrl_misc_clock_gating(sdev, true);
2957e26df0cSKai Vehmanen #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
2967e26df0cSKai Vehmanen 	snd_hdac_set_codec_wakeup(bus, false);
2977e26df0cSKai Vehmanen #endif
2988a300c8fSLiam Girdwood 
2998a300c8fSLiam Girdwood 	return ret;
3008a300c8fSLiam Girdwood }
30113063a2cSZhu Yingjiang 
30213063a2cSZhu Yingjiang void hda_dsp_ctrl_stop_chip(struct snd_sof_dev *sdev)
30313063a2cSZhu Yingjiang {
30413063a2cSZhu Yingjiang 	struct hdac_bus *bus = sof_to_bus(sdev);
30513063a2cSZhu Yingjiang 	struct hdac_stream *stream;
30613063a2cSZhu Yingjiang 	int sd_offset;
30713063a2cSZhu Yingjiang 
30813063a2cSZhu Yingjiang 	if (!bus->chip_init)
30913063a2cSZhu Yingjiang 		return;
31013063a2cSZhu Yingjiang 
31113063a2cSZhu Yingjiang 	/* disable interrupts in stream descriptor */
31213063a2cSZhu Yingjiang 	list_for_each_entry(stream, &bus->stream_list, list) {
31313063a2cSZhu Yingjiang 		sd_offset = SOF_STREAM_SD_OFFSET(stream);
31413063a2cSZhu Yingjiang 		snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
31513063a2cSZhu Yingjiang 					sd_offset +
31613063a2cSZhu Yingjiang 					SOF_HDA_ADSP_REG_CL_SD_CTL,
31713063a2cSZhu Yingjiang 					SOF_HDA_CL_DMA_SD_INT_MASK,
31813063a2cSZhu Yingjiang 					0);
31913063a2cSZhu Yingjiang 	}
32013063a2cSZhu Yingjiang 
32113063a2cSZhu Yingjiang 	/* disable SIE for all streams */
32213063a2cSZhu Yingjiang 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
32313063a2cSZhu Yingjiang 				SOF_HDA_INT_ALL_STREAM,	0);
32413063a2cSZhu Yingjiang 
32513063a2cSZhu Yingjiang 	/* disable controller CIE and GIE */
32613063a2cSZhu Yingjiang 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
32713063a2cSZhu Yingjiang 				SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN,
32813063a2cSZhu Yingjiang 				0);
32913063a2cSZhu Yingjiang 
33013063a2cSZhu Yingjiang 	/* clear stream status */
33113063a2cSZhu Yingjiang 	list_for_each_entry(stream, &bus->stream_list, list) {
33213063a2cSZhu Yingjiang 		sd_offset = SOF_STREAM_SD_OFFSET(stream);
3333a39e0eaSRanjani Sridharan 		snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
3343a39e0eaSRanjani Sridharan 				  sd_offset + SOF_HDA_ADSP_REG_CL_SD_STS,
33513063a2cSZhu Yingjiang 				  SOF_HDA_CL_DMA_SD_INT_MASK);
33613063a2cSZhu Yingjiang 	}
33713063a2cSZhu Yingjiang 
33813063a2cSZhu Yingjiang 	/* clear WAKESTS */
3393a39e0eaSRanjani Sridharan 	snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, SOF_HDA_WAKESTS,
34013063a2cSZhu Yingjiang 			  SOF_HDA_WAKESTS_INT_MASK);
34113063a2cSZhu Yingjiang 
34213063a2cSZhu Yingjiang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
34313063a2cSZhu Yingjiang 	/* clear rirb status */
34413063a2cSZhu Yingjiang 	snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
34513063a2cSZhu Yingjiang #endif
34613063a2cSZhu Yingjiang 
34713063a2cSZhu Yingjiang 	/* clear interrupt status register */
34813063a2cSZhu Yingjiang 	snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS,
34913063a2cSZhu Yingjiang 			  SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_ALL_STREAM);
35013063a2cSZhu Yingjiang 
35113063a2cSZhu Yingjiang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
35213063a2cSZhu Yingjiang 	/* disable CORB/RIRB */
35313063a2cSZhu Yingjiang 	snd_hdac_bus_stop_cmd_io(bus);
35413063a2cSZhu Yingjiang #endif
35513063a2cSZhu Yingjiang 	/* disable position buffer */
35613063a2cSZhu Yingjiang 	if (bus->posbuf.addr) {
35713063a2cSZhu Yingjiang 		snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
35813063a2cSZhu Yingjiang 				  SOF_HDA_ADSP_DPLBASE, 0);
35913063a2cSZhu Yingjiang 		snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
36013063a2cSZhu Yingjiang 				  SOF_HDA_ADSP_DPUBASE, 0);
36113063a2cSZhu Yingjiang 	}
36213063a2cSZhu Yingjiang 
36313063a2cSZhu Yingjiang 	bus->chip_init = false;
36413063a2cSZhu Yingjiang }
365