sony_acpi.c revision 1.2.6.2 1 1.2.6.2 bouyer /* $NetBSD: sony_acpi.c,v 1.2.6.2 2008/01/02 21:53:51 bouyer Exp $ */
2 1.2.6.2 bouyer
3 1.2.6.2 bouyer /*-
4 1.2.6.2 bouyer * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 1.2.6.2 bouyer * All rights reserved.
6 1.2.6.2 bouyer *
7 1.2.6.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.2.6.2 bouyer * by Christos Zoulas.
9 1.2.6.2 bouyer *
10 1.2.6.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.2.6.2 bouyer * modification, are permitted provided that the following conditions
12 1.2.6.2 bouyer * are met:
13 1.2.6.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.2.6.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.2.6.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.2.6.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.2.6.2 bouyer * must display the following acknowledgement:
20 1.2.6.2 bouyer * This product includes software developed by the NetBSD
21 1.2.6.2 bouyer * Foundation, Inc. and its contributors.
22 1.2.6.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.6.2 bouyer * contributors may be used to endorse or promote products derived
24 1.2.6.2 bouyer * from this software without specific prior written permission.
25 1.2.6.2 bouyer *
26 1.2.6.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.6.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.6.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.6.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.6.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.6.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.6.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.6.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.6.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.6.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.6.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.2.6.2 bouyer */
38 1.2.6.2 bouyer #include <sys/cdefs.h>
39 1.2.6.2 bouyer __KERNEL_RCSID(0, "$NetBSD: sony_acpi.c,v 1.2.6.2 2008/01/02 21:53:51 bouyer Exp $");
40 1.2.6.2 bouyer
41 1.2.6.2 bouyer #include <sys/param.h>
42 1.2.6.2 bouyer #include <sys/systm.h>
43 1.2.6.2 bouyer #include <sys/device.h>
44 1.2.6.2 bouyer #include <sys/proc.h>
45 1.2.6.2 bouyer #include <sys/kernel.h>
46 1.2.6.2 bouyer #include <sys/callout.h>
47 1.2.6.2 bouyer #include <sys/sysctl.h>
48 1.2.6.2 bouyer
49 1.2.6.2 bouyer #include <machine/bus.h>
50 1.2.6.2 bouyer
51 1.2.6.2 bouyer #include <dev/acpi/acpica.h>
52 1.2.6.2 bouyer #include <dev/acpi/acpivar.h>
53 1.2.6.2 bouyer
54 1.2.6.2 bouyer #define SONY_NOTIFY_FnKeyEvent 0x92
55 1.2.6.2 bouyer #define SONY_NOTIFY_BrightnessDownPressed 0x85
56 1.2.6.2 bouyer #define SONY_NOTIFY_BrightnessDownReleased 0x05
57 1.2.6.2 bouyer #define SONY_NOTIFY_BrightnessUpPressed 0x86
58 1.2.6.2 bouyer #define SONY_NOTIFY_BrightnessUpReleased 0x06
59 1.2.6.2 bouyer #define SONY_NOTIFY_DisplaySwitchPressed 0x87
60 1.2.6.2 bouyer #define SONY_NOTIFY_DisplaySwitchReleased 0x07
61 1.2.6.2 bouyer #define SONY_NOTIFY_ZoomPressed 0x8a
62 1.2.6.2 bouyer #define SONY_NOTIFY_ZoomReleased 0x0a
63 1.2.6.2 bouyer #define SONY_NOTIFY_SuspendPressed 0x8c
64 1.2.6.2 bouyer #define SONY_NOTIFY_SuspendReleased 0x0c
65 1.2.6.2 bouyer
66 1.2.6.2 bouyer struct sony_acpi_softc {
67 1.2.6.2 bouyer struct device sc_dev;
68 1.2.6.2 bouyer struct sysctllog *sc_log;
69 1.2.6.2 bouyer struct acpi_devnode *sc_node;
70 1.2.6.2 bouyer
71 1.2.6.2 bouyer #define SONY_PSW_SLEEP 0
72 1.2.6.2 bouyer #define SONY_PSW_DISPLAY_CYCLE 1
73 1.2.6.2 bouyer #define SONY_PSW_ZOOM 2
74 1.2.6.2 bouyer #define SONY_PSW_LAST 3
75 1.2.6.2 bouyer struct sysmon_pswitch sc_smpsw[SONY_PSW_LAST];
76 1.2.6.2 bouyer int sc_smpsw_valid;
77 1.2.6.2 bouyer
78 1.2.6.2 bouyer #define SONY_ACPI_QUIRK_FNINIT 0x01
79 1.2.6.2 bouyer int sc_quirks;
80 1.2.6.2 bouyer bool sc_has_pic;
81 1.2.6.2 bouyer
82 1.2.6.2 bouyer struct sony_acpi_pmstate {
83 1.2.6.2 bouyer ACPI_INTEGER brt;
84 1.2.6.2 bouyer } sc_pmstate;
85 1.2.6.2 bouyer };
86 1.2.6.2 bouyer
87 1.2.6.2 bouyer static const char * const sony_acpi_ids[] = {
88 1.2.6.2 bouyer "SNY5001",
89 1.2.6.2 bouyer NULL
90 1.2.6.2 bouyer };
91 1.2.6.2 bouyer
92 1.2.6.2 bouyer static int sony_acpi_match(struct device *, struct cfdata *, void *);
93 1.2.6.2 bouyer static void sony_acpi_attach(struct device *, struct device *, void *);
94 1.2.6.2 bouyer static ACPI_STATUS sony_acpi_eval_set_integer(ACPI_HANDLE, const char *,
95 1.2.6.2 bouyer ACPI_INTEGER, ACPI_INTEGER *);
96 1.2.6.2 bouyer static void sony_acpi_quirk_setup(struct sony_acpi_softc *);
97 1.2.6.2 bouyer static void sony_acpi_notify_handler(ACPI_HANDLE, UINT32, void *);
98 1.2.6.2 bouyer static bool sony_acpi_suspend(device_t);
99 1.2.6.2 bouyer static bool sony_acpi_resume(device_t);
100 1.2.6.2 bouyer static void sony_acpi_brightness_down(device_t);
101 1.2.6.2 bouyer static void sony_acpi_brightness_up(device_t);
102 1.2.6.2 bouyer static ACPI_STATUS sony_acpi_find_pic(ACPI_HANDLE, UINT32, void *, void **);
103 1.2.6.2 bouyer
104 1.2.6.2 bouyer CFATTACH_DECL(sony_acpi, sizeof(struct sony_acpi_softc),
105 1.2.6.2 bouyer sony_acpi_match, sony_acpi_attach, NULL, NULL);
106 1.2.6.2 bouyer
107 1.2.6.2 bouyer static int
108 1.2.6.2 bouyer sony_acpi_match(struct device *parent, struct cfdata *match,
109 1.2.6.2 bouyer void *aux)
110 1.2.6.2 bouyer {
111 1.2.6.2 bouyer struct acpi_attach_args *aa = aux;
112 1.2.6.2 bouyer
113 1.2.6.2 bouyer if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
114 1.2.6.2 bouyer return 0;
115 1.2.6.2 bouyer
116 1.2.6.2 bouyer return acpi_match_hid(aa->aa_node->ad_devinfo, sony_acpi_ids);
117 1.2.6.2 bouyer }
118 1.2.6.2 bouyer
119 1.2.6.2 bouyer static int
120 1.2.6.2 bouyer sony_sysctl_helper(SYSCTLFN_ARGS)
121 1.2.6.2 bouyer {
122 1.2.6.2 bouyer struct sysctlnode node;
123 1.2.6.2 bouyer ACPI_INTEGER acpi_val;
124 1.2.6.2 bouyer ACPI_STATUS rv;
125 1.2.6.2 bouyer int val, old_val, error;
126 1.2.6.2 bouyer char buf[SYSCTL_NAMELEN + 1], *ptr;
127 1.2.6.2 bouyer struct sony_acpi_softc *sc = rnode->sysctl_data;
128 1.2.6.2 bouyer
129 1.2.6.2 bouyer (void)snprintf(buf, sizeof(buf), "G%s", rnode->sysctl_name);
130 1.2.6.2 bouyer for (ptr = buf; *ptr; ptr++)
131 1.2.6.2 bouyer *ptr = toupper(*ptr);
132 1.2.6.2 bouyer
133 1.2.6.2 bouyer rv = acpi_eval_integer(sc->sc_node->ad_handle, buf, &acpi_val);
134 1.2.6.2 bouyer if (ACPI_FAILURE(rv)) {
135 1.2.6.2 bouyer #ifdef DIAGNOSTIC
136 1.2.6.2 bouyer printf("%s: couldn't get `%s'\n", device_xname(&sc->sc_dev), buf);
137 1.2.6.2 bouyer #endif
138 1.2.6.2 bouyer return EIO;
139 1.2.6.2 bouyer }
140 1.2.6.2 bouyer val = old_val = acpi_val;
141 1.2.6.2 bouyer
142 1.2.6.2 bouyer node = *rnode;
143 1.2.6.2 bouyer node.sysctl_data = &val;
144 1.2.6.2 bouyer
145 1.2.6.2 bouyer error = sysctl_lookup(SYSCTLFN_CALL(&node));
146 1.2.6.2 bouyer if (error || newp == NULL)
147 1.2.6.2 bouyer return error;
148 1.2.6.2 bouyer
149 1.2.6.2 bouyer (void)snprintf(buf, sizeof(buf), "S%s", rnode->sysctl_name);
150 1.2.6.2 bouyer acpi_val = val;
151 1.2.6.2 bouyer rv = sony_acpi_eval_set_integer(sc->sc_node->ad_handle, buf,
152 1.2.6.2 bouyer acpi_val, NULL);
153 1.2.6.2 bouyer if (ACPI_FAILURE(rv)) {
154 1.2.6.2 bouyer #ifdef DIAGNOSTIC
155 1.2.6.2 bouyer printf("%s: couldn't set `%s' to %d\n",
156 1.2.6.2 bouyer device_xname(&sc->sc_dev), buf, val);
157 1.2.6.2 bouyer #endif
158 1.2.6.2 bouyer return EIO;
159 1.2.6.2 bouyer }
160 1.2.6.2 bouyer return 0;
161 1.2.6.2 bouyer }
162 1.2.6.2 bouyer
163 1.2.6.2 bouyer static ACPI_STATUS
164 1.2.6.2 bouyer sony_walk_cb(ACPI_HANDLE hnd, UINT32 v, void *context,
165 1.2.6.2 bouyer void **status)
166 1.2.6.2 bouyer {
167 1.2.6.2 bouyer struct sony_acpi_softc *sc = (void*)context;
168 1.2.6.2 bouyer const struct sysctlnode *node, *snode;
169 1.2.6.2 bouyer const char *name = acpi_name(hnd);
170 1.2.6.2 bouyer ACPI_INTEGER acpi_val;
171 1.2.6.2 bouyer char buf[SYSCTL_NAMELEN + 1], *ptr;
172 1.2.6.2 bouyer int rv;
173 1.2.6.2 bouyer
174 1.2.6.2 bouyer if ((name = strrchr(name, '.')) == NULL)
175 1.2.6.2 bouyer return AE_OK;
176 1.2.6.2 bouyer
177 1.2.6.2 bouyer name++;
178 1.2.6.2 bouyer if ((*name != 'G') && (*name != 'S'))
179 1.2.6.2 bouyer return AE_OK;
180 1.2.6.2 bouyer
181 1.2.6.2 bouyer (void)strlcpy(buf, name, sizeof(buf));
182 1.2.6.2 bouyer *buf = 'G';
183 1.2.6.2 bouyer
184 1.2.6.2 bouyer /*
185 1.2.6.2 bouyer * We assume that if the 'get' of the name as an integer is
186 1.2.6.2 bouyer * successful it is ok.
187 1.2.6.2 bouyer */
188 1.2.6.2 bouyer if (acpi_eval_integer(sc->sc_node->ad_handle, buf, &acpi_val))
189 1.2.6.2 bouyer return AE_OK;
190 1.2.6.2 bouyer
191 1.2.6.2 bouyer for (ptr = buf; *ptr; ptr++)
192 1.2.6.2 bouyer *ptr = tolower(*ptr);
193 1.2.6.2 bouyer
194 1.2.6.2 bouyer if ((rv = sysctl_createv(&sc->sc_log, 0, NULL, &node, CTLFLAG_PERMANENT,
195 1.2.6.2 bouyer CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
196 1.2.6.2 bouyer goto out;
197 1.2.6.2 bouyer
198 1.2.6.2 bouyer if ((rv = sysctl_createv(&sc->sc_log, 0, &node, &snode, 0,
199 1.2.6.2 bouyer CTLTYPE_NODE, device_xname(&sc->sc_dev),
200 1.2.6.2 bouyer SYSCTL_DESCR("sony controls"),
201 1.2.6.2 bouyer NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
202 1.2.6.2 bouyer goto out;
203 1.2.6.2 bouyer
204 1.2.6.2 bouyer if ((rv = sysctl_createv(&sc->sc_log, 0, &snode, &node,
205 1.2.6.2 bouyer CTLFLAG_READWRITE, CTLTYPE_INT, buf + 1, NULL,
206 1.2.6.2 bouyer sony_sysctl_helper, 0, sc, 0, CTL_CREATE, CTL_EOL)) != 0)
207 1.2.6.2 bouyer goto out;
208 1.2.6.2 bouyer
209 1.2.6.2 bouyer out:
210 1.2.6.2 bouyer #ifdef DIAGNOSTIC
211 1.2.6.2 bouyer if (rv)
212 1.2.6.2 bouyer printf("%s: sysctl_createv failed (rv = %d)\n",
213 1.2.6.2 bouyer device_xname(&sc->sc_dev), rv);
214 1.2.6.2 bouyer #endif
215 1.2.6.2 bouyer return AE_OK;
216 1.2.6.2 bouyer }
217 1.2.6.2 bouyer
218 1.2.6.2 bouyer ACPI_STATUS
219 1.2.6.2 bouyer sony_acpi_eval_set_integer(ACPI_HANDLE handle, const char *path,
220 1.2.6.2 bouyer ACPI_INTEGER val, ACPI_INTEGER *valp)
221 1.2.6.2 bouyer {
222 1.2.6.2 bouyer ACPI_STATUS rv;
223 1.2.6.2 bouyer ACPI_BUFFER buf;
224 1.2.6.2 bouyer ACPI_OBJECT param, ret_val;
225 1.2.6.2 bouyer ACPI_OBJECT_LIST params;
226 1.2.6.2 bouyer
227 1.2.6.2 bouyer if (handle == NULL)
228 1.2.6.2 bouyer handle = ACPI_ROOT_OBJECT;
229 1.2.6.2 bouyer
230 1.2.6.2 bouyer params.Count = 1;
231 1.2.6.2 bouyer params.Pointer = ¶m;
232 1.2.6.2 bouyer
233 1.2.6.2 bouyer param.Type = ACPI_TYPE_INTEGER;
234 1.2.6.2 bouyer param.Integer.Value = val;
235 1.2.6.2 bouyer
236 1.2.6.2 bouyer buf.Pointer = &ret_val;
237 1.2.6.2 bouyer buf.Length = sizeof(ret_val);
238 1.2.6.2 bouyer
239 1.2.6.2 bouyer rv = AcpiEvaluateObjectTyped(handle, path, ¶ms, &buf,
240 1.2.6.2 bouyer ACPI_TYPE_INTEGER);
241 1.2.6.2 bouyer
242 1.2.6.2 bouyer if (ACPI_SUCCESS(rv) && valp)
243 1.2.6.2 bouyer *valp = ret_val.Integer.Value;
244 1.2.6.2 bouyer
245 1.2.6.2 bouyer return rv;
246 1.2.6.2 bouyer }
247 1.2.6.2 bouyer
248 1.2.6.2 bouyer static void
249 1.2.6.2 bouyer sony_acpi_attach(struct device *parent, struct device *self, void *aux)
250 1.2.6.2 bouyer {
251 1.2.6.2 bouyer struct sony_acpi_softc *sc = (void *)self;
252 1.2.6.2 bouyer struct acpi_attach_args *aa = aux;
253 1.2.6.2 bouyer ACPI_STATUS rv;
254 1.2.6.2 bouyer int i;
255 1.2.6.2 bouyer
256 1.2.6.2 bouyer aprint_naive(": Sony Miscellaneous Controller\n");
257 1.2.6.2 bouyer aprint_normal(": Sony Miscellaneous Controller\n");
258 1.2.6.2 bouyer
259 1.2.6.2 bouyer sc->sc_node = aa->aa_node;
260 1.2.6.2 bouyer
261 1.2.6.2 bouyer rv = AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 100,
262 1.2.6.2 bouyer sony_acpi_find_pic, sc, NULL);
263 1.2.6.2 bouyer if (ACPI_FAILURE(rv))
264 1.2.6.2 bouyer aprint_error_dev(self, "couldn't walk namespace: %s\n",
265 1.2.6.2 bouyer AcpiFormatException(rv));
266 1.2.6.2 bouyer
267 1.2.6.2 bouyer /*
268 1.2.6.2 bouyer * If we don't find an SNY6001 device, assume that we need the
269 1.2.6.2 bouyer * Fn key initialization sequence.
270 1.2.6.2 bouyer */
271 1.2.6.2 bouyer if (sc->sc_has_pic == false)
272 1.2.6.2 bouyer sc->sc_quirks |= SONY_ACPI_QUIRK_FNINIT;
273 1.2.6.2 bouyer
274 1.2.6.2 bouyer sony_acpi_quirk_setup(sc);
275 1.2.6.2 bouyer
276 1.2.6.2 bouyer /* Configure suspend button and hotkeys */
277 1.2.6.2 bouyer sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_name = sc->sc_dev.dv_xname;
278 1.2.6.2 bouyer sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_type = PSWITCH_TYPE_SLEEP;
279 1.2.6.2 bouyer sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_name =
280 1.2.6.2 bouyer PSWITCH_HK_DISPLAY_CYCLE;
281 1.2.6.2 bouyer sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_type = PSWITCH_TYPE_HOTKEY;
282 1.2.6.2 bouyer sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_name = PSWITCH_HK_ZOOM_BUTTON;
283 1.2.6.2 bouyer sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_type = PSWITCH_TYPE_HOTKEY;
284 1.2.6.2 bouyer sc->sc_smpsw_valid = 1;
285 1.2.6.2 bouyer
286 1.2.6.2 bouyer for (i = 0; i < SONY_PSW_LAST; i++)
287 1.2.6.2 bouyer if (sysmon_pswitch_register(&sc->sc_smpsw[i]) != 0) {
288 1.2.6.2 bouyer aprint_error("%s: couldn't register %s with sysmon\n",
289 1.2.6.2 bouyer device_xname(self), sc->sc_smpsw[i].smpsw_name);
290 1.2.6.2 bouyer sc->sc_smpsw_valid = 0;
291 1.2.6.2 bouyer }
292 1.2.6.2 bouyer
293 1.2.6.2 bouyer /* Install notify handler */
294 1.2.6.2 bouyer rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
295 1.2.6.2 bouyer ACPI_DEVICE_NOTIFY, sony_acpi_notify_handler, self);
296 1.2.6.2 bouyer if (ACPI_FAILURE(rv))
297 1.2.6.2 bouyer aprint_error("%s: couldn't install notify handler (%d)\n",
298 1.2.6.2 bouyer device_xname(self), rv);
299 1.2.6.2 bouyer
300 1.2.6.2 bouyer /* Install sysctl handler */
301 1.2.6.2 bouyer rv = AcpiWalkNamespace(ACPI_TYPE_METHOD,
302 1.2.6.2 bouyer sc->sc_node->ad_handle, 1, sony_walk_cb, sc, NULL);
303 1.2.6.2 bouyer #ifdef DIAGNOSTIC
304 1.2.6.2 bouyer if (ACPI_FAILURE(rv))
305 1.2.6.2 bouyer aprint_error("%s: Cannot walk ACPI namespace (%d)\n",
306 1.2.6.2 bouyer device_xname(self), rv);
307 1.2.6.2 bouyer #endif
308 1.2.6.2 bouyer
309 1.2.6.2 bouyer if (!pmf_device_register(self, sony_acpi_suspend, sony_acpi_resume))
310 1.2.6.2 bouyer aprint_error_dev(self, "couldn't establish power handler\n");
311 1.2.6.2 bouyer
312 1.2.6.2 bouyer if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_UP,
313 1.2.6.2 bouyer sony_acpi_brightness_up, true))
314 1.2.6.2 bouyer aprint_error_dev(self, "couldn't register BRIGHTNESS UP handler\n");
315 1.2.6.2 bouyer
316 1.2.6.2 bouyer if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_DOWN,
317 1.2.6.2 bouyer sony_acpi_brightness_down, true))
318 1.2.6.2 bouyer aprint_error_dev(self, "couldn't register BRIGHTNESS DOWN handler\n");
319 1.2.6.2 bouyer }
320 1.2.6.2 bouyer
321 1.2.6.2 bouyer static void
322 1.2.6.2 bouyer sony_acpi_quirk_setup(struct sony_acpi_softc *sc)
323 1.2.6.2 bouyer {
324 1.2.6.2 bouyer ACPI_HANDLE hdl = sc->sc_node->ad_handle;
325 1.2.6.2 bouyer
326 1.2.6.2 bouyer if (sc->sc_quirks & SONY_ACPI_QUIRK_FNINIT) {
327 1.2.6.2 bouyer /* Initialize extra Fn keys */
328 1.2.6.2 bouyer sony_acpi_eval_set_integer(hdl, "SN02", 0x04, NULL);
329 1.2.6.2 bouyer sony_acpi_eval_set_integer(hdl, "SN07", 0x02, NULL);
330 1.2.6.2 bouyer sony_acpi_eval_set_integer(hdl, "SN02", 0x10, NULL);
331 1.2.6.2 bouyer sony_acpi_eval_set_integer(hdl, "SN07", 0x00, NULL);
332 1.2.6.2 bouyer sony_acpi_eval_set_integer(hdl, "SN03", 0x02, NULL);
333 1.2.6.2 bouyer sony_acpi_eval_set_integer(hdl, "SN07", 0x101, NULL);
334 1.2.6.2 bouyer }
335 1.2.6.2 bouyer }
336 1.2.6.2 bouyer
337 1.2.6.2 bouyer static void
338 1.2.6.2 bouyer sony_acpi_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque)
339 1.2.6.2 bouyer {
340 1.2.6.2 bouyer device_t dv = opaque;
341 1.2.6.2 bouyer struct sony_acpi_softc *sc = device_private(dv);
342 1.2.6.2 bouyer ACPI_STATUS rv;
343 1.2.6.2 bouyer ACPI_INTEGER arg;
344 1.2.6.2 bouyer int s;
345 1.2.6.2 bouyer
346 1.2.6.2 bouyer if (notify == SONY_NOTIFY_FnKeyEvent) {
347 1.2.6.2 bouyer rv = sony_acpi_eval_set_integer(hdl, "SN07", 0x202, &arg);
348 1.2.6.2 bouyer if (ACPI_FAILURE(rv))
349 1.2.6.2 bouyer return;
350 1.2.6.2 bouyer
351 1.2.6.2 bouyer notify = arg & 0xff;
352 1.2.6.2 bouyer }
353 1.2.6.2 bouyer
354 1.2.6.2 bouyer s = spltty();
355 1.2.6.2 bouyer switch (notify) {
356 1.2.6.2 bouyer case SONY_NOTIFY_BrightnessDownPressed:
357 1.2.6.2 bouyer sony_acpi_brightness_down(dv);
358 1.2.6.2 bouyer break;
359 1.2.6.2 bouyer case SONY_NOTIFY_BrightnessUpPressed:
360 1.2.6.2 bouyer sony_acpi_brightness_up(dv);
361 1.2.6.2 bouyer break;
362 1.2.6.2 bouyer case SONY_NOTIFY_BrightnessDownReleased:
363 1.2.6.2 bouyer case SONY_NOTIFY_BrightnessUpReleased:
364 1.2.6.2 bouyer break;
365 1.2.6.2 bouyer case SONY_NOTIFY_SuspendPressed:
366 1.2.6.2 bouyer if (!sc->sc_smpsw_valid)
367 1.2.6.2 bouyer break;
368 1.2.6.2 bouyer sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_SLEEP],
369 1.2.6.2 bouyer PSWITCH_EVENT_PRESSED);
370 1.2.6.2 bouyer break;
371 1.2.6.2 bouyer case SONY_NOTIFY_SuspendReleased:
372 1.2.6.2 bouyer break;
373 1.2.6.2 bouyer case SONY_NOTIFY_DisplaySwitchPressed:
374 1.2.6.2 bouyer if (!sc->sc_smpsw_valid)
375 1.2.6.2 bouyer break;
376 1.2.6.2 bouyer sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE],
377 1.2.6.2 bouyer PSWITCH_EVENT_PRESSED);
378 1.2.6.2 bouyer break;
379 1.2.6.2 bouyer case SONY_NOTIFY_DisplaySwitchReleased:
380 1.2.6.2 bouyer break;
381 1.2.6.2 bouyer case SONY_NOTIFY_ZoomPressed:
382 1.2.6.2 bouyer if (!sc->sc_smpsw_valid)
383 1.2.6.2 bouyer break;
384 1.2.6.2 bouyer sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_ZOOM],
385 1.2.6.2 bouyer PSWITCH_EVENT_PRESSED);
386 1.2.6.2 bouyer break;
387 1.2.6.2 bouyer case SONY_NOTIFY_ZoomReleased:
388 1.2.6.2 bouyer break;
389 1.2.6.2 bouyer default:
390 1.2.6.2 bouyer printf("%s: unknown notify event 0x%x\n",
391 1.2.6.2 bouyer device_xname(&sc->sc_dev), notify);
392 1.2.6.2 bouyer break;
393 1.2.6.2 bouyer }
394 1.2.6.2 bouyer splx(s);
395 1.2.6.2 bouyer }
396 1.2.6.2 bouyer
397 1.2.6.2 bouyer static bool
398 1.2.6.2 bouyer sony_acpi_suspend(device_t dv)
399 1.2.6.2 bouyer {
400 1.2.6.2 bouyer struct sony_acpi_softc *sc = device_private(dv);
401 1.2.6.2 bouyer
402 1.2.6.2 bouyer acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &sc->sc_pmstate.brt);
403 1.2.6.2 bouyer
404 1.2.6.2 bouyer return true;
405 1.2.6.2 bouyer }
406 1.2.6.2 bouyer
407 1.2.6.2 bouyer static bool
408 1.2.6.2 bouyer sony_acpi_resume(device_t dv)
409 1.2.6.2 bouyer {
410 1.2.6.2 bouyer struct sony_acpi_softc *sc = device_private(dv);
411 1.2.6.2 bouyer
412 1.2.6.2 bouyer sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT",
413 1.2.6.2 bouyer sc->sc_pmstate.brt, NULL);
414 1.2.6.2 bouyer sony_acpi_quirk_setup(sc);
415 1.2.6.2 bouyer
416 1.2.6.2 bouyer return true;
417 1.2.6.2 bouyer }
418 1.2.6.2 bouyer
419 1.2.6.2 bouyer static void
420 1.2.6.2 bouyer sony_acpi_brightness_up(device_t dv)
421 1.2.6.2 bouyer {
422 1.2.6.2 bouyer struct sony_acpi_softc *sc = device_private(dv);
423 1.2.6.2 bouyer ACPI_INTEGER arg;
424 1.2.6.2 bouyer ACPI_STATUS rv;
425 1.2.6.2 bouyer
426 1.2.6.2 bouyer rv = acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &arg);
427 1.2.6.2 bouyer if (ACPI_FAILURE(rv) || arg > 8)
428 1.2.6.2 bouyer return;
429 1.2.6.2 bouyer arg++;
430 1.2.6.2 bouyer sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT", arg, NULL);
431 1.2.6.2 bouyer }
432 1.2.6.2 bouyer
433 1.2.6.2 bouyer static void
434 1.2.6.2 bouyer sony_acpi_brightness_down(device_t dv)
435 1.2.6.2 bouyer {
436 1.2.6.2 bouyer struct sony_acpi_softc *sc = device_private(dv);
437 1.2.6.2 bouyer ACPI_INTEGER arg;
438 1.2.6.2 bouyer ACPI_STATUS rv;
439 1.2.6.2 bouyer
440 1.2.6.2 bouyer rv = acpi_eval_integer(sc->sc_node->ad_handle, "GBRT", &arg);
441 1.2.6.2 bouyer if (ACPI_FAILURE(rv) || arg == 0)
442 1.2.6.2 bouyer return;
443 1.2.6.2 bouyer arg--;
444 1.2.6.2 bouyer sony_acpi_eval_set_integer(sc->sc_node->ad_handle, "SBRT", arg, NULL);
445 1.2.6.2 bouyer }
446 1.2.6.2 bouyer
447 1.2.6.2 bouyer static ACPI_STATUS
448 1.2.6.2 bouyer sony_acpi_find_pic(ACPI_HANDLE hdl, UINT32 level, void *opaque, void **status)
449 1.2.6.2 bouyer {
450 1.2.6.2 bouyer struct sony_acpi_softc *sc = opaque;
451 1.2.6.2 bouyer ACPI_BUFFER buf;
452 1.2.6.2 bouyer ACPI_STATUS rv;
453 1.2.6.2 bouyer ACPI_DEVICE_INFO *devinfo;
454 1.2.6.2 bouyer
455 1.2.6.2 bouyer buf.Pointer = NULL;
456 1.2.6.2 bouyer buf.Length = ACPI_ALLOCATE_BUFFER;
457 1.2.6.2 bouyer rv = AcpiGetObjectInfo(hdl, &buf);
458 1.2.6.2 bouyer if (ACPI_FAILURE(rv) || buf.Pointer == NULL)
459 1.2.6.2 bouyer return AE_OK; /* we don't want to stop searching */
460 1.2.6.2 bouyer
461 1.2.6.2 bouyer devinfo = buf.Pointer;
462 1.2.6.2 bouyer if (strncmp(devinfo->HardwareId.Value, "SNY6001", 7) == 0)
463 1.2.6.2 bouyer sc->sc_has_pic = true;
464 1.2.6.2 bouyer
465 1.2.6.2 bouyer AcpiOsFree(buf.Pointer);
466 1.2.6.2 bouyer
467 1.2.6.2 bouyer return AE_OK;
468 1.2.6.2 bouyer }
469