]> Pileus Git - ~andy/linux/blobdiff - drivers/platform/x86/dell-laptop.c
dell-laptop: Don't set sw_state from the query callback
[~andy/linux] / drivers / platform / x86 / dell-laptop.c
index bae932b60babd1b4d84b722addd9d6c01e6e6c87..7f47396846d19fc5ea4f01c70554fe14ec68c48d 100644 (file)
@@ -425,21 +425,29 @@ out:
        return ret;
 }
 
+static void dell_rfkill_update_sw_state(struct rfkill *rfkill, int radio,
+                                       int status)
+{
+       rfkill_set_sw_state(rfkill, !!(status & BIT(radio + 16)));
+}
+
+static void dell_rfkill_update_hw_state(struct rfkill *rfkill, int radio,
+                                       int status)
+{
+       if (hwswitch_state & (BIT(radio - 1)))
+               rfkill_set_hw_state(rfkill, !(status & BIT(16)));
+}
+
 static void dell_rfkill_query(struct rfkill *rfkill, void *data)
 {
        int status;
-       int bit = (unsigned long)data + 16;
-       int hwswitch_bit = (unsigned long)data - 1;
 
        get_buffer();
        dell_send_request(buffer, 17, 11);
        status = buffer->output[1];
        release_buffer();
 
-       rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
-
-       if (hwswitch_state & (BIT(hwswitch_bit)))
-               rfkill_set_hw_state(rfkill, !(status & BIT(16)));
+       dell_rfkill_update_hw_state(rfkill, (unsigned long)data, status);
 }
 
 static const struct rfkill_ops dell_rfkill_ops = {
@@ -518,12 +526,25 @@ static const struct file_operations dell_debugfs_fops = {
 
 static void dell_update_rfkill(struct work_struct *ignored)
 {
-       if (wifi_rfkill)
-               dell_rfkill_query(wifi_rfkill, (void *)1);
-       if (bluetooth_rfkill)
-               dell_rfkill_query(bluetooth_rfkill, (void *)2);
-       if (wwan_rfkill)
-               dell_rfkill_query(wwan_rfkill, (void *)3);
+       int status;
+
+       get_buffer();
+       dell_send_request(buffer, 17, 11);
+       status = buffer->output[1];
+       release_buffer();
+
+       if (wifi_rfkill) {
+               dell_rfkill_update_hw_state(wifi_rfkill, 1, status);
+               dell_rfkill_update_sw_state(wifi_rfkill, 1, status);
+       }
+       if (bluetooth_rfkill) {
+               dell_rfkill_update_hw_state(bluetooth_rfkill, 2, status);
+               dell_rfkill_update_sw_state(bluetooth_rfkill, 2, status);
+       }
+       if (wwan_rfkill) {
+               dell_rfkill_update_hw_state(wwan_rfkill, 3, status);
+               dell_rfkill_update_sw_state(wwan_rfkill, 3, status);
+       }
 }
 static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
 
@@ -548,6 +569,9 @@ static int __init dell_setup_rfkill(void)
        buffer->input[0] = 0x2;
        dell_send_request(buffer, 17, 11);
        hwswitch_state = buffer->output[1];
+       /* If there is no hwswitch, then clear all hw-controlled bits */
+       if (!(status & BIT(0)))
+               hwswitch_state &= ~7;
        release_buffer();
 
        if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {