// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) // // This file is provided under a dual BSD/GPLv2 license. When using or // redistributing this file, you may do so under either license. // // Copyright(c) 2018 Intel Corporation // // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com> // Ranjani Sridharan <ranjani.sridharan@linux.intel.com> // Rander Wang <rander.wang@intel.com> // Keyon Jie <yang.jie@linux.intel.com> //
/* * Hardware interface for generic Intel audio DSP HDA IP
*/
/* * The default for SoundWire clock stop quirks is to power gate the IP * and do a Bus Reset, this will need to be modified when the DSP * needs to remain in D0i3 so that the Master does not lose context * and enumeration is not required on clock restart
*/ staticint sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET;
module_param(sdw_clock_stop_quirks, int, 0444);
MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks");
chip = get_chip_info(sdev->pdata); if (chip->hw_ip_version < SOF_INTEL_ACE_2_0) {
res.mmio_base = sdev->bar[HDA_DSP_BAR];
res.hw_ops = &sdw_intel_cnl_hw_ops;
res.shim_base = hdev->desc->sdw_shim_base;
res.alh_base = hdev->desc->sdw_alh_base;
res.ext = false;
res.ops = &sdw_callback;
} else { /* * retrieve eml_lock needed to protect shared registers * in the HDaudio multi-link areas
*/
res.eml_lock = hdac_bus_eml_get_mutex(sof_to_bus(sdev), true,
AZX_REG_ML_LEPTR_ID_SDW); if (!res.eml_lock) return -ENODEV;
res.mmio_base = sdev->bar[HDA_DSP_HDA_BAR]; /* * the SHIM and SoundWire register offsets are link-specific * and will be determined when adding auxiliary devices
*/
res.hw_ops = &sdw_intel_lnl_hw_ops;
res.ext = true;
res.ops = &sdw_ace2x_callback;
/* pre fw run operations */ int hda_dsp_pre_fw_run(struct snd_sof_dev *sdev)
{ /* disable clock gating and power gating */ return hda_dsp_ctrl_clock_power_gating(sdev, false);
}
/* post fw run operations */ int hda_dsp_post_fw_run(struct snd_sof_dev *sdev)
{ int ret;
if (sdev->first_boot) { struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
ret = hda_sdw_startup(sdev); if (ret < 0) {
dev_err(sdev->dev, "error: could not startup SoundWire links\n"); return ret;
}
/* Check if IMR boot is usable */ if (!sof_debug_check_flag(SOF_DBG_IGNORE_D3_PERSISTENT) &&
(sdev->fw_ready.flags & SOF_IPC_INFO_D3_PERSISTENT ||
sdev->pdata->ipc_type == SOF_IPC_TYPE_4)) {
hdev->imrboot_supported = true;
debugfs_create_bool("skip_imr_boot",
0644, sdev->debugfs_root,
&hdev->skip_imr_boot);
}
}
hda_sdw_int_enable(sdev, true);
/* re-enable clock gating and power gating */ return hda_dsp_ctrl_clock_power_gating(sdev, true);
}
EXPORT_SYMBOL_NS(hda_dsp_post_fw_run, "SND_SOC_SOF_INTEL_HDA_GENERIC");
/* HDA base */
sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
/* init i915 and HDMI codecs */
ret = hda_codec_i915_init(sdev); if (ret < 0 && ret != -ENODEV) {
dev_err_probe(sdev->dev, ret, "init of i915 and HDMI codec failed\n"); goto out;
}
/* get controller capabilities */
ret = hda_dsp_ctrl_get_caps(sdev); if (ret < 0) {
dev_err(sdev->dev, "error: get caps error\n");
hda_codec_i915_exit(sdev);
}
out: if (ret < 0)
iounmap(sof_to_bus(sdev)->remap_addr);
/* check if dsp is there */ if (bus->ppcap)
dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n");
/* Init HDA controller after i915 init */
ret = hda_dsp_ctrl_init_chip(sdev); if (ret < 0) {
dev_err(bus->dev, "error: init chip failed with ret: %d\n",
ret); return ret;
}
hda_bus_ml_init(bus);
/* Skip SoundWire if it is not supported */ if (!(interface_mask & BIT(SOF_DAI_INTEL_ALH))) goto skip_soundwire;
/* Skip SoundWire in nocodec mode */ if (IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC_DEBUG_SUPPORT) &&
sof_debug_check_flag(SOF_DBG_FORCE_NOCODEC)) goto skip_soundwire;
/* scan SoundWire capabilities exposed by DSDT */
ret = hda_sdw_acpi_scan(sdev); if (ret < 0) {
dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n"); goto skip_soundwire;
}
link_mask = hdev->info.link_mask; if (!link_mask) {
dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n"); goto skip_soundwire;
}
/* * probe/allocate SoundWire resources. * The hardware configuration takes place in hda_sdw_startup * after power rails are enabled. * It's entirely possible to have a mix of I2S/DMIC/SoundWire * devices, so we allocate the resources in all cases.
*/
ret = hda_sdw_probe(sdev); if (ret < 0) {
dev_err(sdev->dev, "error: SoundWire probe error\n"); return ret;
}
/* * Get global interrupt status. It includes all hardware interrupt * sources in the Intel HD Audio controller.
*/ if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) &
SOF_HDA_INTSTS_GIS) {
/* disable GIE interrupt */
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
SOF_HDA_INTCTL,
SOF_HDA_INT_GLOBAL_EN,
0);
/* deal with streams and controller first */ if (hda_dsp_check_stream_irq(sdev)) {
trace_sof_intel_hda_irq(sdev, "stream");
hda_dsp_stream_threaded_handler(irq, sdev);
}
if (hda_check_ipc_irq(sdev)) {
trace_sof_intel_hda_irq(sdev, "ipc");
sof_ops(sdev)->irq_thread(irq, sdev);
}
if (hda_dsp_check_sdw_irq(sdev)) {
trace_sof_intel_hda_irq(sdev, "sdw");
hda_dsp_sdw_thread(irq, hdev->sdw);
if (hda_dsp_sdw_check_mic_privacy_irq(sdev)) {
trace_sof_intel_hda_irq(sdev, "mic privacy");
hda_dsp_sdw_process_mic_privacy(sdev);
}
}
if (hda_sdw_check_wakeen_irq(sdev)) {
trace_sof_intel_hda_irq(sdev, "wakeen");
hda_sdw_process_wakeen(sdev);
}
hda_codec_check_for_state_change(sdev);
/* enable GIE interrupt */
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
SOF_HDA_INTCTL,
SOF_HDA_INT_GLOBAL_EN,
SOF_HDA_INT_GLOBAL_EN);
return IRQ_HANDLED;
}
int hda_dsp_probe_early(struct snd_sof_dev *sdev)
{ struct pci_dev *pci = to_pci_dev(sdev->dev); struct sof_intel_hda_dev *hdev; conststruct sof_intel_dsp_desc *chip; int ret = 0;
if (!sdev->dspless_mode_selected) { /* * detect DSP by checking class/subclass/prog-id information * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required * class=04 subclass 01 prog-if 00: DSP is present * (and may be required e.g. for DMIC or SSP support) * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works
*/ if (pci->class == 0x040300) {
dev_err(sdev->dev, "the DSP is not enabled on this platform, aborting probe\n"); return -ENODEV;
} elseif (pci->class != 0x040100 && pci->class != 0x040380) {
dev_err(sdev->dev, "unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n",
pci->class); return -ENODEV;
}
dev_info_once(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n",
pci->class);
}
chip = get_chip_info(sdev->pdata); if (!chip) {
dev_err(sdev->dev, "error: no such device supported, chip id:%x\n",
pci->device);
ret = -EIO; goto err;
}
sdev->num_cores = chip->cores_num;
hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL); if (!hdev) return -ENOMEM;
sdev->pdata->hw_pdata = hdev;
hdev->desc = chip;
ret = hda_init(sdev);
int hda_dsp_probe(struct snd_sof_dev *sdev)
{ struct pci_dev *pci = to_pci_dev(sdev->dev); struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; conststruct sof_intel_dsp_desc *chip; int ret = 0;
hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
PLATFORM_DEVID_NONE,
NULL, 0); if (IS_ERR(hdev->dmic_dev)) {
dev_err(sdev->dev, "error: failed to create DMIC device\n"); return PTR_ERR(hdev->dmic_dev);
}
/* * use position update IPC if either it is forced * or we don't have other choice
*/ #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION)
hdev->no_ipc_position = 0; #else
hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0; #endif
if (sdev->dspless_mode_selected)
hdev->no_ipc_position = 1;
if (sdev->dspless_mode_selected) goto skip_dsp_setup;
/* DSP base */
sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR); if (!sdev->bar[HDA_DSP_BAR]) {
dev_err(sdev->dev, "error: ioremap error\n");
ret = -ENXIO; goto hdac_bus_unmap;
}
/* allow 64bit DMA address if supported by H/W */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) {
dev_dbg(sdev->dev, "DMA mask is 32 bit\n");
dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32));
}
dma_set_max_seg_size(&pci->dev, UINT_MAX);
/* init streams */
ret = hda_dsp_stream_init(sdev); if (ret < 0) {
dev_err(sdev->dev, "error: failed to init streams\n"); /* * not all errors are due to memory issues, but trying * to free everything does not harm
*/ goto free_streams;
}
/* * register our IRQ * let's try to enable msi firstly * if it fails, use legacy interrupt mode * TODO: support msi multiple vectors
*/ if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) {
dev_info(sdev->dev, "use msi interrupt mode\n");
sdev->ipc_irq = pci_irq_vector(pci, 0); /* initialised to "false" by kzalloc() */
sdev->msi_enabled = true;
}
if (!sdev->msi_enabled) {
dev_info(sdev->dev, "use legacy interrupt mode\n"); /* * in IO-APIC mode, hda->irq and ipc_irq are using the same * irq number of pci->irq
*/
sdev->ipc_irq = pci->irq;
}
/* * clear TCSEL to clear playback on some HD Audio * codecs. PCI TCSEL is defined in the Intel manuals.
*/
snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
/* init HDA capabilities */
ret = hda_init_caps(sdev); if (ret < 0) goto free_ipc_irq;
chip = get_chip_info(sdev->pdata); if (chip && chip->hw_ip_version >= SOF_INTEL_ACE_2_0) {
ret = hda_sdw_startup(sdev); if (ret < 0) {
dev_err(sdev->dev, "could not startup SoundWire links\n"); goto disable_pp_cap;
}
}
init_waitqueue_head(&hdev->waitq);
hdev->nhlt = intel_nhlt_init(sdev->dev);
return 0;
disable_pp_cap: if (!sdev->dspless_mode_selected) {
hda_dsp_ctrl_ppcap_int_enable(sdev, false);
hda_dsp_ctrl_ppcap_enable(sdev, false);
}
free_ipc_irq:
free_irq(sdev->ipc_irq, sdev);
free_irq_vector: if (sdev->msi_enabled)
pci_free_irq_vectors(pci);
free_streams:
hda_dsp_stream_free(sdev); /* dsp_unmap: not currently used */ if (!sdev->dspless_mode_selected)
iounmap(sdev->bar[HDA_DSP_BAR]);
hdac_bus_unmap:
platform_device_unregister(hdev->dmic_dev);
/* Free the persistent DMA buffers used for base firmware download */ if (hda->cl_dmab.area)
snd_dma_free_pages(&hda->cl_dmab); if (hda->iccmax_dmab.area)
snd_dma_free_pages(&hda->iccmax_dmab);
skip_disable_dsp:
free_irq(sdev->ipc_irq, sdev); if (sdev->msi_enabled)
pci_free_irq_vectors(pci);
hda_dsp_stream_free(sdev);
hda_bus_ml_free(sof_to_bus(sdev));
if (!sdev->dspless_mode_selected)
iounmap(sdev->bar[HDA_DSP_BAR]);
}
EXPORT_SYMBOL_NS(hda_dsp_remove, "SND_SOC_SOF_INTEL_HDA_GENERIC");
for (i = 0; i < HDA_MAX_CODECS; i++) { if (bus->codec_mask & (1 << i))
codec_num++;
}
/* * If no machine driver is found, then: * * generic hda machine driver can handle: * - one HDMI codec, and/or * - one external HDAudio codec
*/ if (!*mach && codec_num <= 2) { bool tplg_fixup = false;
/* * make a local copy of the match array since we might * be modifying it
*/
hda_mach = devm_kmemdup_array(sdev->dev,
snd_soc_acpi_intel_hda_machines,
2, /* we have one entry + sentinel in the array */ sizeof(snd_soc_acpi_intel_hda_machines[0]),
GFP_KERNEL); if (!hda_mach) {
dev_err(bus->dev, "%s: failed to duplicate the HDA match table\n",
__func__); return;
}
/* * topology: use the info from hda_machines since tplg file name * is not overwritten
*/ if (!pdata->tplg_filename)
tplg_fixup = true;
if (tplg_fixup &&
codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask)) {
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, "%s-idisp",
hda_mach->sof_tplg_filename); if (!tplg_filename) return;
hda_mach->sof_tplg_filename = tplg_filename;
}
if (codec_num == 2 ||
(codec_num == 1 && !HDA_IDISP_CODEC(bus->codec_mask))) { /* * Prevent SoundWire links from starting when an external * HDaudio codec is used
*/
hda_mach->mach_params.link_mask = 0;
} else { /* * Allow SoundWire links to start when no external HDaudio codec * was detected. This will not create a SoundWire card but * will help detect if any SoundWire codec reports as ATTACHED.
*/ struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
if (!link_mask) {
dev_info(sdev->dev, "SoundWire links not enabled\n"); return NULL;
}
if (!hdev->sdw) {
dev_dbg(sdev->dev, "SoundWire context not allocated\n"); return NULL;
}
if (!hdev->sdw->peripherals || !hdev->sdw->peripherals->num_peripherals) {
dev_warn(sdev->dev, "No SoundWire peripheral detected in ACPI tables\n"); return NULL;
}
/* * Select SoundWire machine driver if needed using the * alternate tables. This case deals with SoundWire-only * machines, for mixed cases with I2C/I2S the detection relies * on the HID list.
*/ for (mach = pdata->desc->alt_machines;
mach && mach->link_mask; mach++) { /* * On some platforms such as Up Extreme all links * are enabled but only one link can be used by * external codec. Instead of exact match of two masks, * first check whether link_mask of mach is subset of * link_mask supported by hw and then go on searching * link_adr
*/ if (~link_mask & mach->link_mask) continue;
/* No need to match adr if there is no links defined */ if (!mach->links) break;
link = mach->links; for (i = 0; i < hdev->info.count && link->num_adr;
i++, link++) { /* * Try next machine if any expected Slaves * are not found on this link.
*/ if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link,
hdev->sdw->peripherals)) break;
} /* Found if all Slaves are checked */ if (i == hdev->info.count || !link->num_adr) if (!mach->machine_check || mach->machine_check(hdev->sdw)) break;
} if (mach && mach->link_mask) {
mach->mach_params.links = mach->links;
mach->mach_params.link_mask = mach->link_mask;
mach->mach_params.platform = dev_name(sdev->dev);
return mach;
}
dev_info(sdev->dev, "No SoundWire machine driver found for the ACPI-reported configuration:\n");
peripherals = hdev->sdw->peripherals; for (i = 0; i < peripherals->num_peripherals; i++)
dev_info(sdev->dev, "link %d mfg_id 0x%04x part_id 0x%04x version %#x\n",
peripherals->array[i]->bus->link_id,
peripherals->array[i]->id.mfg_id,
peripherals->array[i]->id.part_id,
peripherals->array[i]->id.sdw_version);
/* * In current implementation dmic and ssp quirks are designed for es8336 * machine driver and could not be mixed with codec name and amp name * quirks.
*/
dmic_ssp_quirk = mach->tplg_quirk_mask &
(SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER | SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER);
codec_amp_name_quirk = mach->tplg_quirk_mask &
(SND_SOC_ACPI_TPLG_INTEL_AMP_NAME | SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME);
if (dmic_ssp_quirk && codec_amp_name_quirk) return -EINVAL;
/* Try I2S or DMIC if it is supported */ if (interface_mask & (BIT(SOF_DAI_INTEL_SSP) | BIT(SOF_DAI_INTEL_DMIC))) {
mach = snd_soc_acpi_find_machine(desc->machines); if (mach)
i2s_mach_found = true;
}
/* * If I2S fails and no external HDaudio codec is detected, * try SoundWire if it is supported
*/ if (!mach && !HDA_EXT_CODEC(bus->codec_mask) &&
(interface_mask & BIT(SOF_DAI_INTEL_ALH))) {
mach = hda_sdw_machine_select(sdev); if (mach)
sdw_mach_found = true;
}
/* * Choose HDA generic machine driver if mach is NULL. * Otherwise, set certain mach params.
*/
hda_generic_machine_select(sdev, &mach); if (!mach) {
dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n"); return NULL;
}
/* report BT offload link mask to machine driver */
mach->mach_params.bt_link_mask = check_nhlt_ssp_mask(sdev, NHLT_DEVICE_BT);
dev_info(sdev->dev, "BT link detected in NHLT tables: %#x\n",
mach->mach_params.bt_link_mask);
/* allow for module parameter override */ if (bt_link_mask_override) {
dev_dbg(sdev->dev, "overriding BT link detected in NHLT tables %#x by kernel param %#x\n",
mach->mach_params.bt_link_mask, bt_link_mask_override);
mach->mach_params.bt_link_mask = bt_link_mask_override;
}
if (hweight_long(mach->mach_params.bt_link_mask) > 1) {
dev_warn(sdev->dev, "invalid BT link mask %#x found, reset the mask\n",
mach->mach_params.bt_link_mask);
mach->mach_params.bt_link_mask = 0;
}
/* * Fixup tplg file name by appending dmic num, ssp num, codec/amplifier * name string if quirk flag is set.
*/ if (mach) { bool tplg_fixup = false; bool dmic_fixup = false;
/* * If tplg file name is overridden, use it instead of * the one set in mach table
*/ if (!sof_pdata->tplg_filename) { /* remove file extension if it exists */
tplg_filename = remove_file_ext(sdev->dev, mach->sof_tplg_filename); if (!tplg_filename) return NULL;
if (mach->link_mask) {
mach->mach_params.links = mach->links;
mach->mach_params.link_mask = mach->link_mask;
}
/* report SSP link mask to machine driver */
mach->mach_params.i2s_link_mask = check_nhlt_ssp_mask(sdev, NHLT_DEVICE_I2S);
if (tplg_fixup &&
mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER &&
mach->mach_params.i2s_link_mask) { conststruct sof_intel_dsp_desc *chip = get_chip_info(sdev->pdata); int ssp_num; int mclk_mask;
if (hweight_long(mach->mach_params.i2s_link_mask) > 1 &&
!(mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_MSB))
dev_warn(sdev->dev, "More than one SSP exposed by NHLT, choosing MSB\n");
/* fls returns 1-based results, SSPs indices are 0-based */
ssp_num = fls(mach->mach_params.i2s_link_mask) - 1;
if (ssp_num >= chip->ssp_count) {
dev_err(sdev->dev, "Invalid SSP %d, max on this platform is %d\n",
ssp_num, chip->ssp_count); return NULL;
}
if (tplg_fixup) {
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, "%s%s",
sof_pdata->tplg_filename, ".tplg"); if (!tplg_filename) return NULL;
sof_pdata->tplg_filename = tplg_filename;
}
/* check if mclk_id should be modified from topology defaults */ if (mclk_id_override >= 0) {
dev_info(sdev->dev, "Overriding topology with MCLK %d from kernel_parameter\n", mclk_id_override);
sdev->mclk_id_override = true;
sdev->mclk_id_quirk = mclk_id_override;
}
}
return mach;
}
int hda_pci_intel_probe(struct pci_dev *pci, conststruct pci_device_id *pci_id)
{ int ret;
ret = snd_intel_dsp_driver_probe(pci); if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n"); return -ENODEV;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.