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) 2022 Advanced Micro Devices, Inc. 7 // 8 // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com> 9 // V sujith kumar Reddy <Vsujithkumar.Reddy@amd.com> 10 11 /* ACP-specific Common code */ 12 13 #include "../sof-priv.h" 14 #include "../sof-audio.h" 15 #include "../ops.h" 16 #include "../sof-audio.h" 17 #include "acp.h" 18 #include "acp-dsp-offset.h" 19 20 int acp_dai_probe(struct snd_soc_dai *dai) 21 { 22 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(dai->component); 23 const struct sof_amd_acp_desc *desc = get_chip_info(sdev->pdata); 24 unsigned int val; 25 26 val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, desc->i2s_pin_config_offset); 27 if (val != desc->i2s_mode) { 28 dev_err(sdev->dev, "I2S Mode is not supported (I2S_PIN_CONFIG: %#x)\n", val); 29 return -EINVAL; 30 } 31 32 return 0; 33 } 34 EXPORT_SYMBOL_NS(acp_dai_probe, SND_SOC_SOF_AMD_COMMON); 35 36 struct snd_soc_acpi_mach *amd_sof_machine_select(struct snd_sof_dev *sdev) 37 { 38 struct snd_sof_pdata *sof_pdata = sdev->pdata; 39 const struct sof_dev_desc *desc = sof_pdata->desc; 40 struct snd_soc_acpi_mach *mach; 41 42 mach = snd_soc_acpi_find_machine(desc->machines); 43 if (!mach) { 44 dev_warn(sdev->dev, "No matching ASoC machine driver found\n"); 45 return NULL; 46 } 47 48 sof_pdata->tplg_filename = mach->sof_tplg_filename; 49 sof_pdata->fw_filename = mach->fw_filename; 50 51 return mach; 52 } 53 54 /* AMD Common DSP ops */ 55 struct snd_sof_dsp_ops sof_acp_common_ops = { 56 /* probe and remove */ 57 .probe = amd_sof_acp_probe, 58 .remove = amd_sof_acp_remove, 59 60 /* Register IO */ 61 .write = sof_io_write, 62 .read = sof_io_read, 63 64 /* Block IO */ 65 .block_read = acp_dsp_block_read, 66 .block_write = acp_dsp_block_write, 67 68 /*Firmware loading */ 69 .load_firmware = snd_sof_load_firmware_memcpy, 70 .pre_fw_run = acp_dsp_pre_fw_run, 71 .get_bar_index = acp_get_bar_index, 72 73 /* DSP core boot */ 74 .run = acp_sof_dsp_run, 75 76 /*IPC */ 77 .send_msg = acp_sof_ipc_send_msg, 78 .ipc_msg_data = acp_sof_ipc_msg_data, 79 .get_mailbox_offset = acp_sof_ipc_get_mailbox_offset, 80 .get_window_offset = acp_sof_ipc_get_window_offset, 81 .irq_thread = acp_sof_ipc_irq_thread, 82 83 /* stream callbacks */ 84 .pcm_open = acp_pcm_open, 85 .pcm_close = acp_pcm_close, 86 .pcm_hw_params = acp_pcm_hw_params, 87 88 .hw_info = SNDRV_PCM_INFO_MMAP | 89 SNDRV_PCM_INFO_MMAP_VALID | 90 SNDRV_PCM_INFO_INTERLEAVED | 91 SNDRV_PCM_INFO_PAUSE | 92 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP, 93 94 /* Machine driver callbacks */ 95 .machine_select = amd_sof_machine_select, 96 .machine_register = sof_machine_register, 97 .machine_unregister = sof_machine_unregister, 98 99 /* Trace Logger */ 100 .trace_init = acp_sof_trace_init, 101 .trace_release = acp_sof_trace_release, 102 103 /* PM */ 104 .suspend = amd_sof_acp_suspend, 105 .resume = amd_sof_acp_resume, 106 }; 107 EXPORT_SYMBOL_NS(sof_acp_common_ops, SND_SOC_SOF_AMD_COMMON); 108 109 MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON); 110 MODULE_DESCRIPTION("ACP SOF COMMON Driver"); 111 MODULE_LICENSE("Dual BSD/GPL"); 112