1868bd00fSLiam Girdwood // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2868bd00fSLiam Girdwood // 3868bd00fSLiam Girdwood // This file is provided under a dual BSD/GPLv2 license. When using or 4868bd00fSLiam Girdwood // redistributing this file, you may do so under either license. 5868bd00fSLiam Girdwood // 6868bd00fSLiam Girdwood // Copyright(c) 2018 Intel Corporation. All rights reserved. 7868bd00fSLiam Girdwood // 8868bd00fSLiam Girdwood // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9868bd00fSLiam Girdwood // 10868bd00fSLiam Girdwood // PCM Layer, interface between ALSA and IPC. 11868bd00fSLiam Girdwood // 12868bd00fSLiam Girdwood 13868bd00fSLiam Girdwood #include <linux/pm_runtime.h> 14868bd00fSLiam Girdwood #include <sound/pcm_params.h> 15868bd00fSLiam Girdwood #include <sound/sof.h> 16868bd00fSLiam Girdwood #include "sof-priv.h" 17868bd00fSLiam Girdwood #include "ops.h" 18868bd00fSLiam Girdwood 19868bd00fSLiam Girdwood #define DRV_NAME "sof-audio-component" 20868bd00fSLiam Girdwood 21868bd00fSLiam Girdwood /* Create DMA buffer page table for DSP */ 22868bd00fSLiam Girdwood static int create_page_table(struct snd_pcm_substream *substream, 23868bd00fSLiam Girdwood unsigned char *dma_area, size_t size) 24868bd00fSLiam Girdwood { 25868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 26868bd00fSLiam Girdwood struct snd_soc_component *component = 27868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 28868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 29868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 30868bd00fSLiam Girdwood struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream); 31868bd00fSLiam Girdwood int stream = substream->stream; 32868bd00fSLiam Girdwood 33868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 34868bd00fSLiam Girdwood if (!spcm) 35868bd00fSLiam Girdwood return -EINVAL; 36868bd00fSLiam Girdwood 37868bd00fSLiam Girdwood return snd_sof_create_page_table(sdev, dmab, 38868bd00fSLiam Girdwood spcm->stream[stream].page_table.area, size); 39868bd00fSLiam Girdwood } 40868bd00fSLiam Girdwood 41868bd00fSLiam Girdwood static int sof_pcm_dsp_params(struct snd_sof_pcm *spcm, struct snd_pcm_substream *substream, 42868bd00fSLiam Girdwood const struct sof_ipc_pcm_params_reply *reply) 43868bd00fSLiam Girdwood { 44868bd00fSLiam Girdwood struct snd_sof_dev *sdev = spcm->sdev; 45868bd00fSLiam Girdwood /* validate offset */ 46868bd00fSLiam Girdwood int ret = snd_sof_ipc_pcm_params(sdev, substream, reply); 47868bd00fSLiam Girdwood 48868bd00fSLiam Girdwood if (ret < 0) 49868bd00fSLiam Girdwood dev_err(sdev->dev, "error: got wrong reply for PCM %d\n", 50868bd00fSLiam Girdwood spcm->pcm.pcm_id); 51868bd00fSLiam Girdwood 52868bd00fSLiam Girdwood return ret; 53868bd00fSLiam Girdwood } 54868bd00fSLiam Girdwood 55e2803e61SKeyon Jie /* 56e2803e61SKeyon Jie * sof pcm period elapse work 57e2803e61SKeyon Jie */ 58e2803e61SKeyon Jie static void sof_pcm_period_elapsed_work(struct work_struct *work) 59e2803e61SKeyon Jie { 60e2803e61SKeyon Jie struct snd_sof_pcm_stream *sps = 61e2803e61SKeyon Jie container_of(work, struct snd_sof_pcm_stream, 62e2803e61SKeyon Jie period_elapsed_work); 63e2803e61SKeyon Jie 64e2803e61SKeyon Jie snd_pcm_period_elapsed(sps->substream); 65e2803e61SKeyon Jie } 66e2803e61SKeyon Jie 67e2803e61SKeyon Jie /* 68e2803e61SKeyon Jie * sof pcm period elapse, this could be called at irq thread context. 69e2803e61SKeyon Jie */ 70e2803e61SKeyon Jie void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream) 71e2803e61SKeyon Jie { 72e2803e61SKeyon Jie struct snd_soc_pcm_runtime *rtd = substream->private_data; 73e2803e61SKeyon Jie struct snd_soc_component *component = 74e2803e61SKeyon Jie snd_soc_rtdcom_lookup(rtd, DRV_NAME); 75e2803e61SKeyon Jie struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 76e2803e61SKeyon Jie struct snd_sof_pcm *spcm; 77e2803e61SKeyon Jie 78e2803e61SKeyon Jie spcm = snd_sof_find_spcm_dai(sdev, rtd); 79e2803e61SKeyon Jie if (!spcm) { 80e2803e61SKeyon Jie dev_err(sdev->dev, 81e2803e61SKeyon Jie "error: period elapsed for unknown stream!\n"); 82e2803e61SKeyon Jie return; 83e2803e61SKeyon Jie } 84e2803e61SKeyon Jie 85e2803e61SKeyon Jie /* 86e2803e61SKeyon Jie * snd_pcm_period_elapsed() can be called in interrupt context 87e2803e61SKeyon Jie * before IRQ_HANDLED is returned. Inside snd_pcm_period_elapsed(), 88e2803e61SKeyon Jie * when the PCM is done draining or xrun happened, a STOP IPC will 89e2803e61SKeyon Jie * then be sent and this IPC will hit IPC timeout. 90e2803e61SKeyon Jie * To avoid sending IPC before the previous IPC is handled, we 91e2803e61SKeyon Jie * schedule delayed work here to call the snd_pcm_period_elapsed(). 92e2803e61SKeyon Jie */ 93e2803e61SKeyon Jie schedule_work(&spcm->stream[substream->stream].period_elapsed_work); 94e2803e61SKeyon Jie } 95e2803e61SKeyon Jie EXPORT_SYMBOL(snd_sof_pcm_period_elapsed); 96e2803e61SKeyon Jie 97868bd00fSLiam Girdwood /* this may get called several times by oss emulation */ 98868bd00fSLiam Girdwood static int sof_pcm_hw_params(struct snd_pcm_substream *substream, 99868bd00fSLiam Girdwood struct snd_pcm_hw_params *params) 100868bd00fSLiam Girdwood { 101868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 102868bd00fSLiam Girdwood struct snd_pcm_runtime *runtime = substream->runtime; 103868bd00fSLiam Girdwood struct snd_soc_component *component = 104868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 105868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 106868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 107868bd00fSLiam Girdwood struct sof_ipc_pcm_params pcm; 108868bd00fSLiam Girdwood struct sof_ipc_pcm_params_reply ipc_params_reply; 109868bd00fSLiam Girdwood int ret; 110868bd00fSLiam Girdwood 111868bd00fSLiam Girdwood /* nothing to do for BE */ 112868bd00fSLiam Girdwood if (rtd->dai_link->no_pcm) 113868bd00fSLiam Girdwood return 0; 114868bd00fSLiam Girdwood 115868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 116868bd00fSLiam Girdwood if (!spcm) 117868bd00fSLiam Girdwood return -EINVAL; 118868bd00fSLiam Girdwood 119868bd00fSLiam Girdwood dev_dbg(sdev->dev, "pcm: hw params stream %d dir %d\n", 120868bd00fSLiam Girdwood spcm->pcm.pcm_id, substream->stream); 121868bd00fSLiam Girdwood 122868bd00fSLiam Girdwood memset(&pcm, 0, sizeof(pcm)); 123868bd00fSLiam Girdwood 124868bd00fSLiam Girdwood /* allocate audio buffer pages */ 125868bd00fSLiam Girdwood ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); 126868bd00fSLiam Girdwood if (ret < 0) { 127868bd00fSLiam Girdwood dev_err(sdev->dev, "error: could not allocate %d bytes for PCM %d\n", 128868bd00fSLiam Girdwood params_buffer_bytes(params), spcm->pcm.pcm_id); 129868bd00fSLiam Girdwood return ret; 130868bd00fSLiam Girdwood } 131868bd00fSLiam Girdwood if (ret) { 132868bd00fSLiam Girdwood /* 133868bd00fSLiam Girdwood * ret == 1 means the buffer is changed 134868bd00fSLiam Girdwood * create compressed page table for audio firmware 135868bd00fSLiam Girdwood * ret == 0 means the buffer is not changed 136868bd00fSLiam Girdwood * so no need to regenerate the page table 137868bd00fSLiam Girdwood */ 138868bd00fSLiam Girdwood ret = create_page_table(substream, runtime->dma_area, 139868bd00fSLiam Girdwood runtime->dma_bytes); 140868bd00fSLiam Girdwood if (ret < 0) 141868bd00fSLiam Girdwood return ret; 142868bd00fSLiam Girdwood } 143868bd00fSLiam Girdwood 144868bd00fSLiam Girdwood /* number of pages should be rounded up */ 145868bd00fSLiam Girdwood pcm.params.buffer.pages = PFN_UP(runtime->dma_bytes); 146868bd00fSLiam Girdwood 147868bd00fSLiam Girdwood /* set IPC PCM parameters */ 148868bd00fSLiam Girdwood pcm.hdr.size = sizeof(pcm); 149868bd00fSLiam Girdwood pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS; 150868bd00fSLiam Girdwood pcm.comp_id = spcm->stream[substream->stream].comp_id; 151868bd00fSLiam Girdwood pcm.params.hdr.size = sizeof(pcm.params); 152868bd00fSLiam Girdwood pcm.params.buffer.phy_addr = 153868bd00fSLiam Girdwood spcm->stream[substream->stream].page_table.addr; 154868bd00fSLiam Girdwood pcm.params.buffer.size = runtime->dma_bytes; 155868bd00fSLiam Girdwood pcm.params.direction = substream->stream; 156868bd00fSLiam Girdwood pcm.params.sample_valid_bytes = params_width(params) >> 3; 157868bd00fSLiam Girdwood pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED; 158868bd00fSLiam Girdwood pcm.params.rate = params_rate(params); 159868bd00fSLiam Girdwood pcm.params.channels = params_channels(params); 160868bd00fSLiam Girdwood pcm.params.host_period_bytes = params_period_bytes(params); 161868bd00fSLiam Girdwood 162868bd00fSLiam Girdwood /* container size */ 163868bd00fSLiam Girdwood ret = snd_pcm_format_physical_width(params_format(params)); 164868bd00fSLiam Girdwood if (ret < 0) 165868bd00fSLiam Girdwood return ret; 166868bd00fSLiam Girdwood pcm.params.sample_container_bytes = ret >> 3; 167868bd00fSLiam Girdwood 168868bd00fSLiam Girdwood /* format */ 169868bd00fSLiam Girdwood switch (params_format(params)) { 170868bd00fSLiam Girdwood case SNDRV_PCM_FORMAT_S16: 171868bd00fSLiam Girdwood pcm.params.frame_fmt = SOF_IPC_FRAME_S16_LE; 172868bd00fSLiam Girdwood break; 173868bd00fSLiam Girdwood case SNDRV_PCM_FORMAT_S24: 174868bd00fSLiam Girdwood pcm.params.frame_fmt = SOF_IPC_FRAME_S24_4LE; 175868bd00fSLiam Girdwood break; 176868bd00fSLiam Girdwood case SNDRV_PCM_FORMAT_S32: 177868bd00fSLiam Girdwood pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE; 178868bd00fSLiam Girdwood break; 179868bd00fSLiam Girdwood case SNDRV_PCM_FORMAT_FLOAT: 180868bd00fSLiam Girdwood pcm.params.frame_fmt = SOF_IPC_FRAME_FLOAT; 181868bd00fSLiam Girdwood break; 182868bd00fSLiam Girdwood default: 183868bd00fSLiam Girdwood return -EINVAL; 184868bd00fSLiam Girdwood } 185868bd00fSLiam Girdwood 186868bd00fSLiam Girdwood /* firmware already configured host stream */ 187868bd00fSLiam Girdwood ret = snd_sof_pcm_platform_hw_params(sdev, 188868bd00fSLiam Girdwood substream, 189868bd00fSLiam Girdwood params, 190868bd00fSLiam Girdwood &pcm.params); 191868bd00fSLiam Girdwood if (ret < 0) { 192868bd00fSLiam Girdwood dev_err(sdev->dev, "error: platform hw params failed\n"); 193868bd00fSLiam Girdwood return ret; 194868bd00fSLiam Girdwood } 195868bd00fSLiam Girdwood 196868bd00fSLiam Girdwood dev_dbg(sdev->dev, "stream_tag %d", pcm.params.stream_tag); 197868bd00fSLiam Girdwood 198868bd00fSLiam Girdwood /* send IPC to the DSP */ 199868bd00fSLiam Girdwood ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm), 200868bd00fSLiam Girdwood &ipc_params_reply, sizeof(ipc_params_reply)); 201868bd00fSLiam Girdwood if (ret < 0) { 202868bd00fSLiam Girdwood dev_err(sdev->dev, "error: hw params ipc failed for stream %d\n", 203868bd00fSLiam Girdwood pcm.params.stream_tag); 204868bd00fSLiam Girdwood return ret; 205868bd00fSLiam Girdwood } 206868bd00fSLiam Girdwood 207868bd00fSLiam Girdwood ret = sof_pcm_dsp_params(spcm, substream, &ipc_params_reply); 208868bd00fSLiam Girdwood if (ret < 0) 209868bd00fSLiam Girdwood return ret; 210868bd00fSLiam Girdwood 211868bd00fSLiam Girdwood /* save pcm hw_params */ 212868bd00fSLiam Girdwood memcpy(&spcm->params[substream->stream], params, sizeof(*params)); 213868bd00fSLiam Girdwood 214e2803e61SKeyon Jie INIT_WORK(&spcm->stream[substream->stream].period_elapsed_work, 215e2803e61SKeyon Jie sof_pcm_period_elapsed_work); 216e2803e61SKeyon Jie 217868bd00fSLiam Girdwood return ret; 218868bd00fSLiam Girdwood } 219868bd00fSLiam Girdwood 220868bd00fSLiam Girdwood static int sof_pcm_hw_free(struct snd_pcm_substream *substream) 221868bd00fSLiam Girdwood { 222868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 223868bd00fSLiam Girdwood struct snd_soc_component *component = 224868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 225868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 226868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 227868bd00fSLiam Girdwood struct sof_ipc_stream stream; 228868bd00fSLiam Girdwood struct sof_ipc_reply reply; 229868bd00fSLiam Girdwood int ret; 230868bd00fSLiam Girdwood 231868bd00fSLiam Girdwood /* nothing to do for BE */ 232868bd00fSLiam Girdwood if (rtd->dai_link->no_pcm) 233868bd00fSLiam Girdwood return 0; 234868bd00fSLiam Girdwood 235868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 236868bd00fSLiam Girdwood if (!spcm) 237868bd00fSLiam Girdwood return -EINVAL; 238868bd00fSLiam Girdwood 239868bd00fSLiam Girdwood dev_dbg(sdev->dev, "pcm: free stream %d dir %d\n", spcm->pcm.pcm_id, 240868bd00fSLiam Girdwood substream->stream); 241868bd00fSLiam Girdwood 242868bd00fSLiam Girdwood stream.hdr.size = sizeof(stream); 243868bd00fSLiam Girdwood stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE; 244868bd00fSLiam Girdwood stream.comp_id = spcm->stream[substream->stream].comp_id; 245868bd00fSLiam Girdwood 246868bd00fSLiam Girdwood /* send IPC to the DSP */ 247868bd00fSLiam Girdwood ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, 248868bd00fSLiam Girdwood sizeof(stream), &reply, sizeof(reply)); 249868bd00fSLiam Girdwood 250868bd00fSLiam Girdwood snd_pcm_lib_free_pages(substream); 251e2803e61SKeyon Jie 252e2803e61SKeyon Jie cancel_work_sync(&spcm->stream[substream->stream].period_elapsed_work); 253e2803e61SKeyon Jie 254868bd00fSLiam Girdwood return ret; 255868bd00fSLiam Girdwood } 256868bd00fSLiam Girdwood 257868bd00fSLiam Girdwood static int sof_pcm_prepare(struct snd_pcm_substream *substream) 258868bd00fSLiam Girdwood { 259868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 260868bd00fSLiam Girdwood struct snd_soc_component *component = 261868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 262868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 263868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 264868bd00fSLiam Girdwood int ret; 265868bd00fSLiam Girdwood 266868bd00fSLiam Girdwood /* nothing to do for BE */ 267868bd00fSLiam Girdwood if (rtd->dai_link->no_pcm) 268868bd00fSLiam Girdwood return 0; 269868bd00fSLiam Girdwood 270868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 271868bd00fSLiam Girdwood if (!spcm) 272868bd00fSLiam Girdwood return -EINVAL; 273868bd00fSLiam Girdwood 274868bd00fSLiam Girdwood /* 275868bd00fSLiam Girdwood * check if hw_params needs to be set-up again. 276868bd00fSLiam Girdwood * This is only needed when resuming from system sleep. 277868bd00fSLiam Girdwood */ 278868bd00fSLiam Girdwood if (!spcm->hw_params_upon_resume[substream->stream]) 279868bd00fSLiam Girdwood return 0; 280868bd00fSLiam Girdwood 281868bd00fSLiam Girdwood dev_dbg(sdev->dev, "pcm: prepare stream %d dir %d\n", spcm->pcm.pcm_id, 282868bd00fSLiam Girdwood substream->stream); 283868bd00fSLiam Girdwood 284868bd00fSLiam Girdwood /* set hw_params */ 285868bd00fSLiam Girdwood ret = sof_pcm_hw_params(substream, &spcm->params[substream->stream]); 286868bd00fSLiam Girdwood if (ret < 0) { 287868bd00fSLiam Girdwood dev_err(sdev->dev, "error: set pcm hw_params after resume\n"); 288868bd00fSLiam Girdwood return ret; 289868bd00fSLiam Girdwood } 290868bd00fSLiam Girdwood 291868bd00fSLiam Girdwood return 0; 292868bd00fSLiam Girdwood } 293868bd00fSLiam Girdwood 294868bd00fSLiam Girdwood /* 295868bd00fSLiam Girdwood * FE dai link trigger actions are always executed in non-atomic context because 296868bd00fSLiam Girdwood * they involve IPC's. 297868bd00fSLiam Girdwood */ 298868bd00fSLiam Girdwood static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 299868bd00fSLiam Girdwood { 300868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 301868bd00fSLiam Girdwood struct snd_soc_component *component = 302868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 303868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 304868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 305868bd00fSLiam Girdwood struct sof_ipc_stream stream; 306868bd00fSLiam Girdwood struct sof_ipc_reply reply; 307868bd00fSLiam Girdwood int ret; 308868bd00fSLiam Girdwood 309868bd00fSLiam Girdwood /* nothing to do for BE */ 310868bd00fSLiam Girdwood if (rtd->dai_link->no_pcm) 311868bd00fSLiam Girdwood return 0; 312868bd00fSLiam Girdwood 313868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 314868bd00fSLiam Girdwood if (!spcm) 315868bd00fSLiam Girdwood return -EINVAL; 316868bd00fSLiam Girdwood 317868bd00fSLiam Girdwood dev_dbg(sdev->dev, "pcm: trigger stream %d dir %d cmd %d\n", 318868bd00fSLiam Girdwood spcm->pcm.pcm_id, substream->stream, cmd); 319868bd00fSLiam Girdwood 320868bd00fSLiam Girdwood stream.hdr.size = sizeof(stream); 321868bd00fSLiam Girdwood stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG; 322868bd00fSLiam Girdwood stream.comp_id = spcm->stream[substream->stream].comp_id; 323868bd00fSLiam Girdwood 324868bd00fSLiam Girdwood switch (cmd) { 325868bd00fSLiam Girdwood case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 326868bd00fSLiam Girdwood stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_PAUSE; 327868bd00fSLiam Girdwood break; 328868bd00fSLiam Girdwood case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 329868bd00fSLiam Girdwood stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE; 330868bd00fSLiam Girdwood break; 331868bd00fSLiam Girdwood case SNDRV_PCM_TRIGGER_RESUME: 332868bd00fSLiam Girdwood /* set up hw_params */ 333868bd00fSLiam Girdwood ret = sof_pcm_prepare(substream); 334868bd00fSLiam Girdwood if (ret < 0) { 335868bd00fSLiam Girdwood dev_err(sdev->dev, 336868bd00fSLiam Girdwood "error: failed to set up hw_params upon resume\n"); 337868bd00fSLiam Girdwood return ret; 338868bd00fSLiam Girdwood } 339868bd00fSLiam Girdwood 340868bd00fSLiam Girdwood /* fallthrough */ 341868bd00fSLiam Girdwood case SNDRV_PCM_TRIGGER_START: 342868bd00fSLiam Girdwood stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_START; 343868bd00fSLiam Girdwood break; 344868bd00fSLiam Girdwood case SNDRV_PCM_TRIGGER_SUSPEND: 345868bd00fSLiam Girdwood case SNDRV_PCM_TRIGGER_STOP: 346868bd00fSLiam Girdwood stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP; 347868bd00fSLiam Girdwood break; 348868bd00fSLiam Girdwood default: 349868bd00fSLiam Girdwood dev_err(sdev->dev, "error: unhandled trigger cmd %d\n", cmd); 350868bd00fSLiam Girdwood return -EINVAL; 351868bd00fSLiam Girdwood } 352868bd00fSLiam Girdwood 353868bd00fSLiam Girdwood snd_sof_pcm_platform_trigger(sdev, substream, cmd); 354868bd00fSLiam Girdwood 355868bd00fSLiam Girdwood /* send IPC to the DSP */ 356868bd00fSLiam Girdwood ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, 357868bd00fSLiam Girdwood sizeof(stream), &reply, sizeof(reply)); 358868bd00fSLiam Girdwood 359868bd00fSLiam Girdwood if (ret < 0 || cmd != SNDRV_PCM_TRIGGER_SUSPEND) 360868bd00fSLiam Girdwood return ret; 361868bd00fSLiam Girdwood 362868bd00fSLiam Girdwood /* 363868bd00fSLiam Girdwood * The hw_free op is usually called when the pcm stream is closed. 364868bd00fSLiam Girdwood * Since the stream is not closed during suspend, the DSP needs to be 365868bd00fSLiam Girdwood * notified explicitly to free pcm to prevent errors upon resume. 366868bd00fSLiam Girdwood */ 367868bd00fSLiam Girdwood stream.hdr.size = sizeof(stream); 368868bd00fSLiam Girdwood stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE; 369868bd00fSLiam Girdwood stream.comp_id = spcm->stream[substream->stream].comp_id; 370868bd00fSLiam Girdwood 371868bd00fSLiam Girdwood /* send IPC to the DSP */ 372868bd00fSLiam Girdwood return sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, 373868bd00fSLiam Girdwood sizeof(stream), &reply, sizeof(reply)); 374868bd00fSLiam Girdwood } 375868bd00fSLiam Girdwood 376868bd00fSLiam Girdwood static snd_pcm_uframes_t sof_pcm_pointer(struct snd_pcm_substream *substream) 377868bd00fSLiam Girdwood { 378868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 379868bd00fSLiam Girdwood struct snd_soc_component *component = 380868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 381868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 382868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 383868bd00fSLiam Girdwood snd_pcm_uframes_t host, dai; 384868bd00fSLiam Girdwood 385868bd00fSLiam Girdwood /* nothing to do for BE */ 386868bd00fSLiam Girdwood if (rtd->dai_link->no_pcm) 387868bd00fSLiam Girdwood return 0; 388868bd00fSLiam Girdwood 389868bd00fSLiam Girdwood /* use dsp ops pointer callback directly if set */ 390868bd00fSLiam Girdwood if (sof_ops(sdev)->pcm_pointer) 391868bd00fSLiam Girdwood return sof_ops(sdev)->pcm_pointer(sdev, substream); 392868bd00fSLiam Girdwood 393868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 394868bd00fSLiam Girdwood if (!spcm) 395868bd00fSLiam Girdwood return -EINVAL; 396868bd00fSLiam Girdwood 397868bd00fSLiam Girdwood /* read position from DSP */ 398868bd00fSLiam Girdwood host = bytes_to_frames(substream->runtime, 399868bd00fSLiam Girdwood spcm->stream[substream->stream].posn.host_posn); 400868bd00fSLiam Girdwood dai = bytes_to_frames(substream->runtime, 401868bd00fSLiam Girdwood spcm->stream[substream->stream].posn.dai_posn); 402868bd00fSLiam Girdwood 403868bd00fSLiam Girdwood dev_dbg(sdev->dev, "PCM: stream %d dir %d DMA position %lu DAI position %lu\n", 404868bd00fSLiam Girdwood spcm->pcm.pcm_id, substream->stream, host, dai); 405868bd00fSLiam Girdwood 406868bd00fSLiam Girdwood return host; 407868bd00fSLiam Girdwood } 408868bd00fSLiam Girdwood 409868bd00fSLiam Girdwood static int sof_pcm_open(struct snd_pcm_substream *substream) 410868bd00fSLiam Girdwood { 411868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 412868bd00fSLiam Girdwood struct snd_pcm_runtime *runtime = substream->runtime; 413868bd00fSLiam Girdwood struct snd_soc_component *component = 414868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 415868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 416868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 417868bd00fSLiam Girdwood struct snd_soc_tplg_stream_caps *caps; 418868bd00fSLiam Girdwood int ret; 419868bd00fSLiam Girdwood 420868bd00fSLiam Girdwood /* nothing to do for BE */ 421868bd00fSLiam Girdwood if (rtd->dai_link->no_pcm) 422868bd00fSLiam Girdwood return 0; 423868bd00fSLiam Girdwood 424868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 425868bd00fSLiam Girdwood if (!spcm) 426868bd00fSLiam Girdwood return -EINVAL; 427868bd00fSLiam Girdwood 428868bd00fSLiam Girdwood dev_dbg(sdev->dev, "pcm: open stream %d dir %d\n", spcm->pcm.pcm_id, 429868bd00fSLiam Girdwood substream->stream); 430868bd00fSLiam Girdwood 431868bd00fSLiam Girdwood /* clear hw_params_upon_resume flag */ 432868bd00fSLiam Girdwood spcm->hw_params_upon_resume[substream->stream] = 0; 433868bd00fSLiam Girdwood 434868bd00fSLiam Girdwood caps = &spcm->pcm.caps[substream->stream]; 435868bd00fSLiam Girdwood 436868bd00fSLiam Girdwood /* set any runtime constraints based on topology */ 437868bd00fSLiam Girdwood snd_pcm_hw_constraint_step(substream->runtime, 0, 438868bd00fSLiam Girdwood SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 439868bd00fSLiam Girdwood le32_to_cpu(caps->period_size_min)); 440868bd00fSLiam Girdwood snd_pcm_hw_constraint_step(substream->runtime, 0, 441868bd00fSLiam Girdwood SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 442868bd00fSLiam Girdwood le32_to_cpu(caps->period_size_min)); 443868bd00fSLiam Girdwood 444868bd00fSLiam Girdwood /* set runtime config */ 445868bd00fSLiam Girdwood runtime->hw.info = SNDRV_PCM_INFO_MMAP | 446868bd00fSLiam Girdwood SNDRV_PCM_INFO_MMAP_VALID | 447868bd00fSLiam Girdwood SNDRV_PCM_INFO_INTERLEAVED | 448868bd00fSLiam Girdwood SNDRV_PCM_INFO_PAUSE | 449868bd00fSLiam Girdwood SNDRV_PCM_INFO_NO_PERIOD_WAKEUP; 450868bd00fSLiam Girdwood runtime->hw.formats = le64_to_cpu(caps->formats); 451868bd00fSLiam Girdwood runtime->hw.period_bytes_min = le32_to_cpu(caps->period_size_min); 452868bd00fSLiam Girdwood runtime->hw.period_bytes_max = le32_to_cpu(caps->period_size_max); 453868bd00fSLiam Girdwood runtime->hw.periods_min = le32_to_cpu(caps->periods_min); 454868bd00fSLiam Girdwood runtime->hw.periods_max = le32_to_cpu(caps->periods_max); 455868bd00fSLiam Girdwood 456868bd00fSLiam Girdwood /* 457868bd00fSLiam Girdwood * caps->buffer_size_min is not used since the 458868bd00fSLiam Girdwood * snd_pcm_hardware structure only defines buffer_bytes_max 459868bd00fSLiam Girdwood */ 460868bd00fSLiam Girdwood runtime->hw.buffer_bytes_max = le32_to_cpu(caps->buffer_size_max); 461868bd00fSLiam Girdwood 462868bd00fSLiam Girdwood dev_dbg(sdev->dev, "period min %zd max %zd bytes\n", 463868bd00fSLiam Girdwood runtime->hw.period_bytes_min, 464868bd00fSLiam Girdwood runtime->hw.period_bytes_max); 465868bd00fSLiam Girdwood dev_dbg(sdev->dev, "period count %d max %d\n", 466868bd00fSLiam Girdwood runtime->hw.periods_min, 467868bd00fSLiam Girdwood runtime->hw.periods_max); 468868bd00fSLiam Girdwood dev_dbg(sdev->dev, "buffer max %zd bytes\n", 469868bd00fSLiam Girdwood runtime->hw.buffer_bytes_max); 470868bd00fSLiam Girdwood 471868bd00fSLiam Girdwood /* set wait time - TODO: come from topology */ 472868bd00fSLiam Girdwood substream->wait_time = 500; 473868bd00fSLiam Girdwood 474868bd00fSLiam Girdwood spcm->stream[substream->stream].posn.host_posn = 0; 475868bd00fSLiam Girdwood spcm->stream[substream->stream].posn.dai_posn = 0; 476868bd00fSLiam Girdwood spcm->stream[substream->stream].substream = substream; 477868bd00fSLiam Girdwood 478868bd00fSLiam Girdwood ret = snd_sof_pcm_platform_open(sdev, substream); 479*14a2212dSRanjani Sridharan if (ret < 0) 480*14a2212dSRanjani Sridharan dev_err(sdev->dev, "error: pcm open failed %d\n", ret); 481868bd00fSLiam Girdwood 482868bd00fSLiam Girdwood return ret; 483868bd00fSLiam Girdwood } 484868bd00fSLiam Girdwood 485868bd00fSLiam Girdwood static int sof_pcm_close(struct snd_pcm_substream *substream) 486868bd00fSLiam Girdwood { 487868bd00fSLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 488868bd00fSLiam Girdwood struct snd_soc_component *component = 489868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 490868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 491868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 492868bd00fSLiam Girdwood int err; 493868bd00fSLiam Girdwood 494868bd00fSLiam Girdwood /* nothing to do for BE */ 495868bd00fSLiam Girdwood if (rtd->dai_link->no_pcm) 496868bd00fSLiam Girdwood return 0; 497868bd00fSLiam Girdwood 498868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 499868bd00fSLiam Girdwood if (!spcm) 500868bd00fSLiam Girdwood return -EINVAL; 501868bd00fSLiam Girdwood 502868bd00fSLiam Girdwood dev_dbg(sdev->dev, "pcm: close stream %d dir %d\n", spcm->pcm.pcm_id, 503868bd00fSLiam Girdwood substream->stream); 504868bd00fSLiam Girdwood 505868bd00fSLiam Girdwood err = snd_sof_pcm_platform_close(sdev, substream); 506868bd00fSLiam Girdwood if (err < 0) { 507868bd00fSLiam Girdwood dev_err(sdev->dev, "error: pcm close failed %d\n", 508868bd00fSLiam Girdwood err); 509868bd00fSLiam Girdwood /* 510868bd00fSLiam Girdwood * keep going, no point in preventing the close 511868bd00fSLiam Girdwood * from happening 512868bd00fSLiam Girdwood */ 513868bd00fSLiam Girdwood } 514868bd00fSLiam Girdwood 515868bd00fSLiam Girdwood return 0; 516868bd00fSLiam Girdwood } 517868bd00fSLiam Girdwood 518868bd00fSLiam Girdwood static struct snd_pcm_ops sof_pcm_ops = { 519868bd00fSLiam Girdwood .open = sof_pcm_open, 520868bd00fSLiam Girdwood .close = sof_pcm_close, 521868bd00fSLiam Girdwood .ioctl = snd_pcm_lib_ioctl, 522868bd00fSLiam Girdwood .hw_params = sof_pcm_hw_params, 523868bd00fSLiam Girdwood .prepare = sof_pcm_prepare, 524868bd00fSLiam Girdwood .hw_free = sof_pcm_hw_free, 525868bd00fSLiam Girdwood .trigger = sof_pcm_trigger, 526868bd00fSLiam Girdwood .pointer = sof_pcm_pointer, 527868bd00fSLiam Girdwood .page = snd_pcm_sgbuf_ops_page, 528868bd00fSLiam Girdwood }; 529868bd00fSLiam Girdwood 530868bd00fSLiam Girdwood /* 531868bd00fSLiam Girdwood * Pre-allocate playback/capture audio buffer pages. 532868bd00fSLiam Girdwood * no need to explicitly release memory preallocated by sof_pcm_new in pcm_free 533868bd00fSLiam Girdwood * snd_pcm_lib_preallocate_free_for_all() is called by the core. 534868bd00fSLiam Girdwood */ 535868bd00fSLiam Girdwood static int sof_pcm_new(struct snd_soc_pcm_runtime *rtd) 536868bd00fSLiam Girdwood { 537868bd00fSLiam Girdwood struct snd_soc_component *component = 538868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 539868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 540868bd00fSLiam Girdwood struct snd_sof_pcm *spcm; 541868bd00fSLiam Girdwood struct snd_pcm *pcm = rtd->pcm; 542868bd00fSLiam Girdwood struct snd_soc_tplg_stream_caps *caps; 543868bd00fSLiam Girdwood int stream = SNDRV_PCM_STREAM_PLAYBACK; 544868bd00fSLiam Girdwood 545868bd00fSLiam Girdwood /* find SOF PCM for this RTD */ 546868bd00fSLiam Girdwood spcm = snd_sof_find_spcm_dai(sdev, rtd); 547868bd00fSLiam Girdwood if (!spcm) { 548868bd00fSLiam Girdwood dev_warn(sdev->dev, "warn: can't find PCM with DAI ID %d\n", 549868bd00fSLiam Girdwood rtd->dai_link->id); 550868bd00fSLiam Girdwood return 0; 551868bd00fSLiam Girdwood } 552868bd00fSLiam Girdwood 553868bd00fSLiam Girdwood dev_dbg(sdev->dev, "creating new PCM %s\n", spcm->pcm.pcm_name); 554868bd00fSLiam Girdwood 555868bd00fSLiam Girdwood /* do we need to pre-allocate playback audio buffer pages */ 556868bd00fSLiam Girdwood if (!spcm->pcm.playback) 557868bd00fSLiam Girdwood goto capture; 558868bd00fSLiam Girdwood 559868bd00fSLiam Girdwood caps = &spcm->pcm.caps[stream]; 560868bd00fSLiam Girdwood 561868bd00fSLiam Girdwood /* pre-allocate playback audio buffer pages */ 562868bd00fSLiam Girdwood dev_dbg(sdev->dev, "spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n", 563868bd00fSLiam Girdwood caps->name, caps->buffer_size_min, caps->buffer_size_max); 564868bd00fSLiam Girdwood 565868bd00fSLiam Girdwood snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream, 566868bd00fSLiam Girdwood SNDRV_DMA_TYPE_DEV_SG, sdev->dev, 567868bd00fSLiam Girdwood le32_to_cpu(caps->buffer_size_min), 568868bd00fSLiam Girdwood le32_to_cpu(caps->buffer_size_max)); 569868bd00fSLiam Girdwood capture: 570868bd00fSLiam Girdwood stream = SNDRV_PCM_STREAM_CAPTURE; 571868bd00fSLiam Girdwood 572868bd00fSLiam Girdwood /* do we need to pre-allocate capture audio buffer pages */ 573868bd00fSLiam Girdwood if (!spcm->pcm.capture) 574868bd00fSLiam Girdwood return 0; 575868bd00fSLiam Girdwood 576868bd00fSLiam Girdwood caps = &spcm->pcm.caps[stream]; 577868bd00fSLiam Girdwood 578868bd00fSLiam Girdwood /* pre-allocate capture audio buffer pages */ 579868bd00fSLiam Girdwood dev_dbg(sdev->dev, "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n", 580868bd00fSLiam Girdwood caps->name, caps->buffer_size_min, caps->buffer_size_max); 581868bd00fSLiam Girdwood 582868bd00fSLiam Girdwood snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream, 583868bd00fSLiam Girdwood SNDRV_DMA_TYPE_DEV_SG, sdev->dev, 584868bd00fSLiam Girdwood le32_to_cpu(caps->buffer_size_min), 585868bd00fSLiam Girdwood le32_to_cpu(caps->buffer_size_max)); 586868bd00fSLiam Girdwood 587868bd00fSLiam Girdwood return 0; 588868bd00fSLiam Girdwood } 589868bd00fSLiam Girdwood 590868bd00fSLiam Girdwood /* fixup the BE DAI link to match any values from topology */ 591868bd00fSLiam Girdwood static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, 592868bd00fSLiam Girdwood struct snd_pcm_hw_params *params) 593868bd00fSLiam Girdwood { 594868bd00fSLiam Girdwood struct snd_interval *rate = hw_param_interval(params, 595868bd00fSLiam Girdwood SNDRV_PCM_HW_PARAM_RATE); 596868bd00fSLiam Girdwood struct snd_interval *channels = hw_param_interval(params, 597868bd00fSLiam Girdwood SNDRV_PCM_HW_PARAM_CHANNELS); 598868bd00fSLiam Girdwood struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 599868bd00fSLiam Girdwood struct snd_soc_component *component = 600868bd00fSLiam Girdwood snd_soc_rtdcom_lookup(rtd, DRV_NAME); 601868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 602868bd00fSLiam Girdwood struct snd_sof_dai *dai = 603868bd00fSLiam Girdwood snd_sof_find_dai(sdev, (char *)rtd->dai_link->name); 604868bd00fSLiam Girdwood 605868bd00fSLiam Girdwood /* no topology exists for this BE, try a common configuration */ 606868bd00fSLiam Girdwood if (!dai) { 607868bd00fSLiam Girdwood dev_warn(sdev->dev, "warning: no topology found for BE DAI %s config\n", 608868bd00fSLiam Girdwood rtd->dai_link->name); 609868bd00fSLiam Girdwood 610868bd00fSLiam Girdwood /* set 48k, stereo, 16bits by default */ 611868bd00fSLiam Girdwood rate->min = 48000; 612868bd00fSLiam Girdwood rate->max = 48000; 613868bd00fSLiam Girdwood 614868bd00fSLiam Girdwood channels->min = 2; 615868bd00fSLiam Girdwood channels->max = 2; 616868bd00fSLiam Girdwood 617868bd00fSLiam Girdwood snd_mask_none(fmt); 618868bd00fSLiam Girdwood snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE); 619868bd00fSLiam Girdwood 620868bd00fSLiam Girdwood return 0; 621868bd00fSLiam Girdwood } 622868bd00fSLiam Girdwood 623868bd00fSLiam Girdwood /* read format from topology */ 624868bd00fSLiam Girdwood snd_mask_none(fmt); 625868bd00fSLiam Girdwood 626868bd00fSLiam Girdwood switch (dai->comp_dai.config.frame_fmt) { 627868bd00fSLiam Girdwood case SOF_IPC_FRAME_S16_LE: 628868bd00fSLiam Girdwood snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE); 629868bd00fSLiam Girdwood break; 630868bd00fSLiam Girdwood case SOF_IPC_FRAME_S24_4LE: 631868bd00fSLiam Girdwood snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE); 632868bd00fSLiam Girdwood break; 633868bd00fSLiam Girdwood case SOF_IPC_FRAME_S32_LE: 634868bd00fSLiam Girdwood snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE); 635868bd00fSLiam Girdwood break; 636868bd00fSLiam Girdwood default: 637868bd00fSLiam Girdwood dev_err(sdev->dev, "error: No available DAI format!\n"); 638868bd00fSLiam Girdwood return -EINVAL; 639868bd00fSLiam Girdwood } 640868bd00fSLiam Girdwood 641868bd00fSLiam Girdwood /* read rate and channels from topology */ 642868bd00fSLiam Girdwood switch (dai->dai_config->type) { 643868bd00fSLiam Girdwood case SOF_DAI_INTEL_SSP: 644868bd00fSLiam Girdwood rate->min = dai->dai_config->ssp.fsync_rate; 645868bd00fSLiam Girdwood rate->max = dai->dai_config->ssp.fsync_rate; 646868bd00fSLiam Girdwood channels->min = dai->dai_config->ssp.tdm_slots; 647868bd00fSLiam Girdwood channels->max = dai->dai_config->ssp.tdm_slots; 648868bd00fSLiam Girdwood 649868bd00fSLiam Girdwood dev_dbg(sdev->dev, 650868bd00fSLiam Girdwood "rate_min: %d rate_max: %d\n", rate->min, rate->max); 651868bd00fSLiam Girdwood dev_dbg(sdev->dev, 652868bd00fSLiam Girdwood "channels_min: %d channels_max: %d\n", 653868bd00fSLiam Girdwood channels->min, channels->max); 654868bd00fSLiam Girdwood 655868bd00fSLiam Girdwood break; 656868bd00fSLiam Girdwood case SOF_DAI_INTEL_DMIC: 657868bd00fSLiam Girdwood /* DMIC only supports 16 or 32 bit formats */ 658868bd00fSLiam Girdwood if (dai->comp_dai.config.frame_fmt == SOF_IPC_FRAME_S24_4LE) { 659868bd00fSLiam Girdwood dev_err(sdev->dev, 660868bd00fSLiam Girdwood "error: invalid fmt %d for DAI type %d\n", 661868bd00fSLiam Girdwood dai->comp_dai.config.frame_fmt, 662868bd00fSLiam Girdwood dai->dai_config->type); 663868bd00fSLiam Girdwood } 664868bd00fSLiam Girdwood break; 665868bd00fSLiam Girdwood case SOF_DAI_INTEL_HDA: 666868bd00fSLiam Girdwood /* do nothing for HDA dai_link */ 667868bd00fSLiam Girdwood break; 668868bd00fSLiam Girdwood default: 669868bd00fSLiam Girdwood dev_err(sdev->dev, "error: invalid DAI type %d\n", 670868bd00fSLiam Girdwood dai->dai_config->type); 671868bd00fSLiam Girdwood break; 672868bd00fSLiam Girdwood } 673868bd00fSLiam Girdwood 674868bd00fSLiam Girdwood return 0; 675868bd00fSLiam Girdwood } 676868bd00fSLiam Girdwood 677868bd00fSLiam Girdwood static int sof_pcm_probe(struct snd_soc_component *component) 678868bd00fSLiam Girdwood { 679868bd00fSLiam Girdwood struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 680868bd00fSLiam Girdwood struct snd_sof_pdata *plat_data = sdev->pdata; 681868bd00fSLiam Girdwood const char *tplg_filename; 682868bd00fSLiam Girdwood int ret; 683868bd00fSLiam Girdwood 684868bd00fSLiam Girdwood /* load the default topology */ 685868bd00fSLiam Girdwood sdev->component = component; 686868bd00fSLiam Girdwood 687868bd00fSLiam Girdwood tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, 688868bd00fSLiam Girdwood "%s/%s", 689868bd00fSLiam Girdwood plat_data->tplg_filename_prefix, 690868bd00fSLiam Girdwood plat_data->tplg_filename); 691868bd00fSLiam Girdwood if (!tplg_filename) 692868bd00fSLiam Girdwood return -ENOMEM; 693868bd00fSLiam Girdwood 694868bd00fSLiam Girdwood ret = snd_sof_load_topology(sdev, tplg_filename); 695868bd00fSLiam Girdwood if (ret < 0) { 696868bd00fSLiam Girdwood dev_err(sdev->dev, "error: failed to load DSP topology %d\n", 697868bd00fSLiam Girdwood ret); 698868bd00fSLiam Girdwood return ret; 699868bd00fSLiam Girdwood } 700868bd00fSLiam Girdwood 701868bd00fSLiam Girdwood /* 702868bd00fSLiam Girdwood * Some platforms in SOF, ex: BYT, may not have their platform PM 703868bd00fSLiam Girdwood * callbacks set. Increment the usage count so as to 704868bd00fSLiam Girdwood * prevent the device from entering runtime suspend. 705868bd00fSLiam Girdwood */ 706868bd00fSLiam Girdwood if (!sof_ops(sdev)->runtime_suspend || !sof_ops(sdev)->runtime_resume) 707868bd00fSLiam Girdwood pm_runtime_get_noresume(sdev->dev); 708868bd00fSLiam Girdwood 709868bd00fSLiam Girdwood return ret; 710868bd00fSLiam Girdwood } 711868bd00fSLiam Girdwood 712868bd00fSLiam Girdwood static void sof_pcm_remove(struct snd_soc_component *component) 713868bd00fSLiam Girdwood { 714868bd00fSLiam Girdwood /* remove topology */ 715868bd00fSLiam Girdwood snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL); 716868bd00fSLiam Girdwood } 717868bd00fSLiam Girdwood 718868bd00fSLiam Girdwood void snd_sof_new_platform_drv(struct snd_sof_dev *sdev) 719868bd00fSLiam Girdwood { 720868bd00fSLiam Girdwood struct snd_soc_component_driver *pd = &sdev->plat_drv; 721868bd00fSLiam Girdwood struct snd_sof_pdata *plat_data = sdev->pdata; 722868bd00fSLiam Girdwood const char *drv_name; 723868bd00fSLiam Girdwood 724868bd00fSLiam Girdwood drv_name = plat_data->machine->drv_name; 725868bd00fSLiam Girdwood 726868bd00fSLiam Girdwood pd->name = "sof-audio-component"; 727868bd00fSLiam Girdwood pd->probe = sof_pcm_probe; 728868bd00fSLiam Girdwood pd->remove = sof_pcm_remove; 729868bd00fSLiam Girdwood pd->ops = &sof_pcm_ops; 730868bd00fSLiam Girdwood #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS) 731868bd00fSLiam Girdwood pd->compr_ops = &sof_compressed_ops; 732868bd00fSLiam Girdwood #endif 733868bd00fSLiam Girdwood pd->pcm_new = sof_pcm_new; 734868bd00fSLiam Girdwood pd->ignore_machine = drv_name; 735868bd00fSLiam Girdwood pd->be_hw_params_fixup = sof_pcm_dai_link_fixup; 736868bd00fSLiam Girdwood pd->be_pcm_base = SOF_BE_PCM_BASE; 737868bd00fSLiam Girdwood pd->use_dai_pcm_id = true; 738868bd00fSLiam Girdwood pd->topology_name_prefix = "sof"; 739868bd00fSLiam Girdwood 740868bd00fSLiam Girdwood /* increment module refcount when a pcm is opened */ 741868bd00fSLiam Girdwood pd->module_get_upon_open = 1; 742868bd00fSLiam Girdwood } 743