esi-sir.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*********************************************************************
  2. *
  3. * Filename: esi.c
  4. * Version: 1.6
  5. * Description: Driver for the Extended Systems JetEye PC dongle
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Sat Feb 21 18:54:38 1998
  9. * Modified at: Sun Oct 27 22:01:04 2002
  10. * Modified by: Martin Diehl <mad@mdiehl.de>
  11. *
  12. * Copyright (c) 1999 Dag Brattli, <dagb@cs.uit.no>,
  13. * Copyright (c) 1998 Thomas Davis, <ratbert@radiks.net>,
  14. * Copyright (c) 2002 Martin Diehl, <mad@mdiehl.de>,
  15. * All Rights Reserved.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  29. *
  30. ********************************************************************/
  31. #include <linux/module.h>
  32. #include <linux/delay.h>
  33. #include <linux/init.h>
  34. #include <net/irda/irda.h>
  35. #include "sir-dev.h"
  36. static int esi_open(struct sir_dev *);
  37. static int esi_close(struct sir_dev *);
  38. static int esi_change_speed(struct sir_dev *, unsigned);
  39. static int esi_reset(struct sir_dev *);
  40. static struct dongle_driver esi = {
  41. .owner = THIS_MODULE,
  42. .driver_name = "JetEye PC ESI-9680 PC",
  43. .type = IRDA_ESI_DONGLE,
  44. .open = esi_open,
  45. .close = esi_close,
  46. .reset = esi_reset,
  47. .set_speed = esi_change_speed,
  48. };
  49. static int __init esi_sir_init(void)
  50. {
  51. return irda_register_dongle(&esi);
  52. }
  53. static void __exit esi_sir_cleanup(void)
  54. {
  55. irda_unregister_dongle(&esi);
  56. }
  57. static int esi_open(struct sir_dev *dev)
  58. {
  59. struct qos_info *qos = &dev->qos;
  60. /* Power up and set dongle to 9600 baud */
  61. sirdev_set_dtr_rts(dev, FALSE, TRUE);
  62. qos->baud_rate.bits &= IR_9600|IR_19200|IR_115200;
  63. qos->min_turn_time.bits = 0x01; /* Needs at least 10 ms */
  64. irda_qos_bits_to_value(qos);
  65. /* irda thread waits 50 msec for power settling */
  66. return 0;
  67. }
  68. static int esi_close(struct sir_dev *dev)
  69. {
  70. /* Power off dongle */
  71. sirdev_set_dtr_rts(dev, FALSE, FALSE);
  72. return 0;
  73. }
  74. /*
  75. * Function esi_change_speed (task)
  76. *
  77. * Set the speed for the Extended Systems JetEye PC ESI-9680 type dongle
  78. * Apparently (see old esi-driver) no delays are needed here...
  79. *
  80. */
  81. static int esi_change_speed(struct sir_dev *dev, unsigned speed)
  82. {
  83. int ret = 0;
  84. int dtr, rts;
  85. switch (speed) {
  86. case 19200:
  87. dtr = TRUE;
  88. rts = FALSE;
  89. break;
  90. case 115200:
  91. dtr = rts = TRUE;
  92. break;
  93. default:
  94. ret = -EINVAL;
  95. speed = 9600;
  96. /* fall through */
  97. case 9600:
  98. dtr = FALSE;
  99. rts = TRUE;
  100. break;
  101. }
  102. /* Change speed of dongle */
  103. sirdev_set_dtr_rts(dev, dtr, rts);
  104. dev->speed = speed;
  105. return ret;
  106. }
  107. /*
  108. * Function esi_reset (task)
  109. *
  110. * Reset dongle;
  111. *
  112. */
  113. static int esi_reset(struct sir_dev *dev)
  114. {
  115. sirdev_set_dtr_rts(dev, FALSE, FALSE);
  116. /* Hm, the old esi-driver left the dongle unpowered relying on
  117. * the following speed change to repower. This might work for
  118. * the esi because we only need the modem lines. However, now the
  119. * general rule is reset must bring the dongle to some working
  120. * well-known state because speed change might write to registers.
  121. * The old esi-driver didn't any delay here - let's hope it' fine.
  122. */
  123. sirdev_set_dtr_rts(dev, FALSE, TRUE);
  124. dev->speed = 9600;
  125. return 0;
  126. }
  127. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
  128. MODULE_DESCRIPTION("Extended Systems JetEye PC dongle driver");
  129. MODULE_LICENSE("GPL");
  130. MODULE_ALIAS("irda-dongle-1"); /* IRDA_ESI_DONGLE */
  131. module_init(esi_sir_init);
  132. module_exit(esi_sir_cleanup);