1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 //Copyright(c) 2021 AMD. All rights reserved.
4 //
5 // Author:	Basavaraj Hiregoudar <basavaraj.hiregoudar@amd.com>
6 //		Anup Kulkarni <anup.kulkarni@amd.com>
7 //		Bala Kishore <balakishore.pati@amd.com>
8 
9 #include <sof/audio/component.h>
10 #include <sof/drivers/acp_dai_dma.h>
11 #include <sof/drivers/interrupt.h>
12 #include <sof/lib/alloc.h>
13 #include <sof/lib/dai.h>
14 #include <sof/lib/dma.h>
15 #include <sof/lib/uuid.h>
16 #include <ipc/dai.h>
17 #include <ipc/topology.h>
18 #include <platform/fw_scratch_mem.h>
19 #include <sof/lib/io.h>
20 #include <platform/chip_offset_byte.h>
21 
22 /*0ae40946-dfd2-4140-91-52-0d-d5-a3-ea-ae-81*/
23 DECLARE_SOF_UUID("acp_dmic_dai", acp_dmic_dai_uuid, 0x0ae40946, 0xdfd2, 0x4140,
24 		0x91, 0x52, 0x0d, 0xd5, 0xa3, 0xea, 0xae, 0x81);
25 
26 DECLARE_TR_CTX(acp_dmic_dai_tr, SOF_UUID(acp_dmic_dai_uuid), LOG_LEVEL_INFO);
27 
acp_dmic_dai_set_config(struct dai * dai,struct ipc_config_dai * common_config,void * spec_config)28 static inline int acp_dmic_dai_set_config(struct dai *dai, struct ipc_config_dai *common_config,
29 					  void *spec_config)
30 {
31 	/* nothing to do on dmic dai */
32 	return 0;
33 }
34 
acp_dmic_dai_trigger(struct dai * dai,int cmd,int direction)35 static int acp_dmic_dai_trigger(struct dai *dai, int cmd, int direction)
36 {
37 	dai_dbg(dai, "acp_dmic_dai_trigger");
38 	switch (cmd) {
39 	case COMP_TRIGGER_START:
40 	case COMP_TRIGGER_STOP:
41 	default:
42 		break;
43 	}
44 	return 0;
45 }
46 
acp_dmic_dai_probe(struct dai * dai)47 static int acp_dmic_dai_probe(struct dai *dai)
48 {
49 	/* TODO */
50 	return 0;
51 }
52 
acp_dmic_dai_get_fifo(struct dai * dai,int direction,int stream_id)53 static int acp_dmic_dai_get_fifo(struct dai *dai, int direction, int stream_id)
54 {
55 	switch (direction) {
56 	case DAI_DIR_PLAYBACK:
57 	case DAI_DIR_CAPTURE:
58 		return dai_fifo(dai, direction);
59 	default:
60 		dai_err(dai, "acp_dmic_dai_get_fifo(): Invalid direction");
61 		return -EINVAL;
62 	}
63 }
64 
acp_dmic_dai_get_handshake(struct dai * dai,int direction,int stream_id)65 static int acp_dmic_dai_get_handshake(struct dai *dai, int direction,
66 					int stream_id)
67 {
68 	return dai->plat_data.fifo[direction].handshake;
69 }
70 
acp_dmic_dai_get_hw_params(struct dai * dai,struct sof_ipc_stream_params * params,int dir)71 static int acp_dmic_dai_get_hw_params(struct dai *dai,
72 			      struct sof_ipc_stream_params *params,
73 			      int dir)
74 {
75 	/* ACP only currently supports these parameters */
76 	params->rate = ACP_DEFAULT_SAMPLE_RATE;
77 	params->channels = ACP_DEFAULT_NUM_CHANNELS;
78 	params->buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
79 	params->frame_fmt = SOF_IPC_FRAME_S32_LE;
80 	return 0;
81 }
82 
83 const struct dai_driver acp_dmic_dai_driver = {
84 	.type = SOF_DAI_AMD_DMIC,
85 	.uid = SOF_UUID(acp_dmic_dai_uuid),
86 	.tctx = &acp_dmic_dai_tr,
87 	.dma_dev = DMA_DEV_DMIC,
88 	.dma_caps = DMA_CAP_DMIC,
89 	.ops = {
90 		.trigger		= acp_dmic_dai_trigger,
91 		.set_config		= acp_dmic_dai_set_config,
92 		.probe			= acp_dmic_dai_probe,
93 		.get_fifo		= acp_dmic_dai_get_fifo,
94 		.get_handshake		= acp_dmic_dai_get_handshake,
95 		.get_hw_params		= acp_dmic_dai_get_hw_params,
96 	},
97 };
98