wmi_msi.c revision 1.5.2.2 1 1.5.2.2 rmind /* $NetBSD: wmi_msi.c,v 1.5.2.2 2011/03/05 20:53:05 rmind Exp $ */
2 1.5.2.2 rmind
3 1.5.2.2 rmind /*-
4 1.5.2.2 rmind * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 1.5.2.2 rmind * All rights reserved.
6 1.5.2.2 rmind *
7 1.5.2.2 rmind * This code is derived from software contributed to The NetBSD Foundation
8 1.5.2.2 rmind * by Jukka Ruohonen.
9 1.5.2.2 rmind *
10 1.5.2.2 rmind * Redistribution and use in source and binary forms, with or without
11 1.5.2.2 rmind * modification, are permitted provided that the following conditions
12 1.5.2.2 rmind * are met:
13 1.5.2.2 rmind *
14 1.5.2.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.5.2.2 rmind * notice, this list of conditions and the following disclaimer.
16 1.5.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
17 1.5.2.2 rmind * notice, this list of conditions and the following disclaimer in the
18 1.5.2.2 rmind * documentation and/or other materials provided with the distribution.
19 1.5.2.2 rmind *
20 1.5.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 1.5.2.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.5.2.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.5.2.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 1.5.2.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.5.2.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.5.2.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.5.2.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.5.2.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.5.2.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.5.2.2 rmind * SUCH DAMAGE.
31 1.5.2.2 rmind */
32 1.5.2.2 rmind
33 1.5.2.2 rmind #include <sys/cdefs.h>
34 1.5.2.2 rmind __KERNEL_RCSID(0, "$NetBSD: wmi_msi.c,v 1.5.2.2 2011/03/05 20:53:05 rmind Exp $");
35 1.5.2.2 rmind
36 1.5.2.2 rmind #include <sys/param.h>
37 1.5.2.2 rmind #include <sys/device.h>
38 1.5.2.2 rmind #include <sys/module.h>
39 1.5.2.2 rmind
40 1.5.2.2 rmind #include <dev/acpi/acpireg.h>
41 1.5.2.2 rmind #include <dev/acpi/acpivar.h>
42 1.5.2.2 rmind #include <dev/acpi/wmi/wmi_acpivar.h>
43 1.5.2.2 rmind
44 1.5.2.2 rmind #define _COMPONENT ACPI_RESOURCE_COMPONENT
45 1.5.2.2 rmind ACPI_MODULE_NAME ("wmi_msi")
46 1.5.2.2 rmind
47 1.5.2.2 rmind #define WMI_MSI_HOTKEY_BRIGHTNESS_UP 0xD0
48 1.5.2.2 rmind #define WMI_MSI_HOTKEY_BRIGHTNESS_DOWN 0xD1
49 1.5.2.2 rmind #define WMI_MSI_HOTKEY_VOLUME_UP 0xD2
50 1.5.2.2 rmind #define WMI_MSI_HOTKEY_VOLUME_DOWN 0xD3
51 1.5.2.2 rmind /* WMI_MSI_HOTKEY_UNKNOWN 0xXXXX */
52 1.5.2.2 rmind
53 1.5.2.2 rmind #define WMI_MSI_GUID_EVENT "B6F3EEF2-3D2F-49DC-9DE3-85BCE18C62F2"
54 1.5.2.2 rmind
55 1.5.2.2 rmind struct wmi_msi_softc {
56 1.5.2.2 rmind device_t sc_dev;
57 1.5.2.2 rmind device_t sc_parent;
58 1.5.2.2 rmind };
59 1.5.2.2 rmind
60 1.5.2.2 rmind static int wmi_msi_match(device_t, cfdata_t, void *);
61 1.5.2.2 rmind static void wmi_msi_attach(device_t, device_t, void *);
62 1.5.2.2 rmind static int wmi_msi_detach(device_t, int);
63 1.5.2.2 rmind static void wmi_msi_notify_handler(ACPI_HANDLE, uint32_t, void *);
64 1.5.2.2 rmind static bool wmi_msi_suspend(device_t, const pmf_qual_t *);
65 1.5.2.2 rmind static bool wmi_msi_resume(device_t, const pmf_qual_t *);
66 1.5.2.2 rmind
67 1.5.2.2 rmind CFATTACH_DECL_NEW(wmimsi, sizeof(struct wmi_msi_softc),
68 1.5.2.2 rmind wmi_msi_match, wmi_msi_attach, wmi_msi_detach, NULL);
69 1.5.2.2 rmind
70 1.5.2.2 rmind static int
71 1.5.2.2 rmind wmi_msi_match(device_t parent, cfdata_t match, void *aux)
72 1.5.2.2 rmind {
73 1.5.2.2 rmind return acpi_wmi_guid_match(parent, WMI_MSI_GUID_EVENT);
74 1.5.2.2 rmind }
75 1.5.2.2 rmind
76 1.5.2.2 rmind static void
77 1.5.2.2 rmind wmi_msi_attach(device_t parent, device_t self, void *aux)
78 1.5.2.2 rmind {
79 1.5.2.2 rmind struct wmi_msi_softc *sc = device_private(self);
80 1.5.2.2 rmind ACPI_STATUS rv;
81 1.5.2.2 rmind
82 1.5.2.2 rmind sc->sc_dev = self;
83 1.5.2.2 rmind sc->sc_parent = parent;
84 1.5.2.2 rmind
85 1.5.2.2 rmind rv = acpi_wmi_event_register(parent, wmi_msi_notify_handler);
86 1.5.2.2 rmind
87 1.5.2.2 rmind if (ACPI_FAILURE(rv)) {
88 1.5.2.2 rmind aprint_error(": failed to install WMI notify handler\n");
89 1.5.2.2 rmind return;
90 1.5.2.2 rmind }
91 1.5.2.2 rmind
92 1.5.2.2 rmind aprint_naive("\n");
93 1.5.2.2 rmind aprint_normal(": MSI WMI mappings\n");
94 1.5.2.2 rmind
95 1.5.2.2 rmind (void)pmf_device_register(self, wmi_msi_suspend, wmi_msi_resume);
96 1.5.2.2 rmind }
97 1.5.2.2 rmind
98 1.5.2.2 rmind static int
99 1.5.2.2 rmind wmi_msi_detach(device_t self, int flags)
100 1.5.2.2 rmind {
101 1.5.2.2 rmind struct wmi_msi_softc *sc = device_private(self);
102 1.5.2.2 rmind device_t parent = sc->sc_parent;
103 1.5.2.2 rmind
104 1.5.2.2 rmind (void)pmf_device_deregister(self);
105 1.5.2.2 rmind (void)acpi_wmi_event_deregister(parent);
106 1.5.2.2 rmind
107 1.5.2.2 rmind return 0;
108 1.5.2.2 rmind }
109 1.5.2.2 rmind
110 1.5.2.2 rmind static bool
111 1.5.2.2 rmind wmi_msi_suspend(device_t self, const pmf_qual_t *qual)
112 1.5.2.2 rmind {
113 1.5.2.2 rmind struct wmi_msi_softc *sc = device_private(self);
114 1.5.2.2 rmind device_t parent = sc->sc_parent;
115 1.5.2.2 rmind
116 1.5.2.2 rmind (void)acpi_wmi_event_deregister(parent);
117 1.5.2.2 rmind
118 1.5.2.2 rmind return true;
119 1.5.2.2 rmind }
120 1.5.2.2 rmind
121 1.5.2.2 rmind static bool
122 1.5.2.2 rmind wmi_msi_resume(device_t self, const pmf_qual_t *qual)
123 1.5.2.2 rmind {
124 1.5.2.2 rmind struct wmi_msi_softc *sc = device_private(self);
125 1.5.2.2 rmind device_t parent = sc->sc_parent;
126 1.5.2.2 rmind
127 1.5.2.2 rmind (void)acpi_wmi_event_register(parent, wmi_msi_notify_handler);
128 1.5.2.2 rmind
129 1.5.2.2 rmind return true;
130 1.5.2.2 rmind }
131 1.5.2.2 rmind
132 1.5.2.2 rmind static void
133 1.5.2.2 rmind wmi_msi_notify_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux)
134 1.5.2.2 rmind {
135 1.5.2.2 rmind struct wmi_msi_softc *sc;
136 1.5.2.2 rmind device_t self = aux;
137 1.5.2.2 rmind ACPI_OBJECT *obj;
138 1.5.2.2 rmind ACPI_BUFFER buf;
139 1.5.2.2 rmind ACPI_STATUS rv;
140 1.5.2.2 rmind uint32_t val;
141 1.5.2.2 rmind
142 1.5.2.2 rmind buf.Pointer = NULL;
143 1.5.2.2 rmind
144 1.5.2.2 rmind sc = device_private(self);
145 1.5.2.2 rmind rv = acpi_wmi_event_get(sc->sc_parent, evt, &buf);
146 1.5.2.2 rmind
147 1.5.2.2 rmind if (ACPI_FAILURE(rv))
148 1.5.2.2 rmind goto out;
149 1.5.2.2 rmind
150 1.5.2.2 rmind obj = buf.Pointer;
151 1.5.2.2 rmind
152 1.5.2.2 rmind if (obj->Type != ACPI_TYPE_INTEGER) {
153 1.5.2.2 rmind rv = AE_TYPE;
154 1.5.2.2 rmind goto out;
155 1.5.2.2 rmind }
156 1.5.2.2 rmind
157 1.5.2.2 rmind if (obj->Integer.Value > UINT32_MAX) {
158 1.5.2.2 rmind rv = AE_AML_NUMERIC_OVERFLOW;
159 1.5.2.2 rmind goto out;
160 1.5.2.2 rmind }
161 1.5.2.2 rmind
162 1.5.2.2 rmind val = obj->Integer.Value;
163 1.5.2.2 rmind
164 1.5.2.2 rmind switch (val) {
165 1.5.2.2 rmind
166 1.5.2.2 rmind case WMI_MSI_HOTKEY_BRIGHTNESS_DOWN:
167 1.5.2.2 rmind pmf_event_inject(NULL, PMFE_DISPLAY_BRIGHTNESS_DOWN);
168 1.5.2.2 rmind break;
169 1.5.2.2 rmind
170 1.5.2.2 rmind case WMI_MSI_HOTKEY_BRIGHTNESS_UP:
171 1.5.2.2 rmind pmf_event_inject(NULL, PMFE_DISPLAY_BRIGHTNESS_UP);
172 1.5.2.2 rmind break;
173 1.5.2.2 rmind
174 1.5.2.2 rmind case WMI_MSI_HOTKEY_VOLUME_DOWN:
175 1.5.2.2 rmind pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
176 1.5.2.2 rmind break;
177 1.5.2.2 rmind
178 1.5.2.2 rmind case WMI_MSI_HOTKEY_VOLUME_UP:
179 1.5.2.2 rmind pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
180 1.5.2.2 rmind break;
181 1.5.2.2 rmind
182 1.5.2.2 rmind default:
183 1.5.2.2 rmind aprint_normal_dev(sc->sc_dev,
184 1.5.2.2 rmind "unknown key 0x%02X for event 0x%02X\n", val, evt);
185 1.5.2.2 rmind break;
186 1.5.2.2 rmind }
187 1.5.2.2 rmind
188 1.5.2.2 rmind out:
189 1.5.2.2 rmind if (buf.Pointer != NULL)
190 1.5.2.2 rmind ACPI_FREE(buf.Pointer);
191 1.5.2.2 rmind
192 1.5.2.2 rmind if (ACPI_FAILURE(rv))
193 1.5.2.2 rmind aprint_error_dev(sc->sc_dev, "failed to get data for "
194 1.5.2.2 rmind "event 0x%02X: %s\n", evt, AcpiFormatException(rv));
195 1.5.2.2 rmind }
196 1.5.2.2 rmind
197 1.5.2.2 rmind MODULE(MODULE_CLASS_DRIVER, wmimsi, "acpiwmi");
198 1.5.2.2 rmind
199 1.5.2.2 rmind #ifdef _MODULE
200 1.5.2.2 rmind #include "ioconf.c"
201 1.5.2.2 rmind #endif
202 1.5.2.2 rmind
203 1.5.2.2 rmind static int
204 1.5.2.2 rmind wmimsi_modcmd(modcmd_t cmd, void *aux)
205 1.5.2.2 rmind {
206 1.5.2.2 rmind int rv = 0;
207 1.5.2.2 rmind
208 1.5.2.2 rmind switch (cmd) {
209 1.5.2.2 rmind
210 1.5.2.2 rmind case MODULE_CMD_INIT:
211 1.5.2.2 rmind
212 1.5.2.2 rmind #ifdef _MODULE
213 1.5.2.2 rmind rv = config_init_component(cfdriver_ioconf_wmimsi,
214 1.5.2.2 rmind cfattach_ioconf_wmimsi, cfdata_ioconf_wmimsi);
215 1.5.2.2 rmind #endif
216 1.5.2.2 rmind break;
217 1.5.2.2 rmind
218 1.5.2.2 rmind case MODULE_CMD_FINI:
219 1.5.2.2 rmind
220 1.5.2.2 rmind #ifdef _MODULE
221 1.5.2.2 rmind rv = config_fini_component(cfdriver_ioconf_wmimsi,
222 1.5.2.2 rmind cfattach_ioconf_wmimsi, cfdata_ioconf_wmimsi);
223 1.5.2.2 rmind #endif
224 1.5.2.2 rmind break;
225 1.5.2.2 rmind
226 1.5.2.2 rmind default:
227 1.5.2.2 rmind rv = ENOTTY;
228 1.5.2.2 rmind }
229 1.5.2.2 rmind
230 1.5.2.2 rmind return rv;
231 1.5.2.2 rmind }
232