Commit a7ce3f04 authored by Corentin Chary's avatar Corentin Chary Committed by Matthew Garrett

asus-wmi: introduce struct asus_rfkill

First, this allow use to remove the custom asusrfkill_wlan_query,
but this will also allow us to give struct asus_wmi * to
get_devstate/set_devstate later.
Signed-off-by: default avatarCorentin Chary <corentincj@iksaif.net>
Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
parent 57ab7dae
...@@ -114,6 +114,12 @@ struct asus_wmi_debug { ...@@ -114,6 +114,12 @@ struct asus_wmi_debug {
u32 ctrl_param; u32 ctrl_param;
}; };
struct asus_rfkill {
struct asus_wmi *asus;
struct rfkill *rfkill;
u32 dev_id;
};
struct asus_wmi { struct asus_wmi {
struct input_dev *inputdev; struct input_dev *inputdev;
struct backlight_device *backlight_device; struct backlight_device *backlight_device;
...@@ -124,10 +130,10 @@ struct asus_wmi { ...@@ -124,10 +130,10 @@ struct asus_wmi {
struct workqueue_struct *led_workqueue; struct workqueue_struct *led_workqueue;
struct work_struct tpd_led_work; struct work_struct tpd_led_work;
struct rfkill *wlan_rfkill; struct asus_rfkill wlan;
struct rfkill *bluetooth_rfkill; struct asus_rfkill bluetooth;
struct rfkill *wimax_rfkill; struct asus_rfkill wimax;
struct rfkill *wwan3g_rfkill; struct asus_rfkill wwan3g;
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
struct mutex hotplug_lock; struct mutex hotplug_lock;
...@@ -377,8 +383,8 @@ static void asus_rfkill_hotplug(struct asus_wmi *asus) ...@@ -377,8 +383,8 @@ static void asus_rfkill_hotplug(struct asus_wmi *asus)
mutex_lock(&asus->hotplug_lock); mutex_lock(&asus->hotplug_lock);
if (asus->wlan_rfkill) if (asus->wlan.rfkill)
rfkill_set_sw_state(asus->wlan_rfkill, blocked); rfkill_set_sw_state(asus->wlan.rfkill, blocked);
if (asus->hotplug_slot) { if (asus->hotplug_slot) {
bus = pci_find_bus(0, 1); bus = pci_find_bus(0, 1);
...@@ -570,11 +576,11 @@ static int asus_setup_pci_hotplug(struct asus_wmi *asus) ...@@ -570,11 +576,11 @@ static int asus_setup_pci_hotplug(struct asus_wmi *asus)
*/ */
static int asus_rfkill_set(void *data, bool blocked) static int asus_rfkill_set(void *data, bool blocked)
{ {
int dev_id = (unsigned long)data; struct asus_rfkill *priv = data;
u32 ctrl_param = !blocked; u32 ctrl_param = !blocked;
acpi_status status; acpi_status status;
status = asus_wmi_set_devstate(dev_id, ctrl_param, NULL); status = asus_wmi_set_devstate(priv->dev_id, ctrl_param, NULL);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -EIO; return -EIO;
...@@ -584,20 +590,21 @@ static int asus_rfkill_set(void *data, bool blocked) ...@@ -584,20 +590,21 @@ static int asus_rfkill_set(void *data, bool blocked)
static void asus_rfkill_query(struct rfkill *rfkill, void *data) static void asus_rfkill_query(struct rfkill *rfkill, void *data)
{ {
int dev_id = (unsigned long)data; struct asus_rfkill *priv = data;
int result; int result;
result = asus_wmi_get_devstate_simple(dev_id); result = asus_wmi_get_devstate_simple(priv->dev_id);
if (result < 0) if (result < 0)
return; return;
rfkill_set_sw_state(rfkill, !result); rfkill_set_sw_state(priv->rfkill, !result);
} }
static int asus_rfkill_wlan_set(void *data, bool blocked) static int asus_rfkill_wlan_set(void *data, bool blocked)
{ {
struct asus_wmi *asus = data; struct asus_rfkill *priv = data;
struct asus_wmi *asus = priv->asus;
int ret; int ret;
/* /*
...@@ -608,19 +615,14 @@ static int asus_rfkill_wlan_set(void *data, bool blocked) ...@@ -608,19 +615,14 @@ static int asus_rfkill_wlan_set(void *data, bool blocked)
* any wmi method * any wmi method
*/ */
mutex_lock(&asus->wmi_lock); mutex_lock(&asus->wmi_lock);
ret = asus_rfkill_set((void *)(long)ASUS_WMI_DEVID_WLAN, blocked); ret = asus_rfkill_set(data, blocked);
mutex_unlock(&asus->wmi_lock); mutex_unlock(&asus->wmi_lock);
return ret; return ret;
} }
static void asus_rfkill_wlan_query(struct rfkill *rfkill, void *data)
{
asus_rfkill_query(rfkill, (void *)(long)ASUS_WMI_DEVID_WLAN);
}
static const struct rfkill_ops asus_rfkill_wlan_ops = { static const struct rfkill_ops asus_rfkill_wlan_ops = {
.set_block = asus_rfkill_wlan_set, .set_block = asus_rfkill_wlan_set,
.query = asus_rfkill_wlan_query, .query = asus_rfkill_query,
}; };
static const struct rfkill_ops asus_rfkill_ops = { static const struct rfkill_ops asus_rfkill_ops = {
...@@ -629,20 +631,24 @@ static const struct rfkill_ops asus_rfkill_ops = { ...@@ -629,20 +631,24 @@ static const struct rfkill_ops asus_rfkill_ops = {
}; };
static int asus_new_rfkill(struct asus_wmi *asus, static int asus_new_rfkill(struct asus_wmi *asus,
struct rfkill **rfkill, struct asus_rfkill *arfkill,
const char *name, enum rfkill_type type, int dev_id) const char *name, enum rfkill_type type, int dev_id)
{ {
int result = asus_wmi_get_devstate_simple(dev_id); int result = asus_wmi_get_devstate_simple(dev_id);
struct rfkill **rfkill = &arfkill->rfkill;
if (result < 0) if (result < 0)
return result; return result;
arfkill->dev_id = dev_id;
arfkill->asus = asus;
if (dev_id == ASUS_WMI_DEVID_WLAN && asus->driver->hotplug_wireless) if (dev_id == ASUS_WMI_DEVID_WLAN && asus->driver->hotplug_wireless)
*rfkill = rfkill_alloc(name, &asus->platform_device->dev, type, *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
&asus_rfkill_wlan_ops, asus); &asus_rfkill_wlan_ops, arfkill);
else else
*rfkill = rfkill_alloc(name, &asus->platform_device->dev, type, *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
&asus_rfkill_ops, (void *)(long)dev_id); &asus_rfkill_ops, arfkill);
if (!*rfkill) if (!*rfkill)
return -EINVAL; return -EINVAL;
...@@ -662,10 +668,10 @@ static void asus_wmi_rfkill_exit(struct asus_wmi *asus) ...@@ -662,10 +668,10 @@ static void asus_wmi_rfkill_exit(struct asus_wmi *asus)
asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P5"); asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P6"); asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P7"); asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
if (asus->wlan_rfkill) { if (asus->wlan.rfkill) {
rfkill_unregister(asus->wlan_rfkill); rfkill_unregister(asus->wlan.rfkill);
rfkill_destroy(asus->wlan_rfkill); rfkill_destroy(asus->wlan.rfkill);
asus->wlan_rfkill = NULL; asus->wlan.rfkill = NULL;
} }
/* /*
* Refresh pci hotplug in case the rfkill state was changed after * Refresh pci hotplug in case the rfkill state was changed after
...@@ -677,20 +683,20 @@ static void asus_wmi_rfkill_exit(struct asus_wmi *asus) ...@@ -677,20 +683,20 @@ static void asus_wmi_rfkill_exit(struct asus_wmi *asus)
if (asus->hotplug_workqueue) if (asus->hotplug_workqueue)
destroy_workqueue(asus->hotplug_workqueue); destroy_workqueue(asus->hotplug_workqueue);
if (asus->bluetooth_rfkill) { if (asus->bluetooth.rfkill) {
rfkill_unregister(asus->bluetooth_rfkill); rfkill_unregister(asus->bluetooth.rfkill);
rfkill_destroy(asus->bluetooth_rfkill); rfkill_destroy(asus->bluetooth.rfkill);
asus->bluetooth_rfkill = NULL; asus->bluetooth.rfkill = NULL;
} }
if (asus->wimax_rfkill) { if (asus->wimax.rfkill) {
rfkill_unregister(asus->wimax_rfkill); rfkill_unregister(asus->wimax.rfkill);
rfkill_destroy(asus->wimax_rfkill); rfkill_destroy(asus->wimax.rfkill);
asus->wimax_rfkill = NULL; asus->wimax.rfkill = NULL;
} }
if (asus->wwan3g_rfkill) { if (asus->wwan3g.rfkill) {
rfkill_unregister(asus->wwan3g_rfkill); rfkill_unregister(asus->wwan3g.rfkill);
rfkill_destroy(asus->wwan3g_rfkill); rfkill_destroy(asus->wwan3g.rfkill);
asus->wwan3g_rfkill = NULL; asus->wwan3g.rfkill = NULL;
} }
} }
...@@ -701,30 +707,27 @@ static int asus_wmi_rfkill_init(struct asus_wmi *asus) ...@@ -701,30 +707,27 @@ static int asus_wmi_rfkill_init(struct asus_wmi *asus)
mutex_init(&asus->hotplug_lock); mutex_init(&asus->hotplug_lock);
mutex_init(&asus->wmi_lock); mutex_init(&asus->wmi_lock);
result = asus_new_rfkill(asus, &asus->wlan_rfkill, result = asus_new_rfkill(asus, &asus->wlan, "asus-wlan",
"asus-wlan", RFKILL_TYPE_WLAN, RFKILL_TYPE_WLAN, ASUS_WMI_DEVID_WLAN);
ASUS_WMI_DEVID_WLAN);
if (result && result != -ENODEV) if (result && result != -ENODEV)
goto exit; goto exit;
result = asus_new_rfkill(asus, &asus->bluetooth_rfkill, result = asus_new_rfkill(asus, &asus->bluetooth,
"asus-bluetooth", RFKILL_TYPE_BLUETOOTH, "asus-bluetooth", RFKILL_TYPE_BLUETOOTH,
ASUS_WMI_DEVID_BLUETOOTH); ASUS_WMI_DEVID_BLUETOOTH);
if (result && result != -ENODEV) if (result && result != -ENODEV)
goto exit; goto exit;
result = asus_new_rfkill(asus, &asus->wimax_rfkill, result = asus_new_rfkill(asus, &asus->wimax, "asus-wimax",
"asus-wimax", RFKILL_TYPE_WIMAX, RFKILL_TYPE_WIMAX, ASUS_WMI_DEVID_WIMAX);
ASUS_WMI_DEVID_WIMAX);
if (result && result != -ENODEV) if (result && result != -ENODEV)
goto exit; goto exit;
result = asus_new_rfkill(asus, &asus->wwan3g_rfkill, result = asus_new_rfkill(asus, &asus->wwan3g, "asus-wwan3g",
"asus-wwan3g", RFKILL_TYPE_WWAN, RFKILL_TYPE_WWAN, ASUS_WMI_DEVID_WWAN3G);
ASUS_WMI_DEVID_WWAN3G);
if (result && result != -ENODEV) if (result && result != -ENODEV)
goto exit; goto exit;
...@@ -1277,7 +1280,7 @@ static int asus_hotk_thaw(struct device *device) ...@@ -1277,7 +1280,7 @@ static int asus_hotk_thaw(struct device *device)
{ {
struct asus_wmi *asus = dev_get_drvdata(device); struct asus_wmi *asus = dev_get_drvdata(device);
if (asus->wlan_rfkill) { if (asus->wlan.rfkill) {
bool wlan; bool wlan;
/* /*
...@@ -1298,20 +1301,20 @@ static int asus_hotk_restore(struct device *device) ...@@ -1298,20 +1301,20 @@ static int asus_hotk_restore(struct device *device)
int bl; int bl;
/* Refresh both wlan rfkill state and pci hotplug */ /* Refresh both wlan rfkill state and pci hotplug */
if (asus->wlan_rfkill) if (asus->wlan.rfkill)
asus_rfkill_hotplug(asus); asus_rfkill_hotplug(asus);
if (asus->bluetooth_rfkill) { if (asus->bluetooth.rfkill) {
bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_BLUETOOTH); bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_BLUETOOTH);
rfkill_set_sw_state(asus->bluetooth_rfkill, bl); rfkill_set_sw_state(asus->bluetooth.rfkill, bl);
} }
if (asus->wimax_rfkill) { if (asus->wimax.rfkill) {
bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WIMAX); bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WIMAX);
rfkill_set_sw_state(asus->wimax_rfkill, bl); rfkill_set_sw_state(asus->wimax.rfkill, bl);
} }
if (asus->wwan3g_rfkill) { if (asus->wwan3g.rfkill) {
bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WWAN3G); bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WWAN3G);
rfkill_set_sw_state(asus->wwan3g_rfkill, bl); rfkill_set_sw_state(asus->wwan3g.rfkill, bl);
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment