Home | History | Annotate | Line # | Download | only in isa
attimer_isa.c revision 1.9.6.1
      1  1.9.6.1     mjf /*	$NetBSD: attimer_isa.c,v 1.9.6.1 2008/04/03 12:42:44 mjf Exp $	*/
      2      1.1    cube 
      3      1.1    cube /*
      4      1.1    cube  *  Copyright (c) 2005 The NetBSD Foundation.
      5      1.1    cube  *  All rights reserved.
      6      1.1    cube  *
      7      1.1    cube  *  Redistribution and use in source and binary forms, with or without
      8      1.1    cube  *  modification, are permitted provided that the following conditions
      9      1.1    cube  *  are met:
     10      1.1    cube  *  1. Redistributions of source code must retain the above copyright
     11      1.1    cube  *     notice, this list of conditions and the following disclaimer.
     12      1.1    cube  *  2. Redistributions in binary form must reproduce the above copyright
     13      1.1    cube  *     notice, this list of conditions and the following disclaimer in the
     14      1.1    cube  *     documentation and/or other materials provided with the distribution.
     15      1.6    cube  *  3. Neither the name of The NetBSD Foundation nor the names of its
     16      1.1    cube  *     contributors may be used to endorse or promote products derived
     17      1.1    cube  *     from this software without specific prior written permission.
     18      1.1    cube  *
     19      1.1    cube  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1    cube  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1    cube  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1    cube  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1    cube  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1    cube  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1    cube  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1    cube  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1    cube  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1    cube  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1    cube  *  POSSIBILITY OF SUCH DAMAGE.
     30      1.1    cube  */
     31      1.1    cube 
     32      1.1    cube /*
     33      1.1    cube  * Copyright (c) 1996 Carnegie-Mellon University.
     34      1.1    cube  * All rights reserved.
     35      1.1    cube  *
     36      1.1    cube  * Author: Chris G. Demetriou
     37      1.1    cube  *
     38      1.1    cube  * Permission to use, copy, modify and distribute this software and
     39      1.1    cube  * its documentation is hereby granted, provided that both the copyright
     40      1.1    cube  * notice and this permission notice appear in all copies of the
     41      1.1    cube  * software, derivative works or modified versions, and any portions
     42      1.1    cube  * thereof, and that both notices appear in supporting documentation.
     43      1.1    cube  *
     44      1.1    cube  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     45      1.1    cube  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     46      1.1    cube  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     47      1.1    cube  *
     48      1.1    cube  * Carnegie Mellon requests users of this software to return to
     49      1.1    cube  *
     50      1.1    cube  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     51      1.1    cube  *  School of Computer Science
     52      1.1    cube  *  Carnegie Mellon University
     53      1.1    cube  *  Pittsburgh PA 15213-3890
     54      1.1    cube  *
     55      1.1    cube  * any improvements or extensions that they make and grant Carnegie the
     56      1.1    cube  * rights to redistribute these changes.
     57      1.1    cube  */
     58      1.1    cube 
     59      1.1    cube /*
     60      1.1    cube  * ISA attachment for attimer(4)
     61      1.1    cube  */
     62      1.1    cube 
     63      1.1    cube #include <sys/cdefs.h>
     64  1.9.6.1     mjf __KERNEL_RCSID(0, "$NetBSD: attimer_isa.c,v 1.9.6.1 2008/04/03 12:42:44 mjf Exp $");
     65      1.1    cube 
     66      1.1    cube #include <sys/param.h>
     67      1.1    cube #include <sys/systm.h>
     68      1.1    cube #include <sys/errno.h>
     69      1.1    cube #include <sys/ioctl.h>
     70      1.1    cube #include <sys/device.h>
     71      1.1    cube #include <sys/proc.h>
     72      1.1    cube 
     73      1.7      ad #include <sys/bus.h>
     74      1.1    cube 
     75      1.1    cube #include <dev/ic/attimervar.h>
     76      1.1    cube 
     77      1.1    cube #include <dev/isa/isareg.h>
     78      1.1    cube #include <dev/isa/isavar.h>
     79      1.1    cube 
     80      1.8  dyoung static int	attimer_isa_match(device_t, struct cfdata *, void *);
     81      1.8  dyoung static void	attimer_isa_attach(device_t, device_t, void *);
     82      1.1    cube 
     83  1.9.6.1     mjf CFATTACH_DECL_NEW(attimer_isa, sizeof(struct attimer_softc),
     84      1.9  dyoung     attimer_isa_match, attimer_isa_attach, attimer_detach, NULL);
     85      1.1    cube 
     86      1.1    cube static int
     87  1.9.6.1     mjf attimer_isa_match(device_t parent, cfdata_t match, void *aux)
     88      1.1    cube {
     89      1.1    cube 	struct isa_attach_args *ia = aux;
     90      1.1    cube 	bus_space_handle_t att_ioh;
     91      1.1    cube 
     92      1.1    cube 	if (ISA_DIRECT_CONFIG(ia))
     93      1.1    cube 		return (0);
     94      1.1    cube 
     95      1.1    cube 	/* If values are hardwired to something that they can't be, punt. */
     96      1.1    cube 	if (ia->ia_nio < 1 ||
     97      1.1    cube 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
     98      1.1    cube 	    ia->ia_io[0].ir_addr != IO_TIMER1))
     99      1.1    cube 		return (0);
    100      1.1    cube 
    101      1.1    cube 	if (ia->ia_niomem > 0 &&
    102      1.1    cube 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
    103      1.1    cube 		return (0);
    104      1.1    cube 
    105      1.1    cube 	if (ia->ia_nirq > 0 &&
    106      1.1    cube 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
    107      1.1    cube 		return (0);
    108      1.1    cube 
    109      1.1    cube 	if (ia->ia_ndrq > 0 &&
    110      1.1    cube 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
    111      1.1    cube 		return (0);
    112      1.1    cube 
    113      1.1    cube 	if (bus_space_map(ia->ia_iot, IO_TIMER1, 4, 0, &att_ioh))
    114      1.1    cube 		return 0;
    115      1.1    cube 	bus_space_unmap(ia->ia_iot, att_ioh, 4);
    116      1.1    cube 
    117      1.1    cube 	ia->ia_io[0].ir_addr = IO_TIMER1;
    118      1.1    cube 	ia->ia_io[0].ir_size = 4;
    119      1.1    cube 	ia->ia_nio = 1;
    120      1.1    cube 
    121      1.1    cube 	ia->ia_niomem = 0;
    122      1.1    cube 	ia->ia_nirq = 0;
    123      1.1    cube 	ia->ia_ndrq = 0;
    124      1.1    cube 
    125      1.1    cube 	return 1;
    126      1.1    cube }
    127      1.1    cube 
    128      1.1    cube static void
    129      1.8  dyoung attimer_isa_attach(device_t parent, device_t self, void *aux)
    130      1.1    cube {
    131      1.8  dyoung 	struct attimer_softc *sc = device_private(self);
    132      1.1    cube 	struct isa_attach_args *ia = aux;
    133      1.1    cube 
    134  1.9.6.1     mjf 	sc->sc_dev = self;
    135      1.1    cube 	sc->sc_iot = ia->ia_iot;
    136      1.1    cube 
    137      1.5     uwe 	aprint_naive(": AT Timer\n");
    138      1.1    cube 	aprint_normal(": AT Timer\n");
    139      1.1    cube 
    140      1.9  dyoung 	sc->sc_size = 4;
    141      1.9  dyoung 	if (bus_space_map(sc->sc_iot, IO_TIMER1, sc->sc_size, 0,
    142      1.9  dyoung 	                  &sc->sc_ioh) != 0)
    143  1.9.6.1     mjf 		aprint_error_dev(self, "could not map registers\n");
    144      1.1    cube 	else
    145      1.1    cube 		attimer_attach(sc);
    146      1.1    cube }
    147