xref: /openbmc/linux/sound/soc/sof/intel/cnl.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1e149ca29SPierre-Louis Bossart // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
227302052SLiam Girdwood //
327302052SLiam Girdwood // This file is provided under a dual BSD/GPLv2 license.  When using or
427302052SLiam Girdwood // redistributing this file, you may do so under either license.
527302052SLiam Girdwood //
627302052SLiam Girdwood // Copyright(c) 2018 Intel Corporation. All rights reserved.
727302052SLiam Girdwood //
827302052SLiam Girdwood // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
927302052SLiam Girdwood //	    Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1027302052SLiam Girdwood //	    Rander Wang <rander.wang@intel.com>
1127302052SLiam Girdwood //          Keyon Jie <yang.jie@linux.intel.com>
1227302052SLiam Girdwood //
1327302052SLiam Girdwood 
1427302052SLiam Girdwood /*
1527302052SLiam Girdwood  * Hardware interface for audio DSP on Cannonlake.
1627302052SLiam Girdwood  */
1727302052SLiam Girdwood 
18a4cfdebdSRanjani Sridharan #include <sound/sof/ext_manifest4.h>
19e3105c0cSRanjani Sridharan #include <sound/sof/ipc4/header.h>
20d272b657SBard Liao #include <trace/events/sof_intel.h>
21a4cfdebdSRanjani Sridharan #include "../ipc4-priv.h"
2227302052SLiam Girdwood #include "../ops.h"
2327302052SLiam Girdwood #include "hda.h"
240267de58SKeyon Jie #include "hda-ipc.h"
25285880a2SDaniel Baluta #include "../sof-audio.h"
2627302052SLiam Girdwood 
2727302052SLiam Girdwood static const struct snd_sof_debugfs_map cnl_dsp_debugfs[] = {
2827302052SLiam Girdwood 	{"hda", HDA_DSP_HDA_BAR, 0, 0x4000, SOF_DEBUGFS_ACCESS_ALWAYS},
2927302052SLiam Girdwood 	{"pp", HDA_DSP_PP_BAR,  0, 0x1000, SOF_DEBUGFS_ACCESS_ALWAYS},
3027302052SLiam Girdwood 	{"dsp", HDA_DSP_BAR,  0, 0x10000, SOF_DEBUGFS_ACCESS_ALWAYS},
3127302052SLiam Girdwood };
3227302052SLiam Girdwood 
3327302052SLiam Girdwood static void cnl_ipc_host_done(struct snd_sof_dev *sdev);
3427302052SLiam Girdwood static void cnl_ipc_dsp_done(struct snd_sof_dev *sdev);
3527302052SLiam Girdwood 
cnl_ipc4_irq_thread(int irq,void * context)36e3105c0cSRanjani Sridharan irqreturn_t cnl_ipc4_irq_thread(int irq, void *context)
37e3105c0cSRanjani Sridharan {
38e3105c0cSRanjani Sridharan 	struct sof_ipc4_msg notification_data = {{ 0 }};
39e3105c0cSRanjani Sridharan 	struct snd_sof_dev *sdev = context;
40483e4cdfSPeter Ujfalusi 	bool ack_received = false;
41e3105c0cSRanjani Sridharan 	bool ipc_irq = false;
42e3105c0cSRanjani Sridharan 	u32 hipcida, hipctdr;
43e3105c0cSRanjani Sridharan 
44e3105c0cSRanjani Sridharan 	hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDA);
45c8ed7ce2SPeter Ujfalusi 	hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDR);
46e3105c0cSRanjani Sridharan 	if (hipcida & CNL_DSP_REG_HIPCIDA_DONE) {
47e3105c0cSRanjani Sridharan 		/* DSP received the message */
48e3105c0cSRanjani Sridharan 		snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR,
49e3105c0cSRanjani Sridharan 					CNL_DSP_REG_HIPCCTL,
50e3105c0cSRanjani Sridharan 					CNL_DSP_REG_HIPCCTL_DONE, 0);
51e3105c0cSRanjani Sridharan 		cnl_ipc_dsp_done(sdev);
52e3105c0cSRanjani Sridharan 
53e3105c0cSRanjani Sridharan 		ipc_irq = true;
54483e4cdfSPeter Ujfalusi 		ack_received = true;
55e3105c0cSRanjani Sridharan 	}
56e3105c0cSRanjani Sridharan 
57e3105c0cSRanjani Sridharan 	if (hipctdr & CNL_DSP_REG_HIPCTDR_BUSY) {
58e3105c0cSRanjani Sridharan 		/* Message from DSP (reply or notification) */
59e3105c0cSRanjani Sridharan 		u32 hipctdd = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
60e3105c0cSRanjani Sridharan 					       CNL_DSP_REG_HIPCTDD);
61e3105c0cSRanjani Sridharan 		u32 primary = hipctdr & CNL_DSP_REG_HIPCTDR_MSG_MASK;
62e3105c0cSRanjani Sridharan 		u32 extension = hipctdd & CNL_DSP_REG_HIPCTDD_MSG_MASK;
63e3105c0cSRanjani Sridharan 
64e3105c0cSRanjani Sridharan 		if (primary & SOF_IPC4_MSG_DIR_MASK) {
65e3105c0cSRanjani Sridharan 			/* Reply received */
66acacd9eeSPeter Ujfalusi 			if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
67e3105c0cSRanjani Sridharan 				struct sof_ipc4_msg *data = sdev->ipc->msg.reply_data;
68e3105c0cSRanjani Sridharan 
69e3105c0cSRanjani Sridharan 				data->primary = primary;
70e3105c0cSRanjani Sridharan 				data->extension = extension;
71e3105c0cSRanjani Sridharan 
72e3105c0cSRanjani Sridharan 				spin_lock_irq(&sdev->ipc_lock);
73e3105c0cSRanjani Sridharan 
74e3105c0cSRanjani Sridharan 				snd_sof_ipc_get_reply(sdev);
75010c050fSPeter Ujfalusi 				cnl_ipc_host_done(sdev);
76e3105c0cSRanjani Sridharan 				snd_sof_ipc_reply(sdev, data->primary);
77e3105c0cSRanjani Sridharan 
78e3105c0cSRanjani Sridharan 				spin_unlock_irq(&sdev->ipc_lock);
79e3105c0cSRanjani Sridharan 			} else {
80acacd9eeSPeter Ujfalusi 				dev_dbg_ratelimited(sdev->dev,
81acacd9eeSPeter Ujfalusi 						    "IPC reply before FW_READY: %#x|%#x\n",
82acacd9eeSPeter Ujfalusi 						    primary, extension);
83acacd9eeSPeter Ujfalusi 			}
84acacd9eeSPeter Ujfalusi 		} else {
85e3105c0cSRanjani Sridharan 			/* Notification received */
86e3105c0cSRanjani Sridharan 			notification_data.primary = primary;
87e3105c0cSRanjani Sridharan 			notification_data.extension = extension;
88e3105c0cSRanjani Sridharan 
89e3105c0cSRanjani Sridharan 			sdev->ipc->msg.rx_data = &notification_data;
90e3105c0cSRanjani Sridharan 			snd_sof_ipc_msgs_rx(sdev);
91e3105c0cSRanjani Sridharan 			sdev->ipc->msg.rx_data = NULL;
92e3105c0cSRanjani Sridharan 
93e3105c0cSRanjani Sridharan 			/* Let DSP know that we have finished processing the message */
94e3105c0cSRanjani Sridharan 			cnl_ipc_host_done(sdev);
95010c050fSPeter Ujfalusi 		}
96e3105c0cSRanjani Sridharan 
97e3105c0cSRanjani Sridharan 		ipc_irq = true;
98e3105c0cSRanjani Sridharan 	}
99e3105c0cSRanjani Sridharan 
100e3105c0cSRanjani Sridharan 	if (!ipc_irq)
101e3105c0cSRanjani Sridharan 		/* This interrupt is not shared so no need to return IRQ_NONE. */
102e3105c0cSRanjani Sridharan 		dev_dbg_ratelimited(sdev->dev, "nothing to do in IPC IRQ thread\n");
103e3105c0cSRanjani Sridharan 
104483e4cdfSPeter Ujfalusi 	if (ack_received) {
105483e4cdfSPeter Ujfalusi 		struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
106483e4cdfSPeter Ujfalusi 
107483e4cdfSPeter Ujfalusi 		if (hdev->delayed_ipc_tx_msg)
108483e4cdfSPeter Ujfalusi 			cnl_ipc4_send_msg(sdev, hdev->delayed_ipc_tx_msg);
109483e4cdfSPeter Ujfalusi 	}
110483e4cdfSPeter Ujfalusi 
111e3105c0cSRanjani Sridharan 	return IRQ_HANDLED;
112e3105c0cSRanjani Sridharan }
113e3105c0cSRanjani Sridharan 
cnl_ipc_irq_thread(int irq,void * context)1148b98491aSRanjani Sridharan irqreturn_t cnl_ipc_irq_thread(int irq, void *context)
11527302052SLiam Girdwood {
11627302052SLiam Girdwood 	struct snd_sof_dev *sdev = context;
11727302052SLiam Girdwood 	u32 hipci;
11827302052SLiam Girdwood 	u32 hipcida;
11927302052SLiam Girdwood 	u32 hipctdr;
12027302052SLiam Girdwood 	u32 hipctdd;
12127302052SLiam Girdwood 	u32 msg;
12227302052SLiam Girdwood 	u32 msg_ext;
1233f58521bSPierre-Louis Bossart 	bool ipc_irq = false;
12427302052SLiam Girdwood 
12527302052SLiam Girdwood 	hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDA);
12627302052SLiam Girdwood 	hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDR);
127c24b1b72SPierre-Louis Bossart 	hipctdd = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDD);
128c24b1b72SPierre-Louis Bossart 	hipci = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDR);
12927302052SLiam Girdwood 
13027302052SLiam Girdwood 	/* reply message from DSP */
13109a173a6SPierre-Louis Bossart 	if (hipcida & CNL_DSP_REG_HIPCIDA_DONE) {
13227302052SLiam Girdwood 		msg_ext = hipci & CNL_DSP_REG_HIPCIDR_MSG_MASK;
13327302052SLiam Girdwood 		msg = hipcida & CNL_DSP_REG_HIPCIDA_MSG_MASK;
13427302052SLiam Girdwood 
135d272b657SBard Liao 		trace_sof_intel_ipc_firmware_response(sdev, msg, msg_ext);
13627302052SLiam Girdwood 
13727302052SLiam Girdwood 		/* mask Done interrupt */
13827302052SLiam Girdwood 		snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR,
13927302052SLiam Girdwood 					CNL_DSP_REG_HIPCCTL,
14027302052SLiam Girdwood 					CNL_DSP_REG_HIPCCTL_DONE, 0);
14127302052SLiam Girdwood 
142acacd9eeSPeter Ujfalusi 		if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
1431183e9a6SGuennadi Liakhovetski 			spin_lock_irq(&sdev->ipc_lock);
1441183e9a6SGuennadi Liakhovetski 
14527302052SLiam Girdwood 			/* handle immediate reply from DSP core */
14627302052SLiam Girdwood 			hda_dsp_ipc_get_reply(sdev);
14727302052SLiam Girdwood 			snd_sof_ipc_reply(sdev, msg);
14827302052SLiam Girdwood 
14927302052SLiam Girdwood 			cnl_ipc_dsp_done(sdev);
15027302052SLiam Girdwood 
1511183e9a6SGuennadi Liakhovetski 			spin_unlock_irq(&sdev->ipc_lock);
152acacd9eeSPeter Ujfalusi 		} else {
153acacd9eeSPeter Ujfalusi 			dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_READY: %#x\n",
154acacd9eeSPeter Ujfalusi 					    msg);
155acacd9eeSPeter Ujfalusi 		}
1561183e9a6SGuennadi Liakhovetski 
1573f58521bSPierre-Louis Bossart 		ipc_irq = true;
15827302052SLiam Girdwood 	}
15927302052SLiam Girdwood 
16027302052SLiam Girdwood 	/* new message from DSP */
16127302052SLiam Girdwood 	if (hipctdr & CNL_DSP_REG_HIPCTDR_BUSY) {
16227302052SLiam Girdwood 		msg = hipctdr & CNL_DSP_REG_HIPCTDR_MSG_MASK;
16327302052SLiam Girdwood 		msg_ext = hipctdd & CNL_DSP_REG_HIPCTDD_MSG_MASK;
16427302052SLiam Girdwood 
165d272b657SBard Liao 		trace_sof_intel_ipc_firmware_initiated(sdev, msg, msg_ext);
16627302052SLiam Girdwood 
16727302052SLiam Girdwood 		/* handle messages from DSP */
168b2b10aa7SPeter Ujfalusi 		if ((hipctdr & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC) {
169b2b10aa7SPeter Ujfalusi 			struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
170b2b10aa7SPeter Ujfalusi 			bool non_recoverable = true;
171b2b10aa7SPeter Ujfalusi 
172b2b10aa7SPeter Ujfalusi 			/*
173b2b10aa7SPeter Ujfalusi 			 * This is a PANIC message!
174b2b10aa7SPeter Ujfalusi 			 *
175b2b10aa7SPeter Ujfalusi 			 * If it is arriving during firmware boot and it is not
176b2b10aa7SPeter Ujfalusi 			 * the last boot attempt then change the non_recoverable
177b2b10aa7SPeter Ujfalusi 			 * to false as the DSP might be able to boot in the next
178b2b10aa7SPeter Ujfalusi 			 * iteration(s)
179b2b10aa7SPeter Ujfalusi 			 */
180b2b10aa7SPeter Ujfalusi 			if (sdev->fw_state == SOF_FW_BOOT_IN_PROGRESS &&
181b2b10aa7SPeter Ujfalusi 			    hda->boot_iteration < HDA_FW_BOOT_ATTEMPTS)
182b2b10aa7SPeter Ujfalusi 				non_recoverable = false;
183b2b10aa7SPeter Ujfalusi 
184b2b10aa7SPeter Ujfalusi 			snd_sof_dsp_panic(sdev, HDA_DSP_PANIC_OFFSET(msg_ext),
185b2b10aa7SPeter Ujfalusi 					  non_recoverable);
18627302052SLiam Girdwood 		} else {
18727302052SLiam Girdwood 			snd_sof_ipc_msgs_rx(sdev);
18827302052SLiam Girdwood 		}
18927302052SLiam Girdwood 
19027302052SLiam Girdwood 		cnl_ipc_host_done(sdev);
19127302052SLiam Girdwood 
1923f58521bSPierre-Louis Bossart 		ipc_irq = true;
19327302052SLiam Girdwood 	}
19427302052SLiam Girdwood 
1953f58521bSPierre-Louis Bossart 	if (!ipc_irq) {
1963f58521bSPierre-Louis Bossart 		/*
1973f58521bSPierre-Louis Bossart 		 * This interrupt is not shared so no need to return IRQ_NONE.
1983f58521bSPierre-Louis Bossart 		 */
199717dedb1SKai Vehmanen 		dev_dbg_ratelimited(sdev->dev,
200717dedb1SKai Vehmanen 				    "nothing to do in IPC IRQ thread\n");
2013f58521bSPierre-Louis Bossart 	}
2023f58521bSPierre-Louis Bossart 
2033f58521bSPierre-Louis Bossart 	return IRQ_HANDLED;
20427302052SLiam Girdwood }
20527302052SLiam Girdwood 
cnl_ipc_host_done(struct snd_sof_dev * sdev)20627302052SLiam Girdwood static void cnl_ipc_host_done(struct snd_sof_dev *sdev)
20727302052SLiam Girdwood {
20827302052SLiam Girdwood 	/*
209ddbe9223SPierre-Louis Bossart 	 * clear busy interrupt to tell dsp controller this
210ddbe9223SPierre-Louis Bossart 	 * interrupt has been accepted, not trigger it again
211ddbe9223SPierre-Louis Bossart 	 */
212ddbe9223SPierre-Louis Bossart 	snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR,
213ddbe9223SPierre-Louis Bossart 				       CNL_DSP_REG_HIPCTDR,
214ddbe9223SPierre-Louis Bossart 				       CNL_DSP_REG_HIPCTDR_BUSY,
215ddbe9223SPierre-Louis Bossart 				       CNL_DSP_REG_HIPCTDR_BUSY);
216ddbe9223SPierre-Louis Bossart 	/*
21727302052SLiam Girdwood 	 * set done bit to ack dsp the msg has been
21827302052SLiam Girdwood 	 * processed and send reply msg to dsp
21927302052SLiam Girdwood 	 */
22027302052SLiam Girdwood 	snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR,
22127302052SLiam Girdwood 				       CNL_DSP_REG_HIPCTDA,
22227302052SLiam Girdwood 				       CNL_DSP_REG_HIPCTDA_DONE,
22327302052SLiam Girdwood 				       CNL_DSP_REG_HIPCTDA_DONE);
22427302052SLiam Girdwood }
22527302052SLiam Girdwood 
cnl_ipc_dsp_done(struct snd_sof_dev * sdev)22627302052SLiam Girdwood static void cnl_ipc_dsp_done(struct snd_sof_dev *sdev)
22727302052SLiam Girdwood {
22827302052SLiam Girdwood 	/*
22927302052SLiam Girdwood 	 * set DONE bit - tell DSP we have received the reply msg
23027302052SLiam Girdwood 	 * from DSP, and processed it, don't send more reply to host
23127302052SLiam Girdwood 	 */
23227302052SLiam Girdwood 	snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR,
23327302052SLiam Girdwood 				       CNL_DSP_REG_HIPCIDA,
23427302052SLiam Girdwood 				       CNL_DSP_REG_HIPCIDA_DONE,
23527302052SLiam Girdwood 				       CNL_DSP_REG_HIPCIDA_DONE);
23627302052SLiam Girdwood 
23727302052SLiam Girdwood 	/* unmask Done interrupt */
23827302052SLiam Girdwood 	snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR,
23927302052SLiam Girdwood 				CNL_DSP_REG_HIPCCTL,
24027302052SLiam Girdwood 				CNL_DSP_REG_HIPCCTL_DONE,
24127302052SLiam Girdwood 				CNL_DSP_REG_HIPCCTL_DONE);
24227302052SLiam Girdwood }
24327302052SLiam Girdwood 
cnl_compact_ipc_compress(struct snd_sof_ipc_msg * msg,u32 * dr,u32 * dd)2440267de58SKeyon Jie static bool cnl_compact_ipc_compress(struct snd_sof_ipc_msg *msg,
2450267de58SKeyon Jie 				     u32 *dr, u32 *dd)
2460267de58SKeyon Jie {
2475b6988feSPeter Ujfalusi 	struct sof_ipc_pm_gate *pm_gate = msg->msg_data;
2480267de58SKeyon Jie 
2495b6988feSPeter Ujfalusi 	if (pm_gate->hdr.cmd == (SOF_IPC_GLB_PM_MSG | SOF_IPC_PM_GATE)) {
2500267de58SKeyon Jie 		/* send the compact message via the primary register */
2510267de58SKeyon Jie 		*dr = HDA_IPC_MSG_COMPACT | HDA_IPC_PM_GATE;
2520267de58SKeyon Jie 
2530267de58SKeyon Jie 		/* send payload via the extended data register */
2540267de58SKeyon Jie 		*dd = pm_gate->flags;
2550267de58SKeyon Jie 
2560267de58SKeyon Jie 		return true;
2570267de58SKeyon Jie 	}
2580267de58SKeyon Jie 
2590267de58SKeyon Jie 	return false;
2600267de58SKeyon Jie }
2610267de58SKeyon Jie 
cnl_ipc4_send_msg(struct snd_sof_dev * sdev,struct snd_sof_ipc_msg * msg)262e3105c0cSRanjani Sridharan int cnl_ipc4_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)
263e3105c0cSRanjani Sridharan {
264483e4cdfSPeter Ujfalusi 	struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
265e3105c0cSRanjani Sridharan 	struct sof_ipc4_msg *msg_data = msg->msg_data;
266e3105c0cSRanjani Sridharan 
267483e4cdfSPeter Ujfalusi 	if (hda_ipc4_tx_is_busy(sdev)) {
268483e4cdfSPeter Ujfalusi 		hdev->delayed_ipc_tx_msg = msg;
269483e4cdfSPeter Ujfalusi 		return 0;
270483e4cdfSPeter Ujfalusi 	}
271483e4cdfSPeter Ujfalusi 
272483e4cdfSPeter Ujfalusi 	hdev->delayed_ipc_tx_msg = NULL;
273483e4cdfSPeter Ujfalusi 
274e3105c0cSRanjani Sridharan 	/* send the message via mailbox */
275e3105c0cSRanjani Sridharan 	if (msg_data->data_size)
276e3105c0cSRanjani Sridharan 		sof_mailbox_write(sdev, sdev->host_box.offset, msg_data->data_ptr,
277e3105c0cSRanjani Sridharan 				  msg_data->data_size);
278e3105c0cSRanjani Sridharan 
279e3105c0cSRanjani Sridharan 	snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDD, msg_data->extension);
280e3105c0cSRanjani Sridharan 	snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDR,
281e3105c0cSRanjani Sridharan 			  msg_data->primary | CNL_DSP_REG_HIPCIDR_BUSY);
282e3105c0cSRanjani Sridharan 
2833e6b6ed3SRander Wang 	hda_dsp_ipc4_schedule_d0i3_work(hdev, msg);
2843e6b6ed3SRander Wang 
285e3105c0cSRanjani Sridharan 	return 0;
286e3105c0cSRanjani Sridharan }
287e3105c0cSRanjani Sridharan 
cnl_ipc_send_msg(struct snd_sof_dev * sdev,struct snd_sof_ipc_msg * msg)2888b98491aSRanjani Sridharan int cnl_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)
28927302052SLiam Girdwood {
29063e51fd3SRanjani Sridharan 	struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
29163e51fd3SRanjani Sridharan 	struct sof_ipc_cmd_hdr *hdr;
2920267de58SKeyon Jie 	u32 dr = 0;
2930267de58SKeyon Jie 	u32 dd = 0;
2940267de58SKeyon Jie 
29563e51fd3SRanjani Sridharan 	/*
29663e51fd3SRanjani Sridharan 	 * Currently the only compact IPC supported is the PM_GATE
29763e51fd3SRanjani Sridharan 	 * IPC which is used for transitioning the DSP between the
29863e51fd3SRanjani Sridharan 	 * D0I0 and D0I3 states. And these are sent only during the
29963e51fd3SRanjani Sridharan 	 * set_power_state() op. Therefore, there will never be a case
30063e51fd3SRanjani Sridharan 	 * that a compact IPC results in the DSP exiting D0I3 without
30163e51fd3SRanjani Sridharan 	 * the host and FW being in sync.
30263e51fd3SRanjani Sridharan 	 */
3030267de58SKeyon Jie 	if (cnl_compact_ipc_compress(msg, &dr, &dd)) {
3040267de58SKeyon Jie 		/* send the message via IPC registers */
3050267de58SKeyon Jie 		snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDD,
3060267de58SKeyon Jie 				  dd);
3070267de58SKeyon Jie 		snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDR,
3080267de58SKeyon Jie 				  CNL_DSP_REG_HIPCIDR_BUSY | dr);
30963e51fd3SRanjani Sridharan 		return 0;
31063e51fd3SRanjani Sridharan 	}
31163e51fd3SRanjani Sridharan 
3120267de58SKeyon Jie 	/* send the message via mailbox */
31327302052SLiam Girdwood 	sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data,
31427302052SLiam Girdwood 			  msg->msg_size);
31527302052SLiam Girdwood 	snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDR,
3166fbbc18eSDaniel Baluta 			  CNL_DSP_REG_HIPCIDR_BUSY);
31763e51fd3SRanjani Sridharan 
31863e51fd3SRanjani Sridharan 	hdr = msg->msg_data;
31963e51fd3SRanjani Sridharan 
32063e51fd3SRanjani Sridharan 	/*
32163e51fd3SRanjani Sridharan 	 * Use mod_delayed_work() to schedule the delayed work
32263e51fd3SRanjani Sridharan 	 * to avoid scheduling multiple workqueue items when
32363e51fd3SRanjani Sridharan 	 * IPCs are sent at a high-rate. mod_delayed_work()
32463e51fd3SRanjani Sridharan 	 * modifies the timer if the work is pending.
32563e51fd3SRanjani Sridharan 	 * Also, a new delayed work should not be queued after the
3268932f0cbSRandy Dunlap 	 * CTX_SAVE IPC, which is sent before the DSP enters D3.
32763e51fd3SRanjani Sridharan 	 */
32863e51fd3SRanjani Sridharan 	if (hdr->cmd != (SOF_IPC_GLB_PM_MSG | SOF_IPC_PM_CTX_SAVE))
32963e51fd3SRanjani Sridharan 		mod_delayed_work(system_wq, &hdev->d0i3_work,
33063e51fd3SRanjani Sridharan 				 msecs_to_jiffies(SOF_HDA_D0I3_WORK_DELAY_MS));
33127302052SLiam Girdwood 
33227302052SLiam Girdwood 	return 0;
33327302052SLiam Girdwood }
33427302052SLiam Girdwood 
cnl_ipc_dump(struct snd_sof_dev * sdev)3358b98491aSRanjani Sridharan void cnl_ipc_dump(struct snd_sof_dev *sdev)
336dc20e5f3SPan Xiuli {
337dc20e5f3SPan Xiuli 	u32 hipcctl;
338dc20e5f3SPan Xiuli 	u32 hipcida;
339dc20e5f3SPan Xiuli 	u32 hipctdr;
340dc20e5f3SPan Xiuli 
341f1fd9d0eSKai Vehmanen 	hda_ipc_irq_dump(sdev);
342f1fd9d0eSKai Vehmanen 
343dc20e5f3SPan Xiuli 	/* read IPC status */
344dc20e5f3SPan Xiuli 	hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDA);
345dc20e5f3SPan Xiuli 	hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCCTL);
346dc20e5f3SPan Xiuli 	hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDR);
347dc20e5f3SPan Xiuli 
348dc20e5f3SPan Xiuli 	/* dump the IPC regs */
349dc20e5f3SPan Xiuli 	/* TODO: parse the raw msg */
350dc20e5f3SPan Xiuli 	dev_err(sdev->dev,
351dc20e5f3SPan Xiuli 		"error: host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n",
352dc20e5f3SPan Xiuli 		hipcida, hipctdr, hipcctl);
353dc20e5f3SPan Xiuli }
354dc20e5f3SPan Xiuli 
cnl_ipc4_dump(struct snd_sof_dev * sdev)355a996a333SPeter Ujfalusi void cnl_ipc4_dump(struct snd_sof_dev *sdev)
356a996a333SPeter Ujfalusi {
357a996a333SPeter Ujfalusi 	u32 hipcidr, hipcidd, hipcida, hipctdr, hipctdd, hipctda, hipcctl;
358a996a333SPeter Ujfalusi 
359a996a333SPeter Ujfalusi 	hda_ipc_irq_dump(sdev);
360a996a333SPeter Ujfalusi 
361a996a333SPeter Ujfalusi 	hipcidr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDR);
362a996a333SPeter Ujfalusi 	hipcidd = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDD);
363a996a333SPeter Ujfalusi 	hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDA);
364a996a333SPeter Ujfalusi 	hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDR);
365a996a333SPeter Ujfalusi 	hipctdd = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDD);
366a996a333SPeter Ujfalusi 	hipctda = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDA);
367a996a333SPeter Ujfalusi 	hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCCTL);
368a996a333SPeter Ujfalusi 
369a996a333SPeter Ujfalusi 	/* dump the IPC regs */
370a996a333SPeter Ujfalusi 	/* TODO: parse the raw msg */
371a996a333SPeter Ujfalusi 	dev_err(sdev->dev,
372a996a333SPeter Ujfalusi 		"Host IPC initiator: %#x|%#x|%#x, target: %#x|%#x|%#x, ctl: %#x\n",
373a996a333SPeter Ujfalusi 		hipcidr, hipcidd, hipcida, hipctdr, hipctdd, hipctda, hipcctl);
374a996a333SPeter Ujfalusi }
375a996a333SPeter Ujfalusi 
37627302052SLiam Girdwood /* cannonlake ops */
37737e809d5SPierre-Louis Bossart struct snd_sof_dsp_ops sof_cnl_ops;
37837e809d5SPierre-Louis Bossart EXPORT_SYMBOL_NS(sof_cnl_ops, SND_SOC_SOF_INTEL_HDA_COMMON);
37937e809d5SPierre-Louis Bossart 
sof_cnl_ops_init(struct snd_sof_dev * sdev)38037e809d5SPierre-Louis Bossart int sof_cnl_ops_init(struct snd_sof_dev *sdev)
38137e809d5SPierre-Louis Bossart {
38237e809d5SPierre-Louis Bossart 	/* common defaults */
38337e809d5SPierre-Louis Bossart 	memcpy(&sof_cnl_ops, &sof_hda_common_ops, sizeof(struct snd_sof_dsp_ops));
38437e809d5SPierre-Louis Bossart 
385b0503e84SLibin Yang 	/* probe/remove/shutdown */
38637e809d5SPierre-Louis Bossart 	sof_cnl_ops.shutdown	= hda_dsp_shutdown;
387f71f59ddSDaniel Baluta 
388e3105c0cSRanjani Sridharan 	/* ipc */
389e3105c0cSRanjani Sridharan 	if (sdev->pdata->ipc_type == SOF_IPC) {
39027302052SLiam Girdwood 		/* doorbell */
39137e809d5SPierre-Louis Bossart 		sof_cnl_ops.irq_thread	= cnl_ipc_irq_thread;
39227302052SLiam Girdwood 
39327302052SLiam Girdwood 		/* ipc */
39437e809d5SPierre-Louis Bossart 		sof_cnl_ops.send_msg	= cnl_ipc_send_msg;
395a996a333SPeter Ujfalusi 
396a996a333SPeter Ujfalusi 		/* debug */
397a996a333SPeter Ujfalusi 		sof_cnl_ops.ipc_dump	= cnl_ipc_dump;
398996b07efSRanjani Sridharan 
399996b07efSRanjani Sridharan 		sof_cnl_ops.set_power_state = hda_dsp_set_power_state_ipc3;
400e3105c0cSRanjani Sridharan 	}
401e3105c0cSRanjani Sridharan 
402e3105c0cSRanjani Sridharan 	if (sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
403a4cfdebdSRanjani Sridharan 		struct sof_ipc4_fw_data *ipc4_data;
404a4cfdebdSRanjani Sridharan 
405a4cfdebdSRanjani Sridharan 		sdev->private = devm_kzalloc(sdev->dev, sizeof(*ipc4_data), GFP_KERNEL);
406a4cfdebdSRanjani Sridharan 		if (!sdev->private)
407a4cfdebdSRanjani Sridharan 			return -ENOMEM;
408a4cfdebdSRanjani Sridharan 
409a4cfdebdSRanjani Sridharan 		ipc4_data = sdev->private;
410a4cfdebdSRanjani Sridharan 		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;
411a4cfdebdSRanjani Sridharan 
412cc4a3a19SPeter Ujfalusi 		ipc4_data->mtrace_type = SOF_IPC4_MTRACE_INTEL_CAVS_1_8;
413cc4a3a19SPeter Ujfalusi 
4143ab2c21eSPeter Ujfalusi 		/* External library loading support */
4153ab2c21eSPeter Ujfalusi 		ipc4_data->load_library = hda_dsp_ipc4_load_library;
4163ab2c21eSPeter Ujfalusi 
417a4cfdebdSRanjani Sridharan 		/* doorbell */
418e3105c0cSRanjani Sridharan 		sof_cnl_ops.irq_thread	= cnl_ipc4_irq_thread;
419e3105c0cSRanjani Sridharan 
420e3105c0cSRanjani Sridharan 		/* ipc */
421e3105c0cSRanjani Sridharan 		sof_cnl_ops.send_msg	= cnl_ipc4_send_msg;
422a996a333SPeter Ujfalusi 
423a996a333SPeter Ujfalusi 		/* debug */
424a996a333SPeter Ujfalusi 		sof_cnl_ops.ipc_dump	= cnl_ipc4_dump;
425996b07efSRanjani Sridharan 
426996b07efSRanjani Sridharan 		sof_cnl_ops.set_power_state = hda_dsp_set_power_state_ipc4;
427e3105c0cSRanjani Sridharan 	}
428285880a2SDaniel Baluta 
42951ec71dcSRanjani Sridharan 	/* set DAI driver ops */
43051ec71dcSRanjani Sridharan 	hda_set_dai_drv_ops(sdev, &sof_cnl_ops);
43151ec71dcSRanjani Sridharan 
43227302052SLiam Girdwood 	/* debug */
43337e809d5SPierre-Louis Bossart 	sof_cnl_ops.debug_map	= cnl_dsp_debugfs;
43437e809d5SPierre-Louis Bossart 	sof_cnl_ops.debug_map_count	= ARRAY_SIZE(cnl_dsp_debugfs);
43527302052SLiam Girdwood 
43627302052SLiam Girdwood 	/* pre/post fw run */
43737e809d5SPierre-Louis Bossart 	sof_cnl_ops.post_fw_run = hda_dsp_post_fw_run;
43827302052SLiam Girdwood 
43927302052SLiam Girdwood 	/* firmware run */
44037e809d5SPierre-Louis Bossart 	sof_cnl_ops.run = hda_dsp_cl_boot_firmware;
44127302052SLiam Girdwood 
44237e809d5SPierre-Louis Bossart 	/* dsp core get/put */
44337e809d5SPierre-Louis Bossart 	sof_cnl_ops.core_get = hda_dsp_core_get;
44427302052SLiam Girdwood 
44537e809d5SPierre-Louis Bossart 	return 0;
44627302052SLiam Girdwood };
44737e809d5SPierre-Louis Bossart EXPORT_SYMBOL_NS(sof_cnl_ops_init, SND_SOC_SOF_INTEL_HDA_COMMON);
44827302052SLiam Girdwood 
44927302052SLiam Girdwood const struct sof_intel_dsp_desc cnl_chip_info = {
45027302052SLiam Girdwood 	/* Cannonlake */
45127302052SLiam Girdwood 	.cores_num = 4,
45227302052SLiam Girdwood 	.init_core_mask = 1,
453fde10655SRanjani Sridharan 	.host_managed_cores_mask = GENMASK(3, 0),
45427302052SLiam Girdwood 	.ipc_req = CNL_DSP_REG_HIPCIDR,
45527302052SLiam Girdwood 	.ipc_req_mask = CNL_DSP_REG_HIPCIDR_BUSY,
45627302052SLiam Girdwood 	.ipc_ack = CNL_DSP_REG_HIPCIDA,
45727302052SLiam Girdwood 	.ipc_ack_mask = CNL_DSP_REG_HIPCIDA_DONE,
45827302052SLiam Girdwood 	.ipc_ctl = CNL_DSP_REG_HIPCCTL,
45971778f79SRanjani Sridharan 	.rom_status_reg = HDA_DSP_SRAM_REG_ROM_STATUS,
46027302052SLiam Girdwood 	.rom_init_timeout	= 300,
461b095fe47SZhu Yingjiang 	.ssp_count = CNL_SSP_COUNT,
462b095fe47SZhu Yingjiang 	.ssp_base_offset = CNL_SSP_BASE_OFFSET,
4631cbf6443SBard Liao 	.sdw_shim_base = SDW_SHIM_BASE,
4641cbf6443SBard Liao 	.sdw_alh_base = SDW_ALH_BASE,
465f8632adcSRander Wang 	.d0i3_offset = SOF_HDA_VS_D0I3C,
466625339caSPierre-Louis Bossart 	.read_sdw_lcount =  hda_sdw_check_lcount_common,
4678ebc9074SPierre-Louis Bossart 	.enable_sdw_irq	= hda_common_enable_sdw_irq,
468198fa4bcSBard Liao 	.check_sdw_irq	= hda_common_check_sdw_irq,
469*9362ab78SPierre-Louis Bossart 	.check_sdw_wakeen_irq = hda_sdw_check_wakeen_irq_common,
4703dee239eSRanjani Sridharan 	.check_ipc_irq	= hda_dsp_check_ipc_irq,
471ab222a4aSBard Liao 	.cl_init = cl_dsp_init,
472c714031fSFred Oh 	.power_down_dsp = hda_power_down_dsp,
473b2520dbcSRanjani Sridharan 	.disable_interrupts = hda_dsp_disable_interrupts,
47403cf7262SPierre-Louis Bossart 	.hw_ip_version = SOF_INTEL_CAVS_1_8,
47527302052SLiam Girdwood };
476cf5629e4SPierre-Louis Bossart EXPORT_SYMBOL_NS(cnl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON);
477630be964SZhu Yingjiang 
478290a7c55SPierre-Louis Bossart /*
479290a7c55SPierre-Louis Bossart  * JasperLake is technically derived from IceLake, and should be in
480290a7c55SPierre-Louis Bossart  * described in icl.c. However since JasperLake was designed with
481290a7c55SPierre-Louis Bossart  * two cores, it cannot support the IceLake-specific power-up sequences
482290a7c55SPierre-Louis Bossart  * which rely on core3. To simplify, JasperLake uses the CannonLake ops and
483290a7c55SPierre-Louis Bossart  * is described in cnl.c
484290a7c55SPierre-Louis Bossart  */
4856fd99035SPan Xiuli const struct sof_intel_dsp_desc jsl_chip_info = {
4866fd99035SPan Xiuli 	/* Jasperlake */
4876fd99035SPan Xiuli 	.cores_num = 2,
4886fd99035SPan Xiuli 	.init_core_mask = 1,
489fde10655SRanjani Sridharan 	.host_managed_cores_mask = GENMASK(1, 0),
4906fd99035SPan Xiuli 	.ipc_req = CNL_DSP_REG_HIPCIDR,
4916fd99035SPan Xiuli 	.ipc_req_mask = CNL_DSP_REG_HIPCIDR_BUSY,
4926fd99035SPan Xiuli 	.ipc_ack = CNL_DSP_REG_HIPCIDA,
4936fd99035SPan Xiuli 	.ipc_ack_mask = CNL_DSP_REG_HIPCIDA_DONE,
4946fd99035SPan Xiuli 	.ipc_ctl = CNL_DSP_REG_HIPCCTL,
49571778f79SRanjani Sridharan 	.rom_status_reg = HDA_DSP_SRAM_REG_ROM_STATUS,
4966fd99035SPan Xiuli 	.rom_init_timeout	= 300,
4976fd99035SPan Xiuli 	.ssp_count = ICL_SSP_COUNT,
4986fd99035SPan Xiuli 	.ssp_base_offset = CNL_SSP_BASE_OFFSET,
4991cbf6443SBard Liao 	.sdw_shim_base = SDW_SHIM_BASE,
5001cbf6443SBard Liao 	.sdw_alh_base = SDW_ALH_BASE,
501f8632adcSRander Wang 	.d0i3_offset = SOF_HDA_VS_D0I3C,
502625339caSPierre-Louis Bossart 	.read_sdw_lcount =  hda_sdw_check_lcount_common,
5038ebc9074SPierre-Louis Bossart 	.enable_sdw_irq	= hda_common_enable_sdw_irq,
504198fa4bcSBard Liao 	.check_sdw_irq	= hda_common_check_sdw_irq,
505*9362ab78SPierre-Louis Bossart 	.check_sdw_wakeen_irq = hda_sdw_check_wakeen_irq_common,
5063dee239eSRanjani Sridharan 	.check_ipc_irq	= hda_dsp_check_ipc_irq,
507ab222a4aSBard Liao 	.cl_init = cl_dsp_init,
508c714031fSFred Oh 	.power_down_dsp = hda_power_down_dsp,
509b2520dbcSRanjani Sridharan 	.disable_interrupts = hda_dsp_disable_interrupts,
51003cf7262SPierre-Louis Bossart 	.hw_ip_version = SOF_INTEL_CAVS_2_0,
5116fd99035SPan Xiuli };
512cf5629e4SPierre-Louis Bossart EXPORT_SYMBOL_NS(jsl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON);
513