Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.5
      1 /*	$NetBSD: mcclock_isa.c,v 1.5 2004/09/14 20:32:48 drochner 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.5 2004/09/14 20:32:48 drochner 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/isareg.h>
     47 #include <dev/isa/isavar.h>
     48 
     49 struct mcclock_isa_softc {
     50 	struct mcclock_softc	sc_mcclock;
     51 
     52 	bus_space_tag_t		sc_iot;
     53 	bus_space_handle_t	sc_ioh;
     54 };
     55 
     56 static int	mcclock_isa_match(struct device *, struct cfdata *, void *);
     57 static void	mcclock_isa_attach(struct device *, struct device *, void *);
     58 
     59 CFATTACH_DECL(mcclock_isa, sizeof (struct mcclock_isa_softc),
     60     mcclock_isa_match, mcclock_isa_attach, NULL, NULL);
     61 
     62 static void	mcclock_isa_write(struct mcclock_softc *, u_int, u_int);
     63 static 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 static int
     70 mcclock_isa_match(struct device *parent, struct cfdata *match, void *aux)
     71 {
     72 	struct isa_attach_args *ia = aux;
     73 	bus_space_handle_t ioh;
     74 
     75 	if (ia->ia_nio < 1 ||
     76 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
     77 	     ia->ia_io[0].ir_addr != IO_RTC))
     78 		return (0);
     79 
     80 	if (ia->ia_niomem > 0 &&
     81 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
     82 		return (0);
     83 
     84 	if (ia->ia_nirq > 0 &&
     85 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
     86 		return (0);
     87 
     88 	if (ia->ia_ndrq > 0 &&
     89 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
     90 		return (0);
     91 
     92 	if (bus_space_map(ia->ia_iot, IO_RTC, 0x2, 0, &ioh))
     93 		return (0);
     94 
     95 	bus_space_unmap(ia->ia_iot, ioh, 0x2);
     96 
     97 	ia->ia_nio = 1;
     98 	ia->ia_io[0].ir_addr = IO_RTC;
     99 	ia->ia_io[0].ir_size = 0x02;
    100 
    101 	ia->ia_niomem = 0;
    102 	ia->ia_nirq = 0;
    103 	ia->ia_ndrq = 0;
    104 
    105 	return (1);
    106 }
    107 
    108 static void
    109 mcclock_isa_attach(struct device *parent, struct device *self, void *aux)
    110 {
    111 	struct isa_attach_args *ia = aux;
    112 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)self;
    113 
    114 	sc->sc_iot = ia->ia_iot;
    115 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
    116 	    ia->ia_io[0].ir_size, 0, &sc->sc_ioh))
    117 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    118 
    119 	mcclock_attach(&sc->sc_mcclock, &mcclock_isa_busfns);
    120 }
    121 
    122 static void
    123 mcclock_isa_write(struct mcclock_softc *mcsc, u_int reg, u_int datum)
    124 {
    125 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc;
    126 	bus_space_tag_t iot = sc->sc_iot;
    127 	bus_space_handle_t ioh = sc->sc_ioh;
    128 
    129 	bus_space_write_1(iot, ioh, 0, reg);
    130 	bus_space_write_1(iot, ioh, 1, datum);
    131 }
    132 
    133 static u_int
    134 mcclock_isa_read(struct mcclock_softc *mcsc, u_int reg)
    135 {
    136 	struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc;
    137 	bus_space_tag_t iot = sc->sc_iot;
    138 	bus_space_handle_t ioh = sc->sc_ioh;
    139 
    140 	bus_space_write_1(iot, ioh, 0, reg);
    141 	return bus_space_read_1(iot, ioh, 1);
    142 }
    143