diff options
Diffstat (limited to 'drivers/platform/x86/hp-wmi.c')
-rw-r--r-- | drivers/platform/x86/hp-wmi.c | 414 |
1 files changed, 197 insertions, 217 deletions
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 96ffda493266..0df4209648d1 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -48,41 +48,29 @@ MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C" #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4" -#define HPWMI_DISPLAY_QUERY 0x1 -#define HPWMI_HDDTEMP_QUERY 0x2 -#define HPWMI_ALS_QUERY 0x3 -#define HPWMI_HARDWARE_QUERY 0x4 -#define HPWMI_WIRELESS_QUERY 0x5 -#define HPWMI_BIOS_QUERY 0x9 -#define HPWMI_FEATURE_QUERY 0xb -#define HPWMI_HOTKEY_QUERY 0xc -#define HPWMI_FEATURE2_QUERY 0xd -#define HPWMI_WIRELESS2_QUERY 0x1b -#define HPWMI_POSTCODEERROR_QUERY 0x2a - enum hp_wmi_radio { - HPWMI_WIFI = 0, - HPWMI_BLUETOOTH = 1, - HPWMI_WWAN = 2, - HPWMI_GPS = 3, + HPWMI_WIFI = 0x0, + HPWMI_BLUETOOTH = 0x1, + HPWMI_WWAN = 0x2, + HPWMI_GPS = 0x3, }; enum hp_wmi_event_ids { - HPWMI_DOCK_EVENT = 1, - HPWMI_PARK_HDD = 2, - HPWMI_SMART_ADAPTER = 3, - HPWMI_BEZEL_BUTTON = 4, - HPWMI_WIRELESS = 5, - HPWMI_CPU_BATTERY_THROTTLE = 6, - HPWMI_LOCK_SWITCH = 7, - HPWMI_LID_SWITCH = 8, - HPWMI_SCREEN_ROTATION = 9, - HPWMI_COOLSENSE_SYSTEM_MOBILE = 0x0A, - HPWMI_COOLSENSE_SYSTEM_HOT = 0x0B, - HPWMI_PROXIMITY_SENSOR = 0x0C, - HPWMI_BACKLIT_KB_BRIGHTNESS = 0x0D, - HPWMI_PEAKSHIFT_PERIOD = 0x0F, - HPWMI_BATTERY_CHARGE_PERIOD = 0x10, + HPWMI_DOCK_EVENT = 0x01, + HPWMI_PARK_HDD = 0x02, + HPWMI_SMART_ADAPTER = 0x03, + HPWMI_BEZEL_BUTTON = 0x04, + HPWMI_WIRELESS = 0x05, + HPWMI_CPU_BATTERY_THROTTLE = 0x06, + HPWMI_LOCK_SWITCH = 0x07, + HPWMI_LID_SWITCH = 0x08, + HPWMI_SCREEN_ROTATION = 0x09, + HPWMI_COOLSENSE_SYSTEM_MOBILE = 0x0A, + HPWMI_COOLSENSE_SYSTEM_HOT = 0x0B, + HPWMI_PROXIMITY_SENSOR = 0x0C, + HPWMI_BACKLIT_KB_BRIGHTNESS = 0x0D, + HPWMI_PEAKSHIFT_PERIOD = 0x0F, + HPWMI_BATTERY_CHARGE_PERIOD = 0x10, }; struct bios_args { @@ -93,6 +81,39 @@ struct bios_args { u32 data; }; +enum hp_wmi_commandtype { + HPWMI_DISPLAY_QUERY = 0x01, + HPWMI_HDDTEMP_QUERY = 0x02, + HPWMI_ALS_QUERY = 0x03, + HPWMI_HARDWARE_QUERY = 0x04, + HPWMI_WIRELESS_QUERY = 0x05, + HPWMI_BATTERY_QUERY = 0x07, + HPWMI_BIOS_QUERY = 0x09, + HPWMI_FEATURE_QUERY = 0x0b, + HPWMI_HOTKEY_QUERY = 0x0c, + HPWMI_FEATURE2_QUERY = 0x0d, + HPWMI_WIRELESS2_QUERY = 0x1b, + HPWMI_POSTCODEERROR_QUERY = 0x2a, +}; + +enum hp_wmi_command { + HPWMI_READ = 0x01, + HPWMI_WRITE = 0x02, + HPWMI_ODM = 0x03, +}; + +enum hp_wmi_hardware_mask { + HPWMI_DOCK_MASK = 0x01, + HPWMI_TABLET_MASK = 0x04, +}; + +#define BIOS_ARGS_INIT(write, ctype, size) \ + (struct bios_args) { .signature = 0x55434553, \ + .command = (write) ? 0x2 : 0x1, \ + .commandtype = (ctype), \ + .datasize = (size), \ + .data = 0 } + struct bios_return { u32 sigpass; u32 return_code; @@ -170,8 +191,8 @@ static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES]; /* * hp_wmi_perform_query * - * query: The commandtype -> What should be queried - * write: The command -> 0 read, 1 write, 3 ODM specific + * query: The commandtype (enum hp_wmi_commandtype) + * write: The command (enum hp_wmi_command) * buffer: Buffer used as input and/or output * insize: Size of input buffer * outsize: Size of output buffer @@ -182,27 +203,27 @@ static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES]; * -EINVAL if the output buffer size exceeds buffersize * * Note: The buffersize must at least be the maximum of the input and output - * size. E.g. Battery info query (0x7) is defined to have 1 byte input + * size. E.g. Battery info query is defined to have 1 byte input * and 128 byte output. The caller would do: * buffer = kzalloc(128, GFP_KERNEL); - * ret = hp_wmi_perform_query(0x7, 0, buffer, 1, 128) + * ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ, buffer, 1, 128) */ -static int hp_wmi_perform_query(int query, int write, void *buffer, - int insize, int outsize) +static int hp_wmi_perform_query(int query, enum hp_wmi_command command, + void *buffer, int insize, int outsize) { struct bios_return *bios_return; int actual_outsize; union acpi_object *obj; struct bios_args args = { .signature = 0x55434553, - .command = write ? 0x2 : 0x1, + .command = command, .commandtype = query, .datasize = insize, .data = 0, }; struct acpi_buffer input = { sizeof(struct bios_args), &args }; struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; - u32 rc; + int ret = 0; if (WARN_ON(insize > sizeof(args.data))) return -EINVAL; @@ -214,91 +235,61 @@ static int hp_wmi_perform_query(int query, int write, void *buffer, if (!obj) return -EINVAL; - else if (obj->type != ACPI_TYPE_BUFFER) { - kfree(obj); - return -EINVAL; + + if (obj->type != ACPI_TYPE_BUFFER) { + ret = -EINVAL; + goto out_free; } bios_return = (struct bios_return *)obj->buffer.pointer; - rc = bios_return->return_code; + ret = bios_return->return_code; - if (rc) { - if (rc != HPWMI_RET_UNKNOWN_CMDTYPE) - pr_warn("query 0x%x returned error 0x%x\n", query, rc); - kfree(obj); - return rc; + if (ret) { + if (ret != HPWMI_RET_UNKNOWN_CMDTYPE) + pr_warn("query 0x%x returned error 0x%x\n", query, ret); + goto out_free; } - if (!outsize) { - /* ignore output data */ - kfree(obj); - return 0; - } + /* Ignore output data of zero size */ + if (!outsize) + goto out_free; actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return))); memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize); memset(buffer + actual_outsize, 0, outsize - actual_outsize); + +out_free: kfree(obj); - return 0; + return ret; } -static int hp_wmi_display_state(void) +static int hp_wmi_read_int(int query) { - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state, - sizeof(state), sizeof(state)); - if (ret) - return -EINVAL; - return state; -} + int val = 0, ret; -static int hp_wmi_hddtemp_state(void) -{ - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state, - sizeof(state), sizeof(state)); - if (ret) - return -EINVAL; - return state; -} + ret = hp_wmi_perform_query(query, HPWMI_READ, &val, + sizeof(val), sizeof(val)); -static int hp_wmi_als_state(void) -{ - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state, - sizeof(state), sizeof(state)); if (ret) - return -EINVAL; - return state; + return ret < 0 ? ret : -EINVAL; + + return val; } -static int hp_wmi_dock_state(void) +static int hp_wmi_hw_state(int mask) { - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, - sizeof(state), sizeof(state)); + int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY); - if (ret) - return -EINVAL; + if (state < 0) + return state; return state & 0x1; } -static int hp_wmi_tablet_state(void) -{ - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, - sizeof(state), sizeof(state)); - if (ret) - return ret; - - return (state & 0x4) ? 1 : 0; -} - static int __init hp_wmi_bios_2008_later(void) { int state = 0; - int ret = hp_wmi_perform_query(HPWMI_FEATURE_QUERY, 0, &state, + int ret = hp_wmi_perform_query(HPWMI_FEATURE_QUERY, HPWMI_READ, &state, sizeof(state), sizeof(state)); if (!ret) return 1; @@ -309,7 +300,7 @@ static int __init hp_wmi_bios_2008_later(void) static int __init hp_wmi_bios_2009_later(void) { int state = 0; - int ret = hp_wmi_perform_query(HPWMI_FEATURE2_QUERY, 0, &state, + int ret = hp_wmi_perform_query(HPWMI_FEATURE2_QUERY, HPWMI_READ, &state, sizeof(state), sizeof(state)); if (!ret) return 1; @@ -320,11 +311,10 @@ static int __init hp_wmi_bios_2009_later(void) static int __init hp_wmi_enable_hotkeys(void) { int value = 0x6e; - int ret = hp_wmi_perform_query(HPWMI_BIOS_QUERY, 1, &value, + int ret = hp_wmi_perform_query(HPWMI_BIOS_QUERY, HPWMI_WRITE, &value, sizeof(value), 0); - if (ret) - return -EINVAL; - return 0; + + return ret <= 0 ? ret : -EINVAL; } static int hp_wmi_set_block(void *data, bool blocked) @@ -333,11 +323,10 @@ static int hp_wmi_set_block(void *data, bool blocked) int query = BIT(r + 8) | ((!blocked) << r); int ret; - ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, + ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE, &query, sizeof(query), 0); - if (ret) - return -EINVAL; - return 0; + + return ret <= 0 ? ret : -EINVAL; } static const struct rfkill_ops hp_wmi_rfkill_ops = { @@ -346,47 +335,38 @@ static const struct rfkill_ops hp_wmi_rfkill_ops = { static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) { - int wireless = 0; - int mask; - hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, - &wireless, sizeof(wireless), - sizeof(wireless)); - /* TBD: Pass error */ + int mask = 0x200 << (r * 8); - mask = 0x200 << (r * 8); + int wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY); - if (wireless & mask) - return false; - else - return true; + /* TBD: Pass error */ + WARN_ONCE(wireless < 0, "error executing HPWMI_WIRELESS_QUERY"); + + return !(wireless & mask); } static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) { - int wireless = 0; - int mask; - hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, - &wireless, sizeof(wireless), - sizeof(wireless)); - /* TBD: Pass error */ + int mask = 0x800 << (r * 8); - mask = 0x800 << (r * 8); + int wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY); - if (wireless & mask) - return false; - else - return true; + /* TBD: Pass error */ + WARN_ONCE(wireless < 0, "error executing HPWMI_WIRELESS_QUERY"); + + return !(wireless & mask); } static int hp_wmi_rfkill2_set_block(void *data, bool blocked) { int rfkill_id = (int)(long)data; char buffer[4] = { 0x01, 0x00, rfkill_id, !blocked }; + int ret; - if (hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 1, - buffer, sizeof(buffer), 0)) - return -EINVAL; - return 0; + ret = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_WRITE, + buffer, sizeof(buffer), 0); + + return ret <= 0 ? ret : -EINVAL; } static const struct rfkill_ops hp_wmi_rfkill2_ops = { @@ -395,10 +375,10 @@ static const struct rfkill_ops hp_wmi_rfkill2_ops = { static int hp_wmi_rfkill2_refresh(void) { - int err, i; struct bios_rfkill2_state state; + int err, i; - err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state, + err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state, 0, sizeof(state)); if (err) return err; @@ -422,119 +402,113 @@ static int hp_wmi_rfkill2_refresh(void) return 0; } -static int hp_wmi_post_code_state(void) -{ - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, 0, &state, - sizeof(state), sizeof(state)); - if (ret) - return -EINVAL; - return state; -} - -static ssize_t show_display(struct device *dev, struct device_attribute *attr, +static ssize_t display_show(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_display_state(); + int value = hp_wmi_read_int(HPWMI_DISPLAY_QUERY); if (value < 0) - return -EINVAL; + return value; return sprintf(buf, "%d\n", value); } -static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, +static ssize_t hddtemp_show(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_hddtemp_state(); + int value = hp_wmi_read_int(HPWMI_HDDTEMP_QUERY); if (value < 0) - return -EINVAL; + return value; return sprintf(buf, "%d\n", value); } -static ssize_t show_als(struct device *dev, struct device_attribute *attr, +static ssize_t als_show(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_als_state(); + int value = hp_wmi_read_int(HPWMI_ALS_QUERY); if (value < 0) - return -EINVAL; + return value; return sprintf(buf, "%d\n", value); } -static ssize_t show_dock(struct device *dev, struct device_attribute *attr, +static ssize_t dock_show(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_dock_state(); + int value = hp_wmi_hw_state(HPWMI_DOCK_MASK); if (value < 0) - return -EINVAL; + return value; return sprintf(buf, "%d\n", value); } -static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, - char *buf) +static ssize_t tablet_show(struct device *dev, struct device_attribute *attr, + char *buf) { - int value = hp_wmi_tablet_state(); + int value = hp_wmi_hw_state(HPWMI_TABLET_MASK); if (value < 0) - return -EINVAL; + return value; return sprintf(buf, "%d\n", value); } -static ssize_t show_postcode(struct device *dev, struct device_attribute *attr, - char *buf) +static ssize_t postcode_show(struct device *dev, struct device_attribute *attr, + char *buf) { /* Get the POST error code of previous boot failure. */ - int value = hp_wmi_post_code_state(); + int value = hp_wmi_read_int(HPWMI_POSTCODEERROR_QUERY); if (value < 0) - return -EINVAL; + return value; return sprintf(buf, "0x%x\n", value); } -static ssize_t set_als(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t als_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { u32 tmp = simple_strtoul(buf, NULL, 10); - int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp, + int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_WRITE, &tmp, sizeof(tmp), sizeof(tmp)); if (ret) - return -EINVAL; + return ret < 0 ? ret : -EINVAL; return count; } -static ssize_t set_postcode(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t postcode_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { + long unsigned int tmp2; int ret; u32 tmp; - long unsigned int tmp2; ret = kstrtoul(buf, 10, &tmp2); - if (ret || tmp2 != 1) - return -EINVAL; + if (!ret && tmp2 != 1) + ret = -EINVAL; + if (ret) + goto out; /* Clear the POST error code. It is kept until until cleared. */ tmp = (u32) tmp2; - ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, 1, &tmp, + ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, HPWMI_WRITE, &tmp, sizeof(tmp), sizeof(tmp)); + +out: if (ret) - return -EINVAL; + return ret < 0 ? ret : -EINVAL; return count; } -static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); -static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); -static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); -static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); -static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); -static DEVICE_ATTR(postcode, S_IRUGO | S_IWUSR, show_postcode, set_postcode); +static DEVICE_ATTR_RO(display); +static DEVICE_ATTR_RO(hddtemp); +static DEVICE_ATTR_RW(als); +static DEVICE_ATTR_RO(dock); +static DEVICE_ATTR_RO(tablet); +static DEVICE_ATTR_RW(postcode); static void hp_wmi_notify(u32 value, void *context) { struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; - union acpi_object *obj; u32 event_id, event_data; - int key_code = 0, ret; - u32 *location; + union acpi_object *obj; acpi_status status; + u32 *location; + int key_code; status = wmi_get_event_data(value, &response); if (status != AE_OK) { @@ -572,10 +546,12 @@ static void hp_wmi_notify(u32 value, void *context) switch (event_id) { case HPWMI_DOCK_EVENT: - input_report_switch(hp_wmi_input_dev, SW_DOCK, - hp_wmi_dock_state()); - input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, - hp_wmi_tablet_state()); + if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) + input_report_switch(hp_wmi_input_dev, SW_DOCK, + hp_wmi_hw_state(HPWMI_DOCK_MASK)); + if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) + input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, + hp_wmi_hw_state(HPWMI_TABLET_MASK)); input_sync(hp_wmi_input_dev); break; case HPWMI_PARK_HDD: @@ -583,11 +559,8 @@ static void hp_wmi_notify(u32 value, void *context) case HPWMI_SMART_ADAPTER: break; case HPWMI_BEZEL_BUTTON: - ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, - &key_code, - sizeof(key_code), - sizeof(key_code)); - if (ret) + key_code = hp_wmi_read_int(HPWMI_HOTKEY_QUERY); + if (key_code < 0) break; if (!sparse_keymap_report_event(hp_wmi_input_dev, @@ -643,7 +616,7 @@ static void hp_wmi_notify(u32 value, void *context) static int __init hp_wmi_input_setup(void) { acpi_status status; - int err; + int err, val; hp_wmi_input_dev = input_allocate_device(); if (!hp_wmi_input_dev) @@ -654,17 +627,26 @@ static int __init hp_wmi_input_setup(void) hp_wmi_input_dev->id.bustype = BUS_HOST; __set_bit(EV_SW, hp_wmi_input_dev->evbit); - __set_bit(SW_DOCK, hp_wmi_input_dev->swbit); - __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); + + /* Dock */ + val = hp_wmi_hw_state(HPWMI_DOCK_MASK); + if (!(val < 0)) { + __set_bit(SW_DOCK, hp_wmi_input_dev->swbit); + input_report_switch(hp_wmi_input_dev, SW_DOCK, val); + } + + /* Tablet mode */ + val = hp_wmi_hw_state(HPWMI_TABLET_MASK); + if (!(val < 0)) { + __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); + input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val); + } err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL); if (err) goto err_free_dev; /* Set initial hardware state */ - input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); - input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, - hp_wmi_tablet_state()); input_sync(hp_wmi_input_dev); if (!hp_wmi_bios_2009_later() && hp_wmi_bios_2008_later()) @@ -673,7 +655,7 @@ static int __init hp_wmi_input_setup(void) status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL); if (ACPI_FAILURE(status)) { err = -EIO; - goto err_free_keymap; + goto err_free_dev; } err = input_register_device(hp_wmi_input_dev); @@ -684,8 +666,6 @@ static int __init hp_wmi_input_setup(void) err_uninstall_notifier: wmi_remove_notify_handler(HPWMI_EVENT_GUID); - err_free_keymap: - sparse_keymap_free(hp_wmi_input_dev); err_free_dev: input_free_device(hp_wmi_input_dev); return err; @@ -694,7 +674,6 @@ static int __init hp_wmi_input_setup(void) static void hp_wmi_input_destroy(void) { wmi_remove_notify_handler(HPWMI_EVENT_GUID); - sparse_keymap_free(hp_wmi_input_dev); input_unregister_device(hp_wmi_input_dev); } @@ -710,15 +689,13 @@ static void cleanup_sysfs(struct platform_device *device) static int __init hp_wmi_rfkill_setup(struct platform_device *device) { - int err; - int wireless = 0; + int err, wireless; - err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless, - sizeof(wireless), sizeof(wireless)); - if (err) - return err; + wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY); + if (wireless < 0) + return wireless; - err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, &wireless, + err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE, &wireless, sizeof(wireless), 0); if (err) return err; @@ -795,12 +772,13 @@ register_wifi_error: static int __init hp_wmi_rfkill2_setup(struct platform_device *device) { - int err, i; struct bios_rfkill2_state state; - err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state, + int err, i; + + err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state, 0, sizeof(state)); if (err) - return err; + return err < 0 ? err : -EINVAL; if (state.count > HPWMI_MAX_RFKILL2_DEVICES) { pr_warn("unable to parse 0x1b query output\n"); @@ -950,10 +928,12 @@ static int hp_wmi_resume_handler(struct device *device) * changed. */ if (hp_wmi_input_dev) { - input_report_switch(hp_wmi_input_dev, SW_DOCK, - hp_wmi_dock_state()); - input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, - hp_wmi_tablet_state()); + if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) + input_report_switch(hp_wmi_input_dev, SW_DOCK, + hp_wmi_hw_state(HPWMI_DOCK_MASK)); + if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) + input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, + hp_wmi_hw_state(HPWMI_TABLET_MASK)); input_sync(hp_wmi_input_dev); } @@ -991,9 +971,9 @@ static struct platform_driver hp_wmi_driver = { static int __init hp_wmi_init(void) { - int err; int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); + int err; if (!bios_capable && !event_capable) return -ENODEV; |