| 1 |
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) |
| 2 |
// |
| 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 |
| 7 |
// |
| 8 |
// Authors: Liam Girdwood <[email protected]> |
| 9 |
// Ranjani Sridharan <[email protected]> |
| 10 |
// Rander Wang <[email protected]> |
| 11 |
// Keyon Jie <[email protected]> |
| 12 |
// |
| 13 |
|
| 14 |
/* |
| 15 |
* Hardware interface for generic Intel audio DSP HDA IP |
| 16 |
*/ |
| 17 |
|
| 18 |
#include <sound/hdaudio_ext.h> |
| 19 |
#include <sound/hda_register.h> |
| 20 |
|
| 21 |
#include <linux/acpi.h> |
| 22 |
#include <linux/debugfs.h> |
| 23 |
#include <linux/module.h> |
| 24 |
#include <linux/soundwire/sdw.h> |
| 25 |
#include <linux/soundwire/sdw_intel.h> |
| 26 |
#include <sound/intel-dsp-config.h> |
| 27 |
#include <sound/intel-nhlt.h> |
| 28 |
#include <sound/soc-acpi-intel-ssp-common.h> |
| 29 |
#include <sound/soc_sdw_utils.h> |
| 30 |
#include <sound/sof.h> |
| 31 |
#include <sound/sof/xtensa.h> |
| 32 |
#include <sound/hda-mlink.h> |
| 33 |
#include "../sof-audio.h" |
| 34 |
#include "../sof-pci-dev.h" |
| 35 |
#include "../ops.h" |
| 36 |
#include "../ipc4-topology.h" |
| 37 |
#include "../../intel/common/sof-function-topology-lib.h" |
| 38 |
#include "hda.h" |
| 39 |
|
| 40 |
#include <trace/events/sof_intel.h> |
| 41 |
|
| 42 |
#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) |
| 43 |
#include <sound/soc-acpi-intel-match.h> |
| 44 |
#endif |
| 45 |
|
| 46 |
/* platform specific devices */ |
| 47 |
#include "shim.h" |
| 48 |
|
| 49 |
#if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) |
| 50 |
|
| 51 |
/* |
| 52 |
* The default for SoundWire clock stop quirks is to power gate the IP |
| 53 |
* and do a Bus Reset, this will need to be modified when the DSP |
| 54 |
* needs to remain in D0i3 so that the Master does not lose context |
| 55 |
* and enumeration is not required on clock restart |
| 56 |
*/ |
| 57 |
static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET; |
| 58 |
module_param(sdw_clock_stop_quirks, int, 0444); |
| 59 |
MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks"); |
| 60 |
|
| 61 |
static int sdw_params_stream(struct device *dev, |
| 62 |
struct sdw_intel_stream_params_data *params_data) |
| 63 |
{ |
| 64 |
struct snd_soc_dai *d = params_data->dai; |
| 65 |
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(d, params_data->substream->stream); |
| 66 |
struct snd_sof_dai_config_data data = { 0 }; |
| 67 |
|
| 68 |
if (!w) { |
| 69 |
dev_err(dev, "%s widget not found, check amp link num in the topology\n", |
| 70 |
d->name); |
| 71 |
return -EINVAL; |
| 72 |
} |
| 73 |
data.dai_index = (params_data->link_id << 8) | d->id; |
| 74 |
data.dai_data = params_data->alh_stream_id; |
| 75 |
data.dai_node_id = data.dai_data; |
| 76 |
|
| 77 |
return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_PARAMS, &data); |
| 78 |
} |
| 79 |
|
| 80 |
static int sdw_params_free(struct device *dev, struct sdw_intel_stream_free_data *free_data) |
| 81 |
{ |
| 82 |
struct snd_soc_dai *d = free_data->dai; |
| 83 |
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(d, free_data->substream->stream); |
| 84 |
struct snd_sof_dev *sdev = widget_to_sdev(w); |
| 85 |
|
| 86 |
if (sdev->pdata->ipc_type == SOF_IPC_TYPE_4) { |
| 87 |
struct snd_sof_widget *swidget = w->dobj.private; |
| 88 |
struct snd_sof_dai *dai = swidget->private; |
| 89 |
struct sof_ipc4_copier_data *copier_data; |
| 90 |
struct sof_ipc4_copier *ipc4_copier; |
| 91 |
|
| 92 |
ipc4_copier = dai->private; |
| 93 |
ipc4_copier->dai_index = 0; |
| 94 |
copier_data = &ipc4_copier->data; |
| 95 |
|
| 96 |
/* clear the node ID */ |
| 97 |
copier_data->gtw_cfg.node_id &= ~SOF_IPC4_NODE_INDEX_MASK; |
| 98 |
} |
| 99 |
|
| 100 |
return 0; |
| 101 |
} |
| 102 |
|
| 103 |
struct sdw_intel_ops sdw_callback = { |
| 104 |
.params_stream = sdw_params_stream, |
| 105 |
.free_stream = sdw_params_free, |
| 106 |
}; |
| 107 |
|
| 108 |
static int sdw_ace2x_params_stream(struct device *dev, |
| 109 |
struct sdw_intel_stream_params_data *params_data) |
| 110 |
{ |
| 111 |
return sdw_hda_dai_hw_params(params_data->substream, |
| 112 |
params_data->hw_params, |
| 113 |
params_data->dai, |
| 114 |
params_data->link_id, |
| 115 |
params_data->alh_stream_id); |
| 116 |
} |
| 117 |
|
| 118 |
static int sdw_ace2x_free_stream(struct device *dev, |
| 119 |
struct sdw_intel_stream_free_data *free_data) |
| 120 |
{ |
| 121 |
return sdw_hda_dai_hw_free(free_data->substream, |
| 122 |
free_data->dai, |
| 123 |
free_data->link_id); |
| 124 |
} |
| 125 |
|
| 126 |
static int sdw_ace2x_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) |
| 127 |
{ |
| 128 |
return sdw_hda_dai_trigger(substream, cmd, dai); |
| 129 |
} |
| 130 |
|
| 131 |
static struct sdw_intel_ops sdw_ace2x_callback = { |
| 132 |
.params_stream = sdw_ace2x_params_stream, |
| 133 |
.free_stream = sdw_ace2x_free_stream, |
| 134 |
.trigger = sdw_ace2x_trigger, |
| 135 |
}; |
| 136 |
|
| 137 |
static int hda_sdw_acpi_scan(struct snd_sof_dev *sdev) |
| 138 |
{ |
| 139 |
u32 interface_mask = hda_get_interface_mask(sdev); |
| 140 |
struct sof_intel_hda_dev *hdev; |
| 141 |
acpi_handle handle; |
| 142 |
int ret; |
| 143 |
|
| 144 |
if (!(interface_mask & BIT(SOF_DAI_INTEL_ALH))) |
| 145 |
return -EINVAL; |
| 146 |
|
| 147 |
handle = ACPI_HANDLE(sdev->dev); |
| 148 |
|
| 149 |
/* save ACPI info for the probe step */ |
| 150 |
hdev = sdev->pdata->hw_pdata; |
| 151 |
|
| 152 |
ret = sdw_intel_acpi_scan(handle, &hdev->info); |
| 153 |
if (ret < 0) |
| 154 |
return -EINVAL; |
| 155 |
|
| 156 |
return 0; |
| 157 |
} |
| 158 |
|
| 159 |
static int hda_sdw_probe(struct snd_sof_dev *sdev) |
| 160 |
{ |
| 161 |
const struct sof_intel_dsp_desc *chip; |
| 162 |
struct sof_intel_hda_dev *hdev; |
| 163 |
struct sdw_intel_res res; |
| 164 |
void *sdw; |
| 165 |
|
| 166 |
hdev = sdev->pdata->hw_pdata; |
| 167 |
|
| 168 |
memset(&res, 0, sizeof(res)); |
| 169 |
|
| 170 |
chip = get_chip_info(sdev->pdata); |
| 171 |
if (chip->hw_ip_version < SOF_INTEL_ACE_2_0) { |
| 172 |
res.mmio_base = sdev->bar[HDA_DSP_BAR]; |
| 173 |
res.hw_ops = &sdw_intel_cnl_hw_ops; |
| 174 |
res.shim_base = hdev->desc->sdw_shim_base; |
| 175 |
res.alh_base = hdev->desc->sdw_alh_base; |
| 176 |
res.ext = false; |
| 177 |
res.ops = &sdw_callback; |
| 178 |
} else { |
| 179 |
/* |
| 180 |
* retrieve eml_lock needed to protect shared registers |
| 181 |
* in the HDaudio multi-link areas |
| 182 |
*/ |
| 183 |
res.eml_lock = hdac_bus_eml_get_mutex(sof_to_bus(sdev), true, |
| 184 |
AZX_REG_ML_LEPTR_ID_SDW); |
| 185 |
if (!res.eml_lock) |
| 186 |
return -ENODEV; |
| 187 |
|
| 188 |
res.mmio_base = sdev->bar[HDA_DSP_HDA_BAR]; |
| 189 |
/* |
| 190 |
* the SHIM and SoundWire register offsets are link-specific |
| 191 |
* and will be determined when adding auxiliary devices |
| 192 |
*/ |
| 193 |
res.hw_ops = &sdw_intel_lnl_hw_ops; |
| 194 |
res.ext = true; |
| 195 |
res.ops = &sdw_ace2x_callback; |
| 196 |
|
| 197 |
/* ACE3+ supports microphone privacy */ |
| 198 |
if (chip->hw_ip_version >= SOF_INTEL_ACE_3_0) |
| 199 |
res.mic_privacy = true; |
| 200 |
} |
| 201 |
res.irq = sdev->ipc_irq; |
| 202 |
res.handle = hdev->info.handle; |
| 203 |
res.parent = sdev->dev; |
| 204 |
|
| 205 |
res.dev = sdev->dev; |
| 206 |
res.clock_stop_quirks = sdw_clock_stop_quirks; |
| 207 |
res.hbus = sof_to_bus(sdev); |
| 208 |
|
| 209 |
/* |
| 210 |
* ops and arg fields are not populated for now, |
| 211 |
* they will be needed when the DAI callbacks are |
| 212 |
* provided |
| 213 |
*/ |
| 214 |
|
| 215 |
/* we could filter links here if needed, e.g for quirks */ |
| 216 |
res.count = hdev->info.count; |
| 217 |
res.link_mask = hdev->info.link_mask; |
| 218 |
|
| 219 |
sdw = sdw_intel_probe(&res); |
| 220 |
if (!sdw) { |
| 221 |
dev_err(sdev->dev, "error: SoundWire probe failed\n"); |
| 222 |
return -EINVAL; |
| 223 |
} |
| 224 |
|
| 225 |
/* save context */ |
| 226 |
hdev->sdw = sdw; |
| 227 |
|
| 228 |
return 0; |
| 229 |
} |
| 230 |
|
| 231 |
int hda_sdw_startup(struct snd_sof_dev *sdev) |
| 232 |
{ |
| 233 |
struct sof_intel_hda_dev *hdev; |
| 234 |
struct snd_sof_pdata *pdata = sdev->pdata; |
| 235 |
int ret; |
| 236 |
|
| 237 |
hdev = sdev->pdata->hw_pdata; |
| 238 |
|
| 239 |
if (!hdev->sdw) |
| 240 |
return 0; |
| 241 |
|
| 242 |
if (pdata->machine && !pdata->machine->mach_params.link_mask) |
| 243 |
return 0; |
| 244 |
|
| 245 |
ret = hda_sdw_check_lcount(sdev); |
| 246 |
if (ret < 0) |
| 247 |
return ret; |
| 248 |
|
| 249 |
return sdw_intel_startup(hdev->sdw); |
| 250 |
} |
| 251 |
EXPORT_SYMBOL_NS(hda_sdw_startup, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 252 |
|
| 253 |
static int hda_sdw_exit(struct snd_sof_dev *sdev) |
| 254 |
{ |
| 255 |
struct sof_intel_hda_dev *hdev; |
| 256 |
|
| 257 |
hdev = sdev->pdata->hw_pdata; |
| 258 |
|
| 259 |
if (hdev->sdw) |
| 260 |
sdw_intel_exit(hdev->sdw); |
| 261 |
hdev->sdw = NULL; |
| 262 |
|
| 263 |
hda_sdw_int_enable(sdev, false); |
| 264 |
|
| 265 |
return 0; |
| 266 |
} |
| 267 |
|
| 268 |
bool hda_common_check_sdw_irq(struct snd_sof_dev *sdev) |
| 269 |
{ |
| 270 |
struct sof_intel_hda_dev *hdev; |
| 271 |
bool ret = false; |
| 272 |
u32 irq_status; |
| 273 |
|
| 274 |
hdev = sdev->pdata->hw_pdata; |
| 275 |
|
| 276 |
if (!hdev->sdw) |
| 277 |
return ret; |
| 278 |
|
| 279 |
/* store status */ |
| 280 |
irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS2); |
| 281 |
|
| 282 |
/* invalid message ? */ |
| 283 |
if (irq_status == 0xffffffff) |
| 284 |
goto out; |
| 285 |
|
| 286 |
/* SDW message ? */ |
| 287 |
if (irq_status & HDA_DSP_REG_ADSPIS2_SNDW) |
| 288 |
ret = true; |
| 289 |
|
| 290 |
out: |
| 291 |
return ret; |
| 292 |
} |
| 293 |
EXPORT_SYMBOL_NS(hda_common_check_sdw_irq, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 294 |
|
| 295 |
static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev) |
| 296 |
{ |
| 297 |
u32 interface_mask = hda_get_interface_mask(sdev); |
| 298 |
const struct sof_intel_dsp_desc *chip; |
| 299 |
|
| 300 |
if (!(interface_mask & BIT(SOF_DAI_INTEL_ALH))) |
| 301 |
return false; |
| 302 |
|
| 303 |
chip = get_chip_info(sdev->pdata); |
| 304 |
if (chip && chip->check_sdw_irq) |
| 305 |
return chip->check_sdw_irq(sdev); |
| 306 |
|
| 307 |
return false; |
| 308 |
} |
| 309 |
|
| 310 |
static irqreturn_t hda_dsp_sdw_thread(int irq, void *context) |
| 311 |
{ |
| 312 |
return sdw_intel_thread(irq, context); |
| 313 |
} |
| 314 |
|
| 315 |
bool hda_sdw_check_wakeen_irq_common(struct snd_sof_dev *sdev) |
| 316 |
{ |
| 317 |
struct sof_intel_hda_dev *hdev; |
| 318 |
|
| 319 |
hdev = sdev->pdata->hw_pdata; |
| 320 |
if (hdev->sdw && |
| 321 |
snd_sof_dsp_read(sdev, HDA_DSP_BAR, |
| 322 |
hdev->desc->sdw_shim_base + SDW_SHIM_WAKESTS)) |
| 323 |
return true; |
| 324 |
|
| 325 |
return false; |
| 326 |
} |
| 327 |
EXPORT_SYMBOL_NS(hda_sdw_check_wakeen_irq_common, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 328 |
|
| 329 |
static bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev) |
| 330 |
{ |
| 331 |
u32 interface_mask = hda_get_interface_mask(sdev); |
| 332 |
const struct sof_intel_dsp_desc *chip; |
| 333 |
|
| 334 |
if (!(interface_mask & BIT(SOF_DAI_INTEL_ALH))) |
| 335 |
return false; |
| 336 |
|
| 337 |
chip = get_chip_info(sdev->pdata); |
| 338 |
if (chip && chip->check_sdw_wakeen_irq) |
| 339 |
return chip->check_sdw_wakeen_irq(sdev); |
| 340 |
|
| 341 |
return false; |
| 342 |
} |
| 343 |
|
| 344 |
void hda_sdw_process_wakeen_common(struct snd_sof_dev *sdev) |
| 345 |
{ |
| 346 |
u32 interface_mask = hda_get_interface_mask(sdev); |
| 347 |
struct sof_intel_hda_dev *hdev; |
| 348 |
|
| 349 |
if (!(interface_mask & BIT(SOF_DAI_INTEL_ALH))) |
| 350 |
return; |
| 351 |
|
| 352 |
hdev = sdev->pdata->hw_pdata; |
| 353 |
if (!hdev->sdw) |
| 354 |
return; |
| 355 |
|
| 356 |
sdw_intel_process_wakeen_event(hdev->sdw); |
| 357 |
} |
| 358 |
EXPORT_SYMBOL_NS(hda_sdw_process_wakeen_common, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 359 |
|
| 360 |
static bool hda_dsp_sdw_check_mic_privacy_irq(struct snd_sof_dev *sdev) |
| 361 |
{ |
| 362 |
const struct sof_intel_dsp_desc *chip; |
| 363 |
|
| 364 |
chip = get_chip_info(sdev->pdata); |
| 365 |
if (chip && chip->check_mic_privacy_irq) |
| 366 |
return chip->check_mic_privacy_irq(sdev, true, |
| 367 |
AZX_REG_ML_LEPTR_ID_SDW); |
| 368 |
|
| 369 |
return false; |
| 370 |
} |
| 371 |
|
| 372 |
static void hda_dsp_sdw_process_mic_privacy(struct snd_sof_dev *sdev) |
| 373 |
{ |
| 374 |
const struct sof_intel_dsp_desc *chip; |
| 375 |
|
| 376 |
chip = get_chip_info(sdev->pdata); |
| 377 |
if (chip && chip->process_mic_privacy) |
| 378 |
chip->process_mic_privacy(sdev, true, AZX_REG_ML_LEPTR_ID_SDW); |
| 379 |
} |
| 380 |
|
| 381 |
#else /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */ |
| 382 |
static inline int hda_sdw_acpi_scan(struct snd_sof_dev *sdev) |
| 383 |
{ |
| 384 |
return 0; |
| 385 |
} |
| 386 |
|
| 387 |
static inline int hda_sdw_probe(struct snd_sof_dev *sdev) |
| 388 |
{ |
| 389 |
return 0; |
| 390 |
} |
| 391 |
|
| 392 |
static inline int hda_sdw_exit(struct snd_sof_dev *sdev) |
| 393 |
{ |
| 394 |
return 0; |
| 395 |
} |
| 396 |
|
| 397 |
static inline bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev) |
| 398 |
{ |
| 399 |
return false; |
| 400 |
} |
| 401 |
|
| 402 |
static inline irqreturn_t hda_dsp_sdw_thread(int irq, void *context) |
| 403 |
{ |
| 404 |
return IRQ_HANDLED; |
| 405 |
} |
| 406 |
|
| 407 |
static inline bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev) |
| 408 |
{ |
| 409 |
return false; |
| 410 |
} |
| 411 |
|
| 412 |
static inline bool hda_dsp_sdw_check_mic_privacy_irq(struct snd_sof_dev *sdev) |
| 413 |
{ |
| 414 |
return false; |
| 415 |
} |
| 416 |
|
| 417 |
static inline void hda_dsp_sdw_process_mic_privacy(struct snd_sof_dev *sdev) { } |
| 418 |
|
| 419 |
#endif /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */ |
| 420 |
|
| 421 |
/* pre fw run operations */ |
| 422 |
int hda_dsp_pre_fw_run(struct snd_sof_dev *sdev) |
| 423 |
{ |
| 424 |
/* disable clock gating and power gating */ |
| 425 |
return hda_dsp_ctrl_clock_power_gating(sdev, false); |
| 426 |
} |
| 427 |
|
| 428 |
/* post fw run operations */ |
| 429 |
int hda_dsp_post_fw_run(struct snd_sof_dev *sdev) |
| 430 |
{ |
| 431 |
int ret; |
| 432 |
|
| 433 |
if (sdev->first_boot) { |
| 434 |
struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; |
| 435 |
|
| 436 |
ret = hda_sdw_startup(sdev); |
| 437 |
if (ret < 0) { |
| 438 |
dev_err(sdev->dev, |
| 439 |
"error: could not startup SoundWire links\n"); |
| 440 |
return ret; |
| 441 |
} |
| 442 |
|
| 443 |
/* Check if IMR boot is usable */ |
| 444 |
if (!sof_debug_check_flag(SOF_DBG_IGNORE_D3_PERSISTENT) && |
| 445 |
(sdev->fw_ready.flags & SOF_IPC_INFO_D3_PERSISTENT || |
| 446 |
sdev->pdata->ipc_type == SOF_IPC_TYPE_4)) { |
| 447 |
hdev->imrboot_supported = true; |
| 448 |
debugfs_create_bool("skip_imr_boot", |
| 449 |
0644, sdev->debugfs_root, |
| 450 |
&hdev->skip_imr_boot); |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
hda_sdw_int_enable(sdev, true); |
| 455 |
|
| 456 |
/* re-enable clock gating and power gating */ |
| 457 |
return hda_dsp_ctrl_clock_power_gating(sdev, true); |
| 458 |
} |
| 459 |
EXPORT_SYMBOL_NS(hda_dsp_post_fw_run, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 460 |
|
| 461 |
/* |
| 462 |
* Debug |
| 463 |
*/ |
| 464 |
|
| 465 |
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG) |
| 466 |
static bool hda_use_msi = true; |
| 467 |
module_param_named(use_msi, hda_use_msi, bool, 0444); |
| 468 |
MODULE_PARM_DESC(use_msi, "SOF HDA use PCI MSI mode"); |
| 469 |
#else |
| 470 |
#define hda_use_msi (1) |
| 471 |
#endif |
| 472 |
|
| 473 |
static char *hda_model; |
| 474 |
module_param(hda_model, charp, 0444); |
| 475 |
MODULE_PARM_DESC(hda_model, "Use the given HDA board model."); |
| 476 |
|
| 477 |
static int dmic_num_override = -1; |
| 478 |
module_param_named(dmic_num, dmic_num_override, int, 0444); |
| 479 |
MODULE_PARM_DESC(dmic_num, "SOF HDA DMIC number"); |
| 480 |
|
| 481 |
static int mclk_id_override = -1; |
| 482 |
module_param_named(mclk_id, mclk_id_override, int, 0444); |
| 483 |
MODULE_PARM_DESC(mclk_id, "SOF SSP mclk_id"); |
| 484 |
|
| 485 |
static int bt_link_mask_override = -1; |
| 486 |
module_param_named(bt_link_mask, bt_link_mask_override, int, 0444); |
| 487 |
MODULE_PARM_DESC(bt_link_mask, "SOF BT offload link mask"); |
| 488 |
|
| 489 |
static int hda_init(struct snd_sof_dev *sdev) |
| 490 |
{ |
| 491 |
struct hda_bus *hbus; |
| 492 |
struct hdac_bus *bus; |
| 493 |
struct pci_dev *pci = to_pci_dev(sdev->dev); |
| 494 |
int ret; |
| 495 |
|
| 496 |
hbus = sof_to_hbus(sdev); |
| 497 |
bus = sof_to_bus(sdev); |
| 498 |
|
| 499 |
/* HDA bus init */ |
| 500 |
sof_hda_bus_init(sdev, &pci->dev); |
| 501 |
|
| 502 |
if (sof_hda_position_quirk == SOF_HDA_POSITION_QUIRK_USE_DPIB_REGISTERS) |
| 503 |
bus->use_posbuf = 0; |
| 504 |
else |
| 505 |
bus->use_posbuf = 1; |
| 506 |
bus->bdl_pos_adj = 0; |
| 507 |
bus->sync_write = 1; |
| 508 |
|
| 509 |
mutex_init(&hbus->prepare_mutex); |
| 510 |
hbus->pci = pci; |
| 511 |
hbus->mixer_assigned = -1; |
| 512 |
hbus->modelname = hda_model; |
| 513 |
|
| 514 |
/* initialise hdac bus */ |
| 515 |
bus->addr = pci_resource_start(pci, 0); |
| 516 |
bus->remap_addr = pci_ioremap_bar(pci, 0); |
| 517 |
if (!bus->remap_addr) { |
| 518 |
dev_err(bus->dev, "error: ioremap error\n"); |
| 519 |
return -ENXIO; |
| 520 |
} |
| 521 |
|
| 522 |
/* HDA base */ |
| 523 |
sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr; |
| 524 |
|
| 525 |
/* init i915 and HDMI codecs */ |
| 526 |
ret = hda_codec_i915_init(sdev); |
| 527 |
if (ret < 0 && ret != -ENODEV) { |
| 528 |
dev_err_probe(sdev->dev, ret, "init of i915 and HDMI codec failed\n"); |
| 529 |
goto out; |
| 530 |
} |
| 531 |
|
| 532 |
/* get controller capabilities */ |
| 533 |
ret = hda_dsp_ctrl_get_caps(sdev); |
| 534 |
if (ret < 0) { |
| 535 |
dev_err(sdev->dev, "error: get caps error\n"); |
| 536 |
hda_codec_i915_exit(sdev); |
| 537 |
} |
| 538 |
|
| 539 |
out: |
| 540 |
if (ret < 0) |
| 541 |
iounmap(sof_to_bus(sdev)->remap_addr); |
| 542 |
|
| 543 |
return ret; |
| 544 |
} |
| 545 |
|
| 546 |
static int check_dmic_num(struct snd_sof_dev *sdev) |
| 547 |
{ |
| 548 |
struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; |
| 549 |
struct nhlt_acpi_table *nhlt; |
| 550 |
int dmic_num = 0; |
| 551 |
|
| 552 |
nhlt = hdev->nhlt; |
| 553 |
if (nhlt) |
| 554 |
dmic_num = intel_nhlt_get_dmic_geo(sdev->dev, nhlt); |
| 555 |
|
| 556 |
dev_info(sdev->dev, "DMICs detected in NHLT tables: %d\n", dmic_num); |
| 557 |
|
| 558 |
/* allow for module parameter override */ |
| 559 |
if (dmic_num_override != -1) { |
| 560 |
dev_dbg(sdev->dev, |
| 561 |
"overriding DMICs detected in NHLT tables %d by kernel param %d\n", |
| 562 |
dmic_num, dmic_num_override); |
| 563 |
dmic_num = dmic_num_override; |
| 564 |
} |
| 565 |
|
| 566 |
if (dmic_num < 0 || dmic_num > 4) { |
| 567 |
dev_dbg(sdev->dev, "invalid dmic_number %d\n", dmic_num); |
| 568 |
dmic_num = 0; |
| 569 |
} |
| 570 |
|
| 571 |
return dmic_num; |
| 572 |
} |
| 573 |
|
| 574 |
static int check_nhlt_ssp_mask(struct snd_sof_dev *sdev, u8 device_type) |
| 575 |
{ |
| 576 |
struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; |
| 577 |
struct nhlt_acpi_table *nhlt; |
| 578 |
int ssp_mask = 0; |
| 579 |
|
| 580 |
nhlt = hdev->nhlt; |
| 581 |
if (!nhlt) |
| 582 |
return ssp_mask; |
| 583 |
|
| 584 |
if (intel_nhlt_has_endpoint_type(nhlt, NHLT_LINK_SSP)) { |
| 585 |
ssp_mask = intel_nhlt_ssp_endpoint_mask(nhlt, device_type); |
| 586 |
if (ssp_mask) |
| 587 |
dev_info(sdev->dev, "NHLT device %s(%d) detected, ssp_mask %#x\n", |
| 588 |
device_type == NHLT_DEVICE_BT ? "BT" : "I2S", |
| 589 |
device_type, ssp_mask); |
| 590 |
} |
| 591 |
|
| 592 |
return ssp_mask; |
| 593 |
} |
| 594 |
|
| 595 |
static int check_nhlt_ssp_mclk_mask(struct snd_sof_dev *sdev, int ssp_num) |
| 596 |
{ |
| 597 |
struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; |
| 598 |
struct nhlt_acpi_table *nhlt; |
| 599 |
|
| 600 |
nhlt = hdev->nhlt; |
| 601 |
if (!nhlt) |
| 602 |
return 0; |
| 603 |
|
| 604 |
return intel_nhlt_ssp_mclk_mask(nhlt, ssp_num); |
| 605 |
} |
| 606 |
|
| 607 |
static int hda_init_caps(struct snd_sof_dev *sdev) |
| 608 |
{ |
| 609 |
u32 interface_mask = hda_get_interface_mask(sdev); |
| 610 |
struct hdac_bus *bus = sof_to_bus(sdev); |
| 611 |
struct snd_sof_pdata *pdata = sdev->pdata; |
| 612 |
struct sof_intel_hda_dev *hdev = pdata->hw_pdata; |
| 613 |
u32 link_mask; |
| 614 |
int ret = 0; |
| 615 |
|
| 616 |
/* check if dsp is there */ |
| 617 |
if (bus->ppcap) |
| 618 |
dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n"); |
| 619 |
|
| 620 |
/* Init HDA controller after i915 init */ |
| 621 |
ret = hda_dsp_ctrl_init_chip(sdev, true); |
| 622 |
if (ret < 0) { |
| 623 |
dev_err(bus->dev, "error: init chip failed with ret: %d\n", |
| 624 |
ret); |
| 625 |
return ret; |
| 626 |
} |
| 627 |
|
| 628 |
hda_bus_ml_init(bus); |
| 629 |
|
| 630 |
/* Skip SoundWire if it is not supported */ |
| 631 |
if (!(interface_mask & BIT(SOF_DAI_INTEL_ALH))) |
| 632 |
goto skip_soundwire; |
| 633 |
|
| 634 |
/* Skip SoundWire in nocodec mode */ |
| 635 |
if (IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC_DEBUG_SUPPORT) && |
| 636 |
sof_debug_check_flag(SOF_DBG_FORCE_NOCODEC)) |
| 637 |
goto skip_soundwire; |
| 638 |
|
| 639 |
/* scan SoundWire capabilities exposed by DSDT */ |
| 640 |
ret = hda_sdw_acpi_scan(sdev); |
| 641 |
if (ret < 0) { |
| 642 |
dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n"); |
| 643 |
goto skip_soundwire; |
| 644 |
} |
| 645 |
|
| 646 |
link_mask = hdev->info.link_mask; |
| 647 |
if (!link_mask) { |
| 648 |
dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n"); |
| 649 |
goto skip_soundwire; |
| 650 |
} |
| 651 |
|
| 652 |
/* |
| 653 |
* probe/allocate SoundWire resources. |
| 654 |
* The hardware configuration takes place in hda_sdw_startup |
| 655 |
* after power rails are enabled. |
| 656 |
* It's entirely possible to have a mix of I2S/DMIC/SoundWire |
| 657 |
* devices, so we allocate the resources in all cases. |
| 658 |
*/ |
| 659 |
ret = hda_sdw_probe(sdev); |
| 660 |
if (ret < 0) { |
| 661 |
dev_err(sdev->dev, "error: SoundWire probe error\n"); |
| 662 |
return ret; |
| 663 |
} |
| 664 |
|
| 665 |
skip_soundwire: |
| 666 |
|
| 667 |
/* create codec instances */ |
| 668 |
hda_codec_probe_bus(sdev); |
| 669 |
|
| 670 |
if (!HDA_IDISP_CODEC(bus->codec_mask)) |
| 671 |
hda_codec_i915_display_power(sdev, false); |
| 672 |
|
| 673 |
hda_bus_ml_put_all(bus); |
| 674 |
|
| 675 |
return 0; |
| 676 |
} |
| 677 |
|
| 678 |
static irqreturn_t hda_dsp_interrupt_handler(int irq, void *context) |
| 679 |
{ |
| 680 |
struct snd_sof_dev *sdev = context; |
| 681 |
|
| 682 |
/* |
| 683 |
* Get global interrupt status. It includes all hardware interrupt |
| 684 |
* sources in the Intel HD Audio controller. |
| 685 |
*/ |
| 686 |
if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) & |
| 687 |
SOF_HDA_INTSTS_GIS) { |
| 688 |
|
| 689 |
/* disable GIE interrupt */ |
| 690 |
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, |
| 691 |
SOF_HDA_INTCTL, |
| 692 |
SOF_HDA_INT_GLOBAL_EN, |
| 693 |
0); |
| 694 |
|
| 695 |
return IRQ_WAKE_THREAD; |
| 696 |
} |
| 697 |
|
| 698 |
return IRQ_NONE; |
| 699 |
} |
| 700 |
|
| 701 |
static irqreturn_t hda_dsp_interrupt_thread(int irq, void *context) |
| 702 |
{ |
| 703 |
struct snd_sof_dev *sdev = context; |
| 704 |
struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; |
| 705 |
|
| 706 |
/* deal with streams and controller first */ |
| 707 |
if (hda_dsp_check_stream_irq(sdev)) { |
| 708 |
trace_sof_intel_hda_irq(sdev, "stream"); |
| 709 |
hda_dsp_stream_threaded_handler(irq, sdev); |
| 710 |
} |
| 711 |
|
| 712 |
if (hda_check_ipc_irq(sdev)) { |
| 713 |
trace_sof_intel_hda_irq(sdev, "ipc"); |
| 714 |
sof_ops(sdev)->irq_thread(irq, sdev); |
| 715 |
} |
| 716 |
|
| 717 |
if (hda_dsp_check_sdw_irq(sdev)) { |
| 718 |
trace_sof_intel_hda_irq(sdev, "sdw"); |
| 719 |
|
| 720 |
hda_dsp_sdw_thread(irq, hdev->sdw); |
| 721 |
|
| 722 |
if (hda_dsp_sdw_check_mic_privacy_irq(sdev)) { |
| 723 |
trace_sof_intel_hda_irq(sdev, "mic privacy"); |
| 724 |
hda_dsp_sdw_process_mic_privacy(sdev); |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
if (hda_sdw_check_wakeen_irq(sdev)) { |
| 729 |
trace_sof_intel_hda_irq(sdev, "wakeen"); |
| 730 |
hda_sdw_process_wakeen(sdev); |
| 731 |
} |
| 732 |
|
| 733 |
hda_codec_check_for_state_change(sdev); |
| 734 |
|
| 735 |
/* enable GIE interrupt */ |
| 736 |
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, |
| 737 |
SOF_HDA_INTCTL, |
| 738 |
SOF_HDA_INT_GLOBAL_EN, |
| 739 |
SOF_HDA_INT_GLOBAL_EN); |
| 740 |
|
| 741 |
return IRQ_HANDLED; |
| 742 |
} |
| 743 |
|
| 744 |
int hda_dsp_probe_early(struct snd_sof_dev *sdev) |
| 745 |
{ |
| 746 |
struct pci_dev *pci = to_pci_dev(sdev->dev); |
| 747 |
struct sof_intel_hda_dev *hdev; |
| 748 |
const struct sof_intel_dsp_desc *chip; |
| 749 |
int ret = 0; |
| 750 |
|
| 751 |
if (!sdev->dspless_mode_selected) { |
| 752 |
/* |
| 753 |
* detect DSP by checking class/subclass/prog-id information |
| 754 |
* class=04 subclass 03 prog-if 00: no DSP, legacy driver is required |
| 755 |
* class=04 subclass 01 prog-if 00: DSP is present |
| 756 |
* (and may be required e.g. for DMIC or SSP support) |
| 757 |
* class=04 subclass 03 prog-if 80: either of DSP or legacy mode works |
| 758 |
*/ |
| 759 |
if (pci->class == 0x040300) { |
| 760 |
dev_err(sdev->dev, "the DSP is not enabled on this platform, aborting probe\n"); |
| 761 |
return -ENODEV; |
| 762 |
} else if (pci->class != 0x040100 && pci->class != 0x040380) { |
| 763 |
dev_err(sdev->dev, "unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", |
| 764 |
pci->class); |
| 765 |
return -ENODEV; |
| 766 |
} |
| 767 |
dev_info_once(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", |
| 768 |
pci->class); |
| 769 |
} |
| 770 |
|
| 771 |
chip = get_chip_info(sdev->pdata); |
| 772 |
if (!chip) { |
| 773 |
dev_err(sdev->dev, "error: no such device supported, chip id:%x\n", |
| 774 |
pci->device); |
| 775 |
ret = -EIO; |
| 776 |
goto err; |
| 777 |
} |
| 778 |
|
| 779 |
sdev->num_cores = chip->cores_num; |
| 780 |
|
| 781 |
hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL); |
| 782 |
if (!hdev) |
| 783 |
return -ENOMEM; |
| 784 |
sdev->pdata->hw_pdata = hdev; |
| 785 |
hdev->desc = chip; |
| 786 |
ret = hda_init(sdev); |
| 787 |
|
| 788 |
err: |
| 789 |
return ret; |
| 790 |
} |
| 791 |
EXPORT_SYMBOL_NS(hda_dsp_probe_early, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 792 |
|
| 793 |
int hda_dsp_probe(struct snd_sof_dev *sdev) |
| 794 |
{ |
| 795 |
struct pci_dev *pci = to_pci_dev(sdev->dev); |
| 796 |
struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; |
| 797 |
const struct sof_intel_dsp_desc *chip; |
| 798 |
int ret = 0; |
| 799 |
|
| 800 |
hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec", |
| 801 |
PLATFORM_DEVID_NONE, |
| 802 |
NULL, 0); |
| 803 |
if (IS_ERR(hdev->dmic_dev)) { |
| 804 |
dev_err(sdev->dev, "error: failed to create DMIC device\n"); |
| 805 |
return PTR_ERR(hdev->dmic_dev); |
| 806 |
} |
| 807 |
|
| 808 |
/* |
| 809 |
* use position update IPC if either it is forced |
| 810 |
* or we don't have other choice |
| 811 |
*/ |
| 812 |
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION) |
| 813 |
hdev->no_ipc_position = 0; |
| 814 |
#else |
| 815 |
hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0; |
| 816 |
#endif |
| 817 |
|
| 818 |
if (sdev->dspless_mode_selected) |
| 819 |
hdev->no_ipc_position = 1; |
| 820 |
|
| 821 |
if (sdev->dspless_mode_selected) |
| 822 |
goto skip_dsp_setup; |
| 823 |
|
| 824 |
/* DSP base */ |
| 825 |
sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR); |
| 826 |
if (!sdev->bar[HDA_DSP_BAR]) { |
| 827 |
dev_err(sdev->dev, "error: ioremap error\n"); |
| 828 |
ret = -ENXIO; |
| 829 |
goto hdac_bus_unmap; |
| 830 |
} |
| 831 |
|
| 832 |
sdev->mmio_bar = HDA_DSP_BAR; |
| 833 |
sdev->mailbox_bar = HDA_DSP_BAR; |
| 834 |
skip_dsp_setup: |
| 835 |
|
| 836 |
/* allow 64bit DMA address if supported by H/W */ |
| 837 |
if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) { |
| 838 |
dev_dbg(sdev->dev, "DMA mask is 32 bit\n"); |
| 839 |
dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)); |
| 840 |
} |
| 841 |
dma_set_max_seg_size(&pci->dev, UINT_MAX); |
| 842 |
|
| 843 |
/* init streams */ |
| 844 |
ret = hda_dsp_stream_init(sdev); |
| 845 |
if (ret < 0) { |
| 846 |
dev_err(sdev->dev, "error: failed to init streams\n"); |
| 847 |
/* |
| 848 |
* not all errors are due to memory issues, but trying |
| 849 |
* to free everything does not harm |
| 850 |
*/ |
| 851 |
goto free_streams; |
| 852 |
} |
| 853 |
|
| 854 |
/* |
| 855 |
* register our IRQ |
| 856 |
* let's try to enable msi firstly |
| 857 |
* if it fails, use legacy interrupt mode |
| 858 |
* TODO: support msi multiple vectors |
| 859 |
*/ |
| 860 |
if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) { |
| 861 |
dev_info(sdev->dev, "use msi interrupt mode\n"); |
| 862 |
sdev->ipc_irq = pci_irq_vector(pci, 0); |
| 863 |
/* initialised to "false" by kzalloc() */ |
| 864 |
sdev->msi_enabled = true; |
| 865 |
} |
| 866 |
|
| 867 |
if (!sdev->msi_enabled) { |
| 868 |
dev_info(sdev->dev, "use legacy interrupt mode\n"); |
| 869 |
/* |
| 870 |
* in IO-APIC mode, hda->irq and ipc_irq are using the same |
| 871 |
* irq number of pci->irq |
| 872 |
*/ |
| 873 |
sdev->ipc_irq = pci->irq; |
| 874 |
} |
| 875 |
|
| 876 |
dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq); |
| 877 |
ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler, |
| 878 |
hda_dsp_interrupt_thread, |
| 879 |
IRQF_SHARED, "AudioDSP", sdev); |
| 880 |
if (ret < 0) { |
| 881 |
dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n", |
| 882 |
sdev->ipc_irq); |
| 883 |
goto free_irq_vector; |
| 884 |
} |
| 885 |
|
| 886 |
pci_set_master(pci); |
| 887 |
synchronize_irq(pci->irq); |
| 888 |
|
| 889 |
/* |
| 890 |
* clear TCSEL to clear playback on some HD Audio |
| 891 |
* codecs. PCI TCSEL is defined in the Intel manuals. |
| 892 |
*/ |
| 893 |
snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0); |
| 894 |
|
| 895 |
/* init HDA capabilities */ |
| 896 |
ret = hda_init_caps(sdev); |
| 897 |
if (ret < 0) |
| 898 |
goto free_ipc_irq; |
| 899 |
|
| 900 |
if (!sdev->dspless_mode_selected) { |
| 901 |
/* enable ppcap interrupt */ |
| 902 |
hda_dsp_ctrl_ppcap_enable(sdev, true); |
| 903 |
hda_dsp_ctrl_ppcap_int_enable(sdev, true); |
| 904 |
|
| 905 |
/* set default mailbox offset for FW ready message */ |
| 906 |
sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET; |
| 907 |
|
| 908 |
INIT_DELAYED_WORK(&hdev->d0i3_work, hda_dsp_d0i3_work); |
| 909 |
} |
| 910 |
|
| 911 |
chip = get_chip_info(sdev->pdata); |
| 912 |
if (chip && chip->hw_ip_version >= SOF_INTEL_ACE_2_0) { |
| 913 |
ret = hda_sdw_startup(sdev); |
| 914 |
if (ret < 0) { |
| 915 |
dev_err(sdev->dev, "could not startup SoundWire links\n"); |
| 916 |
goto disable_pp_cap; |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
init_waitqueue_head(&hdev->waitq); |
| 921 |
|
| 922 |
hdev->nhlt = intel_nhlt_init(sdev->dev); |
| 923 |
|
| 924 |
return 0; |
| 925 |
|
| 926 |
disable_pp_cap: |
| 927 |
if (!sdev->dspless_mode_selected) { |
| 928 |
hda_dsp_ctrl_ppcap_int_enable(sdev, false); |
| 929 |
hda_dsp_ctrl_ppcap_enable(sdev, false); |
| 930 |
} |
| 931 |
free_ipc_irq: |
| 932 |
free_irq(sdev->ipc_irq, sdev); |
| 933 |
free_irq_vector: |
| 934 |
if (sdev->msi_enabled) |
| 935 |
pci_free_irq_vectors(pci); |
| 936 |
free_streams: |
| 937 |
hda_dsp_stream_free(sdev); |
| 938 |
/* dsp_unmap: not currently used */ |
| 939 |
if (!sdev->dspless_mode_selected) |
| 940 |
iounmap(sdev->bar[HDA_DSP_BAR]); |
| 941 |
hdac_bus_unmap: |
| 942 |
platform_device_unregister(hdev->dmic_dev); |
| 943 |
|
| 944 |
return ret; |
| 945 |
} |
| 946 |
EXPORT_SYMBOL_NS(hda_dsp_probe, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 947 |
|
| 948 |
void hda_dsp_remove(struct snd_sof_dev *sdev) |
| 949 |
{ |
| 950 |
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; |
| 951 |
const struct sof_intel_dsp_desc *chip = hda->desc; |
| 952 |
struct pci_dev *pci = to_pci_dev(sdev->dev); |
| 953 |
struct nhlt_acpi_table *nhlt = hda->nhlt; |
| 954 |
|
| 955 |
if (nhlt) |
| 956 |
intel_nhlt_free(nhlt); |
| 957 |
|
| 958 |
if (!sdev->dspless_mode_selected) |
| 959 |
/* cancel any attempt for DSP D0I3 */ |
| 960 |
cancel_delayed_work_sync(&hda->d0i3_work); |
| 961 |
|
| 962 |
hda_codec_device_remove(sdev); |
| 963 |
|
| 964 |
hda_sdw_exit(sdev); |
| 965 |
|
| 966 |
if (!IS_ERR_OR_NULL(hda->dmic_dev)) |
| 967 |
platform_device_unregister(hda->dmic_dev); |
| 968 |
|
| 969 |
if (!sdev->dspless_mode_selected) { |
| 970 |
/* disable DSP IRQ */ |
| 971 |
hda_dsp_ctrl_ppcap_int_enable(sdev, false); |
| 972 |
} |
| 973 |
|
| 974 |
/* disable CIE and GIE interrupts */ |
| 975 |
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL, |
| 976 |
SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0); |
| 977 |
|
| 978 |
if (sdev->dspless_mode_selected) |
| 979 |
goto skip_disable_dsp; |
| 980 |
|
| 981 |
/* Cancel the microphone privacy work if mic privacy is active */ |
| 982 |
if (hda->mic_privacy.active) |
| 983 |
cancel_work_sync(&hda->mic_privacy.work); |
| 984 |
|
| 985 |
/* no need to check for error as the DSP will be disabled anyway */ |
| 986 |
if (chip && chip->power_down_dsp) |
| 987 |
chip->power_down_dsp(sdev); |
| 988 |
|
| 989 |
/* disable DSP */ |
| 990 |
hda_dsp_ctrl_ppcap_enable(sdev, false); |
| 991 |
|
| 992 |
/* Free the persistent DMA buffers used for base firmware download */ |
| 993 |
if (hda->cl_dmab.area) |
| 994 |
snd_dma_free_pages(&hda->cl_dmab); |
| 995 |
if (hda->iccmax_dmab.area) |
| 996 |
snd_dma_free_pages(&hda->iccmax_dmab); |
| 997 |
|
| 998 |
skip_disable_dsp: |
| 999 |
free_irq(sdev->ipc_irq, sdev); |
| 1000 |
if (sdev->msi_enabled) |
| 1001 |
pci_free_irq_vectors(pci); |
| 1002 |
|
| 1003 |
hda_dsp_stream_free(sdev); |
| 1004 |
|
| 1005 |
hda_bus_ml_free(sof_to_bus(sdev)); |
| 1006 |
|
| 1007 |
if (!sdev->dspless_mode_selected) |
| 1008 |
iounmap(sdev->bar[HDA_DSP_BAR]); |
| 1009 |
} |
| 1010 |
EXPORT_SYMBOL_NS(hda_dsp_remove, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 1011 |
|
| 1012 |
void hda_dsp_remove_late(struct snd_sof_dev *sdev) |
| 1013 |
{ |
| 1014 |
iounmap(sof_to_bus(sdev)->remap_addr); |
| 1015 |
sof_hda_bus_exit(sdev); |
| 1016 |
hda_codec_i915_exit(sdev); |
| 1017 |
} |
| 1018 |
|
| 1019 |
int hda_power_down_dsp(struct snd_sof_dev *sdev) |
| 1020 |
{ |
| 1021 |
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; |
| 1022 |
const struct sof_intel_dsp_desc *chip = hda->desc; |
| 1023 |
|
| 1024 |
return hda_dsp_core_reset_power_down(sdev, chip->host_managed_cores_mask); |
| 1025 |
} |
| 1026 |
EXPORT_SYMBOL_NS(hda_power_down_dsp, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 1027 |
|
| 1028 |
#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC) |
| 1029 |
static void hda_generic_machine_select(struct snd_sof_dev *sdev, |
| 1030 |
struct snd_soc_acpi_mach **mach) |
| 1031 |
{ |
| 1032 |
struct hdac_bus *bus = sof_to_bus(sdev); |
| 1033 |
struct snd_soc_acpi_mach_params *mach_params; |
| 1034 |
struct snd_soc_acpi_mach *hda_mach; |
| 1035 |
struct snd_sof_pdata *pdata = sdev->pdata; |
| 1036 |
const char *tplg_filename; |
| 1037 |
int codec_num = 0; |
| 1038 |
int i; |
| 1039 |
|
| 1040 |
/* codec detection */ |
| 1041 |
if (!bus->codec_mask) { |
| 1042 |
dev_info(bus->dev, "no hda codecs found!\n"); |
| 1043 |
} else { |
| 1044 |
dev_info(bus->dev, "hda codecs found, mask %lx\n", |
| 1045 |
bus->codec_mask); |
| 1046 |
|
| 1047 |
for (i = 0; i < HDA_MAX_CODECS; i++) { |
| 1048 |
if (bus->codec_mask & (1 << i)) |
| 1049 |
codec_num++; |
| 1050 |
} |
| 1051 |
|
| 1052 |
/* |
| 1053 |
* If no machine driver is found, then: |
| 1054 |
* |
| 1055 |
* generic hda machine driver can handle: |
| 1056 |
* - one HDMI codec, and/or |
| 1057 |
* - one external HDAudio codec |
| 1058 |
*/ |
| 1059 |
if (!*mach && codec_num <= 2) { |
| 1060 |
bool tplg_fixup = false; |
| 1061 |
|
| 1062 |
/* |
| 1063 |
* make a local copy of the match array since we might |
| 1064 |
* be modifying it |
| 1065 |
*/ |
| 1066 |
hda_mach = devm_kmemdup_array(sdev->dev, |
| 1067 |
snd_soc_acpi_intel_hda_machines, |
| 1068 |
2, /* we have one entry + sentinel in the array */ |
| 1069 |
sizeof(snd_soc_acpi_intel_hda_machines[0]), |
| 1070 |
GFP_KERNEL); |
| 1071 |
if (!hda_mach) { |
| 1072 |
dev_err(bus->dev, |
| 1073 |
"%s: failed to duplicate the HDA match table\n", |
| 1074 |
__func__); |
| 1075 |
return; |
| 1076 |
} |
| 1077 |
|
| 1078 |
dev_info(bus->dev, "using HDA machine driver %s now\n", |
| 1079 |
hda_mach->drv_name); |
| 1080 |
|
| 1081 |
/* |
| 1082 |
* topology: use the info from hda_machines since tplg file name |
| 1083 |
* is not overwritten |
| 1084 |
*/ |
| 1085 |
if (!pdata->tplg_filename) |
| 1086 |
tplg_fixup = true; |
| 1087 |
|
| 1088 |
if (tplg_fixup && |
| 1089 |
codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask)) { |
| 1090 |
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 1091 |
"%s-idisp", |
| 1092 |
hda_mach->sof_tplg_filename); |
| 1093 |
if (!tplg_filename) |
| 1094 |
return; |
| 1095 |
|
| 1096 |
hda_mach->sof_tplg_filename = tplg_filename; |
| 1097 |
} |
| 1098 |
|
| 1099 |
if (codec_num == 2 || |
| 1100 |
(codec_num == 1 && !HDA_IDISP_CODEC(bus->codec_mask))) { |
| 1101 |
/* |
| 1102 |
* Prevent SoundWire links from starting when an external |
| 1103 |
* HDaudio codec is used |
| 1104 |
*/ |
| 1105 |
hda_mach->mach_params.link_mask = 0; |
| 1106 |
} else { |
| 1107 |
/* |
| 1108 |
* Allow SoundWire links to start when no external HDaudio codec |
| 1109 |
* was detected. This will not create a SoundWire card but |
| 1110 |
* will help detect if any SoundWire codec reports as ATTACHED. |
| 1111 |
*/ |
| 1112 |
struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; |
| 1113 |
|
| 1114 |
hda_mach->mach_params.link_mask = hdev->info.link_mask; |
| 1115 |
} |
| 1116 |
|
| 1117 |
*mach = hda_mach; |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
/* used by hda machine driver to create dai links */ |
| 1122 |
if (*mach) { |
| 1123 |
mach_params = &(*mach)->mach_params; |
| 1124 |
mach_params->codec_mask = bus->codec_mask; |
| 1125 |
} |
| 1126 |
} |
| 1127 |
#else |
| 1128 |
static void hda_generic_machine_select(struct snd_sof_dev *sdev, |
| 1129 |
struct snd_soc_acpi_mach **mach) |
| 1130 |
{ |
| 1131 |
} |
| 1132 |
#endif |
| 1133 |
|
| 1134 |
#if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) |
| 1135 |
|
| 1136 |
static bool is_endpoint_present(struct sdw_slave *sdw_device, int dai_type) |
| 1137 |
{ |
| 1138 |
int i; |
| 1139 |
|
| 1140 |
/* If SDCA is not present, assume the endpoint is present */ |
| 1141 |
if (!sdw_device->sdca_data.interface_revision) { |
| 1142 |
dev_warn(&sdw_device->dev, "SDCA properties not found in BIOS\n"); |
| 1143 |
return true; |
| 1144 |
} |
| 1145 |
|
| 1146 |
for (i = 0; i < sdw_device->sdca_data.num_functions; i++) { |
| 1147 |
if (dai_type == asoc_sdw_get_dai_type(sdw_device->sdca_data.function[i].type)) |
| 1148 |
return true; |
| 1149 |
} |
| 1150 |
dev_dbg(&sdw_device->dev, "Endpoint DAI type %d not found\n", dai_type); |
| 1151 |
return false; |
| 1152 |
} |
| 1153 |
|
| 1154 |
static struct snd_soc_acpi_adr_device *find_acpi_adr_device(struct device *dev, |
| 1155 |
struct sdw_slave *sdw_device, |
| 1156 |
struct snd_soc_acpi_link_adr *link, |
| 1157 |
int *amp_index) |
| 1158 |
{ |
| 1159 |
struct snd_soc_acpi_adr_device *adr_dev; |
| 1160 |
const char *name_prefix = ""; |
| 1161 |
int index = link->num_adr; |
| 1162 |
bool is_amp = true; /* Set it to false if the codec wiah any NON-AMP DAI type */ |
| 1163 |
int ep_index = 0; |
| 1164 |
int i, j; |
| 1165 |
|
| 1166 |
link->mask = BIT(sdw_device->bus->link_id); |
| 1167 |
/* index is 0 based, we need allocate index + 1 for the array size */ |
| 1168 |
if (!index) |
| 1169 |
adr_dev = devm_kzalloc(dev, sizeof(*adr_dev), GFP_KERNEL); |
| 1170 |
else |
| 1171 |
adr_dev = devm_krealloc(dev, (struct snd_soc_acpi_adr_device *)link->adr_d, |
| 1172 |
(index + 1) * sizeof(*adr_dev), GFP_KERNEL); |
| 1173 |
|
| 1174 |
if (!adr_dev) |
| 1175 |
return NULL; |
| 1176 |
|
| 1177 |
for (i = 0; i < asoc_sdw_get_codec_info_list_count(); i++) { |
| 1178 |
struct snd_soc_acpi_endpoint *endpoints; |
| 1179 |
int amp_group_id = 1; |
| 1180 |
|
| 1181 |
if (sdw_device->id.part_id != codec_info_list[i].part_id) |
| 1182 |
continue; |
| 1183 |
|
| 1184 |
endpoints = devm_kcalloc(dev, codec_info_list[i].dai_num, |
| 1185 |
sizeof(struct snd_soc_acpi_endpoint), GFP_KERNEL); |
| 1186 |
if (!endpoints) |
| 1187 |
return NULL; |
| 1188 |
|
| 1189 |
name_prefix = codec_info_list[i].name_prefix; |
| 1190 |
/* |
| 1191 |
* This should not happen, but add a paranoid check to avoid NULL pointer |
| 1192 |
* dereference |
| 1193 |
*/ |
| 1194 |
if (!name_prefix) { |
| 1195 |
dev_err(dev, "codec_info_list name_prefix of part id %#x is missing\n", |
| 1196 |
codec_info_list[i].part_id); |
| 1197 |
return NULL; |
| 1198 |
} |
| 1199 |
for (j = 0; j < codec_info_list[i].dai_num; j++) { |
| 1200 |
/* Check if the endpoint is present by the SDCA DisCo table */ |
| 1201 |
if (!is_endpoint_present(sdw_device, codec_info_list[i].dais[j].dai_type)) |
| 1202 |
continue; |
| 1203 |
|
| 1204 |
endpoints[ep_index].num = j; |
| 1205 |
if (codec_info_list[i].dais[j].dai_type == SOC_SDW_DAI_TYPE_AMP) { |
| 1206 |
/* Assume all amp are aggregated */ |
| 1207 |
endpoints[ep_index].aggregated = 1; |
| 1208 |
endpoints[ep_index].group_id = amp_group_id; |
| 1209 |
endpoints[ep_index].group_position = *amp_index; |
| 1210 |
/* Set group id = 2 for feedback capture endpoint */ |
| 1211 |
amp_group_id++; |
| 1212 |
} else { |
| 1213 |
endpoints[ep_index].aggregated = 0; |
| 1214 |
endpoints[ep_index].group_id = 0; |
| 1215 |
endpoints[ep_index].group_position = 0; |
| 1216 |
is_amp = false; |
| 1217 |
} |
| 1218 |
ep_index++; |
| 1219 |
} |
| 1220 |
adr_dev[index].endpoints = endpoints; |
| 1221 |
adr_dev[index].num_endpoints = ep_index; |
| 1222 |
break; |
| 1223 |
} |
| 1224 |
|
| 1225 |
if (i == asoc_sdw_get_codec_info_list_count()) { |
| 1226 |
dev_err(dev, "part id %#x is not supported\n", sdw_device->id.part_id); |
| 1227 |
return NULL; |
| 1228 |
} |
| 1229 |
|
| 1230 |
adr_dev[index].adr = ((u64)sdw_device->id.class_id & 0xFF) | |
| 1231 |
((u64)sdw_device->id.part_id & 0xFFFF) << 8 | |
| 1232 |
((u64)sdw_device->id.mfg_id & 0xFFFF) << 24 | |
| 1233 |
((u64)(sdw_device->id.unique_id & 0xF) << 40) | |
| 1234 |
((u64)(sdw_device->id.sdw_version & 0xF) << 44) | |
| 1235 |
((u64)(sdw_device->bus->link_id & 0xF) << 48); |
| 1236 |
|
| 1237 |
if (!is_amp) { |
| 1238 |
/* For non-amp codecs, get name_prefix from codec_info_list[] */ |
| 1239 |
adr_dev[index].name_prefix = devm_kasprintf(dev, GFP_KERNEL, "%s", name_prefix); |
| 1240 |
goto done_name_prefix; |
| 1241 |
} |
| 1242 |
|
| 1243 |
/* |
| 1244 |
* The name_prefix comes from codec_info_list which has a name_prefix per codec. |
| 1245 |
* And we need to give a unique name_prefix for each amp and should be backwards |
| 1246 |
* compatible to the existing acpi match tables to not break existing UCMs. |
| 1247 |
* For the common name_prefix, we append the amp index to it. However, for the |
| 1248 |
* "Left" name_prefix, we convert the second amp name_prefix to "Right" and |
| 1249 |
* for the third and further amps, we set the name_prefix to "AMP<amp_index>". |
| 1250 |
*/ |
| 1251 |
if (!strcmp(name_prefix, "Left")) { |
| 1252 |
switch (*amp_index) { |
| 1253 |
case 1: |
| 1254 |
adr_dev[index].name_prefix = devm_kasprintf(dev, GFP_KERNEL, |
| 1255 |
"%s", "Left"); |
| 1256 |
break; |
| 1257 |
case 2: |
| 1258 |
adr_dev[index].name_prefix = devm_kasprintf(dev, GFP_KERNEL, |
| 1259 |
"%s", "Right"); |
| 1260 |
break; |
| 1261 |
default: |
| 1262 |
/* Set the name_fix to AMP<amp_index> if there are more than 2 amps */ |
| 1263 |
adr_dev[index].name_prefix = devm_kasprintf(dev, GFP_KERNEL, "%s%d", |
| 1264 |
"AMP", *amp_index); |
| 1265 |
break; |
| 1266 |
} |
| 1267 |
} else if (!strcmp(name_prefix, "AMP")) { |
| 1268 |
adr_dev[index].name_prefix = devm_kasprintf(dev, GFP_KERNEL, "%s%d", |
| 1269 |
name_prefix, |
| 1270 |
*amp_index); |
| 1271 |
} else { |
| 1272 |
/* |
| 1273 |
* The name_prefix will be the amp name if it is not "Left" or "AMP", set it to |
| 1274 |
* <name_prefix>-<amp_index> format. Like rt1320-1 |
| 1275 |
*/ |
| 1276 |
adr_dev[index].name_prefix = devm_kasprintf(dev, GFP_KERNEL, "%s-%d", |
| 1277 |
name_prefix, |
| 1278 |
*amp_index); |
| 1279 |
} |
| 1280 |
(*amp_index)++; |
| 1281 |
|
| 1282 |
done_name_prefix: |
| 1283 |
if (!adr_dev[index].name_prefix) { |
| 1284 |
dev_err(dev, "failed to allocate memory for name_prefix\n"); |
| 1285 |
return NULL; |
| 1286 |
} |
| 1287 |
|
| 1288 |
dev_dbg(dev, "adr[%d] 0x%llx link id %d name_prefix \"%s\" is found\n", |
| 1289 |
index, adr_dev[index].adr, sdw_device->bus->link_id, adr_dev[index].name_prefix); |
| 1290 |
|
| 1291 |
link->num_adr++; |
| 1292 |
|
| 1293 |
return adr_dev; |
| 1294 |
} |
| 1295 |
|
| 1296 |
static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev) |
| 1297 |
{ |
| 1298 |
struct snd_sof_pdata *pdata = sdev->pdata; |
| 1299 |
const struct snd_soc_acpi_link_adr *link; |
| 1300 |
const struct sof_intel_dsp_desc *chip; |
| 1301 |
struct snd_soc_acpi_link_adr *links; |
| 1302 |
struct sdw_peripherals *peripherals; |
| 1303 |
struct snd_soc_acpi_mach *mach; |
| 1304 |
struct sof_intel_hda_dev *hdev; |
| 1305 |
int link_index, link_num; |
| 1306 |
int amp_index = 1; |
| 1307 |
u32 link_mask = 0; |
| 1308 |
int i; |
| 1309 |
|
| 1310 |
hdev = pdata->hw_pdata; |
| 1311 |
|
| 1312 |
if (!hdev->info.link_mask) { |
| 1313 |
dev_info(sdev->dev, "SoundWire links not enabled\n"); |
| 1314 |
return NULL; |
| 1315 |
} |
| 1316 |
|
| 1317 |
if (!hdev->sdw) { |
| 1318 |
dev_dbg(sdev->dev, "SoundWire context not allocated\n"); |
| 1319 |
return NULL; |
| 1320 |
} |
| 1321 |
|
| 1322 |
if (!hdev->sdw->peripherals || !hdev->sdw->peripherals->num_peripherals) { |
| 1323 |
dev_warn(sdev->dev, "No SoundWire peripheral detected in ACPI tables\n"); |
| 1324 |
return NULL; |
| 1325 |
} |
| 1326 |
|
| 1327 |
/* |
| 1328 |
* Select SoundWire machine driver if needed using the |
| 1329 |
* alternate tables. This case deals with SoundWire-only |
| 1330 |
* machines, for mixed cases with I2C/I2S the detection relies |
| 1331 |
* on the HID list. |
| 1332 |
*/ |
| 1333 |
for (mach = pdata->desc->alt_machines; |
| 1334 |
mach && mach->link_mask; mach++) { |
| 1335 |
/* |
| 1336 |
* On some platforms such as Up Extreme all links |
| 1337 |
* are enabled but only one link can be used by |
| 1338 |
* external codec. Instead of exact match of two masks, |
| 1339 |
* first check whether link_mask of mach is subset of |
| 1340 |
* link_mask supported by hw and then go on searching |
| 1341 |
* link_adr |
| 1342 |
*/ |
| 1343 |
if (~hdev->info.link_mask & mach->link_mask) |
| 1344 |
continue; |
| 1345 |
|
| 1346 |
/* No need to match adr if there is no links defined */ |
| 1347 |
if (!mach->links) |
| 1348 |
break; |
| 1349 |
|
| 1350 |
link = mach->links; |
| 1351 |
for (i = 0; i < hdev->info.count && link->num_adr; |
| 1352 |
i++, link++) { |
| 1353 |
/* |
| 1354 |
* Try next machine if any expected Slaves |
| 1355 |
* are not found on this link. |
| 1356 |
*/ |
| 1357 |
if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link, |
| 1358 |
hdev->sdw->peripherals)) |
| 1359 |
break; |
| 1360 |
} |
| 1361 |
/* Found if all Slaves are checked */ |
| 1362 |
if (i == hdev->info.count || !link->num_adr) |
| 1363 |
if (!mach->machine_check || mach->machine_check(hdev->sdw)) |
| 1364 |
break; |
| 1365 |
} |
| 1366 |
if (mach && mach->link_mask) { |
| 1367 |
mach->mach_params.links = mach->links; |
| 1368 |
mach->mach_params.link_mask = mach->link_mask; |
| 1369 |
mach->mach_params.platform = dev_name(sdev->dev); |
| 1370 |
|
| 1371 |
return mach; |
| 1372 |
} |
| 1373 |
|
| 1374 |
dev_info(sdev->dev, "No SoundWire machine driver found for the ACPI-reported configuration:\n"); |
| 1375 |
peripherals = hdev->sdw->peripherals; |
| 1376 |
for (i = 0; i < peripherals->num_peripherals; i++) |
| 1377 |
dev_info(sdev->dev, "link %d mfg_id 0x%04x part_id 0x%04x version %#x\n", |
| 1378 |
peripherals->array[i]->bus->link_id, |
| 1379 |
peripherals->array[i]->id.mfg_id, |
| 1380 |
peripherals->array[i]->id.part_id, |
| 1381 |
peripherals->array[i]->id.sdw_version); |
| 1382 |
|
| 1383 |
chip = get_chip_info(sdev->pdata); |
| 1384 |
|
| 1385 |
/* SDCA was not well supported in the BIOS before ACE2.0 */ |
| 1386 |
if (chip->hw_ip_version < SOF_INTEL_ACE_2_0) |
| 1387 |
return NULL; |
| 1388 |
|
| 1389 |
if (!peripherals->num_peripherals) |
| 1390 |
return NULL; |
| 1391 |
|
| 1392 |
/* Create default SDW mach */ |
| 1393 |
mach = devm_kzalloc(sdev->dev, sizeof(*mach), GFP_KERNEL); |
| 1394 |
if (!mach) |
| 1395 |
return NULL; |
| 1396 |
|
| 1397 |
/* Get link mask and link number */ |
| 1398 |
for (i = 0; i < peripherals->num_peripherals; i++) |
| 1399 |
link_mask |= BIT(peripherals->array[i]->bus->link_id); |
| 1400 |
|
| 1401 |
link_num = hweight32(link_mask); |
| 1402 |
/* An empty adr_link is needed to terminate the adr_link loop */ |
| 1403 |
links = devm_kcalloc(sdev->dev, link_num + 1, sizeof(*links), GFP_KERNEL); |
| 1404 |
if (!links) |
| 1405 |
return NULL; |
| 1406 |
|
| 1407 |
/* Generate snd_soc_acpi_link_adr struct for each peripheral reported by the ACPI table */ |
| 1408 |
for (i = 0; i < peripherals->num_peripherals; i++) { |
| 1409 |
/* link_index = the number of used links below the current link */ |
| 1410 |
link_index = hweight32(link_mask & (BIT(peripherals->array[i]->bus->link_id) - 1)); |
| 1411 |
links[link_index].adr_d = find_acpi_adr_device(sdev->dev, peripherals->array[i], |
| 1412 |
&links[link_index], &_index); |
| 1413 |
if (!links[link_index].adr_d) |
| 1414 |
return NULL; |
| 1415 |
} |
| 1416 |
|
| 1417 |
mach->drv_name = "sof_sdw"; |
| 1418 |
mach->mach_params.links = links; |
| 1419 |
mach->mach_params.link_mask = link_mask; |
| 1420 |
mach->mach_params.platform = dev_name(sdev->dev); |
| 1421 |
mach->get_function_tplg_files = sof_sdw_get_tplg_files; |
| 1422 |
/* |
| 1423 |
* Set mach->sof_tplg_filename as a dummy topology to avoid tplg file checking |
| 1424 |
* and being used. |
| 1425 |
*/ |
| 1426 |
mach->sof_tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 1427 |
"sof-%s-dummy.tplg", chip->platform); |
| 1428 |
|
| 1429 |
dev_info(sdev->dev, "Use SoundWire default machine driver with function topologies\n"); |
| 1430 |
return mach; |
| 1431 |
} |
| 1432 |
#else |
| 1433 |
static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev) |
| 1434 |
{ |
| 1435 |
return NULL; |
| 1436 |
} |
| 1437 |
#endif |
| 1438 |
|
| 1439 |
void hda_set_mach_params(struct snd_soc_acpi_mach *mach, |
| 1440 |
struct snd_sof_dev *sdev) |
| 1441 |
{ |
| 1442 |
struct snd_sof_pdata *pdata = sdev->pdata; |
| 1443 |
const struct sof_dev_desc *desc = pdata->desc; |
| 1444 |
struct snd_soc_acpi_mach_params *mach_params; |
| 1445 |
|
| 1446 |
mach_params = &mach->mach_params; |
| 1447 |
mach_params->platform = dev_name(sdev->dev); |
| 1448 |
if (IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC_DEBUG_SUPPORT) && |
| 1449 |
sof_debug_check_flag(SOF_DBG_FORCE_NOCODEC)) |
| 1450 |
mach_params->num_dai_drivers = SOF_SKL_NUM_DAIS_NOCODEC; |
| 1451 |
else |
| 1452 |
mach_params->num_dai_drivers = desc->ops->num_drv; |
| 1453 |
mach_params->dai_drivers = desc->ops->drv; |
| 1454 |
} |
| 1455 |
|
| 1456 |
static int check_tplg_quirk_mask(struct snd_soc_acpi_mach *mach) |
| 1457 |
{ |
| 1458 |
u32 dmic_ssp_quirk; |
| 1459 |
u32 codec_amp_name_quirk; |
| 1460 |
|
| 1461 |
/* |
| 1462 |
* In current implementation dmic and ssp quirks are designed for es8336 |
| 1463 |
* machine driver and could not be mixed with codec name and amp name |
| 1464 |
* quirks. |
| 1465 |
*/ |
| 1466 |
dmic_ssp_quirk = mach->tplg_quirk_mask & |
| 1467 |
(SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER | SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER); |
| 1468 |
codec_amp_name_quirk = mach->tplg_quirk_mask & |
| 1469 |
(SND_SOC_ACPI_TPLG_INTEL_AMP_NAME | SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME); |
| 1470 |
|
| 1471 |
if (dmic_ssp_quirk && codec_amp_name_quirk) |
| 1472 |
return -EINVAL; |
| 1473 |
|
| 1474 |
return 0; |
| 1475 |
} |
| 1476 |
|
| 1477 |
static char *remove_file_ext(struct device *dev, const char *tplg_filename) |
| 1478 |
{ |
| 1479 |
char *filename, *tmp; |
| 1480 |
|
| 1481 |
filename = devm_kstrdup(dev, tplg_filename, GFP_KERNEL); |
| 1482 |
if (!filename) |
| 1483 |
return NULL; |
| 1484 |
|
| 1485 |
/* remove file extension if exist */ |
| 1486 |
tmp = filename; |
| 1487 |
return strsep(&tmp, "."); |
| 1488 |
} |
| 1489 |
|
| 1490 |
struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev) |
| 1491 |
{ |
| 1492 |
u32 interface_mask = hda_get_interface_mask(sdev); |
| 1493 |
struct snd_sof_pdata *sof_pdata = sdev->pdata; |
| 1494 |
const struct sof_dev_desc *desc = sof_pdata->desc; |
| 1495 |
struct hdac_bus *bus = sof_to_bus(sdev); |
| 1496 |
struct snd_soc_acpi_mach *mach = NULL; |
| 1497 |
enum snd_soc_acpi_intel_codec codec_type, amp_type; |
| 1498 |
const char *tplg_filename; |
| 1499 |
const char *tplg_suffix; |
| 1500 |
bool amp_name_valid; |
| 1501 |
bool i2s_mach_found = false; |
| 1502 |
bool sdw_mach_found = false; |
| 1503 |
|
| 1504 |
/* Try I2S or DMIC if it is supported */ |
| 1505 |
if (interface_mask & (BIT(SOF_DAI_INTEL_SSP) | BIT(SOF_DAI_INTEL_DMIC))) { |
| 1506 |
mach = snd_soc_acpi_find_machine(desc->machines); |
| 1507 |
if (mach) |
| 1508 |
i2s_mach_found = true; |
| 1509 |
} |
| 1510 |
|
| 1511 |
/* |
| 1512 |
* If I2S fails and no external HDaudio codec is detected, |
| 1513 |
* try SoundWire if it is supported |
| 1514 |
*/ |
| 1515 |
if (!mach && !HDA_EXT_CODEC(bus->codec_mask) && |
| 1516 |
(interface_mask & BIT(SOF_DAI_INTEL_ALH))) { |
| 1517 |
mach = hda_sdw_machine_select(sdev); |
| 1518 |
if (mach) |
| 1519 |
sdw_mach_found = true; |
| 1520 |
} |
| 1521 |
|
| 1522 |
/* |
| 1523 |
* Choose HDA generic machine driver if mach is NULL. |
| 1524 |
* Otherwise, set certain mach params. |
| 1525 |
*/ |
| 1526 |
hda_generic_machine_select(sdev, &mach); |
| 1527 |
if (!mach) { |
| 1528 |
dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n"); |
| 1529 |
return NULL; |
| 1530 |
} |
| 1531 |
|
| 1532 |
/* report BT offload link mask to machine driver */ |
| 1533 |
mach->mach_params.bt_link_mask = check_nhlt_ssp_mask(sdev, NHLT_DEVICE_BT); |
| 1534 |
|
| 1535 |
dev_info(sdev->dev, "BT link detected in NHLT tables: %#x\n", |
| 1536 |
mach->mach_params.bt_link_mask); |
| 1537 |
|
| 1538 |
/* allow for module parameter override */ |
| 1539 |
if (bt_link_mask_override != -1) { |
| 1540 |
dev_dbg(sdev->dev, "overriding BT link detected in NHLT tables %#x by kernel param %#x\n", |
| 1541 |
mach->mach_params.bt_link_mask, bt_link_mask_override); |
| 1542 |
mach->mach_params.bt_link_mask = bt_link_mask_override; |
| 1543 |
} |
| 1544 |
|
| 1545 |
if (hweight_long(mach->mach_params.bt_link_mask) > 1) { |
| 1546 |
dev_warn(sdev->dev, "invalid BT link mask %#x found, reset the mask\n", |
| 1547 |
mach->mach_params.bt_link_mask); |
| 1548 |
mach->mach_params.bt_link_mask = 0; |
| 1549 |
} |
| 1550 |
|
| 1551 |
/* |
| 1552 |
* Fixup tplg file name by appending dmic num, ssp num, codec/amplifier |
| 1553 |
* name string if quirk flag is set. |
| 1554 |
*/ |
| 1555 |
if (mach) { |
| 1556 |
const struct sof_intel_dsp_desc *chip = get_chip_info(sdev->pdata); |
| 1557 |
bool tplg_fixup = false; |
| 1558 |
bool dmic_fixup = false; |
| 1559 |
|
| 1560 |
/* |
| 1561 |
* If tplg file name is overridden, use it instead of |
| 1562 |
* the one set in mach table |
| 1563 |
*/ |
| 1564 |
if (!sof_pdata->tplg_filename) { |
| 1565 |
/* remove file extension if it exists */ |
| 1566 |
tplg_filename = remove_file_ext(sdev->dev, mach->sof_tplg_filename); |
| 1567 |
if (!tplg_filename) |
| 1568 |
return NULL; |
| 1569 |
|
| 1570 |
sof_pdata->tplg_filename = tplg_filename; |
| 1571 |
tplg_fixup = true; |
| 1572 |
} |
| 1573 |
|
| 1574 |
/* |
| 1575 |
* Checking quirk mask integrity; some quirk flags could not be |
| 1576 |
* set concurrently. |
| 1577 |
*/ |
| 1578 |
if (tplg_fixup && |
| 1579 |
check_tplg_quirk_mask(mach)) { |
| 1580 |
dev_err(sdev->dev, "Invalid tplg quirk mask 0x%x\n", |
| 1581 |
mach->tplg_quirk_mask); |
| 1582 |
return NULL; |
| 1583 |
} |
| 1584 |
|
| 1585 |
/* report to machine driver if any DMICs are found */ |
| 1586 |
mach->mach_params.dmic_num = check_dmic_num(sdev); |
| 1587 |
|
| 1588 |
if (sdw_mach_found || mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER) |
| 1589 |
dmic_fixup = true; |
| 1590 |
|
| 1591 |
if (tplg_fixup && |
| 1592 |
dmic_fixup && |
| 1593 |
mach->mach_params.dmic_num) { |
| 1594 |
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 1595 |
"%s%s%d%s", |
| 1596 |
sof_pdata->tplg_filename, |
| 1597 |
i2s_mach_found ? "-dmic" : "-", |
| 1598 |
mach->mach_params.dmic_num, |
| 1599 |
"ch"); |
| 1600 |
if (!tplg_filename) |
| 1601 |
return NULL; |
| 1602 |
|
| 1603 |
sof_pdata->tplg_filename = tplg_filename; |
| 1604 |
} |
| 1605 |
|
| 1606 |
if (tplg_fixup && mach->mach_params.bt_link_mask && |
| 1607 |
chip->hw_ip_version >= SOF_INTEL_ACE_4_0) { |
| 1608 |
int bt_port = fls(mach->mach_params.bt_link_mask) - 1; |
| 1609 |
|
| 1610 |
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, "%s-ssp%d-bt", |
| 1611 |
sof_pdata->tplg_filename, bt_port); |
| 1612 |
if (!tplg_filename) |
| 1613 |
return NULL; |
| 1614 |
|
| 1615 |
sof_pdata->tplg_filename = tplg_filename; |
| 1616 |
} |
| 1617 |
|
| 1618 |
if (mach->link_mask) { |
| 1619 |
mach->mach_params.links = mach->links; |
| 1620 |
mach->mach_params.link_mask = mach->link_mask; |
| 1621 |
} |
| 1622 |
|
| 1623 |
/* report SSP link mask to machine driver */ |
| 1624 |
mach->mach_params.i2s_link_mask = check_nhlt_ssp_mask(sdev, NHLT_DEVICE_I2S); |
| 1625 |
|
| 1626 |
if (tplg_fixup && |
| 1627 |
mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER && |
| 1628 |
mach->mach_params.i2s_link_mask) { |
| 1629 |
int ssp_num; |
| 1630 |
|
| 1631 |
if (hweight_long(mach->mach_params.i2s_link_mask) > 1 && |
| 1632 |
!(mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_MSB)) |
| 1633 |
dev_warn(sdev->dev, "More than one SSP exposed by NHLT, choosing MSB\n"); |
| 1634 |
|
| 1635 |
/* fls returns 1-based results, SSPs indices are 0-based */ |
| 1636 |
ssp_num = fls(mach->mach_params.i2s_link_mask) - 1; |
| 1637 |
|
| 1638 |
if (ssp_num >= chip->ssp_count) { |
| 1639 |
dev_err(sdev->dev, "Invalid SSP %d, max on this platform is %d\n", |
| 1640 |
ssp_num, chip->ssp_count); |
| 1641 |
return NULL; |
| 1642 |
} |
| 1643 |
|
| 1644 |
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 1645 |
"%s%s%d", |
| 1646 |
sof_pdata->tplg_filename, |
| 1647 |
"-ssp", |
| 1648 |
ssp_num); |
| 1649 |
if (!tplg_filename) |
| 1650 |
return NULL; |
| 1651 |
|
| 1652 |
sof_pdata->tplg_filename = tplg_filename; |
| 1653 |
|
| 1654 |
if (sof_pdata->ipc_type == SOF_IPC_TYPE_3) { |
| 1655 |
int mclk_mask = check_nhlt_ssp_mclk_mask(sdev, |
| 1656 |
ssp_num); |
| 1657 |
|
| 1658 |
if (mclk_mask < 0) { |
| 1659 |
dev_err(sdev->dev, |
| 1660 |
"Invalid MCLK configuration for SSP%d\n", |
| 1661 |
ssp_num); |
| 1662 |
return NULL; |
| 1663 |
} |
| 1664 |
|
| 1665 |
if (mclk_mask) { |
| 1666 |
sdev->mclk_id_override = true; |
| 1667 |
sdev->mclk_id_quirk = (mclk_mask & BIT(0)) ? 0 : 1; |
| 1668 |
dev_info(sdev->dev, |
| 1669 |
"SSP%d to use MCLK id %d (mask: %#x)\n", |
| 1670 |
ssp_num, sdev->mclk_id_quirk, mclk_mask); |
| 1671 |
} else { |
| 1672 |
dev_dbg(sdev->dev, |
| 1673 |
"MCLK mask is empty for SSP%d in NHLT\n", |
| 1674 |
ssp_num); |
| 1675 |
} |
| 1676 |
} |
| 1677 |
} |
| 1678 |
|
| 1679 |
amp_type = snd_soc_acpi_intel_detect_amp_type(sdev->dev); |
| 1680 |
codec_type = snd_soc_acpi_intel_detect_codec_type(sdev->dev); |
| 1681 |
amp_name_valid = amp_type != CODEC_NONE && amp_type != codec_type; |
| 1682 |
|
| 1683 |
if (tplg_fixup && amp_name_valid && |
| 1684 |
mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_AMP_NAME) { |
| 1685 |
tplg_suffix = snd_soc_acpi_intel_get_amp_tplg_suffix(amp_type); |
| 1686 |
if (!tplg_suffix) { |
| 1687 |
dev_err(sdev->dev, "no tplg suffix found, amp %d\n", |
| 1688 |
amp_type); |
| 1689 |
return NULL; |
| 1690 |
} |
| 1691 |
|
| 1692 |
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 1693 |
"%s-%s", |
| 1694 |
sof_pdata->tplg_filename, |
| 1695 |
tplg_suffix); |
| 1696 |
if (!tplg_filename) |
| 1697 |
return NULL; |
| 1698 |
|
| 1699 |
sof_pdata->tplg_filename = tplg_filename; |
| 1700 |
} |
| 1701 |
|
| 1702 |
|
| 1703 |
if (tplg_fixup && |
| 1704 |
mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME && |
| 1705 |
codec_type != CODEC_NONE) { |
| 1706 |
tplg_suffix = snd_soc_acpi_intel_get_codec_tplg_suffix(codec_type); |
| 1707 |
if (!tplg_suffix) { |
| 1708 |
dev_err(sdev->dev, "no tplg suffix found, codec %d\n", |
| 1709 |
codec_type); |
| 1710 |
return NULL; |
| 1711 |
} |
| 1712 |
|
| 1713 |
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 1714 |
"%s-%s", |
| 1715 |
sof_pdata->tplg_filename, |
| 1716 |
tplg_suffix); |
| 1717 |
if (!tplg_filename) |
| 1718 |
return NULL; |
| 1719 |
|
| 1720 |
sof_pdata->tplg_filename = tplg_filename; |
| 1721 |
} |
| 1722 |
|
| 1723 |
if (tplg_fixup) { |
| 1724 |
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 1725 |
"%s%s", |
| 1726 |
sof_pdata->tplg_filename, |
| 1727 |
".tplg"); |
| 1728 |
if (!tplg_filename) |
| 1729 |
return NULL; |
| 1730 |
|
| 1731 |
sof_pdata->tplg_filename = tplg_filename; |
| 1732 |
} |
| 1733 |
|
| 1734 |
/* check if mclk_id should be modified from topology defaults */ |
| 1735 |
if (mclk_id_override >= 0) { |
| 1736 |
dev_info(sdev->dev, "Overriding topology with MCLK %d from kernel_parameter\n", mclk_id_override); |
| 1737 |
sdev->mclk_id_override = true; |
| 1738 |
sdev->mclk_id_quirk = mclk_id_override; |
| 1739 |
} |
| 1740 |
} |
| 1741 |
|
| 1742 |
return mach; |
| 1743 |
} |
| 1744 |
|
| 1745 |
int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) |
| 1746 |
{ |
| 1747 |
int ret; |
| 1748 |
|
| 1749 |
ret = snd_intel_dsp_driver_probe(pci); |
| 1750 |
if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) { |
| 1751 |
dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n"); |
| 1752 |
return -ENODEV; |
| 1753 |
} |
| 1754 |
|
| 1755 |
return sof_pci_probe(pci, pci_id); |
| 1756 |
} |
| 1757 |
EXPORT_SYMBOL_NS(hda_pci_intel_probe, "SND_SOC_SOF_INTEL_HDA_GENERIC"); |
| 1758 |
|
| 1759 |
int hda_register_clients(struct snd_sof_dev *sdev) |
| 1760 |
{ |
| 1761 |
return hda_probes_register(sdev); |
| 1762 |
} |
| 1763 |
|
| 1764 |
void hda_unregister_clients(struct snd_sof_dev *sdev) |
| 1765 |
{ |
| 1766 |
hda_probes_unregister(sdev); |
| 1767 |
} |
| 1768 |
|
| 1769 |
MODULE_LICENSE("Dual BSD/GPL"); |
| 1770 |
MODULE_DESCRIPTION("SOF support for HDaudio platforms"); |
| 1771 |
MODULE_IMPORT_NS("SND_SOC_SOF_PCI_DEV"); |
| 1772 |
MODULE_IMPORT_NS("SND_SOC_SOF_HDA_AUDIO_CODEC"); |
| 1773 |
MODULE_IMPORT_NS("SND_SOC_SOF_HDA_AUDIO_CODEC_I915"); |
| 1774 |
MODULE_IMPORT_NS("SND_SOC_SOF_XTENSA"); |
| 1775 |
MODULE_IMPORT_NS("SND_INTEL_SOUNDWIRE_ACPI"); |
| 1776 |
MODULE_IMPORT_NS("SOUNDWIRE_INTEL_INIT"); |
| 1777 |
MODULE_IMPORT_NS("SOUNDWIRE_INTEL"); |
| 1778 |
MODULE_IMPORT_NS("SND_SOC_SDW_UTILS"); |
| 1779 |
MODULE_IMPORT_NS("SND_SOC_SOF_HDA_MLINK"); |
| 1780 |
MODULE_IMPORT_NS("SND_SOC_SOF_INTEL_HDA_COMMON"); |
| 1781 |
MODULE_IMPORT_NS("SND_SOC_ACPI_INTEL_MATCH"); |