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