blob: 2c0d4d06ab364125a4a3a987c1000385905a7042 [file] [log] [blame]
Pierre-Louis Bossarte149ca22020-05-01 09:58:50 -05001// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
Liam Girdwooddd96dac2019-04-12 11:08:47 -05002//
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 <liam.r.girdwood@linux.intel.com>
9// Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
10// Rander Wang <rander.wang@intel.com>
11// Keyon Jie <yang.jie@linux.intel.com>
12//
13
14/*
15 * Hardware interface for generic Intel audio DSP HDA IP
16 */
17
Liam Girdwooddd96dac2019-04-12 11:08:47 -050018#include <sound/hdaudio_ext.h>
Kai Vehmanenf1fd9d02019-06-12 11:57:03 -050019#include <sound/hda_register.h>
20
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -050021#include <linux/acpi.h>
Liam Girdwooddd96dac2019-04-12 11:08:47 -050022#include <linux/module.h>
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -050023#include <linux/soundwire/sdw.h>
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -050024#include <linux/soundwire/sdw_intel.h>
Pierre-Louis Bossart194fe0f2021-03-01 18:31:22 -060025#include <sound/intel-dsp-config.h>
Pierre-Louis Bossart68b953a2019-08-12 11:06:23 -050026#include <sound/intel-nhlt.h>
Liam Girdwooddd96dac2019-04-12 11:08:47 -050027#include <sound/sof.h>
28#include <sound/sof/xtensa.h>
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -050029#include "../sof-audio.h"
Pierre-Louis Bossart194fe0f2021-03-01 18:31:22 -060030#include "../sof-pci-dev.h"
Liam Girdwooddd96dac2019-04-12 11:08:47 -050031#include "../ops.h"
32#include "hda.h"
Liam Girdwooddd96dac2019-04-12 11:08:47 -050033
34#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
35#include <sound/soc-acpi-intel-match.h>
36#endif
37
38/* platform specific devices */
39#include "shim.h"
40
Liam Girdwoodff2be862019-09-27 15:05:36 -050041#define EXCEPT_MAX_HDR_SIZE 0x400
Ranjani Sridharan29c8e432020-08-25 16:50:38 -070042#define HDA_EXT_ROM_STATUS_SIZE 8
Liam Girdwoodff2be862019-09-27 15:05:36 -050043
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +030044int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w)
45{
46 struct snd_sof_widget *swidget = w->dobj.private;
47 struct snd_soc_component *component = swidget->scomp;
48 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
49 struct sof_ipc_dai_config *config;
50 struct snd_sof_dai *sof_dai;
51 struct sof_ipc_reply reply;
52 int ret;
53
54 sof_dai = swidget->private;
55
56 if (!sof_dai || !sof_dai->dai_config) {
57 dev_err(sdev->dev, "No config for DAI %s\n", w->name);
58 return -EINVAL;
59 }
60
Ranjani Sridharan86f74ba2021-11-23 18:57:59 +020061 /* DAI already configured, reset it before reconfiguring it */
62 if (sof_dai->configured) {
63 ret = hda_ctrl_dai_widget_free(w);
64 if (ret < 0)
65 return ret;
66 }
67
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +030068 config = &sof_dai->dai_config[sof_dai->current_config];
69
70 /*
71 * For static pipelines, the DAI widget would already be set up and calling
72 * sof_widget_setup() simply returns without doing anything.
73 * For dynamic pipelines, the DAI widget will be set up now.
74 */
75 ret = sof_widget_setup(sdev, swidget);
76 if (ret < 0) {
77 dev_err(sdev->dev, "error: failed setting up DAI widget %s\n", w->name);
78 return ret;
79 }
80
Pierre-Louis Bossartb30b60a2021-10-04 12:14:28 -050081 /* set HW_PARAMS flag */
82 config->flags = FIELD_PREP(SOF_DAI_CONFIG_FLAGS_MASK, SOF_DAI_CONFIG_FLAGS_HW_PARAMS);
83
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +030084 /* send DAI_CONFIG IPC */
85 ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size,
86 &reply, sizeof(reply));
87 if (ret < 0) {
88 dev_err(sdev->dev, "error: failed setting DAI config for %s\n", w->name);
89 return ret;
90 }
91
92 sof_dai->configured = true;
93
94 return 0;
95}
96
97int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w)
98{
99 struct snd_sof_widget *swidget = w->dobj.private;
100 struct snd_soc_component *component = swidget->scomp;
101 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
102 struct sof_ipc_dai_config *config;
103 struct snd_sof_dai *sof_dai;
104 struct sof_ipc_reply reply;
105 int ret;
106
107 sof_dai = swidget->private;
108
109 if (!sof_dai || !sof_dai->dai_config) {
110 dev_err(sdev->dev, "error: No config to free DAI %s\n", w->name);
111 return -EINVAL;
112 }
113
114 /* nothing to do if hw_free() is called without restarting the stream after resume. */
115 if (!sof_dai->configured)
116 return 0;
117
118 config = &sof_dai->dai_config[sof_dai->current_config];
119
Pierre-Louis Bossartb30b60a2021-10-04 12:14:28 -0500120 /* set HW_FREE flag */
121 config->flags = FIELD_PREP(SOF_DAI_CONFIG_FLAGS_MASK, SOF_DAI_CONFIG_FLAGS_HW_FREE);
122
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300123 ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size,
124 &reply, sizeof(reply));
125 if (ret < 0)
126 dev_err(sdev->dev, "error: failed resetting DAI config for %s\n", w->name);
127
128 /*
129 * Reset the configured_flag and free the widget even if the IPC fails to keep
130 * the widget use_count balanced
131 */
132 sof_dai->configured = false;
133
134 return sof_widget_free(sdev, swidget);
135}
136
Ranjani Sridharan5fcdbb22021-09-27 15:05:16 +0300137static const struct sof_intel_dsp_desc
138 *get_chip_info(struct snd_sof_pdata *pdata)
139{
140 const struct sof_dev_desc *desc = pdata->desc;
141 const struct sof_intel_dsp_desc *chip_info;
142
143 chip_info = desc->chip_info;
144
145 return chip_info;
146}
147
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500148#if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
149
Pierre-Louis Bossart02df8f42020-03-25 16:50:24 -0500150/*
151 * The default for SoundWire clock stop quirks is to power gate the IP
152 * and do a Bus Reset, this will need to be modified when the DSP
153 * needs to remain in D0i3 so that the Master does not lose context
154 * and enumeration is not required on clock restart
155 */
156static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET;
157module_param(sdw_clock_stop_quirks, int, 0444);
158MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks");
159
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300160static int sdw_dai_config_ipc(struct snd_sof_dev *sdev,
161 struct snd_soc_dapm_widget *w,
162 int link_id, int alh_stream_id, int dai_id, bool setup)
163{
164 struct snd_sof_widget *swidget = w->dobj.private;
165 struct sof_ipc_dai_config *config;
166 struct snd_sof_dai *sof_dai;
167
168 if (!swidget) {
169 dev_err(sdev->dev, "error: No private data for widget %s\n", w->name);
170 return -EINVAL;
171 }
172
173 sof_dai = swidget->private;
174
175 if (!sof_dai || !sof_dai->dai_config) {
176 dev_err(sdev->dev, "error: No config for DAI %s\n", w->name);
177 return -EINVAL;
178 }
179
180 config = &sof_dai->dai_config[sof_dai->current_config];
181
182 /* update config with link and stream ID */
183 config->dai_index = (link_id << 8) | dai_id;
184 config->alh.stream_id = alh_stream_id;
185
186 if (setup)
187 return hda_ctrl_dai_widget_setup(w);
188
189 return hda_ctrl_dai_widget_free(w);
190}
191
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500192static int sdw_params_stream(struct device *dev,
193 struct sdw_intel_stream_params_data *params_data)
194{
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300195 struct snd_pcm_substream *substream = params_data->substream;
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500196 struct snd_sof_dev *sdev = dev_get_drvdata(dev);
197 struct snd_soc_dai *d = params_data->dai;
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300198 struct snd_soc_dapm_widget *w;
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500199
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300200 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
201 w = d->playback_widget;
202 else
203 w = d->capture_widget;
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500204
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300205 return sdw_dai_config_ipc(sdev, w, params_data->link_id, params_data->alh_stream_id,
206 d->id, true);
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500207}
208
209static int sdw_free_stream(struct device *dev,
210 struct sdw_intel_stream_free_data *free_data)
211{
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300212 struct snd_pcm_substream *substream = free_data->substream;
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500213 struct snd_sof_dev *sdev = dev_get_drvdata(dev);
214 struct snd_soc_dai *d = free_data->dai;
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300215 struct snd_soc_dapm_widget *w;
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500216
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300217 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
218 w = d->playback_widget;
219 else
220 w = d->capture_widget;
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500221
Ranjani Sridharan0acb48d2021-09-27 15:05:15 +0300222 /* send invalid stream_id */
223 return sdw_dai_config_ipc(sdev, w, free_data->link_id, 0xFFFF, d->id, false);
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500224}
225
226static const struct sdw_intel_ops sdw_callback = {
227 .params_stream = sdw_params_stream,
228 .free_stream = sdw_free_stream,
229};
230
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500231void hda_sdw_int_enable(struct snd_sof_dev *sdev, bool enable)
232{
233 sdw_intel_enable_irq(sdev->bar[HDA_DSP_BAR], enable);
234}
235
236static int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
237{
238 struct sof_intel_hda_dev *hdev;
239 acpi_handle handle;
240 int ret;
241
242 handle = ACPI_HANDLE(sdev->dev);
243
244 /* save ACPI info for the probe step */
245 hdev = sdev->pdata->hw_pdata;
246
247 ret = sdw_intel_acpi_scan(handle, &hdev->info);
Pierre-Louis Bossart0d4453e2020-04-09 13:44:14 -0500248 if (ret < 0)
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500249 return -EINVAL;
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500250
251 return 0;
252}
253
254static int hda_sdw_probe(struct snd_sof_dev *sdev)
255{
256 struct sof_intel_hda_dev *hdev;
257 struct sdw_intel_res res;
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500258 void *sdw;
259
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500260 hdev = sdev->pdata->hw_pdata;
261
262 memset(&res, 0, sizeof(res));
263
264 res.mmio_base = sdev->bar[HDA_DSP_BAR];
Bard Liao60e9feb2021-07-23 19:54:51 +0800265 res.shim_base = hdev->desc->sdw_shim_base;
266 res.alh_base = hdev->desc->sdw_alh_base;
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500267 res.irq = sdev->ipc_irq;
268 res.handle = hdev->info.handle;
269 res.parent = sdev->dev;
Pierre-Louis Bossartd2c383a2020-03-25 16:50:20 -0500270 res.ops = &sdw_callback;
271 res.dev = sdev->dev;
Pierre-Louis Bossart02df8f42020-03-25 16:50:24 -0500272 res.clock_stop_quirks = sdw_clock_stop_quirks;
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500273
274 /*
275 * ops and arg fields are not populated for now,
276 * they will be needed when the DAI callbacks are
277 * provided
278 */
279
280 /* we could filter links here if needed, e.g for quirks */
281 res.count = hdev->info.count;
282 res.link_mask = hdev->info.link_mask;
283
284 sdw = sdw_intel_probe(&res);
285 if (!sdw) {
286 dev_err(sdev->dev, "error: SoundWire probe failed\n");
287 return -EINVAL;
288 }
289
290 /* save context */
291 hdev->sdw = sdw;
292
293 return 0;
294}
295
296int hda_sdw_startup(struct snd_sof_dev *sdev)
297{
298 struct sof_intel_hda_dev *hdev;
Pierre-Louis Bossart61bef9e2021-07-26 13:28:55 -0500299 struct snd_sof_pdata *pdata = sdev->pdata;
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500300
301 hdev = sdev->pdata->hw_pdata;
302
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -0500303 if (!hdev->sdw)
304 return 0;
305
Pierre-Louis Bossart61bef9e2021-07-26 13:28:55 -0500306 if (pdata->machine && !pdata->machine->mach_params.link_mask)
307 return 0;
308
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500309 return sdw_intel_startup(hdev->sdw);
310}
311
312static int hda_sdw_exit(struct snd_sof_dev *sdev)
313{
314 struct sof_intel_hda_dev *hdev;
315
316 hdev = sdev->pdata->hw_pdata;
317
318 hda_sdw_int_enable(sdev, false);
319
320 if (hdev->sdw)
321 sdw_intel_exit(hdev->sdw);
322 hdev->sdw = NULL;
323
324 return 0;
325}
Bard Liao722ba5f2020-03-25 16:50:23 -0500326
Bard Liao198fa4b2021-07-23 19:54:50 +0800327bool hda_common_check_sdw_irq(struct snd_sof_dev *sdev)
Bard Liao722ba5f2020-03-25 16:50:23 -0500328{
329 struct sof_intel_hda_dev *hdev;
330 bool ret = false;
331 u32 irq_status;
332
333 hdev = sdev->pdata->hw_pdata;
334
335 if (!hdev->sdw)
336 return ret;
337
338 /* store status */
339 irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS2);
340
341 /* invalid message ? */
342 if (irq_status == 0xffffffff)
343 goto out;
344
345 /* SDW message ? */
346 if (irq_status & HDA_DSP_REG_ADSPIS2_SNDW)
347 ret = true;
348
349out:
350 return ret;
351}
352
Bard Liao198fa4b2021-07-23 19:54:50 +0800353static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
354{
355 const struct sof_intel_dsp_desc *chip;
356
357 chip = get_chip_info(sdev->pdata);
358 if (chip && chip->check_sdw_irq)
359 return chip->check_sdw_irq(sdev);
360
361 return false;
362}
363
Bard Liao722ba5f2020-03-25 16:50:23 -0500364static irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
365{
366 return sdw_intel_thread(irq, context);
367}
368
Rander Wang90de3282020-03-25 16:50:26 -0500369static bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
370{
371 struct sof_intel_hda_dev *hdev;
372
373 hdev = sdev->pdata->hw_pdata;
374 if (hdev->sdw &&
375 snd_sof_dsp_read(sdev, HDA_DSP_BAR,
Bard Liao781dd3c82021-07-23 19:54:48 +0800376 hdev->desc->sdw_shim_base + SDW_SHIM_WAKESTS))
Rander Wang90de3282020-03-25 16:50:26 -0500377 return true;
378
379 return false;
380}
381
Rander Wangbbd19cd2020-03-25 16:50:25 -0500382void hda_sdw_process_wakeen(struct snd_sof_dev *sdev)
383{
384 struct sof_intel_hda_dev *hdev;
385
386 hdev = sdev->pdata->hw_pdata;
387 if (!hdev->sdw)
388 return;
389
390 sdw_intel_process_wakeen_event(hdev->sdw);
391}
392
Peter Ujfalusi3e9d5b02021-09-15 10:18:05 +0300393#else /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */
394static inline int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
395{
396 return 0;
397}
398
399static inline int hda_sdw_probe(struct snd_sof_dev *sdev)
400{
401 return 0;
402}
403
404static inline int hda_sdw_exit(struct snd_sof_dev *sdev)
405{
406 return 0;
407}
408
409static inline bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
410{
411 return false;
412}
413
414static inline irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
415{
416 return IRQ_HANDLED;
417}
418
419static inline bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
420{
421 return false;
422}
423
424#endif /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500425
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500426/*
427 * Debug
428 */
429
430struct hda_dsp_msg_code {
431 u32 code;
432 const char *msg;
433};
434
Guennadi Liakhovetski672ff5e2019-07-22 09:13:57 -0500435#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG)
Peter Ujfalusi9d5536e2021-05-21 12:28:04 +0300436static bool hda_use_msi = true;
Guennadi Liakhovetski672ff5e2019-07-22 09:13:57 -0500437module_param_named(use_msi, hda_use_msi, bool, 0444);
438MODULE_PARM_DESC(use_msi, "SOF HDA use PCI MSI mode");
Peter Ujfalusi9d5536e2021-05-21 12:28:04 +0300439#else
440#define hda_use_msi (1)
Guennadi Liakhovetski672ff5e2019-07-22 09:13:57 -0500441#endif
442
Jaroslav Kyselab8d3ad52020-04-24 11:25:20 +0200443static char *hda_model;
444module_param(hda_model, charp, 0444);
445MODULE_PARM_DESC(hda_model, "Use the given HDA board model.");
446
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -0600447#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
Pierre-Louis Bossart68b953a2019-08-12 11:06:23 -0500448static int hda_dmic_num = -1;
449module_param_named(dmic_num, hda_dmic_num, int, 0444);
450MODULE_PARM_DESC(dmic_num, "SOF HDA DMIC number");
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -0600451#endif
Kai Vehmanen139c7fe2019-10-29 15:40:13 +0200452
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -0600453#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
Kai Vehmanen42c67752020-03-12 14:48:53 -0500454static bool hda_codec_use_common_hdmi = IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI);
Kai Vehmanen139c7fe2019-10-29 15:40:13 +0200455module_param_named(use_common_hdmi, hda_codec_use_common_hdmi, bool, 0444);
456MODULE_PARM_DESC(use_common_hdmi, "SOF HDA use common HDMI codec driver");
Pierre-Louis Bossart68b953a2019-08-12 11:06:23 -0500457#endif
458
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500459static const struct hda_dsp_msg_code hda_dsp_rom_msg[] = {
460 {HDA_DSP_ROM_FW_MANIFEST_LOADED, "status: manifest loaded"},
461 {HDA_DSP_ROM_FW_FW_LOADED, "status: fw loaded"},
462 {HDA_DSP_ROM_FW_ENTERED, "status: fw entered"},
463 {HDA_DSP_ROM_CSE_ERROR, "error: cse error"},
464 {HDA_DSP_ROM_CSE_WRONG_RESPONSE, "error: cse wrong response"},
465 {HDA_DSP_ROM_IMR_TO_SMALL, "error: IMR too small"},
466 {HDA_DSP_ROM_BASE_FW_NOT_FOUND, "error: base fw not found"},
467 {HDA_DSP_ROM_CSE_VALIDATION_FAILED, "error: signature verification failed"},
468 {HDA_DSP_ROM_IPC_FATAL_ERROR, "error: ipc fatal error"},
469 {HDA_DSP_ROM_L2_CACHE_ERROR, "error: L2 cache error"},
470 {HDA_DSP_ROM_LOAD_OFFSET_TO_SMALL, "error: load offset too small"},
471 {HDA_DSP_ROM_API_PTR_INVALID, "error: API ptr invalid"},
Colin Ian King07f80452019-05-01 11:23:08 +0100472 {HDA_DSP_ROM_BASEFW_INCOMPAT, "error: base fw incompatible"},
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500473 {HDA_DSP_ROM_UNHANDLED_INTERRUPT, "error: unhandled interrupt"},
474 {HDA_DSP_ROM_MEMORY_HOLE_ECC, "error: ECC memory hole"},
475 {HDA_DSP_ROM_KERNEL_EXCEPTION, "error: kernel exception"},
476 {HDA_DSP_ROM_USER_EXCEPTION, "error: user exception"},
477 {HDA_DSP_ROM_UNEXPECTED_RESET, "error: unexpected reset"},
478 {HDA_DSP_ROM_NULL_FW_ENTRY, "error: null FW entry point"},
479};
480
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500481static void hda_dsp_get_status(struct snd_sof_dev *sdev)
482{
483 u32 status;
484 int i;
485
486 status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
487 HDA_DSP_SRAM_REG_ROM_STATUS);
488
489 for (i = 0; i < ARRAY_SIZE(hda_dsp_rom_msg); i++) {
490 if (status == hda_dsp_rom_msg[i].code) {
491 dev_err(sdev->dev, "%s - code %8.8x\n",
492 hda_dsp_rom_msg[i].msg, status);
493 return;
494 }
495 }
496
497 /* not for us, must be generic sof message */
498 dev_dbg(sdev->dev, "unknown ROM status value %8.8x\n", status);
499}
500
501static void hda_dsp_get_registers(struct snd_sof_dev *sdev,
502 struct sof_ipc_dsp_oops_xtensa *xoops,
503 struct sof_ipc_panic_info *panic_info,
504 u32 *stack, size_t stack_words)
505{
Kai Vehmanen14104eb2019-06-03 11:18:15 -0500506 u32 offset = sdev->dsp_oops_offset;
507
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500508 /* first read registers */
Kai Vehmanen14104eb2019-06-03 11:18:15 -0500509 sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
510
511 /* note: variable AR register array is not read */
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500512
513 /* then get panic info */
Liam Girdwoodff2be862019-09-27 15:05:36 -0500514 if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
515 dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
516 xoops->arch_hdr.totalsize);
517 return;
518 }
Kai Vehmanen14104eb2019-06-03 11:18:15 -0500519 offset += xoops->arch_hdr.totalsize;
520 sof_block_read(sdev, sdev->mmio_bar, offset,
521 panic_info, sizeof(*panic_info));
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500522
523 /* then get the stack */
Kai Vehmanen14104eb2019-06-03 11:18:15 -0500524 offset += sizeof(*panic_info);
525 sof_block_read(sdev, sdev->mmio_bar, offset, stack,
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500526 stack_words * sizeof(u32));
527}
528
Ranjani Sridharan29c8e432020-08-25 16:50:38 -0700529/* dump the first 8 dwords representing the extended ROM status */
Ranjani Sridharan8f7ef6f2020-12-11 12:07:43 +0200530static void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, u32 flags)
Ranjani Sridharan29c8e432020-08-25 16:50:38 -0700531{
532 char msg[128];
533 int len = 0;
534 u32 value;
535 int i;
536
537 for (i = 0; i < HDA_EXT_ROM_STATUS_SIZE; i++) {
538 value = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_ROM_STATUS + i * 0x4);
539 len += snprintf(msg + len, sizeof(msg) - len, " 0x%x", value);
540 }
541
Peter Ujfalusi4fade252021-10-06 14:06:41 +0300542 dev_err(sdev->dev, "extended rom status: %s", msg);
Pierre-Louis Bossart776100a2020-09-17 13:56:33 +0300543
Ranjani Sridharan29c8e432020-08-25 16:50:38 -0700544}
545
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500546void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags)
547{
548 struct sof_ipc_dsp_oops_xtensa xoops;
549 struct sof_ipc_panic_info panic_info;
550 u32 stack[HDA_DSP_STACK_DUMP_SIZE];
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500551
Ranjani Sridharan7ff562f2021-05-28 19:05:50 +0300552 /* print ROM/FW status */
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500553 hda_dsp_get_status(sdev);
554
Peter Ujfalusi3ad7b8f2021-10-06 14:06:45 +0300555 if (flags & SOF_DBG_DUMP_REGS) {
Ranjani Sridharan7ff562f2021-05-28 19:05:50 +0300556 u32 status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_STATUS);
557 u32 panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_TRACEP);
558
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500559 hda_dsp_get_registers(sdev, &xoops, &panic_info, stack,
560 HDA_DSP_STACK_DUMP_SIZE);
561 snd_sof_get_status(sdev, status, panic, &xoops, &panic_info,
562 stack, HDA_DSP_STACK_DUMP_SIZE);
563 } else {
Ranjani Sridharan8f7ef6f2020-12-11 12:07:43 +0200564 hda_dsp_dump_ext_rom_status(sdev, flags);
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500565 }
566}
567
Kai Vehmanenf1fd9d02019-06-12 11:57:03 -0500568void hda_ipc_irq_dump(struct snd_sof_dev *sdev)
569{
570 struct hdac_bus *bus = sof_to_bus(sdev);
571 u32 adspis;
572 u32 intsts;
573 u32 intctl;
574 u32 ppsts;
575 u8 rirbsts;
576
577 /* read key IRQ stats and config registers */
578 adspis = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS);
579 intsts = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
580 intctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL);
581 ppsts = snd_sof_dsp_read(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPSTS);
582 rirbsts = snd_hdac_chip_readb(bus, RIRBSTS);
583
Peter Ujfalusi4fade252021-10-06 14:06:41 +0300584 dev_err(sdev->dev, "hda irq intsts 0x%8.8x intlctl 0x%8.8x rirb %2.2x\n",
Kai Vehmanenf1fd9d02019-06-12 11:57:03 -0500585 intsts, intctl, rirbsts);
Peter Ujfalusi4fade252021-10-06 14:06:41 +0300586 dev_err(sdev->dev, "dsp irq ppsts 0x%8.8x adspis 0x%8.8x\n", ppsts, adspis);
Kai Vehmanenf1fd9d02019-06-12 11:57:03 -0500587}
588
Pan Xiulif3da49f2019-04-30 18:09:33 -0500589void hda_ipc_dump(struct snd_sof_dev *sdev)
590{
591 u32 hipcie;
592 u32 hipct;
593 u32 hipcctl;
594
Kai Vehmanenf1fd9d02019-06-12 11:57:03 -0500595 hda_ipc_irq_dump(sdev);
596
Pan Xiulif3da49f2019-04-30 18:09:33 -0500597 /* read IPC status */
598 hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
599 hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
600 hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL);
601
602 /* dump the IPC regs */
603 /* TODO: parse the raw msg */
Peter Ujfalusi4fade252021-10-06 14:06:41 +0300604 dev_err(sdev->dev, "host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n",
Pan Xiulif3da49f2019-04-30 18:09:33 -0500605 hipcie, hipct, hipcctl);
606}
607
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500608static int hda_init(struct snd_sof_dev *sdev)
609{
610 struct hda_bus *hbus;
611 struct hdac_bus *bus;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500612 struct pci_dev *pci = to_pci_dev(sdev->dev);
613 int ret;
614
615 hbus = sof_to_hbus(sdev);
616 bus = sof_to_bus(sdev);
617
618 /* HDA bus init */
Takashi Iwaid4ff1b32019-08-07 20:50:50 +0200619 sof_hda_bus_init(bus, &pci->dev);
Bard Liao64ca9d92019-05-27 00:58:36 +0800620
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500621 bus->use_posbuf = 1;
622 bus->bdl_pos_adj = 0;
Kai Vehmanenf3416e72019-10-08 11:44:35 -0500623 bus->sync_write = 1;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500624
625 mutex_init(&hbus->prepare_mutex);
626 hbus->pci = pci;
627 hbus->mixer_assigned = -1;
Jaroslav Kyselab8d3ad52020-04-24 11:25:20 +0200628 hbus->modelname = hda_model;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500629
630 /* initialise hdac bus */
631 bus->addr = pci_resource_start(pci, 0);
632 bus->remap_addr = pci_ioremap_bar(pci, 0);
633 if (!bus->remap_addr) {
634 dev_err(bus->dev, "error: ioremap error\n");
635 return -ENXIO;
636 }
637
638 /* HDA base */
639 sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
640
Kai Vehmanenaf7aae12020-02-06 22:02:23 +0200641 /* init i915 and HDMI codecs */
642 ret = hda_codec_i915_init(sdev);
Kai Vehmanen71cc8ab2020-02-20 19:10:28 +0200643 if (ret < 0)
644 dev_warn(sdev->dev, "init of i915 and HDMI codec failed\n");
Kai Vehmanenaf7aae12020-02-06 22:02:23 +0200645
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500646 /* get controller capabilities */
647 ret = hda_dsp_ctrl_get_caps(sdev);
648 if (ret < 0)
649 dev_err(sdev->dev, "error: get caps error\n");
650
651 return ret;
652}
653
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -0600654#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500655
Pierre-Louis Bossart68b953a2019-08-12 11:06:23 -0500656static int check_nhlt_dmic(struct snd_sof_dev *sdev)
657{
658 struct nhlt_acpi_table *nhlt;
659 int dmic_num;
660
661 nhlt = intel_nhlt_init(sdev->dev);
662 if (nhlt) {
663 dmic_num = intel_nhlt_get_dmic_geo(sdev->dev, nhlt);
664 intel_nhlt_free(nhlt);
Jaska Uimonen3dca35e2020-08-25 16:50:36 -0700665 if (dmic_num >= 1 && dmic_num <= 4)
Pierre-Louis Bossart68b953a2019-08-12 11:06:23 -0500666 return dmic_num;
667 }
668
669 return 0;
670}
671
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500672static const char *fixup_tplg_name(struct snd_sof_dev *sdev,
Pierre-Louis Bossart68b953a2019-08-12 11:06:23 -0500673 const char *sof_tplg_filename,
674 const char *idisp_str,
675 const char *dmic_str)
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500676{
677 const char *tplg_filename = NULL;
Guennadi Liakhovetskib9088532021-02-08 17:33:35 -0600678 char *filename, *tmp;
679 const char *split_ext;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500680
Guennadi Liakhovetskib9088532021-02-08 17:33:35 -0600681 filename = kstrdup(sof_tplg_filename, GFP_KERNEL);
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500682 if (!filename)
683 return NULL;
684
685 /* this assumes a .tplg extension */
Guennadi Liakhovetskib9088532021-02-08 17:33:35 -0600686 tmp = filename;
687 split_ext = strsep(&tmp, ".");
688 if (split_ext)
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500689 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
Pierre-Louis Bossart68b953a2019-08-12 11:06:23 -0500690 "%s%s%s.tplg",
691 split_ext, idisp_str, dmic_str);
Guennadi Liakhovetskib9088532021-02-08 17:33:35 -0600692 kfree(filename);
693
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500694 return tplg_filename;
695}
696
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -0600697static int dmic_topology_fixup(struct snd_sof_dev *sdev,
698 const char **tplg_filename,
699 const char *idisp_str,
700 int *dmic_found)
701{
702 const char *default_tplg_filename = *tplg_filename;
703 const char *fixed_tplg_filename;
704 const char *dmic_str;
705 int dmic_num;
706
707 /* first check NHLT for DMICs */
708 dmic_num = check_nhlt_dmic(sdev);
709
710 /* allow for module parameter override */
Pierre-Louis Bossart026370c2021-02-08 17:33:36 -0600711 if (hda_dmic_num != -1) {
712 dev_dbg(sdev->dev,
713 "overriding DMICs detected in NHLT tables %d by kernel param %d\n",
714 dmic_num, hda_dmic_num);
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -0600715 dmic_num = hda_dmic_num;
Pierre-Louis Bossart026370c2021-02-08 17:33:36 -0600716 }
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -0600717
718 switch (dmic_num) {
719 case 1:
720 dmic_str = "-1ch";
721 break;
722 case 2:
723 dmic_str = "-2ch";
724 break;
725 case 3:
726 dmic_str = "-3ch";
727 break;
728 case 4:
729 dmic_str = "-4ch";
730 break;
731 default:
732 dmic_num = 0;
733 dmic_str = "";
734 break;
735 }
736
737 fixed_tplg_filename = fixup_tplg_name(sdev, default_tplg_filename,
738 idisp_str, dmic_str);
739 if (!fixed_tplg_filename)
740 return -ENOMEM;
741
742 dev_info(sdev->dev, "DMICs detected in NHLT tables: %d\n", dmic_num);
743 *dmic_found = dmic_num;
744 *tplg_filename = fixed_tplg_filename;
745
746 return 0;
747}
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500748#endif
749
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500750static int hda_init_caps(struct snd_sof_dev *sdev)
751{
752 struct hdac_bus *bus = sof_to_bus(sdev);
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500753 struct snd_sof_pdata *pdata = sdev->pdata;
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500754#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500755 struct hdac_ext_link *hlink;
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500756#endif
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500757 struct sof_intel_hda_dev *hdev = pdata->hw_pdata;
758 u32 link_mask;
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500759 int ret = 0;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500760
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500761 /* check if dsp is there */
762 if (bus->ppcap)
763 dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n");
764
Ranjani Sridharancc352732019-08-06 15:19:58 -0700765 /* Init HDA controller after i915 init */
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500766 ret = hda_dsp_ctrl_init_chip(sdev, true);
767 if (ret < 0) {
768 dev_err(bus->dev, "error: init chip failed with ret: %d\n",
769 ret);
770 return ret;
771 }
772
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500773 /* scan SoundWire capabilities exposed by DSDT */
774 ret = hda_sdw_acpi_scan(sdev);
775 if (ret < 0) {
Pierre-Louis Bossart0d4453e2020-04-09 13:44:14 -0500776 dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n");
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -0500777 goto skip_soundwire;
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500778 }
779
780 link_mask = hdev->info.link_mask;
781 if (!link_mask) {
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -0500782 dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n");
783 goto skip_soundwire;
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -0500784 }
785
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -0500786 /*
787 * probe/allocate SoundWire resources.
788 * The hardware configuration takes place in hda_sdw_startup
789 * after power rails are enabled.
790 * It's entirely possible to have a mix of I2S/DMIC/SoundWire
791 * devices, so we allocate the resources in all cases.
792 */
793 ret = hda_sdw_probe(sdev);
794 if (ret < 0) {
795 dev_err(sdev->dev, "error: SoundWire probe error\n");
796 return ret;
797 }
798
799skip_soundwire:
800
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500801#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500802 if (bus->mlcap)
803 snd_hdac_ext_bus_get_ml_capabilities(bus);
804
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500805 /* create codec instances */
Ranjani Sridharan80acdd42019-12-04 15:15:52 -0600806 hda_codec_probe_bus(sdev, hda_codec_use_common_hdmi);
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500807
Kai Vehmanen0c754192020-01-20 18:01:16 +0200808 if (!HDA_IDISP_CODEC(bus->codec_mask))
Kai Vehmanen71cc8ab2020-02-20 19:10:28 +0200809 hda_codec_i915_display_power(sdev, false);
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500810
811 /*
812 * we are done probing so decrement link counts
813 */
814 list_for_each_entry(hlink, &bus->hlink_list, list)
815 snd_hdac_ext_bus_link_put(bus, hlink);
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500816#endif
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500817 return 0;
818}
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500819
Kai Vehmanenfd572392021-11-05 13:16:55 +0200820static void hda_check_for_state_change(struct snd_sof_dev *sdev)
821{
822#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
823 struct hdac_bus *bus = sof_to_bus(sdev);
824 unsigned int codec_mask;
825
826 codec_mask = snd_hdac_chip_readw(bus, STATESTS);
827 if (codec_mask) {
828 hda_codec_jack_check(sdev);
829 snd_hdac_chip_writew(bus, STATESTS, codec_mask);
830 }
831#endif
832}
833
Bard Liao7c11af92019-12-04 15:28:59 -0600834static irqreturn_t hda_dsp_interrupt_handler(int irq, void *context)
835{
836 struct snd_sof_dev *sdev = context;
837
838 /*
839 * Get global interrupt status. It includes all hardware interrupt
840 * sources in the Intel HD Audio controller.
841 */
842 if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) &
843 SOF_HDA_INTSTS_GIS) {
844
845 /* disable GIE interrupt */
846 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
847 SOF_HDA_INTCTL,
848 SOF_HDA_INT_GLOBAL_EN,
849 0);
850
851 return IRQ_WAKE_THREAD;
852 }
853
854 return IRQ_NONE;
855}
856
857static irqreturn_t hda_dsp_interrupt_thread(int irq, void *context)
858{
859 struct snd_sof_dev *sdev = context;
Bard Liao722ba5f2020-03-25 16:50:23 -0500860 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
Bard Liao7c11af92019-12-04 15:28:59 -0600861
862 /* deal with streams and controller first */
863 if (hda_dsp_check_stream_irq(sdev))
864 hda_dsp_stream_threaded_handler(irq, sdev);
865
866 if (hda_dsp_check_ipc_irq(sdev))
867 sof_ops(sdev)->irq_thread(irq, sdev);
868
Bard Liao722ba5f2020-03-25 16:50:23 -0500869 if (hda_dsp_check_sdw_irq(sdev))
870 hda_dsp_sdw_thread(irq, hdev->sdw);
871
Rander Wang90de3282020-03-25 16:50:26 -0500872 if (hda_sdw_check_wakeen_irq(sdev))
873 hda_sdw_process_wakeen(sdev);
874
Kai Vehmanenfd572392021-11-05 13:16:55 +0200875 hda_check_for_state_change(sdev);
876
Bard Liao7c11af92019-12-04 15:28:59 -0600877 /* enable GIE interrupt */
878 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
879 SOF_HDA_INTCTL,
880 SOF_HDA_INT_GLOBAL_EN,
881 SOF_HDA_INT_GLOBAL_EN);
882
883 return IRQ_HANDLED;
884}
885
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500886int hda_dsp_probe(struct snd_sof_dev *sdev)
887{
888 struct pci_dev *pci = to_pci_dev(sdev->dev);
889 struct sof_intel_hda_dev *hdev;
890 struct hdac_bus *bus;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500891 const struct sof_intel_dsp_desc *chip;
Zhu Yingjiangbe1b5772019-05-24 14:09:24 -0500892 int ret = 0;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500893
894 /*
895 * detect DSP by checking class/subclass/prog-id information
896 * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required
897 * class=04 subclass 01 prog-if 00: DSP is present
898 * (and may be required e.g. for DMIC or SSP support)
899 * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works
900 */
901 if (pci->class == 0x040300) {
902 dev_err(sdev->dev, "error: the DSP is not enabled on this platform, aborting probe\n");
903 return -ENODEV;
904 } else if (pci->class != 0x040100 && pci->class != 0x040380) {
905 dev_err(sdev->dev, "error: unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", pci->class);
906 return -ENODEV;
907 }
908 dev_info(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", pci->class);
909
910 chip = get_chip_info(sdev->pdata);
911 if (!chip) {
912 dev_err(sdev->dev, "error: no such device supported, chip id:%x\n",
913 pci->device);
914 ret = -EIO;
915 goto err;
916 }
917
918 hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
919 if (!hdev)
920 return -ENOMEM;
921 sdev->pdata->hw_pdata = hdev;
922 hdev->desc = chip;
923
924 hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
925 PLATFORM_DEVID_NONE,
926 NULL, 0);
927 if (IS_ERR(hdev->dmic_dev)) {
928 dev_err(sdev->dev, "error: failed to create DMIC device\n");
929 return PTR_ERR(hdev->dmic_dev);
930 }
931
932 /*
933 * use position update IPC if either it is forced
934 * or we don't have other choice
935 */
936#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION)
937 hdev->no_ipc_position = 0;
938#else
939 hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0;
940#endif
941
942 /* set up HDA base */
943 bus = sof_to_bus(sdev);
944 ret = hda_init(sdev);
945 if (ret < 0)
946 goto hdac_bus_unmap;
947
948 /* DSP base */
949 sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR);
950 if (!sdev->bar[HDA_DSP_BAR]) {
951 dev_err(sdev->dev, "error: ioremap error\n");
952 ret = -ENXIO;
953 goto hdac_bus_unmap;
954 }
955
956 sdev->mmio_bar = HDA_DSP_BAR;
957 sdev->mailbox_bar = HDA_DSP_BAR;
958
959 /* allow 64bit DMA address if supported by H/W */
Takashi Iwaiab152af2021-01-14 14:33:36 +0100960 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) {
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500961 dev_dbg(sdev->dev, "DMA mask is 32 bit\n");
Takashi Iwaiab152af2021-01-14 14:33:36 +0100962 dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32));
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500963 }
964
965 /* init streams */
966 ret = hda_dsp_stream_init(sdev);
967 if (ret < 0) {
968 dev_err(sdev->dev, "error: failed to init streams\n");
969 /*
970 * not all errors are due to memory issues, but trying
971 * to free everything does not harm
972 */
973 goto free_streams;
974 }
975
976 /*
977 * register our IRQ
978 * let's try to enable msi firstly
979 * if it fails, use legacy interrupt mode
Guennadi Liakhovetski672ff5e2019-07-22 09:13:57 -0500980 * TODO: support msi multiple vectors
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500981 */
Pierre-Louis Bossartbb67dd12019-08-06 12:06:03 -0500982 if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) {
Guennadi Liakhovetski672ff5e2019-07-22 09:13:57 -0500983 dev_info(sdev->dev, "use msi interrupt mode\n");
Bard Liao7c11af92019-12-04 15:28:59 -0600984 sdev->ipc_irq = pci_irq_vector(pci, 0);
Guennadi Liakhovetski672ff5e2019-07-22 09:13:57 -0500985 /* initialised to "false" by kzalloc() */
986 sdev->msi_enabled = true;
987 }
988
989 if (!sdev->msi_enabled) {
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500990 dev_info(sdev->dev, "use legacy interrupt mode\n");
991 /*
992 * in IO-APIC mode, hda->irq and ipc_irq are using the same
993 * irq number of pci->irq
994 */
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500995 sdev->ipc_irq = pci->irq;
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500996 }
997
Liam Girdwooddd96dac2019-04-12 11:08:47 -0500998 dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq);
Bard Liao7c11af92019-12-04 15:28:59 -0600999 ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler,
1000 hda_dsp_interrupt_thread,
1001 IRQF_SHARED, "AudioDSP", sdev);
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001002 if (ret < 0) {
1003 dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n",
1004 sdev->ipc_irq);
Bard Liao7c11af92019-12-04 15:28:59 -06001005 goto free_irq_vector;
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001006 }
1007
1008 pci_set_master(pci);
1009 synchronize_irq(pci->irq);
1010
1011 /*
1012 * clear TCSEL to clear playback on some HD Audio
1013 * codecs. PCI TCSEL is defined in the Intel manuals.
1014 */
1015 snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
1016
1017 /* init HDA capabilities */
1018 ret = hda_init_caps(sdev);
1019 if (ret < 0)
1020 goto free_ipc_irq;
1021
Zhu Yingjiang1f5253b2019-05-22 11:21:40 -05001022 /* enable ppcap interrupt */
1023 hda_dsp_ctrl_ppcap_enable(sdev, true);
1024 hda_dsp_ctrl_ppcap_int_enable(sdev, true);
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001025
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001026 /* set default mailbox offset for FW ready message */
1027 sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET;
1028
Ranjani Sridharan63e51fd32020-01-29 16:07:25 -06001029 INIT_DELAYED_WORK(&hdev->d0i3_work, hda_dsp_d0i3_work);
1030
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001031 return 0;
1032
1033free_ipc_irq:
1034 free_irq(sdev->ipc_irq, sdev);
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001035free_irq_vector:
1036 if (sdev->msi_enabled)
1037 pci_free_irq_vectors(pci);
1038free_streams:
1039 hda_dsp_stream_free(sdev);
1040/* dsp_unmap: not currently used */
1041 iounmap(sdev->bar[HDA_DSP_BAR]);
1042hdac_bus_unmap:
Pierre-Louis Bossart5bb0ecd2021-03-01 18:34:10 -06001043 platform_device_unregister(hdev->dmic_dev);
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001044 iounmap(bus->remap_addr);
Kai Vehmanenaf7aae12020-02-06 22:02:23 +02001045 hda_codec_i915_exit(sdev);
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001046err:
1047 return ret;
1048}
1049
1050int hda_dsp_remove(struct snd_sof_dev *sdev)
1051{
1052 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
1053 struct hdac_bus *bus = sof_to_bus(sdev);
1054 struct pci_dev *pci = to_pci_dev(sdev->dev);
1055 const struct sof_intel_dsp_desc *chip = hda->desc;
1056
Ranjani Sridharan63e51fd32020-01-29 16:07:25 -06001057 /* cancel any attempt for DSP D0I3 */
1058 cancel_delayed_work_sync(&hda->d0i3_work);
1059
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001060#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1061 /* codec removal, invoke bus_device_remove */
1062 snd_hdac_ext_bus_device_remove(bus);
1063#endif
1064
Pierre-Louis Bossart51dfed12020-03-25 16:50:18 -05001065 hda_sdw_exit(sdev);
1066
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001067 if (!IS_ERR_OR_NULL(hda->dmic_dev))
1068 platform_device_unregister(hda->dmic_dev);
1069
1070 /* disable DSP IRQ */
1071 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1072 SOF_HDA_PPCTL_PIE, 0);
1073
1074 /* disable CIE and GIE interrupts */
1075 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
1076 SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0);
1077
1078 /* disable cores */
1079 if (chip)
Bard Liaof6c246e2021-01-28 11:38:46 +02001080 snd_sof_dsp_core_power_down(sdev, chip->host_managed_cores_mask);
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001081
1082 /* disable DSP */
1083 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1084 SOF_HDA_PPCTL_GPROCEN, 0);
1085
1086 free_irq(sdev->ipc_irq, sdev);
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001087 if (sdev->msi_enabled)
1088 pci_free_irq_vectors(pci);
1089
1090 hda_dsp_stream_free(sdev);
1091#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1092 snd_hdac_link_free_all(bus);
1093#endif
1094
1095 iounmap(sdev->bar[HDA_DSP_BAR]);
1096 iounmap(bus->remap_addr);
1097
1098#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1099 snd_hdac_ext_bus_exit(bus);
1100#endif
1101 hda_codec_i915_exit(sdev);
1102
1103 return 0;
1104}
1105
Daniel Baluta285880a2019-12-04 15:15:53 -06001106#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1107static int hda_generic_machine_select(struct snd_sof_dev *sdev)
1108{
1109 struct hdac_bus *bus = sof_to_bus(sdev);
1110 struct snd_soc_acpi_mach_params *mach_params;
1111 struct snd_soc_acpi_mach *hda_mach;
1112 struct snd_sof_pdata *pdata = sdev->pdata;
1113 const char *tplg_filename;
1114 const char *idisp_str;
Daniel Baluta285880a2019-12-04 15:15:53 -06001115 int dmic_num = 0;
1116 int codec_num = 0;
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -06001117 int ret;
Daniel Baluta285880a2019-12-04 15:15:53 -06001118 int i;
1119
1120 /* codec detection */
1121 if (!bus->codec_mask) {
1122 dev_info(bus->dev, "no hda codecs found!\n");
1123 } else {
1124 dev_info(bus->dev, "hda codecs found, mask %lx\n",
1125 bus->codec_mask);
1126
1127 for (i = 0; i < HDA_MAX_CODECS; i++) {
1128 if (bus->codec_mask & (1 << i))
1129 codec_num++;
1130 }
1131
1132 /*
1133 * If no machine driver is found, then:
1134 *
Kai Vehmanen71cc8ab2020-02-20 19:10:28 +02001135 * generic hda machine driver can handle:
1136 * - one HDMI codec, and/or
1137 * - one external HDAudio codec
Daniel Baluta285880a2019-12-04 15:15:53 -06001138 */
Kai Vehmanen71cc8ab2020-02-20 19:10:28 +02001139 if (!pdata->machine && codec_num <= 2) {
Daniel Baluta285880a2019-12-04 15:15:53 -06001140 hda_mach = snd_soc_acpi_intel_hda_machines;
1141
Daniel Baluta285880a2019-12-04 15:15:53 -06001142 dev_info(bus->dev, "using HDA machine driver %s now\n",
1143 hda_mach->drv_name);
1144
Kai Vehmanen71cc8ab2020-02-20 19:10:28 +02001145 if (codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask))
Daniel Baluta285880a2019-12-04 15:15:53 -06001146 idisp_str = "-idisp";
1147 else
1148 idisp_str = "";
1149
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -06001150 /* topology: use the info from hda_machines */
1151 tplg_filename = hda_mach->sof_tplg_filename;
1152 ret = dmic_topology_fixup(sdev, &tplg_filename, idisp_str, &dmic_num);
1153 if (ret < 0)
1154 return ret;
Daniel Baluta285880a2019-12-04 15:15:53 -06001155
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -06001156 hda_mach->mach_params.dmic_num = dmic_num;
Daniel Baluta285880a2019-12-04 15:15:53 -06001157 pdata->machine = hda_mach;
1158 pdata->tplg_filename = tplg_filename;
Pierre-Louis Bossart61bef9e2021-07-26 13:28:55 -05001159
1160 if (codec_num == 2) {
1161 /*
1162 * Prevent SoundWire links from starting when an external
1163 * HDaudio codec is used
1164 */
1165 hda_mach->mach_params.link_mask = 0;
1166 }
Daniel Baluta285880a2019-12-04 15:15:53 -06001167 }
1168 }
1169
1170 /* used by hda machine driver to create dai links */
1171 if (pdata->machine) {
1172 mach_params = (struct snd_soc_acpi_mach_params *)
1173 &pdata->machine->mach_params;
1174 mach_params->codec_mask = bus->codec_mask;
1175 mach_params->common_hdmi_codec_drv = hda_codec_use_common_hdmi;
Daniel Baluta285880a2019-12-04 15:15:53 -06001176 }
1177
1178 return 0;
1179}
1180#else
1181static int hda_generic_machine_select(struct snd_sof_dev *sdev)
1182{
1183 return 0;
1184}
1185#endif
1186
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001187#if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
1188/* Check if all Slaves defined on the link can be found */
1189static bool link_slaves_found(struct snd_sof_dev *sdev,
1190 const struct snd_soc_acpi_link_adr *link,
1191 struct sdw_intel_ctx *sdw)
1192{
1193 struct hdac_bus *bus = sof_to_bus(sdev);
1194 struct sdw_intel_slave_id *ids = sdw->ids;
1195 int num_slaves = sdw->num_slaves;
1196 unsigned int part_id, link_id, unique_id, mfg_id;
Pierre-Louis Bossart6f5d5062021-02-08 17:33:33 -06001197 int i, j, k;
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001198
1199 for (i = 0; i < link->num_adr; i++) {
1200 u64 adr = link->adr_d[i].adr;
Pierre-Louis Bossart6f5d5062021-02-08 17:33:33 -06001201 int reported_part_count = 0;
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001202
1203 mfg_id = SDW_MFG_ID(adr);
1204 part_id = SDW_PART_ID(adr);
1205 link_id = SDW_DISCO_LINK_ID(adr);
Pierre-Louis Bossart6f5d5062021-02-08 17:33:33 -06001206
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001207 for (j = 0; j < num_slaves; j++) {
Pierre-Louis Bossart6f5d5062021-02-08 17:33:33 -06001208 /* find out how many identical parts were reported on that link */
1209 if (ids[j].link_id == link_id &&
1210 ids[j].id.part_id == part_id &&
1211 ids[j].id.mfg_id == mfg_id)
1212 reported_part_count++;
1213 }
1214
1215 for (j = 0; j < num_slaves; j++) {
1216 int expected_part_count = 0;
1217
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001218 if (ids[j].link_id != link_id ||
1219 ids[j].id.part_id != part_id ||
1220 ids[j].id.mfg_id != mfg_id)
1221 continue;
Pierre-Louis Bossart6f5d5062021-02-08 17:33:33 -06001222
1223 /* find out how many identical parts are expected */
1224 for (k = 0; k < link->num_adr; k++) {
Pierre-Louis Bossartad839122021-05-11 16:36:59 -05001225 u64 adr2 = link->adr_d[k].adr;
Pierre-Louis Bossart6f5d5062021-02-08 17:33:33 -06001226 unsigned int part_id2, link_id2, mfg_id2;
1227
1228 mfg_id2 = SDW_MFG_ID(adr2);
1229 part_id2 = SDW_PART_ID(adr2);
1230 link_id2 = SDW_DISCO_LINK_ID(adr2);
1231
1232 if (link_id2 == link_id &&
1233 part_id2 == part_id &&
1234 mfg_id2 == mfg_id)
1235 expected_part_count++;
1236 }
1237
1238 if (reported_part_count == expected_part_count) {
1239 /*
1240 * we have to check unique id
1241 * if there is more than one
1242 * Slave on the link
1243 */
1244 unique_id = SDW_UNIQUE_ID(adr);
1245 if (reported_part_count == 1 ||
1246 ids[j].id.unique_id == unique_id) {
1247 dev_dbg(bus->dev, "found %x at link %d\n",
1248 part_id, link_id);
1249 break;
1250 }
1251 } else {
1252 dev_dbg(bus->dev, "part %x reported %d expected %d on link %d, skipping\n",
1253 part_id, reported_part_count, expected_part_count, link_id);
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001254 }
1255 }
1256 if (j == num_slaves) {
1257 dev_dbg(bus->dev,
1258 "Slave %x not found\n",
1259 part_id);
1260 return false;
1261 }
1262 }
1263 return true;
1264}
1265
1266static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1267{
1268 struct snd_sof_pdata *pdata = sdev->pdata;
1269 const struct snd_soc_acpi_link_adr *link;
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001270 struct snd_soc_acpi_mach *mach;
1271 struct sof_intel_hda_dev *hdev;
1272 u32 link_mask;
1273 int i;
1274
1275 hdev = pdata->hw_pdata;
1276 link_mask = hdev->info.link_mask;
1277
1278 /*
1279 * Select SoundWire machine driver if needed using the
1280 * alternate tables. This case deals with SoundWire-only
1281 * machines, for mixed cases with I2C/I2S the detection relies
1282 * on the HID list.
1283 */
1284 if (link_mask && !pdata->machine) {
1285 for (mach = pdata->desc->alt_machines;
1286 mach && mach->link_mask; mach++) {
randerwang7d1952b2020-05-15 16:59:55 +03001287 /*
1288 * On some platforms such as Up Extreme all links
1289 * are enabled but only one link can be used by
1290 * external codec. Instead of exact match of two masks,
1291 * first check whether link_mask of mach is subset of
1292 * link_mask supported by hw and then go on searching
1293 * link_adr
1294 */
1295 if (~link_mask & mach->link_mask)
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001296 continue;
1297
1298 /* No need to match adr if there is no links defined */
1299 if (!mach->links)
1300 break;
1301
1302 link = mach->links;
1303 for (i = 0; i < hdev->info.count && link->num_adr;
1304 i++, link++) {
1305 /*
1306 * Try next machine if any expected Slaves
1307 * are not found on this link.
1308 */
1309 if (!link_slaves_found(sdev, link, hdev->sdw))
1310 break;
1311 }
1312 /* Found if all Slaves are checked */
1313 if (i == hdev->info.count || !link->num_adr)
1314 break;
1315 }
1316 if (mach && mach->link_mask) {
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -06001317 int dmic_num = 0;
1318
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001319 pdata->machine = mach;
1320 mach->mach_params.links = mach->links;
1321 mach->mach_params.link_mask = mach->link_mask;
1322 mach->mach_params.platform = dev_name(sdev->dev);
Libin Yang7da99ef2021-01-25 09:04:58 +02001323 if (mach->sof_fw_filename)
1324 pdata->fw_filename = mach->sof_fw_filename;
1325 else
1326 pdata->fw_filename = pdata->desc->default_fw_filename;
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001327 pdata->tplg_filename = mach->sof_tplg_filename;
Pierre-Louis Bossart7aecf592021-02-08 17:33:34 -06001328
1329 /*
1330 * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1331 * link 2 and 3, thus we only try to enable dmics if all conditions
1332 * are true:
1333 * a) link 2 and 3 are not used by SoundWire
1334 * b) the NHLT table reports the presence of microphones
1335 */
1336 if (!(mach->link_mask & GENMASK(3, 2))) {
1337 const char *tplg_filename = mach->sof_tplg_filename;
1338 int ret;
1339
1340 ret = dmic_topology_fixup(sdev, &tplg_filename, "", &dmic_num);
1341
1342 if (ret < 0)
1343 return ret;
1344
1345 pdata->tplg_filename = tplg_filename;
1346 }
1347 mach->mach_params.dmic_num = dmic_num;
1348
1349 dev_dbg(sdev->dev,
1350 "SoundWire machine driver %s topology %s\n",
1351 mach->drv_name,
1352 pdata->tplg_filename);
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001353 } else {
1354 dev_info(sdev->dev,
1355 "No SoundWire machine driver found\n");
1356 }
1357 }
1358
1359 return 0;
1360}
1361#else
1362static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1363{
1364 return 0;
1365}
1366#endif
1367
Daniel Baluta285880a2019-12-04 15:15:53 -06001368void hda_set_mach_params(const struct snd_soc_acpi_mach *mach,
Pierre-Louis Bossart17e9d6b2021-04-09 15:01:18 -07001369 struct snd_sof_dev *sdev)
Daniel Baluta285880a2019-12-04 15:15:53 -06001370{
Pierre-Louis Bossart974cccf2021-04-09 15:01:19 -07001371 struct snd_sof_pdata *pdata = sdev->pdata;
1372 const struct sof_dev_desc *desc = pdata->desc;
Daniel Baluta285880a2019-12-04 15:15:53 -06001373 struct snd_soc_acpi_mach_params *mach_params;
1374
1375 mach_params = (struct snd_soc_acpi_mach_params *)&mach->mach_params;
Pierre-Louis Bossart17e9d6b2021-04-09 15:01:18 -07001376 mach_params->platform = dev_name(sdev->dev);
Pierre-Louis Bossart974cccf2021-04-09 15:01:19 -07001377 mach_params->num_dai_drivers = desc->ops->num_drv;
1378 mach_params->dai_drivers = desc->ops->drv;
Daniel Baluta285880a2019-12-04 15:15:53 -06001379}
1380
1381void hda_machine_select(struct snd_sof_dev *sdev)
1382{
1383 struct snd_sof_pdata *sof_pdata = sdev->pdata;
1384 const struct sof_dev_desc *desc = sof_pdata->desc;
1385 struct snd_soc_acpi_mach *mach;
1386
1387 mach = snd_soc_acpi_find_machine(desc->machines);
1388 if (mach) {
Sathyanarayana Nujella5253a732020-08-21 14:56:00 -05001389 /*
1390 * If tplg file name is overridden, use it instead of
1391 * the one set in mach table
1392 */
1393 if (!sof_pdata->tplg_filename)
1394 sof_pdata->tplg_filename = mach->sof_tplg_filename;
1395
Daniel Baluta285880a2019-12-04 15:15:53 -06001396 sof_pdata->machine = mach;
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001397
1398 if (mach->link_mask) {
1399 mach->mach_params.links = mach->links;
1400 mach->mach_params.link_mask = mach->link_mask;
1401 }
Daniel Baluta285880a2019-12-04 15:15:53 -06001402 }
1403
1404 /*
Pierre-Louis Bossartb9ddd812020-03-25 16:50:21 -05001405 * If I2S fails, try SoundWire
1406 */
1407 hda_sdw_machine_select(sdev);
1408
1409 /*
Daniel Baluta285880a2019-12-04 15:15:53 -06001410 * Choose HDA generic machine driver if mach is NULL.
1411 * Otherwise, set certain mach params.
1412 */
1413 hda_generic_machine_select(sdev);
1414
1415 if (!sof_pdata->machine)
1416 dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n");
1417}
1418
Pierre-Louis Bossart194fe0f2021-03-01 18:31:22 -06001419int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1420{
1421 int ret;
1422
1423 ret = snd_intel_dsp_driver_probe(pci);
1424 if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
1425 dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n");
1426 return -ENODEV;
1427 }
1428
1429 return sof_pci_probe(pci, pci_id);
1430}
1431EXPORT_SYMBOL_NS(hda_pci_intel_probe, SND_SOC_SOF_INTEL_HDA_COMMON);
1432
Liam Girdwooddd96dac2019-04-12 11:08:47 -05001433MODULE_LICENSE("Dual BSD/GPL");
Pierre-Louis Bossart194fe0f2021-03-01 18:31:22 -06001434MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);
Pierre-Louis Bossart5bd216c2019-12-17 14:22:29 -06001435MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC);
1436MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915);
Pierre-Louis Bossart068ac0d2019-12-17 14:22:31 -06001437MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
Pierre-Louis Bossart08c2a4b2021-03-01 18:31:24 -06001438MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);
Pierre-Louis Bossart1eb62932020-08-19 20:44:04 +08001439MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);