2 * Machine dependent access functions for RTC registers.
4 #ifndef _ASM_MC146818RTC_H
5 #define _ASM_MC146818RTC_H
7 #ifdef CONFIG_SH_MPC1211
8 #undef _ASM_MC146818RTC_H
10 #include <asm/mpc1211/mc146818rtc.h>
15 #define RTC_ALWAYS_BCD 1
17 /* FIXME:RTC Interrupt feature is not implemented yet. */
21 #if defined(CONFIG_CPU_SH3)
22 #define RTC_PORT(n) (R64CNT+(n)*2)
23 #define CMOS_READ(addr) __CMOS_READ(addr,b)
24 #define CMOS_WRITE(val,addr) __CMOS_WRITE(val,addr,b)
26 #elif defined(CONFIG_SH_SECUREEDGE5410)
27 #include <asm/snapgear/io.h>
29 #define RTC_PORT(n) SECUREEDGE_IOPORT_ADDR
30 #define CMOS_READ(addr) secureedge5410_cmos_read(addr)
31 #define CMOS_WRITE(val,addr) secureedge5410_cmos_write(val,addr)
32 extern unsigned char secureedge5410_cmos_read(int addr
);
33 extern void secureedge5410_cmos_write(unsigned char val
, int addr
);
35 #elif defined(CONFIG_CPU_SH4)
36 #define RTC_PORT(n) (R64CNT+(n)*4)
37 #define CMOS_READ(addr) __CMOS_READ(addr,w)
38 #define CMOS_WRITE(val,addr) __CMOS_WRITE(val,addr,w)
41 #define __CMOS_READ(addr, s) ({ \
42 unsigned char val=0, rcr1, rcr2, r64cnt, retry; \
45 val = ctrl_inb(RSECCNT); \
47 case RTC_SECONDS_ALARM: \
48 val = ctrl_inb(RSECAR); \
51 val = ctrl_inb(RMINCNT); \
53 case RTC_MINUTES_ALARM: \
54 val = ctrl_inb(RMINAR); \
57 val = ctrl_inb(RHRCNT); \
59 case RTC_HOURS_ALARM: \
60 val = ctrl_inb(RHRAR); \
62 case RTC_DAY_OF_WEEK: \
63 val = ctrl_inb(RWKCNT); \
65 case RTC_DAY_OF_MONTH: \
66 val = ctrl_inb(RDAYCNT); \
69 val = ctrl_inb(RMONCNT); \
72 val = ctrl_in##s(RYRCNT); \
74 case RTC_REG_A: /* RTC_FREQ_SELECT */ \
75 rcr2 = ctrl_inb(RCR2); \
76 val = (rcr2 & RCR2_PESMASK) >> 4; \
77 rcr1 = ctrl_inb(RCR1); \
78 rcr1 = (rcr1 & (RCR1_CIE | RCR1_AIE)) | RCR1_AF;\
81 ctrl_outb(rcr1, RCR1); /* clear CF */ \
82 r64cnt = ctrl_inb(R64CNT); \
83 } while((ctrl_inb(RCR1) & RCR1_CF) && retry++ < 1000);\
84 r64cnt ^= RTC_BIT_INVERTED; \
85 if(r64cnt == 0x7f || r64cnt == 0) \
88 case RTC_REG_B: /* RTC_CONTROL */ \
89 rcr1 = ctrl_inb(RCR1); \
90 rcr2 = ctrl_inb(RCR2); \
91 if(rcr1 & RCR1_CIE) val |= RTC_UIE; \
92 if(rcr1 & RCR1_AIE) val |= RTC_AIE; \
93 if(rcr2 & RCR2_PESMASK) val |= RTC_PIE; \
94 if(!(rcr2 & RCR2_START))val |= RTC_SET; \
97 case RTC_REG_C: /* RTC_INTR_FLAGS */ \
98 rcr1 = ctrl_inb(RCR1); \
99 rcr1 &= ~(RCR1_CF | RCR1_AF); \
100 ctrl_outb(rcr1, RCR1); \
101 rcr2 = ctrl_inb(RCR2); \
103 ctrl_outb(rcr2, RCR2); \
105 case RTC_REG_D: /* RTC_VALID */ \
106 /* Always valid ... */ \
115 #define __CMOS_WRITE(val, addr, s) ({ \
116 unsigned char rcr1,rcr2; \
119 ctrl_outb(val, RSECCNT); \
121 case RTC_SECONDS_ALARM: \
122 ctrl_outb(val, RSECAR); \
125 ctrl_outb(val, RMINCNT); \
127 case RTC_MINUTES_ALARM: \
128 ctrl_outb(val, RMINAR); \
131 ctrl_outb(val, RHRCNT); \
133 case RTC_HOURS_ALARM: \
134 ctrl_outb(val, RHRAR); \
136 case RTC_DAY_OF_WEEK: \
137 ctrl_outb(val, RWKCNT); \
139 case RTC_DAY_OF_MONTH: \
140 ctrl_outb(val, RDAYCNT); \
143 ctrl_outb(val, RMONCNT); \
146 ctrl_out##s((ctrl_in##s(RYRCNT) & 0xff00) | (val & 0xff), RYRCNT);\
148 case RTC_REG_A: /* RTC_FREQ_SELECT */ \
149 rcr2 = ctrl_inb(RCR2); \
150 if((val & RTC_DIV_CTL) == RTC_DIV_RESET2) \
151 rcr2 |= RCR2_RESET; \
152 ctrl_outb(rcr2, RCR2); \
154 case RTC_REG_B: /* RTC_CONTROL */ \
155 rcr1 = (ctrl_inb(RCR1) & 0x99) | RCR1_AF; \
156 if(val & RTC_AIE) rcr1 |= RCR1_AIE; \
157 else rcr1 &= ~RCR1_AIE; \
158 if(val & RTC_UIE) rcr1 |= RCR1_CIE; \
159 else rcr1 &= ~RCR1_CIE; \
160 ctrl_outb(rcr1, RCR1); \
161 rcr2 = ctrl_inb(RCR2); \
162 if(val & RTC_SET) rcr2 &= ~RCR2_START; \
163 else rcr2 |= RCR2_START; \
164 ctrl_outb(rcr2, RCR2); \
166 case RTC_REG_C: /* RTC_INTR_FLAGS */ \
168 case RTC_REG_D: /* RTC_VALID */ \
175 #endif /* CONFIG_SH_MPC1211 */
176 #endif /* _ASM_MC146818RTC_H */