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