/*
 * Copyright (c) 1996-2003 MIPS Technologies, Inc.
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * mk48t02.h -- MK48T02 Real Time Clock and Non-Volatile RAM
 */


#define TD_NVRAM_SIZE	0x7f8	

/* 
 * For endian independence we declare the registers to be 32-bits
 * wide, but note that the data will then always be in bits 31-24
 * and will have to be shifted down.
 */

struct td_clock {
  unsigned int	td_mem[TD_NVRAM_SIZE];	/* non-volatile ram */
  unsigned int	td_control;	/* control register */
  unsigned int	td_secs;	/* bcd seconds */
  unsigned int	td_mins;	/* bcd minutes */
  unsigned int	td_hours;	/* bcd hours */
  unsigned int	td_day;		/* bcd day (sunday = 1) */
  unsigned int	td_date;	/* bcd date (1-31) */
  unsigned int	td_month;	/* bcd month (1-12) */
  unsigned int	td_year;	/* bcd year (0-99) */
};

/* macro for assembler nvram access */
#define	TD_MEMX(x)	((x)<<2)

/*
 * 'nvram' locations for clock registers
 */
#define TD_CONTROL	0x7f8
#define TD_SECS		0x7f9
#define TD_MINS		0x7fa
#define	TD_HOURS	0x7fb
#define TD_DAY		0x7fc
#define TD_DATE		0x7fd
#define TD_MONTH	0x7fe
#define TD_YEAR		0x7ff

/*
 * Control register bit definitions
 */
#define	TDC_WRITE	0x80000000	/* write lock */
#define	TDC_READ	0x40000000	/* read lock */
#define TDC_CALIBRATE	0x3f000000	/* oscillator calibration */

/*
 * Seconds register bit definitions
 */
#define	TDS_STOP	0x80000000	/* stop oscillator */

/*
 * Hours register bit definitions
 */
#define	TDH_KICK	0x80000000	/* kick oscillator */

/*
 * Day register bit definitions
 */
#define	TDD_FRQTST	0x40000000	/* frequency test */
#define TDD_SUNDAY	1
