/*************************************************************************
 *	Copyright (C), 2014-2016, GenVision Tech. Co., Ltd
 *	File Name: /home/magiche/3254cfg.c
 *	Author: HeYabin        Mail: heyb@genvision.cn
 *	Version: V1.0.0
 *	Date: 2016-10-13 Thu 13:54
 *	Description:
 *	History:
 ************************************************************************/

/*
 * ===  FUNCTION  ===============================================================
 *         Name:  i2c_aic3254_cfg
 *  Description:
 * 		 Return:  0-success; 	1-failed
 * ==============================================================================
 */
int i2c_aic3254_cfg(DM8168_I2cHndl *i2cHndl) {
	t_i2c_reg *regs;

	regs = (t_i2c_reg *) i2c_aic3254;

	while (!(regs->reg_off == 0 && regs->reg_value == 0xFF)) {
		if (regs->reg_off == 254) {
			usleep(1000 * regs->reg_value);
			regs++;
			continue;
		}
		if (regs->reg_off == 255) {
			if (regs->reg_value == 0) {
				miniDSP_A_deal(i2cHndl);
				regs++;
			} else if (regs->reg_value == 1) {
				miniDSP_D_deal(i2cHndl);
				regs++;
			}
			continue;
		}
		DM8168_i2cWrite8(i2cHndl,
		I2C_AIC3254_ADDRESS, &regs->reg_off, &regs->reg_value, 1);
		regs++;
	}

	printf("g_audio_aic3254.ADC_L.reg = %d, value = %d\n", g_audio_aic3254.ADC_L.reg, g_audio_aic3254.ADC_L.value);
	printf("g_audio_aic3254.ADC_R.reg = %d, value = %d\n", g_audio_aic3254.ADC_R.reg, g_audio_aic3254.ADC_R.value);
	printf("g_audio_aic3254.MicPGA_L.reg = %d, value = %d\n", g_audio_aic3254.MicPGA_L.reg, g_audio_aic3254.MicPGA_L.value);
	printf("g_audio_aic3254.MicPGA_R.reg = %d, value = %d\n", g_audio_aic3254.MicPGA_R.reg, g_audio_aic3254.MicPGA_R.value);
	printf("g_audio_aic3254.HeadPhone_L.reg = %d, value = %d\n", g_audio_aic3254.HeadPhone_L.reg,
			g_audio_aic3254.HeadPhone_L.value);
	printf("g_audio_aic3254.HeadPhone_R.reg = %d, value = %d\n", g_audio_aic3254.HeadPhone_R.reg,
			g_audio_aic3254.HeadPhone_R.value);
	printf("g_audio_aic3254.MicBias.reg = %d, value = %d\n", g_audio_aic3254.MicBias.reg, g_audio_aic3254.MicBias.value);
//	printf("g_audio_aic3254.ADC_L.reg = %d, value = %d\n", g_audio_aic3254.ADC_L.reg, g_audio_aic3254.ADC_L.value);

	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.Page_Select_ADC.reg, &g_audio_aic3254.Page_Select_ADC.value,
			1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.ADC_L.reg, &g_audio_aic3254.ADC_L.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.ADC_R.reg, &g_audio_aic3254.ADC_R.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.Page_Select_MicPGA.reg,
			&g_audio_aic3254.Page_Select_MicPGA.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.MicPGA_L.reg, &g_audio_aic3254.MicPGA_L.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.MicPGA_R.reg, &g_audio_aic3254.MicPGA_R.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.Page_Select_HeadPhone.reg,
			&g_audio_aic3254.Page_Select_HeadPhone.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.HeadPhone_L.reg, &g_audio_aic3254.HeadPhone_L.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.HeadPhone_R.reg, &g_audio_aic3254.HeadPhone_R.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.Page_Select_MicBias.reg,
			&g_audio_aic3254.Page_Select_MicBias.value, 1);
	DM8168_i2cWrite8(i2cHndl, I2C_AIC3254_ADDRESS, &g_audio_aic3254.MicBias.reg, &g_audio_aic3254.MicBias.value, 1);

	return 0;
} /* -----  end of function i2c_aic3254_cfg  ----- */

