1 /* $NetBSD: ichlpcib_hpet.c,v 1.3 2011/07/01 18:22:08 dyoung 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.3 2011/07/01 18:22:08 dyoung Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/bus.h> 36 #include <sys/device.h> 37 #include <sys/time.h> 38 #include <sys/timetc.h> 39 40 #include <dev/ic/hpetreg.h> 41 #include <dev/ic/hpetvar.h> 42 #include <dev/ic/i82801lpcreg.h> 43 #include <dev/ic/i82801lpcvar.h> 44 45 static int lpcib_hpet_match(device_t , cfdata_t , void *); 46 static void lpcib_hpet_attach(device_t, device_t, void *); 47 static int lpcib_hpet_detach(device_t, int); 48 49 CFATTACH_DECL_NEW(ichlpcib_hpet, sizeof(struct hpet_softc), 50 lpcib_hpet_match, lpcib_hpet_attach, lpcib_hpet_detach, NULL); 51 52 static int 53 lpcib_hpet_match(device_t parent, cfdata_t match, void *aux) 54 { 55 struct lpcib_hpet_attach_args *arg = aux; 56 bus_space_handle_t bh; 57 bus_space_tag_t bt; 58 59 bt = arg->hpet_mem_t; 60 61 if (bus_space_map(bt, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &bh) != 0) 62 return 0; 63 64 bus_space_unmap(bt, bh, HPET_WINDOW_SIZE); 65 66 return 1; 67 } 68 69 70 static void 71 lpcib_hpet_attach(device_t parent, device_t self, void *aux) 72 { 73 struct hpet_softc *sc = device_private(self); 74 struct lpcib_hpet_attach_args *arg = aux; 75 76 sc->sc_mapped = false; 77 sc->sc_memt = arg->hpet_mem_t; 78 sc->sc_mems = HPET_WINDOW_SIZE; 79 80 if (bus_space_map(sc->sc_memt, arg->hpet_reg, 81 sc->sc_mems, 0, &sc->sc_memh) != 0) { 82 aprint_error(": failed to map mem space\n"); 83 return; 84 } 85 86 aprint_naive("\n"); 87 aprint_normal(": high precision event timer (mem 0x%08x-0x%08x)\n", 88 arg->hpet_reg, arg->hpet_reg + HPET_WINDOW_SIZE); 89 90 sc->sc_mapped = true; 91 hpet_attach_subr(self); 92 } 93 94 static int 95 lpcib_hpet_detach(device_t self, int flags) 96 { 97 struct hpet_softc *sc = device_private(self); 98 int rv; 99 100 if (sc->sc_mapped != true) 101 return 0; 102 103 rv = hpet_detach(self, flags); 104 105 if (rv != 0) 106 return rv; 107 108 bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems); 109 110 return 0; 111 } 112