h1940-bluetooth.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <mach/regs-gpio.h>
  19. #include <mach/hardware.h>
  20. #include <mach/h1940-latch.h>
  21. #define DRV_NAME "h1940-bt"
  22. #ifdef CONFIG_LEDS_H1940
  23. DEFINE_LED_TRIGGER(bt_led_trigger);
  24. #endif
  25. static int state;
  26. /* Bluetooth control */
  27. static void h1940bt_enable(int on)
  28. {
  29. if (on) {
  30. #ifdef CONFIG_LEDS_H1940
  31. /* flashing Blue */
  32. led_trigger_event(bt_led_trigger, LED_HALF);
  33. #endif
  34. /* Power on the chip */
  35. h1940_latch_control(0, H1940_LATCH_BLUETOOTH_POWER);
  36. /* Reset the chip */
  37. mdelay(10);
  38. s3c2410_gpio_setpin(S3C2410_GPH1, 1);
  39. mdelay(10);
  40. s3c2410_gpio_setpin(S3C2410_GPH1, 0);
  41. state = 1;
  42. }
  43. else {
  44. #ifdef CONFIG_LEDS_H1940
  45. led_trigger_event(bt_led_trigger, 0);
  46. #endif
  47. s3c2410_gpio_setpin(S3C2410_GPH1, 1);
  48. mdelay(10);
  49. s3c2410_gpio_setpin(S3C2410_GPH1, 0);
  50. mdelay(10);
  51. h1940_latch_control(H1940_LATCH_BLUETOOTH_POWER, 0);
  52. state = 0;
  53. }
  54. }
  55. static ssize_t h1940bt_show(struct device *dev, struct device_attribute *attr, char *buf)
  56. {
  57. return snprintf(buf, PAGE_SIZE, "%d\n", state);
  58. }
  59. static ssize_t h1940bt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  60. {
  61. int new_state;
  62. char *endp;
  63. new_state = simple_strtoul(buf, &endp, 0);
  64. if (*endp && !isspace(*endp))
  65. return -EINVAL;
  66. h1940bt_enable(new_state);
  67. return count;
  68. }
  69. static DEVICE_ATTR(enable, 0644,
  70. h1940bt_show,
  71. h1940bt_store);
  72. static int __init h1940bt_probe(struct platform_device *pdev)
  73. {
  74. /* Configures BT serial port GPIOs */
  75. s3c2410_gpio_cfgpin(S3C2410_GPH0, S3C2410_GPH0_nCTS0);
  76. s3c2410_gpio_pullup(S3C2410_GPH0, 1);
  77. s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_OUTP);
  78. s3c2410_gpio_pullup(S3C2410_GPH1, 1);
  79. s3c2410_gpio_cfgpin(S3C2410_GPH2, S3C2410_GPH2_TXD0);
  80. s3c2410_gpio_pullup(S3C2410_GPH2, 1);
  81. s3c2410_gpio_cfgpin(S3C2410_GPH3, S3C2410_GPH3_RXD0);
  82. s3c2410_gpio_pullup(S3C2410_GPH3, 1);
  83. #ifdef CONFIG_LEDS_H1940
  84. led_trigger_register_simple("h1940-bluetooth", &bt_led_trigger);
  85. #endif
  86. /* disable BT by default */
  87. h1940bt_enable(0);
  88. return device_create_file(&pdev->dev, &dev_attr_enable);
  89. }
  90. static int h1940bt_remove(struct platform_device *pdev)
  91. {
  92. #ifdef CONFIG_LEDS_H1940
  93. led_trigger_unregister_simple(bt_led_trigger);
  94. #endif
  95. return 0;
  96. }
  97. static struct platform_driver h1940bt_driver = {
  98. .driver = {
  99. .name = DRV_NAME,
  100. },
  101. .probe = h1940bt_probe,
  102. .remove = h1940bt_remove,
  103. };
  104. static int __init h1940bt_init(void)
  105. {
  106. return platform_driver_register(&h1940bt_driver);
  107. }
  108. static void __exit h1940bt_exit(void)
  109. {
  110. platform_driver_unregister(&h1940bt_driver);
  111. }
  112. module_init(h1940bt_init);
  113. module_exit(h1940bt_exit);
  114. MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
  115. MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
  116. MODULE_LICENSE("GPL");