mcclock_jensenio.c revision 1.4
1/* $NetBSD: mcclock_jensenio.c,v 1.4 2002/10/02 04:06:38 thorpej Exp $ */
2
3/*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the NetBSD
21 *	Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*
40 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
41 * All rights reserved.
42 *
43 * Author: Chris G. Demetriou
44 *
45 * Permission to use, copy, modify and distribute this software and
46 * its documentation is hereby granted, provided that both the copyright
47 * notice and this permission notice appear in all copies of the
48 * software, derivative works or modified versions, and any portions
49 * thereof, and that both notices appear in supporting documentation.
50 *
51 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
52 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
53 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
54 *
55 * Carnegie Mellon requests users of this software to return to
56 *
57 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
58 *  School of Computer Science
59 *  Carnegie Mellon University
60 *  Pittsburgh PA 15213-3890
61 *
62 * any improvements or extensions that they make and grant Carnegie the
63 * rights to redistribute these changes.
64 */
65
66#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
67
68__KERNEL_RCSID(0, "$NetBSD: mcclock_jensenio.c,v 1.4 2002/10/02 04:06:38 thorpej Exp $");
69
70#include <sys/param.h>
71#include <sys/kernel.h>
72#include <sys/systm.h>
73#include <sys/device.h>
74
75#include <machine/bus.h>
76
77#include <dev/dec/clockvar.h>
78#include <dev/dec/mcclockvar.h>
79#include <dev/ic/mc146818reg.h>
80#include <dev/eisa/eisavar.h>
81#include <dev/isa/isavar.h>
82#include <alpha/jensenio/jenseniovar.h>
83
84struct mcclock_jensenio_softc {
85	struct mcclock_softc	sc_mcclock;
86
87	bus_space_tag_t		sc_iot;
88	bus_space_handle_t	sc_ioh;
89
90	bus_space_handle_t	sc_std_rtc_ioh;
91};
92
93int	mcclock_jensenio_match(struct device *, struct cfdata *, void *);
94void	mcclock_jensenio_attach(struct device *, struct device *, void *);
95
96CFATTACH_DECL(mcclock_jensenio, sizeof (struct mcclock_jensenio_softc),
97    mcclock_jensenio_match, mcclock_jensenio_attach, NULL, NULL);
98
99void	mcclock_jensenio_write(struct mcclock_softc *, u_int, u_int);
100u_int	mcclock_jensenio_read(struct mcclock_softc *, u_int);
101
102const struct mcclock_busfns mcclock_jensenio_busfns = {
103	mcclock_jensenio_write, mcclock_jensenio_read,
104};
105
106int
107mcclock_jensenio_match(struct device *parent, struct cfdata *match, void *aux)
108{
109	struct jensenio_attach_args *ja = aux;
110
111	/* Always present. */
112	if (strcmp(ja->ja_name, match->cf_name) == 0)
113		return (1);
114
115	return (0);
116}
117
118void
119mcclock_jensenio_attach(struct device *parent, struct device *self, void *aux)
120{
121	struct jensenio_attach_args *ja = aux;
122	struct mcclock_jensenio_softc *sc = (void *) self;
123
124	sc->sc_iot = ja->ja_iot;
125	if (bus_space_map(sc->sc_iot, ja->ja_ioaddr, 0x02, 0,
126	    &sc->sc_ioh))
127		panic("mcclock_jensenio_attach: couldn't map clock I/O space");
128
129	/*
130	 * Map the I/O space normally used by the ISA RTC (port 0x70) so
131	 * as to avoid a false match at that address, as well.
132	 */
133	(void) bus_space_map(sc->sc_iot, 0x70, 0x02, 0,
134	    &sc->sc_std_rtc_ioh);
135
136	mcclock_attach(&sc->sc_mcclock, &mcclock_jensenio_busfns);
137}
138
139void
140mcclock_jensenio_write(struct mcclock_softc *mcsc, u_int reg, u_int datum)
141{
142	struct mcclock_jensenio_softc *sc = (void *) mcsc;
143	bus_space_tag_t iot = sc->sc_iot;
144	bus_space_handle_t ioh = sc->sc_ioh;
145
146	bus_space_write_1(iot, ioh, 0, reg);
147	bus_space_write_1(iot, ioh, 1, datum);
148}
149
150u_int
151mcclock_jensenio_read(struct mcclock_softc *mcsc, u_int reg)
152{
153	struct mcclock_jensenio_softc *sc = (void *) mcsc;
154	bus_space_tag_t iot = sc->sc_iot;
155	bus_space_handle_t ioh = sc->sc_ioh;
156
157	bus_space_write_1(iot, ioh, 0, reg);
158	return bus_space_read_1(iot, ioh, 1);
159}
160