Import 2.3.6pre2
[davej-history.git] / drivers / net / irda / litelink.c
blob84df367da08ab1c1054d37deebe11afcf684b34c
1 /*********************************************************************
2 *
3 * Filename: litelink.c
4 * Version: 1.0
5 * Description: Driver for the Parallax LiteLink dongle
6 * Status: Stable
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Fri May 7 12:50:33 1999
9 * Modified at: Wed May 19 07:25:15 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 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 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
29 ********************************************************************/
31 #include <linux/module.h>
32 #include <linux/delay.h>
33 #include <linux/tty.h>
34 #include <linux/sched.h>
35 #include <linux/init.h>
37 #include <net/irda/irda.h>
38 #include <net/irda/irmod.h>
39 #include <net/irda/irda_device.h>
40 #include <net/irda/dongle.h>
42 #define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
43 #define MAX_DELAY 10000 /* 1 ms */
45 static void litelink_open(struct irda_device *idev, int type);
46 static void litelink_close(struct irda_device *dev);
47 static void litelink_change_speed(struct irda_device *dev, int baudrate);
48 static void litelink_reset(struct irda_device *dev);
49 static void litelink_init_qos(struct irda_device *idev, struct qos_info *qos);
51 /* These are the baudrates supported */
52 static int baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
54 static struct dongle dongle = {
55 LITELINK_DONGLE,
56 litelink_open,
57 litelink_close,
58 litelink_reset,
59 litelink_change_speed,
60 litelink_init_qos,
63 __initfunc(int litelink_init(void))
65 return irda_device_register_dongle(&dongle);
68 void litelink_cleanup(void)
70 irda_device_unregister_dongle(&dongle);
73 static void litelink_open(struct irda_device *idev, int type)
75 strcat(idev->description, " <-> litelink");
77 idev->io.dongle_id = type;
78 idev->flags |= IFF_DONGLE;
80 MOD_INC_USE_COUNT;
83 static void litelink_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 litelink_change_speed (tty, baud)
94 * Change speed of the Litelink dongle. To cycle through the available
95 * baud rates, pulse RTS low for a few ms.
97 static void litelink_change_speed(struct irda_device *idev, int baudrate)
99 int i;
101 ASSERT(idev != NULL, return;);
102 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
104 /* Clear RTS to reset dongle */
105 irda_device_set_dtr_rts(idev, TRUE, FALSE);
107 /* Sleep a minimum of 15 us */
108 udelay(MIN_DELAY);
110 /* Go back to normal mode */
111 irda_device_set_dtr_rts(idev, TRUE, TRUE);
113 /* Sleep a minimum of 15 us */
114 udelay(MIN_DELAY);
116 /* Cycle through avaiable baudrates until we reach the correct one */
117 for (i=0; i<5 && baud_rates[i] != baudrate; i++) {
119 /* Set DTR, clear RTS */
120 irda_device_set_dtr_rts(idev, FALSE, TRUE);
122 /* Sleep a minimum of 15 us */
123 udelay(MIN_DELAY);
125 /* Set DTR, Set RTS */
126 irda_device_set_dtr_rts(idev, TRUE, TRUE);
128 /* Sleep a minimum of 15 us */
129 udelay(MIN_DELAY);
134 * Function litelink_reset (dev)
136 * Reset the Litelink type dongle. Warning, this function must only be
137 * called with a process context!
140 static void litelink_reset(struct irda_device *idev)
142 ASSERT(idev != NULL, return;);
143 ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
145 /* Power on dongle */
146 irda_device_set_dtr_rts(idev, TRUE, TRUE);
148 /* Sleep a minimum of 15 us */
149 udelay(MIN_DELAY);
151 /* Clear RTS to reset dongle */
152 irda_device_set_dtr_rts(idev, TRUE, FALSE);
154 /* Sleep a minimum of 15 us */
155 udelay(MIN_DELAY);
157 /* Go back to normal mode */
158 irda_device_set_dtr_rts(idev, TRUE, TRUE);
160 /* Sleep a minimum of 15 us */
161 udelay(MIN_DELAY);
163 /* This dongles speed defaults to 115200 bps */
164 idev->qos.baud_rate.value = 115200;
168 * Function litelink_init_qos (qos)
170 * Initialize QoS capabilities
173 static void litelink_init_qos(struct irda_device *idev, struct qos_info *qos)
175 qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
176 qos->min_turn_time.bits &= 0x40; /* Needs 0.01 ms */
179 #ifdef MODULE
181 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
182 MODULE_DESCRIPTION("Parallax Litelink dongle driver");
185 * Function init_module (void)
187 * Initialize Litelink module
190 int init_module(void)
192 return litelink_init();
196 * Function cleanup_module (void)
198 * Cleanup Litelink module
201 void cleanup_module(void)
203 litelink_cleanup();
206 #endif