Home | History | Annotate | Line # | Download | only in tc
mcclock_ioasic.c revision 1.3.2.1
      1  1.3.2.1   thorpej /* $NetBSD: mcclock_ioasic.c,v 1.3.2.1 1997/08/23 07:11:56 thorpej 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.3.2.1   thorpej __KERNEL_RCSID(0, "$NetBSD: mcclock_ioasic.c,v 1.3.2.1 1997/08/23 07:11:56 thorpej 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.2  jonathan #include <dev/dec/clockvar.h>
     41      1.3  jonathan #include <dev/dec/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 
     74      1.1  jonathan int
     75      1.1  jonathan mcclock_ioasic_match(parent, match, aux)
     76      1.1  jonathan 	struct device *parent;
     77      1.1  jonathan 	struct cfdata *match;
     78      1.1  jonathan 	void *aux;
     79      1.1  jonathan {
     80      1.1  jonathan #define	CFMATCH(cf,x) !strcmp((cf)->dv_cfdata->cf_driver->cd_name,(x))
     81      1.1  jonathan 	char *name;
     82      1.1  jonathan 	vm_offset_t addr;
     83      1.1  jonathan 
     84      1.1  jonathan 	if (CFMATCH(parent, "mainbus")) {
     85      1.1  jonathan 		struct confargs *ca = aux;
     86      1.1  jonathan 		addr = (vm_offset_t)ca->ca_addr;
     87      1.1  jonathan 		name = ca->ca_name;
     88      1.1  jonathan 	}
     89      1.1  jonathan 	else
     90      1.1  jonathan 	if (CFMATCH(parent, "asic")) {
     91      1.1  jonathan 		struct ioasicdev_attach_args *d = aux;
     92      1.1  jonathan 		addr = d->iada_addr;
     93      1.1  jonathan 		name = d->iada_modname;
     94      1.1  jonathan 	}
     95      1.1  jonathan 	else {
     96      1.1  jonathan 		/*panic("clock must be attached with mainbus or ioasic\n");*/
     97      1.1  jonathan 		printf("clock on %s: must be attached at mainbus or ioasic\n",
     98      1.1  jonathan 		       parent->dv_cfdata->cf_driver->cd_name);
     99      1.1  jonathan 		return(0);
    100      1.1  jonathan 	}
    101      1.1  jonathan 	if (strcmp("mc146818", name))
    102      1.1  jonathan 		return (0);
    103      1.1  jonathan 	return (1);
    104      1.1  jonathan #undef	CFMATCH
    105      1.1  jonathan }
    106      1.1  jonathan 
    107      1.1  jonathan void
    108      1.1  jonathan mcclock_ioasic_attach(parent, self, aux)
    109      1.1  jonathan 	struct device *parent, *self;
    110      1.1  jonathan 	void *aux;
    111      1.1  jonathan {
    112      1.1  jonathan 	struct ioasicdev_attach_args *ioasicdev = aux;
    113      1.1  jonathan 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)self;
    114      1.1  jonathan 
    115      1.1  jonathan 	sc->sc_dp = (struct mcclock_ioasic_clockdatum *)ioasicdev->iada_addr;
    116      1.1  jonathan 
    117      1.1  jonathan 	mcclock_attach(&sc->sc_mcclock, &mcclock_ioasic_busfns);
    118      1.1  jonathan }
    119      1.1  jonathan 
    120      1.1  jonathan void
    121      1.1  jonathan mcclock_ioasic_write(dev, reg, datum)
    122      1.1  jonathan 	struct mcclock_softc *dev;
    123      1.1  jonathan 	u_int reg, datum;
    124      1.1  jonathan {
    125      1.1  jonathan 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
    126      1.1  jonathan 
    127      1.1  jonathan 	sc->sc_dp[reg].datum = datum;
    128      1.1  jonathan }
    129      1.1  jonathan 
    130      1.1  jonathan u_int
    131      1.1  jonathan mcclock_ioasic_read(dev, reg)
    132      1.1  jonathan 	struct mcclock_softc *dev;
    133      1.1  jonathan 	u_int reg;
    134      1.1  jonathan {
    135      1.1  jonathan 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
    136      1.1  jonathan 
    137      1.1  jonathan 	return (sc->sc_dp[reg].datum);
    138      1.1  jonathan }
    139      1.1  jonathan 
    140      1.1  jonathan /*XXX*/
    141      1.1  jonathan /*
    142      1.1  jonathan  * Wait "n" microseconds. (scsi code needs this).
    143      1.1  jonathan  */
    144      1.1  jonathan void
    145      1.1  jonathan delay(n)
    146      1.1  jonathan         int n;
    147      1.1  jonathan {
    148      1.1  jonathan         DELAY(n);
    149      1.1  jonathan }
    150