acer-wmi: schedule threeg and interface sysfs for feature removal
[linux-2.6.git] / drivers / platform / x86 / acer-wmi.c
index d798314..089db86 100644 (file)
@@ -89,7 +89,7 @@ MODULE_LICENSE("GPL");
 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
 
 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
-MODULE_ALIAS("wmi:6AF4F258-B401-42Fd-BE91-3D4AC2D7C0D3");
+MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
 
 enum acer_wmi_event_ids {
@@ -98,13 +98,26 @@ enum acer_wmi_event_ids {
 
 static const struct key_entry acer_wmi_keymap[] = {
        {KE_KEY, 0x01, {KEY_WLAN} },     /* WiFi */
+       {KE_KEY, 0x03, {KEY_WLAN} },     /* WiFi */
        {KE_KEY, 0x12, {KEY_BLUETOOTH} },       /* BT */
        {KE_KEY, 0x21, {KEY_PROG1} },    /* Backup */
        {KE_KEY, 0x22, {KEY_PROG2} },    /* Arcade */
        {KE_KEY, 0x23, {KEY_PROG3} },    /* P_Key */
        {KE_KEY, 0x24, {KEY_PROG4} },    /* Social networking_Key */
+       {KE_IGNORE, 0x41, {KEY_MUTE} },
+       {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
+       {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
+       {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
+       {KE_IGNORE, 0x45, {KEY_STOP} },
+       {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
+       {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
+       {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
+       {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
+       {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
        {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
+       {KE_IGNORE, 0x81, {KEY_SLEEP} },
        {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
+       {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
        {KE_END, 0}
 };
 
@@ -122,6 +135,7 @@ struct event_return_value {
  */
 #define ACER_WMID3_GDS_WIRELESS                (1<<0)  /* WiFi */
 #define ACER_WMID3_GDS_THREEG          (1<<6)  /* 3G */
+#define ACER_WMID3_GDS_WIMAX           (1<<7)  /* WiMAX */
 #define ACER_WMID3_GDS_BLUETOOTH       (1<<11) /* BT */
 
 struct lm_input_params {
@@ -217,6 +231,7 @@ struct acer_debug {
 static struct rfkill *wireless_rfkill;
 static struct rfkill *bluetooth_rfkill;
 static struct rfkill *threeg_rfkill;
+static bool rfkill_inited;
 
 /* Each low-level interface must define at least some of the following */
 struct wmi_interface {
@@ -736,8 +751,11 @@ WMI_execute_u32(u32 method_id, u32 in, u32 *out)
 
        obj = (union acpi_object *) result.pointer;
        if (obj && obj->type == ACPI_TYPE_BUFFER &&
-               obj->buffer.length == sizeof(u32)) {
+               (obj->buffer.length == sizeof(u32) ||
+               obj->buffer.length == sizeof(u64))) {
                tmp = *((u32 *) obj->buffer.pointer);
+       } else if (obj->type == ACPI_TYPE_INTEGER) {
+               tmp = (u32) obj->integer.value;
        } else {
                tmp = 0;
        }
@@ -865,8 +883,11 @@ static acpi_status WMID_set_capabilities(void)
 
        obj = (union acpi_object *) out.pointer;
        if (obj && obj->type == ACPI_TYPE_BUFFER &&
-               obj->buffer.length == sizeof(u32)) {
+               (obj->buffer.length == sizeof(u32) ||
+               obj->buffer.length == sizeof(u64))) {
                devices = *((u32 *) obj->buffer.pointer);
+       } else if (obj->type == ACPI_TYPE_INTEGER) {
+               devices = (u32) obj->integer.value;
        } else {
                kfree(out.pointer);
                return AE_ERROR;
@@ -875,7 +896,8 @@ static acpi_status WMID_set_capabilities(void)
        dmi_walk(type_aa_dmi_decode, NULL);
        if (!has_type_aa) {
                interface->capability |= ACER_CAP_WIRELESS;
-               interface->capability |= ACER_CAP_THREEG;
+               if (devices & 0x40)
+                       interface->capability |= ACER_CAP_THREEG;
                if (devices & 0x10)
                        interface->capability |= ACER_CAP_BLUETOOTH;
        }
@@ -960,10 +982,12 @@ static void __init acer_commandline_init(void)
         * These will all fail silently if the value given is invalid, or the
         * capability isn't available on the given interface
         */
-       set_u32(mailled, ACER_CAP_MAILLED);
-       if (!has_type_aa)
+       if (mailled >= 0)
+               set_u32(mailled, ACER_CAP_MAILLED);
+       if (!has_type_aa && threeg >= 0)
                set_u32(threeg, ACER_CAP_THREEG);
-       set_u32(brightness, ACER_CAP_BRIGHTNESS);
+       if (brightness >= 0)
+               set_u32(brightness, ACER_CAP_BRIGHTNESS);
 }
 
 /*
@@ -1080,7 +1104,7 @@ static acpi_status wmid3_get_device_status(u32 *value, u16 device)
                return AE_ERROR;
        }
        if (obj->buffer.length != 8) {
-               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
+               pr_warn("Unknown buffer length %d\n", obj->buffer.length);
                kfree(obj);
                return AE_ERROR;
        }
@@ -1089,8 +1113,8 @@ static acpi_status wmid3_get_device_status(u32 *value, u16 device)
        kfree(obj);
 
        if (return_value.error_code || return_value.ec_return_value)
-               pr_warning("Get Device Status failed: "
-                       "0x%x - 0x%x\n", return_value.error_code,
+               pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
+                       return_value.error_code,
                        return_value.ec_return_value);
        else
                *value = !!(return_value.devices & device);
@@ -1123,6 +1147,114 @@ static acpi_status get_device_status(u32 *value, u32 cap)
        }
 }
 
+static acpi_status wmid3_set_device_status(u32 value, u16 device)
+{
+       struct wmid3_gds_return_value return_value;
+       acpi_status status;
+       union acpi_object *obj;
+       u16 devices;
+       struct wmid3_gds_input_param params = {
+               .function_num = 0x1,
+               .hotkey_number = 0x01,
+               .devices = ACER_WMID3_GDS_WIRELESS |
+                               ACER_WMID3_GDS_THREEG |
+                               ACER_WMID3_GDS_WIMAX |
+                               ACER_WMID3_GDS_BLUETOOTH,
+       };
+       struct acpi_buffer input = {
+               sizeof(struct wmid3_gds_input_param),
+               &params
+       };
+       struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+       struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
+
+       status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
+       if (ACPI_FAILURE(status))
+               return status;
+
+       obj = output.pointer;
+
+       if (!obj)
+               return AE_ERROR;
+       else if (obj->type != ACPI_TYPE_BUFFER) {
+               kfree(obj);
+               return AE_ERROR;
+       }
+       if (obj->buffer.length != 8) {
+               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
+               kfree(obj);
+               return AE_ERROR;
+       }
+
+       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
+       kfree(obj);
+
+       if (return_value.error_code || return_value.ec_return_value) {
+               pr_warning("Get Current Device Status failed: "
+                       "0x%x - 0x%x\n", return_value.error_code,
+                       return_value.ec_return_value);
+               return status;
+       }
+
+       devices = return_value.devices;
+       params.function_num = 0x2;
+       params.hotkey_number = 0x01;
+       params.devices = (value) ? (devices | device) : (devices & ~device);
+
+       status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
+       if (ACPI_FAILURE(status))
+               return status;
+
+       obj = output2.pointer;
+
+       if (!obj)
+               return AE_ERROR;
+       else if (obj->type != ACPI_TYPE_BUFFER) {
+               kfree(obj);
+               return AE_ERROR;
+       }
+       if (obj->buffer.length != 4) {
+               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
+               kfree(obj);
+               return AE_ERROR;
+       }
+
+       return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
+       kfree(obj);
+
+       if (return_value.error_code || return_value.ec_return_value)
+               pr_warning("Set Device Status failed: "
+                       "0x%x - 0x%x\n", return_value.error_code,
+                       return_value.ec_return_value);
+
+       return status;
+}
+
+static acpi_status set_device_status(u32 value, u32 cap)
+{
+       if (wmi_has_guid(WMID_GUID3)) {
+               u16 device;
+
+               switch (cap) {
+               case ACER_CAP_WIRELESS:
+                       device = ACER_WMID3_GDS_WIRELESS;
+                       break;
+               case ACER_CAP_BLUETOOTH:
+                       device = ACER_WMID3_GDS_BLUETOOTH;
+                       break;
+               case ACER_CAP_THREEG:
+                       device = ACER_WMID3_GDS_THREEG;
+                       break;
+               default:
+                       return AE_ERROR;
+               }
+               return wmid3_set_device_status(value, device);
+
+       } else {
+               return set_u32(value, cap);
+       }
+}
+
 /*
  * Rfkill devices
  */
@@ -1157,9 +1289,13 @@ static int acer_rfkill_set(void *data, bool blocked)
 {
        acpi_status status;
        u32 cap = (unsigned long)data;
-       status = set_u32(!blocked, cap);
-       if (ACPI_FAILURE(status))
-               return -ENODEV;
+
+       if (rfkill_inited) {
+               status = set_device_status(!blocked, cap);
+               if (ACPI_FAILURE(status))
+                       return -ENODEV;
+       }
+
        return 0;
 }
 
@@ -1183,14 +1319,16 @@ static struct rfkill *acer_rfkill_register(struct device *dev,
                return ERR_PTR(-ENOMEM);
 
        status = get_device_status(&state, cap);
-       if (ACPI_SUCCESS(status))
-               rfkill_init_sw_state(rfkill_dev, !state);
 
        err = rfkill_register(rfkill_dev);
        if (err) {
                rfkill_destroy(rfkill_dev);
                return ERR_PTR(err);
        }
+
+       if (ACPI_SUCCESS(status))
+               rfkill_set_sw_state(rfkill_dev, !state);
+
        return rfkill_dev;
 }
 
@@ -1225,14 +1363,19 @@ static int acer_rfkill_init(struct device *dev)
                }
        }
 
-       schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
+       rfkill_inited = true;
+
+       if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
+               schedule_delayed_work(&acer_rfkill_work,
+                       round_jiffies_relative(HZ));
 
        return 0;
 }
 
 static void acer_rfkill_exit(void)
 {
-       cancel_delayed_work_sync(&acer_rfkill_work);
+       if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
+               cancel_delayed_work_sync(&acer_rfkill_work);
 
        rfkill_unregister(wireless_rfkill);
        rfkill_destroy(wireless_rfkill);
@@ -1257,6 +1400,9 @@ static ssize_t show_bool_threeg(struct device *dev,
 {
        u32 result; \
        acpi_status status;
+
+       pr_info("This threeg sysfs will be removed in 2012"
+               " - used by: %s\n", current->comm);
        if (wmi_has_guid(WMID_GUID3))
                status = wmid3_get_device_status(&result,
                                ACER_WMID3_GDS_THREEG);
@@ -1272,8 +1418,10 @@ static ssize_t set_bool_threeg(struct device *dev,
 {
        u32 tmp = simple_strtoul(buf, NULL, 10);
        acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
-               if (ACPI_FAILURE(status))
-                       return -EINVAL;
+       pr_info("This threeg sysfs will be removed in 2012"
+               " - used by: %s\n", current->comm);
+       if (ACPI_FAILURE(status))
+               return -EINVAL;
        return count;
 }
 static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
@@ -1282,6 +1430,8 @@ static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
 static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
        char *buf)
 {
+       pr_info("This interface sysfs will be removed in 2012"
+               " - used by: %s\n", current->comm);
        switch (interface->type) {
        case ACER_AMW0:
                return sprintf(buf, "AMW0\n");
@@ -1302,10 +1452,12 @@ static void acer_wmi_notify(u32 value, void *context)
        union acpi_object *obj;
        struct event_return_value return_value;
        acpi_status status;
+       u16 device_state;
+       const struct key_entry *key;
 
        status = wmi_get_event_data(value, &response);
        if (status != AE_OK) {
-               pr_warning("bad event status 0x%x\n", status);
+               pr_warn("bad event status 0x%x\n", status);
                return;
        }
 
@@ -1314,12 +1466,12 @@ static void acer_wmi_notify(u32 value, void *context)
        if (!obj)
                return;
        if (obj->type != ACPI_TYPE_BUFFER) {
-               pr_warning("Unknown response received %d\n", obj->type);
+               pr_warn("Unknown response received %d\n", obj->type);
                kfree(obj);
                return;
        }
        if (obj->buffer.length != 8) {
-               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
+               pr_warn("Unknown buffer length %d\n", obj->buffer.length);
                kfree(obj);
                return;
        }
@@ -1329,13 +1481,35 @@ static void acer_wmi_notify(u32 value, void *context)
 
        switch (return_value.function) {
        case WMID_HOTKEY_EVENT:
-               if (!sparse_keymap_report_event(acer_wmi_input_dev,
-                               return_value.key_num, 1, true))
-                       pr_warning("Unknown key number - 0x%x\n",
+               device_state = return_value.device_state;
+               pr_debug("device state: 0x%x\n", device_state);
+
+               key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
+                                                       return_value.key_num);
+               if (!key) {
+                       pr_warn("Unknown key number - 0x%x\n",
                                return_value.key_num);
+               } else {
+                       switch (key->keycode) {
+                       case KEY_WLAN:
+                       case KEY_BLUETOOTH:
+                               if (has_cap(ACER_CAP_WIRELESS))
+                                       rfkill_set_sw_state(wireless_rfkill,
+                                               !(device_state & ACER_WMID3_GDS_WIRELESS));
+                               if (has_cap(ACER_CAP_THREEG))
+                                       rfkill_set_sw_state(threeg_rfkill,
+                                               !(device_state & ACER_WMID3_GDS_THREEG));
+                               if (has_cap(ACER_CAP_BLUETOOTH))
+                                       rfkill_set_sw_state(bluetooth_rfkill,
+                                               !(device_state & ACER_WMID3_GDS_BLUETOOTH));
+                               break;
+                       }
+                       sparse_keymap_report_entry(acer_wmi_input_dev, key,
+                                                  1, true);
+               }
                break;
        default:
-               pr_warning("Unknown function number - %d - %d\n",
+               pr_warn("Unknown function number - %d - %d\n",
                        return_value.function, return_value.key_num);
                break;
        }
@@ -1364,7 +1538,7 @@ wmid3_set_lm_mode(struct lm_input_params *params,
                return AE_ERROR;
        }
        if (obj->buffer.length != 4) {
-               pr_warning("Unknown buffer length %d\n", obj->buffer.length);
+               pr_warn("Unknown buffer length %d\n", obj->buffer.length);
                kfree(obj);
                return AE_ERROR;
        }
@@ -1389,11 +1563,11 @@ static int acer_wmi_enable_ec_raw(void)
        status = wmid3_set_lm_mode(&params, &return_value);
 
        if (return_value.error_code || return_value.ec_return_value)
-               pr_warning("Enabling EC raw mode failed: "
-                      "0x%x - 0x%x\n", return_value.error_code,
-                      return_value.ec_return_value);
+               pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
+                       return_value.error_code,
+                       return_value.ec_return_value);
        else
-               pr_info("Enabled EC raw mode");
+               pr_info("Enabled EC raw mode\n");
 
        return status;
 }
@@ -1412,9 +1586,9 @@ static int acer_wmi_enable_lm(void)
        status = wmid3_set_lm_mode(&params, &return_value);
 
        if (return_value.error_code || return_value.ec_return_value)
-               pr_warning("Enabling Launch Manager failed: "
-                      "0x%x - 0x%x\n", return_value.error_code,
-                      return_value.ec_return_value);
+               pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
+                       return_value.error_code,
+                       return_value.ec_return_value);
 
        return status;
 }
@@ -1481,8 +1655,11 @@ static u32 get_wmid_devices(void)
 
        obj = (union acpi_object *) out.pointer;
        if (obj && obj->type == ACPI_TYPE_BUFFER &&
-               obj->buffer.length == sizeof(u32)) {
+               (obj->buffer.length == sizeof(u32) ||
+               obj->buffer.length == sizeof(u64))) {
                devices = *((u32 *) obj->buffer.pointer);
+       } else if (obj->type == ACPI_TYPE_INTEGER) {
+               devices = (u32) obj->integer.value;
        }
 
        kfree(out.pointer);