tosa-bt.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Bluetooth built-in chip control
  3. *
  4. * Copyright (c) 2008 Dmitry Baryshkov
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/gpio.h>
  15. #include <linux/delay.h>
  16. #include <linux/rfkill.h>
  17. #include "tosa_bt.h"
  18. static void tosa_bt_on(struct tosa_bt_data *data)
  19. {
  20. gpio_set_value(data->gpio_reset, 0);
  21. gpio_set_value(data->gpio_pwr, 1);
  22. gpio_set_value(data->gpio_reset, 1);
  23. mdelay(20);
  24. gpio_set_value(data->gpio_reset, 0);
  25. }
  26. static void tosa_bt_off(struct tosa_bt_data *data)
  27. {
  28. gpio_set_value(data->gpio_reset, 1);
  29. mdelay(10);
  30. gpio_set_value(data->gpio_pwr, 0);
  31. gpio_set_value(data->gpio_reset, 0);
  32. }
  33. static int tosa_bt_set_block(void *data, bool blocked)
  34. {
  35. pr_info("BT_RADIO going: %s\n", blocked ? "off" : "on");
  36. if (!blocked) {
  37. pr_info("TOSA_BT: going ON\n");
  38. tosa_bt_on(data);
  39. } else {
  40. pr_info("TOSA_BT: going OFF\n");
  41. tosa_bt_off(data);
  42. }
  43. return 0;
  44. }
  45. static const struct rfkill_ops tosa_bt_rfkill_ops = {
  46. .set_block = tosa_bt_set_block,
  47. };
  48. static int tosa_bt_probe(struct platform_device *dev)
  49. {
  50. int rc;
  51. struct rfkill *rfk;
  52. struct tosa_bt_data *data = dev->dev.platform_data;
  53. rc = gpio_request(data->gpio_reset, "Bluetooth reset");
  54. if (rc)
  55. goto err_reset;
  56. rc = gpio_direction_output(data->gpio_reset, 0);
  57. if (rc)
  58. goto err_reset_dir;
  59. rc = gpio_request(data->gpio_pwr, "Bluetooth power");
  60. if (rc)
  61. goto err_pwr;
  62. rc = gpio_direction_output(data->gpio_pwr, 0);
  63. if (rc)
  64. goto err_pwr_dir;
  65. rfk = rfkill_alloc("tosa-bt", &dev->dev, RFKILL_TYPE_BLUETOOTH,
  66. &tosa_bt_rfkill_ops, data);
  67. if (!rfk) {
  68. rc = -ENOMEM;
  69. goto err_rfk_alloc;
  70. }
  71. rc = rfkill_register(rfk);
  72. if (rc)
  73. goto err_rfkill;
  74. platform_set_drvdata(dev, rfk);
  75. return 0;
  76. err_rfkill:
  77. rfkill_destroy(rfk);
  78. err_rfk_alloc:
  79. tosa_bt_off(data);
  80. err_pwr_dir:
  81. gpio_free(data->gpio_pwr);
  82. err_pwr:
  83. err_reset_dir:
  84. gpio_free(data->gpio_reset);
  85. err_reset:
  86. return rc;
  87. }
  88. static int tosa_bt_remove(struct platform_device *dev)
  89. {
  90. struct tosa_bt_data *data = dev->dev.platform_data;
  91. struct rfkill *rfk = platform_get_drvdata(dev);
  92. platform_set_drvdata(dev, NULL);
  93. if (rfk) {
  94. rfkill_unregister(rfk);
  95. rfkill_destroy(rfk);
  96. }
  97. rfk = NULL;
  98. tosa_bt_off(data);
  99. gpio_free(data->gpio_pwr);
  100. gpio_free(data->gpio_reset);
  101. return 0;
  102. }
  103. static struct platform_driver tosa_bt_driver = {
  104. .probe = tosa_bt_probe,
  105. .remove = tosa_bt_remove,
  106. .driver = {
  107. .name = "tosa-bt",
  108. },
  109. };
  110. module_platform_driver(tosa_bt_driver);
  111. MODULE_LICENSE("GPL");
  112. MODULE_AUTHOR("Dmitry Baryshkov");
  113. MODULE_DESCRIPTION("Bluetooth built-in chip control");