// SPDX-License-Identifier: GPL-2.0
/*
 * audio_input_control_interface.c  --  Mediatek Soundbar kcontrol
 *
 * Copyright (c) 2020 MediaTek Inc.
 * Author: Wen Cai <wen.cai@mediatek.com>
 *
 */
#include "audio_input_control_impl.h"
#include "audio_input_control_interface.h"
struct audio_input_kcontrol_func_type audio_input_kcontrol_func;
static int audio_stream_detect_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	ucontrol->value.enumerated.item[0] = impl_audio_stream_detect_get();
	return 0;
}

static int audio_stream_detect_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	int value = ucontrol->value.enumerated.item[0];

	impl_audio_stream_detect_put(value);
	return 0;
}

static int audio_stream_info_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct audio_stream_info stream_info = {0};

	impl_audio_stream_info_get(&stream_info);
	ucontrol->value.integer.value[0] = stream_info.stream_type;
	ucontrol->value.integer.value[1] = stream_info.ch_num;
	ucontrol->value.integer.value[2] = stream_info.sample_rate;
	ucontrol->value.integer.value[3] = stream_info.channel_config;
	return 0;
}

static int audio_stream_info_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct audio_stream_info stream_info;

	stream_info.stream_type = ucontrol->value.integer.value[0];
	stream_info.ch_num = ucontrol->value.integer.value[1];
	stream_info.sample_rate = ucontrol->value.integer.value[2];
	stream_info.channel_config = ucontrol->value.integer.value[3];
	impl_audio_stream_info_put(&stream_info);
	return 0;
}

static int audio_current_state_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct audio_stream_info stream_info = {0};

	impl_audio_stream_info_get(&stream_info);

	ucontrol->value.integer.value[0] = impl_audio_stream_detect_get();
	ucontrol->value.integer.value[1] = stream_info.stream_type;
	ucontrol->value.integer.value[2] = stream_info.ch_num;
	ucontrol->value.integer.value[3] = stream_info.sample_rate;
	ucontrol->value.integer.value[4] = stream_info.channel_config;
	return 0;
}

#ifdef CURRENTLY_AUDIO_NOT_USE
static int audio_current_state_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	return 0;
}
#endif

int audio_input_kcontrol_init(void)
{
	impl_audio_input_initialize();
	return 0;
}

int reg_audio_input_control_func(void)
{
	int ret = 0;

	audio_input_kcontrol_func.audio_stream_detect_get
			= audio_stream_detect_get;
	audio_input_kcontrol_func.audio_stream_detect_get
			= audio_stream_detect_get;
	audio_input_kcontrol_func.audio_stream_detect_put
			= audio_stream_detect_put;

	audio_input_kcontrol_func.audio_stream_info_get
			= audio_stream_info_get;
	audio_input_kcontrol_func.audio_stream_info_put
			= audio_stream_info_put;
	audio_input_kcontrol_func.audio_current_state_get
			= audio_current_state_get;

	return ret;
}
