Home | History | Annotate | Line # | Download | only in pci
ichlpcib_hpet.c revision 1.2.2.2
      1 /* $NetBSD: ichlpcib_hpet.c,v 1.2.2.2 2011/06/23 14:19:48 cherry Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Minoura Makoto and Matthew R. Green.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: ichlpcib_hpet.c,v 1.2.2.2 2011/06/23 14:19:48 cherry Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/device.h>
     36 #include <sys/time.h>
     37 #include <sys/timetc.h>
     38 
     39 #include <machine/bus.h>
     40 
     41 #include <dev/ic/hpetreg.h>
     42 #include <dev/ic/hpetvar.h>
     43 #include <dev/ic/i82801lpcreg.h>
     44 #include <dev/ic/i82801lpcvar.h>
     45 
     46 static int	lpcib_hpet_match(device_t , cfdata_t , void *);
     47 static void	lpcib_hpet_attach(device_t, device_t, void *);
     48 static int	lpcib_hpet_detach(device_t, int);
     49 
     50 CFATTACH_DECL_NEW(ichlpcib_hpet, sizeof(struct hpet_softc),
     51     lpcib_hpet_match, lpcib_hpet_attach, lpcib_hpet_detach, NULL);
     52 
     53 static int
     54 lpcib_hpet_match(device_t parent, cfdata_t match, void *aux)
     55 {
     56 	struct lpcib_hpet_attach_args *arg = aux;
     57 	bus_space_handle_t bh;
     58 	bus_space_tag_t bt;
     59 
     60 	bt = arg->hpet_mem_t;
     61 
     62 	if (bus_space_map(bt, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &bh) != 0)
     63 		return 0;
     64 
     65 	bus_space_unmap(bt, bh, HPET_WINDOW_SIZE);
     66 
     67 	return 1;
     68 }
     69 
     70 
     71 static void
     72 lpcib_hpet_attach(device_t parent, device_t self, void *aux)
     73 {
     74 	struct hpet_softc *sc = device_private(self);
     75 	struct lpcib_hpet_attach_args *arg = aux;
     76 
     77 	sc->sc_mapped = false;
     78 	sc->sc_memt = arg->hpet_mem_t;
     79 	sc->sc_mems = HPET_WINDOW_SIZE;
     80 
     81 	if (bus_space_map(sc->sc_memt, arg->hpet_reg,
     82 		sc->sc_mems, 0, &sc->sc_memh) != 0) {
     83 		aprint_error(": failed to map mem space\n");
     84 		return;
     85 	}
     86 
     87 	aprint_naive("\n");
     88 	aprint_normal(": high precision event timer (mem 0x%08x-0x%08x)\n",
     89 	    arg->hpet_reg, arg->hpet_reg + HPET_WINDOW_SIZE);
     90 
     91 	sc->sc_mapped = true;
     92 	hpet_attach_subr(self);
     93 }
     94 
     95 static int
     96 lpcib_hpet_detach(device_t self, int flags)
     97 {
     98 	struct hpet_softc *sc = device_private(self);
     99 	int rv;
    100 
    101 	if (sc->sc_mapped != true)
    102 		return 0;
    103 
    104 	rv = hpet_detach(self, flags);
    105 
    106 	if (rv != 0)
    107 		return rv;
    108 
    109 	bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
    110 
    111 	return 0;
    112 }
    113