tosa-bt.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <mach/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_toggle_radio(void *data, enum rfkill_state state)
  34. {
  35. pr_info("BT_RADIO going: %s\n",
  36. state == RFKILL_STATE_ON ? "on" : "off");
  37. if (state == RFKILL_STATE_ON) {
  38. pr_info("TOSA_BT: going ON\n");
  39. tosa_bt_on(data);
  40. } else {
  41. pr_info("TOSA_BT: going OFF\n");
  42. tosa_bt_off(data);
  43. }
  44. return 0;
  45. }
  46. static int tosa_bt_probe(struct platform_device *dev)
  47. {
  48. int rc;
  49. struct rfkill *rfk;
  50. struct tosa_bt_data *data = dev->dev.platform_data;
  51. rc = gpio_request(data->gpio_reset, "Bluetooth reset");
  52. if (rc)
  53. goto err_reset;
  54. rc = gpio_direction_output(data->gpio_reset, 0);
  55. if (rc)
  56. goto err_reset_dir;
  57. rc = gpio_request(data->gpio_pwr, "Bluetooth power");
  58. if (rc)
  59. goto err_pwr;
  60. rc = gpio_direction_output(data->gpio_pwr, 0);
  61. if (rc)
  62. goto err_pwr_dir;
  63. rfk = rfkill_allocate(&dev->dev, RFKILL_TYPE_BLUETOOTH);
  64. if (!rfk) {
  65. rc = -ENOMEM;
  66. goto err_rfk_alloc;
  67. }
  68. rfk->name = "tosa-bt";
  69. rfk->toggle_radio = tosa_bt_toggle_radio;
  70. rfk->data = data;
  71. #ifdef CONFIG_RFKILL_LEDS
  72. rfk->led_trigger.name = "tosa-bt";
  73. #endif
  74. rc = rfkill_register(rfk);
  75. if (rc)
  76. goto err_rfkill;
  77. platform_set_drvdata(dev, rfk);
  78. return 0;
  79. err_rfkill:
  80. if (rfk)
  81. rfkill_free(rfk);
  82. rfk = NULL;
  83. err_rfk_alloc:
  84. tosa_bt_off(data);
  85. err_pwr_dir:
  86. gpio_free(data->gpio_pwr);
  87. err_pwr:
  88. err_reset_dir:
  89. gpio_free(data->gpio_reset);
  90. err_reset:
  91. return rc;
  92. }
  93. static int __devexit tosa_bt_remove(struct platform_device *dev)
  94. {
  95. struct tosa_bt_data *data = dev->dev.platform_data;
  96. struct rfkill *rfk = platform_get_drvdata(dev);
  97. platform_set_drvdata(dev, NULL);
  98. if (rfk)
  99. rfkill_unregister(rfk);
  100. rfk = NULL;
  101. tosa_bt_off(data);
  102. gpio_free(data->gpio_pwr);
  103. gpio_free(data->gpio_reset);
  104. return 0;
  105. }
  106. static struct platform_driver tosa_bt_driver = {
  107. .probe = tosa_bt_probe,
  108. .remove = __devexit_p(tosa_bt_remove),
  109. .driver = {
  110. .name = "tosa-bt",
  111. .owner = THIS_MODULE,
  112. },
  113. };
  114. static int __init tosa_bt_init(void)
  115. {
  116. return platform_driver_register(&tosa_bt_driver);
  117. }
  118. static void __exit tosa_bt_exit(void)
  119. {
  120. platform_driver_unregister(&tosa_bt_driver);
  121. }
  122. module_init(tosa_bt_init);
  123. module_exit(tosa_bt_exit);