1*37725553Sthorpej /* $NetBSD: ug_acpi.c,v 1.7 2021/01/29 15:49:55 thorpej Exp $ */
2ff1c4148Sxtraeme
3ff1c4148Sxtraeme /*
4ff1c4148Sxtraeme * Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro>
5ff1c4148Sxtraeme * All rights reserved.
6ff1c4148Sxtraeme *
7ff1c4148Sxtraeme * Redistribution and use in source and binary forms, with or without
8ff1c4148Sxtraeme * modification, are permitted provided that the following conditions
9ff1c4148Sxtraeme * are met:
10ff1c4148Sxtraeme * 1. Redistributions of source code must retain the above copyright
11ff1c4148Sxtraeme * notice, this list of conditions and the following disclaimer.
12ff1c4148Sxtraeme * 2. The name of the author may not be used to endorse or promote products
13ff1c4148Sxtraeme * derived from this software without specific prior written permission.
14ff1c4148Sxtraeme *
15ff1c4148Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16ff1c4148Sxtraeme * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17ff1c4148Sxtraeme * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18ff1c4148Sxtraeme * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19ff1c4148Sxtraeme * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20ff1c4148Sxtraeme * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21ff1c4148Sxtraeme * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22ff1c4148Sxtraeme * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23ff1c4148Sxtraeme * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ff1c4148Sxtraeme * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ff1c4148Sxtraeme * SUCH DAMAGE.
26ff1c4148Sxtraeme */
27ff1c4148Sxtraeme
2859000b71Sxtraeme #include <sys/cdefs.h>
29*37725553Sthorpej __KERNEL_RCSID(0, "$NetBSD: ug_acpi.c,v 1.7 2021/01/29 15:49:55 thorpej Exp $");
3059000b71Sxtraeme
31ff1c4148Sxtraeme #include <sys/param.h>
32ff1c4148Sxtraeme #include <sys/device.h>
335a425210Sjruoho #include <sys/systm.h>
34ff1c4148Sxtraeme
35ff1c4148Sxtraeme #include <dev/acpi/acpivar.h>
36ff1c4148Sxtraeme
37ff1c4148Sxtraeme #include <dev/ic/ugreg.h>
38ff1c4148Sxtraeme #include <dev/ic/ugvar.h>
39ff1c4148Sxtraeme
40ff1c4148Sxtraeme /* autoconf(9) functions */
418bea7f6bSxtraeme static int ug_acpi_match(device_t, cfdata_t, void *);
428bea7f6bSxtraeme static void ug_acpi_attach(device_t, device_t, void *);
43ff1c4148Sxtraeme
448bea7f6bSxtraeme CFATTACH_DECL_NEW(ug_acpi, sizeof(struct ug_softc), ug_acpi_match,
45ff1c4148Sxtraeme ug_acpi_attach, NULL, NULL);
46ff1c4148Sxtraeme
47ff1c4148Sxtraeme /*
48ff1c4148Sxtraeme * Supported devices
49ff1c4148Sxtraeme * XXX: only uGuru 2005 for now
50ff1c4148Sxtraeme */
51ff1c4148Sxtraeme
52*37725553Sthorpej static const struct device_compatible_entry compat_data[] = {
53*37725553Sthorpej { .compat = "ABT2005" }, /* uGuru 2005 */
54*37725553Sthorpej DEVICE_COMPAT_EOL
55ff1c4148Sxtraeme };
56ff1c4148Sxtraeme
57ff1c4148Sxtraeme static int
ug_acpi_match(device_t parent,cfdata_t match,void * aux)588bea7f6bSxtraeme ug_acpi_match(device_t parent, cfdata_t match, void *aux)
59ff1c4148Sxtraeme {
60ff1c4148Sxtraeme struct acpi_attach_args *aa = aux;
61ff1c4148Sxtraeme
62*37725553Sthorpej return acpi_compatible_match(aa, compat_data);
63ff1c4148Sxtraeme }
64ff1c4148Sxtraeme
65ff1c4148Sxtraeme static void
ug_acpi_attach(device_t parent,device_t self,void * aux)668bea7f6bSxtraeme ug_acpi_attach(device_t parent, device_t self, void *aux)
67ff1c4148Sxtraeme {
688bea7f6bSxtraeme struct ug_softc *sc = device_private(self);
69ff1c4148Sxtraeme struct acpi_attach_args *aa = aux;
70ff1c4148Sxtraeme struct acpi_resources res;
71ff1c4148Sxtraeme struct acpi_io *io;
72ff1c4148Sxtraeme bus_space_handle_t ioh;
73ff1c4148Sxtraeme ACPI_STATUS rv;
74ff1c4148Sxtraeme
75ff1c4148Sxtraeme /* parse resources */
768bea7f6bSxtraeme rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
77ff1c4148Sxtraeme &res, &acpi_resource_parse_ops_default);
78ff1c4148Sxtraeme if (ACPI_FAILURE(rv))
79ff1c4148Sxtraeme return;
80ff1c4148Sxtraeme
81ff1c4148Sxtraeme /* find our i/o registers */
82ff1c4148Sxtraeme io = acpi_res_io(&res, 0);
83ff1c4148Sxtraeme if (io == NULL) {
848bea7f6bSxtraeme aprint_error_dev(self,
858bea7f6bSxtraeme "unable to find i/o register resource\n");
86ff1c4148Sxtraeme acpi_resource_cleanup(&res);
87ff1c4148Sxtraeme return;
88ff1c4148Sxtraeme }
89ff1c4148Sxtraeme
90ff1c4148Sxtraeme if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length,
91ff1c4148Sxtraeme 0, &ioh)) {
928bea7f6bSxtraeme aprint_error_dev(self, "can't map i/o space\n");
93ff1c4148Sxtraeme acpi_resource_cleanup(&res);
94ff1c4148Sxtraeme return;
95ff1c4148Sxtraeme }
96ff1c4148Sxtraeme
978bea7f6bSxtraeme aprint_normal("%s", device_xname(self));
98ff1c4148Sxtraeme
99ff1c4148Sxtraeme sc->version = 2; /* uGuru 2005 */
100ff1c4148Sxtraeme sc->sc_ioh = ioh;
101ff1c4148Sxtraeme sc->sc_iot = aa->aa_iot;
1028bea7f6bSxtraeme ug2_attach(self);
103ff1c4148Sxtraeme
104ff1c4148Sxtraeme acpi_resource_cleanup(&res);
105ff1c4148Sxtraeme }
106