ds17485.c revision 1.2.8.2 1 1.2.8.2 matt /* $NetBSD: ds17485.c,v 1.2.8.2 2007/11/06 23:16:22 matt Exp $ */
2 1.2.8.2 matt
3 1.2.8.2 matt /*
4 1.2.8.2 matt * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.2.8.2 matt * All rights reserved.
6 1.2.8.2 matt *
7 1.2.8.2 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.2.8.2 matt * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
9 1.2.8.2 matt *
10 1.2.8.2 matt * Redistribution and use in source and binary forms, with or without
11 1.2.8.2 matt * modification, are permitted provided that the following conditions
12 1.2.8.2 matt * are met:
13 1.2.8.2 matt * 1. Redistributions of source code must retain the above copyright
14 1.2.8.2 matt * notice, this list of conditions and the following disclaimer.
15 1.2.8.2 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.8.2 matt * notice, this list of conditions and the following disclaimer in the
17 1.2.8.2 matt * documentation and/or other materials provided with the distribution.
18 1.2.8.2 matt * 3. All advertising materials mentioning features or use of this software
19 1.2.8.2 matt * must display the following acknowledgement:
20 1.2.8.2 matt * This product includes software developed by the NetBSD
21 1.2.8.2 matt * Foundation, Inc. and its contributors.
22 1.2.8.2 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.8.2 matt * contributors may be used to endorse or promote products derived
24 1.2.8.2 matt * from this software without specific prior written permission.
25 1.2.8.2 matt *
26 1.2.8.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.8.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.8.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.8.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.8.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.8.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.8.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.8.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.8.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.8.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.8.2 matt * POSSIBILITY OF SUCH DAMAGE.
37 1.2.8.2 matt */
38 1.2.8.2 matt
39 1.2.8.2 matt /*-
40 1.2.8.2 matt * Copyright (c) 1990 The Regents of the University of California.
41 1.2.8.2 matt * All rights reserved.
42 1.2.8.2 matt *
43 1.2.8.2 matt * This code is derived from software contributed to Berkeley by
44 1.2.8.2 matt * William Jolitz and Don Ahn.
45 1.2.8.2 matt *
46 1.2.8.2 matt * Redistribution and use in source and binary forms, with or without
47 1.2.8.2 matt * modification, are permitted provided that the following conditions
48 1.2.8.2 matt * are met:
49 1.2.8.2 matt * 1. Redistributions of source code must retain the above copyright
50 1.2.8.2 matt * notice, this list of conditions and the following disclaimer.
51 1.2.8.2 matt * 2. Redistributions in binary form must reproduce the above copyright
52 1.2.8.2 matt * notice, this list of conditions and the following disclaimer in the
53 1.2.8.2 matt * documentation and/or other materials provided with the distribution.
54 1.2.8.2 matt * 3. Neither the name of the University nor the names of its contributors
55 1.2.8.2 matt * may be used to endorse or promote products derived from this software
56 1.2.8.2 matt * without specific prior written permission.
57 1.2.8.2 matt *
58 1.2.8.2 matt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.2.8.2 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.2.8.2 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.2.8.2 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.2.8.2 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.2.8.2 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.2.8.2 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.2.8.2 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.2.8.2 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.2.8.2 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.2.8.2 matt * SUCH DAMAGE.
69 1.2.8.2 matt *
70 1.2.8.2 matt * @(#)clock.c 7.2 (Berkeley) 5/12/91
71 1.2.8.2 matt */
72 1.2.8.2 matt /*-
73 1.2.8.2 matt * Copyright (c) 1993, 1994 Charles M. Hannum.
74 1.2.8.2 matt *
75 1.2.8.2 matt * This code is derived from software contributed to Berkeley by
76 1.2.8.2 matt * William Jolitz and Don Ahn.
77 1.2.8.2 matt *
78 1.2.8.2 matt * Redistribution and use in source and binary forms, with or without
79 1.2.8.2 matt * modification, are permitted provided that the following conditions
80 1.2.8.2 matt * are met:
81 1.2.8.2 matt * 1. Redistributions of source code must retain the above copyright
82 1.2.8.2 matt * notice, this list of conditions and the following disclaimer.
83 1.2.8.2 matt * 2. Redistributions in binary form must reproduce the above copyright
84 1.2.8.2 matt * notice, this list of conditions and the following disclaimer in the
85 1.2.8.2 matt * documentation and/or other materials provided with the distribution.
86 1.2.8.2 matt * 3. All advertising materials mentioning features or use of this software
87 1.2.8.2 matt * must display the following acknowledgement:
88 1.2.8.2 matt * This product includes software developed by the University of
89 1.2.8.2 matt * California, Berkeley and its contributors.
90 1.2.8.2 matt * 4. Neither the name of the University nor the names of its contributors
91 1.2.8.2 matt * may be used to endorse or promote products derived from this software
92 1.2.8.2 matt * without specific prior written permission.
93 1.2.8.2 matt *
94 1.2.8.2 matt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
95 1.2.8.2 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 1.2.8.2 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 1.2.8.2 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
98 1.2.8.2 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99 1.2.8.2 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
100 1.2.8.2 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
101 1.2.8.2 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102 1.2.8.2 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103 1.2.8.2 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 1.2.8.2 matt * SUCH DAMAGE.
105 1.2.8.2 matt *
106 1.2.8.2 matt * @(#)clock.c 7.2 (Berkeley) 5/12/91
107 1.2.8.2 matt */
108 1.2.8.2 matt /*
109 1.2.8.2 matt * Mach Operating System
110 1.2.8.2 matt * Copyright (c) 1991,1990,1989 Carnegie Mellon University
111 1.2.8.2 matt * All Rights Reserved.
112 1.2.8.2 matt *
113 1.2.8.2 matt * Permission to use, copy, modify and distribute this software and its
114 1.2.8.2 matt * documentation is hereby granted, provided that both the copyright
115 1.2.8.2 matt * notice and this permission notice appear in all copies of the
116 1.2.8.2 matt * software, derivative works or modified versions, and any portions
117 1.2.8.2 matt * thereof, and that both notices appear in supporting documentation.
118 1.2.8.2 matt *
119 1.2.8.2 matt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
120 1.2.8.2 matt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
121 1.2.8.2 matt * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
122 1.2.8.2 matt *
123 1.2.8.2 matt * Carnegie Mellon requests users of this software to return to
124 1.2.8.2 matt *
125 1.2.8.2 matt * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
126 1.2.8.2 matt * School of Computer Science
127 1.2.8.2 matt * Carnegie Mellon University
128 1.2.8.2 matt * Pittsburgh PA 15213-3890
129 1.2.8.2 matt *
130 1.2.8.2 matt * any improvements or extensions that they make and grant Carnegie Mellon
131 1.2.8.2 matt * the rights to redistribute these changes.
132 1.2.8.2 matt */
133 1.2.8.2 matt /*
134 1.2.8.2 matt Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
135 1.2.8.2 matt
136 1.2.8.2 matt All Rights Reserved
137 1.2.8.2 matt
138 1.2.8.2 matt Permission to use, copy, modify, and distribute this software and
139 1.2.8.2 matt its documentation for any purpose and without fee is hereby
140 1.2.8.2 matt granted, provided that the above copyright notice appears in all
141 1.2.8.2 matt copies and that both the copyright notice and this permission notice
142 1.2.8.2 matt appear in supporting documentation, and that the name of Intel
143 1.2.8.2 matt not be used in advertising or publicity pertaining to distribution
144 1.2.8.2 matt of the software without specific, written prior permission.
145 1.2.8.2 matt
146 1.2.8.2 matt INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
147 1.2.8.2 matt INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
148 1.2.8.2 matt IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
149 1.2.8.2 matt CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
150 1.2.8.2 matt LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
151 1.2.8.2 matt NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
152 1.2.8.2 matt WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
153 1.2.8.2 matt */
154 1.2.8.2 matt
155 1.2.8.2 matt /*
156 1.2.8.2 matt * Primitive clock interrupt routines.
157 1.2.8.2 matt */
158 1.2.8.2 matt
159 1.2.8.2 matt #include <sys/cdefs.h>
160 1.2.8.2 matt __KERNEL_RCSID(0, "$NetBSD: ds17485.c,v 1.2.8.2 2007/11/06 23:16:22 matt Exp $");
161 1.2.8.2 matt
162 1.2.8.2 matt #include <sys/param.h>
163 1.2.8.2 matt #include <sys/systm.h>
164 1.2.8.2 matt #include <sys/kernel.h>
165 1.2.8.2 matt #include <sys/device.h>
166 1.2.8.2 matt
167 1.2.8.2 matt #include <machine/cpu.h>
168 1.2.8.2 matt #include <machine/intr.h>
169 1.2.8.2 matt #include <machine/bus.h>
170 1.2.8.2 matt
171 1.2.8.2 matt #include <dev/clock_subr.h>
172 1.2.8.2 matt #include <dev/ic/mc146818reg.h>
173 1.2.8.2 matt #include <dev/ic/mc146818var.h>
174 1.2.8.2 matt
175 1.2.8.2 matt #include <arch/evbppc/pmppc/dev/mainbus.h>
176 1.2.8.2 matt #include <machine/pmppc.h>
177 1.2.8.2 matt
178 1.2.8.2 matt static int rtc_match(struct device *, struct cfdata *, void *);
179 1.2.8.2 matt static void rtc_attach(struct device *, struct device *, void *);
180 1.2.8.2 matt
181 1.2.8.2 matt static u_int rtc_read(struct mc146818_softc *, u_int);
182 1.2.8.2 matt static void rtc_write(struct mc146818_softc *, u_int, u_int);
183 1.2.8.2 matt
184 1.2.8.2 matt CFATTACH_DECL(rtc, sizeof(struct mc146818_softc),
185 1.2.8.2 matt rtc_match, rtc_attach, NULL, NULL);
186 1.2.8.2 matt
187 1.2.8.2 matt static int rtc_attached = 0;
188 1.2.8.2 matt int
189 1.2.8.2 matt rtc_match(struct device *parent, struct cfdata *cf, void *aux)
190 1.2.8.2 matt {
191 1.2.8.2 matt struct mainbus_attach_args *maa = aux;
192 1.2.8.2 matt
193 1.2.8.2 matt return (!rtc_attached && strcmp(maa->mb_name, "rtc") == 0);
194 1.2.8.2 matt }
195 1.2.8.2 matt
196 1.2.8.2 matt void
197 1.2.8.2 matt rtc_attach(struct device *parent, struct device *self, void *aux)
198 1.2.8.2 matt {
199 1.2.8.2 matt struct mc146818_softc *sc = (struct mc146818_softc *)self;
200 1.2.8.2 matt struct mainbus_attach_args *maa = aux;
201 1.2.8.2 matt
202 1.2.8.2 matt sc->sc_bst = maa->mb_bt;
203 1.2.8.2 matt if (bus_space_map(sc->sc_bst, maa->mb_addr, PMPPC_RTC_SIZE, 0,
204 1.2.8.2 matt &sc->sc_bsh)) {
205 1.2.8.2 matt printf("%s: can't map i/o space\n", self->dv_xname);
206 1.2.8.2 matt return;
207 1.2.8.2 matt }
208 1.2.8.2 matt
209 1.2.8.2 matt rtc_attached = 1;
210 1.2.8.2 matt #ifdef DEBUG
211 1.2.8.2 matt rtc_print();
212 1.2.8.2 matt #endif
213 1.2.8.2 matt rtc_write(sc, MC_REGA, MC_BASE_32_KHz | MC_RATE_1024_Hz);
214 1.2.8.2 matt rtc_write(sc, MC_REGB, MC_REGB_24HR);
215 1.2.8.2 matt
216 1.2.8.2 matt sc->sc_mcread = rtc_read;
217 1.2.8.2 matt sc->sc_mcwrite = rtc_write;
218 1.2.8.2 matt sc->sc_flag = 0;
219 1.2.8.2 matt sc->sc_year0 = 1900;
220 1.2.8.2 matt mc146818_attach(sc);
221 1.2.8.2 matt
222 1.2.8.2 matt todr_attach(&sc->sc_handle);
223 1.2.8.2 matt /* printf(": Dallas Semiconductor DS17485\n"); */
224 1.2.8.2 matt printf("\n");
225 1.2.8.2 matt }
226 1.2.8.2 matt
227 1.2.8.2 matt u_int
228 1.2.8.2 matt rtc_read(struct mc146818_softc *sc, u_int reg)
229 1.2.8.2 matt {
230 1.2.8.2 matt
231 1.2.8.2 matt return (bus_space_read_1(sc->sc_bst, sc->sc_bsh, reg));
232 1.2.8.2 matt }
233 1.2.8.2 matt
234 1.2.8.2 matt void
235 1.2.8.2 matt rtc_write(struct mc146818_softc *sc, u_int reg, u_int datum)
236 1.2.8.2 matt {
237 1.2.8.2 matt
238 1.2.8.2 matt bus_space_write_1(sc->sc_bst, sc->sc_bsh, reg, datum);
239 1.2.8.2 matt }
240