1 /* $OpenBSD: mcclock_isa.c,v 1.7 2002/03/14 01:26:27 millert Exp $ */ 2 /* $NetBSD: mcclock_isa.c,v 1.5 1996/12/05 01:39:29 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 31 #include <sys/param.h> 32 #include <sys/kernel.h> 33 #include <sys/systm.h> 34 #include <sys/device.h> 35 36 #include <machine/bus.h> 37 38 #include <alpha/alpha/clockvar.h> 39 #include <alpha/alpha/mcclockvar.h> 40 #include <dev/ic/mc146818reg.h> 41 #include <dev/isa/isavar.h> 42 43 struct mcclock_isa_softc { 44 struct mcclock_softc sc_mcclock; 45 46 bus_space_tag_t sc_iot; 47 bus_space_handle_t sc_ioh; 48 }; 49 50 #ifdef __BROKEN_INDIRECT_CONFIG 51 int mcclock_isa_match(struct device *, void *, void *); 52 #else 53 int mcclock_isa_match(struct device *, struct cfdata *, void *); 54 #endif 55 void mcclock_isa_attach(struct device *, struct device *, void *); 56 57 struct cfattach mcclock_isa_ca = { 58 sizeof (struct mcclock_isa_softc), mcclock_isa_match, 59 mcclock_isa_attach, 60 }; 61 62 void mcclock_isa_write(struct mcclock_softc *, u_int, u_int); 63 u_int mcclock_isa_read(struct mcclock_softc *, u_int); 64 65 const struct mcclock_busfns mcclock_isa_busfns = { 66 mcclock_isa_write, mcclock_isa_read, 67 }; 68 69 int 70 mcclock_isa_match(parent, match, aux) 71 struct device *parent; 72 #ifdef __BROKEN_INDIRECT_CONFIG 73 void *match; 74 #else 75 struct cfdata *match; 76 #endif 77 void *aux; 78 { 79 struct isa_attach_args *ia = aux; 80 bus_space_handle_t ioh; 81 82 if ((ia->ia_iobase != IOBASEUNK && ia->ia_iobase != 0x70) || 83 /* (ia->ia_iosize != 0 && ia->ia_iosize != 0x2) || XXX isa.c */ 84 ia->ia_maddr != MADDRUNK || ia->ia_msize != 0 || 85 ia->ia_irq != IRQUNK || ia->ia_drq != DRQUNK) 86 return (0); 87 88 if (bus_space_map(ia->ia_iot, 0x70, 0x2, 0, &ioh)) 89 return (0); 90 91 bus_space_unmap(ia->ia_iot, ioh, 0x2); 92 93 ia->ia_iobase = 0x70; 94 ia->ia_iosize = 0x2; 95 96 return (1); 97 } 98 99 void 100 mcclock_isa_attach(parent, self, aux) 101 struct device *parent, *self; 102 void *aux; 103 { 104 struct isa_attach_args *ia = aux; 105 struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)self; 106 107 sc->sc_iot = ia->ia_iot; 108 if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0, 109 &sc->sc_ioh)) 110 panic("mcclock_isa_attach: couldn't map clock I/O space"); 111 112 mcclock_attach(&sc->sc_mcclock, &mcclock_isa_busfns); 113 } 114 115 void 116 mcclock_isa_write(mcsc, reg, datum) 117 struct mcclock_softc *mcsc; 118 u_int reg, datum; 119 { 120 struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc; 121 bus_space_tag_t iot = sc->sc_iot; 122 bus_space_handle_t ioh = sc->sc_ioh; 123 124 bus_space_write_1(iot, ioh, 0, reg); 125 bus_space_write_1(iot, ioh, 1, datum); 126 } 127 128 u_int 129 mcclock_isa_read(mcsc, reg) 130 struct mcclock_softc *mcsc; 131 u_int reg; 132 { 133 struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc; 134 bus_space_tag_t iot = sc->sc_iot; 135 bus_space_handle_t ioh = sc->sc_ioh; 136 137 bus_space_write_1(iot, ioh, 0, reg); 138 return bus_space_read_1(iot, ioh, 1); 139 } 140