1/* $Id: rtc.h,v 1.1.1.1 2008/10/15 03:29:02 james26_jang Exp $ */ 2 3#ifndef __RTC_H__ 4#define __RTC_H__ 5 6 7#include <linux/config.h> 8 9#ifdef CONFIG_ETRAX_DS1302 10 /* Dallas DS1302 clock/calendar register numbers. */ 11# define RTC_SECONDS 0 12# define RTC_MINUTES 1 13# define RTC_HOURS 2 14# define RTC_DAY_OF_MONTH 3 15# define RTC_MONTH 4 16# define RTC_WEEKDAY 5 17# define RTC_YEAR 6 18# define RTC_CONTROL 7 19 20 /* Bits in CONTROL register. */ 21# define RTC_CONTROL_WRITEPROTECT 0x80 22# define RTC_TRICKLECHARGER 8 23 24 /* Bits in TRICKLECHARGER register TCS TCS TCS TCS DS DS RS RS. */ 25# define RTC_TCR_PATTERN 0xA0 /* 1010xxxx */ 26# define RTC_TCR_1DIOD 0x04 /* xxxx01xx */ 27# define RTC_TCR_2DIOD 0x08 /* xxxx10xx */ 28# define RTC_TCR_DISABLED 0x00 /* xxxxxx00 Disabled */ 29# define RTC_TCR_2KOHM 0x01 /* xxxxxx01 2KOhm */ 30# define RTC_TCR_4KOHM 0x02 /* xxxxxx10 4kOhm */ 31# define RTC_TCR_8KOHM 0x03 /* xxxxxx11 8kOhm */ 32 33#elif defined(CONFIG_ETRAX_PCF8563) 34 /* I2C bus slave registers. */ 35# define RTC_I2C_READ 0xa3 36# define RTC_I2C_WRITE 0xa2 37 38 /* Phillips PCF8563 registers. */ 39# define RTC_CONTROL1 0x00 /* Control/Status register 1. */ 40# define RTC_CONTROL2 0x01 /* Control/Status register 2. */ 41# define RTC_CLOCKOUT_FREQ 0x0d /* CLKOUT frequency. */ 42# define RTC_TIMER_CONTROL 0x0e /* Timer control. */ 43# define RTC_TIMER_CNTDOWN 0x0f /* Timer countdown. */ 44 45 /* BCD encoded clock registers. */ 46# define RTC_SECONDS 0x02 47# define RTC_MINUTES 0x03 48# define RTC_HOURS 0x04 49# define RTC_DAY_OF_MONTH 0x05 50# define RTC_WEEKDAY 0x06 /* Not coded in BCD! */ 51# define RTC_MONTH 0x07 52# define RTC_YEAR 0x08 53# define RTC_MINUTE_ALARM 0x09 54# define RTC_HOUR_ALARM 0x0a 55# define RTC_DAY_ALARM 0x0b 56# define RTC_WEEKDAY_ALARM 0x0c 57 58#endif 59 60#ifdef CONFIG_ETRAX_DS1302 61# define CMOS_READ(x) ds1302_readreg(x) 62# define CMOS_WRITE(val,reg) ds1302_writereg(reg,val) 63# define RTC_INIT() ds1302_init() 64#elif defined(CONFIG_ETRAX_PCF8563) 65# define CMOS_READ(x) i2c_readreg(RTC_I2C_READ, x) 66# define CMOS_WRITE(val,reg) i2c_writereg(RTC_I2C_WRITE,reg,val) 67# define RTC_INIT() pcf8563_init() 68#else 69 /* No RTC configured so we shouldn't try to access any. */ 70# define CMOS_READ(x) 42 71# define CMOS_WRITE(x,y) 72# define RTC_INIT() (-1) 73#endif 74 75/* Conversions to and from the RTC BCD encoded format. */ 76#define BCD_TO_BIN(x) ((x)=((x)&15) + ((x)>>4)*10) 77#define BIN_TO_BCD(x) ((x)=(((x)/10)<<4) + (x)%10) 78 79/* 80 * The struct used to pass data via the following ioctl. Similar to the 81 * struct tm in <time.h>, but it needs to be here so that the kernel 82 * source is self contained, allowing cross-compiles, etc. etc. 83 */ 84struct rtc_time { 85 int tm_sec; 86 int tm_min; 87 int tm_hour; 88 int tm_mday; 89 int tm_mon; 90 int tm_year; 91 int tm_wday; 92 int tm_yday; 93 int tm_isdst; 94}; 95 96/* ioctl() calls that are permitted to the /dev/rtc interface. */ 97#ifdef CONFIG_ETRAX_DS1302 98# define DS1302_MAGIC 'p' 99# define RTC_RD_TIME _IOR(DS1302_MAGIC, 0x09, struct rtc_time) /* Read RTC time. */ 100# define RTC_SET_TIME _IOW(DS1302_MAGIC, 0x0a, struct rtc_time) /* Set RTC time. */ 101# define RTC_SET_CHARGE _IOW(DS1302_MAGIC, 0x0b, int) /* Set CHARGE mode. */ 102#elif defined(CONFIG_ETRAX_PCF8563) 103# define PCF8563_MAGIC 'T' 104# define RTC_RD_TIME _IOR(PCF8563_MAGIC, 0x01, struct rtc_time) /* Read RTC time. */ 105# define RTC_SET_TIME _IOW(PCF8563_MAGIC, 0x02, struct rtc_time) /* Set RTC time. */ 106# define RTC_SET_CHARGE _IOW(PCF8563_MAGIC, 0x03, int) 107# define RTC_MAX_IOCTL 3 108#endif 109 110#endif /* __RTC_H__ */ 111