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