h1940-bluetooth.c 3.2 KB

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