attimer_acpi.c revision 1.11
1/* $NetBSD: attimer_acpi.c,v 1.11 2008/04/28 20:23:47 martin Exp $ */
2
3/*
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Quentin Garnier.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca>
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 *    notice, this list of conditions and the following disclaimer.
41 * 2. The name of the author may not be used to endorse or promote products
42 *    derived from this software without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
48 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
49 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
51 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 */
56
57/*
58 * ACPI attimer(4) attachment based on lpt_acpi.c by Jared D. McNeill.
59 */
60
61#include <sys/cdefs.h>
62__KERNEL_RCSID(0, "$NetBSD: attimer_acpi.c,v 1.11 2008/04/28 20:23:47 martin Exp $");
63
64#include <sys/param.h>
65#include <sys/systm.h>
66#include <sys/errno.h>
67#include <sys/ioctl.h>
68#include <sys/device.h>
69#include <sys/proc.h>
70
71#include <sys/bus.h>
72
73#include <dev/acpi/acpica.h>
74#include <dev/acpi/acpireg.h>
75#include <dev/acpi/acpivar.h>
76
77#include <dev/ic/attimervar.h>
78
79static int	attimer_acpi_match(device_t, cfdata_t, void *);
80static void	attimer_acpi_attach(device_t, device_t, void *);
81
82CFATTACH_DECL_NEW(attimer_acpi, sizeof(struct attimer_softc),
83    attimer_acpi_match, attimer_acpi_attach, attimer_detach, NULL);
84
85/*
86 * Supported device IDs
87 */
88
89static const char * const attimer_acpi_ids[] = {
90	"PNP0100",	/* AT Timer */
91	NULL
92};
93
94/*
95 * attimer_acpi_match: autoconf(9) match routine
96 */
97static int
98attimer_acpi_match(device_t parent, cfdata_t match, void *aux)
99{
100	struct acpi_attach_args *aa = aux;
101
102	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
103		return 0;
104
105	return acpi_match_hid(aa->aa_node->ad_devinfo, attimer_acpi_ids);
106}
107
108/*
109 * attimer_acpi_attach: autoconf(9) attach routine
110 */
111static void
112attimer_acpi_attach(device_t parent, device_t self, void *aux)
113{
114	struct attimer_softc *sc = device_private(self);
115	struct acpi_attach_args *aa = aux;
116	struct acpi_resources res;
117	struct acpi_io *io;
118	ACPI_STATUS rv;
119
120	sc->sc_dev = self;
121
122	aprint_naive(": AT Timer\n");
123	aprint_normal(": AT Timer\n");
124
125	/* parse resources */
126	rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
127	    &res, &acpi_resource_parse_ops_default);
128	if (ACPI_FAILURE(rv))
129		return;
130
131	/* find our i/o registers */
132	io = acpi_res_io(&res, 0);
133	if (io == NULL) {
134		aprint_error_dev(self,
135		    "unable to find i/o register resource\n");
136		goto out;
137	}
138
139	sc->sc_iot = aa->aa_iot;
140	sc->sc_size = io->ar_length;
141	if (bus_space_map(sc->sc_iot, io->ar_base, sc->sc_size,
142		    0, &sc->sc_ioh) != 0) {
143		aprint_error_dev(self, "can't map i/o space\n");
144		goto out;
145	}
146
147	attimer_attach(sc);
148
149 out:
150	acpi_resource_cleanup(&res);
151}
152