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#include <linux/autoconf.h>
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/types.h>
41#include <linux/err.h>
42#include <linux/proc_fs.h>
43#include <linux/backlight.h>
44#include <linux/fb.h>
45#include <linux/leds.h>
46#include <linux/platform_device.h>
47#include <acpi/acpi_drivers.h>
48#include <acpi/acpi_bus.h>
49#include <asm/uaccess.h>
50
51#define ASUS_LAPTOP_VERSION "0.42"
52
53#define ASUS_HOTK_NAME "Asus Laptop Support"
54#define ASUS_HOTK_CLASS "hotkey"
55#define ASUS_HOTK_DEVICE_NAME "Hotkey"
56#define ASUS_HOTK_FILE "asus-laptop"
57#define ASUS_HOTK_PREFIX "\\_SB.ATKD."
58
59
60
61
62#define ATKD_BR_UP 0x10
63#define ATKD_BR_DOWN 0x20
64#define ATKD_LCD_ON 0x33
65#define ATKD_LCD_OFF 0x34
66
67
68
69
70#define WL_HWRS 0x80
71#define BT_HWRS 0x100
72
73
74
75
76
77#define WL_ON 0x01
78#define BT_ON 0x02
79#define MLED_ON 0x04
80#define TLED_ON 0x08
81#define RLED_ON 0x10
82#define PLED_ON 0x20
83#define GLED_ON 0x40
84#define LCD_ON 0x80
85#define GPS_ON 0x100
86
87#define ASUS_LOG ASUS_HOTK_FILE ": "
88#define ASUS_ERR KERN_ERR ASUS_LOG
89#define ASUS_WARNING KERN_WARNING ASUS_LOG
90#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
91#define ASUS_INFO KERN_INFO ASUS_LOG
92#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
93
94MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
95MODULE_DESCRIPTION(ASUS_HOTK_NAME);
96MODULE_LICENSE("GPL");
97
98
99
100
101
102
103
104
105
106
107static uint wapf = 1;
108module_param(wapf, uint, 0644);
109MODULE_PARM_DESC(wapf, "WAPF value");
110
111#define ASUS_HANDLE(object, paths...) \
112 static acpi_handle object##_handle = NULL; \
113 static char *object##_paths[] = { paths }
114
115
116ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
117ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
118ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED");
119ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED");
120ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED");
121
122
123ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
124
125
126
127
128
129ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
130ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
131ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS");
132
133
134ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
135ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
136
137
138ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10",
139 "\\_SB.PCI0.ISA.EC0._Q10",
140 "\\_SB.PCI0.PX40.ECD0._Q10",
141 "\\_SB.PCI0.PX40.EC0.Q10",
142 "\\_SB.PCI0.LPCB.EC0._Q10",
143 "\\_SB.PCI0.PX40.Q10",
144 "\\Q10");
145
146
147ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
148ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD",
149
150 "\\_SB.PCI0.P0P2.VGA.GETD",
151
152 "\\_SB.PCI0.P0P3.VGA.GETD",
153 "\\_SB.PCI0.P0PA.VGA.GETD",
154 "\\_SB.PCI0.PCI1.VGAC.NMAP",
155 "\\_SB.PCI0.VGA.GETD",
156 "\\ACTD",
157 "\\ADVG",
158 "\\DNXT",
159 "\\INFB",
160 "\\SSTE");
161
162ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC");
163ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL");
164
165
166
167ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON");
168ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF");
169ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
170
171
172
173
174
175struct asus_hotk {
176 char *name;
177 struct acpi_device *device;
178 acpi_handle handle;
179 char status;
180 u32 ledd_status;
181 u8 light_level;
182 u8 light_switch;
183 u16 event_count[128];
184};
185
186
187
188
189
190
191static struct acpi_table_header *asus_info;
192
193
194static struct asus_hotk *hotk;
195
196
197
198
199static const struct acpi_device_id asus_device_ids[] = {
200 {"ATK0100", 0},
201 {"", 0},
202};
203MODULE_DEVICE_TABLE(acpi, asus_device_ids);
204
205static int asus_hotk_add(struct acpi_device *device);
206static int asus_hotk_remove(struct acpi_device *device, int type);
207static struct acpi_driver asus_hotk_driver = {
208 .name = ASUS_HOTK_NAME,
209 .class = ASUS_HOTK_CLASS,
210 .ids = asus_device_ids,
211 .ops = {
212 .add = asus_hotk_add,
213 .remove = asus_hotk_remove,
214 },
215};
216
217
218static struct backlight_device *asus_backlight_device;
219
220
221
222
223static int read_brightness(struct backlight_device *bd);
224static int update_bl_status(struct backlight_device *bd);
225static struct backlight_ops asusbl_ops = {
226 .get_brightness = read_brightness,
227 .update_status = update_bl_status,
228};
229
230
231
232
233
234static struct workqueue_struct *led_workqueue;
235
236#define ASUS_LED(object, ledname) \
237 static void object##_led_set(struct led_classdev *led_cdev, \
238 enum led_brightness value); \
239 static void object##_led_update(struct work_struct *ignored); \
240 static int object##_led_wk; \
241 static DECLARE_WORK(object##_led_work, object##_led_update); \
242 static struct led_classdev object##_led = { \
243 .name = "asus:" ledname, \
244 .brightness_set = object##_led_set, \
245 }
246
247ASUS_LED(mled, "mail");
248ASUS_LED(tled, "touchpad");
249ASUS_LED(rled, "record");
250ASUS_LED(pled, "phone");
251ASUS_LED(gled, "gaming");
252
253
254
255
256
257
258
259
260static int write_acpi_int(acpi_handle handle, const char *method, int val,
261 struct acpi_buffer *output)
262{
263 struct acpi_object_list params;
264 union acpi_object in_obj;
265 acpi_status status;
266
267 params.count = 1;
268 params.pointer = &in_obj;
269 in_obj.type = ACPI_TYPE_INTEGER;
270 in_obj.integer.value = val;
271
272 status = acpi_evaluate_object(handle, (char *)method, ¶ms, output);
273 return (status == AE_OK);
274}
275
276static int read_wireless_status(int mask)
277{
278 ulong status;
279 acpi_status rv = AE_OK;
280
281 if (!wireless_status_handle)
282 return (hotk->status & mask) ? 1 : 0;
283
284 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
285 if (ACPI_FAILURE(rv))
286 printk(ASUS_WARNING "Error reading Wireless status\n");
287 else
288 return (status & mask) ? 1 : 0;
289
290 return (hotk->status & mask) ? 1 : 0;
291}
292
293static int read_gps_status(void)
294{
295 ulong status;
296 acpi_status rv = AE_OK;
297
298 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
299 if (ACPI_FAILURE(rv))
300 printk(ASUS_WARNING "Error reading GPS status\n");
301 else
302 return status ? 1 : 0;
303
304 return (hotk->status & GPS_ON) ? 1 : 0;
305}
306
307
308static int read_status(int mask)
309{
310
311 if (mask == BT_ON || mask == WL_ON)
312 return read_wireless_status(mask);
313 else if (mask == GPS_ON)
314 return read_gps_status();
315
316 return (hotk->status & mask) ? 1 : 0;
317}
318
319static void write_status(acpi_handle handle, int out, int mask)
320{
321 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
322
323 switch (mask) {
324 case MLED_ON:
325 out = !out & 0x1;
326 break;
327 case GLED_ON:
328 out = (out & 0x1) + 1;
329 break;
330 case GPS_ON:
331 handle = (out) ? gps_on_handle : gps_off_handle;
332 out = 0x02;
333 break;
334 default:
335 out &= 0x1;
336 break;
337 }
338
339 if (handle && !write_acpi_int(handle, NULL, out, NULL))
340 printk(ASUS_WARNING " write failed %x\n", mask);
341}
342
343
344#define ASUS_LED_HANDLER(object, mask) \
345 static void object##_led_set(struct led_classdev *led_cdev, \
346 enum led_brightness value) \
347 { \
348 object##_led_wk = value; \
349 queue_work(led_workqueue, &object##_led_work); \
350 } \
351 static void object##_led_update(struct work_struct *ignored) \
352 { \
353 int value = object##_led_wk; \
354 write_status(object##_set_handle, value, (mask)); \
355 }
356
357ASUS_LED_HANDLER(mled, MLED_ON);
358ASUS_LED_HANDLER(pled, PLED_ON);
359ASUS_LED_HANDLER(rled, RLED_ON);
360ASUS_LED_HANDLER(tled, TLED_ON);
361ASUS_LED_HANDLER(gled, GLED_ON);
362
363static int get_lcd_state(void)
364{
365 return read_status(LCD_ON);
366}
367
368static int set_lcd_state(int value)
369{
370 int lcd = 0;
371 acpi_status status = 0;
372
373 lcd = value ? 1 : 0;
374
375 if (lcd == get_lcd_state())
376 return 0;
377
378 if (lcd_switch_handle) {
379 status = acpi_evaluate_object(lcd_switch_handle,
380 NULL, NULL, NULL);
381
382 if (ACPI_FAILURE(status))
383 printk(ASUS_WARNING "Error switching LCD\n");
384 }
385
386 write_status(NULL, lcd, LCD_ON);
387 return 0;
388}
389
390static void lcd_blank(int blank)
391{
392 struct backlight_device *bd = asus_backlight_device;
393
394 if (bd) {
395 bd->props.power = blank;
396 backlight_update_status(bd);
397 }
398}
399
400static int read_brightness(struct backlight_device *bd)
401{
402 ulong value;
403 acpi_status rv = AE_OK;
404
405 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
406 if (ACPI_FAILURE(rv))
407 printk(ASUS_WARNING "Error reading brightness\n");
408
409 return value;
410}
411
412static int set_brightness(struct backlight_device *bd, int value)
413{
414 int ret = 0;
415
416 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
417
418
419 if (!write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
420 printk(ASUS_WARNING "Error changing brightness\n");
421 ret = -EIO;
422 }
423
424 return ret;
425}
426
427static int update_bl_status(struct backlight_device *bd)
428{
429 int rv;
430 int value = bd->props.brightness;
431
432 rv = set_brightness(bd, value);
433 if (rv)
434 return rv;
435
436 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
437 return set_lcd_state(value);
438}
439
440
441
442
443
444
445
446
447
448
449static ssize_t show_infos(struct device *dev,
450 struct device_attribute *attr, char *page)
451{
452 int len = 0;
453 ulong temp;
454 char buf[16];
455 acpi_status rv = AE_OK;
456
457
458
459
460
461
462 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
463 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
464
465
466
467
468
469
470 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
471 if (!ACPI_FAILURE(rv))
472 len += sprintf(page + len, "SFUN value : 0x%04x\n",
473 (uint) temp);
474
475
476
477
478
479
480
481 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
482 if (!ACPI_FAILURE(rv))
483 len += sprintf(page + len, "ASYM value : 0x%04x\n",
484 (uint) temp);
485 if (asus_info) {
486 snprintf(buf, 16, "%d", asus_info->length);
487 len += sprintf(page + len, "DSDT length : %s\n", buf);
488 snprintf(buf, 16, "%d", asus_info->checksum);
489 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
490 snprintf(buf, 16, "%d", asus_info->revision);
491 len += sprintf(page + len, "DSDT revision : %s\n", buf);
492 snprintf(buf, 7, "%s", asus_info->oem_id);
493 len += sprintf(page + len, "OEM id : %s\n", buf);
494 snprintf(buf, 9, "%s", asus_info->oem_table_id);
495 len += sprintf(page + len, "OEM table id : %s\n", buf);
496 snprintf(buf, 16, "%x", asus_info->oem_revision);
497 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
498 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
499 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
500 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
501 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
502 }
503
504 return len;
505}
506
507static int parse_arg(const char *buf, unsigned long count, int *val)
508{
509 if (!count)
510 return 0;
511 if (count > 31)
512 return -EINVAL;
513 if (sscanf(buf, "%i", val) != 1)
514 return -EINVAL;
515 return count;
516}
517
518static ssize_t store_status(const char *buf, size_t count,
519 acpi_handle handle, int mask)
520{
521 int rv, value;
522 int out = 0;
523
524 rv = parse_arg(buf, count, &value);
525 if (rv > 0)
526 out = value ? 1 : 0;
527
528 write_status(handle, out, mask);
529
530 return rv;
531}
532
533
534
535
536static ssize_t show_ledd(struct device *dev,
537 struct device_attribute *attr, char *buf)
538{
539 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
540}
541
542static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
543 const char *buf, size_t count)
544{
545 int rv, value;
546
547 rv = parse_arg(buf, count, &value);
548 if (rv > 0) {
549 if (!write_acpi_int(ledd_set_handle, NULL, value, NULL))
550 printk(ASUS_WARNING "LED display write failed\n");
551 else
552 hotk->ledd_status = (u32) value;
553 }
554 return rv;
555}
556
557
558
559
560static ssize_t show_wlan(struct device *dev,
561 struct device_attribute *attr, char *buf)
562{
563 return sprintf(buf, "%d\n", read_status(WL_ON));
564}
565
566static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
567 const char *buf, size_t count)
568{
569 return store_status(buf, count, wl_switch_handle, WL_ON);
570}
571
572
573
574
575static ssize_t show_bluetooth(struct device *dev,
576 struct device_attribute *attr, char *buf)
577{
578 return sprintf(buf, "%d\n", read_status(BT_ON));
579}
580
581static ssize_t store_bluetooth(struct device *dev,
582 struct device_attribute *attr, const char *buf,
583 size_t count)
584{
585 return store_status(buf, count, bt_switch_handle, BT_ON);
586}
587
588
589
590
591static void set_display(int value)
592{
593
594 if (!write_acpi_int(display_set_handle, NULL, value, NULL))
595 printk(ASUS_WARNING "Error setting display\n");
596 return;
597}
598
599static int read_display(void)
600{
601 ulong value = 0;
602 acpi_status rv = AE_OK;
603
604
605
606 if (display_get_handle) {
607 rv = acpi_evaluate_integer(display_get_handle, NULL,
608 NULL, &value);
609 if (ACPI_FAILURE(rv))
610 printk(ASUS_WARNING "Error reading display status\n");
611 }
612
613 value &= 0x0F;
614
615 return value;
616}
617
618
619
620
621
622static ssize_t show_disp(struct device *dev,
623 struct device_attribute *attr, char *buf)
624{
625 return sprintf(buf, "%d\n", read_display());
626}
627
628
629
630
631
632
633
634
635static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
636 const char *buf, size_t count)
637{
638 int rv, value;
639
640 rv = parse_arg(buf, count, &value);
641 if (rv > 0)
642 set_display(value);
643 return rv;
644}
645
646
647
648
649static void set_light_sens_switch(int value)
650{
651 if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
652 printk(ASUS_WARNING "Error setting light sensor switch\n");
653 hotk->light_switch = value;
654}
655
656static ssize_t show_lssw(struct device *dev,
657 struct device_attribute *attr, char *buf)
658{
659 return sprintf(buf, "%d\n", hotk->light_switch);
660}
661
662static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
663 const char *buf, size_t count)
664{
665 int rv, value;
666
667 rv = parse_arg(buf, count, &value);
668 if (rv > 0)
669 set_light_sens_switch(value ? 1 : 0);
670
671 return rv;
672}
673
674static void set_light_sens_level(int value)
675{
676 if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
677 printk(ASUS_WARNING "Error setting light sensor level\n");
678 hotk->light_level = value;
679}
680
681static ssize_t show_lslvl(struct device *dev,
682 struct device_attribute *attr, char *buf)
683{
684 return sprintf(buf, "%d\n", hotk->light_level);
685}
686
687static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
688 const char *buf, size_t count)
689{
690 int rv, value;
691
692 rv = parse_arg(buf, count, &value);
693 if (rv > 0) {
694 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
695
696 set_light_sens_level(value);
697 }
698
699 return rv;
700}
701
702
703
704
705static ssize_t show_gps(struct device *dev,
706 struct device_attribute *attr, char *buf)
707{
708 return sprintf(buf, "%d\n", read_status(GPS_ON));
709}
710
711static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
712 const char *buf, size_t count)
713{
714 return store_status(buf, count, NULL, GPS_ON);
715}
716
717static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
718{
719
720 if (!hotk)
721 return;
722
723
724
725
726
727 if (event == ATKD_LCD_ON) {
728 write_status(NULL, 1, LCD_ON);
729 lcd_blank(FB_BLANK_UNBLANK);
730 } else if (event == ATKD_LCD_OFF) {
731 write_status(NULL, 0, LCD_ON);
732 lcd_blank(FB_BLANK_POWERDOWN);
733 }
734
735 acpi_bus_generate_proc_event(hotk->device, event,
736 hotk->event_count[event % 128]++);
737
738 return;
739}
740
741#define ASUS_CREATE_DEVICE_ATTR(_name) \
742 struct device_attribute dev_attr_##_name = { \
743 .attr = { \
744 .name = __stringify(_name), \
745 .mode = 0 }, \
746 .show = NULL, \
747 .store = NULL, \
748 }
749
750#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
751 do { \
752 dev_attr_##_name.attr.mode = _mode; \
753 dev_attr_##_name.show = _show; \
754 dev_attr_##_name.store = _store; \
755 } while(0)
756
757static ASUS_CREATE_DEVICE_ATTR(infos);
758static ASUS_CREATE_DEVICE_ATTR(wlan);
759static ASUS_CREATE_DEVICE_ATTR(bluetooth);
760static ASUS_CREATE_DEVICE_ATTR(display);
761static ASUS_CREATE_DEVICE_ATTR(ledd);
762static ASUS_CREATE_DEVICE_ATTR(ls_switch);
763static ASUS_CREATE_DEVICE_ATTR(ls_level);
764static ASUS_CREATE_DEVICE_ATTR(gps);
765
766static struct attribute *asuspf_attributes[] = {
767 &dev_attr_infos.attr,
768 &dev_attr_wlan.attr,
769 &dev_attr_bluetooth.attr,
770 &dev_attr_display.attr,
771 &dev_attr_ledd.attr,
772 &dev_attr_ls_switch.attr,
773 &dev_attr_ls_level.attr,
774 &dev_attr_gps.attr,
775 NULL
776};
777
778static struct attribute_group asuspf_attribute_group = {
779 .attrs = asuspf_attributes
780};
781
782static struct platform_driver asuspf_driver = {
783 .driver = {
784 .name = ASUS_HOTK_FILE,
785 .owner = THIS_MODULE,
786 }
787};
788
789static struct platform_device *asuspf_device;
790
791static void asus_hotk_add_fs(void)
792{
793 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
794
795 if (wl_switch_handle)
796 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
797
798 if (bt_switch_handle)
799 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
800 show_bluetooth, store_bluetooth);
801
802 if (display_set_handle && display_get_handle)
803 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
804 else if (display_set_handle)
805 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
806
807 if (ledd_set_handle)
808 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
809
810 if (ls_switch_handle && ls_level_handle) {
811 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
812 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
813 }
814
815 if (gps_status_handle && gps_on_handle && gps_off_handle)
816 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
817}
818
819static int asus_handle_init(char *name, acpi_handle * handle,
820 char **paths, int num_paths)
821{
822 int i;
823 acpi_status status;
824
825 for (i = 0; i < num_paths; i++) {
826 status = acpi_get_handle(NULL, paths[i], handle);
827 if (ACPI_SUCCESS(status))
828 return 0;
829 }
830
831 *handle = NULL;
832 return -ENODEV;
833}
834
835#define ASUS_HANDLE_INIT(object) \
836 asus_handle_init(#object, &object##_handle, object##_paths, \
837 ARRAY_SIZE(object##_paths))
838
839
840
841
842
843static int asus_hotk_get_info(void)
844{
845 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
846 union acpi_object *model = NULL;
847 ulong bsts_result, hwrs_result;
848 char *string = NULL;
849 acpi_status status;
850
851
852
853
854
855
856
857
858
859 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
860 if (ACPI_FAILURE(status))
861 printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
862
863
864 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
865 printk(ASUS_ERR "Hotkey initialization failed\n");
866 return -ENODEV;
867 }
868
869
870 status =
871 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
872 if (ACPI_FAILURE(status))
873 printk(ASUS_WARNING "Error calling BSTS\n");
874 else if (bsts_result)
875 printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
876 (uint) bsts_result);
877
878
879 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
880
881
882
883
884
885
886
887 if (buffer.pointer) {
888 model = buffer.pointer;
889 switch (model->type) {
890 case ACPI_TYPE_STRING:
891 string = model->string.pointer;
892 break;
893 case ACPI_TYPE_BUFFER:
894 string = model->buffer.pointer;
895 break;
896 default:
897 string = "";
898 break;
899 }
900 }
901 hotk->name = kstrdup(string, GFP_KERNEL);
902 if (!hotk->name)
903 return -ENOMEM;
904
905 if (*string)
906 printk(ASUS_NOTICE " %s model detected\n", string);
907
908 ASUS_HANDLE_INIT(mled_set);
909 ASUS_HANDLE_INIT(tled_set);
910 ASUS_HANDLE_INIT(rled_set);
911 ASUS_HANDLE_INIT(pled_set);
912 ASUS_HANDLE_INIT(gled_set);
913
914 ASUS_HANDLE_INIT(ledd_set);
915
916
917
918
919
920
921
922 status =
923 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
924 if (ACPI_FAILURE(status))
925 hwrs_result = WL_HWRS | BT_HWRS;
926
927 if (hwrs_result & WL_HWRS)
928 ASUS_HANDLE_INIT(wl_switch);
929 if (hwrs_result & BT_HWRS)
930 ASUS_HANDLE_INIT(bt_switch);
931
932 ASUS_HANDLE_INIT(wireless_status);
933
934 ASUS_HANDLE_INIT(brightness_set);
935 ASUS_HANDLE_INIT(brightness_get);
936
937 ASUS_HANDLE_INIT(lcd_switch);
938
939 ASUS_HANDLE_INIT(display_set);
940 ASUS_HANDLE_INIT(display_get);
941
942
943
944 if (!ASUS_HANDLE_INIT(ls_switch))
945 ASUS_HANDLE_INIT(ls_level);
946
947 ASUS_HANDLE_INIT(gps_on);
948 ASUS_HANDLE_INIT(gps_off);
949 ASUS_HANDLE_INIT(gps_status);
950
951 kfree(model);
952
953 return AE_OK;
954}
955
956static int asus_hotk_check(void)
957{
958 int result = 0;
959
960 result = acpi_bus_get_status(hotk->device);
961 if (result)
962 return result;
963
964 if (hotk->device->status.present) {
965 result = asus_hotk_get_info();
966 } else {
967 printk(ASUS_ERR "Hotkey device not present, aborting\n");
968 return -EINVAL;
969 }
970
971 return result;
972}
973
974static int asus_hotk_found;
975
976static int asus_hotk_add(struct acpi_device *device)
977{
978 acpi_status status = AE_OK;
979 int result;
980
981 if (!device)
982 return -EINVAL;
983
984 printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
985 ASUS_LAPTOP_VERSION);
986
987 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
988 if (!hotk)
989 return -ENOMEM;
990
991 hotk->handle = device->handle;
992 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
993 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
994 acpi_driver_data(device) = hotk;
995 hotk->device = device;
996
997 result = asus_hotk_check();
998 if (result)
999 goto end;
1000
1001 asus_hotk_add_fs();
1002
1003
1004
1005
1006
1007 status = acpi_install_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
1008 asus_hotk_notify, hotk);
1009 if (ACPI_FAILURE(status))
1010 printk(ASUS_ERR "Error installing notify handler\n");
1011
1012 asus_hotk_found = 1;
1013
1014
1015 write_status(bt_switch_handle, 1, BT_ON);
1016 write_status(wl_switch_handle, 1, WL_ON);
1017
1018
1019 write_status(NULL, read_status(BT_ON), BT_ON);
1020 write_status(NULL, read_status(WL_ON), WL_ON);
1021
1022
1023 write_status(NULL, 1, LCD_ON);
1024
1025
1026 hotk->ledd_status = 0xFFF;
1027
1028
1029 hotk->light_switch = 1;
1030 hotk->light_level = 0;
1031
1032 if (ls_switch_handle)
1033 set_light_sens_switch(hotk->light_switch);
1034
1035 if (ls_level_handle)
1036 set_light_sens_level(hotk->light_level);
1037
1038
1039 write_status(NULL, 1, GPS_ON);
1040
1041 end:
1042 if (result) {
1043 kfree(hotk->name);
1044 kfree(hotk);
1045 }
1046
1047 return result;
1048}
1049
1050static int asus_hotk_remove(struct acpi_device *device, int type)
1051{
1052 acpi_status status = 0;
1053
1054 if (!device || !acpi_driver_data(device))
1055 return -EINVAL;
1056
1057 status = acpi_remove_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
1058 asus_hotk_notify);
1059 if (ACPI_FAILURE(status))
1060 printk(ASUS_ERR "Error removing notify handler\n");
1061
1062 kfree(hotk->name);
1063 kfree(hotk);
1064
1065 return 0;
1066}
1067
1068static void asus_backlight_exit(void)
1069{
1070 if (asus_backlight_device)
1071 backlight_device_unregister(asus_backlight_device);
1072}
1073
1074#define ASUS_LED_UNREGISTER(object) \
1075 if (object##_led.dev) \
1076 led_classdev_unregister(&object##_led)
1077
1078static void asus_led_exit(void)
1079{
1080 destroy_workqueue(led_workqueue);
1081 ASUS_LED_UNREGISTER(mled);
1082 ASUS_LED_UNREGISTER(tled);
1083 ASUS_LED_UNREGISTER(pled);
1084 ASUS_LED_UNREGISTER(rled);
1085 ASUS_LED_UNREGISTER(gled);
1086}
1087
1088static void __exit asus_laptop_exit(void)
1089{
1090 asus_backlight_exit();
1091 asus_led_exit();
1092
1093 acpi_bus_unregister_driver(&asus_hotk_driver);
1094 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1095 platform_device_unregister(asuspf_device);
1096 platform_driver_unregister(&asuspf_driver);
1097}
1098
1099static int asus_backlight_init(struct device *dev)
1100{
1101 struct backlight_device *bd;
1102
1103 if (brightness_set_handle && lcd_switch_handle) {
1104 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
1105 NULL, &asusbl_ops);
1106 if (IS_ERR(bd)) {
1107 printk(ASUS_ERR
1108 "Could not register asus backlight device\n");
1109 asus_backlight_device = NULL;
1110 return PTR_ERR(bd);
1111 }
1112
1113 asus_backlight_device = bd;
1114
1115 bd->props.max_brightness = 15;
1116 bd->props.brightness = read_brightness(NULL);
1117 bd->props.power = FB_BLANK_UNBLANK;
1118 backlight_update_status(bd);
1119 }
1120 return 0;
1121}
1122
1123static int asus_led_register(acpi_handle handle,
1124 struct led_classdev *ldev, struct device *dev)
1125{
1126 if (!handle)
1127 return 0;
1128
1129 return led_classdev_register(dev, ldev);
1130}
1131
1132#define ASUS_LED_REGISTER(object, device) \
1133 asus_led_register(object##_set_handle, &object##_led, device)
1134
1135static int asus_led_init(struct device *dev)
1136{
1137 int rv;
1138
1139 rv = ASUS_LED_REGISTER(mled, dev);
1140 if (rv)
1141 goto out;
1142
1143 rv = ASUS_LED_REGISTER(tled, dev);
1144 if (rv)
1145 goto out1;
1146
1147 rv = ASUS_LED_REGISTER(rled, dev);
1148 if (rv)
1149 goto out2;
1150
1151 rv = ASUS_LED_REGISTER(pled, dev);
1152 if (rv)
1153 goto out3;
1154
1155 rv = ASUS_LED_REGISTER(gled, dev);
1156 if (rv)
1157 goto out4;
1158
1159 led_workqueue = create_singlethread_workqueue("led_workqueue");
1160 if (!led_workqueue)
1161 goto out5;
1162
1163 return 0;
1164out5:
1165 rv = -ENOMEM;
1166 ASUS_LED_UNREGISTER(gled);
1167out4:
1168 ASUS_LED_UNREGISTER(pled);
1169out3:
1170 ASUS_LED_UNREGISTER(rled);
1171out2:
1172 ASUS_LED_UNREGISTER(tled);
1173out1:
1174 ASUS_LED_UNREGISTER(mled);
1175out:
1176 return rv;
1177}
1178
1179static int __init asus_laptop_init(void)
1180{
1181 struct device *dev;
1182 int result;
1183
1184 if (acpi_disabled)
1185 return -ENODEV;
1186
1187 result = acpi_bus_register_driver(&asus_hotk_driver);
1188 if (result < 0)
1189 return result;
1190
1191
1192
1193
1194
1195
1196
1197
1198 if (!asus_hotk_found) {
1199 acpi_bus_unregister_driver(&asus_hotk_driver);
1200 return -ENODEV;
1201 }
1202
1203 dev = acpi_get_physical_device(hotk->device->handle);
1204
1205 result = asus_backlight_init(dev);
1206 if (result)
1207 goto fail_backlight;
1208
1209 result = asus_led_init(dev);
1210 if (result)
1211 goto fail_led;
1212
1213
1214 result = platform_driver_register(&asuspf_driver);
1215 if (result)
1216 goto fail_platform_driver;
1217
1218 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1219 if (!asuspf_device) {
1220 result = -ENOMEM;
1221 goto fail_platform_device1;
1222 }
1223
1224 result = platform_device_add(asuspf_device);
1225 if (result)
1226 goto fail_platform_device2;
1227
1228 result = sysfs_create_group(&asuspf_device->dev.kobj,
1229 &asuspf_attribute_group);
1230 if (result)
1231 goto fail_sysfs;
1232
1233 return 0;
1234
1235 fail_sysfs:
1236 platform_device_del(asuspf_device);
1237
1238 fail_platform_device2:
1239 platform_device_put(asuspf_device);
1240
1241 fail_platform_device1:
1242 platform_driver_unregister(&asuspf_driver);
1243
1244 fail_platform_driver:
1245 asus_led_exit();
1246
1247 fail_led:
1248 asus_backlight_exit();
1249
1250 fail_backlight:
1251
1252 return result;
1253}
1254
1255module_init(asus_laptop_init);
1256module_exit(asus_laptop_exit);
1257