Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.9
      1 /* $NetBSD: mcclock_isa.c,v 1.9 1997/07/22 18:50:58 jonathan 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 <machine/options.h>		/* Config options headers */
     31 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     32 
     33 __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.9 1997/07/22 18:50:58 jonathan Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/kernel.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 
     40 #include <machine/bus.h>
     41 
     42 #include <dev/dec/clockvar.h>
     43 #include <dev/dec/mcclockvar.h>
     44 #include <dev/ic/mc146818reg.h>
     45 #include <dev/isa/isavar.h>
     46 
     47 struct mcclock_isa_softc {
     48 	struct mcclock_softc	sc_mcclock;
     49 
     50 	bus_space_tag_t		sc_iot;
     51 	bus_space_handle_t	sc_ioh;
     52 };
     53 
     54 int	mcclock_isa_match __P((struct device *, struct cfdata *, void *));
     55 void	mcclock_isa_attach __P((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 __P((struct mcclock_softc *, u_int, u_int));
     63 u_int	mcclock_isa_read __P((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 	struct cfdata *match;
     73 	void *aux;
     74 {
     75 	struct isa_attach_args *ia = aux;
     76 	bus_space_handle_t ioh;
     77 
     78         if ((ia->ia_iobase != IOBASEUNK && ia->ia_iobase != 0x70) ||
     79             /* (ia->ia_iosize != 0 && ia->ia_iosize != 0x2) || XXX isa.c */
     80             ia->ia_maddr != MADDRUNK || ia->ia_msize != 0 ||
     81             ia->ia_irq != IRQUNK || ia->ia_drq != DRQUNK)
     82                 return (0);
     83 
     84 	if (bus_space_map(ia->ia_iot, 0x70, 0x2, 0, &ioh))
     85 		return (0);
     86 
     87 	bus_space_unmap(ia->ia_iot, ioh, 0x2);
     88 
     89 	ia->ia_iobase = 0x70;
     90 	ia->ia_iosize = 0x2;
     91 
     92 	return (1);
     93 }
     94 
     95 void
     96 mcclock_isa_attach(parent, self, aux)
     97 	struct device *parent, *self;
     98 	void *aux;
     99 {
    100 	struct isa_attach_args *ia = aux;
    101 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)self;
    102 
    103 	sc->sc_iot = ia->ia_iot;
    104 	if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0,
    105 	    &sc->sc_ioh))
    106 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    107 
    108 	mcclock_attach(&sc->sc_mcclock, &mcclock_isa_busfns);
    109 }
    110 
    111 void
    112 mcclock_isa_write(mcsc, reg, datum)
    113 	struct mcclock_softc *mcsc;
    114 	u_int reg, datum;
    115 {
    116 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc;
    117 	bus_space_tag_t iot = sc->sc_iot;
    118 	bus_space_handle_t ioh = sc->sc_ioh;
    119 
    120 	bus_space_write_1(iot, ioh, 0, reg);
    121 	bus_space_write_1(iot, ioh, 1, datum);
    122 }
    123 
    124 u_int
    125 mcclock_isa_read(mcsc, reg)
    126 	struct mcclock_softc *mcsc;
    127 	u_int reg;
    128 {
    129 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc;
    130 	bus_space_tag_t iot = sc->sc_iot;
    131 	bus_space_handle_t ioh = sc->sc_ioh;
    132 
    133 	bus_space_write_1(iot, ioh, 0, reg);
    134 	return bus_space_read_1(iot, ioh, 1);
    135 }
    136