eeepc-wmi: add keys found on EeePC 1215T
[linux-flexiantxendom0-natty.git] / drivers / platform / x86 / eeepc-wmi.c
index 75dd692..6afd643 100644 (file)
@@ -65,21 +65,36 @@ MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID);
 #define NOTIFY_BRNDOWN_MIN             0x20
 #define NOTIFY_BRNDOWN_MAX             0x2e
 
+/* WMI Methods */
 #define EEEPC_WMI_METHODID_DSTS                0x53544344
 #define EEEPC_WMI_METHODID_DEVS                0x53564544
 #define EEEPC_WMI_METHODID_CFVS                0x53564643
 
+/* Wireless */
 #define EEEPC_WMI_DEVID_WLAN           0x00010011
 #define EEEPC_WMI_DEVID_BLUETOOTH      0x00010013
 #define EEEPC_WMI_DEVID_WIMAX          0x00010017
 #define EEEPC_WMI_DEVID_WWAN3G         0x00010019
-#define EEEPC_WMI_DEVID_BACKLIGHT      0x00050012
+
+/* Backlight and Brightness */
+#define EEEPC_WMI_DEVID_BACKLIGHT      0x00050011
+#define EEEPC_WMI_DEVID_BRIGHTNESS     0x00050012
+
+/* Misc */
 #define EEEPC_WMI_DEVID_CAMERA         0x00060013
+
+/* Storage */
 #define EEEPC_WMI_DEVID_CARDREADER     0x00080013
-#define EEEPC_WMI_DEVID_TPDLED         0x00100011
 
+/* Input */
+#define EEEPC_WMI_DEVID_TOUCHPAD       0x00100011
+#define EEEPC_WMI_DEVID_TOUCHPAD_LED   0x00100012
+
+/* DSTS masks */
 #define EEEPC_WMI_DSTS_STATUS_BIT      0x00000001
 #define EEEPC_WMI_DSTS_PRESENCE_BIT    0x00010000
+#define EEEPC_WMI_DSTS_BRIGHTNESS_MASK 0x000000FF
+#define EEEPC_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00
 
 static bool hotplug_wireless;
 
@@ -89,6 +104,13 @@ MODULE_PARM_DESC(hotplug_wireless,
                 "If your laptop needs that, please report to "
                 "acpi4asus-user@lists.sourceforge.net.");
 
+/* Values for T101MT "Home" key */
+#define HOME_PRESS                     0xe4
+#define HOME_HOLD                      0xea
+#define HOME_RELEASE                   0xe5
+
+#define EEEPC_WMI_KEY_IGNORE (-1)
+
 static const struct key_entry eeepc_wmi_keymap[] = {
        /* Sleep already handled via generic ACPI code */
        { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
@@ -96,13 +118,16 @@ static const struct key_entry eeepc_wmi_keymap[] = {
        { KE_KEY, 0x30, { KEY_VOLUMEUP } },
        { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
        { KE_KEY, 0x32, { KEY_MUTE } },
-       { KE_KEY, 0x5c, { KEY_F15 } },
+       { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */
        { KE_KEY, 0x5d, { KEY_WLAN } },
        { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */
        { KE_KEY, 0x88, { KEY_WLAN } },
+       { KE_KEY, 0xbd, { KEY_CAMERA } },
        { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
-       { KE_KEY, 0xe0, { KEY_PROG1 } },
-       { KE_KEY, 0xe1, { KEY_F14 } },
+       { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */
+       { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */
+       { KE_KEY, HOME_PRESS, { KEY_CONFIG } },
+       { KE_KEY, 0xe8, { KEY_SCREENLOCK } },
        { KE_KEY, 0xe9, { KEY_BRIGHTNESS_ZERO } },
        { KE_END, 0},
 };
@@ -163,6 +188,7 @@ static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc)
        eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0";
        eeepc->inputdev->id.bustype = BUS_HOST;
        eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
+       __set_bit(EV_REP, eeepc->inputdev->evbit);
 
        err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL);
        if (err)
@@ -262,7 +288,7 @@ static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
 }
 
 /* Helper for special devices with magic return codes */
-static int eeepc_wmi_get_devstate_simple(u32 dev_id)
+static int eeepc_wmi_get_devstate_bits(u32 dev_id, u32 mask)
 {
        u32 retval = 0;
        acpi_status status;
@@ -275,7 +301,12 @@ static int eeepc_wmi_get_devstate_simple(u32 dev_id)
        if (!(retval & EEEPC_WMI_DSTS_PRESENCE_BIT))
                return -ENODEV;
 
-       return retval & EEEPC_WMI_DSTS_STATUS_BIT;
+       return retval & mask;
+}
+
+static int eeepc_wmi_get_devstate_simple(u32 dev_id)
+{
+       return eeepc_wmi_get_devstate_bits(dev_id, EEEPC_WMI_DSTS_STATUS_BIT);
 }
 
 /*
@@ -295,7 +326,7 @@ static void tpd_led_update(struct work_struct *work)
        eeepc = container_of(work, struct eeepc_wmi, tpd_led_work);
 
        ctrl_param = eeepc->tpd_led_wk;
-       eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TPDLED, ctrl_param, NULL);
+       eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL);
 }
 
 static void tpd_led_set(struct led_classdev *led_cdev,
@@ -309,9 +340,9 @@ static void tpd_led_set(struct led_classdev *led_cdev,
        queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
 }
 
-static int read_tpd_state(struct eeepc_wmi *eeepc)
+static int read_tpd_led_state(struct eeepc_wmi *eeepc)
 {
-       return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TPDLED);
+       return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TOUCHPAD_LED);
 }
 
 static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
@@ -320,14 +351,14 @@ static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
 
        eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
 
-       return read_tpd_state(eeepc);
+       return read_tpd_led_state(eeepc);
 }
 
 static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc)
 {
        int rv;
 
-       if (read_tpd_state(eeepc) < 0)
+       if (read_tpd_led_state(eeepc) < 0)
                return 0;
 
        eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
@@ -740,6 +771,9 @@ static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc)
        if (result && result != -ENODEV)
                goto exit;
 
+       if (!eeepc->hotplug_wireless)
+               goto exit;
+
        result = eeepc_setup_pci_hotplug(eeepc);
        /*
         * If we get -EBUSY then something else is handling the PCI hotplug -
@@ -770,34 +804,53 @@ exit:
 /*
  * Backlight
  */
+static int read_backlight_power(void)
+{
+       int ret = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_BACKLIGHT);
+
+       if (ret < 0)
+               return ret;
+
+       return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
+}
+
 static int read_brightness(struct backlight_device *bd)
 {
        u32 retval;
        acpi_status status;
 
-       status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &retval);
+       status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BRIGHTNESS, &retval);
 
        if (ACPI_FAILURE(status))
-               return -1;
+               return -EIO;
        else
-               return retval & 0xFF;
+               return retval & EEEPC_WMI_DSTS_BRIGHTNESS_MASK;
 }
 
 static int update_bl_status(struct backlight_device *bd)
 {
-
        u32 ctrl_param;
        acpi_status status;
+       int power;
 
        ctrl_param = bd->props.brightness;
 
-       status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT,
+       status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BRIGHTNESS,
                                        ctrl_param, NULL);
 
        if (ACPI_FAILURE(status))
-               return -1;
-       else
-               return 0;
+               return -EIO;
+
+       power = read_backlight_power();
+       if (power != -ENODEV && bd->props.power != power) {
+               ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK);
+               status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT,
+                                               ctrl_param, NULL);
+
+               if (ACPI_FAILURE(status))
+                       return -EIO;
+       }
+       return 0;
 }
 
 static const struct backlight_ops eeepc_wmi_bl_ops = {
@@ -827,9 +880,29 @@ static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc)
 {
        struct backlight_device *bd;
        struct backlight_properties props;
+       int max;
+       int power;
+
+       max = eeepc_wmi_get_devstate_bits(EEEPC_WMI_DEVID_BRIGHTNESS,
+                                         EEEPC_WMI_DSTS_MAX_BRIGTH_MASK);
+       power = read_backlight_power();
+
+       if (max < 0 && power < 0) {
+               /* Try to keep the original error */
+               if (max == -ENODEV && power == -ENODEV)
+                       return -ENODEV;
+               if (max != -ENODEV)
+                       return max;
+               else
+                       return power;
+       }
+       if (max == -ENODEV)
+               max = 0;
+       if (power == -ENODEV)
+               power = FB_BLANK_UNBLANK;
 
        memset(&props, 0, sizeof(struct backlight_properties));
-       props.max_brightness = 15;
+       props.max_brightness = max;
        bd = backlight_device_register(EEEPC_WMI_FILE,
                                       &eeepc->platform_device->dev, eeepc,
                                       &eeepc_wmi_bl_ops, &props);
@@ -841,7 +914,7 @@ static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc)
        eeepc->backlight_device = bd;
 
        bd->props.brightness = read_brightness(bd);
-       bd->props.power = FB_BLANK_UNBLANK;
+       bd->props.power = power;
        backlight_update_status(bd);
 
        return 0;
@@ -855,6 +928,25 @@ static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc)
        eeepc->backlight_device = NULL;
 }
 
+static void eeepc_wmi_homekey_filter(struct eeepc_wmi *eeepc, int *code,
+                                    unsigned int *value, bool *autorelease)
+{
+       switch (*code) {
+       case HOME_PRESS:
+               *value = 1;
+               *autorelease = 0;
+               break;
+       case HOME_HOLD:
+               *code = EEEPC_WMI_KEY_IGNORE;
+               break;
+       case HOME_RELEASE:
+               *code = HOME_PRESS;
+               *value = 0;
+               *autorelease = 0;
+               break;
+       }
+}
+
 static void eeepc_wmi_notify(u32 value, void *context)
 {
        struct eeepc_wmi *eeepc = context;
@@ -863,6 +955,8 @@ static void eeepc_wmi_notify(u32 value, void *context)
        acpi_status status;
        int code;
        int orig_code;
+       unsigned int key_value = 1;
+       bool autorelease = 1;
 
        status = wmi_get_event_data(value, &response);
        if (status != AE_OK) {
@@ -876,6 +970,11 @@ static void eeepc_wmi_notify(u32 value, void *context)
                code = obj->integer.value;
                orig_code = code;
 
+               eeepc_wmi_homekey_filter(eeepc, &code, &key_value,
+                                        &autorelease);
+               if (code == EEEPC_WMI_KEY_IGNORE)
+                       goto exit;
+
                if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
                        code = NOTIFY_BRNUP_MIN;
                else if (code >= NOTIFY_BRNDOWN_MIN &&
@@ -887,11 +986,12 @@ static void eeepc_wmi_notify(u32 value, void *context)
                                eeepc_wmi_backlight_notify(eeepc, orig_code);
                }
 
-               if (!sparse_keymap_report_event(eeepc->inputdev,
-                                               code, 1, true))
+               if (!sparse_keymap_report_event(eeepc->inputdev, code,
+                                               key_value, autorelease))
                        pr_info("Unknown key %x pressed\n", code);
        }
 
+exit:
        kfree(obj);
 }
 
@@ -956,6 +1056,7 @@ static ssize_t show_sys_wmi(int devid, char *buf)
                .store  = store_##_name,                                \
        }
 
+EEEPC_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, EEEPC_WMI_DEVID_TOUCHPAD);
 EEEPC_WMI_CREATE_DEVICE_ATTR(camera, 0644, EEEPC_WMI_DEVID_CAMERA);
 EEEPC_WMI_CREATE_DEVICE_ATTR(cardr, 0644, EEEPC_WMI_DEVID_CARDREADER);
 
@@ -986,6 +1087,7 @@ static struct attribute *platform_attributes[] = {
        &dev_attr_cpufv.attr,
        &dev_attr_camera.attr,
        &dev_attr_cardr.attr,
+       &dev_attr_touchpad.attr,
        NULL
 };
 
@@ -1000,6 +1102,8 @@ static mode_t eeepc_sysfs_is_visible(struct kobject *kobj,
                devid = EEEPC_WMI_DEVID_CAMERA;
        else if (attr == &dev_attr_cardr.attr)
                devid = EEEPC_WMI_DEVID_CARDREADER;
+       else if (attr == &dev_attr_touchpad.attr)
+               devid = EEEPC_WMI_DEVID_TOUCHPAD;
 
        if (devid != -1)
                supported = eeepc_wmi_get_devstate_simple(devid) != -ENODEV;
@@ -1202,7 +1306,7 @@ static int __init eeepc_wmi_add(struct platform_device *pdev)
 
        if (!acpi_video_backlight_support()) {
                err = eeepc_wmi_backlight_init(eeepc);
-               if (err)
+               if (err && err != -ENODEV)
                        goto fail_backlight;
        } else
                pr_info("Backlight controlled by ACPI video driver\n");