Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rfkill.c
Go to the documentation of this file.
1 /*
2  * Linux RFKILL support for RTL8187
3  *
4  * Copyright (c) 2009 Herton Ronaldo Krzesinski <[email protected]>
5  *
6  * Based on the RFKILL handling in the r8187 driver, which is:
7  * Copyright (c) Realtek Semiconductor Corp. All rights reserved.
8  *
9  * Thanks to Realtek for their support!
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  */
15 
16 #include <linux/types.h>
17 #include <linux/usb.h>
18 #include <net/mac80211.h>
19 
20 #include "rtl8187.h"
21 #include "rfkill.h"
22 
23 static bool rtl8187_is_radio_enabled(struct rtl8187_priv *priv)
24 {
25  u8 gpio;
26 
27  gpio = rtl818x_ioread8(priv, &priv->map->GPIO0);
28  rtl818x_iowrite8(priv, &priv->map->GPIO0, gpio & ~priv->rfkill_mask);
29  gpio = rtl818x_ioread8(priv, &priv->map->GPIO1);
30 
31  return gpio & priv->rfkill_mask;
32 }
33 
35 {
36  struct rtl8187_priv *priv = hw->priv;
37 
38  priv->rfkill_off = rtl8187_is_radio_enabled(priv);
39  printk(KERN_INFO "rtl8187: wireless switch is %s\n",
40  priv->rfkill_off ? "on" : "off");
43 }
44 
46 {
47  bool enabled;
48  struct rtl8187_priv *priv = hw->priv;
49 
50  mutex_lock(&priv->conf_mutex);
51  enabled = rtl8187_is_radio_enabled(priv);
52  if (unlikely(enabled != priv->rfkill_off)) {
53  priv->rfkill_off = enabled;
54  printk(KERN_INFO "rtl8187: wireless radio switch turned %s\n",
55  enabled ? "on" : "off");
56  wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
57  }
58  mutex_unlock(&priv->conf_mutex);
59 }
60 
62 {
64 }