actisys-sir.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*********************************************************************
  2. *
  3. * Filename: actisys.c
  4. * Version: 1.1
  5. * Description: Implementation for the ACTiSYS IR-220L and IR-220L+
  6. * dongles
  7. * Status: Beta.
  8. * Authors: Dag Brattli <dagb@cs.uit.no> (initially)
  9. * Jean Tourrilhes <jt@hpl.hp.com> (new version)
  10. * Martin Diehl <mad@mdiehl.de> (new version for sir_dev)
  11. * Created at: Wed Oct 21 20:02:35 1998
  12. * Modified at: Sun Oct 27 22:02:13 2002
  13. * Modified by: Martin Diehl <mad@mdiehl.de>
  14. *
  15. * Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
  16. * Copyright (c) 1999 Jean Tourrilhes
  17. * Copyright (c) 2002 Martin Diehl
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * Neither Dag Brattli nor University of Tromsø admit liability nor
  25. * provide warranty for any of this software. This material is
  26. * provided "AS-IS" and at no charge.
  27. *
  28. ********************************************************************/
  29. /*
  30. * Changelog
  31. *
  32. * 0.8 -> 0.9999 - Jean
  33. * o New initialisation procedure : much safer and correct
  34. * o New procedure the change speed : much faster and simpler
  35. * o Other cleanups & comments
  36. * Thanks to Lichen Wang @ Actisys for his excellent help...
  37. *
  38. * 1.0 -> 1.1 - Martin Diehl
  39. * modified for new sir infrastructure
  40. */
  41. #include <linux/module.h>
  42. #include <linux/delay.h>
  43. #include <linux/init.h>
  44. #include <net/irda/irda.h>
  45. #include "sir-dev.h"
  46. /*
  47. * Define the timing of the pulses we send to the dongle (to reset it, and
  48. * to toggle speeds). Basically, the limit here is the propagation speed of
  49. * the signals through the serial port, the dongle being much faster. Any
  50. * serial port support 115 kb/s, so we are sure that pulses 8.5 us wide can
  51. * go through cleanly . If you are on the wild side, you can try to lower
  52. * this value (Actisys recommended me 2 us, and 0 us work for me on a P233!)
  53. */
  54. #define MIN_DELAY 10 /* 10 us to be on the conservative side */
  55. static int actisys_open(struct sir_dev *);
  56. static int actisys_close(struct sir_dev *);
  57. static int actisys_change_speed(struct sir_dev *, unsigned);
  58. static int actisys_reset(struct sir_dev *);
  59. /* These are the baudrates supported, in the order available */
  60. /* Note : the 220L doesn't support 38400, but we will fix that below */
  61. static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
  62. #define MAX_SPEEDS ARRAY_SIZE(baud_rates)
  63. static struct dongle_driver act220l = {
  64. .owner = THIS_MODULE,
  65. .driver_name = "Actisys ACT-220L",
  66. .type = IRDA_ACTISYS_DONGLE,
  67. .open = actisys_open,
  68. .close = actisys_close,
  69. .reset = actisys_reset,
  70. .set_speed = actisys_change_speed,
  71. };
  72. static struct dongle_driver act220l_plus = {
  73. .owner = THIS_MODULE,
  74. .driver_name = "Actisys ACT-220L+",
  75. .type = IRDA_ACTISYS_PLUS_DONGLE,
  76. .open = actisys_open,
  77. .close = actisys_close,
  78. .reset = actisys_reset,
  79. .set_speed = actisys_change_speed,
  80. };
  81. static int __init actisys_sir_init(void)
  82. {
  83. int ret;
  84. /* First, register an Actisys 220L dongle */
  85. ret = irda_register_dongle(&act220l);
  86. if (ret < 0)
  87. return ret;
  88. /* Now, register an Actisys 220L+ dongle */
  89. ret = irda_register_dongle(&act220l_plus);
  90. if (ret < 0) {
  91. irda_unregister_dongle(&act220l);
  92. return ret;
  93. }
  94. return 0;
  95. }
  96. static void __exit actisys_sir_cleanup(void)
  97. {
  98. /* We have to remove both dongles */
  99. irda_unregister_dongle(&act220l_plus);
  100. irda_unregister_dongle(&act220l);
  101. }
  102. static int actisys_open(struct sir_dev *dev)
  103. {
  104. struct qos_info *qos = &dev->qos;
  105. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  106. /* Set the speeds we can accept */
  107. qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
  108. /* Remove support for 38400 if this is not a 220L+ dongle */
  109. if (dev->dongle_drv->type == IRDA_ACTISYS_DONGLE)
  110. qos->baud_rate.bits &= ~IR_38400;
  111. qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
  112. irda_qos_bits_to_value(qos);
  113. /* irda thread waits 50 msec for power settling */
  114. return 0;
  115. }
  116. static int actisys_close(struct sir_dev *dev)
  117. {
  118. /* Power off the dongle */
  119. sirdev_set_dtr_rts(dev, FALSE, FALSE);
  120. return 0;
  121. }
  122. /*
  123. * Function actisys_change_speed (task)
  124. *
  125. * Change speed of the ACTiSYS IR-220L and IR-220L+ type IrDA dongles.
  126. * To cycle through the available baud rates, pulse RTS low for a few us.
  127. *
  128. * First, we reset the dongle to always start from a known state.
  129. * Then, we cycle through the speeds by pulsing RTS low and then up.
  130. * The dongle allow us to pulse quite fast, se we can set speed in one go,
  131. * which is must faster ( < 100 us) and less complex than what is found
  132. * in some other dongle drivers...
  133. * Note that even if the new speed is the same as the current speed,
  134. * we reassert the speed. This make sure that things are all right,
  135. * and it's fast anyway...
  136. * By the way, this function will work for both type of dongles,
  137. * because the additional speed is at the end of the sequence...
  138. */
  139. static int actisys_change_speed(struct sir_dev *dev, unsigned speed)
  140. {
  141. int ret = 0;
  142. int i = 0;
  143. pr_debug("%s(), speed=%d (was %d)\n", __func__, speed, dev->speed);
  144. /* dongle was already resetted from irda_request state machine,
  145. * we are in known state (dongle default)
  146. */
  147. /*
  148. * Now, we can set the speed requested. Send RTS pulses until we
  149. * reach the target speed
  150. */
  151. for (i = 0; i < MAX_SPEEDS; i++) {
  152. if (speed == baud_rates[i]) {
  153. dev->speed = speed;
  154. break;
  155. }
  156. /* Set RTS low for 10 us */
  157. sirdev_set_dtr_rts(dev, TRUE, FALSE);
  158. udelay(MIN_DELAY);
  159. /* Set RTS high for 10 us */
  160. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  161. udelay(MIN_DELAY);
  162. }
  163. /* Check if life is sweet... */
  164. if (i >= MAX_SPEEDS) {
  165. actisys_reset(dev);
  166. ret = -EINVAL; /* This should not happen */
  167. }
  168. /* Basta lavoro, on se casse d'ici... */
  169. return ret;
  170. }
  171. /*
  172. * Function actisys_reset (task)
  173. *
  174. * Reset the Actisys type dongle. Warning, this function must only be
  175. * called with a process context!
  176. *
  177. * We need to do two things in this function :
  178. * o first make sure that the dongle is in a state where it can operate
  179. * o second put the dongle in a know state
  180. *
  181. * The dongle is powered of the RTS and DTR lines. In the dongle, there
  182. * is a big capacitor to accommodate the current spikes. This capacitor
  183. * takes a least 50 ms to be charged. In theory, the Bios set those lines
  184. * up, so by the time we arrive here we should be set. It doesn't hurt
  185. * to be on the conservative side, so we will wait...
  186. * <Martin : move above comment to irda_config_fsm>
  187. * Then, we set the speed to 9600 b/s to get in a known state (see in
  188. * change_speed for details). It is needed because the IrDA stack
  189. * has tried to set the speed immediately after our first return,
  190. * so before we can be sure the dongle is up and running.
  191. */
  192. static int actisys_reset(struct sir_dev *dev)
  193. {
  194. /* Reset the dongle : set DTR low for 10 us */
  195. sirdev_set_dtr_rts(dev, FALSE, TRUE);
  196. udelay(MIN_DELAY);
  197. /* Go back to normal mode */
  198. sirdev_set_dtr_rts(dev, TRUE, TRUE);
  199. dev->speed = 9600; /* That's the default */
  200. return 0;
  201. }
  202. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no> - Jean Tourrilhes <jt@hpl.hp.com>");
  203. MODULE_DESCRIPTION("ACTiSYS IR-220L and IR-220L+ dongle driver");
  204. MODULE_LICENSE("GPL");
  205. MODULE_ALIAS("irda-dongle-2"); /* IRDA_ACTISYS_DONGLE */
  206. MODULE_ALIAS("irda-dongle-3"); /* IRDA_ACTISYS_PLUS_DONGLE */
  207. module_init(actisys_sir_init);
  208. module_exit(actisys_sir_cleanup);