summaryrefslogtreecommitdiffstats
path: root/sys/dev/acpi_support/acpi_asus.c
blob: 51ca6fa354588fa785f7f5fe6b1e6805be5feedf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
/*-
 * Copyright (c) 2004, 2005 Philip Paeps <philip@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

/*
 * Driver for extra ACPI-controlled gadgets (hotkeys, leds, etc) found on
 * recent Asus (and Medion) laptops.  Inspired by the acpi4asus project which
 * implements these features in the Linux kernel.
 *
 *   <http://sourceforge.net/projects/acpi4asus/>
 *
 * Currently should support most features, but could use some more testing.
 * Particularly the display-switching stuff is a bit hairy.  If you have an
 * Asus laptop which doesn't appear to be supported, or strange things happen
 * when using this driver, please report to <acpi@FreeBSD.org>.
 */

#include "opt_acpi.h"
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/sbuf.h>

#include <contrib/dev/acpica/include/acpi.h>
#include <contrib/dev/acpica/include/accommon.h>

#include <dev/acpica/acpivar.h>
#include <dev/led/led.h>

/* Methods */
#define ACPI_ASUS_METHOD_BRN	1
#define ACPI_ASUS_METHOD_DISP	2
#define ACPI_ASUS_METHOD_LCD	3
#define ACPI_ASUS_METHOD_CAMERA	4
#define ACPI_ASUS_METHOD_CARDRD	5
#define ACPI_ASUS_METHOD_WLAN	6

#define _COMPONENT	ACPI_OEM
ACPI_MODULE_NAME("ASUS")

struct acpi_asus_model {
	char	*name;

	char	*bled_set;
	char	*dled_set;
	char	*gled_set;
	char	*mled_set;
	char	*tled_set;
	char	*wled_set;

	char	*brn_get;
	char	*brn_set;
	char	*brn_up;
	char	*brn_dn;

	char	*lcd_get;
	char	*lcd_set;

	char	*disp_get;
	char	*disp_set;

	char	*cam_get;
	char	*cam_set;

	char	*crd_get;
	char	*crd_set;

	char	*wlan_get;
	char	*wlan_set;

	void	(*n_func)(ACPI_HANDLE, UINT32, void *);

	char	*lcdd;
	void	(*lcdd_n_func)(ACPI_HANDLE, UINT32, void *);
};

struct acpi_asus_led {
	struct acpi_asus_softc *sc;
	struct cdev	*cdev;
	int		busy;
	int		state;
	enum {
		ACPI_ASUS_LED_BLED,
		ACPI_ASUS_LED_DLED,
		ACPI_ASUS_LED_GLED,
		ACPI_ASUS_LED_MLED,
		ACPI_ASUS_LED_TLED,
		ACPI_ASUS_LED_WLED,
	} type;
};

struct acpi_asus_softc {
	device_t		dev;
	ACPI_HANDLE		handle;
	ACPI_HANDLE		lcdd_handle;

	struct acpi_asus_model	*model;
	struct sysctl_ctx_list	sysctl_ctx;
	struct sysctl_oid	*sysctl_tree;

	struct acpi_asus_led	s_bled;
	struct acpi_asus_led	s_dled;
	struct acpi_asus_led	s_gled;
	struct acpi_asus_led	s_mled;
	struct acpi_asus_led	s_tled;
	struct acpi_asus_led	s_wled;

	int			s_brn;
	int			s_disp;
	int			s_lcd;
	int			s_cam;
	int			s_crd;
	int			s_wlan;
};

static void	acpi_asus_lcdd_notify(ACPI_HANDLE h, UINT32 notify,
    void *context);

/*
 * We can identify Asus laptops from the string they return
 * as a result of calling the ATK0100 'INIT' method.
 */
static struct acpi_asus_model acpi_asus_models[] = {
	{
		.name		= "xxN",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.lcd_get	= "\\BKLT",
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.disp_get	= "\\ADVG",
		.disp_set	= "SDSP"
	},
	{
		.name		= "A1x",
		.mled_set	= "MLED",
		.lcd_get	= "\\BKLI",
		.lcd_set	= "\\_SB.PCI0.ISA.EC0._Q10",
		.brn_up		= "\\_SB.PCI0.ISA.EC0._Q0E",
		.brn_dn		= "\\_SB.PCI0.ISA.EC0._Q0F"
	},
	{
		.name		= "A2x",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.lcd_get	= "\\BAOF",
		.lcd_set	= "\\Q10",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.disp_get	= "\\INFB",
		.disp_set	= "SDSP"
	},
	{
		.name           = "A3E",
		.mled_set       = "MLED",
		.wled_set       = "WLED",
		.lcd_get        = "\\_SB.PCI0.SBRG.EC0.RPIN(0x67)",
		.lcd_set        = "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get        = "GPLV",
		.brn_set        = "SPLV",
		.disp_get       = "\\_SB.PCI0.P0P2.VGA.GETD",
		.disp_set       = "SDSP"
	},
	{
		.name           = "A3F",
		.mled_set       = "MLED",
		.wled_set       = "WLED",
		.bled_set       = "BLED",
		.lcd_get        = "\\_SB.PCI0.SBRG.EC0.RPIN(0x11)",
		.lcd_set        = "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get        = "GPLV",
		.brn_set        = "SPLV",
		.disp_get       = "\\SSTE",
		.disp_set       = "SDSP"
	},
	{
		.name           = "A3N",
		.mled_set       = "MLED",
		.bled_set       = "BLED",
		.wled_set       = "WLED",
		.lcd_get        = "\\BKLT",
		.lcd_set        = "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get        = "GPLV",
		.brn_set        = "SPLV",
		.disp_get       = "\\_SB.PCI0.P0P3.VGA.GETD",
		.disp_set       = "SDSP"
	},
	{
		.name		= "A4D",
		.mled_set	= "MLED",
		.brn_up		= "\\_SB_.PCI0.SBRG.EC0._Q0E",
		.brn_dn		= "\\_SB_.PCI0.SBRG.EC0._Q0F",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
#ifdef notyet
		.disp_get	= "\\_SB_.PCI0.SBRG.EC0._Q10",
		.disp_set	= "\\_SB_.PCI0.SBRG.EC0._Q11"
#endif
	},
	{
		.name		= "A6V",
		.bled_set	= "BLED",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.lcd_get	= NULL,
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.disp_get	= "\\_SB.PCI0.P0P3.VGA.GETD",
		.disp_set	= "SDSP"
	},
	{
		.name		= "A8SR",
		.bled_set	= "BLED",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.lcd_get	= NULL,
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.disp_get	= "\\_SB.PCI0.P0P1.VGA.GETD",
		.disp_set	= "SDSP",
		.lcdd		= "\\_SB.PCI0.P0P1.VGA.LCDD",
		.lcdd_n_func	= acpi_asus_lcdd_notify
	},
	{
		.name		= "D1x",
		.mled_set	= "MLED",
		.lcd_get	= "\\GP11",
		.lcd_set	= "\\Q0D",
		.brn_up		= "\\Q0C",
		.brn_dn		= "\\Q0B",
		.disp_get	= "\\INFB",
		.disp_set	= "SDSP"
	},
	{
		.name		= "G2K",
		.bled_set	= "BLED",
		.dled_set	= "DLED",
		.gled_set	= "GLED",
		.mled_set	= "MLED",
		.tled_set	= "TLED",
		.wled_set	= "WLED",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.lcd_get	= "\\_SB.PCI0.SBRG.EC0.RPIN",
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.disp_get	= "\\_SB.PCI0.PCE2.VGA.GETD",
		.disp_set	= "SDSP",
	},
	{
		.name		= "L2D",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.brn_up		= "\\Q0E",
		.brn_dn		= "\\Q0F",
		.lcd_get	= "\\SGP0",
		.lcd_set	= "\\Q10"
	},
	{
		.name		= "L3C",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.lcd_get	= "\\GL32",
		.lcd_set	= "\\_SB.PCI0.PX40.ECD0._Q10"
	},
	{
		.name		= "L3D",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.lcd_get	= "\\BKLG",
		.lcd_set	= "\\Q10"
	},
	{
		.name		= "L3H",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.lcd_get	= "\\_SB.PCI0.PM.PBC",
		.lcd_set	= "EHK",
		.disp_get	= "\\_SB.INFB",
		.disp_set	= "SDSP"
	},
	{
		.name		= "L4R",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.lcd_get	= "\\_SB.PCI0.SBSM.SEO4",
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.disp_get	= "\\_SB.PCI0.P0P1.VGA.GETD",
		.disp_set	= "SDSP"
	},
	{
		.name		= "L5x",
		.mled_set	= "MLED",
		.tled_set	= "TLED",
		.lcd_get	= "\\BAOF",
		.lcd_set	= "\\Q0D",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.disp_get	= "\\INFB",
		.disp_set	= "SDSP"
	},
	{
		.name		= "L8L"
		/* Only has hotkeys, apparently */
	},
	{
		.name		= "M1A",
		.mled_set	= "MLED",
		.brn_up		= "\\_SB.PCI0.PX40.EC0.Q0E",
		.brn_dn		= "\\_SB.PCI0.PX40.EC0.Q0F",
		.lcd_get	= "\\PNOF",
		.lcd_set	= "\\_SB.PCI0.PX40.EC0.Q10"
	},
	{
		.name		= "M2E",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.lcd_get	= "\\GP06",
		.lcd_set	= "\\Q10"
	},
	{
		.name		= "M6N",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.lcd_get	= "\\_SB.BKLT",
		.brn_set	= "SPLV",
		.brn_get	= "GPLV",
		.disp_set	= "SDSP",
		.disp_get	= "\\SSTE"
	},
	{
		.name		= "M6R",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.lcd_get	= "\\_SB.PCI0.SBSM.SEO4",
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.disp_get	= "\\SSTE",
		.disp_set	= "SDSP"
	},
	{
		.name		= "S1x",
		.mled_set	= "MLED",
		.wled_set	= "WLED",
		.lcd_get	= "\\PNOF",
		.lcd_set	= "\\_SB.PCI0.PX40.Q10",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV"
	},
	{
		.name		= "S2x",
		.mled_set	= "MLED",
		.lcd_get	= "\\BKLI",
		.lcd_set	= "\\_SB.PCI0.ISA.EC0._Q10",
		.brn_up		= "\\_SB.PCI0.ISA.EC0._Q0B",
		.brn_dn		= "\\_SB.PCI0.ISA.EC0._Q0A"
	},
	{
		.name		= "V6V",
		.bled_set	= "BLED",
		.tled_set	= "TLED",
		.wled_set	= "WLED",
		.lcd_get	= "\\BKLT",
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.disp_get	= "\\_SB.PCI0.P0P1.VGA.GETD",
		.disp_set	= "SDSP"
	},
	{
		.name		= "W5A",
		.bled_set	= "BLED",
		.lcd_get	= "\\BKLT",
		.lcd_set	= "\\_SB.PCI0.SBRG.EC0._Q10",
		.brn_get	= "GPLV",
		.brn_set	= "SPLV",
		.disp_get	= "\\_SB.PCI0.P0P2.VGA.GETD",
		.disp_set	= "SDSP"
	},

	{ .name = NULL }
};

/*
 * Samsung P30/P35 laptops have an Asus ATK0100 gadget interface,
 * but they can't be probed quite the same way as Asus laptops.
 */
static struct acpi_asus_model acpi_samsung_models[] = {
	{
		.name		= "P30",
		.wled_set	= "WLED",
		.brn_up		= "\\_SB.PCI0.LPCB.EC0._Q68",
		.brn_dn		= "\\_SB.PCI0.LPCB.EC0._Q69",
		.lcd_get	= "\\BKLT",
		.lcd_set	= "\\_SB.PCI0.LPCB.EC0._Q0E"
	},

	{ .name = NULL }
};

static void	acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context);

/*
 * EeePC have an Asus ASUS010 gadget interface,
 * but they can't be probed quite the same way as Asus laptops.
 */
static struct acpi_asus_model acpi_eeepc_models[] = {
	{
		.name		= "EEE",
		.brn_get	= "\\_SB.ATKD.PBLG",
		.brn_set	= "\\_SB.ATKD.PBLS",
		.cam_get	= "\\_SB.ATKD.CAMG",
		.cam_set	= "\\_SB.ATKD.CAMS",
		.crd_set	= "\\_SB.ATKD.CRDS",
		.crd_get	= "\\_SB.ATKD.CRDG",
		.wlan_get	= "\\_SB.ATKD.WLDG",
		.wlan_set	= "\\_SB.ATKD.WLDS",
		.n_func		= acpi_asus_eeepc_notify
	},

	{ .name = NULL }
};

static struct {
	char	*name;
	char	*description;
	int	method;
	int	flags;
} acpi_asus_sysctls[] = {
	{
		.name		= "lcd_backlight",
		.method		= ACPI_ASUS_METHOD_LCD,
		.description	= "state of the lcd backlight",
		.flags 		= CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY
	},
	{
		.name		= "lcd_brightness",
		.method		= ACPI_ASUS_METHOD_BRN,
		.description	= "brightness of the lcd panel",
		.flags 		= CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY
	},
	{
		.name		= "video_output",
		.method		= ACPI_ASUS_METHOD_DISP,
		.description	= "display output state",
		.flags 		= CTLTYPE_INT | CTLFLAG_RW
	},
	{
		.name		= "camera",
		.method		= ACPI_ASUS_METHOD_CAMERA,
		.description	= "internal camera state",  
		.flags 		= CTLTYPE_INT | CTLFLAG_RW
	},
	{
		.name		= "cardreader",
		.method		= ACPI_ASUS_METHOD_CARDRD,
		.description	= "internal card reader state",
		.flags 		= CTLTYPE_INT | CTLFLAG_RW
	},
	{
		.name		= "wlan",
		.method		= ACPI_ASUS_METHOD_WLAN,
		.description	= "wireless lan state",
		.flags		= CTLTYPE_INT | CTLFLAG_RW
	},

	{ .name = NULL }
};

ACPI_SERIAL_DECL(asus, "ACPI ASUS extras");

/* Function prototypes */
static int	acpi_asus_probe(device_t dev);
static int	acpi_asus_attach(device_t dev);
static int	acpi_asus_detach(device_t dev);

static void	acpi_asus_led(struct acpi_asus_led *led, int state);
static void	acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused);

static int	acpi_asus_sysctl(SYSCTL_HANDLER_ARGS);
static int	acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method);
static int	acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method);
static int	acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int val);

static void	acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context);

static device_method_t acpi_asus_methods[] = {
	DEVMETHOD(device_probe,  acpi_asus_probe),
	DEVMETHOD(device_attach, acpi_asus_attach),
	DEVMETHOD(device_detach, acpi_asus_detach),

	{ 0, 0 }
};

static driver_t acpi_asus_driver = {
	"acpi_asus",
	acpi_asus_methods,
	sizeof(struct acpi_asus_softc)
};

static devclass_t acpi_asus_devclass;

DRIVER_MODULE(acpi_asus, acpi, acpi_asus_driver, acpi_asus_devclass, 0, 0);
MODULE_DEPEND(acpi_asus, acpi, 1, 1, 1);

static int
acpi_asus_probe(device_t dev)
{
	struct acpi_asus_model	*model;
	struct acpi_asus_softc	*sc;
	struct sbuf		*sb;
	ACPI_BUFFER		Buf;
	ACPI_OBJECT		Arg, *Obj;
	ACPI_OBJECT_LIST	Args;
	static char		*asus_ids[] = { "ATK0100", "ASUS010", NULL };
	char *rstr;

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	if (acpi_disabled("asus"))
		return (ENXIO);
	rstr = ACPI_ID_PROBE(device_get_parent(dev), dev, asus_ids);
	if (rstr == NULL) {
		return (ENXIO);
	}

	sc = device_get_softc(dev);
	sc->dev = dev;
	sc->handle = acpi_get_handle(dev);

	Arg.Type = ACPI_TYPE_INTEGER;
	Arg.Integer.Value = 0;

	Args.Count = 1;
	Args.Pointer = &Arg;

	Buf.Pointer = NULL;
	Buf.Length = ACPI_ALLOCATE_BUFFER;

	AcpiEvaluateObject(sc->handle, "INIT", &Args, &Buf);
	Obj = Buf.Pointer;

	/*
	 * The Samsung P30 returns a null-pointer from INIT, we
	 * can identify it from the 'ODEM' string in the DSDT.
	 */
	if (Obj->String.Pointer == NULL) {
		ACPI_STATUS		status;
		ACPI_TABLE_HEADER	th;

		status = AcpiGetTableHeader(ACPI_SIG_DSDT, 0, &th);
		if (ACPI_FAILURE(status)) {
			device_printf(dev, "Unsupported (Samsung?) laptop\n");
			AcpiOsFree(Buf.Pointer);
			return (ENXIO);
		}

		if (strncmp("ODEM", th.OemTableId, 4) == 0) {
			sc->model = &acpi_samsung_models[0];
			device_set_desc(dev, "Samsung P30 Laptop Extras");
			AcpiOsFree(Buf.Pointer);
			return (0);
		}

		/* EeePC */
		if (strncmp("ASUS010", rstr, 7) == 0) {
			sc->model = &acpi_eeepc_models[0];
			device_set_desc(dev, "ASUS EeePC");
			AcpiOsFree(Buf.Pointer);
			return (0);
		}
	}

	sb = sbuf_new_auto();
	if (sb == NULL)
		return (ENOMEM);

	/*
	 * Asus laptops are simply identified by name, easy!
	 */
	for (model = acpi_asus_models; model->name != NULL; model++) {
		if (strncmp(Obj->String.Pointer, model->name, 3) == 0) {

good:
			sbuf_printf(sb, "Asus %s Laptop Extras",
			    Obj->String.Pointer);
			sbuf_finish(sb);

			sc->model = model;
			device_set_desc_copy(dev, sbuf_data(sb));

			sbuf_delete(sb);
			AcpiOsFree(Buf.Pointer);
			return (0);
		}
		
		/*
		 * Some models look exactly the same as other models, but have
		 * their own ids.  If we spot these, set them up with the same
		 * details as the models they're like, possibly dealing with
		 * small differences.
		 *
		 * XXX: there must be a prettier way to do this!
		 */
		else if (strncmp(model->name, "xxN", 3) == 0 &&
		    (strncmp(Obj->String.Pointer, "M3N", 3) == 0 ||
		     strncmp(Obj->String.Pointer, "S1N", 3) == 0))
			goto good;
		else if (strncmp(model->name, "A1x", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "A1", 2) == 0)
			goto good;
		else if (strncmp(model->name, "A2x", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "A2", 2) == 0)
			goto good;
		else if (strncmp(model->name, "A3F", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "A6F", 3) == 0)
			goto good;
		else if (strncmp(model->name, "D1x", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "D1", 2) == 0)
			goto good;
		else if (strncmp(model->name, "L3H", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "L2E", 3) == 0)
			goto good;
		else if (strncmp(model->name, "L5x", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "L5", 2) == 0)
			goto good;
		else if (strncmp(model->name, "M2E", 3) == 0 &&
		    (strncmp(Obj->String.Pointer, "M2", 2) == 0 ||
		     strncmp(Obj->String.Pointer, "L4E", 3) == 0))
			goto good;
		else if (strncmp(model->name, "S1x", 3) == 0 &&
		    (strncmp(Obj->String.Pointer, "L8", 2) == 0 ||
		     strncmp(Obj->String.Pointer, "S1", 2) == 0))
			goto good;
		else if (strncmp(model->name, "S2x", 3) == 0 &&
		    (strncmp(Obj->String.Pointer, "J1", 2) == 0 ||
		     strncmp(Obj->String.Pointer, "S2", 2) == 0))
			goto good;

		/* L2B is like L3C but has no lcd_get method */
		else if (strncmp(model->name, "L3C", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "L2B", 3) == 0) {
			model->lcd_get = NULL;
			goto good;
		}

		/* A3G is like M6R but with a different lcd_get method */
		else if (strncmp(model->name, "M6R", 3) == 0 &&
		    strncmp(Obj->String.Pointer, "A3G", 3) == 0) {
			model->lcd_get = "\\BLFG";
			goto good;
		}

		/* M2N and W1N are like xxN with added WLED */
		else if (strncmp(model->name, "xxN", 3) == 0 &&
		    (strncmp(Obj->String.Pointer, "M2N", 3) == 0 ||
		     strncmp(Obj->String.Pointer, "W1N", 3) == 0)) {
			model->wled_set = "WLED";
			goto good;
		}

		/* M5N and S5N are like xxN without MLED */
		else if (strncmp(model->name, "xxN", 3) == 0 &&
		    (strncmp(Obj->String.Pointer, "M5N", 3) == 0 ||
		     strncmp(Obj->String.Pointer, "S5N", 3) == 0)) {
			model->mled_set = NULL;
			goto good;
		}
	}

	sbuf_printf(sb, "Unsupported Asus laptop: %s\n", Obj->String.Pointer);
	sbuf_finish(sb);

	device_printf(dev, sbuf_data(sb));

	sbuf_delete(sb);
	AcpiOsFree(Buf.Pointer);

	return (ENXIO);
}

static int
acpi_asus_attach(device_t dev)
{
	struct acpi_asus_softc	*sc;
	struct acpi_softc	*acpi_sc;

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	sc = device_get_softc(dev);
	acpi_sc = acpi_device_get_parent_softc(dev);

	/* Build sysctl tree */
	sysctl_ctx_init(&sc->sysctl_ctx);
	sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
	    SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
	    OID_AUTO, "asus", CTLFLAG_RD, 0, "");

	/* Hook up nodes */
	for (int i = 0; acpi_asus_sysctls[i].name != NULL; i++) {
		if (!acpi_asus_sysctl_init(sc, acpi_asus_sysctls[i].method))
			continue;

		SYSCTL_ADD_PROC(&sc->sysctl_ctx,
		    SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
		    acpi_asus_sysctls[i].name,
		    acpi_asus_sysctls[i].flags,
		    sc, i, acpi_asus_sysctl, "I",
		    acpi_asus_sysctls[i].description);
	}

	/* Attach leds */
	if (sc->model->bled_set) {
		sc->s_bled.busy = 0;
		sc->s_bled.sc = sc;
		sc->s_bled.type = ACPI_ASUS_LED_BLED;
		sc->s_bled.cdev =
		    led_create_state((led_t *)acpi_asus_led, &sc->s_bled,
			"bled", 1);
	}

	if (sc->model->dled_set) {
		sc->s_dled.busy = 0;
		sc->s_dled.sc = sc;
		sc->s_dled.type = ACPI_ASUS_LED_DLED;
		sc->s_dled.cdev =
		    led_create((led_t *)acpi_asus_led, &sc->s_dled, "dled");
	}

	if (sc->model->gled_set) {
		sc->s_gled.busy = 0;
		sc->s_gled.sc = sc;
		sc->s_gled.type = ACPI_ASUS_LED_GLED;
		sc->s_gled.cdev =
		    led_create((led_t *)acpi_asus_led, &sc->s_gled, "gled");
	}

	if (sc->model->mled_set) {
		sc->s_mled.busy = 0;
		sc->s_mled.sc = sc;
		sc->s_mled.type = ACPI_ASUS_LED_MLED;
		sc->s_mled.cdev =
		    led_create((led_t *)acpi_asus_led, &sc->s_mled, "mled");
	}

	if (sc->model->tled_set) {
		sc->s_tled.busy = 0;
		sc->s_tled.sc = sc;
		sc->s_tled.type = ACPI_ASUS_LED_TLED;
		sc->s_tled.cdev =
		    led_create_state((led_t *)acpi_asus_led, &sc->s_tled,
			"tled", 1);
	}

	if (sc->model->wled_set) {
		sc->s_wled.busy = 0;
		sc->s_wled.sc = sc;
		sc->s_wled.type = ACPI_ASUS_LED_WLED;
		sc->s_wled.cdev =
		    led_create_state((led_t *)acpi_asus_led, &sc->s_wled,
			"wled", 1);
	}

	/* Activate hotkeys */
	AcpiEvaluateObject(sc->handle, "BSTS", NULL, NULL);

	/* Handle notifies */
	if (sc->model->n_func == NULL)
		sc->model->n_func = acpi_asus_notify;

	AcpiInstallNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
	    sc->model->n_func, dev);

	/* Find and hook the 'LCDD' object */
	if (sc->model->lcdd != NULL && sc->model->lcdd_n_func != NULL) {
		ACPI_STATUS res;

		sc->lcdd_handle = NULL;
		res = AcpiGetHandle((sc->model->lcdd[0] == '\\' ?
		    NULL : sc->handle), sc->model->lcdd, &(sc->lcdd_handle));
		if (ACPI_SUCCESS(res)) {
			AcpiInstallNotifyHandler((sc->lcdd_handle),
			    ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func, dev);
	    	} else {
	    		printf("%s: unable to find LCD device '%s'\n",
	    		    __func__, sc->model->lcdd);
	    	}
	}

	return (0);
}

static int
acpi_asus_detach(device_t dev)
{
	struct acpi_asus_softc	*sc;

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	sc = device_get_softc(dev);

	/* Turn the lights off */
	if (sc->model->bled_set)
		led_destroy(sc->s_bled.cdev);

	if (sc->model->dled_set)
		led_destroy(sc->s_dled.cdev);

	if (sc->model->gled_set)
		led_destroy(sc->s_gled.cdev);

	if (sc->model->mled_set)
		led_destroy(sc->s_mled.cdev);

	if (sc->model->tled_set)
		led_destroy(sc->s_tled.cdev);

	if (sc->model->wled_set)
		led_destroy(sc->s_wled.cdev);

	/* Remove notify handler */
	AcpiRemoveNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
	    acpi_asus_notify);
	
	if (sc->lcdd_handle) {
		KASSERT(sc->model->lcdd_n_func != NULL,
		    ("model->lcdd_n_func is NULL, but lcdd_handle is non-zero"));
		AcpiRemoveNotifyHandler((sc->lcdd_handle),
		    ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func);
	}

	/* Free sysctl tree */
	sysctl_ctx_free(&sc->sysctl_ctx);

	return (0);
}

static void
acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused)
{
	struct acpi_asus_softc	*sc;
	char			*method;
	int			state;
	
	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	sc = led->sc;

	switch (led->type) {
	case ACPI_ASUS_LED_BLED:
		method = sc->model->bled_set;
		state = led->state;
		break;
	case ACPI_ASUS_LED_DLED:
		method = sc->model->dled_set;
		state = led->state;
		break;
	case ACPI_ASUS_LED_GLED:
		method = sc->model->gled_set;
		state = led->state + 1;	/* 1: off, 2: on */
		break;
	case ACPI_ASUS_LED_MLED:
		method = sc->model->mled_set;
		state = !led->state;	/* inverted */
		break;
	case ACPI_ASUS_LED_TLED:
		method = sc->model->tled_set;
		state = led->state;
		break;
	case ACPI_ASUS_LED_WLED:
		method = sc->model->wled_set;
		state = led->state;
		break;
	default:
		printf("acpi_asus_led: invalid LED type %d\n",
		    (int)led->type);
		return;
	}

	acpi_SetInteger(sc->handle, method, state);
	led->busy = 0;
}
	
static void
acpi_asus_led(struct acpi_asus_led *led, int state)
{

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	if (led->busy)
		return;

	led->busy = 1;
	led->state = state;

	AcpiOsExecute(OSL_NOTIFY_HANDLER, (void *)acpi_asus_led_task, led);
}

static int
acpi_asus_sysctl(SYSCTL_HANDLER_ARGS)
{
	struct acpi_asus_softc	*sc;
	int			arg;
	int			error = 0;
	int			function;
	int			method;
	
	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	sc = (struct acpi_asus_softc *)oidp->oid_arg1;
	function = oidp->oid_arg2;
	method = acpi_asus_sysctls[function].method;

	ACPI_SERIAL_BEGIN(asus);
	arg = acpi_asus_sysctl_get(sc, method);
	error = sysctl_handle_int(oidp, &arg, 0, req);

	/* Sanity check */
	if (error != 0 || req->newptr == NULL)
		goto out;

	/* Update */
	error = acpi_asus_sysctl_set(sc, method, arg);

out:
	ACPI_SERIAL_END(asus);
	return (error);
}

static int
acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method)
{
	int val = 0;

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
	ACPI_SERIAL_ASSERT(asus);

	switch (method) {
	case ACPI_ASUS_METHOD_BRN:
		val = sc->s_brn;
		break;
	case ACPI_ASUS_METHOD_DISP:
		val = sc->s_disp;
		break;
	case ACPI_ASUS_METHOD_LCD:
		val = sc->s_lcd;
		break;
	case ACPI_ASUS_METHOD_CAMERA:
		val = sc->s_cam;
		break;
	case ACPI_ASUS_METHOD_CARDRD:
		val = sc->s_crd;
		break;
	case ACPI_ASUS_METHOD_WLAN:
		val = sc->s_wlan;
		break;
	}

	return (val);
}

static int
acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int arg)
{
	ACPI_STATUS		status = AE_OK;
	ACPI_OBJECT_LIST 	acpiargs;
	ACPI_OBJECT		acpiarg[1];

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
	ACPI_SERIAL_ASSERT(asus);

	acpiargs.Count = 1;
	acpiargs.Pointer = acpiarg;
	acpiarg[0].Type = ACPI_TYPE_INTEGER;
	acpiarg[0].Integer.Value = arg;

	switch (method) {
	case ACPI_ASUS_METHOD_BRN:
		if (arg < 0 || arg > 15)
			return (EINVAL);

		if (sc->model->brn_set)
			status = acpi_SetInteger(sc->handle,
			    sc->model->brn_set, arg);
		else {
			while (arg != 0) {
				status = AcpiEvaluateObject(sc->handle,
				    (arg > 0) ?  sc->model->brn_up :
				    sc->model->brn_dn, NULL, NULL);
				(arg > 0) ? arg-- : arg++;
			}
		}

		if (ACPI_SUCCESS(status))
			sc->s_brn = arg;

		break;
	case ACPI_ASUS_METHOD_DISP:
		if (arg < 0 || arg > 7)
			return (EINVAL);

		status = acpi_SetInteger(sc->handle,
		    sc->model->disp_set, arg);

		if (ACPI_SUCCESS(status))
			sc->s_disp = arg;

		break;
	case ACPI_ASUS_METHOD_LCD:
		if (arg < 0 || arg > 1)
			return (EINVAL);

		if (strncmp(sc->model->name, "L3H", 3) != 0)
			status = AcpiEvaluateObject(sc->handle,
			    sc->model->lcd_set, NULL, NULL);
		else
			status = acpi_SetInteger(sc->handle,
			    sc->model->lcd_set, 0x7);

		if (ACPI_SUCCESS(status))
			sc->s_lcd = arg;

		break;
	case ACPI_ASUS_METHOD_CAMERA:
		if (arg < 0 || arg > 1)
			return (EINVAL);

		status = AcpiEvaluateObject(sc->handle,
		    sc->model->cam_set, &acpiargs, NULL);

		if (ACPI_SUCCESS(status))
			sc->s_cam = arg;
		break;
	case ACPI_ASUS_METHOD_CARDRD:
		if (arg < 0 || arg > 1)
			return (EINVAL);

		status = AcpiEvaluateObject(sc->handle,
		    sc->model->crd_set, &acpiargs, NULL);

		if (ACPI_SUCCESS(status))
			sc->s_crd = arg;
		break;
	case ACPI_ASUS_METHOD_WLAN:
		if (arg < 0 || arg > 1)
			return (EINVAL);

		status = AcpiEvaluateObject(sc->handle,
		    sc->model->wlan_set, &acpiargs, NULL);

		if (ACPI_SUCCESS(status))
			sc->s_wlan = arg;
		break;
	}

	return (0);
}

static int
acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method)
{
	ACPI_STATUS	status;

	switch (method) {
	case ACPI_ASUS_METHOD_BRN:
		if (sc->model->brn_get) {
			/* GPLV/SPLV models */
			status = acpi_GetInteger(sc->handle,
			    sc->model->brn_get, &sc->s_brn);
			if (ACPI_SUCCESS(status))
				return (TRUE);
		} else if (sc->model->brn_up) {
			/* Relative models */
			status = AcpiEvaluateObject(sc->handle,
			    sc->model->brn_up, NULL, NULL);
			if (ACPI_FAILURE(status))
				return (FALSE);

			status = AcpiEvaluateObject(sc->handle,
			    sc->model->brn_dn, NULL, NULL);
			if (ACPI_FAILURE(status))
				return (FALSE);

			return (TRUE);
		}
		return (FALSE);
	case ACPI_ASUS_METHOD_DISP:
		if (sc->model->disp_get) {
			status = acpi_GetInteger(sc->handle,
			    sc->model->disp_get, &sc->s_disp);
			if (ACPI_SUCCESS(status))
				return (TRUE);
		}
		return (FALSE);
	case ACPI_ASUS_METHOD_LCD:
		if (sc->model->lcd_get) {
			if (strncmp(sc->model->name, "G2K", 3) == 0) {
				ACPI_BUFFER		Buf;
				ACPI_OBJECT		Arg, Obj;
				ACPI_OBJECT_LIST	Args;

				Arg.Type = ACPI_TYPE_INTEGER;
				Arg.Integer.Value = 0x11;
				Args.Count = 1;
				Args.Pointer = &Arg;
				Buf.Length = sizeof(Obj);
				Buf.Pointer = &Obj;

				status = AcpiEvaluateObject(sc->handle,
				    sc->model->lcd_get, &Args, &Buf);
				if (ACPI_SUCCESS(status) &&
				    Obj.Type == ACPI_TYPE_INTEGER) {
					sc->s_lcd = Obj.Integer.Value;
					return (TRUE);
				}
			} else if (strncmp(sc->model->name, "L3H", 3) == 0) {
				ACPI_BUFFER		Buf;
				ACPI_OBJECT		Arg[2], Obj;
				ACPI_OBJECT_LIST	Args;

				/* L3H is a bit special */
				Arg[0].Type = ACPI_TYPE_INTEGER;
				Arg[0].Integer.Value = 0x02;
				Arg[1].Type = ACPI_TYPE_INTEGER;
				Arg[1].Integer.Value = 0x03;

				Args.Count = 2;
				Args.Pointer = Arg;

				Buf.Length = sizeof(Obj);
				Buf.Pointer = &Obj;

				status = AcpiEvaluateObject(sc->handle,
				    sc->model->lcd_get, &Args, &Buf);
				if (ACPI_SUCCESS(status) &&
				    Obj.Type == ACPI_TYPE_INTEGER) {
					sc->s_lcd = Obj.Integer.Value >> 8;
					return (TRUE);
				}
			} else {
				status = acpi_GetInteger(sc->handle,
				    sc->model->lcd_get, &sc->s_lcd);
				if (ACPI_SUCCESS(status))
					return (TRUE);
			}
		}
		return (FALSE);
	case ACPI_ASUS_METHOD_CAMERA:
		if (sc->model->cam_get) {
			status = acpi_GetInteger(sc->handle,
			    sc->model->cam_get, &sc->s_cam);
			if (ACPI_SUCCESS(status))
				return (TRUE);
		}
		return (FALSE);
	case ACPI_ASUS_METHOD_CARDRD:
		if (sc->model->crd_get) {
			status = acpi_GetInteger(sc->handle,
			    sc->model->crd_get, &sc->s_crd);
			if (ACPI_SUCCESS(status))
				return (TRUE);
		}
		return (FALSE);
	case ACPI_ASUS_METHOD_WLAN:
		if (sc->model->wlan_get) {
			status = acpi_GetInteger(sc->handle,
			    sc->model->wlan_get, &sc->s_wlan);
			if (ACPI_SUCCESS(status))
				return (TRUE);
		}
		return (FALSE);
	}
	return (FALSE);
}

static void
acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context)
{
	struct acpi_asus_softc	*sc;
	struct acpi_softc	*acpi_sc;

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	sc = device_get_softc((device_t)context);
	acpi_sc = acpi_device_get_parent_softc(sc->dev);

	ACPI_SERIAL_BEGIN(asus);
	if ((notify & ~0x10) <= 15) {
		sc->s_brn = notify & ~0x10;
		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
	} else if ((notify & ~0x20) <= 15) {
		sc->s_brn = notify & ~0x20;
		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
	} else if (notify == 0x33) {
		sc->s_lcd = 1;
		ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned on\n");
	} else if (notify == 0x34) {
		sc->s_lcd = 0;
		ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned off\n");
	} else if (notify == 0x86) {
		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1);
		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
	} else if (notify == 0x87) {
		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1);
		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
	} else {
		/* Notify devd(8) */
		acpi_UserNotify("ASUS", h, notify);
	}
	ACPI_SERIAL_END(asus);
}

static void
acpi_asus_lcdd_notify(ACPI_HANDLE h, UINT32 notify, void *context)
{
	struct acpi_asus_softc	*sc;
	struct acpi_softc	*acpi_sc;

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	sc = device_get_softc((device_t)context);
	acpi_sc = acpi_device_get_parent_softc(sc->dev);

	ACPI_SERIAL_BEGIN(asus);
	switch (notify) {
	case 0x87:
		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1);
		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
		break;
	case 0x86:
		acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1);
		ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
		break;
	}
	ACPI_SERIAL_END(asus);
}

static void
acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context)
{
	struct acpi_asus_softc	*sc;
	struct acpi_softc	*acpi_sc;

	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);

	sc = device_get_softc((device_t)context);
	acpi_sc = acpi_device_get_parent_softc(sc->dev);

	ACPI_SERIAL_BEGIN(asus);
	if ((notify & ~0x20) <= 15) {
		sc->s_brn = notify & ~0x20;
		ACPI_VPRINT(sc->dev, acpi_sc,
		    "Brightness increased/decreased\n");
	} else {
		/* Notify devd(8) */
		acpi_UserNotify("ASUS-Eee", h, notify);
	}
	ACPI_SERIAL_END(asus);
}
OpenPOWER on IntegriCloud