litelink-sir.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. *
  29. ********************************************************************/
  30. /*
  31. * Modified at: Thu Jan 15 2003
  32. * Modified by: Eugene Crosser <crosser@average.org>
  33. *
  34. * Convert to "new" IRDA infrastructure for kernel 2.6
  35. */
  36. #include <linux/module.h>
  37. #include <linux/delay.h>
  38. #include <linux/init.h>
  39. #include <net/irda/irda.h>
  40. #include "sir-dev.h"
  41. #define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
  42. #define MAX_DELAY 10000 /* 1 ms */
  43. static int litelink_open(struct sir_dev *dev);
  44. static int litelink_close(struct sir_dev *dev);
  45. static int litelink_change_speed(struct sir_dev *dev, unsigned speed);
  46. static int litelink_reset(struct sir_dev *dev);
  47. /* These are the baudrates supported - 9600 must be last one! */
  48. static unsigned baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
  49. static struct dongle_driver litelink = {
  50. .owner = THIS_MODULE,
  51. .driver_name = "Parallax LiteLink",
  52. .type = IRDA_LITELINK_DONGLE,
  53. .open = litelink_open,
  54. .close = litelink_close,
  55. .reset = litelink_reset,
  56. .set_speed = litelink_change_speed,
  57. };
  58. static int __init litelink_sir_init(void)
  59. {
  60. return irda_register_dongle(&litelink);
  61. }
  62. static void __exit litelink_sir_cleanup(void)
  63. {
  64. irda_unregister_dongle(&litelink);
  65. }
  66. static int litelink_open(struct sir_dev *dev)
  67. {
  68. struct qos_info *qos = &dev->qos;
  69. IRDA_DEBUG(2, "%s()\n", __func__);
  70. /* Power up dongle */
  71. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  72. /* Set the speeds we can accept */
  73. qos->baud_rate.bits &= IR_115200|IR_57600|IR_38400|IR_19200|IR_9600;
  74. qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
  75. irda_qos_bits_to_value(qos);
  76. /* irda thread waits 50 msec for power settling */
  77. return 0;
  78. }
  79. static int litelink_close(struct sir_dev *dev)
  80. {
  81. IRDA_DEBUG(2, "%s()\n", __func__);
  82. /* Power off dongle */
  83. sirdev_set_dtr_rts(dev, FALSE, FALSE);
  84. return 0;
  85. }
  86. /*
  87. * Function litelink_change_speed (task)
  88. *
  89. * Change speed of the Litelink dongle. To cycle through the available
  90. * baud rates, pulse RTS low for a few ms.
  91. */
  92. static int litelink_change_speed(struct sir_dev *dev, unsigned speed)
  93. {
  94. int i;
  95. IRDA_DEBUG(2, "%s()\n", __func__);
  96. /* dongle already reset by irda-thread - current speed (dongle and
  97. * port) is the default speed (115200 for litelink!)
  98. */
  99. /* Cycle through avaiable baudrates until we reach the correct one */
  100. for (i = 0; baud_rates[i] != speed; i++) {
  101. /* end-of-list reached due to invalid speed request */
  102. if (baud_rates[i] == 9600)
  103. break;
  104. /* Set DTR, clear RTS */
  105. sirdev_set_dtr_rts(dev, FALSE, TRUE);
  106. /* Sleep a minimum of 15 us */
  107. udelay(MIN_DELAY);
  108. /* Set DTR, Set RTS */
  109. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  110. /* Sleep a minimum of 15 us */
  111. udelay(MIN_DELAY);
  112. }
  113. dev->speed = baud_rates[i];
  114. /* invalid baudrate should not happen - but if, we return -EINVAL and
  115. * the dongle configured for 9600 so the stack has a chance to recover
  116. */
  117. return (dev->speed == speed) ? 0 : -EINVAL;
  118. }
  119. /*
  120. * Function litelink_reset (task)
  121. *
  122. * Reset the Litelink type dongle.
  123. *
  124. */
  125. static int litelink_reset(struct sir_dev *dev)
  126. {
  127. IRDA_DEBUG(2, "%s()\n", __func__);
  128. /* probably the power-up can be dropped here, but with only
  129. * 15 usec delay it's not worth the risk unless somebody with
  130. * the hardware confirms it doesn't break anything...
  131. */
  132. /* Power on dongle */
  133. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  134. /* Sleep a minimum of 15 us */
  135. udelay(MIN_DELAY);
  136. /* Clear RTS to reset dongle */
  137. sirdev_set_dtr_rts(dev, TRUE, FALSE);
  138. /* Sleep a minimum of 15 us */
  139. udelay(MIN_DELAY);
  140. /* Go back to normal mode */
  141. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  142. /* Sleep a minimum of 15 us */
  143. udelay(MIN_DELAY);
  144. /* This dongles speed defaults to 115200 bps */
  145. dev->speed = 115200;
  146. return 0;
  147. }
  148. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
  149. MODULE_DESCRIPTION("Parallax Litelink dongle driver");
  150. MODULE_LICENSE("GPL");
  151. MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */
  152. /*
  153. * Function init_module (void)
  154. *
  155. * Initialize Litelink module
  156. *
  157. */
  158. module_init(litelink_sir_init);
  159. /*
  160. * Function cleanup_module (void)
  161. *
  162. * Cleanup Litelink module
  163. *
  164. */
  165. module_exit(litelink_sir_cleanup);