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: Mon May 10 16:10:17 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/sched.h>
29 #include <linux/init.h>
31 #include <asm/ioctls.h>
32 #include <asm/segment.h>
33 #include <asm/uaccess.h>
35 #include <net/irda/irda.h>
36 #include <net/irda/irda_device.h>
37 #include <net/irda/irtty.h>
38 #include <net/irda/dongle.h>
40 static void tekram_reset(struct irda_device
*dev
, int unused
);
41 static void tekram_open(struct irda_device
*dev
, int type
);
42 static void tekram_close(struct irda_device
*dev
);
43 static void tekram_change_speed(struct irda_device
*dev
, int baud
);
44 static void tekram_init_qos(struct irda_device
*idev
, struct qos_info
*qos
);
46 #define TEKRAM_115200 0x00
47 #define TEKRAM_57600 0x01
48 #define TEKRAM_38400 0x02
49 #define TEKRAM_19200 0x03
50 #define TEKRAM_9600 0x04
52 #define TEKRAM_PW 0x10 /* Pulse select bit */
54 static struct dongle dongle
= {
63 __initfunc(int tekram_init(void))
65 return irda_device_register_dongle(&dongle
);
68 void tekram_cleanup(void)
70 irda_device_unregister_dongle(&dongle
);
73 static void tekram_open(struct irda_device
*idev
, int type
)
75 strcat(idev
->description
, " <-> tekram");
77 idev
->io
.dongle_id
= type
;
78 idev
->flags
|= IFF_DONGLE
;
83 static void tekram_close(struct irda_device
*idev
)
85 /* Power off dongle */
86 irda_device_set_dtr_rts(idev
, FALSE
, FALSE
);
92 * Function tekram_change_speed (tty, baud)
94 * Set the speed for the Tekram IRMate 210 type dongle. Warning, this
95 * function must be called with a process context!
99 * 2. set RTS, and wait at least 7 us
100 * 3. send Control Byte to the IR-210 through TXD to set new baud rate
101 * wait until the stop bit of Control Byte is sent (for 9600 baud rate,
102 * it takes about 100 msec)
103 * 5. clear RTS (return to NORMAL Operation)
104 * 6. wait at least 50 us, new setting (baud rate, etc) takes effect here
107 static void tekram_change_speed(struct irda_device
*idev
, int baud
)
111 DEBUG(4, __FUNCTION__
"()\n");
113 ASSERT(idev
!= NULL
, return;);
114 ASSERT(idev
->magic
== IRDA_DEVICE_MAGIC
, return;);
119 byte
= TEKRAM_PW
|TEKRAM_9600
;
122 byte
= TEKRAM_PW
|TEKRAM_19200
;
125 byte
= TEKRAM_PW
|TEKRAM_38400
;
128 byte
= TEKRAM_PW
|TEKRAM_57600
;
131 byte
= TEKRAM_PW
|TEKRAM_115200
;
135 /* Set DTR, Clear RTS */
136 irda_device_set_dtr_rts(idev
, TRUE
, FALSE
);
138 /* Wait at least 7us */
141 /* Write control byte */
142 irda_device_raw_write(idev
, &byte
, 1);
144 /* Wait at least 100 ms */
145 current
->state
= TASK_INTERRUPTIBLE
;
146 schedule_timeout(MSECS_TO_JIFFIES(100));
148 /* Set DTR, Set RTS */
149 irda_device_set_dtr_rts(idev
, TRUE
, TRUE
);
153 * Function tekram_reset (driver)
155 * This function resets the tekram dongle. Warning, this function
156 * must be called with a process context!!
159 * 0. Clear RTS and DTR, and wait 50 ms (power off the IR-210 )
161 * 2. set DTR, and wait at least 1 ms
162 * 3. clear DTR to SPACE state, wait at least 50 us for further
165 void tekram_reset(struct irda_device
*idev
, int unused
)
167 ASSERT(idev
!= NULL
, return;);
168 ASSERT(idev
->magic
== IRDA_DEVICE_MAGIC
, return;);
170 /* Power off dongle */
171 irda_device_set_dtr_rts(idev
, FALSE
, FALSE
);
174 current
->state
= TASK_INTERRUPTIBLE
;
175 schedule_timeout(MSECS_TO_JIFFIES(50));
177 /* Clear DTR, Set RTS */
178 irda_device_set_dtr_rts(idev
, FALSE
, TRUE
);
180 /* Should sleep 1 ms, but 10-20 should not do any harm */
181 current
->state
= TASK_INTERRUPTIBLE
;
182 schedule_timeout(MSECS_TO_JIFFIES(20));
184 /* Set DTR, Set RTS */
185 irda_device_set_dtr_rts(idev
, TRUE
, TRUE
);
193 * Function tekram_init_qos (qos)
195 * Initialize QoS capabilities
198 static void tekram_init_qos(struct irda_device
*idev
, struct qos_info
*qos
)
200 qos
->baud_rate
.bits
&= IR_9600
|IR_19200
|IR_38400
|IR_57600
|IR_115200
;
201 qos
->min_turn_time
.bits
&= 0x01; /* Needs at least 10 ms */
202 irda_qos_bits_to_value(qos
);
207 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
208 MODULE_DESCRIPTION("Tekram IrMate IR-210B dongle driver");
211 * Function init_module (void)
213 * Initialize Tekram module
216 int init_module(void)
218 return tekram_init();
222 * Function cleanup_module (void)
224 * Cleanup Tekram module
227 void cleanup_module(void)