h1940-bluetooth.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #include <mach/h1940.h>
  24. #define DRV_NAME "h1940-bt"
  25. /* Bluetooth control */
  26. static void h1940bt_enable(int on)
  27. {
  28. if (on) {
  29. /* Power on the chip */
  30. gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
  31. /* Reset the chip */
  32. mdelay(10);
  33. gpio_set_value(S3C2410_GPH(1), 1);
  34. mdelay(10);
  35. gpio_set_value(S3C2410_GPH(1), 0);
  36. h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
  37. }
  38. else {
  39. gpio_set_value(S3C2410_GPH(1), 1);
  40. mdelay(10);
  41. gpio_set_value(S3C2410_GPH(1), 0);
  42. mdelay(10);
  43. gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
  44. h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
  45. }
  46. }
  47. static int h1940bt_set_block(void *data, bool blocked)
  48. {
  49. h1940bt_enable(!blocked);
  50. return 0;
  51. }
  52. static const struct rfkill_ops h1940bt_rfkill_ops = {
  53. .set_block = h1940bt_set_block,
  54. };
  55. static int __devinit h1940bt_probe(struct platform_device *pdev)
  56. {
  57. struct rfkill *rfk;
  58. int ret = 0;
  59. ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
  60. if (ret) {
  61. dev_err(&pdev->dev, "could not get GPH1\n");
  62. return ret;
  63. }
  64. ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
  65. if (ret) {
  66. gpio_free(S3C2410_GPH(1));
  67. dev_err(&pdev->dev, "could not get BT_POWER\n");
  68. return ret;
  69. }
  70. /* Configures BT serial port GPIOs */
  71. s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
  72. s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
  73. s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
  74. s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
  75. s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
  76. s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
  77. s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
  78. s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
  79. rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
  80. &h1940bt_rfkill_ops, NULL);
  81. if (!rfk) {
  82. ret = -ENOMEM;
  83. goto err_rfk_alloc;
  84. }
  85. ret = rfkill_register(rfk);
  86. if (ret)
  87. goto err_rfkill;
  88. platform_set_drvdata(pdev, rfk);
  89. return 0;
  90. err_rfkill:
  91. rfkill_destroy(rfk);
  92. err_rfk_alloc:
  93. return ret;
  94. }
  95. static int h1940bt_remove(struct platform_device *pdev)
  96. {
  97. struct rfkill *rfk = platform_get_drvdata(pdev);
  98. platform_set_drvdata(pdev, NULL);
  99. gpio_free(S3C2410_GPH(1));
  100. if (rfk) {
  101. rfkill_unregister(rfk);
  102. rfkill_destroy(rfk);
  103. }
  104. rfk = NULL;
  105. h1940bt_enable(0);
  106. return 0;
  107. }
  108. static struct platform_driver h1940bt_driver = {
  109. .driver = {
  110. .name = DRV_NAME,
  111. },
  112. .probe = h1940bt_probe,
  113. .remove = h1940bt_remove,
  114. };
  115. static int __init h1940bt_init(void)
  116. {
  117. return platform_driver_register(&h1940bt_driver);
  118. }
  119. static void __exit h1940bt_exit(void)
  120. {
  121. platform_driver_unregister(&h1940bt_driver);
  122. }
  123. module_init(h1940bt_init);
  124. module_exit(h1940bt_exit);
  125. MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
  126. MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
  127. MODULE_LICENSE("GPL");