WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / wireless / realtek / rtl818x / rtl8187 / rfkill.c
blobc57a4742b03eddf9e6c0e6fad7fa3461bb906546
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Linux RFKILL support for RTL8187
5 * Copyright (c) 2009 Herton Ronaldo Krzesinski <herton@mandriva.com.br>
7 * Based on the RFKILL handling in the r8187 driver, which is:
8 * Copyright (c) Realtek Semiconductor Corp. All rights reserved.
10 * Thanks to Realtek for their support!
13 #include <linux/types.h>
14 #include <linux/usb.h>
15 #include <net/mac80211.h>
17 #include "rtl8187.h"
18 #include "rfkill.h"
20 static bool rtl8187_is_radio_enabled(struct rtl8187_priv *priv)
22 u8 gpio;
24 gpio = rtl818x_ioread8(priv, &priv->map->GPIO0);
25 rtl818x_iowrite8(priv, &priv->map->GPIO0, gpio & ~priv->rfkill_mask);
26 gpio = rtl818x_ioread8(priv, &priv->map->GPIO1);
28 return gpio & priv->rfkill_mask;
31 void rtl8187_rfkill_init(struct ieee80211_hw *hw)
33 struct rtl8187_priv *priv = hw->priv;
35 priv->rfkill_off = rtl8187_is_radio_enabled(priv);
36 printk(KERN_INFO "rtl8187: wireless switch is %s\n",
37 priv->rfkill_off ? "on" : "off");
38 wiphy_rfkill_set_hw_state(hw->wiphy, !priv->rfkill_off);
39 wiphy_rfkill_start_polling(hw->wiphy);
42 void rtl8187_rfkill_poll(struct ieee80211_hw *hw)
44 bool enabled;
45 struct rtl8187_priv *priv = hw->priv;
47 mutex_lock(&priv->conf_mutex);
48 enabled = rtl8187_is_radio_enabled(priv);
49 if (unlikely(enabled != priv->rfkill_off)) {
50 priv->rfkill_off = enabled;
51 printk(KERN_INFO "rtl8187: wireless radio switch turned %s\n",
52 enabled ? "on" : "off");
53 wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
55 mutex_unlock(&priv->conf_mutex);
58 void rtl8187_rfkill_exit(struct ieee80211_hw *hw)
60 wiphy_rfkill_stop_polling(hw->wiphy);