2 * eepc-laptop.c - Asus Eee PC extras
4 * Based on asus_acpi.c as patched for the Eee PC by Asus:
5 * ftp://ftp.asus.com/pub/ASUS/EeePC/701/ASUS_ACPI_071126.rar
6 * Based on eee.c from eeepc-linux
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/types.h>
23 #include <linux/platform_device.h>
24 #include <linux/backlight.h>
26 #include <linux/hwmon.h>
27 #include <linux/hwmon-sysfs.h>
28 #include <acpi/acpi_drivers.h>
29 #include <acpi/acpi_bus.h>
30 #include <linux/uaccess.h>
31 #include <linux/input.h>
32 #include <linux/rfkill.h>
33 #include <linux/pci.h>
35 #define EEEPC_LAPTOP_VERSION "0.1"
37 #define EEEPC_HOTK_NAME "Eee PC Hotkey Driver"
38 #define EEEPC_HOTK_FILE "eeepc"
39 #define EEEPC_HOTK_CLASS "hotkey"
40 #define EEEPC_HOTK_DEVICE_NAME "Hotkey"
41 #define EEEPC_HOTK_HID "ASUS010"
43 #define EEEPC_LOG EEEPC_HOTK_FILE ": "
44 #define EEEPC_ERR KERN_ERR EEEPC_LOG
45 #define EEEPC_WARNING KERN_WARNING EEEPC_LOG
46 #define EEEPC_NOTICE KERN_NOTICE EEEPC_LOG
47 #define EEEPC_INFO KERN_INFO EEEPC_LOG
50 * Definitions for Asus EeePC
52 #define NOTIFY_WLAN_ON 0x10
53 #define NOTIFY_BRN_MIN 0x20
54 #define NOTIFY_BRN_MAX 0x2f
57 DISABLE_ASL_WLAN = 0x0001,
58 DISABLE_ASL_BLUETOOTH = 0x0002,
59 DISABLE_ASL_IRDA = 0x0004,
60 DISABLE_ASL_CAMERA = 0x0008,
61 DISABLE_ASL_TV = 0x0010,
62 DISABLE_ASL_GPS = 0x0020,
63 DISABLE_ASL_DISPLAYSWITCH = 0x0040,
64 DISABLE_ASL_MODEM = 0x0080,
65 DISABLE_ASL_CARDREADER = 0x0100
82 CM_ASL_CPUTEMPERATURE,
93 static const char *cm_getv[] = {
94 "WLDG", "BTHG", NULL, NULL,
95 "CAMG", NULL, NULL, NULL,
96 NULL, "PBLG", NULL, NULL,
97 "CFVG", NULL, NULL, NULL,
98 "USBG", NULL, NULL, "MODG",
102 static const char *cm_setv[] = {
103 "WLDS", "BTHS", NULL, NULL,
104 "CAMS", NULL, NULL, NULL,
105 "SDSP", "PBLS", "HDPS", NULL,
106 "CFVS", NULL, NULL, NULL,
107 "USBG", NULL, NULL, "MODS",
111 #define EEEPC_EC "\\_SB.PCI0.SBRG.EC0."
113 #define EEEPC_EC_FAN_PWM EEEPC_EC "SC02" /* Fan PWM duty cycle (%) */
114 #define EEEPC_EC_SC02 0x63
115 #define EEEPC_EC_FAN_HRPM EEEPC_EC "SC05" /* High byte, fan speed (RPM) */
116 #define EEEPC_EC_FAN_LRPM EEEPC_EC "SC06" /* Low byte, fan speed (RPM) */
117 #define EEEPC_EC_FAN_CTRL EEEPC_EC "SFB3" /* Byte containing SF25 */
118 #define EEEPC_EC_SFB3 0xD3
121 * This is the main structure, we can use it to store useful information
122 * about the hotk device
125 struct acpi_device *device; /* the device we are in */
126 acpi_handle handle; /* the handle of the hotk device */
127 u32 cm_supported; /* the control methods supported
129 uint init_flag; /* Init flags */
130 u16 event_count[128]; /* count for each event */
131 struct input_dev *inputdev;
133 struct rfkill *eeepc_wlan_rfkill;
134 struct rfkill *eeepc_bluetooth_rfkill;
137 /* The actual device the driver binds to */
138 static struct eeepc_hotk *ehotk;
140 /* Platform device/driver */
141 static struct platform_driver platform_driver = {
143 .name = EEEPC_HOTK_FILE,
144 .owner = THIS_MODULE,
148 static struct platform_device *platform_device;
156 enum { KE_KEY, KE_END };
158 static struct key_entry eeepc_keymap[] = {
159 /* Sleep already handled via generic ACPI code */
160 {KE_KEY, 0x10, KEY_WLAN },
161 {KE_KEY, 0x11, KEY_WLAN },
162 {KE_KEY, 0x12, KEY_PROG1 },
163 {KE_KEY, 0x13, KEY_MUTE },
164 {KE_KEY, 0x14, KEY_VOLUMEDOWN },
165 {KE_KEY, 0x15, KEY_VOLUMEUP },
166 {KE_KEY, 0x1a, KEY_COFFEE },
167 {KE_KEY, 0x1b, KEY_ZOOM },
168 {KE_KEY, 0x1c, KEY_PROG2 },
169 {KE_KEY, 0x1d, KEY_PROG3 },
170 {KE_KEY, NOTIFY_BRN_MIN, KEY_BRIGHTNESSDOWN },
171 {KE_KEY, NOTIFY_BRN_MIN + 2, KEY_BRIGHTNESSUP },
172 {KE_KEY, 0x30, KEY_SWITCHVIDEOMODE },
173 {KE_KEY, 0x31, KEY_SWITCHVIDEOMODE },
174 {KE_KEY, 0x32, KEY_SWITCHVIDEOMODE },
179 * The hotkey driver declaration
181 static int eeepc_hotk_add(struct acpi_device *device);
182 static int eeepc_hotk_remove(struct acpi_device *device, int type);
183 static int eeepc_hotk_resume(struct acpi_device *device);
185 static const struct acpi_device_id eeepc_device_ids[] = {
189 MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
191 static struct acpi_driver eeepc_hotk_driver = {
192 .name = EEEPC_HOTK_NAME,
193 .class = EEEPC_HOTK_CLASS,
194 .ids = eeepc_device_ids,
196 .add = eeepc_hotk_add,
197 .remove = eeepc_hotk_remove,
198 .resume = eeepc_hotk_resume,
202 /* The backlight device /sys/class/backlight */
203 static struct backlight_device *eeepc_backlight_device;
205 /* The hwmon device */
206 static struct device *eeepc_hwmon_device;
209 * The backlight class declaration
211 static int read_brightness(struct backlight_device *bd);
212 static int update_bl_status(struct backlight_device *bd);
213 static struct backlight_ops eeepcbl_ops = {
214 .get_brightness = read_brightness,
215 .update_status = update_bl_status,
218 MODULE_AUTHOR("Corentin Chary, Eric Cooper");
219 MODULE_DESCRIPTION(EEEPC_HOTK_NAME);
220 MODULE_LICENSE("GPL");
225 static int write_acpi_int(acpi_handle handle, const char *method, int val,
226 struct acpi_buffer *output)
228 struct acpi_object_list params;
229 union acpi_object in_obj;
233 params.pointer = &in_obj;
234 in_obj.type = ACPI_TYPE_INTEGER;
235 in_obj.integer.value = val;
237 status = acpi_evaluate_object(handle, (char *)method, ¶ms, output);
238 return (status == AE_OK ? 0 : -1);
241 static int read_acpi_int(acpi_handle handle, const char *method, int *val)
244 unsigned long long result;
246 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
247 if (ACPI_FAILURE(status)) {
256 static int set_acpi(int cm, int value)
258 if (ehotk->cm_supported & (0x1 << cm)) {
259 const char *method = cm_setv[cm];
262 if (write_acpi_int(ehotk->handle, method, value, NULL))
263 printk(EEEPC_WARNING "Error writing %s\n", method);
268 static int get_acpi(int cm)
271 if ((ehotk->cm_supported & (0x1 << cm))) {
272 const char *method = cm_getv[cm];
275 if (read_acpi_int(ehotk->handle, method, &value))
276 printk(EEEPC_WARNING "Error reading %s\n", method);
284 static int read_brightness(struct backlight_device *bd)
286 return get_acpi(CM_ASL_PANELBRIGHT);
289 static int set_brightness(struct backlight_device *bd, int value)
291 value = max(0, min(15, value));
292 return set_acpi(CM_ASL_PANELBRIGHT, value);
295 static int update_bl_status(struct backlight_device *bd)
297 return set_brightness(bd, bd->props.brightness);
304 static bool eeepc_wlan_rfkill_blocked(void)
306 if (get_acpi(CM_ASL_WLAN) == 1)
311 static int eeepc_rfkill_set(void *data, bool blocked)
313 unsigned long asl = (unsigned long)data;
314 return set_acpi(asl, !blocked);
317 static const struct rfkill_ops eeepc_rfkill_ops = {
318 .set_block = eeepc_rfkill_set,
324 static int parse_arg(const char *buf, unsigned long count, int *val)
328 if (sscanf(buf, "%i", val) != 1)
333 static ssize_t store_sys_acpi(int cm, const char *buf, size_t count)
337 rv = parse_arg(buf, count, &value);
343 static ssize_t show_sys_acpi(int cm, char *buf)
345 return sprintf(buf, "%d\n", get_acpi(cm));
348 #define EEEPC_CREATE_DEVICE_ATTR(_name, _cm) \
349 static ssize_t show_##_name(struct device *dev, \
350 struct device_attribute *attr, \
353 return show_sys_acpi(_cm, buf); \
355 static ssize_t store_##_name(struct device *dev, \
356 struct device_attribute *attr, \
357 const char *buf, size_t count) \
359 return store_sys_acpi(_cm, buf, count); \
361 static struct device_attribute dev_attr_##_name = { \
363 .name = __stringify(_name), \
365 .show = show_##_name, \
366 .store = store_##_name, \
369 EEEPC_CREATE_DEVICE_ATTR(camera, CM_ASL_CAMERA);
370 EEEPC_CREATE_DEVICE_ATTR(cardr, CM_ASL_CARDREADER);
371 EEEPC_CREATE_DEVICE_ATTR(disp, CM_ASL_DISPLAYSWITCH);
372 EEEPC_CREATE_DEVICE_ATTR(cpufv, CM_ASL_CPUFV);
374 static struct attribute *platform_attributes[] = {
375 &dev_attr_camera.attr,
376 &dev_attr_cardr.attr,
378 &dev_attr_cpufv.attr,
382 static struct attribute_group platform_attribute_group = {
383 .attrs = platform_attributes
389 static struct key_entry *eepc_get_entry_by_scancode(int code)
391 struct key_entry *key;
393 for (key = eeepc_keymap; key->type != KE_END; key++)
394 if (code == key->code)
400 static struct key_entry *eepc_get_entry_by_keycode(int code)
402 struct key_entry *key;
404 for (key = eeepc_keymap; key->type != KE_END; key++)
405 if (code == key->keycode && key->type == KE_KEY)
411 static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
413 struct key_entry *key = eepc_get_entry_by_scancode(scancode);
415 if (key && key->type == KE_KEY) {
416 *keycode = key->keycode;
423 static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
425 struct key_entry *key;
428 if (keycode < 0 || keycode > KEY_MAX)
431 key = eepc_get_entry_by_scancode(scancode);
432 if (key && key->type == KE_KEY) {
433 old_keycode = key->keycode;
434 key->keycode = keycode;
435 set_bit(keycode, dev->keybit);
436 if (!eepc_get_entry_by_keycode(old_keycode))
437 clear_bit(old_keycode, dev->keybit);
444 static int eeepc_hotk_check(void)
446 const struct key_entry *key;
447 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
450 result = acpi_bus_get_status(ehotk->device);
453 if (ehotk->device->status.present) {
454 if (write_acpi_int(ehotk->handle, "INIT", ehotk->init_flag,
456 printk(EEEPC_ERR "Hotkey initialization failed\n");
459 printk(EEEPC_NOTICE "Hotkey init flags 0x%x\n",
462 /* get control methods supported */
463 if (read_acpi_int(ehotk->handle, "CMSG"
464 , &ehotk->cm_supported)) {
466 "Get control methods supported failed\n");
470 "Get control methods supported: 0x%x\n",
471 ehotk->cm_supported);
473 ehotk->inputdev = input_allocate_device();
474 if (!ehotk->inputdev) {
475 printk(EEEPC_INFO "Unable to allocate input device\n");
478 ehotk->inputdev->name = "Asus EeePC extra buttons";
479 ehotk->inputdev->phys = EEEPC_HOTK_FILE "/input0";
480 ehotk->inputdev->id.bustype = BUS_HOST;
481 ehotk->inputdev->getkeycode = eeepc_getkeycode;
482 ehotk->inputdev->setkeycode = eeepc_setkeycode;
484 for (key = eeepc_keymap; key->type != KE_END; key++) {
487 set_bit(EV_KEY, ehotk->inputdev->evbit);
488 set_bit(key->keycode, ehotk->inputdev->keybit);
492 result = input_register_device(ehotk->inputdev);
494 printk(EEEPC_INFO "Unable to register input device\n");
495 input_free_device(ehotk->inputdev);
499 printk(EEEPC_ERR "Hotkey device not present, aborting\n");
505 static int notify_brn(void)
507 /* returns the *previous* brightness, or -1 */
508 struct backlight_device *bd = eeepc_backlight_device;
510 int old = bd->props.brightness;
511 bd->props.brightness = read_brightness(bd);
517 static void eeepc_rfkill_hotplug(void)
520 struct pci_bus *bus = pci_find_bus(0, 1);
524 printk(EEEPC_WARNING "Unable to find PCI bus 1?\n");
528 blocked = eeepc_wlan_rfkill_blocked();
530 dev = pci_get_slot(bus, 0);
532 /* Device already present */
536 dev = pci_scan_single_device(bus, 0);
538 pci_bus_assign_resources(bus);
539 if (pci_bus_add_device(dev))
540 printk(EEEPC_ERR "Unable to hotplug wifi\n");
543 dev = pci_get_slot(bus, 0);
545 pci_remove_bus_device(dev);
550 rfkill_set_sw_state(ehotk->eeepc_wlan_rfkill, blocked);
553 static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
555 if (event != ACPI_NOTIFY_BUS_CHECK)
558 eeepc_rfkill_hotplug();
561 static void eeepc_hotk_notify(acpi_handle handle, u32 event, void *data)
563 static struct key_entry *key;
569 if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX)
571 count = ehotk->event_count[event % 128]++;
572 acpi_bus_generate_proc_event(ehotk->device, event, count);
573 acpi_bus_generate_netlink_event(ehotk->device->pnp.device_class,
574 dev_name(&ehotk->device->dev), event,
576 if (ehotk->inputdev) {
577 if (brn != -ENODEV) {
578 /* brightness-change events need special
579 * handling for conversion to key events
584 brn += NOTIFY_BRN_MIN;
586 event = NOTIFY_BRN_MIN; /* brightness down */
587 else if (event > brn)
588 event = NOTIFY_BRN_MIN + 2; /* ... up */
590 event = NOTIFY_BRN_MIN + 1; /* ... unchanged */
592 key = eepc_get_entry_by_scancode(event);
596 input_report_key(ehotk->inputdev, key->keycode,
598 input_sync(ehotk->inputdev);
599 input_report_key(ehotk->inputdev, key->keycode,
601 input_sync(ehotk->inputdev);
608 static int eeepc_register_rfkill_notifier(char *node)
610 acpi_status status = AE_OK;
613 status = acpi_get_handle(NULL, node, &handle);
615 if (ACPI_SUCCESS(status)) {
616 status = acpi_install_notify_handler(handle,
620 if (ACPI_FAILURE(status))
622 "Failed to register notify on %s\n", node);
629 static void eeepc_unregister_rfkill_notifier(char *node)
631 acpi_status status = AE_OK;
634 status = acpi_get_handle(NULL, node, &handle);
636 if (ACPI_SUCCESS(status)) {
637 status = acpi_remove_notify_handler(handle,
639 eeepc_rfkill_notify);
640 if (ACPI_FAILURE(status))
642 "Error removing rfkill notify handler %s\n",
647 static int eeepc_hotk_add(struct acpi_device *device)
649 acpi_status status = AE_OK;
654 printk(EEEPC_NOTICE EEEPC_HOTK_NAME "\n");
655 ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
658 ehotk->init_flag = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
659 ehotk->handle = device->handle;
660 strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
661 strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
662 device->driver_data = ehotk;
663 ehotk->device = device;
664 result = eeepc_hotk_check();
667 status = acpi_install_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
668 eeepc_hotk_notify, ehotk);
669 if (ACPI_FAILURE(status))
670 printk(EEEPC_ERR "Error installing notify handler\n");
672 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
673 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
675 if (get_acpi(CM_ASL_WLAN) != -1) {
676 ehotk->eeepc_wlan_rfkill = rfkill_alloc("eeepc-wlan",
680 (void *)CM_ASL_WLAN);
682 if (!ehotk->eeepc_wlan_rfkill)
685 rfkill_init_sw_state(ehotk->eeepc_wlan_rfkill,
686 get_acpi(CM_ASL_WLAN) != 1);
687 result = rfkill_register(ehotk->eeepc_wlan_rfkill);
692 if (get_acpi(CM_ASL_BLUETOOTH) != -1) {
693 ehotk->eeepc_bluetooth_rfkill =
694 rfkill_alloc("eeepc-bluetooth",
696 RFKILL_TYPE_BLUETOOTH,
698 (void *)CM_ASL_BLUETOOTH);
700 if (!ehotk->eeepc_bluetooth_rfkill)
703 rfkill_init_sw_state(ehotk->eeepc_bluetooth_rfkill,
704 get_acpi(CM_ASL_BLUETOOTH) != 1);
705 result = rfkill_register(ehotk->eeepc_bluetooth_rfkill);
713 rfkill_destroy(ehotk->eeepc_bluetooth_rfkill);
714 rfkill_unregister(ehotk->eeepc_wlan_rfkill);
716 rfkill_destroy(ehotk->eeepc_wlan_rfkill);
717 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
718 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
726 static int eeepc_hotk_remove(struct acpi_device *device, int type)
728 acpi_status status = 0;
730 if (!device || !acpi_driver_data(device))
732 status = acpi_remove_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
734 if (ACPI_FAILURE(status))
735 printk(EEEPC_ERR "Error removing notify handler\n");
737 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
738 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
744 static int eeepc_hotk_resume(struct acpi_device *device)
746 if (ehotk->eeepc_wlan_rfkill) {
749 /* Workaround - it seems that _PTS disables the wireless
750 without notification or changing the value read by WLAN.
751 Normally this is fine because the correct value is restored
752 from the non-volatile storage on resume, but we need to do
753 it ourself if case suspend is aborted, or we lose wireless.
755 wlan = get_acpi(CM_ASL_WLAN);
756 set_acpi(CM_ASL_WLAN, wlan);
758 rfkill_set_sw_state(ehotk->eeepc_wlan_rfkill,
761 eeepc_rfkill_hotplug();
764 if (ehotk->eeepc_bluetooth_rfkill)
765 rfkill_set_sw_state(ehotk->eeepc_bluetooth_rfkill,
766 get_acpi(CM_ASL_BLUETOOTH) != 1);
774 static int eeepc_get_fan_pwm(void)
778 read_acpi_int(NULL, EEEPC_EC_FAN_PWM, &value);
779 value = value * 255 / 100;
783 static void eeepc_set_fan_pwm(int value)
785 value = SENSORS_LIMIT(value, 0, 255);
786 value = value * 100 / 255;
787 ec_write(EEEPC_EC_SC02, value);
790 static int eeepc_get_fan_rpm(void)
795 read_acpi_int(NULL, EEEPC_EC_FAN_HRPM, &high);
796 read_acpi_int(NULL, EEEPC_EC_FAN_LRPM, &low);
797 return (high << 8 | low);
800 static int eeepc_get_fan_ctrl(void)
804 read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
805 return ((value & 0x02 ? 1 : 0));
808 static void eeepc_set_fan_ctrl(int manual)
812 read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
817 ec_write(EEEPC_EC_SFB3, value);
820 static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
824 rv = parse_arg(buf, count, &value);
830 static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
832 return sprintf(buf, "%d\n", get());
835 #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
836 static ssize_t show_##_name(struct device *dev, \
837 struct device_attribute *attr, \
840 return show_sys_hwmon(_set, buf); \
842 static ssize_t store_##_name(struct device *dev, \
843 struct device_attribute *attr, \
844 const char *buf, size_t count) \
846 return store_sys_hwmon(_get, buf, count); \
848 static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
850 EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
851 EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
852 eeepc_get_fan_pwm, eeepc_set_fan_pwm);
853 EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
854 eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
857 show_name(struct device *dev, struct device_attribute *attr, char *buf)
859 return sprintf(buf, "eeepc\n");
861 static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
863 static struct attribute *hwmon_attributes[] = {
864 &sensor_dev_attr_pwm1.dev_attr.attr,
865 &sensor_dev_attr_fan1_input.dev_attr.attr,
866 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
867 &sensor_dev_attr_name.dev_attr.attr,
871 static struct attribute_group hwmon_attribute_group = {
872 .attrs = hwmon_attributes
878 static void eeepc_backlight_exit(void)
880 if (eeepc_backlight_device)
881 backlight_device_unregister(eeepc_backlight_device);
882 eeepc_backlight_device = NULL;
885 static void eeepc_rfkill_exit(void)
887 if (ehotk->eeepc_wlan_rfkill)
888 rfkill_unregister(ehotk->eeepc_wlan_rfkill);
889 if (ehotk->eeepc_bluetooth_rfkill)
890 rfkill_unregister(ehotk->eeepc_bluetooth_rfkill);
893 static void eeepc_input_exit(void)
896 input_unregister_device(ehotk->inputdev);
899 static void eeepc_hwmon_exit(void)
901 struct device *hwmon;
903 hwmon = eeepc_hwmon_device;
906 sysfs_remove_group(&hwmon->kobj,
907 &hwmon_attribute_group);
908 hwmon_device_unregister(hwmon);
909 eeepc_hwmon_device = NULL;
912 static void __exit eeepc_laptop_exit(void)
914 eeepc_backlight_exit();
918 acpi_bus_unregister_driver(&eeepc_hotk_driver);
919 sysfs_remove_group(&platform_device->dev.kobj,
920 &platform_attribute_group);
921 platform_device_unregister(platform_device);
922 platform_driver_unregister(&platform_driver);
925 static int eeepc_backlight_init(struct device *dev)
927 struct backlight_device *bd;
929 bd = backlight_device_register(EEEPC_HOTK_FILE, dev,
933 "Could not register eeepc backlight device\n");
934 eeepc_backlight_device = NULL;
937 eeepc_backlight_device = bd;
938 bd->props.max_brightness = 15;
939 bd->props.brightness = read_brightness(NULL);
940 bd->props.power = FB_BLANK_UNBLANK;
941 backlight_update_status(bd);
945 static int eeepc_hwmon_init(struct device *dev)
947 struct device *hwmon;
950 hwmon = hwmon_device_register(dev);
953 "Could not register eeepc hwmon device\n");
954 eeepc_hwmon_device = NULL;
955 return PTR_ERR(hwmon);
957 eeepc_hwmon_device = hwmon;
958 result = sysfs_create_group(&hwmon->kobj,
959 &hwmon_attribute_group);
965 static int __init eeepc_laptop_init(void)
972 result = acpi_bus_register_driver(&eeepc_hotk_driver);
976 acpi_bus_unregister_driver(&eeepc_hotk_driver);
979 dev = acpi_get_physical_device(ehotk->device->handle);
981 if (!acpi_video_backlight_support()) {
982 result = eeepc_backlight_init(dev);
986 printk(EEEPC_INFO "Backlight controlled by ACPI video "
989 result = eeepc_hwmon_init(dev);
992 /* Register platform stuff */
993 result = platform_driver_register(&platform_driver);
995 goto fail_platform_driver;
996 platform_device = platform_device_alloc(EEEPC_HOTK_FILE, -1);
997 if (!platform_device) {
999 goto fail_platform_device1;
1001 result = platform_device_add(platform_device);
1003 goto fail_platform_device2;
1004 result = sysfs_create_group(&platform_device->dev.kobj,
1005 &platform_attribute_group);
1010 platform_device_del(platform_device);
1011 fail_platform_device2:
1012 platform_device_put(platform_device);
1013 fail_platform_device1:
1014 platform_driver_unregister(&platform_driver);
1015 fail_platform_driver:
1018 eeepc_backlight_exit();
1021 eeepc_rfkill_exit();
1025 module_init(eeepc_laptop_init);
1026 module_exit(eeepc_laptop_exit);