xref: /netbsd-src/sys/dev/acpi/hpet_acpi.c (revision 3816d47b2c42fcd6e549e3407f842a5b1a1d23ad)
1 /* $NetBSD: hpet_acpi.c,v 1.4 2009/02/17 12:46:01 jmcneill Exp $ */
2 
3 /*
4  * Copyright (c) 2006 Nicolas Joly
5  * All rights reserved.
6  *
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.
17  *
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.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.4 2009/02/17 12:46:01 jmcneill Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/device.h>
38 
39 #include <sys/bus.h>
40 
41 #include <dev/acpi/acpica.h>
42 #include <dev/acpi/acpireg.h>
43 #include <dev/acpi/acpivar.h>
44 
45 #include <sys/time.h>
46 #include <sys/timetc.h>
47 
48 #include <dev/ic/hpetvar.h>
49 
50 static int	hpet_acpi_match(device_t, cfdata_t, void *);
51 static void	hpet_acpi_attach(device_t, device_t, void *);
52 
53 
54 CFATTACH_DECL_NEW(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match,
55     hpet_acpi_attach, NULL, NULL);
56 
57 /*
58  * Supported device IDs
59  */
60 
61 static const char * const hpet_acpi_ids[] = {
62 	"PNP0103",
63 	NULL
64 };
65 
66 /*
67  * hpet_acpi_match: autoconf(9) match routine
68  */
69 static int
70 hpet_acpi_match(device_t parent, cfdata_t match, void *aux)
71 {
72 	struct acpi_attach_args *aa = aux;
73 
74 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
75 		return 0;
76 
77 	return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids);
78 }
79 
80 static void
81 hpet_acpi_attach(device_t parent, device_t self, void *aux)
82 {
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;
88 
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;
94 
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;
101 	}
102 
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;
108 	}
109 
110 	hpet_attach_subr(self);
111 
112  out:
113 	acpi_resource_cleanup(&res);
114 }
115