[TG3]: Add tagged status support.
[linux-2.6/verdex.git] / drivers / net / irda / litelink.c
blob7db11431d0f48cc65c9e223554ec2f1970792e4e
1 /*********************************************************************
2 *
3 * Filename: litelink.c
4 * Version: 1.1
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: Fri Dec 17 09:14:23 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/init.h>
36 #include <net/irda/irda.h>
37 #include <net/irda/irda_device.h>
39 #define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
40 #define MAX_DELAY 10000 /* 1 ms */
42 static void litelink_open(dongle_t *self, struct qos_info *qos);
43 static void litelink_close(dongle_t *self);
44 static int litelink_change_speed(struct irda_task *task);
45 static int litelink_reset(struct irda_task *task);
47 /* These are the baudrates supported */
48 static __u32 baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
50 static struct dongle_reg dongle = {
51 .type = IRDA_LITELINK_DONGLE,
52 .open = litelink_open,
53 .close = litelink_close,
54 .reset = litelink_reset,
55 .change_speed = litelink_change_speed,
56 .owner = THIS_MODULE,
59 static int __init litelink_init(void)
61 return irda_device_register_dongle(&dongle);
64 static void __exit litelink_cleanup(void)
66 irda_device_unregister_dongle(&dongle);
69 static void litelink_open(dongle_t *self, struct qos_info *qos)
71 qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
72 qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
75 static void litelink_close(dongle_t *self)
77 /* Power off dongle */
78 self->set_dtr_rts(self->dev, FALSE, FALSE);
82 * Function litelink_change_speed (task)
84 * Change speed of the Litelink dongle. To cycle through the available
85 * baud rates, pulse RTS low for a few ms.
87 static int litelink_change_speed(struct irda_task *task)
89 dongle_t *self = (dongle_t *) task->instance;
90 __u32 speed = (__u32) task->param;
91 int i;
93 /* Clear RTS to reset dongle */
94 self->set_dtr_rts(self->dev, TRUE, FALSE);
96 /* Sleep a minimum of 15 us */
97 udelay(MIN_DELAY);
99 /* Go back to normal mode */
100 self->set_dtr_rts(self->dev, TRUE, TRUE);
102 /* Sleep a minimum of 15 us */
103 udelay(MIN_DELAY);
105 /* Cycle through avaiable baudrates until we reach the correct one */
106 for (i=0; i<5 && baud_rates[i] != speed; i++) {
107 /* Set DTR, clear RTS */
108 self->set_dtr_rts(self->dev, FALSE, TRUE);
110 /* Sleep a minimum of 15 us */
111 udelay(MIN_DELAY);
113 /* Set DTR, Set RTS */
114 self->set_dtr_rts(self->dev, TRUE, TRUE);
116 /* Sleep a minimum of 15 us */
117 udelay(MIN_DELAY);
119 irda_task_next_state(task, IRDA_TASK_DONE);
121 return 0;
125 * Function litelink_reset (task)
127 * Reset the Litelink type dongle.
130 static int litelink_reset(struct irda_task *task)
132 dongle_t *self = (dongle_t *) task->instance;
134 /* Power on dongle */
135 self->set_dtr_rts(self->dev, TRUE, TRUE);
137 /* Sleep a minimum of 15 us */
138 udelay(MIN_DELAY);
140 /* Clear RTS to reset dongle */
141 self->set_dtr_rts(self->dev, TRUE, FALSE);
143 /* Sleep a minimum of 15 us */
144 udelay(MIN_DELAY);
146 /* Go back to normal mode */
147 self->set_dtr_rts(self->dev, TRUE, TRUE);
149 /* Sleep a minimum of 15 us */
150 udelay(MIN_DELAY);
152 /* This dongles speed defaults to 115200 bps */
153 self->speed = 115200;
155 irda_task_next_state(task, IRDA_TASK_DONE);
157 return 0;
160 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
161 MODULE_DESCRIPTION("Parallax Litelink dongle driver");
162 MODULE_LICENSE("GPL");
163 MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */
166 * Function init_module (void)
168 * Initialize Litelink module
171 module_init(litelink_init);
174 * Function cleanup_module (void)
176 * Cleanup Litelink module
179 module_exit(litelink_cleanup);