Skip to content

Commit 2448915

Browse files
AngeloGioacchino Del Regnobroonie
authored andcommitted
ASoC: SOF: mediatek: Commonize duplicated functions
In order to reduce duplication, move the ADSP mailbox callbacks handle_reply(), handle_request(), and other common SOF callbacks send_msg(), get_bar_index(), pcm_hw_params() and pcm_pointer() to the mtk-adsp-common.c file. This cleanup brings no functional differences. Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://patch.msgid.link/20250320115300.137410-1-angelogioacchino.delregno@collabora.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 6271b74 commit 2448915

File tree

4 files changed

+152
-198
lines changed

4 files changed

+152
-198
lines changed

sound/soc/sof/mediatek/mt8186/mt8186.c

Lines changed: 6 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <sound/sof/xtensa.h>
2323
#include "../../ops.h"
2424
#include "../../sof-of-dev.h"
25-
#include "../../sof-audio.h"
2625
#include "../adsp_helper.h"
2726
#include "../mtk-adsp-common.h"
2827
#include "mt8186.h"
@@ -38,53 +37,9 @@ static int mt8186_get_window_offset(struct snd_sof_dev *sdev, u32 id)
3837
return MBOX_OFFSET;
3938
}
4039

41-
static int mt8186_send_msg(struct snd_sof_dev *sdev,
42-
struct snd_sof_ipc_msg *msg)
43-
{
44-
struct adsp_priv *priv = sdev->pdata->hw_pdata;
45-
46-
sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data,
47-
msg->msg_size);
48-
49-
return mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_REQ, MTK_ADSP_IPC_OP_REQ);
50-
}
51-
52-
static void mt8186_dsp_handle_reply(struct mtk_adsp_ipc *ipc)
53-
{
54-
struct adsp_priv *priv = mtk_adsp_ipc_get_data(ipc);
55-
unsigned long flags;
56-
57-
spin_lock_irqsave(&priv->sdev->ipc_lock, flags);
58-
snd_sof_ipc_process_reply(priv->sdev, 0);
59-
spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags);
60-
}
61-
62-
static void mt8186_dsp_handle_request(struct mtk_adsp_ipc *ipc)
63-
{
64-
struct adsp_priv *priv = mtk_adsp_ipc_get_data(ipc);
65-
u32 p; /* panic code */
66-
int ret;
67-
68-
/* Read the message from the debug box. */
69-
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4,
70-
&p, sizeof(p));
71-
72-
/* Check to see if the message is a panic code 0x0dead*** */
73-
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC) {
74-
snd_sof_dsp_panic(priv->sdev, p, true);
75-
} else {
76-
snd_sof_ipc_msgs_rx(priv->sdev);
77-
78-
/* tell DSP cmd is done */
79-
ret = mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_RSP, MTK_ADSP_IPC_OP_RSP);
80-
if (ret)
81-
dev_err(priv->dev, "request send ipc failed");
82-
}
83-
}
84-
8540
static const struct mtk_adsp_ipc_ops dsp_ops = {
86-
.handle_reply = mt8186_dsp_handle_reply,
87-
.handle_request = mt8186_dsp_handle_request,
41+
.handle_reply = mtk_adsp_handle_reply,
42+
.handle_request = mtk_adsp_handle_request,
8843
};
8944

9045
static int platform_parse_resource(struct platform_device *pdev, void *data)
@@ -381,54 +336,6 @@ static int mt8186_dsp_resume(struct snd_sof_dev *sdev)
381336
return ret;
382337
}
383338

384-
/* on mt8186 there is 1 to 1 match between type and BAR idx */
385-
static int mt8186_get_bar_index(struct snd_sof_dev *sdev, u32 type)
386-
{
387-
return type;
388-
}
389-
390-
static int mt8186_pcm_hw_params(struct snd_sof_dev *sdev,
391-
struct snd_pcm_substream *substream,
392-
struct snd_pcm_hw_params *params,
393-
struct snd_sof_platform_stream_params *platform_params)
394-
{
395-
platform_params->cont_update_posn = 1;
396-
397-
return 0;
398-
}
399-
400-
static snd_pcm_uframes_t mt8186_pcm_pointer(struct snd_sof_dev *sdev,
401-
struct snd_pcm_substream *substream)
402-
{
403-
int ret;
404-
snd_pcm_uframes_t pos;
405-
struct snd_sof_pcm *spcm;
406-
struct sof_ipc_stream_posn posn;
407-
struct snd_sof_pcm_stream *stream;
408-
struct snd_soc_component *scomp = sdev->component;
409-
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
410-
411-
spcm = snd_sof_find_spcm_dai(scomp, rtd);
412-
if (!spcm) {
413-
dev_warn_ratelimited(sdev->dev, "warn: can't find PCM with DAI ID %d\n",
414-
rtd->dai_link->id);
415-
return 0;
416-
}
417-
418-
stream = &spcm->stream[substream->stream];
419-
ret = snd_sof_ipc_msg_data(sdev, stream, &posn, sizeof(posn));
420-
if (ret < 0) {
421-
dev_warn(sdev->dev, "failed to read stream position: %d\n", ret);
422-
return 0;
423-
}
424-
425-
memcpy(&stream->posn, &posn, sizeof(posn));
426-
pos = spcm->stream[substream->stream].posn.host_posn;
427-
pos = bytes_to_frames(substream->runtime, pos);
428-
429-
return pos;
430-
}
431-
432339
static void mt8186_adsp_dump(struct snd_sof_dev *sdev, u32 flags)
433340
{
434341
u32 dbg_pc, dbg_data, dbg_inst, dbg_ls0stat, dbg_status, faultinfo;
@@ -505,19 +412,19 @@ static const struct snd_sof_dsp_ops sof_mt8186_ops = {
505412
.read64 = sof_io_read64,
506413

507414
/* ipc */
508-
.send_msg = mt8186_send_msg,
415+
.send_msg = mtk_adsp_send_msg,
509416
.get_mailbox_offset = mt8186_get_mailbox_offset,
510417
.get_window_offset = mt8186_get_window_offset,
511418
.ipc_msg_data = sof_ipc_msg_data,
512419
.set_stream_data_offset = sof_set_stream_data_offset,
513420

514421
/* misc */
515-
.get_bar_index = mt8186_get_bar_index,
422+
.get_bar_index = mtk_adsp_get_bar_index,
516423

517424
/* stream callbacks */
518425
.pcm_open = sof_stream_pcm_open,
519-
.pcm_hw_params = mt8186_pcm_hw_params,
520-
.pcm_pointer = mt8186_pcm_pointer,
426+
.pcm_hw_params = mtk_adsp_stream_pcm_hw_params,
427+
.pcm_pointer = mtk_adsp_stream_pcm_pointer,
521428
.pcm_close = sof_stream_pcm_close,
522429

523430
/* firmware loading */

sound/soc/sof/mediatek/mt8195/mt8195.c

Lines changed: 6 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <sound/sof/xtensa.h>
2323
#include "../../ops.h"
2424
#include "../../sof-of-dev.h"
25-
#include "../../sof-audio.h"
2625
#include "../adsp_helper.h"
2726
#include "../mtk-adsp-common.h"
2827
#include "mt8195.h"
@@ -38,53 +37,9 @@ static int mt8195_get_window_offset(struct snd_sof_dev *sdev, u32 id)
3837
return MBOX_OFFSET;
3938
}
4039

41-
static int mt8195_send_msg(struct snd_sof_dev *sdev,
42-
struct snd_sof_ipc_msg *msg)
43-
{
44-
struct adsp_priv *priv = sdev->pdata->hw_pdata;
45-
46-
sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data,
47-
msg->msg_size);
48-
49-
return mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_REQ, MTK_ADSP_IPC_OP_REQ);
50-
}
51-
52-
static void mt8195_dsp_handle_reply(struct mtk_adsp_ipc *ipc)
53-
{
54-
struct adsp_priv *priv = mtk_adsp_ipc_get_data(ipc);
55-
unsigned long flags;
56-
57-
spin_lock_irqsave(&priv->sdev->ipc_lock, flags);
58-
snd_sof_ipc_process_reply(priv->sdev, 0);
59-
spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags);
60-
}
61-
62-
static void mt8195_dsp_handle_request(struct mtk_adsp_ipc *ipc)
63-
{
64-
struct adsp_priv *priv = mtk_adsp_ipc_get_data(ipc);
65-
u32 p; /* panic code */
66-
int ret;
67-
68-
/* Read the message from the debug box. */
69-
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4,
70-
&p, sizeof(p));
71-
72-
/* Check to see if the message is a panic code 0x0dead*** */
73-
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC) {
74-
snd_sof_dsp_panic(priv->sdev, p, true);
75-
} else {
76-
snd_sof_ipc_msgs_rx(priv->sdev);
77-
78-
/* tell DSP cmd is done */
79-
ret = mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_RSP, MTK_ADSP_IPC_OP_RSP);
80-
if (ret)
81-
dev_err(priv->dev, "request send ipc failed");
82-
}
83-
}
84-
8540
static const struct mtk_adsp_ipc_ops dsp_ops = {
86-
.handle_reply = mt8195_dsp_handle_reply,
87-
.handle_request = mt8195_dsp_handle_request,
41+
.handle_reply = mtk_adsp_handle_reply,
42+
.handle_request = mtk_adsp_handle_request,
8843
};
8944

9045
static int platform_parse_resource(struct platform_device *pdev, void *data)
@@ -400,54 +355,6 @@ static int mt8195_dsp_resume(struct snd_sof_dev *sdev)
400355
return ret;
401356
}
402357

403-
/* on mt8195 there is 1 to 1 match between type and BAR idx */
404-
static int mt8195_get_bar_index(struct snd_sof_dev *sdev, u32 type)
405-
{
406-
return type;
407-
}
408-
409-
static int mt8195_pcm_hw_params(struct snd_sof_dev *sdev,
410-
struct snd_pcm_substream *substream,
411-
struct snd_pcm_hw_params *params,
412-
struct snd_sof_platform_stream_params *platform_params)
413-
{
414-
platform_params->cont_update_posn = 1;
415-
416-
return 0;
417-
}
418-
419-
static snd_pcm_uframes_t mt8195_pcm_pointer(struct snd_sof_dev *sdev,
420-
struct snd_pcm_substream *substream)
421-
{
422-
int ret;
423-
snd_pcm_uframes_t pos;
424-
struct snd_sof_pcm *spcm;
425-
struct sof_ipc_stream_posn posn;
426-
struct snd_sof_pcm_stream *stream;
427-
struct snd_soc_component *scomp = sdev->component;
428-
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
429-
430-
spcm = snd_sof_find_spcm_dai(scomp, rtd);
431-
if (!spcm) {
432-
dev_warn_ratelimited(sdev->dev, "warn: can't find PCM with DAI ID %d\n",
433-
rtd->dai_link->id);
434-
return 0;
435-
}
436-
437-
stream = &spcm->stream[substream->stream];
438-
ret = snd_sof_ipc_msg_data(sdev, stream, &posn, sizeof(posn));
439-
if (ret < 0) {
440-
dev_warn(sdev->dev, "failed to read stream position: %d\n", ret);
441-
return 0;
442-
}
443-
444-
memcpy(&stream->posn, &posn, sizeof(posn));
445-
pos = spcm->stream[substream->stream].posn.host_posn;
446-
pos = bytes_to_frames(substream->runtime, pos);
447-
448-
return pos;
449-
}
450-
451358
static void mt8195_adsp_dump(struct snd_sof_dev *sdev, u32 flags)
452359
{
453360
u32 dbg_pc, dbg_data, dbg_bus0, dbg_bus1, dbg_inst;
@@ -529,19 +436,19 @@ static const struct snd_sof_dsp_ops sof_mt8195_ops = {
529436
.read64 = sof_io_read64,
530437

531438
/* ipc */
532-
.send_msg = mt8195_send_msg,
439+
.send_msg = mtk_adsp_send_msg,
533440
.get_mailbox_offset = mt8195_get_mailbox_offset,
534441
.get_window_offset = mt8195_get_window_offset,
535442
.ipc_msg_data = sof_ipc_msg_data,
536443
.set_stream_data_offset = sof_set_stream_data_offset,
537444

538445
/* misc */
539-
.get_bar_index = mt8195_get_bar_index,
446+
.get_bar_index = mtk_adsp_get_bar_index,
540447

541448
/* stream callbacks */
542449
.pcm_open = sof_stream_pcm_open,
543-
.pcm_hw_params = mt8195_pcm_hw_params,
544-
.pcm_pointer = mt8195_pcm_pointer,
450+
.pcm_hw_params = mtk_adsp_stream_pcm_hw_params,
451+
.pcm_pointer = mtk_adsp_stream_pcm_pointer,
545452
.pcm_close = sof_stream_pcm_close,
546453

547454
/* firmware loading */

0 commit comments

Comments
 (0)