Home | History | Annotate | Line # | Download | only in tc
mcclock_ioasic.c revision 1.1
      1  1.1  jonathan /* $NetBSD: mcclock_ioasic.c,v 1.1 1997/06/22 09:34:50 jonathan Exp $ */
      2  1.1  jonathan 
      3  1.1  jonathan /*
      4  1.1  jonathan  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
      5  1.1  jonathan  * All rights reserved.
      6  1.1  jonathan  *
      7  1.1  jonathan  * Author: Chris G. Demetriou
      8  1.1  jonathan  *
      9  1.1  jonathan  * Permission to use, copy, modify and distribute this software and
     10  1.1  jonathan  * its documentation is hereby granted, provided that both the copyright
     11  1.1  jonathan  * notice and this permission notice appear in all copies of the
     12  1.1  jonathan  * software, derivative works or modified versions, and any portions
     13  1.1  jonathan  * thereof, and that both notices appear in supporting documentation.
     14  1.1  jonathan  *
     15  1.1  jonathan  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.1  jonathan  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  1.1  jonathan  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.1  jonathan  *
     19  1.1  jonathan  * Carnegie Mellon requests users of this software to return to
     20  1.1  jonathan  *
     21  1.1  jonathan  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  1.1  jonathan  *  School of Computer Science
     23  1.1  jonathan  *  Carnegie Mellon University
     24  1.1  jonathan  *  Pittsburgh PA 15213-3890
     25  1.1  jonathan  *
     26  1.1  jonathan  * any improvements or extensions that they make and grant Carnegie the
     27  1.1  jonathan  * rights to redistribute these changes.
     28  1.1  jonathan  */
     29  1.1  jonathan 
     30  1.1  jonathan #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31  1.1  jonathan 
     32  1.1  jonathan __KERNEL_RCSID(0, "$NetBSD: mcclock_ioasic.c,v 1.1 1997/06/22 09:34:50 jonathan Exp $");
     33  1.1  jonathan 
     34  1.1  jonathan #include <sys/param.h>
     35  1.1  jonathan #include <sys/kernel.h>
     36  1.1  jonathan #include <sys/systm.h>
     37  1.1  jonathan #include <sys/device.h>
     38  1.1  jonathan 
     39  1.1  jonathan #include <machine/autoconf.h>
     40  1.1  jonathan #include <dev/tc/clockvar.h>
     41  1.1  jonathan #include <dev/tc/mcclockvar.h>
     42  1.1  jonathan #include <dev/ic/mc146818reg.h>
     43  1.1  jonathan #include <dev/tc/tcreg.h>
     44  1.1  jonathan #include <dev/tc/tcvar.h>
     45  1.1  jonathan #include <dev/tc/ioasicvar.h>                   /* XXX */
     46  1.1  jonathan 
     47  1.1  jonathan struct mcclock_ioasic_clockdatum {
     48  1.1  jonathan 	u_char	datum;
     49  1.1  jonathan 	char	pad[3];
     50  1.1  jonathan };
     51  1.1  jonathan 
     52  1.1  jonathan struct mcclock_ioasic_softc {
     53  1.1  jonathan 	struct mcclock_softc	sc_mcclock;
     54  1.1  jonathan 
     55  1.1  jonathan 	struct mcclock_ioasic_clockdatum *sc_dp;
     56  1.1  jonathan };
     57  1.1  jonathan 
     58  1.1  jonathan int	mcclock_ioasic_match __P((struct device *, struct cfdata *, void *));
     59  1.1  jonathan void	mcclock_ioasic_attach __P((struct device *, struct device *, void *));
     60  1.1  jonathan 
     61  1.1  jonathan struct cfattach mcclock_ioasic_ca = {
     62  1.1  jonathan 	sizeof (struct mcclock_ioasic_softc), (void *)mcclock_ioasic_match,
     63  1.1  jonathan 	    mcclock_ioasic_attach,
     64  1.1  jonathan };
     65  1.1  jonathan 
     66  1.1  jonathan void	mcclock_ioasic_write __P((struct mcclock_softc *, u_int, u_int));
     67  1.1  jonathan u_int	mcclock_ioasic_read __P((struct mcclock_softc *, u_int));
     68  1.1  jonathan 
     69  1.1  jonathan const struct mcclock_busfns mcclock_ioasic_busfns = {
     70  1.1  jonathan 	mcclock_ioasic_write, mcclock_ioasic_read,
     71  1.1  jonathan };
     72  1.1  jonathan 
     73  1.1  jonathan volatile struct chiptime *Mach_clock_addr; /* XXX glue for pmax heritage */
     74  1.1  jonathan 
     75  1.1  jonathan int
     76  1.1  jonathan mcclock_ioasic_match(parent, match, aux)
     77  1.1  jonathan 	struct device *parent;
     78  1.1  jonathan 	struct cfdata *match;
     79  1.1  jonathan 	void *aux;
     80  1.1  jonathan {
     81  1.1  jonathan #define	CFMATCH(cf,x) !strcmp((cf)->dv_cfdata->cf_driver->cd_name,(x))
     82  1.1  jonathan 	char *name;
     83  1.1  jonathan 	vm_offset_t addr;
     84  1.1  jonathan 
     85  1.1  jonathan 	if (CFMATCH(parent, "mainbus")) {
     86  1.1  jonathan 		struct confargs *ca = aux;
     87  1.1  jonathan 		addr = (vm_offset_t)ca->ca_addr;
     88  1.1  jonathan 		name = ca->ca_name;
     89  1.1  jonathan 	}
     90  1.1  jonathan 	else
     91  1.1  jonathan 	if (CFMATCH(parent, "asic")) {
     92  1.1  jonathan 		struct ioasicdev_attach_args *d = aux;
     93  1.1  jonathan 		addr = d->iada_addr;
     94  1.1  jonathan 		name = d->iada_modname;
     95  1.1  jonathan 	}
     96  1.1  jonathan 	else {
     97  1.1  jonathan 		/*panic("clock must be attached with mainbus or ioasic\n");*/
     98  1.1  jonathan 		printf("clock on %s: must be attached at mainbus or ioasic\n",
     99  1.1  jonathan 		       parent->dv_cfdata->cf_driver->cd_name);
    100  1.1  jonathan 		return(0);
    101  1.1  jonathan 	}
    102  1.1  jonathan 	if (strcmp("mc146818", name))
    103  1.1  jonathan 		return (0);
    104  1.1  jonathan 	Mach_clock_addr = (struct chiptime *)MIPS_PHYS_TO_KSEG1(addr);
    105  1.1  jonathan 	return (1);
    106  1.1  jonathan #undef	CFMATCH
    107  1.1  jonathan }
    108  1.1  jonathan 
    109  1.1  jonathan void
    110  1.1  jonathan mcclock_ioasic_attach(parent, self, aux)
    111  1.1  jonathan 	struct device *parent, *self;
    112  1.1  jonathan 	void *aux;
    113  1.1  jonathan {
    114  1.1  jonathan 	struct ioasicdev_attach_args *ioasicdev = aux;
    115  1.1  jonathan 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)self;
    116  1.1  jonathan 
    117  1.1  jonathan 	sc->sc_dp = (struct mcclock_ioasic_clockdatum *)ioasicdev->iada_addr;
    118  1.1  jonathan 
    119  1.1  jonathan 	mcclock_attach(&sc->sc_mcclock, &mcclock_ioasic_busfns);
    120  1.1  jonathan }
    121  1.1  jonathan 
    122  1.1  jonathan void
    123  1.1  jonathan mcclock_ioasic_write(dev, reg, datum)
    124  1.1  jonathan 	struct mcclock_softc *dev;
    125  1.1  jonathan 	u_int reg, datum;
    126  1.1  jonathan {
    127  1.1  jonathan 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
    128  1.1  jonathan 
    129  1.1  jonathan 	sc->sc_dp[reg].datum = datum;
    130  1.1  jonathan }
    131  1.1  jonathan 
    132  1.1  jonathan u_int
    133  1.1  jonathan mcclock_ioasic_read(dev, reg)
    134  1.1  jonathan 	struct mcclock_softc *dev;
    135  1.1  jonathan 	u_int reg;
    136  1.1  jonathan {
    137  1.1  jonathan 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
    138  1.1  jonathan 
    139  1.1  jonathan 	return (sc->sc_dp[reg].datum);
    140  1.1  jonathan }
    141  1.1  jonathan 
    142  1.1  jonathan /*XXX*/
    143  1.1  jonathan /*
    144  1.1  jonathan  * Wait "n" microseconds. (scsi code needs this).
    145  1.1  jonathan  */
    146  1.1  jonathan void
    147  1.1  jonathan delay(n)
    148  1.1  jonathan         int n;
    149  1.1  jonathan {
    150  1.1  jonathan         DELAY(n);
    151  1.1  jonathan }
    152