X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fmisc%2Fasus-laptop.c;h=d15ee5e3420138481dd2a8e803eb86931ef2db13;hb=dfcba200679dc3f62212154b65b40b835ce69ab7;hp=58ab44dc52d8d07974bfee90453f4fa210928c09;hpb=6b7091e74fe176da97917ca60524e2b3554305f0;p=linux-2.6-omap-h63xx.git diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c index 58ab44dc52d..d15ee5e3420 100644 --- a/drivers/misc/asus-laptop.c +++ b/drivers/misc/asus-laptop.c @@ -79,9 +79,9 @@ #define BT_ON 0x02 //internal Bluetooth #define MLED_ON 0x04 //mail LED #define TLED_ON 0x08 //touchpad LED -#define RLED_ON 0x10 //Record LED -#define PLED_ON 0x20 //Phone LED -#define LCD_ON 0x40 //LCD backlight +#define RLED_ON 0x10 //Record LED +#define PLED_ON 0x20 //Phone LED +#define LCD_ON 0x40 //LCD backlight #define ASUS_LOG ASUS_HOTK_FILE ": " #define ASUS_ERR KERN_ERR ASUS_LOG @@ -101,8 +101,11 @@ MODULE_LICENSE("GPL"); /* LED */ ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED"); ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED"); -ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */ -ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */ +ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */ +ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */ + +/* LEDD */ +ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM"); /* Bluetooth and WLAN * WLED and BLED are not handled like other XLED, because in some dsdt @@ -110,30 +113,52 @@ ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */ */ ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED"); ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED"); -ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */ +ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */ /* Brightness */ ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV"); ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV"); /* Backlight */ -ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */ - "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */ - "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */ - "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */ - "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */ - "\\_SB.PCI0.PX40.Q10", /* S1x */ - "\\Q10"); /* A2x, L2D, L3D, M2E */ +ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */ + "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */ + "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */ + "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */ + "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */ + "\\_SB.PCI0.PX40.Q10", /* S1x */ + "\\Q10"); /* A2x, L2D, L3D, M2E */ + +/* Display */ +ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP"); +ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G + M6A M6V VX-1 V6J V6V W3Z */ + "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V + S5A M5A z33A W1Jc W2V */ + "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */ + "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */ + "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */ + "\\_SB.PCI0.VGA.GETD", /* Z96F */ + "\\ACTD", /* A2D */ + "\\ADVG", /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */ + "\\DNXT", /* P30 */ + "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */ + "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */ + +ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */ +ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */ /* * This is the main structure, we can use it to store anything interesting * about the hotk device */ struct asus_hotk { - char *name; //laptop name + char *name; //laptop name struct acpi_device *device; //the device we are in acpi_handle handle; //the handle of the hotk device char status; //status of the hotk, for LEDs, ... + u32 ledd_status; //status of the LED display + u8 light_level; //light sensor level + u8 light_switch; //light sensor switch value u16 event_count[128]; //count for each event TODO make this better }; @@ -171,10 +196,9 @@ static struct backlight_device *asus_backlight_device; static int read_brightness(struct backlight_device *bd); static int update_bl_status(struct backlight_device *bd); static struct backlight_properties asusbl_data = { - .owner = THIS_MODULE, - .get_brightness = read_brightness, - .update_status = update_bl_status, - .max_brightness = 15, + .get_brightness = read_brightness, + .update_status = update_bl_status, + .max_brightness = 15, }; /* These functions actually update the LED's, and are called from a @@ -237,7 +261,8 @@ static int read_acpi_int(acpi_handle handle, const char *method, int *val, return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER); } -static int read_wireless_status(int mask) { +static int read_wireless_status(int mask) +{ int status; if (!wireless_status_handle) @@ -261,8 +286,7 @@ static int read_status(int mask) return (hotk->status & mask) ? 1 : 0; } -static void write_status(acpi_handle handle, int out, int mask, - int invert) +static void write_status(acpi_handle handle, int out, int mask, int invert) { hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask); @@ -307,7 +331,7 @@ static int set_lcd_state(int value) if (lcd == get_lcd_state()) return 0; - if(lcd_switch_handle) { + if (lcd_switch_handle) { status = acpi_evaluate_object(lcd_switch_handle, NULL, NULL, NULL); @@ -323,12 +347,12 @@ static void lcd_blank(int blank) { struct backlight_device *bd = asus_backlight_device; - if(bd) { + if (bd) { down(&bd->sem); - if(likely(bd->props)) { + if (likely(bd->props)) { bd->props->power = blank; - if(likely(bd->props->update_status)) - bd->props->update_status(bd); + if (likely(bd->props->update_status)) + bd->props->update_status(bd); } up(&bd->sem); } @@ -365,7 +389,7 @@ static int update_bl_status(struct backlight_device *bd) int value = bd->props->brightness; rv = set_brightness(bd, value); - if(rv) + if (rv) return rv; value = (bd->props->power == FB_BLANK_UNBLANK) ? 1 : 0; @@ -382,7 +406,7 @@ static int update_bl_status(struct backlight_device *bd) * number of bytes written in page */ static ssize_t show_infos(struct device *dev, - struct device_attribute *attr, char *page) + struct device_attribute *attr, char *page) { int len = 0; int temp; @@ -461,6 +485,30 @@ static ssize_t store_status(const char *buf, size_t count, return rv; } +/* + * LEDD display + */ +static ssize_t show_ledd(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "0x%08x\n", hotk->ledd_status); +} + +static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int rv, value; + + rv = parse_arg(buf, count, &value); + if (rv > 0) { + if (!write_acpi_int(ledd_set_handle, NULL, value, NULL)) + printk(ASUS_WARNING "LED display write failed\n"); + else + hotk->ledd_status = (u32) value; + } + return rv; +} + /* * WLAN */ @@ -485,12 +533,124 @@ static ssize_t show_bluetooth(struct device *dev, return sprintf(buf, "%d\n", read_status(BT_ON)); } -static ssize_t store_bluetooth(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t store_bluetooth(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) { return store_status(buf, count, bt_switch_handle, BT_ON, 0); } +/* + * Display + */ +static void set_display(int value) +{ + /* no sanity check needed for now */ + if (!write_acpi_int(display_set_handle, NULL, value, NULL)) + printk(ASUS_WARNING "Error setting display\n"); + return; +} + +static int read_display(void) +{ + int value = 0; + + /* In most of the case, we know how to set the display, but sometime + we can't read it */ + if (display_get_handle) { + if (!read_acpi_int(display_get_handle, NULL, &value, NULL)) + printk(ASUS_WARNING "Error reading display status\n"); + } + + value &= 0x0F; /* needed for some models, shouldn't hurt others */ + + return value; +} + +/* + * Now, *this* one could be more user-friendly, but so far, no-one has + * complained. The significance of bits is the same as in store_disp() + */ +static ssize_t show_disp(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", read_display()); +} + +/* + * Experimental support for display switching. As of now: 1 should activate + * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI. + * Any combination (bitwise) of these will suffice. I never actually tested 4 + * displays hooked up simultaneously, so be warned. See the acpi4asus README + * for more info. + */ +static ssize_t store_disp(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int rv, value; + + rv = parse_arg(buf, count, &value); + if (rv > 0) + set_display(value); + return rv; +} + +/* + * Light Sens + */ +static void set_light_sens_switch(int value) +{ + if (!write_acpi_int(ls_switch_handle, NULL, value, NULL)) + printk(ASUS_WARNING "Error setting light sensor switch\n"); + hotk->light_switch = value; +} + +static ssize_t show_lssw(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", hotk->light_switch); +} + +static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int rv, value; + + rv = parse_arg(buf, count, &value); + if (rv > 0) + set_light_sens_switch(value ? 1 : 0); + + return rv; +} + +static void set_light_sens_level(int value) +{ + if (!write_acpi_int(ls_level_handle, NULL, value, NULL)) + printk(ASUS_WARNING "Error setting light sensor level\n"); + hotk->light_level = value; +} + +static ssize_t show_lslvl(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", hotk->light_level); +} + +static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int rv, value; + + rv = parse_arg(buf, count, &value); + if (rv > 0) { + value = (0 < value) ? ((15 < value) ? 15 : value) : 0; + /* 0 <= value <= 15 */ + set_light_sens_level(value); + } + + return rv; +} + static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) { /* TODO Find a better way to handle events count. */ @@ -504,7 +664,7 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) if (event == ATKD_LCD_ON) { write_status(NULL, 1, LCD_ON, 0); lcd_blank(FB_BLANK_UNBLANK); - } else if(event == ATKD_LCD_OFF) { + } else if (event == ATKD_LCD_OFF) { write_status(NULL, 0, LCD_ON, 0); lcd_blank(FB_BLANK_POWERDOWN); } @@ -535,28 +695,35 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) static ASUS_CREATE_DEVICE_ATTR(infos); static ASUS_CREATE_DEVICE_ATTR(wlan); static ASUS_CREATE_DEVICE_ATTR(bluetooth); +static ASUS_CREATE_DEVICE_ATTR(display); +static ASUS_CREATE_DEVICE_ATTR(ledd); +static ASUS_CREATE_DEVICE_ATTR(ls_switch); +static ASUS_CREATE_DEVICE_ATTR(ls_level); static struct attribute *asuspf_attributes[] = { - &dev_attr_infos.attr, - &dev_attr_wlan.attr, - &dev_attr_bluetooth.attr, - NULL + &dev_attr_infos.attr, + &dev_attr_wlan.attr, + &dev_attr_bluetooth.attr, + &dev_attr_display.attr, + &dev_attr_ledd.attr, + &dev_attr_ls_switch.attr, + &dev_attr_ls_level.attr, + NULL }; static struct attribute_group asuspf_attribute_group = { - .attrs = asuspf_attributes + .attrs = asuspf_attributes }; static struct platform_driver asuspf_driver = { - .driver = { - .name = ASUS_HOTK_FILE, - .owner = THIS_MODULE, - } + .driver = { + .name = ASUS_HOTK_FILE, + .owner = THIS_MODULE, + } }; static struct platform_device *asuspf_device; - static void asus_hotk_add_fs(void) { ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL); @@ -567,9 +734,22 @@ static void asus_hotk_add_fs(void) if (bt_switch_handle) ASUS_SET_DEVICE_ATTR(bluetooth, 0644, show_bluetooth, store_bluetooth); + + if (display_set_handle && display_get_handle) + ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp); + else if (display_set_handle) + ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp); + + if (ledd_set_handle) + ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd); + + if (ls_switch_handle && ls_level_handle) { + ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl); + ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw); + } } -static int asus_handle_init(char *name, acpi_handle *handle, +static int asus_handle_init(char *name, acpi_handle * handle, char **paths, int num_paths) { int i; @@ -589,7 +769,6 @@ static int asus_handle_init(char *name, acpi_handle *handle, asus_handle_init(#object, &object##_handle, object##_paths, \ ARRAY_SIZE(object##_paths)) - /* * This function is used to initialize the hotk with right values. In this * method, we can make all the detection we want, and modify the hotk struct @@ -597,7 +776,6 @@ static int asus_handle_init(char *name, acpi_handle *handle, static int asus_hotk_get_info(void) { struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *model = NULL; int bsts_result, hwrs_result; char *string = NULL; @@ -611,11 +789,9 @@ static int asus_hotk_get_info(void) * HID), this bit will be moved. A global variable asus_info contains * the DSDT header. */ - status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt); + status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info); if (ACPI_FAILURE(status)) printk(ASUS_WARNING "Couldn't get the DSDT table header\n"); - else - asus_info = dsdt.pointer; /* We have to write 0 on init this far for all ASUS models */ if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { @@ -654,7 +830,7 @@ static int asus_hotk_get_info(void) if (!hotk->name) return -ENOMEM; - if(*string) + if (*string) printk(ASUS_NOTICE " %s model detected\n", string); ASUS_HANDLE_INIT(mled_set); @@ -662,6 +838,8 @@ static int asus_hotk_get_info(void) ASUS_HANDLE_INIT(rled_set); ASUS_HANDLE_INIT(pled_set); + ASUS_HANDLE_INIT(ledd_set); + /* * The HWRS method return informations about the hardware. * 0x80 bit is for WLAN, 0x100 for Bluetooth. @@ -671,9 +849,9 @@ static int asus_hotk_get_info(void) if (!read_acpi_int(hotk->handle, "HRWS", &hwrs_result, NULL)) hwrs_result = WL_HWRS | BT_HWRS; - if(hwrs_result & WL_HWRS) + if (hwrs_result & WL_HWRS) ASUS_HANDLE_INIT(wl_switch); - if(hwrs_result & BT_HWRS) + if (hwrs_result & BT_HWRS) ASUS_HANDLE_INIT(bt_switch); ASUS_HANDLE_INIT(wireless_status); @@ -683,6 +861,14 @@ static int asus_hotk_get_info(void) ASUS_HANDLE_INIT(lcd_switch); + ASUS_HANDLE_INIT(display_set); + ASUS_HANDLE_INIT(display_get); + + /* There is a lot of models with "ALSL", but a few get + a real light sens, so we need to check it. */ + if (ASUS_HANDLE_INIT(ls_switch)) + ASUS_HANDLE_INIT(ls_level); + kfree(model); return AE_OK; @@ -754,6 +940,19 @@ static int asus_hotk_add(struct acpi_device *device) /* LCD Backlight is on by default */ write_status(NULL, 1, LCD_ON, 0); + /* LED display is off by default */ + hotk->ledd_status = 0xFFF; + + /* Set initial values of light sensor and level */ + hotk->light_switch = 1; /* Default to light sensor disabled */ + hotk->light_level = 0; /* level 5 for sensor sensitivity */ + + if (ls_switch_handle) + set_light_sens_switch(hotk->light_switch); + + if (ls_level_handle) + set_light_sens_level(hotk->light_level); + end: if (result) { kfree(hotk->name); @@ -783,7 +982,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type) static void asus_backlight_exit(void) { - if(asus_backlight_device) + if (asus_backlight_device) backlight_device_unregister(asus_backlight_device); } @@ -808,21 +1007,19 @@ static void __exit asus_laptop_exit(void) asus_led_exit(); acpi_bus_unregister_driver(&asus_hotk_driver); - sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group); - platform_device_unregister(asuspf_device); - platform_driver_unregister(&asuspf_driver); - - kfree(asus_info); + sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group); + platform_device_unregister(asuspf_device); + platform_driver_unregister(&asuspf_driver); } -static int asus_backlight_init(struct device * dev) +static int asus_backlight_init(struct device *dev) { struct backlight_device *bd; - if(brightness_set_handle && lcd_switch_handle) { - bd = backlight_device_register (ASUS_HOTK_FILE, dev, - NULL, &asusbl_data); - if (IS_ERR (bd)) { + if (brightness_set_handle && lcd_switch_handle) { + bd = backlight_device_register(ASUS_HOTK_FILE, dev, + NULL, &asusbl_data); + if (IS_ERR(bd)) { printk(ASUS_ERR "Could not register asus backlight device\n"); asus_backlight_device = NULL; @@ -832,11 +1029,11 @@ static int asus_backlight_init(struct device * dev) asus_backlight_device = bd; down(&bd->sem); - if(likely(bd->props)) { + if (likely(bd->props)) { bd->props->brightness = read_brightness(NULL); bd->props->power = FB_BLANK_UNBLANK; - if(likely(bd->props->update_status)) - bd->props->update_status(bd); + if (likely(bd->props->update_status)) + bd->props->update_status(bd); } up(&bd->sem); } @@ -844,39 +1041,39 @@ static int asus_backlight_init(struct device * dev) } static int asus_led_register(acpi_handle handle, - struct led_classdev * ldev, - struct device * dev) + struct led_classdev *ldev, struct device *dev) { - if(!handle) + if (!handle) return 0; return led_classdev_register(dev, ldev); } + #define ASUS_LED_REGISTER(object, device) \ asus_led_register(object##_set_handle, &object##_led, device) -static int asus_led_init(struct device * dev) +static int asus_led_init(struct device *dev) { int rv; rv = ASUS_LED_REGISTER(mled, dev); - if(rv) + if (rv) return rv; rv = ASUS_LED_REGISTER(tled, dev); - if(rv) + if (rv) return rv; rv = ASUS_LED_REGISTER(rled, dev); - if(rv) + if (rv) return rv; rv = ASUS_LED_REGISTER(pled, dev); - if(rv) + if (rv) return rv; led_workqueue = create_singlethread_workqueue("led_workqueue"); - if(!led_workqueue) + if (!led_workqueue) return -ENOMEM; return 0; @@ -890,11 +1087,6 @@ static int __init asus_laptop_init(void) if (acpi_disabled) return -ENODEV; - if (!acpi_specific_hotkey_enabled) { - printk(ASUS_ERR "Using generic hotkey driver\n"); - return -ENODEV; - } - result = acpi_bus_register_driver(&asus_hotk_driver); if (result < 0) return result; @@ -914,51 +1106,51 @@ static int __init asus_laptop_init(void) dev = acpi_get_physical_device(hotk->device->handle); result = asus_backlight_init(dev); - if(result) + if (result) goto fail_backlight; result = asus_led_init(dev); - if(result) + if (result) goto fail_led; - /* Register platform stuff */ + /* Register platform stuff */ result = platform_driver_register(&asuspf_driver); - if (result) - goto fail_platform_driver; + if (result) + goto fail_platform_driver; - asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1); - if (!asuspf_device) { - result = -ENOMEM; - goto fail_platform_device1; - } + asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1); + if (!asuspf_device) { + result = -ENOMEM; + goto fail_platform_device1; + } - result = platform_device_add(asuspf_device); - if (result) - goto fail_platform_device2; + result = platform_device_add(asuspf_device); + if (result) + goto fail_platform_device2; - result = sysfs_create_group(&asuspf_device->dev.kobj, + result = sysfs_create_group(&asuspf_device->dev.kobj, &asuspf_attribute_group); - if (result) - goto fail_sysfs; + if (result) + goto fail_sysfs; - return 0; + return 0; -fail_sysfs: - platform_device_del(asuspf_device); + fail_sysfs: + platform_device_del(asuspf_device); -fail_platform_device2: + fail_platform_device2: platform_device_put(asuspf_device); -fail_platform_device1: - platform_driver_unregister(&asuspf_driver); + fail_platform_device1: + platform_driver_unregister(&asuspf_driver); -fail_platform_driver: + fail_platform_driver: asus_led_exit(); -fail_led: + fail_led: asus_backlight_exit(); -fail_backlight: + fail_backlight: return result; }