spic_acpi.c revision 1.5 1 /* $NetBSD: spic_acpi.c,v 1.5 2010/01/30 18:35:49 jruoho 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 (at) 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.5 2010/01/30 18:35:49 jruoho 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/acpireg.h>
47 #include <dev/acpi/acpivar.h>
48
49 #define _COMPONENT ACPI_RESOURCE_COMPONENT
50 ACPI_MODULE_NAME ("spic_acpi")
51
52 struct spic_acpi_softc {
53 struct spic_softc sc_spic; /* spic device */
54
55 struct acpi_devnode *sc_node; /* our ACPI devnode */
56
57 void *sc_ih;
58 };
59
60 static const char * const spic_acpi_ids[] = {
61 "SNY6001",
62 NULL
63 };
64
65 static int spic_acpi_match(device_t, cfdata_t, void *);
66 static void spic_acpi_attach(device_t, device_t, void *);
67
68 CFATTACH_DECL_NEW(spic_acpi, sizeof(struct spic_acpi_softc),
69 spic_acpi_match, spic_acpi_attach, NULL, NULL);
70
71
72 static int
73 spic_acpi_match(device_t parent, cfdata_t match, void *aux)
74 {
75 struct acpi_attach_args *aa = aux;
76
77 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
78 return (0);
79
80 return (acpi_match_hid(aa->aa_node->ad_devinfo, spic_acpi_ids));
81 }
82
83 static void
84 spic_acpi_attach(device_t parent, device_t self, void *aux)
85 {
86 struct spic_acpi_softc *sc = device_private(self);
87 struct acpi_attach_args *aa = aux;
88 struct acpi_io *io;
89 struct acpi_irq *irq;
90 struct acpi_resources res;
91
92 ACPI_STATUS rv;
93
94 sc->sc_spic.sc_dev = self;
95 sc->sc_node = aa->aa_node;
96
97 /* Parse our resources. */
98 rv = acpi_resource_parse(self, sc->sc_node->ad_handle,
99 "_CRS", &res, &acpi_resource_parse_ops_default);
100 if (ACPI_FAILURE(rv))
101 return;
102
103 sc->sc_spic.sc_iot = aa->aa_iot;
104 io = acpi_res_io(&res, 0);
105 if (io == NULL) {
106 aprint_error_dev(self, "unable to find io resource\n");
107 goto out;
108 }
109 if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
110 0, &sc->sc_spic.sc_ioh) != 0) {
111 aprint_error_dev(self, "unable to map data register\n");
112 goto out;
113 }
114 irq = acpi_res_irq(&res, 0);
115 if (irq == NULL) {
116 aprint_error_dev(self, "unable to find irq resource\n");
117 /* XXX unmap */
118 goto out;
119 }
120 #if 0
121 sc->sc_ih = isa_intr_establish(NULL, irq->ar_irq,
122 IST_EDGE, IPL_TTY, spic_intr, sc);
123 #endif
124
125 if (!pmf_device_register(self, spic_suspend, spic_resume))
126 aprint_error_dev(self, "couldn't establish power handler\n");
127 else
128 pmf_class_input_register(self);
129
130 spic_attach(&sc->sc_spic);
131 out:
132 acpi_resource_cleanup(&res);
133 }
134