* 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
*/
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;
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 */
}
}
- 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)
}
}
+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;
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;