wl127x-rfkill.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Bluetooth TI wl127x rfkill power control via GPIO
  3. *
  4. * Copyright (C) 2009 Motorola, Inc.
  5. * Copyright (C) 2008 Texas Instruments
  6. * Initial code: Pavan Savoy <pavan.savoy@gmail.com> (wl127x_power.c)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/gpio.h>
  26. #include <linux/rfkill.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/wl127x-rfkill.h>
  29. static int wl127x_rfkill_set_power(void *data, enum rfkill_state state)
  30. {
  31. int nshutdown_gpio = (int) data;
  32. switch (state) {
  33. case RFKILL_STATE_UNBLOCKED:
  34. gpio_set_value(nshutdown_gpio, 1);
  35. break;
  36. case RFKILL_STATE_SOFT_BLOCKED:
  37. gpio_set_value(nshutdown_gpio, 0);
  38. break;
  39. default:
  40. printk(KERN_ERR "invalid bluetooth rfkill state %d\n", state);
  41. }
  42. return 0;
  43. }
  44. static int wl127x_rfkill_probe(struct platform_device *pdev)
  45. {
  46. int rc = 0;
  47. struct wl127x_rfkill_platform_data *pdata = pdev->dev.platform_data;
  48. enum rfkill_state default_state = RFKILL_STATE_SOFT_BLOCKED; /* off */
  49. rc = gpio_request(pdata->nshutdown_gpio, "wl127x_nshutdown_gpio");
  50. if (unlikely(rc))
  51. return rc;
  52. rc = gpio_direction_output(pdata->nshutdown_gpio, 0);
  53. if (unlikely(rc))
  54. return rc;
  55. rfkill_set_default(RFKILL_TYPE_BLUETOOTH, default_state);
  56. wl127x_rfkill_set_power(NULL, default_state);
  57. pdata->rfkill = rfkill_allocate(&pdev->dev, RFKILL_TYPE_BLUETOOTH);
  58. if (unlikely(!pdata->rfkill))
  59. return -ENOMEM;
  60. pdata->rfkill->name = "wl127x";
  61. pdata->rfkill->state = default_state;
  62. /* userspace cannot take exclusive control */
  63. pdata->rfkill->user_claim_unsupported = 1;
  64. pdata->rfkill->user_claim = 0;
  65. pdata->rfkill->data = (void *) pdata->nshutdown_gpio;
  66. pdata->rfkill->toggle_radio = wl127x_rfkill_set_power;
  67. rc = rfkill_register(pdata->rfkill);
  68. if (unlikely(rc))
  69. rfkill_free(pdata->rfkill);
  70. return 0;
  71. }
  72. static int wl127x_rfkill_remove(struct platform_device *pdev)
  73. {
  74. struct wl127x_rfkill_platform_data *pdata = pdev->dev.platform_data;
  75. rfkill_unregister(pdata->rfkill);
  76. rfkill_free(pdata->rfkill);
  77. gpio_free(pdata->nshutdown_gpio);
  78. return 0;
  79. }
  80. static struct platform_driver wl127x_rfkill_platform_driver = {
  81. .probe = wl127x_rfkill_probe,
  82. .remove = wl127x_rfkill_remove,
  83. .driver = {
  84. .name = "wl127x-rfkill",
  85. .owner = THIS_MODULE,
  86. },
  87. };
  88. static int __init wl127x_rfkill_init(void)
  89. {
  90. return platform_driver_register(&wl127x_rfkill_platform_driver);
  91. }
  92. static void __exit wl127x_rfkill_exit(void)
  93. {
  94. platform_driver_unregister(&wl127x_rfkill_platform_driver);
  95. }
  96. module_init(wl127x_rfkill_init);
  97. module_exit(wl127x_rfkill_exit);
  98. MODULE_ALIAS("platform:wl127x");
  99. MODULE_DESCRIPTION("wl127x-rfkill");
  100. MODULE_AUTHOR("Motorola");
  101. MODULE_LICENSE("GPL");