h1940-bluetooth.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * arch/arm/mach-s3c2410/h1940-bluetooth.c
  3. * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file COPYING in the main directory of this archive for
  7. * more details.
  8. *
  9. * S3C2410 bluetooth "driver"
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/delay.h>
  15. #include <linux/string.h>
  16. #include <linux/ctype.h>
  17. #include <linux/leds.h>
  18. #include <linux/gpio.h>
  19. #include <linux/rfkill.h>
  20. #include <mach/regs-gpio.h>
  21. #include <mach/hardware.h>
  22. #include <mach/h1940-latch.h>
  23. #define DRV_NAME "h1940-bt"
  24. /* Bluetooth control */
  25. static void h1940bt_enable(int on)
  26. {
  27. if (on) {
  28. /* Power on the chip */
  29. h1940_latch_control(0, H1940_LATCH_BLUETOOTH_POWER);
  30. /* Reset the chip */
  31. mdelay(10);
  32. gpio_set_value(S3C2410_GPH(1), 1);
  33. mdelay(10);
  34. gpio_set_value(S3C2410_GPH(1), 0);
  35. }
  36. else {
  37. gpio_set_value(S3C2410_GPH(1), 1);
  38. mdelay(10);
  39. gpio_set_value(S3C2410_GPH(1), 0);
  40. mdelay(10);
  41. h1940_latch_control(H1940_LATCH_BLUETOOTH_POWER, 0);
  42. }
  43. }
  44. static int h1940bt_set_block(void *data, bool blocked)
  45. {
  46. h1940bt_enable(!blocked);
  47. return 0;
  48. }
  49. static const struct rfkill_ops h1940bt_rfkill_ops = {
  50. .set_block = h1940bt_set_block,
  51. };
  52. static int __devinit h1940bt_probe(struct platform_device *pdev)
  53. {
  54. struct rfkill *rfk;
  55. int ret = 0;
  56. ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
  57. if (ret) {
  58. dev_err(&pdev->dev, "could not get GPH1\n");\
  59. return ret;
  60. }
  61. /* Configures BT serial port GPIOs */
  62. s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
  63. s3c_gpio_cfgpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
  64. s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
  65. s3c_gpio_cfgpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
  66. s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
  67. s3c_gpio_cfgpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
  68. s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
  69. s3c_gpio_cfgpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
  70. rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
  71. &h1940bt_rfkill_ops, NULL);
  72. if (!rfk) {
  73. ret = -ENOMEM;
  74. goto err_rfk_alloc;
  75. }
  76. rfkill_set_led_trigger_name(rfk, "h1940-bluetooth");
  77. ret = rfkill_register(rfk);
  78. if (ret)
  79. goto err_rfkill;
  80. platform_set_drvdata(pdev, rfk);
  81. return 0;
  82. err_rfkill:
  83. rfkill_destroy(rfk);
  84. err_rfk_alloc:
  85. return ret;
  86. }
  87. static int h1940bt_remove(struct platform_device *pdev)
  88. {
  89. struct rfkill *rfk = platform_get_drvdata(pdev);
  90. platform_set_drvdata(pdev, NULL);
  91. gpio_free(S3C2410_GPH(1));
  92. if (rfk) {
  93. rfkill_unregister(rfk);
  94. rfkill_destroy(rfk);
  95. }
  96. rfk = NULL;
  97. h1940bt_enable(0);
  98. return 0;
  99. }
  100. static struct platform_driver h1940bt_driver = {
  101. .driver = {
  102. .name = DRV_NAME,
  103. },
  104. .probe = h1940bt_probe,
  105. .remove = h1940bt_remove,
  106. };
  107. static int __init h1940bt_init(void)
  108. {
  109. return platform_driver_register(&h1940bt_driver);
  110. }
  111. static void __exit h1940bt_exit(void)
  112. {
  113. platform_driver_unregister(&h1940bt_driver);
  114. }
  115. module_init(h1940bt_init);
  116. module_exit(h1940bt_exit);
  117. MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
  118. MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
  119. MODULE_LICENSE("GPL");