xref: /netbsd-src/sys/dev/acpi/spic_acpi.c (revision 3816d47b2c42fcd6e549e3407f842a5b1a1d23ad)
1 /*	$NetBSD: spic_acpi.c,v 1.4 2009/08/09 19:36:28 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Lennart Augustsson (lennart@augustsson.net).
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 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: spic_acpi.c,v 1.4 2009/08/09 19:36:28 christos Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/proc.h>
39 #include <sys/kernel.h>
40 #include <sys/callout.h>
41 #include <sys/bus.h>
42 
43 #include <dev/ic/spicvar.h>
44 
45 #include <dev/acpi/acpica.h>
46 #include <dev/acpi/acpivar.h>
47 
48 struct spic_acpi_softc {
49 	struct spic_softc sc_spic;	/* spic device */
50 
51 	struct acpi_devnode *sc_node;	/* our ACPI devnode */
52 
53 	void *sc_ih;
54 };
55 
56 static const char * const spic_acpi_ids[] = {
57 	"SNY6001",
58 	NULL
59 };
60 
61 static int	spic_acpi_match(device_t, cfdata_t, void *);
62 static void	spic_acpi_attach(device_t, device_t, void *);
63 
64 CFATTACH_DECL_NEW(spic_acpi, sizeof(struct spic_acpi_softc),
65     spic_acpi_match, spic_acpi_attach, NULL, NULL);
66 
67 
68 static int
69 spic_acpi_match(device_t parent, cfdata_t match, void *aux)
70 {
71 	struct acpi_attach_args *aa = aux;
72 
73 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
74 		return (0);
75 
76 	return (acpi_match_hid(aa->aa_node->ad_devinfo, spic_acpi_ids));
77 }
78 
79 static void
80 spic_acpi_attach(device_t parent, device_t self, void *aux)
81 {
82 	struct spic_acpi_softc *sc = device_private(self);
83 	struct acpi_attach_args *aa = aux;
84 	struct acpi_io *io;
85 	struct acpi_irq *irq;
86 	struct acpi_resources res;
87 
88 	ACPI_STATUS rv;
89 
90 	sc->sc_spic.sc_dev = self;
91 	sc->sc_node = aa->aa_node;
92 
93 	/* Parse our resources. */
94 	rv = acpi_resource_parse(self, sc->sc_node->ad_handle,
95 	    "_CRS", &res, &acpi_resource_parse_ops_default);
96 	if (ACPI_FAILURE(rv))
97 		return;
98 
99 	sc->sc_spic.sc_iot = aa->aa_iot;
100 	io = acpi_res_io(&res, 0);
101 	if (io == NULL) {
102 		aprint_error_dev(self, "unable to find io resource\n");
103 		goto out;
104 	}
105 	if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
106 	    0, &sc->sc_spic.sc_ioh) != 0) {
107 		aprint_error_dev(self, "unable to map data register\n");
108 		goto out;
109 	}
110 	irq = acpi_res_irq(&res, 0);
111 	if (irq == NULL) {
112 		aprint_error_dev(self, "unable to find irq resource\n");
113 		/* XXX unmap */
114 		goto out;
115 	}
116 #if 0
117 	sc->sc_ih = isa_intr_establish(NULL, irq->ar_irq,
118 	    IST_EDGE, IPL_TTY, spic_intr, sc);
119 #endif
120 
121 	if (!pmf_device_register(self, spic_suspend, spic_resume))
122 		aprint_error_dev(self, "couldn't establish power handler\n");
123 	else
124 		pmf_class_input_register(self);
125 
126 	spic_attach(&sc->sc_spic);
127  out:
128 	acpi_resource_cleanup(&res);
129 }
130