h1940-bluetooth.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
  33. mdelay(10);
  34. s3c2410_gpio_setpin(S3C2410_GPH(1), 0);
  35. }
  36. else {
  37. s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
  38. mdelay(10);
  39. s3c2410_gpio_setpin(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 __init h1940bt_probe(struct platform_device *pdev)
  53. {
  54. struct rfkill *rfk;
  55. int ret = 0;
  56. /* Configures BT serial port GPIOs */
  57. s3c2410_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
  58. s3c2410_gpio_pullup(S3C2410_GPH(0), 1);
  59. s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
  60. s3c2410_gpio_pullup(S3C2410_GPH(1), 1);
  61. s3c2410_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
  62. s3c2410_gpio_pullup(S3C2410_GPH(2), 1);
  63. s3c2410_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
  64. s3c2410_gpio_pullup(S3C2410_GPH(3), 1);
  65. rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
  66. &h1940bt_rfkill_ops, NULL);
  67. if (!rfk) {
  68. ret = -ENOMEM;
  69. goto err_rfk_alloc;
  70. }
  71. rfkill_set_led_trigger_name(rfk, "h1940-bluetooth");
  72. ret = rfkill_register(rfk);
  73. if (ret)
  74. goto err_rfkill;
  75. platform_set_drvdata(pdev, rfk);
  76. return 0;
  77. err_rfkill:
  78. rfkill_destroy(rfk);
  79. err_rfk_alloc:
  80. return ret;
  81. }
  82. static int h1940bt_remove(struct platform_device *pdev)
  83. {
  84. struct rfkill *rfk = platform_get_drvdata(pdev);
  85. platform_set_drvdata(pdev, NULL);
  86. if (rfk) {
  87. rfkill_unregister(rfk);
  88. rfkill_destroy(rfk);
  89. }
  90. rfk = NULL;
  91. h1940bt_enable(0);
  92. return 0;
  93. }
  94. static struct platform_driver h1940bt_driver = {
  95. .driver = {
  96. .name = DRV_NAME,
  97. },
  98. .probe = h1940bt_probe,
  99. .remove = h1940bt_remove,
  100. };
  101. static int __init h1940bt_init(void)
  102. {
  103. return platform_driver_register(&h1940bt_driver);
  104. }
  105. static void __exit h1940bt_exit(void)
  106. {
  107. platform_driver_unregister(&h1940bt_driver);
  108. }
  109. module_init(h1940bt_init);
  110. module_exit(h1940bt_exit);
  111. MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
  112. MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
  113. MODULE_LICENSE("GPL");