OSDN Git Service

eeepc-laptop: rfkill rewrite
authorCorentin Chary <corentincj@iksaif.net>
Sun, 27 Sep 2009 18:29:37 +0000 (20:29 +0200)
committerCorentin Chary <corentincj@iksaif.net>
Wed, 30 Sep 2009 20:17:42 +0000 (22:17 +0200)
Make callbacks more generic

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
drivers/platform/x86/eeepc-laptop.c

index 353a898..17a14a5 100644 (file)
@@ -299,40 +299,36 @@ static int update_bl_status(struct backlight_device *bd)
  * Rfkill helpers
  */
 
-static int eeepc_wlan_rfkill_set(void *data, enum rfkill_state state)
+static bool eeepc_wlan_rfkill_blocked(void)
 {
-       if (state == RFKILL_STATE_SOFT_BLOCKED)
-               return set_acpi(CM_ASL_WLAN, 0);
-       else
-               return set_acpi(CM_ASL_WLAN, 1);
+       if (get_acpi(CM_ASL_WLAN) == 1)
+               return false;
+       return true;
 }
 
-static int eeepc_wlan_rfkill_state(void *data, enum rfkill_state *state)
+static int eeepc_rfkill_set(void *data, enum rfkill_state state)
 {
-       if (get_acpi(CM_ASL_WLAN) == 1)
-               *state = RFKILL_STATE_UNBLOCKED;
-       else
-               *state = RFKILL_STATE_SOFT_BLOCKED;
+       unsigned long asl = (unsigned long)data;
+
+       if (state == RFKILL_STATE_UNBLOCKED)
+               return set_acpi(asl, 1);
+       else if (state == RFKILL_STATE_SOFT_BLOCKED)
+               return set_acpi(asl, 0);
        return 0;
 }
 
-static int eeepc_bluetooth_rfkill_set(void *data, enum rfkill_state state)
+static int eeepc_rfkill_state(void *data, enum rfkill_state *state)
 {
-       if (state == RFKILL_STATE_SOFT_BLOCKED)
-               return set_acpi(CM_ASL_BLUETOOTH, 0);
-       else
-               return set_acpi(CM_ASL_BLUETOOTH, 1);
-}
+       unsigned long asl = (unsigned long)data;
 
-static int eeepc_bluetooth_rfkill_state(void *data, enum rfkill_state *state)
-{
-       if (get_acpi(CM_ASL_BLUETOOTH) == 1)
+       if (get_acpi(asl) == 1)
                *state = RFKILL_STATE_UNBLOCKED;
        else
                *state = RFKILL_STATE_SOFT_BLOCKED;
        return 0;
 }
 
+
 /*
  * Sys helpers
  */
@@ -531,9 +527,9 @@ static int notify_brn(void)
 
 static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
 {
-       enum rfkill_state state;
        struct pci_dev *dev;
        struct pci_bus *bus = pci_find_bus(0, 1);
+       bool blocked;
 
        if (event != ACPI_NOTIFY_BUS_CHECK)
                return;
@@ -543,9 +539,8 @@ static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
                return;
        }
 
-       eeepc_wlan_rfkill_state(ehotk->eeepc_wlan_rfkill, &state);
-
-       if (state == RFKILL_STATE_UNBLOCKED) {
+       blocked = eeepc_wlan_rfkill_blocked();
+       if (!blocked) {
                dev = pci_get_slot(bus, 0);
                if (dev) {
                        /* Device already present */
@@ -566,7 +561,8 @@ static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
                }
        }
 
-       rfkill_force_state(ehotk->eeepc_wlan_rfkill, state);
+       rfkill_force_state(ehotk->eeepc_wlan_rfkill, blocked ?
+                          RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED);
 }
 
 static void eeepc_hotk_notify(acpi_handle handle, u32 event, void *data)
@@ -655,6 +651,29 @@ static void eeepc_unregister_rfkill_notifier(char *node)
        }
 }
 
+static struct rfkill *eeepc_rfkill_alloc(const char *name,
+                                        struct device *dev,
+                                        enum rfkill_type type, int asl)
+{
+       struct rfkill *rfkill;
+
+       rfkill = rfkill_allocate(dev, type);
+       if (!rfkill)
+               return NULL;
+
+       rfkill->name = name;
+       rfkill->toggle_radio = eeepc_rfkill_set;
+       rfkill->get_state = eeepc_rfkill_state;
+       if (get_acpi(asl) == 1) {
+               rfkill->state = RFKILL_STATE_UNBLOCKED;
+               rfkill_set_default(type, RFKILL_STATE_UNBLOCKED);
+       } else {
+               rfkill->state = RFKILL_STATE_SOFT_BLOCKED;
+               rfkill_set_default(type, RFKILL_STATE_SOFT_BLOCKED);
+       }
+       return rfkill;
+}
+
 static int eeepc_hotk_add(struct acpi_device *device)
 {
        acpi_status status = AE_OK;
@@ -684,55 +703,30 @@ static int eeepc_hotk_add(struct acpi_device *device)
        eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
 
        if (get_acpi(CM_ASL_WLAN) != -1) {
-               ehotk->eeepc_wlan_rfkill = rfkill_allocate(&device->dev,
-                                                          RFKILL_TYPE_WLAN);
+               ehotk->eeepc_wlan_rfkill =
+                       eeepc_rfkill_alloc("eeepc-wlan",
+                                          &device->dev,
+                                          RFKILL_TYPE_WLAN,
+                                          CM_ASL_WLAN);
 
                if (!ehotk->eeepc_wlan_rfkill)
                        goto wlan_fail;
 
-               ehotk->eeepc_wlan_rfkill->name = "eeepc-wlan";
-               ehotk->eeepc_wlan_rfkill->toggle_radio = eeepc_wlan_rfkill_set;
-               ehotk->eeepc_wlan_rfkill->get_state = eeepc_wlan_rfkill_state;
-               if (get_acpi(CM_ASL_WLAN) == 1) {
-                       ehotk->eeepc_wlan_rfkill->state =
-                               RFKILL_STATE_UNBLOCKED;
-                       rfkill_set_default(RFKILL_TYPE_WLAN,
-                                          RFKILL_STATE_UNBLOCKED);
-               } else {
-                       ehotk->eeepc_wlan_rfkill->state =
-                               RFKILL_STATE_SOFT_BLOCKED;
-                       rfkill_set_default(RFKILL_TYPE_WLAN,
-                                          RFKILL_STATE_SOFT_BLOCKED);
-               }
                result = rfkill_register(ehotk->eeepc_wlan_rfkill);
                if (result)
                        goto wlan_fail;
        }
 
        if (get_acpi(CM_ASL_BLUETOOTH) != -1) {
-               ehotk->eeepc_bluetooth_rfkill =
-                       rfkill_allocate(&device->dev, RFKILL_TYPE_BLUETOOTH);
+               ehotk->eeepc_wlan_rfkill =
+                       eeepc_rfkill_alloc("eeepc-bluetooth",
+                                          &device->dev,
+                                          RFKILL_TYPE_BLUETOOTH,
+                                          CM_ASL_BLUETOOTH);
 
                if (!ehotk->eeepc_bluetooth_rfkill)
                        goto bluetooth_fail;
 
-               ehotk->eeepc_bluetooth_rfkill->name = "eeepc-bluetooth";
-               ehotk->eeepc_bluetooth_rfkill->toggle_radio =
-                       eeepc_bluetooth_rfkill_set;
-               ehotk->eeepc_bluetooth_rfkill->get_state =
-                       eeepc_bluetooth_rfkill_state;
-               if (get_acpi(CM_ASL_BLUETOOTH) == 1) {
-                       ehotk->eeepc_bluetooth_rfkill->state =
-                               RFKILL_STATE_UNBLOCKED;
-                       rfkill_set_default(RFKILL_TYPE_BLUETOOTH,
-                                          RFKILL_STATE_UNBLOCKED);
-               } else {
-                       ehotk->eeepc_bluetooth_rfkill->state =
-                               RFKILL_STATE_SOFT_BLOCKED;
-                       rfkill_set_default(RFKILL_TYPE_BLUETOOTH,
-                                          RFKILL_STATE_SOFT_BLOCKED);
-               }
-
                result = rfkill_register(ehotk->eeepc_bluetooth_rfkill);
                if (result)
                        goto bluetooth_fail;