rfkill.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Linux RFKILL support for RTL8187
  3. *
  4. * Copyright (c) 2009 Herton Ronaldo Krzesinski <herton@mandriva.com.br>
  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. #include <linux/types.h>
  16. #include <linux/usb.h>
  17. #include <net/mac80211.h>
  18. #include "rtl8187.h"
  19. #include "rfkill.h"
  20. static bool rtl8187_is_radio_enabled(struct rtl8187_priv *priv)
  21. {
  22. u8 gpio;
  23. gpio = rtl818x_ioread8(priv, &priv->map->GPIO0);
  24. rtl818x_iowrite8(priv, &priv->map->GPIO0, gpio & ~priv->rfkill_mask);
  25. gpio = rtl818x_ioread8(priv, &priv->map->GPIO1);
  26. return gpio & priv->rfkill_mask;
  27. }
  28. void rtl8187_rfkill_init(struct ieee80211_hw *hw)
  29. {
  30. struct rtl8187_priv *priv = hw->priv;
  31. priv->rfkill_off = rtl8187_is_radio_enabled(priv);
  32. printk(KERN_INFO "rtl8187: wireless switch is %s\n",
  33. priv->rfkill_off ? "on" : "off");
  34. wiphy_rfkill_set_hw_state(hw->wiphy, !priv->rfkill_off);
  35. wiphy_rfkill_start_polling(hw->wiphy);
  36. }
  37. void rtl8187_rfkill_poll(struct ieee80211_hw *hw)
  38. {
  39. bool enabled;
  40. struct rtl8187_priv *priv = hw->priv;
  41. mutex_lock(&priv->conf_mutex);
  42. enabled = rtl8187_is_radio_enabled(priv);
  43. if (unlikely(enabled != priv->rfkill_off)) {
  44. priv->rfkill_off = enabled;
  45. printk(KERN_INFO "rtl8187: wireless radio switch turned %s\n",
  46. enabled ? "on" : "off");
  47. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  48. }
  49. mutex_unlock(&priv->conf_mutex);
  50. }
  51. void rtl8187_rfkill_exit(struct ieee80211_hw *hw)
  52. {
  53. wiphy_rfkill_stop_polling(hw->wiphy);
  54. }