hpet_acpi.c revision 1.3
1/* $NetBSD: hpet_acpi.c,v 1.3 2008/03/21 13:28:14 xtraeme 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.3 2008/03/21 13:28:14 xtraeme 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
50static int	hpet_acpi_match(device_t, cfdata_t, void *);
51static void	hpet_acpi_attach(device_t, device_t, void *);
52
53
54CFATTACH_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
61static const char * const hpet_acpi_ids[] = {
62	"PNP0103",
63	NULL
64};
65
66/*
67 * hpet_acpi_match: autoconf(9) match routine
68 */
69static int
70hpet_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
80static void
81hpet_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	aprint_naive("\n");
90	aprint_normal("\n");
91
92	/* parse resources */
93	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
94	    &res, &acpi_resource_parse_ops_default);
95	if (ACPI_FAILURE(rv))
96		return;
97
98	/* find our mem registers */
99	mem = acpi_res_mem(&res, 0);
100	if (mem == NULL) {
101		aprint_error_dev(self,
102		    "unable to find mem register resource\n");
103		goto out;
104	}
105
106	sc->sc_memt = aa->aa_memt;
107	if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length,
108		    0, &sc->sc_memh)) {
109		aprint_error_dev(self, "can't map mem space\n");
110		goto out;
111	}
112
113	hpet_attach_subr(self);
114
115 out:
116	acpi_resource_cleanup(&res);
117}
118