/* 2012-09-16: File added and changed by Sony Corporation */
/*
 * icx_rtc.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_pwc.h"
#include "icx_rtc.h"


/*-----------------------------------------------------------------------------
 * Function : rtc_is_alarm
 * Abstruct : Check RTC alarm wake up
 * Input    : none
 * Returen  : 0 / 1 
 *----------------------------------------------------------------------------*/
int rtc_is_alarm(void)
{
	unsigned char rtc2_rd;

	if (pwc_read(PWC_RTC_RTC2_RD, &rtc2_rd) == 0)
		if (rtc2_rd & PWC_RTC_RTC2_AFG)
			return 1;
	
	return 0;
}

/*-----------------------------------------------------------------------------
 * Function : rtc_get_date
 * Abstruct : Get current date
 * Input    : data_buf : a buffer to be saved the data
 * Returen  : 0 : OK / others : NG
 *----------------------------------------------------------------------------*/
int rtc_get_date(rtc_date_t *date_buf)
{
	unsigned char data;
	int ret = 0;

	if (date_buf == NULL)
		return  -EINVAL;

	ret |= pwc_read(PWC_RTC_YEAR_RD,  &data);
	date_buf->year        = data;
	ret |= pwc_read(PWC_RTC_MONTH_RD, &data);
	date_buf->tm.e.month  = data;
	ret |= pwc_read(PWC_RTC_DAY_RD,   &data);
	date_buf->tm.e.day    = data;
	ret |= pwc_read(PWC_RTC_HOUR_RD,  &data);
	date_buf->tm.e.hour   = data;
	ret |= pwc_read(PWC_RTC_MIN_RD,   &data);
	date_buf->tm.e.minute = data;

	return ret;
}

#endif /* CONFIG_ICX */
