// SPDX-License-Identifier: BSD-3-Clause
//
//Copyright(c) 2023 AMD. All rights reserved.
//
//Author:       Basavaraj Hiregoudar <basavaraj.hiregoudar@amd.com>
//              SaiSurya, Ch <saisurya.chakkaveeravenkatanaga@amd.com>

#include <sof/common.h>
#include <sof/drivers/acp_dai_dma.h>
#include <sof/lib/dai.h>
#include <sof/lib/memory.h>
#include <rtos/sof.h>
#include <rtos/spinlock.h>
#include <ipc/dai.h>
#include <ipc/stream.h>

static struct dai hsdai[] = {
	{
		.index = 1,
		.plat_data = {
			.base = DAI_BASE,
			.fifo[SOF_IPC_STREAM_PLAYBACK] = {
			.offset         = DAI_BASE + HS_TX_FIFO_OFFST,
			.depth          = 8,
			.handshake      = 1,
			},
		},
		.drv = &acp_hsdai_driver,
	},
};

static struct dai spdai[] = {
	{
		.index = 0,
		.plat_data = {
			.base = DAI_BASE,
			.fifo[SOF_IPC_STREAM_PLAYBACK] = {
				.offset         = DAI_BASE + BT_TX_FIFO_OFFST,
				.depth          = 8,
				.handshake      = 5,
			},
			.fifo[SOF_IPC_STREAM_CAPTURE] = {
				.offset         = DAI_BASE + BT_RX_FIFO_OFFST,
				.depth          = 8,
				.handshake      = 4,
			},
		},
		.drv = &acp_spdai_driver,
	}
};

#ifdef ACP_BT_ENABLE
static struct dai btdai[] = {
	{
		.index = 0,
		.plat_data = {
			.base = DAI_BASE,
			.fifo[SOF_IPC_STREAM_PLAYBACK] = {
				.offset		= DAI_BASE + BT_TX_FIFO_OFFST,
				.depth		= 8,
				.handshake	= 3,
			},
			.fifo[SOF_IPC_STREAM_CAPTURE] = {
				.offset		= DAI_BASE + BT_RX_FIFO_OFFST,
				.depth		= 8,
				.handshake	= 2,
			},
		},
		.drv = &acp_btdai_driver,
	},
};
#endif

const struct dai_type_info dti[] = {
	{
		.type		= SOF_DAI_AMD_HS,
		.dai_array	= hsdai,
		.num_dais	= ARRAY_SIZE(hsdai)
	},
	{
		.type		= SOF_DAI_AMD_SP,
		.dai_array	= spdai,
		.num_dais	= ARRAY_SIZE(spdai)
	},
#ifdef ACP_BT_ENABLE
	{
		.type = SOF_DAI_AMD_BT,
		.dai_array = btdai,
		.num_dais = ARRAY_SIZE(btdai)
	},
#endif
};

const struct dai_info lib_dai = {
	.dai_type_array = dti,
	.num_dai_types = ARRAY_SIZE(dti)
};

int dai_init(struct sof *sof)
{
	int i;

	/* initialize spin locks early to enable ref counting */
	for (i = 0; i < ARRAY_SIZE(hsdai); i++)
		k_spinlock_init(&hsdai[i].lock);
	for (i = 0; i < ARRAY_SIZE(spdai); i++)
		k_spinlock_init(&spdai[i].lock);
#ifdef ACP_BT_ENABLE
	/* initialize spin locks early to enable ref counting */
	for (i = 0; i < ARRAY_SIZE(btdai); i++)
		k_spinlock_init(&btdai[i].lock);
#endif
	sof->dai_info = &lib_dai;
	return 0;
}
