Skip to content

Commit f9cf3b2

Browse files
committed
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>
1 parent c7ef144 commit f9cf3b2

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

‎drivers/platform/x86/hp-wmi.c‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ enum hp_wmi_command {
102102
HPWMI_ODM = 0x03,
103103
};
104104

105+
enum hp_wmi_hardware_mask {
106+
HPWMI_DOCK_MASK = 0x01,
107+
HPWMI_TABLET_MASK = 0x04,
108+
};
109+
105110
#define BIOS_ARGS_INIT(write, ctype, size) \
106111
(struct bios_args) { .signature = 0x55434553, \
107112
.command = (write) ? 0x2 : 0x1, \
@@ -271,7 +276,7 @@ static int hp_wmi_read_int(int query)
271276
return val;
272277
}
273278

274-
static int hp_wmi_dock_state(void)
279+
static int hp_wmi_hw_state(int mask)
275280
{
276281
int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY);
277282

@@ -281,16 +286,6 @@ static int hp_wmi_dock_state(void)
281286
return state & 0x1;
282287
}
283288

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-
294289
static int __init hp_wmi_bios_2008_later(void)
295290
{
296291
int state = 0;
@@ -438,7 +433,7 @@ static ssize_t show_als(struct device *dev, struct device_attribute *attr,
438433
static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
439434
char *buf)
440435
{
441-
int value = hp_wmi_dock_state();
436+
int value = hp_wmi_hw_state(HPWMI_DOCK_MASK);
442437
if (value < 0)
443438
return -EINVAL;
444439
return sprintf(buf, "%d\n", value);
@@ -447,7 +442,7 @@ static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
447442
static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
448443
char *buf)
449444
{
450-
int value = hp_wmi_tablet_state();
445+
int value = hp_wmi_hw_state(HPWMI_TABLET_MASK);
451446
if (value < 0)
452447
return -EINVAL;
453448
return sprintf(buf, "%d\n", value);
@@ -550,10 +545,10 @@ static void hp_wmi_notify(u32 value, void *context)
550545
case HPWMI_DOCK_EVENT:
551546
if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
552547
input_report_switch(hp_wmi_input_dev, SW_DOCK,
553-
hp_wmi_dock_state());
548+
hp_wmi_hw_state(HPWMI_DOCK_MASK));
554549
if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
555550
input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
556-
hp_wmi_tablet_state());
551+
hp_wmi_hw_state(HPWMI_TABLET_MASK));
557552
input_sync(hp_wmi_input_dev);
558553
break;
559554
case HPWMI_PARK_HDD:
@@ -631,14 +626,14 @@ static int __init hp_wmi_input_setup(void)
631626
__set_bit(EV_SW, hp_wmi_input_dev->evbit);
632627

633628
/* Dock */
634-
val = hp_wmi_dock_state();
629+
val = hp_wmi_hw_state(HPWMI_DOCK_MASK);
635630
if (!(val < 0)) {
636631
__set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
637632
input_report_switch(hp_wmi_input_dev, SW_DOCK, val);
638633
}
639634

640635
/* Tablet mode */
641-
val = hp_wmi_tablet_state();
636+
val = hp_wmi_hw_state(HPWMI_TABLET_MASK);
642637
if (!(val < 0)) {
643638
__set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
644639
input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val);
@@ -932,10 +927,10 @@ static int hp_wmi_resume_handler(struct device *device)
932927
if (hp_wmi_input_dev) {
933928
if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
934929
input_report_switch(hp_wmi_input_dev, SW_DOCK,
935-
hp_wmi_dock_state());
930+
hp_wmi_hw_state(HPWMI_DOCK_MASK));
936931
if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
937932
input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
938-
hp_wmi_tablet_state());
933+
hp_wmi_hw_state(HPWMI_TABLET_MASK));
939934
input_sync(hp_wmi_input_dev);
940935
}
941936

0 commit comments

Comments
 (0)