mcclock_jensenio.c revision 1.2
1/* $NetBSD: mcclock_jensenio.c,v 1.2 2002/09/27 02:24:08 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.2 2002/09/27 02:24:08 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 96struct cfattach mcclock_jensenio_ca = { 97 sizeof (struct mcclock_jensenio_softc), mcclock_jensenio_match, 98 mcclock_jensenio_attach, 99}; 100 101void mcclock_jensenio_write(struct mcclock_softc *, u_int, u_int); 102u_int mcclock_jensenio_read(struct mcclock_softc *, u_int); 103 104const struct mcclock_busfns mcclock_jensenio_busfns = { 105 mcclock_jensenio_write, mcclock_jensenio_read, 106}; 107 108int 109mcclock_jensenio_match(struct device *parent, struct cfdata *match, void *aux) 110{ 111 struct jensenio_attach_args *ja = aux; 112 113 /* Always present. */ 114 if (strcmp(ja->ja_name, match->cf_name) == 0) 115 return (1); 116 117 return (0); 118} 119 120void 121mcclock_jensenio_attach(struct device *parent, struct device *self, void *aux) 122{ 123 struct jensenio_attach_args *ja = aux; 124 struct mcclock_jensenio_softc *sc = (void *) self; 125 126 sc->sc_iot = ja->ja_iot; 127 if (bus_space_map(sc->sc_iot, ja->ja_ioaddr, 0x02, 0, 128 &sc->sc_ioh)) 129 panic("mcclock_jensenio_attach: couldn't map clock I/O space"); 130 131 /* 132 * Map the I/O space normally used by the ISA RTC (port 0x70) so 133 * as to avoid a false match at that address, as well. 134 */ 135 (void) bus_space_map(sc->sc_iot, 0x70, 0x02, 0, 136 &sc->sc_std_rtc_ioh); 137 138 mcclock_attach(&sc->sc_mcclock, &mcclock_jensenio_busfns); 139} 140 141void 142mcclock_jensenio_write(struct mcclock_softc *mcsc, u_int reg, u_int datum) 143{ 144 struct mcclock_jensenio_softc *sc = (void *) mcsc; 145 bus_space_tag_t iot = sc->sc_iot; 146 bus_space_handle_t ioh = sc->sc_ioh; 147 148 bus_space_write_1(iot, ioh, 0, reg); 149 bus_space_write_1(iot, ioh, 1, datum); 150} 151 152u_int 153mcclock_jensenio_read(struct mcclock_softc *mcsc, u_int reg) 154{ 155 struct mcclock_jensenio_softc *sc = (void *) mcsc; 156 bus_space_tag_t iot = sc->sc_iot; 157 bus_space_handle_t ioh = sc->sc_ioh; 158 159 bus_space_write_1(iot, ioh, 0, reg); 160 return bus_space_read_1(iot, ioh, 1); 161} 162