board-sapphire-rfkill.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* linux/arch/arm/mach-msm/board-sapphire-rfkill.c
  2. * Copyright (C) 2007-2009 HTC Corporation.
  3. * Author: Thomas Tsai <thomas_tsai@htc.com>
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. /* Control bluetooth power for sapphire platform */
  15. #include <linux/platform_device.h>
  16. #include <linux/module.h>
  17. #include <linux/device.h>
  18. #include <linux/rfkill.h>
  19. #include <linux/delay.h>
  20. #include <linux/gpio.h>
  21. #include <asm/mach-types.h>
  22. #include "gpio_chip.h"
  23. #include "board-sapphire.h"
  24. static struct rfkill *bt_rfk;
  25. static const char bt_name[] = "brf6300";
  26. extern int sapphire_bt_fastclock_power(int on);
  27. static int bluetooth_set_power(void *data, bool blocked)
  28. {
  29. if (!blocked) {
  30. sapphire_bt_fastclock_power(1);
  31. gpio_set_value(SAPPHIRE_GPIO_BT_32K_EN, 1);
  32. udelay(10);
  33. gpio_direction_output(101, 1);
  34. } else {
  35. gpio_direction_output(101, 0);
  36. gpio_set_value(SAPPHIRE_GPIO_BT_32K_EN, 0);
  37. sapphire_bt_fastclock_power(0);
  38. }
  39. return 0;
  40. }
  41. static struct rfkill_ops sapphire_rfkill_ops = {
  42. .set_block = bluetooth_set_power,
  43. };
  44. static int sapphire_rfkill_probe(struct platform_device *pdev)
  45. {
  46. int rc = 0;
  47. bool default_state = true; /* off */
  48. bluetooth_set_power(NULL, default_state);
  49. bt_rfk = rfkill_alloc(bt_name, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
  50. &sapphire_rfkill_ops, NULL);
  51. if (!bt_rfk)
  52. return -ENOMEM;
  53. /* userspace cannot take exclusive control */
  54. rfkill_set_states(bt_rfk, default_state, false);
  55. rc = rfkill_register(bt_rfk);
  56. if (rc)
  57. rfkill_destroy(bt_rfk);
  58. return rc;
  59. }
  60. static int sapphire_rfkill_remove(struct platform_device *dev)
  61. {
  62. rfkill_unregister(bt_rfk);
  63. rfkill_destroy(bt_rfk);
  64. return 0;
  65. }
  66. static struct platform_driver sapphire_rfkill_driver = {
  67. .probe = sapphire_rfkill_probe,
  68. .remove = sapphire_rfkill_remove,
  69. .driver = {
  70. .name = "sapphire_rfkill",
  71. .owner = THIS_MODULE,
  72. },
  73. };
  74. static int __init sapphire_rfkill_init(void)
  75. {
  76. return platform_driver_register(&sapphire_rfkill_driver);
  77. }
  78. static void __exit sapphire_rfkill_exit(void)
  79. {
  80. platform_driver_unregister(&sapphire_rfkill_driver);
  81. }
  82. module_init(sapphire_rfkill_init);
  83. module_exit(sapphire_rfkill_exit);
  84. MODULE_DESCRIPTION("sapphire rfkill");
  85. MODULE_AUTHOR("Nick Pelly <npelly@google.com>");
  86. MODULE_LICENSE("GPL");