1 /* $NetBSD: mcclock_isa.c,v 1.4 2002/10/02 04:59:48 thorpej Exp $ */ 2 /* $OpenBSD: clock_mc.c,v 1.9 1998/03/16 09:38:26 pefo Exp $ */ 3 /* NetBSD: clock_mc.c,v 1.2 1995/06/28 04:30:30 cgd Exp */ 4 5 /* 6 * Copyright (c) 1988 University of Utah. 7 * Copyright (c) 1992, 1993 8 * The Regents of the University of California. All rights reserved. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * the Systems Programming Group of the University of Utah Computer 12 * Science Department and Ralph Campbell. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. All advertising materials mentioning features or use of this software 23 * must display the following acknowledgement: 24 * This product includes software developed by the University of 25 * California, Berkeley and its contributors. 26 * 4. Neither the name of the University nor the names of its contributors 27 * may be used to endorse or promote products derived from this software 28 * without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 * 42 * from: Utah Hdr: clock.c 1.18 91/01/21 43 * 44 * @(#)clock.c 8.1 (Berkeley) 6/10/93 45 */ 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 #include <sys/device.h> 50 51 #include <machine/bus.h> 52 53 #include <dev/isa/isareg.h> 54 #include <dev/isa/isavar.h> 55 56 #include <dev/ic/mc146818reg.h> 57 58 #include <arc/dev/mcclockvar.h> 59 #include <arc/isa/mcclock_isavar.h> 60 61 int mcclock_isa_match __P((struct device *, struct cfdata *, void *)); 62 void mcclock_isa_attach __P((struct device *, struct device *, void *)); 63 64 CFATTACH_DECL(mcclock_isa, sizeof(struct mcclock_softc), 65 mcclock_isa_match, mcclock_isa_attach, NULL, NULL); 66 67 /* Deskstation clock access code */ 68 u_int mc_isa_read __P((struct mcclock_softc *, u_int)); 69 void mc_isa_write __P((struct mcclock_softc *, u_int, u_int)); 70 71 struct mcclock_busfns mcclock_isa_busfns = { 72 mc_isa_read, mc_isa_write 73 }; 74 75 int mcclock_isa_conf = 0; 76 77 int 78 mcclock_isa_match(parent, match, aux) 79 struct device *parent; 80 struct cfdata *match; 81 void *aux; 82 { 83 struct isa_attach_args *ia = aux; 84 bus_space_handle_t ioh; 85 86 if (ia->ia_nio < 1 || 87 (ia->ia_io[0].ir_addr != ISACF_PORT_DEFAULT && 88 ia->ia_io[0].ir_addr != 0x70)) 89 return (0); 90 91 if (ia->ia_niomem > 0 && 92 (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT)) 93 return (0); 94 95 if (ia->ia_nirq > 0 && 96 (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT)) 97 return (0); 98 99 if (ia->ia_ndrq > 0 && 100 (ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT)) 101 return (0); 102 103 if (!mcclock_isa_conf) 104 return (0); 105 106 if (bus_space_map(ia->ia_iot, 0x70, 0x02, 0, &ioh)) 107 return (0); 108 109 bus_space_unmap(ia->ia_iot, ioh, 0x02); 110 111 ia->ia_nio = 1; 112 ia->ia_io[0].ir_addr = 0x70; 113 ia->ia_io[0].ir_size = 0x02; 114 115 ia->ia_niomem = 0; 116 ia->ia_nirq = 0; 117 ia->ia_ndrq = 0; 118 119 return (1); 120 } 121 122 void 123 mcclock_isa_attach(parent, self, aux) 124 struct device *parent; 125 struct device *self; 126 void *aux; 127 { 128 struct mcclock_softc *sc = (struct mcclock_softc *)self; 129 struct isa_attach_args *ia = aux; 130 131 sc->sc_iot = ia->ia_iot; 132 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 133 ia->ia_io[0].ir_size, 0, &sc->sc_ioh)) 134 panic("mcclock_isa_attach: couldn't map clock I/O space"); 135 136 mcclock_attach(sc, &mcclock_isa_busfns, 80); 137 138 /* Turn interrupts off, just in case. */ 139 mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR); 140 } 141 142 u_int 143 mc_isa_read(sc, reg) 144 struct mcclock_softc *sc; 145 u_int reg; 146 { 147 148 bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg); 149 return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, 1)); 150 } 151 152 void 153 mc_isa_write(sc, reg, datum) 154 struct mcclock_softc *sc; 155 u_int reg, datum; 156 { 157 158 bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg); 159 bus_space_write_1(sc->sc_iot, sc->sc_ioh, 1, datum); 160 } 161 162