]> Pileus Git - ~andy/linux/blobdiff - drivers/platform/x86/dell-laptop.c
dell-laptop: Do not skip setting blocked bit rfkill_set while hw-blocked
[~andy/linux] / drivers / platform / x86 / dell-laptop.c
index 48fabf6b6ecb6a8a94986a44adfdab32ed188f5b..b33b77991523d8395b1b7b49a25c38896720a2b8 100644 (file)
@@ -404,42 +404,56 @@ static int dell_rfkill_set(void *data, bool blocked)
        int disable = blocked ? 1 : 0;
        unsigned long radio = (unsigned long)data;
        int hwswitch_bit = (unsigned long)data - 1;
-       int ret = 0;
 
        get_buffer();
        dell_send_request(buffer, 17, 11);
 
        /* If the hardware switch controls this radio, and the hardware
-          switch is disabled, don't allow changing the software state */
+          switch is disabled, always disable the radio */
        if ((hwswitch_state & BIT(hwswitch_bit)) &&
-           !(buffer->output[1] & BIT(16))) {
-               ret = -EINVAL;
-               goto out;
-       }
+           !(buffer->output[1] & BIT(16)))
+               disable = 1;
 
        buffer->input[0] = (1 | (radio<<8) | (disable << 16));
        dell_send_request(buffer, 17, 11);
 
-out:
        release_buffer();
-       return ret;
+       return 0;
+}
+
+/* Must be called with the buffer held */
+static void dell_rfkill_update_sw_state(struct rfkill *rfkill, int radio,
+                                       int status)
+{
+       if (status & BIT(0)) {
+               /* Has hw-switch, sync sw_state to BIOS */
+               int block = rfkill_blocked(rfkill);
+               buffer->input[0] = (1 | (radio << 8) | (block << 16));
+               dell_send_request(buffer, 17, 11);
+       } else {
+               /* No hw-switch, sync BIOS state to sw_state */
+               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)));
+       dell_rfkill_update_hw_state(rfkill, (unsigned long)data, status);
 
-       if (hwswitch_state & (BIT(hwswitch_bit)))
-               rfkill_set_hw_state(rfkill, !(status & BIT(16)));
+       release_buffer();
 }
 
 static const struct rfkill_ops dell_rfkill_ops = {
@@ -518,12 +532,26 @@ 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];
+
+       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);
+       }
+
+       release_buffer();
 }
 static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);