/* 2012-09-16: File added and changed by Sony Corporation */
/*
 * icx_dac.c
 *
 * Copyright 2011 Sony Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <common.h>

#ifdef CONFIG_ICX

#include <asm/errno.h>

#include "icx_nvp.h"
#include "icx_dac.h"


/*********************/
/*@ Global variables */
/*********************/

extern dac_ops_t dac_cs47l01_ops;

static dac_ops_t *dac_ops = NULL;


/********************/
/*@ Global routines */
/********************/

/*-----------------------------------------------------------------------------
 * Function : dac_init
 * Abstruct : Initialize DAC device
 * Input    : none
 * Returen  : 0 : OK / -ENODEV : NG
 *----------------------------------------------------------------------------*/
int dac_init(void)
{
	u_int dac_type;

	dac_type = nvp_get_sysinfo_dac();

	switch (dac_type) {

		/* CS47L01 */
		case NVP_SYSINFO_DAC_TBS:
			dac_ops = &dac_cs47l01_ops;
			break;

		default :
			break;
	}

	if (!dac_ops)
		return -ENODEV;

	dac_ops->power_on();

	return 0;
}

/*-----------------------------------------------------------------------------
 * Function : dac_exit
 * Abstruct : Shutdown DAC device
 * Input    : none
 * Returen  : none
 *----------------------------------------------------------------------------*/
void dac_exit(void)
{
	if (dac_ops && dac_ops->power_off)
		dac_ops->power_off();
}

/*-----------------------------------------------------------------------------
 * Function : dac_enable_mute
 * Abstruct : Enable mute
 * Input    : none
 * Returen  : none
 *----------------------------------------------------------------------------*/
void dac_enable_mute(void)
{
	if (dac_ops && dac_ops->enable_mute)
		dac_ops->enable_mute();
}

/*-----------------------------------------------------------------------------
 * Function : dac_disable_mute
 * Abstruct : Disable mute
 * Input    : none
 * Returen  : none
 *----------------------------------------------------------------------------*/
void dac_disable_mute(void)
{
	if (dac_ops && dac_ops->disable_mute) 
		dac_ops->disable_mute();
}

/*-----------------------------------------------------------------------------
 * Function : dac_beep_on
 * Abstruct : Sound a beep
 * Input    : period : period to sound a beep
 * Returen  : none
 *----------------------------------------------------------------------------*/
void dac_beep_on(unsigned int period)
{
	if (dac_ops && dac_ops->beep_on)
		dac_ops->beep_on(period);
}

/*-----------------------------------------------------------------------------
 * Function : dac_beep_off
 * Abstruct : Stop to sound a beep
 * Input    : none
 * Returen  : none
 *----------------------------------------------------------------------------*/
void dac_beep_off(void)
{
	if (dac_ops && dac_ops->beep_off) 
		dac_ops->beep_off();
}

/*-----------------------------------------------------------------------------
 * Function : dac_on_boot
 * Abstruct : on kernel boot (u-boot -> kernel)
 * Input    : none
 * Returen  : none
 *----------------------------------------------------------------------------*/
void dac_on_boot(void)
{
	if (dac_ops && dac_ops->on_boot)
		dac_ops->on_boot();
}

#endif /* CONFIG_ICX */
