Import 2.3.4pre3
[davej-history.git] / drivers / net / irda / tekram.c
blobe99cb0d445018121fe718d74e9c8644e7050ab8a
1 /*********************************************************************
2 *
3 * Filename: tekram.c
4 * Version: 1.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 = {
55 TEKRAM_DONGLE,
56 tekram_open,
57 tekram_close,
58 tekram_reset,
59 tekram_change_speed,
60 tekram_init_qos,
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;
80 MOD_INC_USE_COUNT;
83 static void tekram_close(struct irda_device *idev)
85 /* Power off dongle */
86 irda_device_set_dtr_rts(idev, FALSE, FALSE);
88 MOD_DEC_USE_COUNT;
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!
97 * Algorithm
98 * 1. clear DTR
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
105 * after
107 static void tekram_change_speed(struct irda_device *idev, int baud)
109 __u8 byte;
111 DEBUG(4, __FUNCTION__ "()\n");
113 ASSERT(idev != NULL, return;);
114 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
116 switch (baud) {
117 default:
118 case 9600:
119 byte = TEKRAM_PW|TEKRAM_9600;
120 break;
121 case 19200:
122 byte = TEKRAM_PW|TEKRAM_19200;
123 break;
124 case 34800:
125 byte = TEKRAM_PW|TEKRAM_38400;
126 break;
127 case 57600:
128 byte = TEKRAM_PW|TEKRAM_57600;
129 break;
130 case 115200:
131 byte = TEKRAM_PW|TEKRAM_115200;
132 break;
135 /* Set DTR, Clear RTS */
136 irda_device_set_dtr_rts(idev, TRUE, FALSE);
138 /* Wait at least 7us */
139 udelay(7);
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!!
158 * Algorithm:
159 * 0. Clear RTS and DTR, and wait 50 ms (power off the IR-210 )
160 * 1. clear RTS
161 * 2. set DTR, and wait at least 1 ms
162 * 3. clear DTR to SPACE state, wait at least 50 us for further
163 * operation
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);
173 /* Sleep 50 ms */
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);
187 udelay(50);
189 /* Finished! */
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);
205 #ifdef MODULE
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)
229 tekram_cleanup();
232 #endif /* MODULE */