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