xref: /linux/sound/soc/sof/intel/lnl.c (revision a67c554dbc0fdd7e3c5909cb9f0fff41c51b2e9d)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // Copyright(c) 2023 Intel Corporation
4 
5 /*
6  * Hardware interface for audio DSP on LunarLake.
7  */
8 
9 #include <linux/debugfs.h>
10 #include <linux/firmware.h>
11 #include <sound/hda_register.h>
12 #include <sound/sof/ipc4/header.h>
13 #include <trace/events/sof_intel.h>
14 #include "../ipc4-priv.h"
15 #include "../ops.h"
16 #include "hda.h"
17 #include "hda-ipc.h"
18 #include "../sof-audio.h"
19 #include "mtl.h"
20 #include "lnl.h"
21 #include <sound/hda-mlink.h>
22 
23 /* Configure DSP offload for DMIC/SSP/UAOL */
24 static void hdac_bus_set_dsp_offload(struct hdac_bus *bus, bool enable)
25 {
26 	hdac_bus_eml_enable_offload(bus, true, AZX_REG_ML_LEPTR_ID_INTEL_SSP, enable);
27 	hdac_bus_eml_enable_offload(bus, true, AZX_REG_ML_LEPTR_ID_INTEL_DMIC, enable);
28 	hdac_bus_eml_enable_offload(bus, true, AZX_REG_ML_LEPTR_ID_INTEL_UAOL, enable);
29 }
30 
31 static int lnl_hda_dsp_probe(struct snd_sof_dev *sdev)
32 {
33 	int ret;
34 
35 	ret = hda_dsp_probe(sdev);
36 	if (ret < 0)
37 		return ret;
38 
39 	hdac_bus_set_dsp_offload(sof_to_bus(sdev), true);
40 
41 	return 0;
42 }
43 
44 static void lnl_hda_dsp_remove(struct snd_sof_dev *sdev)
45 {
46 	hdac_bus_set_dsp_offload(sof_to_bus(sdev), false);
47 	hda_dsp_remove(sdev);
48 }
49 
50 static int lnl_hda_dsp_resume(struct snd_sof_dev *sdev)
51 {
52 	int ret;
53 
54 	ret = hda_dsp_resume(sdev);
55 	if (ret < 0)
56 		return ret;
57 
58 	hdac_bus_set_dsp_offload(sof_to_bus(sdev), true);
59 
60 	return 0;
61 }
62 
63 static int lnl_hda_dsp_runtime_resume(struct snd_sof_dev *sdev)
64 {
65 	int ret;
66 
67 	ret = hda_dsp_runtime_resume(sdev);
68 	if (ret < 0)
69 		return ret;
70 
71 	hdac_bus_set_dsp_offload(sof_to_bus(sdev), true);
72 
73 	return 0;
74 }
75 
76 static int lnl_dsp_post_fw_run(struct snd_sof_dev *sdev)
77 {
78 	if (sdev->first_boot) {
79 		struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
80 
81 		/* Check if IMR boot is usable */
82 		if (!sof_debug_check_flag(SOF_DBG_IGNORE_D3_PERSISTENT)) {
83 			hda->imrboot_supported = true;
84 			debugfs_create_bool("skip_imr_boot",
85 					    0644, sdev->debugfs_root,
86 					    &hda->skip_imr_boot);
87 		}
88 	}
89 
90 	return 0;
91 }
92 
93 int sof_lnl_set_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *dsp_ops)
94 {
95 	int ret;
96 
97 	ret = sof_mtl_set_ops(sdev, dsp_ops);
98 	if (ret)
99 		return ret;
100 
101 	/* probe/remove */
102 	if (!sdev->dspless_mode_selected) {
103 		dsp_ops->probe = lnl_hda_dsp_probe;
104 		dsp_ops->remove = lnl_hda_dsp_remove;
105 	}
106 
107 	/* post fw run */
108 	dsp_ops->post_fw_run = lnl_dsp_post_fw_run;
109 
110 	/* PM */
111 	if (!sdev->dspless_mode_selected) {
112 		dsp_ops->resume = lnl_hda_dsp_resume;
113 		dsp_ops->runtime_resume = lnl_hda_dsp_runtime_resume;
114 	}
115 
116 	return 0;
117 }
118 EXPORT_SYMBOL_NS(sof_lnl_set_ops, "SND_SOC_SOF_INTEL_LNL");
119 
120 /* Check if an SDW IRQ occurred */
121 bool lnl_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
122 {
123 	struct hdac_bus *bus = sof_to_bus(sdev);
124 
125 	return hdac_bus_eml_check_interrupt(bus, true,  AZX_REG_ML_LEPTR_ID_SDW);
126 }
127 EXPORT_SYMBOL_NS(lnl_dsp_check_sdw_irq, "SND_SOC_SOF_INTEL_LNL");
128 
129 int lnl_dsp_disable_interrupts(struct snd_sof_dev *sdev)
130 {
131 	mtl_disable_ipc_interrupts(sdev);
132 	return mtl_enable_interrupts(sdev, false);
133 }
134 EXPORT_SYMBOL_NS(lnl_dsp_disable_interrupts, "SND_SOC_SOF_INTEL_LNL");
135 
136 bool lnl_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
137 {
138 	struct hdac_bus *bus = sof_to_bus(sdev);
139 	u16 wake_sts;
140 
141 	/*
142 	 * we need to use the global HDaudio WAKEEN/STS to be able to
143 	 * detect wakes in low-power modes. The link-specific information
144 	 * is handled in the process_wakeen() helper, this helper only
145 	 * detects a SoundWire wake without identifying the link.
146 	 */
147 	wake_sts = snd_hdac_chip_readw(bus, STATESTS);
148 
149 	/* filter out the range of SDIs that can be set for SoundWire */
150 	return wake_sts & GENMASK(SDW_MAX_DEVICES, SDW_INTEL_DEV_NUM_IDA_MIN);
151 }
152 EXPORT_SYMBOL_NS(lnl_sdw_check_wakeen_irq, "SND_SOC_SOF_INTEL_LNL");
153 
154 const struct sof_intel_dsp_desc lnl_chip_info = {
155 	.cores_num = 5,
156 	.init_core_mask = BIT(0),
157 	.host_managed_cores_mask = BIT(0),
158 	.ipc_req = MTL_DSP_REG_HFIPCXIDR,
159 	.ipc_req_mask = MTL_DSP_REG_HFIPCXIDR_BUSY,
160 	.ipc_ack = MTL_DSP_REG_HFIPCXIDA,
161 	.ipc_ack_mask = MTL_DSP_REG_HFIPCXIDA_DONE,
162 	.ipc_ctl = MTL_DSP_REG_HFIPCXCTL,
163 	.rom_status_reg = LNL_DSP_REG_HFDSC,
164 	.rom_init_timeout = 300,
165 	.ssp_count = MTL_SSP_COUNT,
166 	.d0i3_offset = MTL_HDA_VS_D0I3C,
167 	.read_sdw_lcount =  hda_sdw_check_lcount_ext,
168 	.check_sdw_irq = lnl_dsp_check_sdw_irq,
169 	.check_sdw_wakeen_irq = lnl_sdw_check_wakeen_irq,
170 	.sdw_process_wakeen = hda_sdw_process_wakeen_common,
171 	.check_ipc_irq = mtl_dsp_check_ipc_irq,
172 	.cl_init = mtl_dsp_cl_init,
173 	.power_down_dsp = mtl_power_down_dsp,
174 	.disable_interrupts = lnl_dsp_disable_interrupts,
175 	.hw_ip_version = SOF_INTEL_ACE_2_0,
176 	.platform = "lnl",
177 };
178 
179 MODULE_IMPORT_NS("SND_SOC_SOF_INTEL_MTL");
180 MODULE_IMPORT_NS("SND_SOC_SOF_HDA_MLINK");
181