Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.16.6.1
      1  1.16.6.1      matt /* $NetBSD: mcclock_isa.c,v 1.16.6.1 2007/11/06 23:13:56 matt Exp $ */
      2       1.2       cgd 
      3       1.2       cgd /*
      4       1.2       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5       1.2       cgd  * All rights reserved.
      6       1.2       cgd  *
      7       1.2       cgd  * Author: Chris G. Demetriou
      8       1.2       cgd  *
      9       1.2       cgd  * Permission to use, copy, modify and distribute this software and
     10       1.2       cgd  * its documentation is hereby granted, provided that both the copyright
     11       1.2       cgd  * notice and this permission notice appear in all copies of the
     12       1.2       cgd  * software, derivative works or modified versions, and any portions
     13       1.2       cgd  * thereof, and that both notices appear in supporting documentation.
     14       1.2       cgd  *
     15       1.2       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16       1.2       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17       1.2       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18       1.2       cgd  *
     19       1.2       cgd  * Carnegie Mellon requests users of this software to return to
     20       1.2       cgd  *
     21       1.2       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22       1.2       cgd  *  School of Computer Science
     23       1.2       cgd  *  Carnegie Mellon University
     24       1.2       cgd  *  Pittsburgh PA 15213-3890
     25       1.2       cgd  *
     26       1.2       cgd  * any improvements or extensions that they make and grant Carnegie the
     27       1.2       cgd  * rights to redistribute these changes.
     28       1.2       cgd  */
     29       1.7       cgd 
     30       1.8       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31       1.8       cgd 
     32  1.16.6.1      matt __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.16.6.1 2007/11/06 23:13:56 matt Exp $");
     33       1.1       cgd 
     34       1.1       cgd #include <sys/param.h>
     35       1.1       cgd #include <sys/kernel.h>
     36       1.1       cgd #include <sys/systm.h>
     37       1.1       cgd #include <sys/device.h>
     38       1.1       cgd 
     39       1.1       cgd #include <machine/bus.h>
     40       1.1       cgd 
     41      1.16   tsutsui #include <dev/clock_subr.h>
     42      1.16   tsutsui 
     43       1.1       cgd #include <dev/ic/mc146818reg.h>
     44      1.16   tsutsui #include <dev/ic/mc146818var.h>
     45       1.1       cgd #include <dev/isa/isavar.h>
     46       1.1       cgd 
     47      1.16   tsutsui #include <alpha/alpha/mcclockvar.h>
     48       1.1       cgd 
     49      1.16   tsutsui int	mcclock_isa_match(struct device *, struct cfdata *, void *);
     50      1.16   tsutsui void	mcclock_isa_attach(struct device *, struct device *, void *);
     51       1.1       cgd 
     52      1.16   tsutsui CFATTACH_DECL(mcclock_isa, sizeof(struct mc146818_softc),
     53      1.13   thorpej     mcclock_isa_match, mcclock_isa_attach, NULL, NULL);
     54       1.1       cgd 
     55      1.16   tsutsui void	mcclock_isa_write(struct mc146818_softc *, u_int, u_int);
     56      1.16   tsutsui u_int	mcclock_isa_read(struct mc146818_softc *, u_int);
     57       1.1       cgd 
     58       1.1       cgd int
     59      1.16   tsutsui mcclock_isa_match(struct device *parent, struct cfdata *match, void *aux)
     60       1.1       cgd {
     61       1.1       cgd 	struct isa_attach_args *ia = aux;
     62       1.4       cgd 	bus_space_handle_t ioh;
     63       1.1       cgd 
     64      1.11   thorpej 	if (ia->ia_nio < 1 ||
     65      1.14  drochner 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
     66      1.11   thorpej 	     ia->ia_io[0].ir_addr != 0x70))
     67      1.11   thorpej 		return (0);
     68      1.11   thorpej 
     69      1.11   thorpej 	if (ia->ia_niomem > 0 &&
     70      1.14  drochner 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
     71      1.11   thorpej 		return (0);
     72      1.11   thorpej 
     73      1.11   thorpej 	if (ia->ia_nirq > 0 &&
     74      1.14  drochner 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
     75      1.11   thorpej 		return (0);
     76      1.11   thorpej 
     77      1.11   thorpej 	if (ia->ia_ndrq > 0 &&
     78      1.14  drochner 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
     79      1.11   thorpej 		return (0);
     80       1.4       cgd 
     81       1.4       cgd 	if (bus_space_map(ia->ia_iot, 0x70, 0x2, 0, &ioh))
     82       1.1       cgd 		return (0);
     83       1.1       cgd 
     84       1.4       cgd 	bus_space_unmap(ia->ia_iot, ioh, 0x2);
     85       1.4       cgd 
     86      1.11   thorpej 	ia->ia_nio = 1;
     87      1.11   thorpej 	ia->ia_io[0].ir_addr = 0x70;
     88      1.11   thorpej 	ia->ia_io[0].ir_size = 0x02;
     89      1.11   thorpej 
     90      1.11   thorpej 	ia->ia_niomem = 0;
     91      1.11   thorpej 	ia->ia_nirq = 0;
     92      1.11   thorpej 	ia->ia_ndrq = 0;
     93       1.1       cgd 
     94       1.1       cgd 	return (1);
     95       1.1       cgd }
     96       1.1       cgd 
     97       1.1       cgd void
     98      1.16   tsutsui mcclock_isa_attach(struct device *parent, struct device *self, void *aux)
     99       1.1       cgd {
    100       1.1       cgd 	struct isa_attach_args *ia = aux;
    101      1.16   tsutsui 	struct mc146818_softc *sc = (void *)self;
    102       1.1       cgd 
    103      1.16   tsutsui 	sc->sc_bst = ia->ia_iot;
    104      1.16   tsutsui 	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
    105      1.16   tsutsui 	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
    106       1.1       cgd 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    107       1.1       cgd 
    108      1.16   tsutsui 	sc->sc_mcread  = mcclock_isa_read;
    109      1.16   tsutsui 	sc->sc_mcwrite = mcclock_isa_write;
    110      1.16   tsutsui 
    111      1.16   tsutsui 	mcclock_attach(sc);
    112       1.1       cgd }
    113       1.1       cgd 
    114       1.1       cgd void
    115      1.16   tsutsui mcclock_isa_write(struct mc146818_softc *sc, u_int reg, u_int datum)
    116       1.1       cgd {
    117      1.16   tsutsui 	bus_space_tag_t iot = sc->sc_bst;
    118      1.16   tsutsui 	bus_space_handle_t ioh = sc->sc_bsh;
    119       1.1       cgd 
    120       1.3       cgd 	bus_space_write_1(iot, ioh, 0, reg);
    121       1.3       cgd 	bus_space_write_1(iot, ioh, 1, datum);
    122       1.1       cgd }
    123       1.1       cgd 
    124       1.1       cgd u_int
    125      1.16   tsutsui mcclock_isa_read(struct mc146818_softc *sc, u_int reg)
    126       1.1       cgd {
    127      1.16   tsutsui 	bus_space_tag_t iot = sc->sc_bst;
    128      1.16   tsutsui 	bus_space_handle_t ioh = sc->sc_bsh;
    129       1.1       cgd 
    130       1.3       cgd 	bus_space_write_1(iot, ioh, 0, reg);
    131       1.3       cgd 	return bus_space_read_1(iot, ioh, 1);
    132       1.1       cgd }
    133