h1940-bluetooth.c 3.0 KB

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