h1940-bluetooth.c 3.2 KB

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