No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / sparc64 / dev / rtc.c
blob9a85f4b5c668a0747dce9fe4c8993cc54c2bb466
1 /* $NetBSD: rtc.c,v 1.5 2008/03/29 05:42:46 tsutsui Exp $ */
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1994 Gordon W. Ross
7 * Copyright (c) 1993 Adam Glass
8 * Copyright (c) 1996 Paul Kranenburg
9 * Copyright (c) 1996
10 * The President and Fellows of Harvard College. All rights reserved.
12 * This software was developed by the Computer Systems Engineering group
13 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
14 * contributed to Berkeley.
16 * All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Harvard University.
19 * This product includes software developed by the University of
20 * California, Lawrence Berkeley Laboratory.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * This product includes software developed by the University of
34 * California, Berkeley and its contributors.
35 * This product includes software developed by Paul Kranenburg.
36 * This product includes software developed by Harvard University.
37 * 4. Neither the name of the University nor the names of its contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
41 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
53 * @(#)clock.c 8.1 (Berkeley) 6/11/93
54 * from: NetBSD: clock.c,v 1.80 2006/09/03 22:27:45 gdamore Exp
58 #include <sys/cdefs.h>
59 __KERNEL_RCSID(0, "$NetBSD: rtc.c,v 1.5 2008/03/29 05:42:46 tsutsui Exp $");
62 * Clock driver for 'rtc' - mc146818 driver.
65 #include <sys/param.h>
66 #include <sys/kernel.h>
67 #include <sys/device.h>
68 #include <sys/proc.h>
70 #include <machine/bus.h>
71 #include <machine/autoconf.h>
73 #include <dev/clock_subr.h>
74 #include <dev/ic/mc146818reg.h>
75 #include <dev/ic/mc146818var.h>
77 #include <dev/ebus/ebusreg.h>
78 #include <dev/ebus/ebusvar.h>
80 static int rtc_ebus_match(device_t, cfdata_t, void *);
81 static void rtc_ebus_attach(device_t, device_t, void *);
83 CFATTACH_DECL_NEW(rtc_ebus, sizeof(struct mc146818_softc),
84 rtc_ebus_match, rtc_ebus_attach, NULL, NULL);
86 u_int rtc_read_reg(struct mc146818_softc *, u_int);
87 void rtc_write_reg(struct mc146818_softc *, u_int, u_int);
88 u_int rtc_getcent(struct mc146818_softc *);
89 void rtc_setcent(struct mc146818_softc *, u_int);
91 static int
92 rtc_ebus_match(device_t parent, cfdata_t cf, void *aux)
94 struct ebus_attach_args *ea = aux;
96 return (strcmp("rtc", ea->ea_name) == 0);
100 * `rtc' is a ds1287 on an ebus (actually an isa bus, but we use the
101 * ebus driver for isa.) So we can use ebus_wenable() but need to do
102 * different attach work and use different todr routines. It does not
103 * incorporate an IDPROM.
107 * XXX the stupid ds1287 is not mapped directly but uses an address
108 * and a data reg so we cannot access the stuuupid thing w/o having
109 * write access to the registers.
111 * XXXX We really need to mutex register access!
113 #define RTC_ADDR 0
114 #define RTC_DATA 1
115 u_int
116 rtc_read_reg(struct mc146818_softc *sc, u_int reg)
119 bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg);
120 return (bus_space_read_1(sc->sc_bst, sc->sc_bsh, RTC_DATA));
122 void
123 rtc_write_reg(struct mc146818_softc *sc, u_int reg, u_int val)
126 bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg);
127 bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_DATA, val);
130 /* ARGSUSED */
131 static void
132 rtc_ebus_attach(device_t parent, device_t self, void *aux)
134 struct mc146818_softc *sc = device_private(self);
135 struct ebus_attach_args *ea = aux;
136 char *model;
137 int sz;
139 sc->sc_dev = self;
140 sc->sc_bst = ea->ea_bustag;
142 /* hard code to 8K? */
143 sz = ea->ea_reg[0].size;
145 if (bus_space_map(sc->sc_bst,
146 EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
147 sz, 0,
148 &sc->sc_bsh) != 0) {
149 aprint_error(": can't map register\n");
150 return;
153 model = prom_getpropstring(ea->ea_node, "model");
154 #ifdef DIAGNOSTIC
155 if (model == NULL)
156 panic("clockattach_rtc: no model property");
157 #endif
159 /* Our TOD clock year 0 is 0 */
160 sc->sc_year0 = 0;
161 sc->sc_flag = MC146818_NO_CENT_ADJUST;
162 sc->sc_mcread = rtc_read_reg;
163 sc->sc_mcwrite = rtc_write_reg;
164 sc->sc_getcent = rtc_getcent;
165 sc->sc_setcent = rtc_setcent;
166 mc146818_attach(sc);
168 aprint_normal(": %s\n", model);
171 * Turn interrupts off, just in case. (Although they shouldn't
172 * be wired to an interrupt controller on sparcs).
174 rtc_write_reg(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
177 * Apparently on some machines the TOD registers are on the same
178 * physical page as the COM registers. So we won't protect them.
180 /*sc->sc_handle.todr_setwen = NULL;*/
184 * MD mc146818 RTC todr routines.
187 /* Loooks like Sun stores the century info somewhere in CMOS RAM */
188 #define MC_CENT 0x32
190 u_int
191 rtc_getcent(struct mc146818_softc *sc)
194 return rtc_read_reg(sc, MC_CENT);
196 void
197 rtc_setcent(struct mc146818_softc *sc, u_int cent)
200 rtc_write_reg(sc, MC_CENT, cent);