h1940-bluetooth.c 3.0 KB

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