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