Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.17.16.1
      1  1.17.16.1       mjf /* $NetBSD: mcclock_isa.c,v 1.17.16.1 2008/04/03 12:42:10 mjf 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.17.16.1       mjf __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.17.16.1 2008/04/03 12:42:10 mjf 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.17.16.1       mjf int	mcclock_isa_match(device_t, cfdata_t, void *);
     50  1.17.16.1       mjf void	mcclock_isa_attach(device_t, device_t, void *);
     51        1.1       cgd 
     52  1.17.16.1       mjf CFATTACH_DECL_NEW(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.17.16.1       mjf mcclock_isa_match(device_t parent, cfdata_t cf, 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.17.16.1       mjf mcclock_isa_attach(device_t parent, device_t self, void *aux)
     99        1.1       cgd {
    100  1.17.16.1       mjf 	struct mc146818_softc *sc = device_private(self);
    101        1.1       cgd 	struct isa_attach_args *ia = aux;
    102        1.1       cgd 
    103  1.17.16.1       mjf 	sc->sc_dev = self;
    104       1.16   tsutsui 	sc->sc_bst = ia->ia_iot;
    105       1.16   tsutsui 	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
    106       1.16   tsutsui 	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
    107        1.1       cgd 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    108        1.1       cgd 
    109       1.16   tsutsui 	sc->sc_mcread  = mcclock_isa_read;
    110       1.16   tsutsui 	sc->sc_mcwrite = mcclock_isa_write;
    111       1.16   tsutsui 
    112       1.16   tsutsui 	mcclock_attach(sc);
    113        1.1       cgd }
    114        1.1       cgd 
    115        1.1       cgd void
    116       1.16   tsutsui mcclock_isa_write(struct mc146818_softc *sc, u_int reg, u_int datum)
    117        1.1       cgd {
    118       1.16   tsutsui 	bus_space_tag_t iot = sc->sc_bst;
    119       1.16   tsutsui 	bus_space_handle_t ioh = sc->sc_bsh;
    120        1.1       cgd 
    121        1.3       cgd 	bus_space_write_1(iot, ioh, 0, reg);
    122        1.3       cgd 	bus_space_write_1(iot, ioh, 1, datum);
    123        1.1       cgd }
    124        1.1       cgd 
    125        1.1       cgd u_int
    126       1.16   tsutsui mcclock_isa_read(struct mc146818_softc *sc, u_int reg)
    127        1.1       cgd {
    128       1.16   tsutsui 	bus_space_tag_t iot = sc->sc_bst;
    129       1.16   tsutsui 	bus_space_handle_t ioh = sc->sc_bsh;
    130        1.1       cgd 
    131        1.3       cgd 	bus_space_write_1(iot, ioh, 0, reg);
    132        1.3       cgd 	return bus_space_read_1(iot, ioh, 1);
    133        1.1       cgd }
    134