diff options
author | Darren Hart (VMware) <dvhart@infradead.org> | 2017-04-19 20:03:38 -0400 |
---|---|---|
committer | Darren Hart (VMware) <dvhart@infradead.org> | 2017-04-20 16:26:16 -0400 |
commit | f9cf3b2880cc41ec2b44aa24fa156bffe934f9c7 (patch) | |
tree | 890f1ce87fd763d68a330edd54c3e124c81bf12d | |
parent | c7ef144c12033052c956ca9d80b2dfc19c73d939 (diff) |
platform/x86: hp-wmi: Refactor dock and tablet state fetchers
Both dock and tablet use the HPWMI_HARDWARE_QUERY, but require different
masks. Rather than using two functions with magic masks, define the
masks, and use a common accessor.
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
Tested-by: Carlo Caione <carlo@endlessm.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
-rw-r--r-- | drivers/platform/x86/hp-wmi.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 577805987d35..9b71829843ad 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c | |||
@@ -102,6 +102,11 @@ enum hp_wmi_command { | |||
102 | HPWMI_ODM = 0x03, | 102 | HPWMI_ODM = 0x03, |
103 | }; | 103 | }; |
104 | 104 | ||
105 | enum hp_wmi_hardware_mask { | ||
106 | HPWMI_DOCK_MASK = 0x01, | ||
107 | HPWMI_TABLET_MASK = 0x04, | ||
108 | }; | ||
109 | |||
105 | #define BIOS_ARGS_INIT(write, ctype, size) \ | 110 | #define BIOS_ARGS_INIT(write, ctype, size) \ |
106 | (struct bios_args) { .signature = 0x55434553, \ | 111 | (struct bios_args) { .signature = 0x55434553, \ |
107 | .command = (write) ? 0x2 : 0x1, \ | 112 | .command = (write) ? 0x2 : 0x1, \ |
@@ -271,7 +276,7 @@ static int hp_wmi_read_int(int query) | |||
271 | return val; | 276 | return val; |
272 | } | 277 | } |
273 | 278 | ||
274 | static int hp_wmi_dock_state(void) | 279 | static int hp_wmi_hw_state(int mask) |
275 | { | 280 | { |
276 | int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY); | 281 | int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY); |
277 | 282 | ||
@@ -281,16 +286,6 @@ static int hp_wmi_dock_state(void) | |||
281 | return state & 0x1; | 286 | return state & 0x1; |
282 | } | 287 | } |
283 | 288 | ||
284 | static int hp_wmi_tablet_state(void) | ||
285 | { | ||
286 | int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY); | ||
287 | |||
288 | if (state < 0) | ||
289 | return state; | ||
290 | |||
291 | return (state & 0x4) ? 1 : 0; | ||
292 | } | ||
293 | |||
294 | static int __init hp_wmi_bios_2008_later(void) | 289 | static int __init hp_wmi_bios_2008_later(void) |
295 | { | 290 | { |
296 | int state = 0; | 291 | int state = 0; |
@@ -438,7 +433,7 @@ static ssize_t show_als(struct device *dev, struct device_attribute *attr, | |||
438 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, | 433 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, |
439 | char *buf) | 434 | char *buf) |
440 | { | 435 | { |
441 | int value = hp_wmi_dock_state(); | 436 | int value = hp_wmi_hw_state(HPWMI_DOCK_MASK); |
442 | if (value < 0) | 437 | if (value < 0) |
443 | return -EINVAL; | 438 | return -EINVAL; |
444 | return sprintf(buf, "%d\n", value); | 439 | return sprintf(buf, "%d\n", value); |
@@ -447,7 +442,7 @@ static ssize_t show_dock(struct device *dev, struct device_attribute *attr, | |||
447 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, | 442 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, |
448 | char *buf) | 443 | char *buf) |
449 | { | 444 | { |
450 | int value = hp_wmi_tablet_state(); | 445 | int value = hp_wmi_hw_state(HPWMI_TABLET_MASK); |
451 | if (value < 0) | 446 | if (value < 0) |
452 | return -EINVAL; | 447 | return -EINVAL; |
453 | return sprintf(buf, "%d\n", value); | 448 | return sprintf(buf, "%d\n", value); |
@@ -550,10 +545,10 @@ static void hp_wmi_notify(u32 value, void *context) | |||
550 | case HPWMI_DOCK_EVENT: | 545 | case HPWMI_DOCK_EVENT: |
551 | if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) | 546 | if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) |
552 | input_report_switch(hp_wmi_input_dev, SW_DOCK, | 547 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
553 | hp_wmi_dock_state()); | 548 | hp_wmi_hw_state(HPWMI_DOCK_MASK)); |
554 | if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) | 549 | if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) |
555 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | 550 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
556 | hp_wmi_tablet_state()); | 551 | hp_wmi_hw_state(HPWMI_TABLET_MASK)); |
557 | input_sync(hp_wmi_input_dev); | 552 | input_sync(hp_wmi_input_dev); |
558 | break; | 553 | break; |
559 | case HPWMI_PARK_HDD: | 554 | case HPWMI_PARK_HDD: |
@@ -631,14 +626,14 @@ static int __init hp_wmi_input_setup(void) | |||
631 | __set_bit(EV_SW, hp_wmi_input_dev->evbit); | 626 | __set_bit(EV_SW, hp_wmi_input_dev->evbit); |
632 | 627 | ||
633 | /* Dock */ | 628 | /* Dock */ |
634 | val = hp_wmi_dock_state(); | 629 | val = hp_wmi_hw_state(HPWMI_DOCK_MASK); |
635 | if (!(val < 0)) { | 630 | if (!(val < 0)) { |
636 | __set_bit(SW_DOCK, hp_wmi_input_dev->swbit); | 631 | __set_bit(SW_DOCK, hp_wmi_input_dev->swbit); |
637 | input_report_switch(hp_wmi_input_dev, SW_DOCK, val); | 632 | input_report_switch(hp_wmi_input_dev, SW_DOCK, val); |
638 | } | 633 | } |
639 | 634 | ||
640 | /* Tablet mode */ | 635 | /* Tablet mode */ |
641 | val = hp_wmi_tablet_state(); | 636 | val = hp_wmi_hw_state(HPWMI_TABLET_MASK); |
642 | if (!(val < 0)) { | 637 | if (!(val < 0)) { |
643 | __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); | 638 | __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); |
644 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val); | 639 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val); |
@@ -932,10 +927,10 @@ static int hp_wmi_resume_handler(struct device *device) | |||
932 | if (hp_wmi_input_dev) { | 927 | if (hp_wmi_input_dev) { |
933 | if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) | 928 | if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) |
934 | input_report_switch(hp_wmi_input_dev, SW_DOCK, | 929 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
935 | hp_wmi_dock_state()); | 930 | hp_wmi_hw_state(HPWMI_DOCK_MASK)); |
936 | if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) | 931 | if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) |
937 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | 932 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
938 | hp_wmi_tablet_state()); | 933 | hp_wmi_hw_state(HPWMI_TABLET_MASK)); |
939 | input_sync(hp_wmi_input_dev); | 934 | input_sync(hp_wmi_input_dev); |
940 | } | 935 | } |
941 | 936 | ||