Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / acpi / hpet_acpi.c
blob6fcb31a9f7954ec4ad52c4e0458c45c9044897fd
1 /* $NetBSD: hpet_acpi.c,v 1.3 2008/03/21 13:28:14 xtraeme Exp $ */
3 /*
4 * Copyright (c) 2006 Nicolas Joly
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.3 2008/03/21 13:28:14 xtraeme Exp $");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/device.h>
39 #include <sys/bus.h>
41 #include <dev/acpi/acpica.h>
42 #include <dev/acpi/acpireg.h>
43 #include <dev/acpi/acpivar.h>
45 #include <sys/time.h>
46 #include <sys/timetc.h>
48 #include <dev/ic/hpetvar.h>
50 static int hpet_acpi_match(device_t, cfdata_t, void *);
51 static void hpet_acpi_attach(device_t, device_t, void *);
54 CFATTACH_DECL_NEW(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match,
55 hpet_acpi_attach, NULL, NULL);
58 * Supported device IDs
61 static const char * const hpet_acpi_ids[] = {
62 "PNP0103",
63 NULL
67 * hpet_acpi_match: autoconf(9) match routine
69 static int
70 hpet_acpi_match(device_t parent, cfdata_t match, void *aux)
72 struct acpi_attach_args *aa = aux;
74 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
75 return 0;
77 return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids);
80 static void
81 hpet_acpi_attach(device_t parent, device_t self, void *aux)
83 struct hpet_softc *sc = device_private(self);
84 struct acpi_attach_args *aa = aux;
85 struct acpi_resources res;
86 struct acpi_mem *mem;
87 ACPI_STATUS rv;
89 /* parse resources */
90 rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
91 &res, &acpi_resource_parse_ops_default);
92 if (ACPI_FAILURE(rv))
93 return;
95 /* find our mem registers */
96 mem = acpi_res_mem(&res, 0);
97 if (mem == NULL) {
98 aprint_error_dev(self,
99 "unable to find mem register resource\n");
100 goto out;
103 sc->sc_memt = aa->aa_memt;
104 if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length,
105 0, &sc->sc_memh)) {
106 aprint_error_dev(self, "can't map mem space\n");
107 goto out;
110 hpet_attach_subr(self);
112 out:
113 acpi_resource_cleanup(&res);