1 /* $NetBSD: mcclock_isa.c,v 1.3 2008/03/28 19:05:50 tsutsui Exp $ */
4 * Copyright (c) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz and Don Ahn.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)clock.c 7.2 (Berkeley) 5/12/91
37 * Copyright (c) 1993, 1994 Charles M. Hannum.
39 * This code is derived from software contributed to Berkeley by
40 * William Jolitz and Don Ahn.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the University of
53 * California, Berkeley and its contributors.
54 * 4. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * @(#)clock.c 7.2 (Berkeley) 5/12/91
73 * Mach Operating System
74 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
75 * All Rights Reserved.
77 * Permission to use, copy, modify and distribute this software and its
78 * documentation is hereby granted, provided that both the copyright
79 * notice and this permission notice appear in all copies of the
80 * software, derivative works or modified versions, and any portions
81 * thereof, and that both notices appear in supporting documentation.
83 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
84 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
85 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
87 * Carnegie Mellon requests users of this software to return to
89 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
90 * School of Computer Science
91 * Carnegie Mellon University
92 * Pittsburgh PA 15213-3890
94 * any improvements or extensions that they make and grant Carnegie Mellon
95 * the rights to redistribute these changes.
98 Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
102 Permission to use, copy, modify, and distribute this software and
103 its documentation for any purpose and without fee is hereby
104 granted, provided that the above copyright notice appears in all
105 copies and that both the copyright notice and this permission notice
106 appear in supporting documentation, and that the name of Intel
107 not be used in advertising or publicity pertaining to distribution
108 of the software without specific, written prior permission.
110 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
111 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
112 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
113 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
114 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
115 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
116 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
119 #include <sys/cdefs.h>
120 __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.3 2008/03/28 19:05:50 tsutsui Exp $");
122 #include <sys/param.h>
123 #include <sys/systm.h>
124 #include <sys/kernel.h>
125 #include <sys/device.h>
126 #include <sys/time.h>
128 #include <machine/bus.h>
130 #include <dev/clock_subr.h>
131 #include <dev/isa/isareg.h>
132 #include <dev/isa/isavar.h>
133 #include <dev/ic/mc146818reg.h>
134 #include <dev/ic/mc146818var.h>
137 * We only deal with the RTC portion of the mc146818 right now. Later
138 * we might want to add support for the NVRAM portion, since it
139 * appears that some systems use that.
142 static int mcclock_isa_probe(device_t
, cfdata_t
, void *);
143 static void mcclock_isa_attach(device_t
, device_t
, void *);
145 CFATTACH_DECL_NEW(mcclock_isa
, sizeof(struct mc146818_softc
),
146 mcclock_isa_probe
, mcclock_isa_attach
, NULL
, NULL
);
149 mcclock_isa_read(struct mc146818_softc
*sc
, unsigned reg
)
152 bus_space_write_1(sc
->sc_bst
, sc
->sc_bsh
, 0, reg
);
153 return bus_space_read_1(sc
->sc_bst
, sc
->sc_bsh
, 1);
157 mcclock_isa_write(struct mc146818_softc
*sc
, unsigned reg
, unsigned datum
)
160 bus_space_write_1(sc
->sc_bst
, sc
->sc_bsh
, 0, reg
);
161 bus_space_write_1(sc
->sc_bst
, sc
->sc_bsh
, 1, datum
);
165 mcclock_isa_probe(device_t parent
, cfdata_t cf
, void *aux
)
167 struct isa_attach_args
*ia
= aux
;
168 bus_space_handle_t ioh
;
173 if (ISA_DIRECT_CONFIG(ia
))
176 if ((ia
->ia_io
[0].ir_addr
!= ISA_UNKNOWN_PORT
) &&
177 (ia
->ia_io
[0].ir_addr
!= IO_RTC
))
180 if (ia
->ia_niomem
> 0 &&
181 (ia
->ia_iomem
[0].ir_addr
!= ISA_UNKNOWN_IOMEM
))
184 if (ia
->ia_nirq
> 0 &&
185 (ia
->ia_irq
[0].ir_irq
!= ISA_UNKNOWN_IRQ
))
188 if (ia
->ia_ndrq
> 0 &&
189 (ia
->ia_drq
[0].ir_drq
!= ISA_UNKNOWN_DRQ
))
192 if (bus_space_map(ia
->ia_iot
, IO_RTC
, 2, 0, &ioh
))
194 bus_space_unmap(ia
->ia_iot
, ioh
, 2);
196 ia
->ia_io
[0].ir_addr
= IO_RTC
;
197 ia
->ia_io
[0].ir_size
= 2;
208 mcclock_isa_attach(device_t parent
, device_t self
, void *aux
)
210 struct mc146818_softc
*sc
= device_private(self
);
211 struct isa_attach_args
*ia
= aux
;
214 sc
->sc_bst
= ia
->ia_iot
;
215 if (bus_space_map(sc
->sc_bst
, ia
->ia_io
[0].ir_addr
,
216 ia
->ia_io
[0].ir_size
, 0, &sc
->sc_bsh
)) {
217 aprint_error(": can't map registers!\n");
222 * Select a 32KHz crystal, periodic interrupt every 1024 Hz.
223 * XXX: We disable periodic interrupts, so why set a rate?
225 mcclock_isa_write(sc
, MC_REGA
, MC_BASE_32_KHz
| MC_RATE_1024_Hz
);
228 * 24 Hour clock, no interrupts please.
230 mcclock_isa_write(sc
, MC_REGB
, MC_REGB_24HR
);
234 sc
->sc_mcread
= mcclock_isa_read
;
235 sc
->sc_mcwrite
= mcclock_isa_write
;
238 * XXX: perhaps on some systems we should manage the century byte?
239 * For now we don't worry about it. (Ugly MD code.)
241 sc
->sc_getcent
= mcclock_isa_getcent
;
242 sc
->sc_setcent
= mcclock_isa_setcent
;