1 /* $NetBSD: getsecs.c,v 1.2 2006/09/11 13:48:57 nonaka Exp $ */
6 #include <netinet/in.h>
7 #include <netinet/in_systm.h>
9 #include <lib/libsa/stand.h>
10 #include <lib/libsa/net.h>
11 #include <lib/libsa/netif.h>
12 #include <lib/libkern/libkern.h>
14 #include <sh3/devreg.h>
15 #include <sh3/scireg.h>
17 #include <dev/ic/rs5c313reg.h>
22 * Web page: http://www.ricoh.co.jp/LSI/product_rtc/3wire/5c313/
24 * How to control RS5C313 on LANDISK
25 * see http://www.mizore.jp/wiki/index.php?LANDISK/rtc
28 uint8_t rtc_read(uint32_t addr
);
29 void rtc_write(uint32_t addr
, uint8_t data
);
35 SHREG_SCSPTR
= SCSPTR_SPB1IO
| SCSPTR_SPB1DT
36 | SCSPTR_SPB0IO
| SCSPTR_SPB0DT
;
39 /* control RTC chip enable */
45 _reg_write_1(0xb0000003, (1 << 1));
47 _reg_write_1(0xb0000003, (0 << 1));
56 SHREG_SCSPTR
|= SCSPTR_SPB0DT
;
58 SHREG_SCSPTR
&= ~SCSPTR_SPB0DT
;
67 SHREG_SCSPTR
|= SCSPTR_SPB1IO
;
69 SHREG_SCSPTR
&= ~SCSPTR_SPB1IO
;
79 SHREG_SCSPTR
|= SCSPTR_SPB1DT
;
81 SHREG_SCSPTR
&= ~SCSPTR_SPB1DT
;
94 d
= (SHREG_SCSPTR
& SCSPTR_SPB1DT
) ? 1 : 0;
103 rtc_read(uint32_t addr
)
111 rtc_do(1); /* Don't care */
112 rtc_do(1); /* R/#W = 1(READ) */
113 rtc_do(1); /* AD = 1 */
114 rtc_do(0); /* DT = 0 */
115 rtc_do(addr
& 0x8); /* A3 */
116 rtc_do(addr
& 0x4); /* A2 */
117 rtc_do(addr
& 0x2); /* A1 */
118 rtc_do(addr
& 0x1); /* A0 */
125 data
= rtc_di(); /* D3 */
127 data
|= rtc_di(); /* D2 */
129 data
|= rtc_di(); /* D1 */
131 data
|= rtc_di(); /* D0 */
139 rtc_write(uint32_t addr
, uint8_t data
)
146 rtc_do(1); /* Don't care */
147 rtc_do(0); /* R/#W = 0(WRITE) */
148 rtc_do(1); /* AD = 1 */
149 rtc_do(0); /* DT = 0 */
150 rtc_do(addr
& 0x8); /* A3 */
151 rtc_do(addr
& 0x4); /* A2 */
152 rtc_do(addr
& 0x2); /* A1 */
153 rtc_do(addr
& 0x1); /* A0 */
155 rtc_do(1); /* Don't care */
156 rtc_do(0); /* R/#W = 0(WRITE) */
157 rtc_do(0); /* AD = 0 */
158 rtc_do(1); /* DT = 1 */
159 rtc_do(data
& 0x8); /* D3 */
160 rtc_do(data
& 0x4); /* D2 */
161 rtc_do(data
& 0x2); /* D1 */
162 rtc_do(data
& 0x1); /* D0 */
170 uint32_t sec
, min
, hour
, day
;
176 sec
= rtc_read(RS5C313_SEC1
);
177 sec
+= rtc_read(RS5C313_SEC10
) * 10;
178 min
= rtc_read(RS5C313_MIN1
);
179 min
+= rtc_read(RS5C313_MIN10
) * 10;
180 hour
= rtc_read(RS5C313_HOUR1
);
181 hour
+= rtc_read(RS5C313_HOUR10
) * 10;
182 day
= rtc_read(RS5C313_DAY1
);
183 day
+= rtc_read(RS5C313_DAY10
) * 10;
185 mon
= rtc_read(RS5C313_MON1
);
186 mon
+= rtc_read(RS5C313_MON10
) * 10;
187 year
= rtc_read(RS5C313_YEAR1
);
188 year
+= rtc_read(RS5C313_YEAR10
) * 10;
193 secs
+= hour
* 60 * 60;
194 secs
+= day
* 60 * 60 * 24;
200 printf("getsecs: secs = %d\n", (uint32_t)secs
);