/* mc146818K.h - 146818 RTC (Real Time Clock) */

/* Copyright 2010-2011 Kontron KGSC */
/* Copyright 1984-2001 Wind River Systems, Inc. */

/*
modification history
--------------------
02a,23jul10,edv  derived to RTC driver for Kontron
01c,13apr01,hdn  added macros for status register A, B, C, D.
01b,09nov93,vin  moved AUX_CLK_RATE_MIN and AUX_CLK_RATE_MAX macro definitions
                 to config.h
01a,17aug93,hdn	 written.
*/

#ifndef	__INCmc146818h
#define	__INCmc146818h

#ifdef __cplusplus
extern "C" {
#endif


#ifndef	_ASMLANGUAGE

typedef struct
    {
    int rate;
    char bits;
    } CLK_RATE;

#endif	/* _ASMLANGUAGE */



/* offset of calendar registers  */

#define MC146818_YEAR		0x09	/* Year Register */
#define MC146818_MONTH		0x08	/* Month Register */
#define MC146818_DATE		0x07	/* Day of Month Register */
#define MC146818_DAY		0x06	/* Day of Week Register */
#define MC146818_HOUR		0x04	/* Hour Register */
#define MC146818_MIN		0x02	/* Minutes Register */
#define MC146818_SEC		0x00	/* Minutes Register */



/* offset of status register A, B, C, D */

#define MC146818_STATUS_A		0x0a	/* Status Register A */
#define MC146818_STATUS_B		0x0b	/* Status Register B */
#define MC146818_STATUS_C		0x0c	/* Status Register C */
#define MC146818_STATUS_D		0x0d	/* Status Register D */

/* bit values for status register A - RW except UIP */

#define MC146818_UIP			0x80	/* Update In Progress */
#define MC146818_DV_BITS		0x70	/* Divider Bits */
#define MC146818_RS_BITS		0x0f	/* Rate Selection Bits */

/* bit values for status register B - RW */

#define MC146818_SET			0x80	/* Set to 1 (abort update) */
#define MC146818_PIE			0x40	/* Periodic Int Enable */
#define MC146818_AIE			0x20	/* Alarm Int Enable */
#define MC146818_UIE			0x10	/* Update-ended Int Enable */
#define MC146818_SQWE			0x08	/* Square Wave Enable */
#define MC146818_DM			0x04	/* Date Mode */
#define MC146818_24			0x02	/* 1=24-hour 0=12-hour */
#define MC146818_DSE			0x01	/* Daylight Saving Enable */

/* bit values for status register C - R */

#define MC146818_IRQF			0x80	/* Int Request Flag */
#define MC146818_PF			0x40	/* Periodic Int Flag */
#define MC146818_AF			0x20	/* Alarm Int Flag */
#define MC146818_UF			0x10	/* Update-ended Int Flag */

/* bit values for status register D - R */

#define MC146818_VRT			0x80	/* Valid RAM and Time */


#define	BIN2BCD(b)	(((b)%10) | (((b)/10)<<4))
#define	BCD2BIN(b)	(((b)&0xf) + ((b)>>4)*10)

struct vxbRTCFunctionality
	{
    char	timerName[MAX_DRV_NAME_LEN + 1] ; /* timer Name */
	

	/*  get current date and times */
	STATUS (*rtcTimeGet)(VXB_DEVICE_ID, struct tm *);
	/*  set current date and times */
	STATUS (*rtcTimeSet)(VXB_DEVICE_ID, struct tm *);
	};

METHOD_DECL(vxbRtcGet);
METHOD_DECL(vxbRtcSet);

#ifdef __cplusplus
}
#endif

#endif	/* __INCmc146818h */
