Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
0002 //
0003 // This file is provided under a dual BSD/GPLv2 license.  When using or
0004 // redistributing this file, you may do so under either license.
0005 //
0006 // Copyright(c) 2018 Intel Corporation. All rights reserved.
0007 //
0008 // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
0009 //      Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
0010 //      Rander Wang <rander.wang@intel.com>
0011 //          Keyon Jie <yang.jie@linux.intel.com>
0012 //
0013 
0014 /*
0015  * Hardware interface for generic Intel audio DSP HDA IP
0016  */
0017 
0018 #include <sound/hdaudio_ext.h>
0019 #include "../ops.h"
0020 #include "hda.h"
0021 
0022 static int hda_dsp_trace_prepare(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab)
0023 {
0024     struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
0025     struct hdac_ext_stream *hext_stream = hda->dtrace_stream;
0026     struct hdac_stream *hstream = &hext_stream->hstream;
0027     int ret;
0028 
0029     hstream->period_bytes = 0;/* initialize period_bytes */
0030     hstream->bufsize = dmab->bytes;
0031 
0032     ret = hda_dsp_stream_hw_params(sdev, hext_stream, dmab, NULL);
0033     if (ret < 0)
0034         dev_err(sdev->dev, "error: hdac prepare failed: %d\n", ret);
0035 
0036     return ret;
0037 }
0038 
0039 int hda_dsp_trace_init(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
0040                struct sof_ipc_dma_trace_params_ext *dtrace_params)
0041 {
0042     struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
0043     int ret;
0044 
0045     hda->dtrace_stream = hda_dsp_stream_get(sdev, SNDRV_PCM_STREAM_CAPTURE,
0046                         SOF_HDA_STREAM_DMI_L1_COMPATIBLE);
0047 
0048     if (!hda->dtrace_stream) {
0049         dev_err(sdev->dev,
0050             "error: no available capture stream for DMA trace\n");
0051         return -ENODEV;
0052     }
0053 
0054     dtrace_params->stream_tag = hda->dtrace_stream->hstream.stream_tag;
0055 
0056     /*
0057      * initialize capture stream, set BDL address and return corresponding
0058      * stream tag which will be sent to the firmware by IPC message.
0059      */
0060     ret = hda_dsp_trace_prepare(sdev, dmab);
0061     if (ret < 0) {
0062         dev_err(sdev->dev, "error: hdac trace init failed: %d\n", ret);
0063         hda_dsp_stream_put(sdev, SNDRV_PCM_STREAM_CAPTURE,
0064                    dtrace_params->stream_tag);
0065         hda->dtrace_stream = NULL;
0066         dtrace_params->stream_tag = 0;
0067     }
0068 
0069     return ret;
0070 }
0071 
0072 int hda_dsp_trace_release(struct snd_sof_dev *sdev)
0073 {
0074     struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
0075     struct hdac_stream *hstream;
0076 
0077     if (hda->dtrace_stream) {
0078         hstream = &hda->dtrace_stream->hstream;
0079         hda_dsp_stream_put(sdev,
0080                    SNDRV_PCM_STREAM_CAPTURE,
0081                    hstream->stream_tag);
0082         hda->dtrace_stream = NULL;
0083         return 0;
0084     }
0085 
0086     dev_dbg(sdev->dev, "DMA trace stream is not opened!\n");
0087     return -ENODEV;
0088 }
0089 
0090 int hda_dsp_trace_trigger(struct snd_sof_dev *sdev, int cmd)
0091 {
0092     struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
0093 
0094     return hda_dsp_stream_trigger(sdev, hda->dtrace_stream, cmd);
0095 }