hpet_acpi.c revision 1.1
1/* $NetBSD: hpet_acpi.c,v 1.1 2007/03/08 14:26:28 njoly 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.1 2007/03/08 14:26:28 njoly 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 <machine/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(struct device *, struct cfdata *, void *);
51static void	hpet_acpi_attach(struct device *, struct device *, void *);
52
53
54CFATTACH_DECL(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(struct device *parent, struct cfdata *match,
71    void *aux)
72{
73	struct acpi_attach_args *aa = aux;
74
75	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
76		return 0;
77
78	return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids);
79}
80
81static void
82hpet_acpi_attach(struct device *parent, struct device *self, void *aux)
83{
84	struct hpet_softc *sc = (struct hpet_softc *)self;
85	struct acpi_attach_args *aa = aux;
86	struct acpi_resources res;
87	struct acpi_mem *mem;
88	ACPI_STATUS rv;
89
90	aprint_naive("\n");
91	aprint_normal("\n");
92
93	/* parse resources */
94	rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
95	    &res, &acpi_resource_parse_ops_default);
96	if (ACPI_FAILURE(rv))
97		return;
98
99	/* find our mem registers */
100	mem = acpi_res_mem(&res, 0);
101	if (mem == NULL) {
102		aprint_error("%s: unable to find mem register resource\n",
103		    sc->sc_dev.dv_xname);
104		goto out;
105	}
106
107	sc->sc_memt = aa->aa_memt;
108	if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length,
109		    0, &sc->sc_memh)) {
110		aprint_error("%s: can't map mem space\n", sc->sc_dev.dv_xname);
111		goto out;
112	}
113
114	hpet_attach_subr(sc);
115
116 out:
117	acpi_resource_cleanup(&res);
118}
119