ds1286reg.h revision 1.6 1 1.6 perry /* $NetBSD: ds1286reg.h,v 1.6 2005/02/04 02:10:36 perry Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 2001 Rafal K. Boni
5 1.1 thorpej *
6 1.1 thorpej * Redistribution and use in source and binary forms, with or without
7 1.1 thorpej * modification, are permitted provided that the following conditions
8 1.1 thorpej * are met:
9 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
10 1.1 thorpej * notice, this list of conditions and the following disclaimer.
11 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
13 1.1 thorpej * documentation and/or other materials provided with the distribution.
14 1.1 thorpej * 3. The name of the author may not be used to endorse or promote products
15 1.1 thorpej * derived from this software without specific prior written permission.
16 1.1 thorpej *
17 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 thorpej */
28 1.1 thorpej
29 1.1 thorpej /*
30 1.1 thorpej * Originally based on mc146818reg.h, with the following license:
31 1.1 thorpej *
32 1.1 thorpej * Copyright (c) 1995 Carnegie-Mellon University.
33 1.1 thorpej * All rights reserved.
34 1.1 thorpej *
35 1.1 thorpej * Permission to use, copy, modify and distribute this software and
36 1.1 thorpej * its documentation is hereby granted, provided that both the copyright
37 1.1 thorpej * notice and this permission notice appear in all copies of the
38 1.1 thorpej * software, derivative works or modified versions, and any portions
39 1.1 thorpej * thereof, and that both notices appear in supporting documentation.
40 1.1 thorpej *
41 1.1 thorpej * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
42 1.1 thorpej * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
43 1.1 thorpej * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
44 1.1 thorpej *
45 1.1 thorpej * Carnegie Mellon requests users of this software to return to
46 1.1 thorpej *
47 1.1 thorpej * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
48 1.1 thorpej * School of Computer Science
49 1.1 thorpej * Carnegie Mellon University
50 1.1 thorpej * Pittsburgh PA 15213-3890
51 1.1 thorpej *
52 1.1 thorpej * any improvements or extensions that they make and grant Carnegie the
53 1.1 thorpej * rights to redistribute these changes.
54 1.1 thorpej */
55 1.1 thorpej
56 1.1 thorpej /*
57 1.1 thorpej * Definitions for the Dallas Semiconductor DS1286/DS1386 Real Time Clock.
58 1.1 thorpej *
59 1.1 thorpej * Plucked right from the Dallas Semicomductor specs available at
60 1.2 kleink * http://pdfserv.maxim-ic.com/arpdf/DS1286.pdf and
61 1.2 kleink * http://pdfserv.maxim-ic.com/arpdf/DS1386-DS1386P.pdf
62 1.1 thorpej *
63 1.1 thorpej * The DS1286 and 1386 have 14 clock-related registers and some amount
64 1.1 thorpej * of user registers (50 for the 1286, 8K or 32K for the 1386). The
65 1.1 thorpej * first eleven registers contain time-of-day and alarm data, the rest
66 1.1 thorpej * contain various control bits and the watchdog timer functionality.
67 1.1 thorpej *
68 1.1 thorpej * Since the locations of these ports and the method used to access
69 1.1 thorpej * them can be machine-dependent, the low-level details of reading
70 1.1 thorpej * and writing the RTC's registers are handled by machine-specific
71 1.1 thorpej * functions.
72 1.1 thorpej *
73 1.4 rafal * The DS1286/DS1386 chips always store time-of-day and alarm data in
74 1.4 rafal * BCD. The "hour" time-of-year and alarm fields can either be stored
75 1.4 rafal * in AM/PM format, or in 24-hour format. If AM/PM format is chosen,
76 1.4 rafal * the hour fields can have the values: 1-12 (for AM) and 21-32 (for
77 1.4 rafal * PM). If the 24-hour format is chosen, they can have the values 0
78 1.4 rafal * to 23. The hour format is selectable separately for the time and
79 1.4 rafal * alarm fields, and is controller by bit 6 of the respective register.
80 1.1 thorpej */
81 1.1 thorpej
82 1.1 thorpej /*
83 1.1 thorpej * The registers, and the bits within each register.
84 1.1 thorpej */
85 1.1 thorpej
86 1.4 rafal #define DS1286_SUBSEC 0x0 /* Time of year: hundredths of seconds (0-99) */
87 1.4 rafal #define DS1286_SEC 0x1 /* Time of year: seconds (0-59) */
88 1.4 rafal #define DS1286_MIN 0x2 /* Time of year: minutes (0-59) */
89 1.4 rafal #define DS1286_AMIN 0x3 /* Alarm: minutes */
90 1.4 rafal #define DS1286_HOUR 0x4 /* Time of year: hour (see above) */
91 1.4 rafal
92 1.4 rafal #define DS1286_HOUR_12MODE 0x40 /* Hour mode: 12-hour (on), 24 (off) */
93 1.4 rafal #define DS1286_HOUR_12HR_PM 0x20 /* AM/PM in 12-hour mode: on = PM */
94 1.4 rafal #define DS1286_HOUR_12HR_MASK 0x1f /* Mask for hours in 12hour mode */
95 1.4 rafal #define DS1286_HOUR_24HR_MASK 0x3f /* Mask for hours in 24hour mode */
96 1.4 rafal
97 1.4 rafal #define DS1286_AHOUR 0x5 /* Alarm: hour */
98 1.4 rafal #define DS1286_DOW 0x6 /* Time of year: day of week (1-7) */
99 1.4 rafal #define DS1286_ADOW 0x7 /* Alarm: day of week (1-7) */
100 1.4 rafal #define DS1286_DOM 0x8 /* Time of year: day of month (1-31) */
101 1.4 rafal #define DS1286_MONTH 0x9 /* Time of year: month (1-12), wave generator */
102 1.4 rafal
103 1.4 rafal #define DS1286_MONTH_MASK 0x3f /* Mask to extract month */
104 1.4 rafal #define DS1286_WAVEGEN_MASK 0xc0 /* Mask to extract wave bits */
105 1.4 rafal
106 1.4 rafal #define DS1286_YEAR 0xA /* Time of year: year in century (0-99) */
107 1.4 rafal
108 1.4 rafal #define DS1286_CONTROL 0xB /* Control register A */
109 1.4 rafal
110 1.4 rafal #define DS1286_TE 0x80 /* Update in progress (on == disable update) */
111 1.4 rafal #define DS1286_INTSWAP 0x40 /* Swap INTA, INTB outputs */
112 1.4 rafal #define DS1286_INTBSRC 0x20 /* INTB source (on) or sink (off) current */
113 1.4 rafal #define DS1286_INTAPLS 0x10 /* INTA pulse (on) or level (off) mode */
114 1.4 rafal #define DS1286_WAM 0x08 /* Watchdog alarm mask */
115 1.4 rafal #define DS1286_TDM 0x04 /* Time-of-day alarm mask */
116 1.4 rafal #define DS1286_WAF 0x02 /* Watchdog alarm flag */
117 1.4 rafal #define DS1286_TDF 0x01 /* Time-of-day alarm flag */
118 1.1 thorpej
119 1.4 rafal #define DS1286_NREGS 0xd /* 14 registers; CMOS follows */
120 1.4 rafal #define DS1286_NTODREGS 0xb /* 11 of those regs are for TOD and alarm */
121 1.1 thorpej
122 1.4 rafal #define DS1286_NVRAM_START 0xe /* start of NVRAM: offset 14 */
123 1.1 thorpej
124 1.1 thorpej /* NVRAM size depends on the chip -- the 1286 only has 50 bytes, whereas
125 1.1 thorpej * the 1386 can have 8K or 32K
126 1.1 thorpej */
127 1.4 rafal #define DS1286_NVRAM_SIZE 50 /* 50 bytes of NVRAM */
128 1.1 thorpej
129 1.1 thorpej /*
130 1.1 thorpej * RTC register/NVRAM read and write functions -- machine-dependent.
131 1.1 thorpej * Appropriately manipulate RTC registers to get/put data values.
132 1.1 thorpej */
133 1.6 perry u_int ds1286_read(void *, u_int);
134 1.6 perry void ds1286_write(void *, u_int, u_int);
135 1.1 thorpej
136 1.1 thorpej /*
137 1.1 thorpej * A collection of TOD/Alarm registers.
138 1.1 thorpej */
139 1.4 rafal typedef u_int ds1286_todregs[DS1286_NTODREGS];
140 1.1 thorpej
141 1.1 thorpej /*
142 1.1 thorpej * Get all of the TOD/Alarm registers
143 1.1 thorpej * Must be called at splhigh(), and with the RTC properly set up.
144 1.1 thorpej */
145 1.1 thorpej #define DS1286_GETTOD(sc, regs) \
146 1.1 thorpej do { \
147 1.1 thorpej int i; \
148 1.1 thorpej u_int ctl; \
149 1.1 thorpej \
150 1.1 thorpej /* turn off update for now */ \
151 1.4 rafal ctl = ds1286_read(sc, DS1286_CONTROL); \
152 1.4 rafal ds1286_write(sc, DS1286_CONTROL, ctl | DS1286_TE); \
153 1.1 thorpej \
154 1.1 thorpej /* read all of the tod/alarm regs */ \
155 1.4 rafal for (i = 0; i < DS1286_NTODREGS; i++) \
156 1.1 thorpej (*regs)[i] = ds1286_read(sc, i); \
157 1.1 thorpej \
158 1.1 thorpej /* turn update back on */ \
159 1.4 rafal ds1286_write(sc, DS1286_CONTROL, ctl); \
160 1.1 thorpej } while (0);
161 1.1 thorpej
162 1.1 thorpej /*
163 1.1 thorpej * Set all of the TOD/Alarm registers
164 1.1 thorpej * Must be called at splhigh(), and with the RTC properly set up.
165 1.1 thorpej */
166 1.1 thorpej #define DS1286_PUTTOD(sc, regs) \
167 1.1 thorpej do { \
168 1.1 thorpej int i; \
169 1.1 thorpej u_int ctl; \
170 1.1 thorpej \
171 1.1 thorpej /* turn off update for now */ \
172 1.4 rafal ctl = ds1286_read(sc, DS1286_CONTROL); \
173 1.4 rafal ds1286_write(sc, DS1286_CONTROL, ctl | DS1286_TE); \
174 1.1 thorpej \
175 1.1 thorpej /* write all of the tod/alarm regs */ \
176 1.4 rafal for (i = 0; i < DS1286_NTODREGS; i++) \
177 1.1 thorpej ds1286_write(sc, i, (*regs)[i]); \
178 1.1 thorpej \
179 1.1 thorpej /* turn update back on */ \
180 1.4 rafal ds1286_write(sc, DS1286_CONTROL, ctl); \
181 1.1 thorpej } while (0);
182