Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.7
      1 /*	$NetBSD: mcclock_isa.c,v 1.7 2006/03/28 03:43:57 gdamore 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.7 2006/03/28 03:43:57 gdamore 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/clock_subr.h>
     42 #include <dev/ic/mc146818reg.h>
     43 #include <dev/ic/mc146818var.h>
     44 
     45 #include <dev/isa/isareg.h>
     46 #include <dev/isa/isavar.h>
     47 
     48 /*
     49  * Note the Algorithmics PMON firmware uses a different year base.
     50  */
     51 #define	ALGOR_YEAR_ZERO		1920
     52 
     53 static int	mcclock_isa_match(struct device *, struct cfdata *, void *);
     54 static void	mcclock_isa_attach(struct device *, struct device *, void *);
     55 
     56 CFATTACH_DECL(mcclock_isa, sizeof (struct mc146818_softc),
     57     mcclock_isa_match, mcclock_isa_attach, NULL, NULL);
     58 
     59 static void	mcclock_isa_write(struct mc146818_softc *, u_int, u_int);
     60 static u_int	mcclock_isa_read(struct mc146818_softc *, u_int);
     61 
     62 extern todr_chip_handle_t	todr_handle;
     63 
     64 static int
     65 mcclock_isa_match(struct device *parent, struct cfdata *match, void *aux)
     66 {
     67 	struct isa_attach_args *ia = aux;
     68 	bus_space_handle_t ioh;
     69 
     70 	if (ia->ia_nio < 1 ||
     71 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
     72 	     ia->ia_io[0].ir_addr != IO_RTC))
     73 		return (0);
     74 
     75 	if (ia->ia_niomem > 0 &&
     76 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
     77 		return (0);
     78 
     79 	if (ia->ia_nirq > 0 &&
     80 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
     81 		return (0);
     82 
     83 	if (ia->ia_ndrq > 0 &&
     84 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
     85 		return (0);
     86 
     87 	if (bus_space_map(ia->ia_iot, IO_RTC, 0x2, 0, &ioh))
     88 		return (0);
     89 
     90 	bus_space_unmap(ia->ia_iot, ioh, 0x2);
     91 
     92 	ia->ia_nio = 1;
     93 	ia->ia_io[0].ir_addr = IO_RTC;
     94 	ia->ia_io[0].ir_size = 0x02;
     95 
     96 	ia->ia_niomem = 0;
     97 	ia->ia_nirq = 0;
     98 	ia->ia_ndrq = 0;
     99 
    100 	return (1);
    101 }
    102 
    103 static void
    104 mcclock_isa_attach(struct device *parent, struct device *self, void *aux)
    105 {
    106 	struct isa_attach_args *ia = aux;
    107 	struct mc146818_softc *sc = (struct mc146818_softc *)self;
    108 
    109 	sc->sc_bst = ia->ia_iot;
    110 	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
    111 	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
    112 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    113 
    114 	sc->sc_year0 = ALGOR_YEAR_ZERO;
    115 	sc->sc_flag = MC146818_NO_CENT_ADJUST;
    116 	sc->sc_mcread = mcclock_isa_read;
    117 	sc->sc_mcwrite = mcclock_isa_write;
    118 	sc->sc_getcent = NULL;
    119 	sc->sc_setcent = NULL;
    120 
    121 	/*
    122 	 * Turn interrupts off, just in case.  Need to leave the SQWE
    123 	 * set, because that's the DRAM refresh signal on Rev. B boards.
    124 	 */
    125 	mcclock_isa_write(sc, MC_REGB, MC_REGB_SQWE | MC_REGB_BINARY |
    126 	    MC_REGB_24HR);
    127 
    128 	mc146818_attach(sc);
    129 
    130 	todr_handle = &sc->sc_handle;
    131 }
    132 
    133 void
    134 mcclock_isa_write(struct mc146818_softc *sc, u_int reg, u_int datum)
    135 {
    136 	bus_space_tag_t iot = sc->sc_bst;
    137 	bus_space_handle_t ioh = sc->sc_bsh;
    138 
    139 	bus_space_write_1(iot, ioh, 0, reg);
    140 	bus_space_write_1(iot, ioh, 1, datum);
    141 }
    142 
    143 u_int
    144 mcclock_isa_read(struct mc146818_softc *sc, u_int reg)
    145 {
    146 	bus_space_tag_t iot = sc->sc_bst;
    147 	bus_space_handle_t ioh = sc->sc_bsh;
    148 
    149 	bus_space_write_1(iot, ioh, 0, reg);
    150 	return bus_space_read_1(iot, ioh, 1);
    151 }
    152