litelink.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. #include <linux/module.h>
  31. #include <linux/delay.h>
  32. #include <linux/tty.h>
  33. #include <linux/init.h>
  34. #include <net/irda/irda.h>
  35. #include <net/irda/irda_device.h>
  36. #define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
  37. #define MAX_DELAY 10000 /* 1 ms */
  38. static void litelink_open(dongle_t *self, struct qos_info *qos);
  39. static void litelink_close(dongle_t *self);
  40. static int litelink_change_speed(struct irda_task *task);
  41. static int litelink_reset(struct irda_task *task);
  42. /* These are the baudrates supported */
  43. static __u32 baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
  44. static struct dongle_reg dongle = {
  45. .type = IRDA_LITELINK_DONGLE,
  46. .open = litelink_open,
  47. .close = litelink_close,
  48. .reset = litelink_reset,
  49. .change_speed = litelink_change_speed,
  50. .owner = THIS_MODULE,
  51. };
  52. static int __init litelink_init(void)
  53. {
  54. return irda_device_register_dongle(&dongle);
  55. }
  56. static void __exit litelink_cleanup(void)
  57. {
  58. irda_device_unregister_dongle(&dongle);
  59. }
  60. static void litelink_open(dongle_t *self, struct qos_info *qos)
  61. {
  62. qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
  63. qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
  64. }
  65. static void litelink_close(dongle_t *self)
  66. {
  67. /* Power off dongle */
  68. self->set_dtr_rts(self->dev, FALSE, FALSE);
  69. }
  70. /*
  71. * Function litelink_change_speed (task)
  72. *
  73. * Change speed of the Litelink dongle. To cycle through the available
  74. * baud rates, pulse RTS low for a few ms.
  75. */
  76. static int litelink_change_speed(struct irda_task *task)
  77. {
  78. dongle_t *self = (dongle_t *) task->instance;
  79. __u32 speed = (__u32) task->param;
  80. int i;
  81. /* Clear RTS to reset dongle */
  82. self->set_dtr_rts(self->dev, TRUE, FALSE);
  83. /* Sleep a minimum of 15 us */
  84. udelay(MIN_DELAY);
  85. /* Go back to normal mode */
  86. self->set_dtr_rts(self->dev, TRUE, TRUE);
  87. /* Sleep a minimum of 15 us */
  88. udelay(MIN_DELAY);
  89. /* Cycle through avaiable baudrates until we reach the correct one */
  90. for (i=0; i<5 && baud_rates[i] != speed; i++) {
  91. /* Set DTR, clear RTS */
  92. self->set_dtr_rts(self->dev, FALSE, TRUE);
  93. /* Sleep a minimum of 15 us */
  94. udelay(MIN_DELAY);
  95. /* Set DTR, Set RTS */
  96. self->set_dtr_rts(self->dev, TRUE, TRUE);
  97. /* Sleep a minimum of 15 us */
  98. udelay(MIN_DELAY);
  99. }
  100. irda_task_next_state(task, IRDA_TASK_DONE);
  101. return 0;
  102. }
  103. /*
  104. * Function litelink_reset (task)
  105. *
  106. * Reset the Litelink type dongle.
  107. *
  108. */
  109. static int litelink_reset(struct irda_task *task)
  110. {
  111. dongle_t *self = (dongle_t *) task->instance;
  112. /* Power on dongle */
  113. self->set_dtr_rts(self->dev, TRUE, TRUE);
  114. /* Sleep a minimum of 15 us */
  115. udelay(MIN_DELAY);
  116. /* Clear RTS to reset dongle */
  117. self->set_dtr_rts(self->dev, TRUE, FALSE);
  118. /* Sleep a minimum of 15 us */
  119. udelay(MIN_DELAY);
  120. /* Go back to normal mode */
  121. self->set_dtr_rts(self->dev, TRUE, TRUE);
  122. /* Sleep a minimum of 15 us */
  123. udelay(MIN_DELAY);
  124. /* This dongles speed defaults to 115200 bps */
  125. self->speed = 115200;
  126. irda_task_next_state(task, IRDA_TASK_DONE);
  127. return 0;
  128. }
  129. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
  130. MODULE_DESCRIPTION("Parallax Litelink dongle driver");
  131. MODULE_LICENSE("GPL");
  132. MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */
  133. /*
  134. * Function init_module (void)
  135. *
  136. * Initialize Litelink module
  137. *
  138. */
  139. module_init(litelink_init);
  140. /*
  141. * Function cleanup_module (void)
  142. *
  143. * Cleanup Litelink module
  144. *
  145. */
  146. module_exit(litelink_cleanup);