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