1 /*********************************************************************
5 * Description: Implementation of the Tekram IrMate IR-210B dongle
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Wed Oct 21 20:02:35 1998
9 * Modified at: Fri Dec 17 09:13:09 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
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.
19 * Neither Dag Brattli nor University of Tromsø admit liability nor
20 * provide warranty for any of this software. This material is
21 * provided "AS-IS" and at no charge.
23 ********************************************************************/
25 #include <linux/module.h>
26 #include <linux/delay.h>
27 #include <linux/tty.h>
28 #include <linux/init.h>
30 #include <net/irda/irda.h>
31 #include <net/irda/irda_device.h>
33 static void tekram_open(dongle_t *self, struct qos_info *qos);
34 static void tekram_close(dongle_t *self);
35 static int tekram_change_speed(struct irda_task *task);
36 static int tekram_reset(struct irda_task *task);
38 #define TEKRAM_115200 0x00
39 #define TEKRAM_57600 0x01
40 #define TEKRAM_38400 0x02
41 #define TEKRAM_19200 0x03
42 #define TEKRAM_9600 0x04
44 #define TEKRAM_PW 0x10 /* Pulse select bit */
46 static struct dongle_reg dongle = {
47 .type = IRDA_TEKRAM_DONGLE,
49 .close = tekram_close,
50 .reset = tekram_reset,
51 .change_speed = tekram_change_speed,
55 static int __init tekram_init(void)
57 return irda_device_register_dongle(&dongle);
60 static void __exit tekram_cleanup(void)
62 irda_device_unregister_dongle(&dongle);
65 static void tekram_open(dongle_t *self, struct qos_info *qos)
67 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
69 qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
70 qos->min_turn_time.bits = 0x01; /* Needs at least 10 ms */
71 irda_qos_bits_to_value(qos);
74 static void tekram_close(dongle_t *self)
76 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
78 /* Power off dongle */
79 self->set_dtr_rts(self->dev, FALSE, FALSE);
82 irda_task_delete(self->reset_task);
84 irda_task_delete(self->speed_task);
88 * Function tekram_change_speed (dev, state, speed)
90 * Set the speed for the Tekram IRMate 210 type dongle. Warning, this
91 * function must be called with a process context!
95 * 2. set RTS, and wait at least 7 us
96 * 3. send Control Byte to the IR-210 through TXD to set new baud rate
97 * wait until the stop bit of Control Byte is sent (for 9600 baud rate,
98 * it takes about 100 msec)
99 * 5. clear RTS (return to NORMAL Operation)
100 * 6. wait at least 50 us, new setting (baud rate, etc) takes effect here
103 static int tekram_change_speed(struct irda_task *task)
105 dongle_t *self = (dongle_t *) task->instance;
106 __u32 speed = (__u32) task->param;
110 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
112 ASSERT(task != NULL, return -1;);
114 if (self->speed_task && self->speed_task != task) {
115 IRDA_DEBUG(0, "%s(), busy!\n", __FUNCTION__ );
116 return msecs_to_jiffies(10);
118 self->speed_task = task;
123 byte = TEKRAM_PW|TEKRAM_9600;
126 byte = TEKRAM_PW|TEKRAM_19200;
129 byte = TEKRAM_PW|TEKRAM_38400;
132 byte = TEKRAM_PW|TEKRAM_57600;
135 byte = TEKRAM_115200;
139 switch (task->state) {
141 case IRDA_TASK_CHILD_INIT:
143 * Need to reset the dongle and go to 9600 bps before
146 if (irda_task_execute(self, tekram_reset, NULL, task,
149 /* Dongle need more time to reset */
150 irda_task_next_state(task, IRDA_TASK_CHILD_WAIT);
152 /* Give reset 1 sec to finish */
153 ret = msecs_to_jiffies(1000);
155 irda_task_next_state(task, IRDA_TASK_CHILD_DONE);
157 case IRDA_TASK_CHILD_WAIT:
158 WARNING("%s(), resetting dongle timed out!\n", __FUNCTION__);
161 case IRDA_TASK_CHILD_DONE:
162 /* Set DTR, Clear RTS */
163 self->set_dtr_rts(self->dev, TRUE, FALSE);
165 /* Wait at least 7us */
168 /* Write control byte */
169 self->write(self->dev, &byte, 1);
171 irda_task_next_state(task, IRDA_TASK_WAIT);
173 /* Wait at least 100 ms */
174 ret = msecs_to_jiffies(150);
177 /* Set DTR, Set RTS */
178 self->set_dtr_rts(self->dev, TRUE, TRUE);
180 irda_task_next_state(task, IRDA_TASK_DONE);
181 self->speed_task = NULL;
184 ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state);
185 irda_task_next_state(task, IRDA_TASK_DONE);
186 self->speed_task = NULL;
194 * Function tekram_reset (driver)
196 * This function resets the tekram dongle. Warning, this function
197 * must be called with a process context!!
200 * 0. Clear RTS and DTR, and wait 50 ms (power off the IR-210 )
202 * 2. set DTR, and wait at least 1 ms
203 * 3. clear DTR to SPACE state, wait at least 50 us for further
206 int tekram_reset(struct irda_task *task)
208 dongle_t *self = (dongle_t *) task->instance;
211 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
213 ASSERT(task != NULL, return -1;);
215 if (self->reset_task && self->reset_task != task) {
216 IRDA_DEBUG(0, "%s(), busy!\n", __FUNCTION__ );
217 return msecs_to_jiffies(10);
219 self->reset_task = task;
221 /* Power off dongle */
222 //self->set_dtr_rts(self->dev, FALSE, FALSE);
223 self->set_dtr_rts(self->dev, TRUE, TRUE);
225 switch (task->state) {
227 irda_task_next_state(task, IRDA_TASK_WAIT1);
230 ret = msecs_to_jiffies(50);
232 case IRDA_TASK_WAIT1:
233 /* Clear DTR, Set RTS */
234 self->set_dtr_rts(self->dev, FALSE, TRUE);
236 irda_task_next_state(task, IRDA_TASK_WAIT2);
238 /* Should sleep 1 ms */
239 ret = msecs_to_jiffies(1);
241 case IRDA_TASK_WAIT2:
242 /* Set DTR, Set RTS */
243 self->set_dtr_rts(self->dev, TRUE, TRUE);
245 /* Wait at least 50 us */
248 irda_task_next_state(task, IRDA_TASK_DONE);
249 self->reset_task = NULL;
252 ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state);
253 irda_task_next_state(task, IRDA_TASK_DONE);
254 self->reset_task = NULL;
260 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
261 MODULE_DESCRIPTION("Tekram IrMate IR-210B dongle driver");
262 MODULE_LICENSE("GPL");
263 MODULE_ALIAS("irda-dongle-0"); /* IRDA_TEKRAM_DONGLE */
266 * Function init_module (void)
268 * Initialize Tekram module
271 module_init(tekram_init);
274 * Function cleanup_module (void)
276 * Cleanup Tekram module
279 module_exit(tekram_cleanup);