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