xref: /netbsd/sys/dev/acpi/hpet_acpi.c (revision 6550d01e)
1 /* $NetBSD: hpet_acpi.c,v 1.5 2010/03/05 14:00:17 jruoho 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.5 2010/03/05 14:00:17 jruoho Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/device.h>
36 #include <sys/systm.h>
37 #include <sys/time.h>
38 #include <sys/timetc.h>
39 
40 #include <dev/acpi/acpivar.h>
41 
42 #include <dev/ic/hpetvar.h>
43 
44 static int	hpet_acpi_match(device_t, cfdata_t, void *);
45 static void	hpet_acpi_attach(device_t, device_t, void *);
46 
47 
48 CFATTACH_DECL_NEW(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match,
49     hpet_acpi_attach, NULL, NULL);
50 
51 /*
52  * Supported device IDs
53  */
54 
55 static const char * const hpet_acpi_ids[] = {
56 	"PNP0103",
57 	NULL
58 };
59 
60 /*
61  * hpet_acpi_match: autoconf(9) match routine
62  */
63 static int
64 hpet_acpi_match(device_t parent, cfdata_t match, void *aux)
65 {
66 	struct acpi_attach_args *aa = aux;
67 
68 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
69 		return 0;
70 
71 	return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids);
72 }
73 
74 static void
75 hpet_acpi_attach(device_t parent, device_t self, void *aux)
76 {
77 	struct hpet_softc *sc = device_private(self);
78 	struct acpi_attach_args *aa = aux;
79 	struct acpi_resources res;
80 	struct acpi_mem *mem;
81 	ACPI_STATUS rv;
82 
83 	/* parse resources */
84 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
85 	    &res, &acpi_resource_parse_ops_default);
86 	if (ACPI_FAILURE(rv))
87 		return;
88 
89 	/* find our mem registers */
90 	mem = acpi_res_mem(&res, 0);
91 	if (mem == NULL) {
92 		aprint_error_dev(self,
93 		    "unable to find mem register resource\n");
94 		goto out;
95 	}
96 
97 	sc->sc_memt = aa->aa_memt;
98 	if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length,
99 		    0, &sc->sc_memh)) {
100 		aprint_error_dev(self, "can't map mem space\n");
101 		goto out;
102 	}
103 
104 	hpet_attach_subr(self);
105 
106  out:
107 	acpi_resource_cleanup(&res);
108 }
109