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 IRDA_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 IRDA_WARNING("%s(), resetting dongle timed out!\n",
162 case IRDA_TASK_CHILD_DONE:
163 /* Set DTR, Clear RTS */
164 self->set_dtr_rts(self->dev, TRUE, FALSE);
166 /* Wait at least 7us */
169 /* Write control byte */
170 self->write(self->dev, &byte, 1);
172 irda_task_next_state(task, IRDA_TASK_WAIT);
174 /* Wait at least 100 ms */
175 ret = msecs_to_jiffies(150);
178 /* Set DTR, Set RTS */
179 self->set_dtr_rts(self->dev, TRUE, TRUE);
181 irda_task_next_state(task, IRDA_TASK_DONE);
182 self->speed_task = NULL;
185 IRDA_ERROR("%s(), unknown state %d\n",
186 __FUNCTION__, task->state);
187 irda_task_next_state(task, IRDA_TASK_DONE);
188 self->speed_task = NULL;
196 * Function tekram_reset (driver)
198 * This function resets the tekram dongle. Warning, this function
199 * must be called with a process context!!
202 * 0. Clear RTS and DTR, and wait 50 ms (power off the IR-210 )
204 * 2. set DTR, and wait at least 1 ms
205 * 3. clear DTR to SPACE state, wait at least 50 us for further
208 int tekram_reset(struct irda_task *task)
210 dongle_t *self = (dongle_t *) task->instance;
213 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
215 IRDA_ASSERT(task != NULL, return -1;);
217 if (self->reset_task && self->reset_task != task) {
218 IRDA_DEBUG(0, "%s(), busy!\n", __FUNCTION__ );
219 return msecs_to_jiffies(10);
221 self->reset_task = task;
223 /* Power off dongle */
224 //self->set_dtr_rts(self->dev, FALSE, FALSE);
225 self->set_dtr_rts(self->dev, TRUE, TRUE);
227 switch (task->state) {
229 irda_task_next_state(task, IRDA_TASK_WAIT1);
232 ret = msecs_to_jiffies(50);
234 case IRDA_TASK_WAIT1:
235 /* Clear DTR, Set RTS */
236 self->set_dtr_rts(self->dev, FALSE, TRUE);
238 irda_task_next_state(task, IRDA_TASK_WAIT2);
240 /* Should sleep 1 ms */
241 ret = msecs_to_jiffies(1);
243 case IRDA_TASK_WAIT2:
244 /* Set DTR, Set RTS */
245 self->set_dtr_rts(self->dev, TRUE, TRUE);
247 /* Wait at least 50 us */
250 irda_task_next_state(task, IRDA_TASK_DONE);
251 self->reset_task = NULL;
254 IRDA_ERROR("%s(), unknown state %d\n",
255 __FUNCTION__, task->state);
256 irda_task_next_state(task, IRDA_TASK_DONE);
257 self->reset_task = NULL;
263 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
264 MODULE_DESCRIPTION("Tekram IrMate IR-210B dongle driver");
265 MODULE_LICENSE("GPL");
266 MODULE_ALIAS("irda-dongle-0"); /* IRDA_TEKRAM_DONGLE */
269 * Function init_module (void)
271 * Initialize Tekram module
274 module_init(tekram_init);
277 * Function cleanup_module (void)
279 * Cleanup Tekram module
282 module_exit(tekram_cleanup);