xref: /openbmc/linux/sound/soc/sof/amd/acp-trace.c (revision 234489ac)
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) 2021 Advanced Micro Devices, Inc. All rights reserved.
7 //
8 // Authors: Vishnuvardhanrao Ravuapati <vishnuvardhanrao.ravulapati@amd.com>
9 //	    V Sujith Kumar Reddy <Vsujithkumar.Reddy@amd.com>
10 
11 /*This file support Host TRACE Logger driver callback for SOF FW */
12 
13 #include "acp.h"
14 
15 #define ACP_LOGGER_STREAM	8
16 #define NUM_PAGES		16
17 
18 int acp_sof_trace_release(struct snd_sof_dev *sdev)
19 {
20 	struct acp_dsp_stream *stream;
21 	struct acp_dev_data *adata;
22 	int ret;
23 
24 	adata = sdev->pdata->hw_pdata;
25 	stream = adata->dtrace_stream;
26 	ret = acp_dsp_stream_put(sdev, stream);
27 	if (ret < 0) {
28 		dev_err(sdev->dev, "Failed to release trace stream\n");
29 		return ret;
30 	}
31 
32 	adata->dtrace_stream = NULL;
33 	return 0;
34 }
35 EXPORT_SYMBOL_NS(acp_sof_trace_release, SND_SOC_SOF_AMD_COMMON);
36 
37 int acp_sof_trace_init(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
38 		       struct sof_ipc_dma_trace_params_ext *dtrace_params)
39 {
40 	struct acp_dsp_stream *stream;
41 	struct acp_dev_data *adata;
42 	int ret;
43 
44 	adata = sdev->pdata->hw_pdata;
45 	stream = acp_dsp_stream_get(sdev, ACP_LOGGER_STREAM);
46 	if (!stream)
47 		return -ENODEV;
48 
49 	stream->dmab = dmab;
50 	stream->num_pages = NUM_PAGES;
51 
52 	ret = acp_dsp_stream_config(sdev, stream);
53 	if (ret < 0) {
54 		acp_dsp_stream_put(sdev, stream);
55 		return ret;
56 	}
57 
58 	adata->dtrace_stream = stream;
59 	dtrace_params->stream_tag = stream->stream_tag;
60 	dtrace_params->buffer.phy_addr = stream->reg_offset;
61 
62 	return 0;
63 }
64 EXPORT_SYMBOL_NS(acp_sof_trace_init, SND_SOC_SOF_AMD_COMMON);
65