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, 0x12, KEY_PROG1 },
162 {KE_KEY, 0x13, KEY_MUTE },
163 {KE_KEY, 0x14, KEY_VOLUMEDOWN },
164 {KE_KEY, 0x15, KEY_VOLUMEUP },
165 {KE_KEY, 0x1a, KEY_COFFEE },
166 {KE_KEY, 0x1b, KEY_ZOOM },
167 {KE_KEY, 0x1c, KEY_PROG2 },
168 {KE_KEY, 0x1d, KEY_PROG3 },
169 {KE_KEY, 0x30, KEY_SWITCHVIDEOMODE },
170 {KE_KEY, 0x31, KEY_SWITCHVIDEOMODE },
171 {KE_KEY, 0x32, KEY_SWITCHVIDEOMODE },
176 * The hotkey driver declaration
178 static int eeepc_hotk_add(struct acpi_device *device);
179 static int eeepc_hotk_remove(struct acpi_device *device, int type);
181 static const struct acpi_device_id eeepc_device_ids[] = {
185 MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
187 static struct acpi_driver eeepc_hotk_driver = {
188 .name = EEEPC_HOTK_NAME,
189 .class = EEEPC_HOTK_CLASS,
190 .ids = eeepc_device_ids,
192 .add = eeepc_hotk_add,
193 .remove = eeepc_hotk_remove,
197 /* The backlight device /sys/class/backlight */
198 static struct backlight_device *eeepc_backlight_device;
200 /* The hwmon device */
201 static struct device *eeepc_hwmon_device;
204 * The backlight class declaration
206 static int read_brightness(struct backlight_device *bd);
207 static int update_bl_status(struct backlight_device *bd);
208 static struct backlight_ops eeepcbl_ops = {
209 .get_brightness = read_brightness,
210 .update_status = update_bl_status,
213 MODULE_AUTHOR("Corentin Chary, Eric Cooper");
214 MODULE_DESCRIPTION(EEEPC_HOTK_NAME);
215 MODULE_LICENSE("GPL");
220 static int write_acpi_int(acpi_handle handle, const char *method, int val,
221 struct acpi_buffer *output)
223 struct acpi_object_list params;
224 union acpi_object in_obj;
228 params.pointer = &in_obj;
229 in_obj.type = ACPI_TYPE_INTEGER;
230 in_obj.integer.value = val;
232 status = acpi_evaluate_object(handle, (char *)method, ¶ms, output);
233 return (status == AE_OK ? 0 : -1);
236 static int read_acpi_int(acpi_handle handle, const char *method, int *val)
239 unsigned long long result;
241 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
242 if (ACPI_FAILURE(status)) {
251 static int set_acpi(int cm, int value)
253 if (ehotk->cm_supported & (0x1 << cm)) {
254 const char *method = cm_setv[cm];
257 if (write_acpi_int(ehotk->handle, method, value, NULL))
258 printk(EEEPC_WARNING "Error writing %s\n", method);
263 static int get_acpi(int cm)
266 if ((ehotk->cm_supported & (0x1 << cm))) {
267 const char *method = cm_getv[cm];
270 if (read_acpi_int(ehotk->handle, method, &value))
271 printk(EEEPC_WARNING "Error reading %s\n", method);
279 static int read_brightness(struct backlight_device *bd)
281 return get_acpi(CM_ASL_PANELBRIGHT);
284 static int set_brightness(struct backlight_device *bd, int value)
286 value = max(0, min(15, value));
287 return set_acpi(CM_ASL_PANELBRIGHT, value);
290 static int update_bl_status(struct backlight_device *bd)
292 return set_brightness(bd, bd->props.brightness);
299 static int eeepc_wlan_rfkill_set(void *data, enum rfkill_state state)
301 if (state == RFKILL_STATE_SOFT_BLOCKED)
302 return set_acpi(CM_ASL_WLAN, 0);
304 return set_acpi(CM_ASL_WLAN, 1);
307 static int eeepc_wlan_rfkill_state(void *data, enum rfkill_state *state)
309 if (get_acpi(CM_ASL_WLAN) == 1)
310 *state = RFKILL_STATE_UNBLOCKED;
312 *state = RFKILL_STATE_SOFT_BLOCKED;
316 static int eeepc_bluetooth_rfkill_set(void *data, enum rfkill_state state)
318 if (state == RFKILL_STATE_SOFT_BLOCKED)
319 return set_acpi(CM_ASL_BLUETOOTH, 0);
321 return set_acpi(CM_ASL_BLUETOOTH, 1);
324 static int eeepc_bluetooth_rfkill_state(void *data, enum rfkill_state *state)
326 if (get_acpi(CM_ASL_BLUETOOTH) == 1)
327 *state = RFKILL_STATE_UNBLOCKED;
329 *state = RFKILL_STATE_SOFT_BLOCKED;
336 static int parse_arg(const char *buf, unsigned long count, int *val)
340 if (sscanf(buf, "%i", val) != 1)
345 static ssize_t store_sys_acpi(int cm, const char *buf, size_t count)
349 rv = parse_arg(buf, count, &value);
355 static ssize_t show_sys_acpi(int cm, char *buf)
357 return sprintf(buf, "%d\n", get_acpi(cm));
360 #define EEEPC_CREATE_DEVICE_ATTR(_name, _cm) \
361 static ssize_t show_##_name(struct device *dev, \
362 struct device_attribute *attr, \
365 return show_sys_acpi(_cm, buf); \
367 static ssize_t store_##_name(struct device *dev, \
368 struct device_attribute *attr, \
369 const char *buf, size_t count) \
371 return store_sys_acpi(_cm, buf, count); \
373 static struct device_attribute dev_attr_##_name = { \
375 .name = __stringify(_name), \
377 .show = show_##_name, \
378 .store = store_##_name, \
381 EEEPC_CREATE_DEVICE_ATTR(camera, CM_ASL_CAMERA);
382 EEEPC_CREATE_DEVICE_ATTR(cardr, CM_ASL_CARDREADER);
383 EEEPC_CREATE_DEVICE_ATTR(disp, CM_ASL_DISPLAYSWITCH);
385 static struct attribute *platform_attributes[] = {
386 &dev_attr_camera.attr,
387 &dev_attr_cardr.attr,
392 static struct attribute_group platform_attribute_group = {
393 .attrs = platform_attributes
399 static struct key_entry *eepc_get_entry_by_scancode(int code)
401 struct key_entry *key;
403 for (key = eeepc_keymap; key->type != KE_END; key++)
404 if (code == key->code)
410 static struct key_entry *eepc_get_entry_by_keycode(int code)
412 struct key_entry *key;
414 for (key = eeepc_keymap; key->type != KE_END; key++)
415 if (code == key->keycode && key->type == KE_KEY)
421 static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
423 struct key_entry *key = eepc_get_entry_by_scancode(scancode);
425 if (key && key->type == KE_KEY) {
426 *keycode = key->keycode;
433 static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
435 struct key_entry *key;
438 if (keycode < 0 || keycode > KEY_MAX)
441 key = eepc_get_entry_by_scancode(scancode);
442 if (key && key->type == KE_KEY) {
443 old_keycode = key->keycode;
444 key->keycode = keycode;
445 set_bit(keycode, dev->keybit);
446 if (!eepc_get_entry_by_keycode(old_keycode))
447 clear_bit(old_keycode, dev->keybit);
454 static int eeepc_hotk_check(void)
456 const struct key_entry *key;
457 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
460 result = acpi_bus_get_status(ehotk->device);
463 if (ehotk->device->status.present) {
464 if (write_acpi_int(ehotk->handle, "INIT", ehotk->init_flag,
466 printk(EEEPC_ERR "Hotkey initialization failed\n");
469 printk(EEEPC_NOTICE "Hotkey init flags 0x%x\n",
472 /* get control methods supported */
473 if (read_acpi_int(ehotk->handle, "CMSG"
474 , &ehotk->cm_supported)) {
476 "Get control methods supported failed\n");
480 "Get control methods supported: 0x%x\n",
481 ehotk->cm_supported);
483 ehotk->inputdev = input_allocate_device();
484 if (!ehotk->inputdev) {
485 printk(EEEPC_INFO "Unable to allocate input device\n");
488 ehotk->inputdev->name = "Asus EeePC extra buttons";
489 ehotk->inputdev->phys = EEEPC_HOTK_FILE "/input0";
490 ehotk->inputdev->id.bustype = BUS_HOST;
491 ehotk->inputdev->getkeycode = eeepc_getkeycode;
492 ehotk->inputdev->setkeycode = eeepc_setkeycode;
494 for (key = eeepc_keymap; key->type != KE_END; key++) {
497 set_bit(EV_KEY, ehotk->inputdev->evbit);
498 set_bit(key->keycode, ehotk->inputdev->keybit);
502 result = input_register_device(ehotk->inputdev);
504 printk(EEEPC_INFO "Unable to register input device\n");
505 input_free_device(ehotk->inputdev);
509 printk(EEEPC_ERR "Hotkey device not present, aborting\n");
515 static void notify_brn(void)
517 struct backlight_device *bd = eeepc_backlight_device;
519 bd->props.brightness = read_brightness(bd);
522 static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
525 struct pci_bus *bus = pci_find_bus(0, 1);
527 if (event != ACPI_NOTIFY_BUS_CHECK)
531 printk(EEEPC_WARNING "Unable to find PCI bus 1?\n");
535 if (get_acpi(CM_ASL_WLAN) == 1) {
536 dev = pci_get_slot(bus, 0);
538 /* Device already present */
542 dev = pci_scan_single_device(bus, 0);
544 pci_bus_assign_resources(bus);
545 if (pci_bus_add_device(dev))
546 printk(EEEPC_ERR "Unable to hotplug wifi\n");
549 dev = pci_get_slot(bus, 0);
551 pci_remove_bus_device(dev);
557 static void eeepc_hotk_notify(acpi_handle handle, u32 event, void *data)
559 static struct key_entry *key;
562 if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX)
564 acpi_bus_generate_netlink_event(ehotk->device->pnp.device_class,
565 dev_name(&ehotk->device->dev), event,
566 ehotk->event_count[event % 128]++);
567 if (ehotk->inputdev) {
568 key = eepc_get_entry_by_scancode(event);
572 input_report_key(ehotk->inputdev, key->keycode,
574 input_sync(ehotk->inputdev);
575 input_report_key(ehotk->inputdev, key->keycode,
577 input_sync(ehotk->inputdev);
584 static int eeepc_register_rfkill_notifier(char *node)
586 acpi_status status = AE_OK;
589 status = acpi_get_handle(NULL, node, &handle);
591 if (ACPI_SUCCESS(status)) {
592 status = acpi_install_notify_handler(handle,
596 if (ACPI_FAILURE(status))
598 "Failed to register notify on %s\n", node);
605 static void eeepc_unregister_rfkill_notifier(char *node)
607 acpi_status status = AE_OK;
610 status = acpi_get_handle(NULL, node, &handle);
612 if (ACPI_SUCCESS(status)) {
613 status = acpi_remove_notify_handler(handle,
615 eeepc_rfkill_notify);
616 if (ACPI_FAILURE(status))
618 "Error removing rfkill notify handler %s\n",
623 static int eeepc_hotk_add(struct acpi_device *device)
625 acpi_status status = AE_OK;
630 printk(EEEPC_NOTICE EEEPC_HOTK_NAME "\n");
631 ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
634 ehotk->init_flag = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
635 ehotk->handle = device->handle;
636 strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
637 strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
638 device->driver_data = ehotk;
639 ehotk->device = device;
640 result = eeepc_hotk_check();
643 status = acpi_install_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
644 eeepc_hotk_notify, ehotk);
645 if (ACPI_FAILURE(status))
646 printk(EEEPC_ERR "Error installing notify handler\n");
648 if (get_acpi(CM_ASL_WLAN) != -1) {
649 ehotk->eeepc_wlan_rfkill = rfkill_allocate(&device->dev,
652 if (!ehotk->eeepc_wlan_rfkill)
655 ehotk->eeepc_wlan_rfkill->name = "eeepc-wlan";
656 ehotk->eeepc_wlan_rfkill->toggle_radio = eeepc_wlan_rfkill_set;
657 ehotk->eeepc_wlan_rfkill->get_state = eeepc_wlan_rfkill_state;
658 if (get_acpi(CM_ASL_WLAN) == 1) {
659 ehotk->eeepc_wlan_rfkill->state =
660 RFKILL_STATE_UNBLOCKED;
661 rfkill_set_default(RFKILL_TYPE_WLAN,
662 RFKILL_STATE_UNBLOCKED);
664 ehotk->eeepc_wlan_rfkill->state =
665 RFKILL_STATE_SOFT_BLOCKED;
666 rfkill_set_default(RFKILL_TYPE_WLAN,
667 RFKILL_STATE_SOFT_BLOCKED);
669 result = rfkill_register(ehotk->eeepc_wlan_rfkill);
674 if (get_acpi(CM_ASL_BLUETOOTH) != -1) {
675 ehotk->eeepc_bluetooth_rfkill =
676 rfkill_allocate(&device->dev, RFKILL_TYPE_BLUETOOTH);
678 if (!ehotk->eeepc_bluetooth_rfkill)
681 ehotk->eeepc_bluetooth_rfkill->name = "eeepc-bluetooth";
682 ehotk->eeepc_bluetooth_rfkill->toggle_radio =
683 eeepc_bluetooth_rfkill_set;
684 ehotk->eeepc_bluetooth_rfkill->get_state =
685 eeepc_bluetooth_rfkill_state;
686 if (get_acpi(CM_ASL_BLUETOOTH) == 1) {
687 ehotk->eeepc_bluetooth_rfkill->state =
688 RFKILL_STATE_UNBLOCKED;
689 rfkill_set_default(RFKILL_TYPE_BLUETOOTH,
690 RFKILL_STATE_UNBLOCKED);
692 ehotk->eeepc_bluetooth_rfkill->state =
693 RFKILL_STATE_SOFT_BLOCKED;
694 rfkill_set_default(RFKILL_TYPE_BLUETOOTH,
695 RFKILL_STATE_SOFT_BLOCKED);
698 result = rfkill_register(ehotk->eeepc_bluetooth_rfkill);
703 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
704 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
709 if (ehotk->eeepc_bluetooth_rfkill)
710 rfkill_free(ehotk->eeepc_bluetooth_rfkill);
711 rfkill_unregister(ehotk->eeepc_wlan_rfkill);
712 ehotk->eeepc_wlan_rfkill = NULL;
714 if (ehotk->eeepc_wlan_rfkill)
715 rfkill_free(ehotk->eeepc_wlan_rfkill);
723 static int eeepc_hotk_remove(struct acpi_device *device, int type)
725 acpi_status status = 0;
727 if (!device || !acpi_driver_data(device))
729 status = acpi_remove_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
731 if (ACPI_FAILURE(status))
732 printk(EEEPC_ERR "Error removing notify handler\n");
734 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
735 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
744 static int eeepc_get_fan_pwm(void)
748 read_acpi_int(NULL, EEEPC_EC_FAN_PWM, &value);
749 value = value * 255 / 100;
753 static void eeepc_set_fan_pwm(int value)
755 value = SENSORS_LIMIT(value, 0, 255);
756 value = value * 100 / 255;
757 ec_write(EEEPC_EC_SC02, value);
760 static int eeepc_get_fan_rpm(void)
765 read_acpi_int(NULL, EEEPC_EC_FAN_HRPM, &high);
766 read_acpi_int(NULL, EEEPC_EC_FAN_LRPM, &low);
767 return (high << 8 | low);
770 static int eeepc_get_fan_ctrl(void)
774 read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
775 return ((value & 0x02 ? 1 : 0));
778 static void eeepc_set_fan_ctrl(int manual)
782 read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
787 ec_write(EEEPC_EC_SFB3, value);
790 static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
794 rv = parse_arg(buf, count, &value);
800 static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
802 return sprintf(buf, "%d\n", get());
805 #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
806 static ssize_t show_##_name(struct device *dev, \
807 struct device_attribute *attr, \
810 return show_sys_hwmon(_set, buf); \
812 static ssize_t store_##_name(struct device *dev, \
813 struct device_attribute *attr, \
814 const char *buf, size_t count) \
816 return store_sys_hwmon(_get, buf, count); \
818 static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
820 EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
821 EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
822 eeepc_get_fan_pwm, eeepc_set_fan_pwm);
823 EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
824 eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
827 show_name(struct device *dev, struct device_attribute *attr, char *buf)
829 return sprintf(buf, "eeepc\n");
831 static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
833 static struct attribute *hwmon_attributes[] = {
834 &sensor_dev_attr_pwm1.dev_attr.attr,
835 &sensor_dev_attr_fan1_input.dev_attr.attr,
836 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
837 &sensor_dev_attr_name.dev_attr.attr,
841 static struct attribute_group hwmon_attribute_group = {
842 .attrs = hwmon_attributes
848 static void eeepc_backlight_exit(void)
850 if (eeepc_backlight_device)
851 backlight_device_unregister(eeepc_backlight_device);
852 eeepc_backlight_device = NULL;
855 static void eeepc_rfkill_exit(void)
857 if (ehotk->eeepc_wlan_rfkill)
858 rfkill_unregister(ehotk->eeepc_wlan_rfkill);
859 if (ehotk->eeepc_bluetooth_rfkill)
860 rfkill_unregister(ehotk->eeepc_bluetooth_rfkill);
863 static void eeepc_input_exit(void)
866 input_unregister_device(ehotk->inputdev);
869 static void eeepc_hwmon_exit(void)
871 struct device *hwmon;
873 hwmon = eeepc_hwmon_device;
876 sysfs_remove_group(&hwmon->kobj,
877 &hwmon_attribute_group);
878 hwmon_device_unregister(hwmon);
879 eeepc_hwmon_device = NULL;
882 static void __exit eeepc_laptop_exit(void)
884 eeepc_backlight_exit();
888 acpi_bus_unregister_driver(&eeepc_hotk_driver);
889 sysfs_remove_group(&platform_device->dev.kobj,
890 &platform_attribute_group);
891 platform_device_unregister(platform_device);
892 platform_driver_unregister(&platform_driver);
895 static int eeepc_backlight_init(struct device *dev)
897 struct backlight_device *bd;
899 bd = backlight_device_register(EEEPC_HOTK_FILE, dev,
903 "Could not register eeepc backlight device\n");
904 eeepc_backlight_device = NULL;
907 eeepc_backlight_device = bd;
908 bd->props.max_brightness = 15;
909 bd->props.brightness = read_brightness(NULL);
910 bd->props.power = FB_BLANK_UNBLANK;
911 backlight_update_status(bd);
915 static int eeepc_hwmon_init(struct device *dev)
917 struct device *hwmon;
920 hwmon = hwmon_device_register(dev);
923 "Could not register eeepc hwmon device\n");
924 eeepc_hwmon_device = NULL;
925 return PTR_ERR(hwmon);
927 eeepc_hwmon_device = hwmon;
928 result = sysfs_create_group(&hwmon->kobj,
929 &hwmon_attribute_group);
935 static int __init eeepc_laptop_init(void)
942 result = acpi_bus_register_driver(&eeepc_hotk_driver);
946 acpi_bus_unregister_driver(&eeepc_hotk_driver);
949 dev = acpi_get_physical_device(ehotk->device->handle);
951 if (!acpi_video_backlight_support()) {
952 result = eeepc_backlight_init(dev);
956 printk(EEEPC_INFO "Backlight controlled by ACPI video "
959 result = eeepc_hwmon_init(dev);
962 /* Register platform stuff */
963 result = platform_driver_register(&platform_driver);
965 goto fail_platform_driver;
966 platform_device = platform_device_alloc(EEEPC_HOTK_FILE, -1);
967 if (!platform_device) {
969 goto fail_platform_device1;
971 result = platform_device_add(platform_device);
973 goto fail_platform_device2;
974 result = sysfs_create_group(&platform_device->dev.kobj,
975 &platform_attribute_group);
980 platform_device_del(platform_device);
981 fail_platform_device2:
982 platform_device_put(platform_device);
983 fail_platform_device1:
984 platform_driver_unregister(&platform_driver);
985 fail_platform_driver:
988 eeepc_backlight_exit();
995 module_init(eeepc_laptop_init);
996 module_exit(eeepc_laptop_exit);