xref: /freebsd/sys/dev/acpi_support/acpi_asus.c (revision fcb560670601b2a4d87bb31d7531c8dcc37ee71b)
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 
421 	{ .name = NULL }
422 };
423 
424 /*
425  * Samsung P30/P35 laptops have an Asus ATK0100 gadget interface,
426  * but they can't be probed quite the same way as Asus laptops.
427  */
428 static struct acpi_asus_model acpi_samsung_models[] = {
429 	{
430 		.name		= "P30",
431 		.wled_set	= "WLED",
432 		.brn_up		= "\\_SB.PCI0.LPCB.EC0._Q68",
433 		.brn_dn		= "\\_SB.PCI0.LPCB.EC0._Q69",
434 		.lcd_get	= "\\BKLT",
435 		.lcd_set	= "\\_SB.PCI0.LPCB.EC0._Q0E"
436 	},
437 
438 	{ .name = NULL }
439 };
440 
441 static void	acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context);
442 
443 /*
444  * EeePC have an Asus ASUS010 gadget interface,
445  * but they can't be probed quite the same way as Asus laptops.
446  */
447 static struct acpi_asus_model acpi_eeepc_models[] = {
448 	{
449 		.name		= "EEE",
450 		.brn_get	= "\\_SB.ATKD.PBLG",
451 		.brn_set	= "\\_SB.ATKD.PBLS",
452 		.cam_get	= "\\_SB.ATKD.CAMG",
453 		.cam_set	= "\\_SB.ATKD.CAMS",
454 		.crd_set	= "\\_SB.ATKD.CRDS",
455 		.crd_get	= "\\_SB.ATKD.CRDG",
456 		.wlan_get	= "\\_SB.ATKD.WLDG",
457 		.wlan_set	= "\\_SB.ATKD.WLDS",
458 		.n_func		= acpi_asus_eeepc_notify
459 	},
460 
461 	{ .name = NULL }
462 };
463 
464 static struct {
465 	char	*name;
466 	char	*description;
467 	int	method;
468 	int	flag_anybody;
469 } acpi_asus_sysctls[] = {
470 	{
471 		.name		= "lcd_backlight",
472 		.method		= ACPI_ASUS_METHOD_LCD,
473 		.description	= "state of the lcd backlight",
474 		.flag_anybody	= 1
475 	},
476 	{
477 		.name		= "lcd_brightness",
478 		.method		= ACPI_ASUS_METHOD_BRN,
479 		.description	= "brightness of the lcd panel",
480 		.flag_anybody	= 1
481 	},
482 	{
483 		.name		= "video_output",
484 		.method		= ACPI_ASUS_METHOD_DISP,
485 		.description	= "display output state",
486 	},
487 	{
488 		.name		= "camera",
489 		.method		= ACPI_ASUS_METHOD_CAMERA,
490 		.description	= "internal camera state",
491 	},
492 	{
493 		.name		= "cardreader",
494 		.method		= ACPI_ASUS_METHOD_CARDRD,
495 		.description	= "internal card reader state",
496 	},
497 	{
498 		.name		= "wlan",
499 		.method		= ACPI_ASUS_METHOD_WLAN,
500 		.description	= "wireless lan state",
501 	},
502 
503 	{ .name = NULL }
504 };
505 
506 ACPI_SERIAL_DECL(asus, "ACPI ASUS extras");
507 
508 /* Function prototypes */
509 static int	acpi_asus_probe(device_t dev);
510 static int	acpi_asus_attach(device_t dev);
511 static int	acpi_asus_detach(device_t dev);
512 
513 static void	acpi_asus_led(struct acpi_asus_led *led, int state);
514 static void	acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused);
515 
516 static int	acpi_asus_sysctl(SYSCTL_HANDLER_ARGS);
517 static int	acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method);
518 static int	acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method);
519 static int	acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int val);
520 
521 static void	acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context);
522 
523 static device_method_t acpi_asus_methods[] = {
524 	DEVMETHOD(device_probe,  acpi_asus_probe),
525 	DEVMETHOD(device_attach, acpi_asus_attach),
526 	DEVMETHOD(device_detach, acpi_asus_detach),
527 
528 	{ 0, 0 }
529 };
530 
531 static driver_t acpi_asus_driver = {
532 	"acpi_asus",
533 	acpi_asus_methods,
534 	sizeof(struct acpi_asus_softc)
535 };
536 
537 static devclass_t acpi_asus_devclass;
538 
539 DRIVER_MODULE(acpi_asus, acpi, acpi_asus_driver, acpi_asus_devclass, 0, 0);
540 MODULE_DEPEND(acpi_asus, acpi, 1, 1, 1);
541 
542 static int
543 acpi_asus_probe(device_t dev)
544 {
545 	struct acpi_asus_model	*model;
546 	struct acpi_asus_softc	*sc;
547 	struct sbuf		*sb;
548 	ACPI_BUFFER		Buf;
549 	ACPI_OBJECT		Arg, *Obj;
550 	ACPI_OBJECT_LIST	Args;
551 	static char		*asus_ids[] = { "ATK0100", "ASUS010", NULL };
552 	char *rstr;
553 
554 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
555 
556 	if (acpi_disabled("asus"))
557 		return (ENXIO);
558 	rstr = ACPI_ID_PROBE(device_get_parent(dev), dev, asus_ids);
559 	if (rstr == NULL) {
560 		return (ENXIO);
561 	}
562 
563 	sc = device_get_softc(dev);
564 	sc->dev = dev;
565 	sc->handle = acpi_get_handle(dev);
566 
567 	Arg.Type = ACPI_TYPE_INTEGER;
568 	Arg.Integer.Value = 0;
569 
570 	Args.Count = 1;
571 	Args.Pointer = &Arg;
572 
573 	Buf.Pointer = NULL;
574 	Buf.Length = ACPI_ALLOCATE_BUFFER;
575 
576 	AcpiEvaluateObject(sc->handle, "INIT", &Args, &Buf);
577 	Obj = Buf.Pointer;
578 
579 	/*
580 	 * The Samsung P30 returns a null-pointer from INIT, we
581 	 * can identify it from the 'ODEM' string in the DSDT.
582 	 */
583 	if (Obj->String.Pointer == NULL) {
584 		ACPI_STATUS		status;
585 		ACPI_TABLE_HEADER	th;
586 
587 		status = AcpiGetTableHeader(ACPI_SIG_DSDT, 0, &th);
588 		if (ACPI_FAILURE(status)) {
589 			device_printf(dev, "Unsupported (Samsung?) laptop\n");
590 			AcpiOsFree(Buf.Pointer);
591 			return (ENXIO);
592 		}
593 
594 		if (strncmp("ODEM", th.OemTableId, 4) == 0) {
595 			sc->model = &acpi_samsung_models[0];
596 			device_set_desc(dev, "Samsung P30 Laptop Extras");
597 			AcpiOsFree(Buf.Pointer);
598 			return (0);
599 		}
600 
601 		/* EeePC */
602 		if (strncmp("ASUS010", rstr, 7) == 0) {
603 			sc->model = &acpi_eeepc_models[0];
604 			device_set_desc(dev, "ASUS EeePC");
605 			AcpiOsFree(Buf.Pointer);
606 			return (0);
607 		}
608 	}
609 
610 	sb = sbuf_new_auto();
611 	if (sb == NULL)
612 		return (ENOMEM);
613 
614 	/*
615 	 * Asus laptops are simply identified by name, easy!
616 	 */
617 	for (model = acpi_asus_models; model->name != NULL; model++) {
618 		if (strncmp(Obj->String.Pointer, model->name, 3) == 0) {
619 
620 good:
621 			sbuf_printf(sb, "Asus %s Laptop Extras",
622 			    Obj->String.Pointer);
623 			sbuf_finish(sb);
624 
625 			sc->model = model;
626 			device_set_desc_copy(dev, sbuf_data(sb));
627 
628 			sbuf_delete(sb);
629 			AcpiOsFree(Buf.Pointer);
630 			return (0);
631 		}
632 
633 		/*
634 		 * Some models look exactly the same as other models, but have
635 		 * their own ids.  If we spot these, set them up with the same
636 		 * details as the models they're like, possibly dealing with
637 		 * small differences.
638 		 *
639 		 * XXX: there must be a prettier way to do this!
640 		 */
641 		else if (strncmp(model->name, "xxN", 3) == 0 &&
642 		    (strncmp(Obj->String.Pointer, "M3N", 3) == 0 ||
643 		     strncmp(Obj->String.Pointer, "S1N", 3) == 0))
644 			goto good;
645 		else if (strncmp(model->name, "A1x", 3) == 0 &&
646 		    strncmp(Obj->String.Pointer, "A1", 2) == 0)
647 			goto good;
648 		else if (strncmp(model->name, "A2x", 3) == 0 &&
649 		    strncmp(Obj->String.Pointer, "A2", 2) == 0)
650 			goto good;
651 		else if (strncmp(model->name, "A3F", 3) == 0 &&
652 		    strncmp(Obj->String.Pointer, "A6F", 3) == 0)
653 			goto good;
654 		else if (strncmp(model->name, "D1x", 3) == 0 &&
655 		    strncmp(Obj->String.Pointer, "D1", 2) == 0)
656 			goto good;
657 		else if (strncmp(model->name, "L3H", 3) == 0 &&
658 		    strncmp(Obj->String.Pointer, "L2E", 3) == 0)
659 			goto good;
660 		else if (strncmp(model->name, "L5x", 3) == 0 &&
661 		    strncmp(Obj->String.Pointer, "L5", 2) == 0)
662 			goto good;
663 		else if (strncmp(model->name, "M2E", 3) == 0 &&
664 		    (strncmp(Obj->String.Pointer, "M2", 2) == 0 ||
665 		     strncmp(Obj->String.Pointer, "L4E", 3) == 0))
666 			goto good;
667 		else if (strncmp(model->name, "S1x", 3) == 0 &&
668 		    (strncmp(Obj->String.Pointer, "L8", 2) == 0 ||
669 		     strncmp(Obj->String.Pointer, "S1", 2) == 0))
670 			goto good;
671 		else if (strncmp(model->name, "S2x", 3) == 0 &&
672 		    (strncmp(Obj->String.Pointer, "J1", 2) == 0 ||
673 		     strncmp(Obj->String.Pointer, "S2", 2) == 0))
674 			goto good;
675 
676 		/* L2B is like L3C but has no lcd_get method */
677 		else if (strncmp(model->name, "L3C", 3) == 0 &&
678 		    strncmp(Obj->String.Pointer, "L2B", 3) == 0) {
679 			model->lcd_get = NULL;
680 			goto good;
681 		}
682 
683 		/* A3G is like M6R but with a different lcd_get method */
684 		else if (strncmp(model->name, "M6R", 3) == 0 &&
685 		    strncmp(Obj->String.Pointer, "A3G", 3) == 0) {
686 			model->lcd_get = "\\BLFG";
687 			goto good;
688 		}
689 
690 		/* M2N and W1N are like xxN with added WLED */
691 		else if (strncmp(model->name, "xxN", 3) == 0 &&
692 		    (strncmp(Obj->String.Pointer, "M2N", 3) == 0 ||
693 		     strncmp(Obj->String.Pointer, "W1N", 3) == 0)) {
694 			model->wled_set = "WLED";
695 			goto good;
696 		}
697 
698 		/* M5N and S5N are like xxN without MLED */
699 		else if (strncmp(model->name, "xxN", 3) == 0 &&
700 		    (strncmp(Obj->String.Pointer, "M5N", 3) == 0 ||
701 		     strncmp(Obj->String.Pointer, "S5N", 3) == 0)) {
702 			model->mled_set = NULL;
703 			goto good;
704 		}
705 	}
706 
707 	sbuf_printf(sb, "Unsupported Asus laptop: %s\n", Obj->String.Pointer);
708 	sbuf_finish(sb);
709 
710 	device_printf(dev, "%s", sbuf_data(sb));
711 
712 	sbuf_delete(sb);
713 	AcpiOsFree(Buf.Pointer);
714 
715 	return (ENXIO);
716 }
717 
718 static int
719 acpi_asus_attach(device_t dev)
720 {
721 	struct acpi_asus_softc	*sc;
722 	struct acpi_softc	*acpi_sc;
723 
724 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
725 
726 	sc = device_get_softc(dev);
727 	acpi_sc = acpi_device_get_parent_softc(dev);
728 
729 	/* Build sysctl tree */
730 	sysctl_ctx_init(&sc->sysctl_ctx);
731 	sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
732 	    SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
733 	    OID_AUTO, "asus", CTLFLAG_RD, 0, "");
734 
735 	/* Hook up nodes */
736 	for (int i = 0; acpi_asus_sysctls[i].name != NULL; i++) {
737 		if (!acpi_asus_sysctl_init(sc, acpi_asus_sysctls[i].method))
738 			continue;
739 
740 		if (acpi_asus_sysctls[i].flag_anybody != 0) {
741 			SYSCTL_ADD_PROC(&sc->sysctl_ctx,
742 			    SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
743 			    acpi_asus_sysctls[i].name,
744 			    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
745 			    sc, i, acpi_asus_sysctl, "I",
746 			    acpi_asus_sysctls[i].description);
747 		} else {
748 			SYSCTL_ADD_PROC(&sc->sysctl_ctx,
749 			    SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
750 			    acpi_asus_sysctls[i].name,
751 			    CTLTYPE_INT | CTLFLAG_RW,
752 			    sc, i, acpi_asus_sysctl, "I",
753 			    acpi_asus_sysctls[i].description);
754 		}
755 	}
756 
757 	/* Attach leds */
758 	if (sc->model->bled_set) {
759 		sc->s_bled.busy = 0;
760 		sc->s_bled.sc = sc;
761 		sc->s_bled.type = ACPI_ASUS_LED_BLED;
762 		sc->s_bled.cdev =
763 		    led_create_state((led_t *)acpi_asus_led, &sc->s_bled,
764 			"bled", 1);
765 	}
766 
767 	if (sc->model->dled_set) {
768 		sc->s_dled.busy = 0;
769 		sc->s_dled.sc = sc;
770 		sc->s_dled.type = ACPI_ASUS_LED_DLED;
771 		sc->s_dled.cdev =
772 		    led_create((led_t *)acpi_asus_led, &sc->s_dled, "dled");
773 	}
774 
775 	if (sc->model->gled_set) {
776 		sc->s_gled.busy = 0;
777 		sc->s_gled.sc = sc;
778 		sc->s_gled.type = ACPI_ASUS_LED_GLED;
779 		sc->s_gled.cdev =
780 		    led_create((led_t *)acpi_asus_led, &sc->s_gled, "gled");
781 	}
782 
783 	if (sc->model->mled_set) {
784 		sc->s_mled.busy = 0;
785 		sc->s_mled.sc = sc;
786 		sc->s_mled.type = ACPI_ASUS_LED_MLED;
787 		sc->s_mled.cdev =
788 		    led_create((led_t *)acpi_asus_led, &sc->s_mled, "mled");
789 	}
790 
791 	if (sc->model->tled_set) {
792 		sc->s_tled.busy = 0;
793 		sc->s_tled.sc = sc;
794 		sc->s_tled.type = ACPI_ASUS_LED_TLED;
795 		sc->s_tled.cdev =
796 		    led_create_state((led_t *)acpi_asus_led, &sc->s_tled,
797 			"tled", 1);
798 	}
799 
800 	if (sc->model->wled_set) {
801 		sc->s_wled.busy = 0;
802 		sc->s_wled.sc = sc;
803 		sc->s_wled.type = ACPI_ASUS_LED_WLED;
804 		sc->s_wled.cdev =
805 		    led_create_state((led_t *)acpi_asus_led, &sc->s_wled,
806 			"wled", 1);
807 	}
808 
809 	/* Activate hotkeys */
810 	AcpiEvaluateObject(sc->handle, "BSTS", NULL, NULL);
811 
812 	/* Handle notifies */
813 	if (sc->model->n_func == NULL)
814 		sc->model->n_func = acpi_asus_notify;
815 
816 	AcpiInstallNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
817 	    sc->model->n_func, dev);
818 
819 	/* Find and hook the 'LCDD' object */
820 	if (sc->model->lcdd != NULL && sc->model->lcdd_n_func != NULL) {
821 		ACPI_STATUS res;
822 
823 		sc->lcdd_handle = NULL;
824 		res = AcpiGetHandle((sc->model->lcdd[0] == '\\' ?
825 		    NULL : sc->handle), sc->model->lcdd, &(sc->lcdd_handle));
826 		if (ACPI_SUCCESS(res)) {
827 			AcpiInstallNotifyHandler((sc->lcdd_handle),
828 			    ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func, dev);
829 	    	} else {
830 	    		printf("%s: unable to find LCD device '%s'\n",
831 	    		    __func__, sc->model->lcdd);
832 	    	}
833 	}
834 
835 	return (0);
836 }
837 
838 static int
839 acpi_asus_detach(device_t dev)
840 {
841 	struct acpi_asus_softc	*sc;
842 
843 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
844 
845 	sc = device_get_softc(dev);
846 
847 	/* Turn the lights off */
848 	if (sc->model->bled_set)
849 		led_destroy(sc->s_bled.cdev);
850 
851 	if (sc->model->dled_set)
852 		led_destroy(sc->s_dled.cdev);
853 
854 	if (sc->model->gled_set)
855 		led_destroy(sc->s_gled.cdev);
856 
857 	if (sc->model->mled_set)
858 		led_destroy(sc->s_mled.cdev);
859 
860 	if (sc->model->tled_set)
861 		led_destroy(sc->s_tled.cdev);
862 
863 	if (sc->model->wled_set)
864 		led_destroy(sc->s_wled.cdev);
865 
866 	/* Remove notify handler */
867 	AcpiRemoveNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
868 	    acpi_asus_notify);
869 
870 	if (sc->lcdd_handle) {
871 		KASSERT(sc->model->lcdd_n_func != NULL,
872 		    ("model->lcdd_n_func is NULL, but lcdd_handle is non-zero"));
873 		AcpiRemoveNotifyHandler((sc->lcdd_handle),
874 		    ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func);
875 	}
876 
877 	/* Free sysctl tree */
878 	sysctl_ctx_free(&sc->sysctl_ctx);
879 
880 	return (0);
881 }
882 
883 static void
884 acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused)
885 {
886 	struct acpi_asus_softc	*sc;
887 	char			*method;
888 	int			state;
889 
890 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
891 
892 	sc = led->sc;
893 
894 	switch (led->type) {
895 	case ACPI_ASUS_LED_BLED:
896 		method = sc->model->bled_set;
897 		state = led->state;
898 		break;
899 	case ACPI_ASUS_LED_DLED:
900 		method = sc->model->dled_set;
901 		state = led->state;
902 		break;
903 	case ACPI_ASUS_LED_GLED:
904 		method = sc->model->gled_set;
905 		state = led->state + 1;	/* 1: off, 2: on */
906 		break;
907 	case ACPI_ASUS_LED_MLED:
908 		method = sc->model->mled_set;
909 		state = !led->state;	/* inverted */
910 		break;
911 	case ACPI_ASUS_LED_TLED:
912 		method = sc->model->tled_set;
913 		state = led->state;
914 		break;
915 	case ACPI_ASUS_LED_WLED:
916 		method = sc->model->wled_set;
917 		state = led->state;
918 		break;
919 	default:
920 		printf("acpi_asus_led: invalid LED type %d\n",
921 		    (int)led->type);
922 		return;
923 	}
924 
925 	acpi_SetInteger(sc->handle, method, state);
926 	led->busy = 0;
927 }
928 
929 static void
930 acpi_asus_led(struct acpi_asus_led *led, int state)
931 {
932 
933 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
934 
935 	if (led->busy)
936 		return;
937 
938 	led->busy = 1;
939 	led->state = state;
940 
941 	AcpiOsExecute(OSL_NOTIFY_HANDLER, (void *)acpi_asus_led_task, led);
942 }
943 
944 static int
945 acpi_asus_sysctl(SYSCTL_HANDLER_ARGS)
946 {
947 	struct acpi_asus_softc	*sc;
948 	int			arg;
949 	int			error = 0;
950 	int			function;
951 	int			method;
952 
953 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
954 
955 	sc = (struct acpi_asus_softc *)oidp->oid_arg1;
956 	function = oidp->oid_arg2;
957 	method = acpi_asus_sysctls[function].method;
958 
959 	ACPI_SERIAL_BEGIN(asus);
960 	arg = acpi_asus_sysctl_get(sc, method);
961 	error = sysctl_handle_int(oidp, &arg, 0, req);
962 
963 	/* Sanity check */
964 	if (error != 0 || req->newptr == NULL)
965 		goto out;
966 
967 	/* Update */
968 	error = acpi_asus_sysctl_set(sc, method, arg);
969 
970 out:
971 	ACPI_SERIAL_END(asus);
972 	return (error);
973 }
974 
975 static int
976 acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method)
977 {
978 	int val = 0;
979 
980 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
981 	ACPI_SERIAL_ASSERT(asus);
982 
983 	switch (method) {
984 	case ACPI_ASUS_METHOD_BRN:
985 		val = sc->s_brn;
986 		break;
987 	case ACPI_ASUS_METHOD_DISP:
988 		val = sc->s_disp;
989 		break;
990 	case ACPI_ASUS_METHOD_LCD:
991 		val = sc->s_lcd;
992 		break;
993 	case ACPI_ASUS_METHOD_CAMERA:
994 		val = sc->s_cam;
995 		break;
996 	case ACPI_ASUS_METHOD_CARDRD:
997 		val = sc->s_crd;
998 		break;
999 	case ACPI_ASUS_METHOD_WLAN:
1000 		val = sc->s_wlan;
1001 		break;
1002 	}
1003 
1004 	return (val);
1005 }
1006 
1007 static int
1008 acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int arg)
1009 {
1010 	ACPI_STATUS		status = AE_OK;
1011 	ACPI_OBJECT_LIST 	acpiargs;
1012 	ACPI_OBJECT		acpiarg[1];
1013 
1014 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1015 	ACPI_SERIAL_ASSERT(asus);
1016 
1017 	acpiargs.Count = 1;
1018 	acpiargs.Pointer = acpiarg;
1019 	acpiarg[0].Type = ACPI_TYPE_INTEGER;
1020 	acpiarg[0].Integer.Value = arg;
1021 
1022 	switch (method) {
1023 	case ACPI_ASUS_METHOD_BRN:
1024 		if (arg < 0 || arg > 15)
1025 			return (EINVAL);
1026 
1027 		if (sc->model->brn_set)
1028 			status = acpi_SetInteger(sc->handle,
1029 			    sc->model->brn_set, arg);
1030 		else {
1031 			while (arg != 0) {
1032 				status = AcpiEvaluateObject(sc->handle,
1033 				    (arg > 0) ?  sc->model->brn_up :
1034 				    sc->model->brn_dn, NULL, NULL);
1035 				(arg > 0) ? arg-- : arg++;
1036 			}
1037 		}
1038 
1039 		if (ACPI_SUCCESS(status))
1040 			sc->s_brn = arg;
1041 
1042 		break;
1043 	case ACPI_ASUS_METHOD_DISP:
1044 		if (arg < 0 || arg > 7)
1045 			return (EINVAL);
1046 
1047 		status = acpi_SetInteger(sc->handle,
1048 		    sc->model->disp_set, arg);
1049 
1050 		if (ACPI_SUCCESS(status))
1051 			sc->s_disp = arg;
1052 
1053 		break;
1054 	case ACPI_ASUS_METHOD_LCD:
1055 		if (arg < 0 || arg > 1)
1056 			return (EINVAL);
1057 
1058 		if (strncmp(sc->model->name, "L3H", 3) != 0)
1059 			status = AcpiEvaluateObject(sc->handle,
1060 			    sc->model->lcd_set, NULL, NULL);
1061 		else
1062 			status = acpi_SetInteger(sc->handle,
1063 			    sc->model->lcd_set, 0x7);
1064 
1065 		if (ACPI_SUCCESS(status))
1066 			sc->s_lcd = arg;
1067 
1068 		break;
1069 	case ACPI_ASUS_METHOD_CAMERA:
1070 		if (arg < 0 || arg > 1)
1071 			return (EINVAL);
1072 
1073 		status = AcpiEvaluateObject(sc->handle,
1074 		    sc->model->cam_set, &acpiargs, NULL);
1075 
1076 		if (ACPI_SUCCESS(status))
1077 			sc->s_cam = arg;
1078 		break;
1079 	case ACPI_ASUS_METHOD_CARDRD:
1080 		if (arg < 0 || arg > 1)
1081 			return (EINVAL);
1082 
1083 		status = AcpiEvaluateObject(sc->handle,
1084 		    sc->model->crd_set, &acpiargs, NULL);
1085 
1086 		if (ACPI_SUCCESS(status))
1087 			sc->s_crd = arg;
1088 		break;
1089 	case ACPI_ASUS_METHOD_WLAN:
1090 		if (arg < 0 || arg > 1)
1091 			return (EINVAL);
1092 
1093 		status = AcpiEvaluateObject(sc->handle,
1094 		    sc->model->wlan_set, &acpiargs, NULL);
1095 
1096 		if (ACPI_SUCCESS(status))
1097 			sc->s_wlan = arg;
1098 		break;
1099 	}
1100 
1101 	return (0);
1102 }
1103 
1104 static int
1105 acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method)
1106 {
1107 	ACPI_STATUS	status;
1108 
1109 	switch (method) {
1110 	case ACPI_ASUS_METHOD_BRN:
1111 		if (sc->model->brn_get) {
1112 			/* GPLV/SPLV models */
1113 			status = acpi_GetInteger(sc->handle,
1114 			    sc->model->brn_get, &sc->s_brn);
1115 			if (ACPI_SUCCESS(status))
1116 				return (TRUE);
1117 		} else if (sc->model->brn_up) {
1118 			/* Relative models */
1119 			status = AcpiEvaluateObject(sc->handle,
1120 			    sc->model->brn_up, NULL, NULL);
1121 			if (ACPI_FAILURE(status))
1122 				return (FALSE);
1123 
1124 			status = AcpiEvaluateObject(sc->handle,
1125 			    sc->model->brn_dn, NULL, NULL);
1126 			if (ACPI_FAILURE(status))
1127 				return (FALSE);
1128 
1129 			return (TRUE);
1130 		}
1131 		return (FALSE);
1132 	case ACPI_ASUS_METHOD_DISP:
1133 		if (sc->model->disp_get) {
1134 			status = acpi_GetInteger(sc->handle,
1135 			    sc->model->disp_get, &sc->s_disp);
1136 			if (ACPI_SUCCESS(status))
1137 				return (TRUE);
1138 		}
1139 		return (FALSE);
1140 	case ACPI_ASUS_METHOD_LCD:
1141 		if (sc->model->lcd_get) {
1142 			if (strncmp(sc->model->name, "L3H", 3) == 0) {
1143 				ACPI_BUFFER		Buf;
1144 				ACPI_OBJECT		Arg[2], Obj;
1145 				ACPI_OBJECT_LIST	Args;
1146 
1147 				/* L3H is a bit special */
1148 				Arg[0].Type = ACPI_TYPE_INTEGER;
1149 				Arg[0].Integer.Value = 0x02;
1150 				Arg[1].Type = ACPI_TYPE_INTEGER;
1151 				Arg[1].Integer.Value = 0x03;
1152 
1153 				Args.Count = 2;
1154 				Args.Pointer = Arg;
1155 
1156 				Buf.Length = sizeof(Obj);
1157 				Buf.Pointer = &Obj;
1158 
1159 				status = AcpiEvaluateObject(sc->handle,
1160 				    sc->model->lcd_get, &Args, &Buf);
1161 				if (ACPI_SUCCESS(status) &&
1162 				    Obj.Type == ACPI_TYPE_INTEGER) {
1163 					sc->s_lcd = Obj.Integer.Value >> 8;
1164 					return (TRUE);
1165 				}
1166 			} else {
1167 				status = acpi_GetInteger(sc->handle,
1168 				    sc->model->lcd_get, &sc->s_lcd);
1169 				if (ACPI_SUCCESS(status))
1170 					return (TRUE);
1171 			}
1172 		}
1173 		return (FALSE);
1174 	case ACPI_ASUS_METHOD_CAMERA:
1175 		if (sc->model->cam_get) {
1176 			status = acpi_GetInteger(sc->handle,
1177 			    sc->model->cam_get, &sc->s_cam);
1178 			if (ACPI_SUCCESS(status))
1179 				return (TRUE);
1180 		}
1181 		return (FALSE);
1182 	case ACPI_ASUS_METHOD_CARDRD:
1183 		if (sc->model->crd_get) {
1184 			status = acpi_GetInteger(sc->handle,
1185 			    sc->model->crd_get, &sc->s_crd);
1186 			if (ACPI_SUCCESS(status))
1187 				return (TRUE);
1188 		}
1189 		return (FALSE);
1190 	case ACPI_ASUS_METHOD_WLAN:
1191 		if (sc->model->wlan_get) {
1192 			status = acpi_GetInteger(sc->handle,
1193 			    sc->model->wlan_get, &sc->s_wlan);
1194 			if (ACPI_SUCCESS(status))
1195 				return (TRUE);
1196 		}
1197 		return (FALSE);
1198 	}
1199 	return (FALSE);
1200 }
1201 
1202 static void
1203 acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context)
1204 {
1205 	struct acpi_asus_softc	*sc;
1206 	struct acpi_softc	*acpi_sc;
1207 
1208 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1209 
1210 	sc = device_get_softc((device_t)context);
1211 	acpi_sc = acpi_device_get_parent_softc(sc->dev);
1212 
1213 	ACPI_SERIAL_BEGIN(asus);
1214 	if ((notify & ~0x10) <= 15) {
1215 		sc->s_brn = notify & ~0x10;
1216 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
1217 	} else if ((notify & ~0x20) <= 15) {
1218 		sc->s_brn = notify & ~0x20;
1219 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
1220 	} else if (notify == 0x33) {
1221 		sc->s_lcd = 1;
1222 		ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned on\n");
1223 	} else if (notify == 0x34) {
1224 		sc->s_lcd = 0;
1225 		ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned off\n");
1226 	} else if (notify == 0x86) {
1227 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1);
1228 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
1229 	} else if (notify == 0x87) {
1230 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1);
1231 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
1232 	} else {
1233 		/* Notify devd(8) */
1234 		acpi_UserNotify("ASUS", h, notify);
1235 	}
1236 	ACPI_SERIAL_END(asus);
1237 }
1238 
1239 static void
1240 acpi_asus_lcdd_notify(ACPI_HANDLE h, UINT32 notify, void *context)
1241 {
1242 	struct acpi_asus_softc	*sc;
1243 	struct acpi_softc	*acpi_sc;
1244 
1245 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1246 
1247 	sc = device_get_softc((device_t)context);
1248 	acpi_sc = acpi_device_get_parent_softc(sc->dev);
1249 
1250 	ACPI_SERIAL_BEGIN(asus);
1251 	switch (notify) {
1252 	case 0x87:
1253 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1);
1254 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
1255 		break;
1256 	case 0x86:
1257 		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1);
1258 		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
1259 		break;
1260 	}
1261 	ACPI_SERIAL_END(asus);
1262 }
1263 
1264 static void
1265 acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context)
1266 {
1267 	struct acpi_asus_softc	*sc;
1268 	struct acpi_softc	*acpi_sc;
1269 
1270 	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1271 
1272 	sc = device_get_softc((device_t)context);
1273 	acpi_sc = acpi_device_get_parent_softc(sc->dev);
1274 
1275 	ACPI_SERIAL_BEGIN(asus);
1276 	if ((notify & ~0x20) <= 15) {
1277 		sc->s_brn = notify & ~0x20;
1278 		ACPI_VPRINT(sc->dev, acpi_sc,
1279 		    "Brightness increased/decreased\n");
1280 	} else {
1281 		/* Notify devd(8) */
1282 		acpi_UserNotify("ASUS-Eee", h, notify);
1283 	}
1284 	ACPI_SERIAL_END(asus);
1285 }
1286