ug_acpi.c revision 1.1
1/* $NetBSD: ug_acpi.c,v 1.1 2007/05/08 16:48:38 xtraeme Exp $ */
2
3/*
4 * Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro>
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. The name of the author may not be used to endorse or promote products
13 *    derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
30#include <sys/errno.h>
31#include <sys/ioctl.h>
32#include <sys/syslog.h>
33#include <sys/device.h>
34#include <sys/proc.h>
35#include <sys/envsys.h>
36
37#include <machine/bus.h>
38
39#include <dev/acpi/acpica.h>
40#include <dev/acpi/acpireg.h>
41#include <dev/acpi/acpivar.h>
42
43#include <dev/sysmon/sysmonvar.h>
44
45#include <dev/ic/ugreg.h>
46#include <dev/ic/ugvar.h>
47
48/* autoconf(9) functions */
49static int	ug_acpi_match(struct device *, struct cfdata *, void *);
50static void	ug_acpi_attach(struct device *, struct device *, void *);
51
52CFATTACH_DECL(ug_acpi, sizeof(struct ug_softc), ug_acpi_match,
53    ug_acpi_attach, NULL, NULL);
54
55/*
56 * Supported devices
57 * XXX: only uGuru 2005 for now
58 */
59
60static const char* const ug_acpi_ids[] = {
61	"ABT2005",	/* uGuru 2005 */
62	NULL
63};
64
65static int
66ug_acpi_match(struct device *parent, struct cfdata *match,
67    void *aux)
68{
69	struct acpi_attach_args *aa = aux;
70
71	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
72		return 0;
73
74	return acpi_match_hid(aa->aa_node->ad_devinfo, ug_acpi_ids);
75}
76
77static void
78ug_acpi_attach(struct device *parent, struct device *self, void *aux)
79{
80	struct ug_softc *sc = (struct ug_softc*)self;
81	struct acpi_attach_args *aa = aux;
82	struct acpi_resources res;
83	struct acpi_io *io;
84	bus_space_handle_t ioh;
85	ACPI_STATUS rv;
86
87	aprint_naive("\n");
88	aprint_normal("\n");
89
90	/* parse resources */
91	rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
92	    &res, &acpi_resource_parse_ops_default);
93	if (ACPI_FAILURE(rv))
94		return;
95
96	/* find our i/o registers */
97	io = acpi_res_io(&res, 0);
98	if (io == NULL) {
99		aprint_error("%s: unable to find i/o register resource\n",
100		    sc->sc_dev.dv_xname);
101		acpi_resource_cleanup(&res);
102		return;
103	}
104
105	if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length,
106	    0, &ioh)) {
107		aprint_error("%s: can't map i/o space\n",
108		    sc->sc_dev.dv_xname);
109		acpi_resource_cleanup(&res);
110		return;
111	}
112
113	aprint_normal("%s", sc->sc_dev.dv_xname);
114
115	sc->version = 2;	/* uGuru 2005 */
116	sc->sc_ioh = ioh;
117	sc->sc_iot = aa->aa_iot;
118	ug2_attach(sc);
119
120	acpi_resource_cleanup(&res);
121}
122