litelink-sir.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. /* Power up dongle */
  68. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  69. /* Set the speeds we can accept */
  70. qos->baud_rate.bits &= IR_115200|IR_57600|IR_38400|IR_19200|IR_9600;
  71. qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
  72. irda_qos_bits_to_value(qos);
  73. /* irda thread waits 50 msec for power settling */
  74. return 0;
  75. }
  76. static int litelink_close(struct sir_dev *dev)
  77. {
  78. /* Power off dongle */
  79. sirdev_set_dtr_rts(dev, FALSE, FALSE);
  80. return 0;
  81. }
  82. /*
  83. * Function litelink_change_speed (task)
  84. *
  85. * Change speed of the Litelink dongle. To cycle through the available
  86. * baud rates, pulse RTS low for a few ms.
  87. */
  88. static int litelink_change_speed(struct sir_dev *dev, unsigned speed)
  89. {
  90. int i;
  91. /* dongle already reset by irda-thread - current speed (dongle and
  92. * port) is the default speed (115200 for litelink!)
  93. */
  94. /* Cycle through avaiable baudrates until we reach the correct one */
  95. for (i = 0; baud_rates[i] != speed; i++) {
  96. /* end-of-list reached due to invalid speed request */
  97. if (baud_rates[i] == 9600)
  98. break;
  99. /* Set DTR, clear RTS */
  100. sirdev_set_dtr_rts(dev, FALSE, TRUE);
  101. /* Sleep a minimum of 15 us */
  102. udelay(MIN_DELAY);
  103. /* Set DTR, Set RTS */
  104. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  105. /* Sleep a minimum of 15 us */
  106. udelay(MIN_DELAY);
  107. }
  108. dev->speed = baud_rates[i];
  109. /* invalid baudrate should not happen - but if, we return -EINVAL and
  110. * the dongle configured for 9600 so the stack has a chance to recover
  111. */
  112. return (dev->speed == speed) ? 0 : -EINVAL;
  113. }
  114. /*
  115. * Function litelink_reset (task)
  116. *
  117. * Reset the Litelink type dongle.
  118. *
  119. */
  120. static int litelink_reset(struct sir_dev *dev)
  121. {
  122. /* probably the power-up can be dropped here, but with only
  123. * 15 usec delay it's not worth the risk unless somebody with
  124. * the hardware confirms it doesn't break anything...
  125. */
  126. /* Power on dongle */
  127. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  128. /* Sleep a minimum of 15 us */
  129. udelay(MIN_DELAY);
  130. /* Clear RTS to reset dongle */
  131. sirdev_set_dtr_rts(dev, TRUE, FALSE);
  132. /* Sleep a minimum of 15 us */
  133. udelay(MIN_DELAY);
  134. /* Go back to normal mode */
  135. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  136. /* Sleep a minimum of 15 us */
  137. udelay(MIN_DELAY);
  138. /* This dongles speed defaults to 115200 bps */
  139. dev->speed = 115200;
  140. return 0;
  141. }
  142. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
  143. MODULE_DESCRIPTION("Parallax Litelink dongle driver");
  144. MODULE_LICENSE("GPL");
  145. MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */
  146. /*
  147. * Function init_module (void)
  148. *
  149. * Initialize Litelink module
  150. *
  151. */
  152. module_init(litelink_sir_init);
  153. /*
  154. * Function cleanup_module (void)
  155. *
  156. * Cleanup Litelink module
  157. *
  158. */
  159. module_exit(litelink_sir_cleanup);