Import 2.3.10pre5
[davej-history.git] / drivers / net / irda / tekram.c
blobc47cf68d7c5ed992269749fbb46a3ce7cc50de74
1 /*********************************************************************
2 *
3 * Filename: tekram.c
4 * Version: 1.2
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: Sun May 16 14:33:42 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 <net/irda/irda.h>
32 #include <net/irda/irda_device.h>
33 #include <net/irda/irtty.h>
34 #include <net/irda/dongle.h>
36 static void tekram_reset(struct irda_device *dev);
37 static void tekram_open(struct irda_device *dev, int type);
38 static void tekram_close(struct irda_device *dev);
39 static void tekram_change_speed(struct irda_device *dev, int baud);
40 static void tekram_init_qos(struct irda_device *idev, struct qos_info *qos);
42 #define TEKRAM_115200 0x00
43 #define TEKRAM_57600 0x01
44 #define TEKRAM_38400 0x02
45 #define TEKRAM_19200 0x03
46 #define TEKRAM_9600 0x04
48 #define TEKRAM_PW 0x10 /* Pulse select bit */
50 static struct dongle dongle = {
51 TEKRAM_DONGLE,
52 tekram_open,
53 tekram_close,
54 tekram_reset,
55 tekram_change_speed,
56 tekram_init_qos,
59 int __init tekram_init(void)
61 return irda_device_register_dongle(&dongle);
64 void tekram_cleanup(void)
66 irda_device_unregister_dongle(&dongle);
69 static void tekram_open(struct irda_device *idev, int type)
71 strcat(idev->description, " <-> tekram");
73 idev->io.dongle_id = type;
74 idev->flags |= IFF_DONGLE;
76 MOD_INC_USE_COUNT;
79 static void tekram_close(struct irda_device *idev)
81 /* Power off dongle */
82 irda_device_set_dtr_rts(idev, FALSE, FALSE);
84 MOD_DEC_USE_COUNT;
88 * Function tekram_change_speed (tty, baud)
90 * Set the speed for the Tekram IRMate 210 type dongle. Warning, this
91 * function must be called with a process context!
93 * Algorithm
94 * 1. clear DTR
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
101 * after
103 static void tekram_change_speed(struct irda_device *idev, int baud)
105 __u8 byte;
107 DEBUG(4, __FUNCTION__ "()\n");
109 ASSERT(idev != NULL, return;);
110 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
112 switch (baud) {
113 default:
114 case 9600:
115 byte = TEKRAM_PW|TEKRAM_9600;
116 break;
117 case 19200:
118 byte = TEKRAM_PW|TEKRAM_19200;
119 break;
120 case 38400:
121 byte = TEKRAM_PW|TEKRAM_38400;
122 break;
123 case 57600:
124 byte = TEKRAM_PW|TEKRAM_57600;
125 break;
126 case 115200:
127 byte = TEKRAM_PW|TEKRAM_115200;
128 break;
131 /* Need to reset the dongle and go to 9600 bps before programming */
132 tekram_reset(idev);
134 /* Set DTR, Clear RTS */
135 irda_device_set_dtr_rts(idev, TRUE, FALSE);
137 /* Wait at least 7us */
138 udelay(7);
140 /* Write control byte */
141 irda_device_raw_write(idev, &byte, 1);
143 /* Wait at least 100 ms */
144 current->state = TASK_INTERRUPTIBLE;
145 schedule_timeout(MSECS_TO_JIFFIES(100));
147 /* Set DTR, Set RTS */
148 irda_device_set_dtr_rts(idev, TRUE, TRUE);
152 * Function tekram_reset (driver)
154 * This function resets the tekram dongle. Warning, this function
155 * must be called with a process context!!
157 * Algorithm:
158 * 0. Clear RTS and DTR, and wait 50 ms (power off the IR-210 )
159 * 1. clear RTS
160 * 2. set DTR, and wait at least 1 ms
161 * 3. clear DTR to SPACE state, wait at least 50 us for further
162 * operation
164 void tekram_reset(struct irda_device *idev)
166 ASSERT(idev != NULL, return;);
167 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
169 /* Power off dongle */
170 irda_device_set_dtr_rts(idev, FALSE, FALSE);
172 /* Sleep 50 ms */
173 current->state = TASK_INTERRUPTIBLE;
174 schedule_timeout(MSECS_TO_JIFFIES(50));
176 /* Clear DTR, Set RTS */
177 irda_device_set_dtr_rts(idev, FALSE, TRUE);
179 /* Should sleep 1 ms, but 10-20 should not do any harm */
180 current->state = TASK_INTERRUPTIBLE;
181 schedule_timeout(MSECS_TO_JIFFIES(20));
183 /* Set DTR, Set RTS */
184 irda_device_set_dtr_rts(idev, TRUE, TRUE);
186 udelay(50);
188 /* Make sure the IrDA chip also goes to defalt speed */
189 if (idev->change_speed)
190 idev->change_speed(idev, 9600);
194 * Function tekram_init_qos (qos)
196 * Initialize QoS capabilities
199 static void tekram_init_qos(struct irda_device *idev, struct qos_info *qos)
201 qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
202 qos->min_turn_time.bits &= 0x01; /* Needs at least 10 ms */
203 irda_qos_bits_to_value(qos);
206 #ifdef MODULE
208 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
209 MODULE_DESCRIPTION("Tekram IrMate IR-210B dongle driver");
212 * Function init_module (void)
214 * Initialize Tekram module
217 int init_module(void)
219 return tekram_init();
223 * Function cleanup_module (void)
225 * Cleanup Tekram module
228 void cleanup_module(void)
230 tekram_cleanup();
233 #endif /* MODULE */