Commit 40969c7d authored by Corentin Chary's avatar Corentin Chary Committed by Matthew Garrett

asus-laptop: cleanup rfkill code

Signed-off-by: default avatarCorentin Chary <corentincj@iksaif.net>
Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
parent ce6c468f
...@@ -218,7 +218,7 @@ struct asus_led { ...@@ -218,7 +218,7 @@ struct asus_led {
/* /*
* Same thing for rfkill * Same thing for rfkill
*/ */
struct asus_pega_rfkill { struct asus_rfkill {
int control_id; /* type of control. Maps to PEGA_* values */ int control_id; /* type of control. Maps to PEGA_* values */
struct rfkill *rfkill; struct rfkill *rfkill;
struct asus_laptop *asus; struct asus_laptop *asus;
...@@ -256,11 +256,10 @@ struct asus_laptop { ...@@ -256,11 +256,10 @@ struct asus_laptop {
int pega_acc_y; int pega_acc_y;
int pega_acc_z; int pega_acc_z;
struct rfkill *gps_rfkill; struct asus_rfkill wlan;
struct asus_rfkill bluetooth;
struct asus_pega_rfkill wlanrfk; struct asus_rfkill wwan;
struct asus_pega_rfkill btrfk; struct asus_rfkill gps;
struct asus_pega_rfkill wwanrfk;
acpi_handle handle; /* the handle of the hotk device */ acpi_handle handle; /* the handle of the hotk device */
u32 ledd_status; /* status of the LED display */ u32 ledd_status; /* status of the LED display */
...@@ -1228,7 +1227,7 @@ static ssize_t store_gps(struct device *dev, struct device_attribute *attr, ...@@ -1228,7 +1227,7 @@ static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
ret = asus_gps_switch(asus, !!value); ret = asus_gps_switch(asus, !!value);
if (ret) if (ret)
return ret; return ret;
rfkill_set_sw_state(asus->gps_rfkill, !value); rfkill_set_sw_state(asus->gps.rfkill, !value);
return rv; return rv;
} }
...@@ -1246,13 +1245,22 @@ static const struct rfkill_ops asus_gps_rfkill_ops = { ...@@ -1246,13 +1245,22 @@ static const struct rfkill_ops asus_gps_rfkill_ops = {
.set_block = asus_gps_rfkill_set, .set_block = asus_gps_rfkill_set,
}; };
static void asus_rfkill_terminate(struct asus_rfkill *rfk)
{
if (!rfk->rfkill)
return ;
rfkill_unregister(rfk->rfkill);
rfkill_destroy(rfk->rfkill);
rfk->rfkill = NULL;
}
static void asus_rfkill_exit(struct asus_laptop *asus) static void asus_rfkill_exit(struct asus_laptop *asus)
{ {
if (asus->gps_rfkill) { asus_rfkill_terminate(&asus->wwan);
rfkill_unregister(asus->gps_rfkill); asus_rfkill_terminate(&asus->bluetooth);
rfkill_destroy(asus->gps_rfkill); asus_rfkill_terminate(&asus->wlan);
asus->gps_rfkill = NULL; asus_rfkill_terminate(&asus->gps);
}
} }
static int asus_rfkill_init(struct asus_laptop *asus) static int asus_rfkill_init(struct asus_laptop *asus)
...@@ -1264,16 +1272,16 @@ static int asus_rfkill_init(struct asus_laptop *asus) ...@@ -1264,16 +1272,16 @@ static int asus_rfkill_init(struct asus_laptop *asus)
acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL)) acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
return 0; return 0;
asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev, asus->gps.rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
RFKILL_TYPE_GPS, RFKILL_TYPE_GPS,
&asus_gps_rfkill_ops, asus); &asus_gps_rfkill_ops, asus);
if (!asus->gps_rfkill) if (!asus->gps.rfkill)
return -EINVAL; return -EINVAL;
result = rfkill_register(asus->gps_rfkill); result = rfkill_register(asus->gps.rfkill);
if (result) { if (result) {
rfkill_destroy(asus->gps_rfkill); rfkill_destroy(asus->gps.rfkill);
asus->gps_rfkill = NULL; asus->gps.rfkill = NULL;
} }
return result; return result;
...@@ -1281,11 +1289,9 @@ static int asus_rfkill_init(struct asus_laptop *asus) ...@@ -1281,11 +1289,9 @@ static int asus_rfkill_init(struct asus_laptop *asus)
static int pega_rfkill_set(void *data, bool blocked) static int pega_rfkill_set(void *data, bool blocked)
{ {
struct asus_pega_rfkill *pega_rfk = data; struct asus_rfkill *rfk = data;
int ret = asus_pega_lucid_set(pega_rfk->asus, pega_rfk->control_id, !blocked);
pr_warn("Setting rfkill %d, to %d; returned %d\n", pega_rfk->control_id, !blocked, ret);
int ret = asus_pega_lucid_set(rfk->asus, rfk->control_id, !blocked);
return ret; return ret;
} }
...@@ -1293,40 +1299,22 @@ static const struct rfkill_ops pega_rfkill_ops = { ...@@ -1293,40 +1299,22 @@ static const struct rfkill_ops pega_rfkill_ops = {
.set_block = pega_rfkill_set, .set_block = pega_rfkill_set,
}; };
static void pega_rfkill_terminate(struct asus_pega_rfkill *pega_rfk) static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
{ const char *name, int controlid, int rfkill_type)
pr_warn("Terminating %d\n", pega_rfk->control_id);
if (pega_rfk->rfkill) {
rfkill_unregister(pega_rfk->rfkill);
rfkill_destroy(pega_rfk->rfkill);
pega_rfk->rfkill = NULL;
}
}
static void pega_rfkill_exit(struct asus_laptop *asus)
{
pega_rfkill_terminate(&asus->wwanrfk);
pega_rfkill_terminate(&asus->btrfk);
pega_rfkill_terminate(&asus->wlanrfk);
}
static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_pega_rfkill *pega_rfk,
const char *name, int controlid, int rfkill_type)
{ {
int result; int result;
pr_warn("Setting up rfk %s, control %d, type %d\n", name, controlid, rfkill_type); rfk->control_id = controlid;
pega_rfk->control_id = controlid; rfk->asus = asus;
pega_rfk->asus = asus; rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
pega_rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev, rfkill_type, &pega_rfkill_ops, rfk);
rfkill_type, &pega_rfkill_ops, pega_rfk); if (!rfk->rfkill)
if (!pega_rfk->rfkill)
return -EINVAL; return -EINVAL;
result = rfkill_register(pega_rfk->rfkill); result = rfkill_register(rfk->rfkill);
if (result) { if (result) {
rfkill_destroy(pega_rfk->rfkill); rfkill_destroy(rfk->rfkill);
pega_rfk->rfkill = NULL; rfk->rfkill = NULL;
} }
return result; return result;
...@@ -1339,22 +1327,22 @@ static int pega_rfkill_init(struct asus_laptop *asus) ...@@ -1339,22 +1327,22 @@ static int pega_rfkill_init(struct asus_laptop *asus)
if(!asus->is_pega_lucid) if(!asus->is_pega_lucid)
return -ENODEV; return -ENODEV;
ret = pega_rfkill_setup(asus, &asus->wlanrfk, "pega-wlan", PEGA_WLAN, RFKILL_TYPE_WLAN); ret = pega_rfkill_setup(asus, &asus->wlan, "pega-wlan",
PEGA_WLAN, RFKILL_TYPE_WLAN);
if(ret) if(ret)
return ret; goto exit;
ret = pega_rfkill_setup(asus, &asus->btrfk, "pega-bt", PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
if(ret) ret = pega_rfkill_setup(asus, &asus->bluetooth, "pega-bt",
goto err_btrfk; PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
ret = pega_rfkill_setup(asus, &asus->wwanrfk, "pega-wwan", PEGA_WWAN, RFKILL_TYPE_WWAN);
if(ret) if(ret)
goto err_wwanrfk; goto exit;
pr_warn("Pega rfkill init succeeded\n"); ret = pega_rfkill_setup(asus, &asus->wwan, "pega-wwan",
return 0; PEGA_WWAN, RFKILL_TYPE_WWAN);
err_wwanrfk:
pega_rfkill_terminate(&asus->btrfk); exit:
err_btrfk: if (ret)
pega_rfkill_terminate(&asus->wlanrfk); asus_rfkill_exit(asus);
return ret; return ret;
} }
...@@ -1377,7 +1365,7 @@ static int asus_input_init(struct asus_laptop *asus) ...@@ -1377,7 +1365,7 @@ static int asus_input_init(struct asus_laptop *asus)
input = input_allocate_device(); input = input_allocate_device();
if (!input) { if (!input) {
pr_info("Unable to allocate input device\n"); pr_warn("Unable to allocate input device\n");
return -ENOMEM; return -ENOMEM;
} }
input->name = "Asus Laptop extra buttons"; input->name = "Asus Laptop extra buttons";
...@@ -1392,7 +1380,7 @@ static int asus_input_init(struct asus_laptop *asus) ...@@ -1392,7 +1380,7 @@ static int asus_input_init(struct asus_laptop *asus)
} }
error = input_register_device(input); error = input_register_device(input);
if (error) { if (error) {
pr_info("Unable to register input device\n"); pr_warn("Unable to register input device\n");
goto err_free_keymap; goto err_free_keymap;
} }
...@@ -1830,7 +1818,6 @@ static int asus_acpi_remove(struct acpi_device *device, int type) ...@@ -1830,7 +1818,6 @@ static int asus_acpi_remove(struct acpi_device *device, int type)
asus_led_exit(asus); asus_led_exit(asus);
asus_input_exit(asus); asus_input_exit(asus);
pega_accel_exit(asus); pega_accel_exit(asus);
pega_rfkill_exit(asus);
asus_platform_exit(asus); asus_platform_exit(asus);
kfree(asus->name); kfree(asus->name);
......
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