xref: /freebsd/sys/dev/acpi_support/acpi_asus.c (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1 /*-
2  * Copyright (c) 2004, 2005 Philip Paeps <philip@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 /*
31  * Driver for extra ACPI-controlled gadgets (hotkeys, leds, etc) found on
32  * recent Asus (and Medion) laptops.  Inspired by the acpi4asus project which
33  * implements these features in the Linux kernel.
34  *
35  *   <http://sourceforge.net/projects/acpi4asus/>
36  *
37  * Currently should support most features, but could use some more testing.
38  * Particularly the display-switching stuff is a bit hairy.  If you have an
39  * Asus laptop which doesn't appear to be supported, or strange things happen
40  * when using this driver, please report to <acpi@FreeBSD.org>.
41  */
42 
43 #include "opt_acpi.h"
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
47 #include <sys/bus.h>
48 #include <sys/sbuf.h>
49 
50 #include <contrib/dev/acpica/include/acpi.h>
51 #include <contrib/dev/acpica/include/accommon.h>
52 
53 #include <dev/acpica/acpivar.h>
54 #include <dev/led/led.h>
55 
56 /* Methods */
57 #define ACPI_ASUS_METHOD_BRN	1
58 #define ACPI_ASUS_METHOD_DISP	2
59 #define ACPI_ASUS_METHOD_LCD	3
60 #define ACPI_ASUS_METHOD_CAMERA	4
61 #define ACPI_ASUS_METHOD_CARDRD	5
62 #define ACPI_ASUS_METHOD_WLAN	6
63 
64 #define _COMPONENT	ACPI_OEM
65 ACPI_MODULE_NAME("ASUS")
66 
67 struct acpi_asus_model {
68 	char	*name;
69 
70 	char	*bled_set;
71 	char	*dled_set;
72 	char	*gled_set;
73 	char	*mled_set;
74 	char	*tled_set;
75 	char	*wled_set;
76 
77 	char	*brn_get;
78 	char	*brn_set;
79 	char	*brn_up;
80 	char	*brn_dn;
81 
82 	char	*lcd_get;
83 	char	*lcd_set;
84 
85 	char	*disp_get;
86 	char	*disp_set;
87 
88 	char	*cam_get;
89 	char	*cam_set;
90 
91 	char	*crd_get;
92 	char	*crd_set;
93 
94 	char	*wlan_get;
95 	char	*wlan_set;
96 
97 	void	(*n_func)(ACPI_HANDLE, UINT32, void *);
98 
99 	char	*lcdd;
100 	void	(*lcdd_n_func)(ACPI_HANDLE, UINT32, void *);
101 };
102 
103 struct acpi_asus_led {
104 	struct acpi_asus_softc *sc;
105 	struct cdev	*cdev;
106 	int		busy;
107 	int		state;
108 	enum {
109 		ACPI_ASUS_LED_BLED,
110 		ACPI_ASUS_LED_DLED,
111 		ACPI_ASUS_LED_GLED,
112 		ACPI_ASUS_LED_MLED,
113 		ACPI_ASUS_LED_TLED,
114 		ACPI_ASUS_LED_WLED,
115 	} type;
116 };
117 
118 struct acpi_asus_softc {
119 	device_t		dev;
120 	ACPI_HANDLE		handle;
121 	ACPI_HANDLE		lcdd_handle;
122 
123 	struct acpi_asus_model	*model;
124 	struct sysctl_ctx_list	sysctl_ctx;
125 	struct sysctl_oid	*sysctl_tree;
126 
127 	struct acpi_asus_led	s_bled;
128 	struct acpi_asus_led	s_dled;
129 	struct acpi_asus_led	s_gled;
130 	struct acpi_asus_led	s_mled;
131 	struct acpi_asus_led	s_tled;
132 	struct acpi_asus_led	s_wled;
133 
134 	int			s_brn;
135 	int			s_disp;
136 	int			s_lcd;
137 	int			s_cam;
138 	int			s_crd;
139 	int			s_wlan;
140 };
141 
142 static void	acpi_asus_lcdd_notify(ACPI_HANDLE h, UINT32 notify,
143     void *context);
144 
145 /*
146  * We can identify Asus laptops from the string they return
147  * as a result of calling the ATK0100 'INIT' method.
148  */
149 static struct acpi_asus_model acpi_asus_models[] = {
150 	{
151 		.name		= "xxN",
152 		.mled_set	= "MLED",
153 		.wled_set	= "WLED",
154 		.lcd_get	= "\\BKLT",
155 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
156 		.brn_get	= "GPLV",
157 		.brn_set	= "SPLV",
158 		.disp_get	= "\\ADVG",
159 		.disp_set	= "SDSP"
160 	},
161 	{
162 		.name		= "A1x",
163 		.mled_set	= "MLED",
164 		.lcd_get	= "\\BKLI",
165 		.lcd_set	= "\\_SB.PCI0.ISA.EC0._Q10",
166 		.brn_up		= "\\_SB.PCI0.ISA.EC0._Q0E",
167 		.brn_dn		= "\\_SB.PCI0.ISA.EC0._Q0F"
168 	},
169 	{
170 		.name		= "A2x",
171 		.mled_set	= "MLED",
172 		.wled_set	= "WLED",
173 		.lcd_get	= "\\BAOF",
174 		.lcd_set	= "\\Q10",
175 		.brn_get	= "GPLV",
176 		.brn_set	= "SPLV",
177 		.disp_get	= "\\INFB",
178 		.disp_set	= "SDSP"
179 	},
180 	{
181 		.name           = "A3E",
182 		.mled_set       = "MLED",
183 		.wled_set       = "WLED",
184 		.lcd_get        = "\\_SB.PCI0.SBRG.EC0.RPIN(0x67)",
185 		.lcd_set        = "\\_SB.PCI0.SBRG.EC0._Q10",
186 		.brn_get        = "GPLV",
187 		.brn_set        = "SPLV",
188 		.disp_get       = "\\_SB.PCI0.P0P2.VGA.GETD",
189 		.disp_set       = "SDSP"
190 	},
191 	{
192 		.name           = "A3F",
193 		.mled_set       = "MLED",
194 		.wled_set       = "WLED",
195 		.bled_set       = "BLED",
196 		.lcd_get        = "\\_SB.PCI0.SBRG.EC0.RPIN(0x11)",
197 		.lcd_set        = "\\_SB.PCI0.SBRG.EC0._Q10",
198 		.brn_get        = "GPLV",
199 		.brn_set        = "SPLV",
200 		.disp_get       = "\\SSTE",
201 		.disp_set       = "SDSP"
202 	},
203 	{
204 		.name           = "A3N",
205 		.mled_set       = "MLED",
206 		.bled_set       = "BLED",
207 		.wled_set       = "WLED",
208 		.lcd_get        = "\\BKLT",
209 		.lcd_set        = "\\_SB.PCI0.SBRG.EC0._Q10",
210 		.brn_get        = "GPLV",
211 		.brn_set        = "SPLV",
212 		.disp_get       = "\\_SB.PCI0.P0P3.VGA.GETD",
213 		.disp_set       = "SDSP"
214 	},
215 	{
216 		.name		= "A4D",
217 		.mled_set	= "MLED",
218 		.brn_up		= "\\_SB_.PCI0.SBRG.EC0._Q0E",
219 		.brn_dn		= "\\_SB_.PCI0.SBRG.EC0._Q0F",
220 		.brn_get	= "GPLV",
221 		.brn_set	= "SPLV",
222 #ifdef notyet
223 		.disp_get	= "\\_SB_.PCI0.SBRG.EC0._Q10",
224 		.disp_set	= "\\_SB_.PCI0.SBRG.EC0._Q11"
225 #endif
226 	},
227 	{
228 		.name		= "A6V",
229 		.bled_set	= "BLED",
230 		.mled_set	= "MLED",
231 		.wled_set	= "WLED",
232 		.lcd_get	= NULL,
233 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
234 		.brn_get	= "GPLV",
235 		.brn_set	= "SPLV",
236 		.disp_get	= "\\_SB.PCI0.P0P3.VGA.GETD",
237 		.disp_set	= "SDSP"
238 	},
239 	{
240 		.name		= "A8SR",
241 		.bled_set	= "BLED",
242 		.mled_set	= "MLED",
243 		.wled_set	= "WLED",
244 		.lcd_get	= NULL,
245 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
246 		.brn_get	= "GPLV",
247 		.brn_set	= "SPLV",
248 		.disp_get	= "\\_SB.PCI0.P0P1.VGA.GETD",
249 		.disp_set	= "SDSP",
250 		.lcdd		= "\\_SB.PCI0.P0P1.VGA.LCDD",
251 		.lcdd_n_func	= acpi_asus_lcdd_notify
252 	},
253 	{
254 		.name		= "D1x",
255 		.mled_set	= "MLED",
256 		.lcd_get	= "\\GP11",
257 		.lcd_set	= "\\Q0D",
258 		.brn_up		= "\\Q0C",
259 		.brn_dn		= "\\Q0B",
260 		.disp_get	= "\\INFB",
261 		.disp_set	= "SDSP"
262 	},
263 	{
264 		.name		= "G2K",
265 		.bled_set	= "BLED",
266 		.dled_set	= "DLED",
267 		.gled_set	= "GLED",
268 		.mled_set	= "MLED",
269 		.tled_set	= "TLED",
270 		.wled_set	= "WLED",
271 		.brn_get	= "GPLV",
272 		.brn_set	= "SPLV",
273 		.lcd_get	= "GBTL",
274 		.lcd_set	= "SBTL",
275 		.disp_get	= "\\_SB.PCI0.PCE2.VGA.GETD",
276 		.disp_set	= "SDSP",
277 	},
278 	{
279 		.name		= "L2D",
280 		.mled_set	= "MLED",
281 		.wled_set	= "WLED",
282 		.brn_up		= "\\Q0E",
283 		.brn_dn		= "\\Q0F",
284 		.lcd_get	= "\\SGP0",
285 		.lcd_set	= "\\Q10"
286 	},
287 	{
288 		.name		= "L3C",
289 		.mled_set	= "MLED",
290 		.wled_set	= "WLED",
291 		.brn_get	= "GPLV",
292 		.brn_set	= "SPLV",
293 		.lcd_get	= "\\GL32",
294 		.lcd_set	= "\\_SB.PCI0.PX40.ECD0._Q10"
295 	},
296 	{
297 		.name		= "L3D",
298 		.mled_set	= "MLED",
299 		.wled_set	= "WLED",
300 		.brn_get	= "GPLV",
301 		.brn_set	= "SPLV",
302 		.lcd_get	= "\\BKLG",
303 		.lcd_set	= "\\Q10"
304 	},
305 	{
306 		.name		= "L3H",
307 		.mled_set	= "MLED",
308 		.wled_set	= "WLED",
309 		.brn_get	= "GPLV",
310 		.brn_set	= "SPLV",
311 		.lcd_get	= "\\_SB.PCI0.PM.PBC",
312 		.lcd_set	= "EHK",
313 		.disp_get	= "\\_SB.INFB",
314 		.disp_set	= "SDSP"
315 	},
316 	{
317 		.name		= "L4R",
318 		.mled_set	= "MLED",
319 		.wled_set	= "WLED",
320 		.brn_get	= "GPLV",
321 		.brn_set	= "SPLV",
322 		.lcd_get	= "\\_SB.PCI0.SBSM.SEO4",
323 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
324 		.disp_get	= "\\_SB.PCI0.P0P1.VGA.GETD",
325 		.disp_set	= "SDSP"
326 	},
327 	{
328 		.name		= "L5x",
329 		.mled_set	= "MLED",
330 		.tled_set	= "TLED",
331 		.lcd_get	= "\\BAOF",
332 		.lcd_set	= "\\Q0D",
333 		.brn_get	= "GPLV",
334 		.brn_set	= "SPLV",
335 		.disp_get	= "\\INFB",
336 		.disp_set	= "SDSP"
337 	},
338 	{
339 		.name		= "L8L"
340 		/* Only has hotkeys, apparently */
341 	},
342 	{
343 		.name		= "M1A",
344 		.mled_set	= "MLED",
345 		.brn_up		= "\\_SB.PCI0.PX40.EC0.Q0E",
346 		.brn_dn		= "\\_SB.PCI0.PX40.EC0.Q0F",
347 		.lcd_get	= "\\PNOF",
348 		.lcd_set	= "\\_SB.PCI0.PX40.EC0.Q10"
349 	},
350 	{
351 		.name		= "M2E",
352 		.mled_set	= "MLED",
353 		.wled_set	= "WLED",
354 		.brn_get	= "GPLV",
355 		.brn_set	= "SPLV",
356 		.lcd_get	= "\\GP06",
357 		.lcd_set	= "\\Q10"
358 	},
359 	{
360 		.name		= "M6N",
361 		.mled_set	= "MLED",
362 		.wled_set	= "WLED",
363 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
364 		.lcd_get	= "\\_SB.BKLT",
365 		.brn_set	= "SPLV",
366 		.brn_get	= "GPLV",
367 		.disp_set	= "SDSP",
368 		.disp_get	= "\\SSTE"
369 	},
370 	{
371 		.name		= "M6R",
372 		.mled_set	= "MLED",
373 		.wled_set	= "WLED",
374 		.brn_get	= "GPLV",
375 		.brn_set	= "SPLV",
376 		.lcd_get	= "\\_SB.PCI0.SBSM.SEO4",
377 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
378 		.disp_get	= "\\SSTE",
379 		.disp_set	= "SDSP"
380 	},
381 	{
382 		.name		= "S1x",
383 		.mled_set	= "MLED",
384 		.wled_set	= "WLED",
385 		.lcd_get	= "\\PNOF",
386 		.lcd_set	= "\\_SB.PCI0.PX40.Q10",
387 		.brn_get	= "GPLV",
388 		.brn_set	= "SPLV"
389 	},
390 	{
391 		.name		= "S2x",
392 		.mled_set	= "MLED",
393 		.lcd_get	= "\\BKLI",
394 		.lcd_set	= "\\_SB.PCI0.ISA.EC0._Q10",
395 		.brn_up		= "\\_SB.PCI0.ISA.EC0._Q0B",
396 		.brn_dn		= "\\_SB.PCI0.ISA.EC0._Q0A"
397 	},
398 	{
399 		.name		= "V6V",
400 		.bled_set	= "BLED",
401 		.tled_set	= "TLED",
402 		.wled_set	= "WLED",
403 		.lcd_get	= "\\BKLT",
404 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
405 		.brn_get	= "GPLV",
406 		.brn_set	= "SPLV",
407 		.disp_get	= "\\_SB.PCI0.P0P1.VGA.GETD",
408 		.disp_set	= "SDSP"
409 	},
410 	{
411 		.name		= "W5A",
412 		.bled_set	= "BLED",
413 		.lcd_get	= "\\BKLT",
414 		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
415 		.brn_get	= "GPLV",
416 		.brn_set	= "SPLV",
417 		.disp_get	= "\\_SB.PCI0.P0P2.VGA.GETD",
418 		.disp_set	= "SDSP"
419 	},
420 	{ .name = NULL }
421 };
422 
423 /*
424  * Samsung P30/P35 laptops have an Asus ATK0100 gadget interface,
425  * but they can't be probed quite the same way as Asus laptops.
426  */
427 static struct acpi_asus_model acpi_samsung_models[] = {
428 	{
429 		.name		= "P30",
430 		.wled_set	= "WLED",
431 		.brn_up		= "\\_SB.PCI0.LPCB.EC0._Q68",
432 		.brn_dn		= "\\_SB.PCI0.LPCB.EC0._Q69",
433 		.lcd_get	= "\\BKLT",
434 		.lcd_set	= "\\_SB.PCI0.LPCB.EC0._Q0E"
435 	},
436 	{ .name = NULL }
437 };
438 
439 static void	acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context);
440 
441 /*
442  * EeePC have an Asus ASUS010 gadget interface,
443  * but they can't be probed quite the same way as Asus laptops.
444  */
445 static struct acpi_asus_model acpi_eeepc_models[] = {
446 	{
447 		.name		= "EEE",
448 		.brn_get	= "\\_SB.ATKD.PBLG",
449 		.brn_set	= "\\_SB.ATKD.PBLS",
450 		.cam_get	= "\\_SB.ATKD.CAMG",
451 		.cam_set	= "\\_SB.ATKD.CAMS",
452 		.crd_set	= "\\_SB.ATKD.CRDS",
453 		.crd_get	= "\\_SB.ATKD.CRDG",
454 		.wlan_get	= "\\_SB.ATKD.WLDG",
455 		.wlan_set	= "\\_SB.ATKD.WLDS",
456 		.n_func		= acpi_asus_eeepc_notify
457 	},
458 	{ .name = NULL }
459 };
460 
461 static struct {
462 	char	*name;
463 	char	*description;
464 	int	method;
465 	int	flag_anybody;
466 } acpi_asus_sysctls[] = {
467 	{
468 		.name		= "lcd_backlight",
469 		.method		= ACPI_ASUS_METHOD_LCD,
470 		.description	= "state of the lcd backlight",
471 		.flag_anybody	= 1
472 	},
473 	{
474 		.name		= "lcd_brightness",
475 		.method		= ACPI_ASUS_METHOD_BRN,
476 		.description	= "brightness of the lcd panel",
477 		.flag_anybody	= 1
478 	},
479 	{
480 		.name		= "video_output",
481 		.method		= ACPI_ASUS_METHOD_DISP,
482 		.description	= "display output state",
483 	},
484 	{
485 		.name		= "camera",
486 		.method		= ACPI_ASUS_METHOD_CAMERA,
487 		.description	= "internal camera state",
488 	},
489 	{
490 		.name		= "cardreader",
491 		.method		= ACPI_ASUS_METHOD_CARDRD,
492 		.description	= "internal card reader state",
493 	},
494 	{
495 		.name		= "wlan",
496 		.method		= ACPI_ASUS_METHOD_WLAN,
497 		.description	= "wireless lan state",
498 	},
499 	{ .name = NULL }
500 };
501 
502 ACPI_SERIAL_DECL(asus, "ACPI ASUS extras");
503 
504 /* Function prototypes */
505 static int	acpi_asus_probe(device_t dev);
506 static int	acpi_asus_attach(device_t dev);
507 static int	acpi_asus_detach(device_t dev);
508 
509 static void	acpi_asus_led(struct acpi_asus_led *led, int state);
510 static void	acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused);
511 
512 static int	acpi_asus_sysctl(SYSCTL_HANDLER_ARGS);
513 static int	acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method);
514 static int	acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method);
515 static int	acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int val);
516 
517 static void	acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context);
518 
519 static device_method_t acpi_asus_methods[] = {
520 	DEVMETHOD(device_probe,  acpi_asus_probe),
521 	DEVMETHOD(device_attach, acpi_asus_attach),
522 	DEVMETHOD(device_detach, acpi_asus_detach),
523 	{ 0, 0 }
524 };
525 
526 static driver_t acpi_asus_driver = {
527 	"acpi_asus",
528 	acpi_asus_methods,
529 	sizeof(struct acpi_asus_softc)
530 };
531 
532 static devclass_t acpi_asus_devclass;
533 
534 DRIVER_MODULE(acpi_asus, acpi, acpi_asus_driver, acpi_asus_devclass, 0, 0);
535 MODULE_DEPEND(acpi_asus, acpi, 1, 1, 1);
536 
537 static int
538 acpi_asus_probe(device_t dev)
539 {
540 	struct acpi_asus_model	*model;
541 	struct acpi_asus_softc	*sc;
542 	struct sbuf		*sb;
543 	ACPI_BUFFER		Buf;
544 	ACPI_OBJECT		Arg, *Obj;
545 	ACPI_OBJECT_LIST	Args;
546 	static char		*asus_ids[] = { "ATK0100", "ASUS010", NULL };
547 	int rv;
548 	char *rstr;
549 
550 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
551 
552 	if (acpi_disabled("asus"))
553 		return (ENXIO);
554 	rv = ACPI_ID_PROBE(device_get_parent(dev), dev, asus_ids, &rstr);
555 	if (rv > 0) {
556 		return (rv);
557 	}
558 
559 	sc = device_get_softc(dev);
560 	sc->dev = dev;
561 	sc->handle = acpi_get_handle(dev);
562 
563 	Arg.Type = ACPI_TYPE_INTEGER;
564 	Arg.Integer.Value = 0;
565 
566 	Args.Count = 1;
567 	Args.Pointer = &Arg;
568 
569 	Buf.Pointer = NULL;
570 	Buf.Length = ACPI_ALLOCATE_BUFFER;
571 
572 	AcpiEvaluateObject(sc->handle, "INIT", &Args, &Buf);
573 	Obj = Buf.Pointer;
574 
575 	/*
576 	 * The Samsung P30 returns a null-pointer from INIT, we
577 	 * can identify it from the 'ODEM' string in the DSDT.
578 	 */
579 	if (Obj->String.Pointer == NULL) {
580 		ACPI_STATUS		status;
581 		ACPI_TABLE_HEADER	th;
582 
583 		status = AcpiGetTableHeader(ACPI_SIG_DSDT, 0, &th);
584 		if (ACPI_FAILURE(status)) {
585 			device_printf(dev, "Unsupported (Samsung?) laptop\n");
586 			AcpiOsFree(Buf.Pointer);
587 			return (ENXIO);
588 		}
589 
590 		if (strncmp("ODEM", th.OemTableId, 4) == 0) {
591 			sc->model = &acpi_samsung_models[0];
592 			device_set_desc(dev, "Samsung P30 Laptop Extras");
593 			AcpiOsFree(Buf.Pointer);
594 			return (rv);
595 		}
596 
597 		/* EeePC */
598 		if (strncmp("ASUS010", rstr, 7) == 0) {
599 			sc->model = &acpi_eeepc_models[0];
600 			device_set_desc(dev, "ASUS EeePC");
601 			AcpiOsFree(Buf.Pointer);
602 			return (rv);
603 		}
604 	}
605 
606 	sb = sbuf_new_auto();
607 	if (sb == NULL)
608 		return (ENOMEM);
609 
610 	/*
611 	 * Asus laptops are simply identified by name, easy!
612 	 */
613 	for (model = acpi_asus_models; model->name != NULL; model++) {
614 		if (strncmp(Obj->String.Pointer, model->name, 3) == 0) {
615 good:
616 			sbuf_printf(sb, "Asus %s Laptop Extras",
617 			    Obj->String.Pointer);
618 			sbuf_finish(sb);
619 
620 			sc->model = model;
621 			device_set_desc_copy(dev, sbuf_data(sb));
622 
623 			sbuf_delete(sb);
624 			AcpiOsFree(Buf.Pointer);
625 			return (rv);
626 		}
627 
628 		/*
629 		 * Some models look exactly the same as other models, but have
630 		 * their own ids.  If we spot these, set them up with the same
631 		 * details as the models they're like, possibly dealing with
632 		 * small differences.
633 		 *
634 		 * XXX: there must be a prettier way to do this!
635 		 */
636 		else if (strncmp(model->name, "xxN", 3) == 0 &&
637 		    (strncmp(Obj->String.Pointer, "M3N", 3) == 0 ||
638 		     strncmp(Obj->String.Pointer, "S1N", 3) == 0))
639 			goto good;
640 		else if (strncmp(model->name, "A1x", 3) == 0 &&
641 		    strncmp(Obj->String.Pointer, "A1", 2) == 0)
642 			goto good;
643 		else if (strncmp(model->name, "A2x", 3) == 0 &&
644 		    strncmp(Obj->String.Pointer, "A2", 2) == 0)
645 			goto good;
646 		else if (strncmp(model->name, "A3F", 3) == 0 &&
647 		    strncmp(Obj->String.Pointer, "A6F", 3) == 0)
648 			goto good;
649 		else if (strncmp(model->name, "D1x", 3) == 0 &&
650 		    strncmp(Obj->String.Pointer, "D1", 2) == 0)
651 			goto good;
652 		else if (strncmp(model->name, "L3H", 3) == 0 &&
653 		    strncmp(Obj->String.Pointer, "L2E", 3) == 0)
654 			goto good;
655 		else if (strncmp(model->name, "L5x", 3) == 0 &&
656 		    strncmp(Obj->String.Pointer, "L5", 2) == 0)
657 			goto good;
658 		else if (strncmp(model->name, "M2E", 3) == 0 &&
659 		    (strncmp(Obj->String.Pointer, "M2", 2) == 0 ||
660 		     strncmp(Obj->String.Pointer, "L4E", 3) == 0))
661 			goto good;
662 		else if (strncmp(model->name, "S1x", 3) == 0 &&
663 		    (strncmp(Obj->String.Pointer, "L8", 2) == 0 ||
664 		     strncmp(Obj->String.Pointer, "S1", 2) == 0))
665 			goto good;
666 		else if (strncmp(model->name, "S2x", 3) == 0 &&
667 		    (strncmp(Obj->String.Pointer, "J1", 2) == 0 ||
668 		     strncmp(Obj->String.Pointer, "S2", 2) == 0))
669 			goto good;
670 
671 		/* L2B is like L3C but has no lcd_get method */
672 		else if (strncmp(model->name, "L3C", 3) == 0 &&
673 		    strncmp(Obj->String.Pointer, "L2B", 3) == 0) {
674 			model->lcd_get = NULL;
675 			goto good;
676 		}
677 
678 		/* A3G is like M6R but with a different lcd_get method */
679 		else if (strncmp(model->name, "M6R", 3) == 0 &&
680 		    strncmp(Obj->String.Pointer, "A3G", 3) == 0) {
681 			model->lcd_get = "\\BLFG";
682 			goto good;
683 		}
684 
685 		/* M2N and W1N are like xxN with added WLED */
686 		else if (strncmp(model->name, "xxN", 3) == 0 &&
687 		    (strncmp(Obj->String.Pointer, "M2N", 3) == 0 ||
688 		     strncmp(Obj->String.Pointer, "W1N", 3) == 0)) {
689 			model->wled_set = "WLED";
690 			goto good;
691 		}
692 
693 		/* M5N and S5N are like xxN without MLED */
694 		else if (strncmp(model->name, "xxN", 3) == 0 &&
695 		    (strncmp(Obj->String.Pointer, "M5N", 3) == 0 ||
696 		     strncmp(Obj->String.Pointer, "S5N", 3) == 0)) {
697 			model->mled_set = NULL;
698 			goto good;
699 		}
700 	}
701 
702 	sbuf_printf(sb, "Unsupported Asus laptop: %s\n", Obj->String.Pointer);
703 	sbuf_finish(sb);
704 
705 	device_printf(dev, "%s", sbuf_data(sb));
706 
707 	sbuf_delete(sb);
708 	AcpiOsFree(Buf.Pointer);
709 
710 	return (ENXIO);
711 }
712 
713 static int
714 acpi_asus_attach(device_t dev)
715 {
716 	struct acpi_asus_softc	*sc;
717 	struct acpi_softc	*acpi_sc;
718 
719 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
720 
721 	sc = device_get_softc(dev);
722 	acpi_sc = acpi_device_get_parent_softc(dev);
723 
724 	/* Build sysctl tree */
725 	sysctl_ctx_init(&sc->sysctl_ctx);
726 	sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
727 	    SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
728 	    OID_AUTO, "asus", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "");
729 
730 	/* Hook up nodes */
731 	for (int i = 0; acpi_asus_sysctls[i].name != NULL; i++) {
732 		if (!acpi_asus_sysctl_init(sc, acpi_asus_sysctls[i].method))
733 			continue;
734 
735 		if (acpi_asus_sysctls[i].flag_anybody != 0) {
736 			SYSCTL_ADD_PROC(&sc->sysctl_ctx,
737 			    SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
738 			    acpi_asus_sysctls[i].name,
739 			    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY |
740 			    CTLFLAG_NEEDGIANT, sc, i, acpi_asus_sysctl, "I",
741 			    acpi_asus_sysctls[i].description);
742 		} else {
743 			SYSCTL_ADD_PROC(&sc->sysctl_ctx,
744 			    SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
745 			    acpi_asus_sysctls[i].name,
746 			    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
747 			    sc, i, acpi_asus_sysctl, "I",
748 			    acpi_asus_sysctls[i].description);
749 		}
750 	}
751 
752 	/* Attach leds */
753 	if (sc->model->bled_set) {
754 		sc->s_bled.busy = 0;
755 		sc->s_bled.sc = sc;
756 		sc->s_bled.type = ACPI_ASUS_LED_BLED;
757 		sc->s_bled.cdev =
758 		    led_create_state((led_t *)acpi_asus_led, &sc->s_bled,
759 			"bled", 1);
760 	}
761 
762 	if (sc->model->dled_set) {
763 		sc->s_dled.busy = 0;
764 		sc->s_dled.sc = sc;
765 		sc->s_dled.type = ACPI_ASUS_LED_DLED;
766 		sc->s_dled.cdev =
767 		    led_create((led_t *)acpi_asus_led, &sc->s_dled, "dled");
768 	}
769 
770 	if (sc->model->gled_set) {
771 		sc->s_gled.busy = 0;
772 		sc->s_gled.sc = sc;
773 		sc->s_gled.type = ACPI_ASUS_LED_GLED;
774 		sc->s_gled.cdev =
775 		    led_create((led_t *)acpi_asus_led, &sc->s_gled, "gled");
776 	}
777 
778 	if (sc->model->mled_set) {
779 		sc->s_mled.busy = 0;
780 		sc->s_mled.sc = sc;
781 		sc->s_mled.type = ACPI_ASUS_LED_MLED;
782 		sc->s_mled.cdev =
783 		    led_create((led_t *)acpi_asus_led, &sc->s_mled, "mled");
784 	}
785 
786 	if (sc->model->tled_set) {
787 		sc->s_tled.busy = 0;
788 		sc->s_tled.sc = sc;
789 		sc->s_tled.type = ACPI_ASUS_LED_TLED;
790 		sc->s_tled.cdev =
791 		    led_create_state((led_t *)acpi_asus_led, &sc->s_tled,
792 			"tled", 1);
793 	}
794 
795 	if (sc->model->wled_set) {
796 		sc->s_wled.busy = 0;
797 		sc->s_wled.sc = sc;
798 		sc->s_wled.type = ACPI_ASUS_LED_WLED;
799 		sc->s_wled.cdev =
800 		    led_create_state((led_t *)acpi_asus_led, &sc->s_wled,
801 			"wled", 1);
802 	}
803 
804 	/* Activate hotkeys */
805 	AcpiEvaluateObject(sc->handle, "BSTS", NULL, NULL);
806 
807 	/* Handle notifies */
808 	if (sc->model->n_func == NULL)
809 		sc->model->n_func = acpi_asus_notify;
810 
811 	AcpiInstallNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
812 	    sc->model->n_func, dev);
813 
814 	/* Find and hook the 'LCDD' object */
815 	if (sc->model->lcdd != NULL && sc->model->lcdd_n_func != NULL) {
816 		ACPI_STATUS res;
817 
818 		sc->lcdd_handle = NULL;
819 		res = AcpiGetHandle((sc->model->lcdd[0] == '\\' ?
820 		    NULL : sc->handle), sc->model->lcdd, &(sc->lcdd_handle));
821 		if (ACPI_SUCCESS(res)) {
822 			AcpiInstallNotifyHandler((sc->lcdd_handle),
823 			    ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func, dev);
824 	    	} else {
825 	    		printf("%s: unable to find LCD device '%s'\n",
826 	    		    __func__, sc->model->lcdd);
827 	    	}
828 	}
829 
830 	return (0);
831 }
832 
833 static int
834 acpi_asus_detach(device_t dev)
835 {
836 	struct acpi_asus_softc	*sc;
837 
838 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
839 
840 	sc = device_get_softc(dev);
841 
842 	/* Turn the lights off */
843 	if (sc->model->bled_set)
844 		led_destroy(sc->s_bled.cdev);
845 
846 	if (sc->model->dled_set)
847 		led_destroy(sc->s_dled.cdev);
848 
849 	if (sc->model->gled_set)
850 		led_destroy(sc->s_gled.cdev);
851 
852 	if (sc->model->mled_set)
853 		led_destroy(sc->s_mled.cdev);
854 
855 	if (sc->model->tled_set)
856 		led_destroy(sc->s_tled.cdev);
857 
858 	if (sc->model->wled_set)
859 		led_destroy(sc->s_wled.cdev);
860 
861 	/* Remove notify handler */
862 	AcpiRemoveNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
863 	    acpi_asus_notify);
864 
865 	if (sc->lcdd_handle) {
866 		KASSERT(sc->model->lcdd_n_func != NULL,
867 		    ("model->lcdd_n_func is NULL, but lcdd_handle is non-zero"));
868 		AcpiRemoveNotifyHandler((sc->lcdd_handle),
869 		    ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func);
870 	}
871 
872 	/* Free sysctl tree */
873 	sysctl_ctx_free(&sc->sysctl_ctx);
874 
875 	return (0);
876 }
877 
878 static void
879 acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused)
880 {
881 	struct acpi_asus_softc	*sc;
882 	char			*method;
883 	int			state;
884 
885 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
886 
887 	sc = led->sc;
888 
889 	switch (led->type) {
890 	case ACPI_ASUS_LED_BLED:
891 		method = sc->model->bled_set;
892 		state = led->state;
893 		break;
894 	case ACPI_ASUS_LED_DLED:
895 		method = sc->model->dled_set;
896 		state = led->state;
897 		break;
898 	case ACPI_ASUS_LED_GLED:
899 		method = sc->model->gled_set;
900 		state = led->state + 1;	/* 1: off, 2: on */
901 		break;
902 	case ACPI_ASUS_LED_MLED:
903 		method = sc->model->mled_set;
904 		state = !led->state;	/* inverted */
905 		break;
906 	case ACPI_ASUS_LED_TLED:
907 		method = sc->model->tled_set;
908 		state = led->state;
909 		break;
910 	case ACPI_ASUS_LED_WLED:
911 		method = sc->model->wled_set;
912 		state = led->state;
913 		break;
914 	default:
915 		printf("acpi_asus_led: invalid LED type %d\n",
916 		    (int)led->type);
917 		return;
918 	}
919 
920 	acpi_SetInteger(sc->handle, method, state);
921 	led->busy = 0;
922 }
923 
924 static void
925 acpi_asus_led(struct acpi_asus_led *led, int state)
926 {
927 
928 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
929 
930 	if (led->busy)
931 		return;
932 
933 	led->busy = 1;
934 	led->state = state;
935 
936 	AcpiOsExecute(OSL_NOTIFY_HANDLER, (void *)acpi_asus_led_task, led);
937 }
938 
939 static int
940 acpi_asus_sysctl(SYSCTL_HANDLER_ARGS)
941 {
942 	struct acpi_asus_softc	*sc;
943 	int			arg;
944 	int			error = 0;
945 	int			function;
946 	int			method;
947 
948 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
949 
950 	sc = (struct acpi_asus_softc *)oidp->oid_arg1;
951 	function = oidp->oid_arg2;
952 	method = acpi_asus_sysctls[function].method;
953 
954 	ACPI_SERIAL_BEGIN(asus);
955 	arg = acpi_asus_sysctl_get(sc, method);
956 	error = sysctl_handle_int(oidp, &arg, 0, req);
957 
958 	/* Sanity check */
959 	if (error != 0 || req->newptr == NULL)
960 		goto out;
961 
962 	/* Update */
963 	error = acpi_asus_sysctl_set(sc, method, arg);
964 
965 out:
966 	ACPI_SERIAL_END(asus);
967 	return (error);
968 }
969 
970 static int
971 acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method)
972 {
973 	int val = 0;
974 
975 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
976 	ACPI_SERIAL_ASSERT(asus);
977 
978 	switch (method) {
979 	case ACPI_ASUS_METHOD_BRN:
980 		val = sc->s_brn;
981 		break;
982 	case ACPI_ASUS_METHOD_DISP:
983 		val = sc->s_disp;
984 		break;
985 	case ACPI_ASUS_METHOD_LCD:
986 		val = sc->s_lcd;
987 		break;
988 	case ACPI_ASUS_METHOD_CAMERA:
989 		val = sc->s_cam;
990 		break;
991 	case ACPI_ASUS_METHOD_CARDRD:
992 		val = sc->s_crd;
993 		break;
994 	case ACPI_ASUS_METHOD_WLAN:
995 		val = sc->s_wlan;
996 		break;
997 	}
998 
999 	return (val);
1000 }
1001 
1002 static int
1003 acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int arg)
1004 {
1005 	ACPI_STATUS		status = AE_OK;
1006 	ACPI_OBJECT_LIST 	acpiargs;
1007 	ACPI_OBJECT		acpiarg[1];
1008 
1009 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1010 	ACPI_SERIAL_ASSERT(asus);
1011 
1012 	acpiargs.Count = 1;
1013 	acpiargs.Pointer = acpiarg;
1014 	acpiarg[0].Type = ACPI_TYPE_INTEGER;
1015 	acpiarg[0].Integer.Value = arg;
1016 
1017 	switch (method) {
1018 	case ACPI_ASUS_METHOD_BRN:
1019 		if (arg < 0 || arg > 15)
1020 			return (EINVAL);
1021 
1022 		if (sc->model->brn_set)
1023 			status = acpi_SetInteger(sc->handle,
1024 			    sc->model->brn_set, arg);
1025 		else {
1026 			while (arg != 0) {
1027 				status = AcpiEvaluateObject(sc->handle,
1028 				    (arg > 0) ?  sc->model->brn_up :
1029 				    sc->model->brn_dn, NULL, NULL);
1030 				(arg > 0) ? arg-- : arg++;
1031 			}
1032 		}
1033 
1034 		if (ACPI_SUCCESS(status))
1035 			sc->s_brn = arg;
1036 
1037 		break;
1038 	case ACPI_ASUS_METHOD_DISP:
1039 		if (arg < 0 || arg > 7)
1040 			return (EINVAL);
1041 
1042 		status = acpi_SetInteger(sc->handle,
1043 		    sc->model->disp_set, arg);
1044 
1045 		if (ACPI_SUCCESS(status))
1046 			sc->s_disp = arg;
1047 
1048 		break;
1049 	case ACPI_ASUS_METHOD_LCD:
1050 		if (arg < 0 || arg > 1)
1051 			return (EINVAL);
1052 
1053 		if (strncmp(sc->model->name, "L3H", 3) != 0)
1054 			status = AcpiEvaluateObject(sc->handle,
1055 			    sc->model->lcd_set, NULL, NULL);
1056 		else
1057 			status = acpi_SetInteger(sc->handle,
1058 			    sc->model->lcd_set, 0x7);
1059 
1060 		if (ACPI_SUCCESS(status))
1061 			sc->s_lcd = arg;
1062 
1063 		break;
1064 	case ACPI_ASUS_METHOD_CAMERA:
1065 		if (arg < 0 || arg > 1)
1066 			return (EINVAL);
1067 
1068 		status = AcpiEvaluateObject(sc->handle,
1069 		    sc->model->cam_set, &acpiargs, NULL);
1070 
1071 		if (ACPI_SUCCESS(status))
1072 			sc->s_cam = arg;
1073 		break;
1074 	case ACPI_ASUS_METHOD_CARDRD:
1075 		if (arg < 0 || arg > 1)
1076 			return (EINVAL);
1077 
1078 		status = AcpiEvaluateObject(sc->handle,
1079 		    sc->model->crd_set, &acpiargs, NULL);
1080 
1081 		if (ACPI_SUCCESS(status))
1082 			sc->s_crd = arg;
1083 		break;
1084 	case ACPI_ASUS_METHOD_WLAN:
1085 		if (arg < 0 || arg > 1)
1086 			return (EINVAL);
1087 
1088 		status = AcpiEvaluateObject(sc->handle,
1089 		    sc->model->wlan_set, &acpiargs, NULL);
1090 
1091 		if (ACPI_SUCCESS(status))
1092 			sc->s_wlan = arg;
1093 		break;
1094 	}
1095 
1096 	return (0);
1097 }
1098 
1099 static int
1100 acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method)
1101 {
1102 	ACPI_STATUS	status;
1103 
1104 	switch (method) {
1105 	case ACPI_ASUS_METHOD_BRN:
1106 		if (sc->model->brn_get) {
1107 			/* GPLV/SPLV models */
1108 			status = acpi_GetInteger(sc->handle,
1109 			    sc->model->brn_get, &sc->s_brn);
1110 			if (ACPI_SUCCESS(status))
1111 				return (TRUE);
1112 		} else if (sc->model->brn_up) {
1113 			/* Relative models */
1114 			status = AcpiEvaluateObject(sc->handle,
1115 			    sc->model->brn_up, NULL, NULL);
1116 			if (ACPI_FAILURE(status))
1117 				return (FALSE);
1118 
1119 			status = AcpiEvaluateObject(sc->handle,
1120 			    sc->model->brn_dn, NULL, NULL);
1121 			if (ACPI_FAILURE(status))
1122 				return (FALSE);
1123 
1124 			return (TRUE);
1125 		}
1126 		return (FALSE);
1127 	case ACPI_ASUS_METHOD_DISP:
1128 		if (sc->model->disp_get) {
1129 			status = acpi_GetInteger(sc->handle,
1130 			    sc->model->disp_get, &sc->s_disp);
1131 			if (ACPI_SUCCESS(status))
1132 				return (TRUE);
1133 		}
1134 		return (FALSE);
1135 	case ACPI_ASUS_METHOD_LCD:
1136 		if (sc->model->lcd_get) {
1137 			if (strncmp(sc->model->name, "L3H", 3) == 0) {
1138 				ACPI_BUFFER		Buf;
1139 				ACPI_OBJECT		Arg[2], Obj;
1140 				ACPI_OBJECT_LIST	Args;
1141 
1142 				/* L3H is a bit special */
1143 				Arg[0].Type = ACPI_TYPE_INTEGER;
1144 				Arg[0].Integer.Value = 0x02;
1145 				Arg[1].Type = ACPI_TYPE_INTEGER;
1146 				Arg[1].Integer.Value = 0x03;
1147 
1148 				Args.Count = 2;
1149 				Args.Pointer = Arg;
1150 
1151 				Buf.Length = sizeof(Obj);
1152 				Buf.Pointer = &Obj;
1153 
1154 				status = AcpiEvaluateObject(sc->handle,
1155 				    sc->model->lcd_get, &Args, &Buf);
1156 				if (ACPI_SUCCESS(status) &&
1157 				    Obj.Type == ACPI_TYPE_INTEGER) {
1158 					sc->s_lcd = Obj.Integer.Value >> 8;
1159 					return (TRUE);
1160 				}
1161 			} else {
1162 				status = acpi_GetInteger(sc->handle,
1163 				    sc->model->lcd_get, &sc->s_lcd);
1164 				if (ACPI_SUCCESS(status))
1165 					return (TRUE);
1166 			}
1167 		}
1168 		return (FALSE);
1169 	case ACPI_ASUS_METHOD_CAMERA:
1170 		if (sc->model->cam_get) {
1171 			status = acpi_GetInteger(sc->handle,
1172 			    sc->model->cam_get, &sc->s_cam);
1173 			if (ACPI_SUCCESS(status))
1174 				return (TRUE);
1175 		}
1176 		return (FALSE);
1177 	case ACPI_ASUS_METHOD_CARDRD:
1178 		if (sc->model->crd_get) {
1179 			status = acpi_GetInteger(sc->handle,
1180 			    sc->model->crd_get, &sc->s_crd);
1181 			if (ACPI_SUCCESS(status))
1182 				return (TRUE);
1183 		}
1184 		return (FALSE);
1185 	case ACPI_ASUS_METHOD_WLAN:
1186 		if (sc->model->wlan_get) {
1187 			status = acpi_GetInteger(sc->handle,
1188 			    sc->model->wlan_get, &sc->s_wlan);
1189 			if (ACPI_SUCCESS(status))
1190 				return (TRUE);
1191 		}
1192 		return (FALSE);
1193 	}
1194 	return (FALSE);
1195 }
1196 
1197 static void
1198 acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context)
1199 {
1200 	struct acpi_asus_softc	*sc;
1201 	struct acpi_softc	*acpi_sc;
1202 
1203 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1204 
1205 	sc = device_get_softc((device_t)context);
1206 	acpi_sc = acpi_device_get_parent_softc(sc->dev);
1207 
1208 	ACPI_SERIAL_BEGIN(asus);
1209 	if ((notify & ~0x10) <= 15) {
1210 		sc->s_brn = notify & ~0x10;
1211 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
1212 	} else if ((notify & ~0x20) <= 15) {
1213 		sc->s_brn = notify & ~0x20;
1214 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
1215 	} else if (notify == 0x33) {
1216 		sc->s_lcd = 1;
1217 		ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned on\n");
1218 	} else if (notify == 0x34) {
1219 		sc->s_lcd = 0;
1220 		ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned off\n");
1221 	} else if (notify == 0x86) {
1222 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1);
1223 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
1224 	} else if (notify == 0x87) {
1225 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1);
1226 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
1227 	} else {
1228 		/* Notify devd(8) */
1229 		acpi_UserNotify("ASUS", h, notify);
1230 	}
1231 	ACPI_SERIAL_END(asus);
1232 }
1233 
1234 static void
1235 acpi_asus_lcdd_notify(ACPI_HANDLE h, UINT32 notify, void *context)
1236 {
1237 	struct acpi_asus_softc	*sc;
1238 	struct acpi_softc	*acpi_sc;
1239 
1240 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1241 
1242 	sc = device_get_softc((device_t)context);
1243 	acpi_sc = acpi_device_get_parent_softc(sc->dev);
1244 
1245 	ACPI_SERIAL_BEGIN(asus);
1246 	switch (notify) {
1247 	case 0x87:
1248 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1);
1249 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
1250 		break;
1251 	case 0x86:
1252 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1);
1253 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
1254 		break;
1255 	}
1256 	ACPI_SERIAL_END(asus);
1257 }
1258 
1259 static void
1260 acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context)
1261 {
1262 	struct acpi_asus_softc	*sc;
1263 	struct acpi_softc	*acpi_sc;
1264 
1265 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1266 
1267 	sc = device_get_softc((device_t)context);
1268 	acpi_sc = acpi_device_get_parent_softc(sc->dev);
1269 
1270 	ACPI_SERIAL_BEGIN(asus);
1271 	if ((notify & ~0x20) <= 15) {
1272 		sc->s_brn = notify & ~0x20;
1273 		ACPI_VPRINT(sc->dev, acpi_sc,
1274 		    "Brightness increased/decreased\n");
1275 	} else {
1276 		/* Notify devd(8) */
1277 		acpi_UserNotify("ASUS-Eee", h, notify);
1278 	}
1279 	ACPI_SERIAL_END(asus);
1280 }
1281