From patchwork Mon Aug 17 23:27:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 42209 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7HNSKSP018447 for ; Mon, 17 Aug 2009 23:28:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751436AbZHQX1R (ORCPT ); Mon, 17 Aug 2009 19:27:17 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758325AbZHQX1Q (ORCPT ); Mon, 17 Aug 2009 19:27:16 -0400 Received: from ausc60ps301.us.dell.com ([143.166.148.206]:23877 "EHLO ausc60ps301.us.dell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932448AbZHQX0y (ORCPT ); Mon, 17 Aug 2009 19:26:54 -0400 X-Loopcount0: from 10.9.160.253 Message-ID: <4A89E768.7010207@dell.com> Date: Mon, 17 Aug 2009 18:27:36 -0500 From: Mario Limonciello User-Agent: Thunderbird 2.0.0.22 (X11/20090804) MIME-Version: 1.0 To: cezary.jackiewicz@gmail.com CC: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] Add rfkill support to compal-laptop X-Enigmail-Version: 0.95.7 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In order to be useful in modern kernels and standard interfaces, compal-laptop should have rfkill support. This patch adds it. --- drivers/platform/x86/compal-laptop.c.old 2009-08-17 07:01:36.244874430 -0500 +++ drivers/platform/x86/compal-laptop.c 2009-08-17 07:02:15.012836625 -0500 @@ -52,6 +52,7 @@ #include #include #include +#include #define COMPAL_DRIVER_VERSION "0.2.6" @@ -64,6 +65,9 @@ #define WLAN_MASK 0x01 #define BT_MASK 0x02 +static struct rfkill *wifi_rfkill; +static struct rfkill *bluetooth_rfkill; + static int force; module_param(force, bool, 0); MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); @@ -89,6 +93,87 @@ return (int) result; } +static void compal_rfkill_query(struct rfkill *rfkill, void *data) +{ + unsigned long radio = (unsigned long) data; + u8 result; + bool blocked; + + ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); + + if ((result & KILLSWITCH_MASK) == 0) + blocked = 1; + else if (radio == WLAN_MASK) + blocked = !(result & WLAN_MASK); + else + blocked = !((result & BT_MASK) >> 1); + + rfkill_set_sw_state(rfkill,blocked); + rfkill_set_hw_state(rfkill,0); +} + +static int compal_rfkill_set(void *data, bool blocked) +{ + unsigned long radio = (unsigned long) data; + u8 result, value; + + ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); + + if ((result & KILLSWITCH_MASK) == 0) + return -EINVAL; + else { + if (!blocked) + value = (u8) (result | radio); + else + value = (u8) (result & ~radio); + ec_write(COMPAL_EC_COMMAND_WIRELESS, value); + } + + return 0; +} + +static const struct rfkill_ops compal_rfkill_ops = { + .set_block = compal_rfkill_set, + .query = compal_rfkill_query, +}; + +static int setup_rfkill(void) +{ + int ret; + + wifi_rfkill = rfkill_alloc("compal-wifi", NULL, RFKILL_TYPE_WLAN, + &compal_rfkill_ops, (void *) WLAN_MASK); + if (!wifi_rfkill) { + ret = -ENOMEM; + goto err_wifi; + } + ret = rfkill_register(wifi_rfkill); + if (ret) + goto err_wifi; + + bluetooth_rfkill = rfkill_alloc("compal-bluetooth", NULL, RFKILL_TYPE_BLUETOOTH, + &compal_rfkill_ops, (void *) BT_MASK); + if (!bluetooth_rfkill) { + ret = -ENOMEM; + goto err_bt; + } + ret = rfkill_register(bluetooth_rfkill); + if (ret) + goto err_bt; + + return 0; +err_bt: + rfkill_destroy(bluetooth_rfkill); + if (bluetooth_rfkill) + rfkill_unregister(bluetooth_rfkill); +err_wifi: + rfkill_destroy(wifi_rfkill); + if (wifi_rfkill) + rfkill_unregister(wifi_rfkill); + + return ret; +} + static int set_wlan_state(int state) { u8 result, value; @@ -357,6 +442,12 @@ if (!force && !dmi_check_system(compal_dmi_table)) return -ENODEV; + ret = setup_rfkill(); + if (ret) { + printk(KERN_WARNING "compal-laptop: Unable to setup rfkill\n"); + goto fail_rfkill; + } + /* Register backlight stuff */ if (!acpi_video_backlight_support()) { @@ -410,6 +501,13 @@ backlight_device_unregister(compalbl_device); +fail_rfkill: + + if (wifi_rfkill) + rfkill_unregister(wifi_rfkill); + if (bluetooth_rfkill) + rfkill_unregister(bluetooth_rfkill); + return ret; } @@ -420,6 +518,10 @@ platform_device_unregister(compal_device); platform_driver_unregister(&compal_driver); backlight_device_unregister(compalbl_device); + if (wifi_rfkill) + rfkill_unregister(wifi_rfkill); + if (bluetooth_rfkill) + rfkill_unregister(bluetooth_rfkill); printk(KERN_INFO "compal-laptop: driver unloaded.\n"); }