1 /* $NetBSD: mcclock_jensenio.c,v 1.8 2008/03/29 05:42:45 tsutsui Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
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.
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.
33 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
34 * All rights reserved.
36 * Author: Chris G. Demetriou
38 * Permission to use, copy, modify and distribute this software and
39 * its documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
59 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
61 __KERNEL_RCSID(0, "$NetBSD: mcclock_jensenio.c,v 1.8 2008/03/29 05:42:45 tsutsui Exp $");
63 #include <sys/param.h>
64 #include <sys/kernel.h>
65 #include <sys/systm.h>
66 #include <sys/device.h>
68 #include <machine/bus.h>
70 #include <dev/clock_subr.h>
72 #include <dev/ic/mc146818reg.h>
73 #include <dev/ic/mc146818var.h>
74 #include <dev/eisa/eisavar.h>
75 #include <dev/isa/isavar.h>
76 #include <alpha/jensenio/jenseniovar.h>
77 #include <alpha/alpha/mcclockvar.h>
79 struct mcclock_jensenio_softc
{
80 struct mc146818_softc sc_mc146818
;
82 bus_space_handle_t sc_std_rtc_ioh
;
85 int mcclock_jensenio_match(device_t
, cfdata_t
, void *);
86 void mcclock_jensenio_attach(device_t
, device_t
, void *);
88 CFATTACH_DECL_NEW(mcclock_jensenio
, sizeof(struct mcclock_jensenio_softc
),
89 mcclock_jensenio_match
, mcclock_jensenio_attach
, NULL
, NULL
);
91 void mcclock_jensenio_write(struct mc146818_softc
*, u_int
, u_int
);
92 u_int
mcclock_jensenio_read(struct mc146818_softc
*, u_int
);
96 mcclock_jensenio_match(device_t parent
, cfdata_t cf
, void *aux
)
98 struct jensenio_attach_args
*ja
= aux
;
100 /* Always present. */
101 if (strcmp(ja
->ja_name
, cf
->cf_name
) == 0)
108 mcclock_jensenio_attach(device_t parent
, device_t self
, void *aux
)
110 struct mcclock_jensenio_softc
*jsc
= device_private(self
);
111 struct jensenio_attach_args
*ja
= aux
;
112 struct mc146818_softc
*sc
= &jsc
->sc_mc146818
;
115 sc
->sc_bst
= ja
->ja_iot
;
116 if (bus_space_map(sc
->sc_bst
, ja
->ja_ioaddr
, 0x02, 0,
118 panic("mcclock_jensenio_attach: couldn't map clock I/O space");
121 * Map the I/O space normally used by the ISA RTC (port 0x70) so
122 * as to avoid a false match at that address, as well.
124 (void)bus_space_map(sc
->sc_bst
, 0x70, 0x02, 0,
125 &jsc
->sc_std_rtc_ioh
);
127 sc
->sc_mcread
= mcclock_jensenio_read
;
128 sc
->sc_mcwrite
= mcclock_jensenio_write
;
134 mcclock_jensenio_write(struct mc146818_softc
*sc
, u_int reg
, u_int datum
)
136 bus_space_tag_t iot
= sc
->sc_bst
;
137 bus_space_handle_t ioh
= sc
->sc_bsh
;
139 bus_space_write_1(iot
, ioh
, 0, reg
);
140 bus_space_write_1(iot
, ioh
, 1, datum
);
144 mcclock_jensenio_read(struct mc146818_softc
*sc
, u_int reg
)
146 bus_space_tag_t iot
= sc
->sc_bst
;
147 bus_space_handle_t ioh
= sc
->sc_bsh
;
149 bus_space_write_1(iot
, ioh
, 0, reg
);
150 return bus_space_read_1(iot
, ioh
, 1);