// SPDX-License-Identifier: GPL-2.0
/*
 * audio_output_control_interface.c  --  Mediatek Soundbar kcontrol
 *
 * Copyright (c) 2020 MediaTek Inc.
 * Author: Wen Cai <wen.cai@mediatek.com>
 *
 */

#include "audio_output_control_impl.h"
#include "audio_output_control_interface.h"
struct audio_output_kcontrol_func_type audio_output_kcontrol_func;
static int speaker_mute_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	ucontrol->value.enumerated.item[0] = impl_speaker_mute_get();
	return 0;
}

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

	impl_speaker_mute_put(value);
	return 0;
}

static int audio_out_sample_rate_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	ucontrol->value.integer.value[0] = impl_audio_out_sample_rate_get();
	return 0;
}

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

	impl_audio_out_sample_rate_put(value);
	return 0;
}

static int audio_out_chmap_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct audio_out_chmap_t audio_out_chmap = {0};
	int i = 0;

	impl_audio_out_chmap_get(&audio_out_chmap);
	for (i = 0; i < MAX_AUDIO_OUT_CH; i++)
		ucontrol->value.integer.value[i] = audio_out_chmap.chmap[i];

	return 0;
}

static int audio_out_chmap_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct audio_out_chmap_t audio_out_chmap;
	int i = 0;

	for (i = 0; i < MAX_AUDIO_OUT_CH; i++)
		audio_out_chmap.chmap[i] = ucontrol->value.integer.value[i];

	impl_audio_out_chmap_put(&audio_out_chmap);
	return 0;
}

static int main_out_gain_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	ucontrol->value.integer.value[0] = impl_main_out_gain_get();
	return 0;
}

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

	impl_main_out_gain_put(value);
	return 0;
}

static int main_out_gain2_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	ucontrol->value.integer.value[0] = impl_main_out_gain2_get();
	return 0;
}

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

	impl_main_out_gain2_put(value);
	return 0;
}

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

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

	impl_mixer_mute_put(value);
	return 0;
}


int audio_output_kcontrol_init(void)
{
	impl_audio_output_initialize();
	return 0;
}

int reg_audio_output_control_func(void)
{
	int ret = 0;

	audio_output_kcontrol_func.audio_out_mute_i2stx1_get = speaker_mute_get;
	audio_output_kcontrol_func.audio_out_mute_i2stx1_put = speaker_mute_put;
	audio_output_kcontrol_func.audio_out_sample_rate_get
			= audio_out_sample_rate_get;
	audio_output_kcontrol_func.audio_out_sample_rate_put
			= audio_out_sample_rate_put;
	audio_output_kcontrol_func.audio_out_chmap_get = audio_out_chmap_get;
	audio_output_kcontrol_func.audio_out_chmap_put = audio_out_chmap_put;
	audio_output_kcontrol_func.main_out_gain_get = main_out_gain_get;
	audio_output_kcontrol_func.main_out_gain_put = main_out_gain_put;
	audio_output_kcontrol_func.main_out_gain2_get = main_out_gain2_get;
	audio_output_kcontrol_func.main_out_gain2_put = main_out_gain2_put;
	audio_output_kcontrol_func.mixer_mute_get = mixer_mute_get;
	audio_output_kcontrol_func.mixer_mute_put = mixer_mute_put;

	return ret;
}



