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