platform/x86: asus-wmi: add a helper for device presence
authorDaniel Drake <drake@endlessm.com>
Mon, 29 Jul 2019 08:27:38 +0000 (16:27 +0800)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 30 Jul 2019 11:14:38 +0000 (14:14 +0300)
Factor out the WLAN LED and lightbar LED presence checks into a
helper function, which will also be used by the upcoming CPU fan device
support.

Signed-off-by: Daniel Drake <drake@endlessm.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/x86/asus-wmi.c

index fc2939ac1cfe76048f420cdaa2c1981d4c20b6fd..25f1e256c4423d3f027a0850b29ed75501818c9f 100644 (file)
@@ -358,6 +358,14 @@ static int asus_wmi_get_devstate_simple(struct asus_wmi *asus, u32 dev_id)
                                          ASUS_WMI_DSTS_STATUS_BIT);
 }
 
+static bool asus_wmi_dev_is_present(struct asus_wmi *asus, u32 dev_id)
+{
+       u32 retval;
+       int status = asus_wmi_get_devstate(asus, dev_id, &retval);
+
+       return status == 0 && (retval & ASUS_WMI_DSTS_PRESENCE_BIT);
+}
+
 /* LEDs ***********************************************************************/
 
 /*
@@ -503,15 +511,6 @@ static int wlan_led_unknown_state(struct asus_wmi *asus)
        return result & ASUS_WMI_DSTS_UNKNOWN_BIT;
 }
 
-static int wlan_led_presence(struct asus_wmi *asus)
-{
-       u32 result;
-
-       asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result);
-
-       return result & ASUS_WMI_DSTS_PRESENCE_BIT;
-}
-
 static void wlan_led_update(struct work_struct *work)
 {
        int ctrl_param;
@@ -578,15 +577,6 @@ static enum led_brightness lightbar_led_get(struct led_classdev *led_cdev)
        return result & ASUS_WMI_DSTS_LIGHTBAR_MASK;
 }
 
-static int lightbar_led_presence(struct asus_wmi *asus)
-{
-       u32 result;
-
-       asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_LIGHTBAR, &result);
-
-       return result & ASUS_WMI_DSTS_PRESENCE_BIT;
-}
-
 static void asus_wmi_led_exit(struct asus_wmi *asus)
 {
        if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
@@ -637,7 +627,8 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
                        goto error;
        }
 
-       if (wlan_led_presence(asus) && (asus->driver->quirks->wapf > 0)) {
+       if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_WIRELESS_LED)
+                       && (asus->driver->quirks->wapf > 0)) {
                INIT_WORK(&asus->wlan_led_work, wlan_led_update);
 
                asus->wlan_led.name = "asus::wlan";
@@ -654,7 +645,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
                        goto error;
        }
 
-       if (lightbar_led_presence(asus)) {
+       if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_LIGHTBAR)) {
                INIT_WORK(&asus->lightbar_led_work, lightbar_led_update);
 
                asus->lightbar_led.name = "asus::lightbar";