Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.1
      1 /*	$NetBSD: mcclock_isa.c,v 1.1 2002/03/07 14:44:03 simonb 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/cdefs.h>			/* RCS ID & Copyright macro defns */
     31 
     32 __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.1 2002/03/07 14:44:03 simonb Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/kernel.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 
     39 #include <machine/bus.h>
     40 
     41 #include <dev/ic/mc146818reg.h>
     42 
     43 #include <evbmips/evbmips/clockvar.h>
     44 #include <evbmips/dev/mcclockvar.h>
     45 
     46 #include <dev/isa/isavar.h>
     47 
     48 struct mcclock_isa_softc {
     49 	struct mcclock_softc	sc_mcclock;
     50 
     51 	bus_space_tag_t		sc_iot;
     52 	bus_space_handle_t	sc_ioh;
     53 };
     54 
     55 static int	mcclock_isa_match(struct device *, struct cfdata *, void *);
     56 static void	mcclock_isa_attach(struct device *, struct device *, void *);
     57 
     58 struct cfattach mcclock_isa_ca = {
     59 	sizeof (struct mcclock_isa_softc), mcclock_isa_match,
     60 	    mcclock_isa_attach,
     61 };
     62 
     63 static void	mcclock_isa_write(struct mcclock_softc *, u_int, u_int);
     64 static u_int	mcclock_isa_read(struct mcclock_softc *, u_int);
     65 
     66 const struct mcclock_busfns mcclock_isa_busfns = {
     67 	mcclock_isa_write, mcclock_isa_read,
     68 };
     69 
     70 static int
     71 mcclock_isa_match(struct device *parent, struct cfdata *match, void *aux)
     72 {
     73 	struct isa_attach_args *ia = aux;
     74 	bus_space_handle_t ioh;
     75 
     76 	if (ia->ia_nio < 1 ||
     77 	    (ia->ia_io[0].ir_addr != ISACF_PORT_DEFAULT &&
     78 	     ia->ia_io[0].ir_addr != 0x70))
     79 		return (0);
     80 
     81 	if (ia->ia_niomem > 0 &&
     82 	    (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT))
     83 		return (0);
     84 
     85 	if (ia->ia_nirq > 0 &&
     86 	    (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT))
     87 		return (0);
     88 
     89 	if (ia->ia_ndrq > 0 &&
     90 	    (ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT))
     91 		return (0);
     92 
     93 	if (bus_space_map(ia->ia_iot, 0x70, 0x2, 0, &ioh))
     94 		return (0);
     95 
     96 	bus_space_unmap(ia->ia_iot, ioh, 0x2);
     97 
     98 	ia->ia_nio = 1;
     99 	ia->ia_io[0].ir_addr = 0x70;
    100 	ia->ia_io[0].ir_size = 0x02;
    101 
    102 	ia->ia_niomem = 0;
    103 	ia->ia_nirq = 0;
    104 	ia->ia_ndrq = 0;
    105 
    106 	return (1);
    107 }
    108 
    109 static void
    110 mcclock_isa_attach(struct device *parent, struct device *self, void *aux)
    111 {
    112 	struct isa_attach_args *ia = aux;
    113 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)self;
    114 
    115 	sc->sc_iot = ia->ia_iot;
    116 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
    117 	    ia->ia_io[0].ir_size, 0, &sc->sc_ioh))
    118 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    119 
    120 	mcclock_attach(&sc->sc_mcclock, &mcclock_isa_busfns);
    121 }
    122 
    123 static void
    124 mcclock_isa_write(struct mcclock_softc *mcsc, u_int reg, u_int datum)
    125 {
    126 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc;
    127 	bus_space_tag_t iot = sc->sc_iot;
    128 	bus_space_handle_t ioh = sc->sc_ioh;
    129 
    130 	bus_space_write_1(iot, ioh, 0, reg);
    131 	bus_space_write_1(iot, ioh, 1, datum);
    132 }
    133 
    134 static u_int
    135 mcclock_isa_read(struct mcclock_softc *mcsc, u_int reg)
    136 {
    137 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc;
    138 	bus_space_tag_t iot = sc->sc_iot;
    139 	bus_space_handle_t ioh = sc->sc_ioh;
    140 
    141 	bus_space_write_1(iot, ioh, 0, reg);
    142 	return bus_space_read_1(iot, ioh, 1);
    143 }
    144