litelink-sir.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*********************************************************************
  2. *
  3. * Filename: litelink.c
  4. * Version: 1.1
  5. * Description: Driver for the Parallax LiteLink dongle
  6. * Status: Stable
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Fri May 7 12:50:33 1999
  9. * Modified at: Fri Dec 17 09:14:23 1999
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  26. *
  27. ********************************************************************/
  28. /*
  29. * Modified at: Thu Jan 15 2003
  30. * Modified by: Eugene Crosser <crosser@average.org>
  31. *
  32. * Convert to "new" IRDA infrastructure for kernel 2.6
  33. */
  34. #include <linux/module.h>
  35. #include <linux/delay.h>
  36. #include <linux/init.h>
  37. #include <net/irda/irda.h>
  38. #include "sir-dev.h"
  39. #define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
  40. #define MAX_DELAY 10000 /* 1 ms */
  41. static int litelink_open(struct sir_dev *dev);
  42. static int litelink_close(struct sir_dev *dev);
  43. static int litelink_change_speed(struct sir_dev *dev, unsigned speed);
  44. static int litelink_reset(struct sir_dev *dev);
  45. /* These are the baudrates supported - 9600 must be last one! */
  46. static unsigned baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
  47. static struct dongle_driver litelink = {
  48. .owner = THIS_MODULE,
  49. .driver_name = "Parallax LiteLink",
  50. .type = IRDA_LITELINK_DONGLE,
  51. .open = litelink_open,
  52. .close = litelink_close,
  53. .reset = litelink_reset,
  54. .set_speed = litelink_change_speed,
  55. };
  56. static int __init litelink_sir_init(void)
  57. {
  58. return irda_register_dongle(&litelink);
  59. }
  60. static void __exit litelink_sir_cleanup(void)
  61. {
  62. irda_unregister_dongle(&litelink);
  63. }
  64. static int litelink_open(struct sir_dev *dev)
  65. {
  66. struct qos_info *qos = &dev->qos;
  67. IRDA_DEBUG(2, "%s()\n", __func__);
  68. /* Power up dongle */
  69. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  70. /* Set the speeds we can accept */
  71. qos->baud_rate.bits &= IR_115200|IR_57600|IR_38400|IR_19200|IR_9600;
  72. qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
  73. irda_qos_bits_to_value(qos);
  74. /* irda thread waits 50 msec for power settling */
  75. return 0;
  76. }
  77. static int litelink_close(struct sir_dev *dev)
  78. {
  79. IRDA_DEBUG(2, "%s()\n", __func__);
  80. /* Power off dongle */
  81. sirdev_set_dtr_rts(dev, FALSE, FALSE);
  82. return 0;
  83. }
  84. /*
  85. * Function litelink_change_speed (task)
  86. *
  87. * Change speed of the Litelink dongle. To cycle through the available
  88. * baud rates, pulse RTS low for a few ms.
  89. */
  90. static int litelink_change_speed(struct sir_dev *dev, unsigned speed)
  91. {
  92. int i;
  93. IRDA_DEBUG(2, "%s()\n", __func__);
  94. /* dongle already reset by irda-thread - current speed (dongle and
  95. * port) is the default speed (115200 for litelink!)
  96. */
  97. /* Cycle through avaiable baudrates until we reach the correct one */
  98. for (i = 0; baud_rates[i] != speed; i++) {
  99. /* end-of-list reached due to invalid speed request */
  100. if (baud_rates[i] == 9600)
  101. break;
  102. /* Set DTR, clear RTS */
  103. sirdev_set_dtr_rts(dev, FALSE, TRUE);
  104. /* Sleep a minimum of 15 us */
  105. udelay(MIN_DELAY);
  106. /* Set DTR, Set RTS */
  107. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  108. /* Sleep a minimum of 15 us */
  109. udelay(MIN_DELAY);
  110. }
  111. dev->speed = baud_rates[i];
  112. /* invalid baudrate should not happen - but if, we return -EINVAL and
  113. * the dongle configured for 9600 so the stack has a chance to recover
  114. */
  115. return (dev->speed == speed) ? 0 : -EINVAL;
  116. }
  117. /*
  118. * Function litelink_reset (task)
  119. *
  120. * Reset the Litelink type dongle.
  121. *
  122. */
  123. static int litelink_reset(struct sir_dev *dev)
  124. {
  125. IRDA_DEBUG(2, "%s()\n", __func__);
  126. /* probably the power-up can be dropped here, but with only
  127. * 15 usec delay it's not worth the risk unless somebody with
  128. * the hardware confirms it doesn't break anything...
  129. */
  130. /* Power on dongle */
  131. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  132. /* Sleep a minimum of 15 us */
  133. udelay(MIN_DELAY);
  134. /* Clear RTS to reset dongle */
  135. sirdev_set_dtr_rts(dev, TRUE, FALSE);
  136. /* Sleep a minimum of 15 us */
  137. udelay(MIN_DELAY);
  138. /* Go back to normal mode */
  139. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  140. /* Sleep a minimum of 15 us */
  141. udelay(MIN_DELAY);
  142. /* This dongles speed defaults to 115200 bps */
  143. dev->speed = 115200;
  144. return 0;
  145. }
  146. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
  147. MODULE_DESCRIPTION("Parallax Litelink dongle driver");
  148. MODULE_LICENSE("GPL");
  149. MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */
  150. /*
  151. * Function init_module (void)
  152. *
  153. * Initialize Litelink module
  154. *
  155. */
  156. module_init(litelink_sir_init);
  157. /*
  158. * Function cleanup_module (void)
  159. *
  160. * Cleanup Litelink module
  161. *
  162. */
  163. module_exit(litelink_sir_cleanup);