File: /usr/src/linux/drivers/net/irda/litelink.c

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>
11      * 
12      *     Copyright (c) 1999 Dag Brattli, All Rights Reserved.
13      *     
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.
18      * 
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.
23      * 
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
28      *     
29      ********************************************************************/
30     
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>
36     
37     #include <net/irda/irda.h>
38     #include <net/irda/irmod.h>
39     #include <net/irda/irda_device.h>
40     
41     #define MIN_DELAY 25      /* 15 us, but wait a little more to be sure */
42     #define MAX_DELAY 10000   /* 1 ms */
43     
44     static void litelink_open(dongle_t *self, struct qos_info *qos);
45     static void litelink_close(dongle_t *self);
46     static int  litelink_change_speed(struct irda_task *task);
47     static int  litelink_reset(struct irda_task *task);
48     
49     /* These are the baudrates supported */
50     static __u32 baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
51     
52     static struct dongle_reg dongle = {
53     	Q_NULL,
54     	IRDA_LITELINK_DONGLE,
55     	litelink_open,
56     	litelink_close,
57     	litelink_reset,
58     	litelink_change_speed,
59     };
60     
61     int __init litelink_init(void)
62     {
63     	return irda_device_register_dongle(&dongle);
64     }
65     
66     void litelink_cleanup(void)
67     {
68     	irda_device_unregister_dongle(&dongle);
69     }
70     
71     static void litelink_open(dongle_t *self, struct qos_info *qos)
72     {
73     	qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
74     	qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
75     
76     	MOD_INC_USE_COUNT;
77     }
78     
79     static void litelink_close(dongle_t *self)
80     {
81     	/* Power off dongle */
82     	self->set_dtr_rts(self->dev, FALSE, FALSE);
83     
84     	MOD_DEC_USE_COUNT;
85     }
86     
87     /*
88      * Function litelink_change_speed (task)
89      *
90      *    Change speed of the Litelink dongle. To cycle through the available 
91      *    baud rates, pulse RTS low for a few ms.  
92      */
93     static int litelink_change_speed(struct irda_task *task)
94     {
95     	dongle_t *self = (dongle_t *) task->instance;
96     	__u32 speed = (__u32) task->param;
97             int i;
98     	
99     	/* Clear RTS to reset dongle */
100     	self->set_dtr_rts(self->dev, TRUE, FALSE);
101     
102     	/* Sleep a minimum of 15 us */
103     	udelay(MIN_DELAY);
104     
105     	/* Go back to normal mode */
106     	self->set_dtr_rts(self->dev, TRUE, TRUE);
107     	
108     	/* Sleep a minimum of 15 us */
109     	udelay(MIN_DELAY);
110     	
111     	/* Cycle through avaiable baudrates until we reach the correct one */
112     	for (i=0; i<5 && baud_rates[i] != speed; i++) {
113     		/* Set DTR, clear RTS */
114     		self->set_dtr_rts(self->dev, FALSE, TRUE);
115     		
116     		/* Sleep a minimum of 15 us */
117     		udelay(MIN_DELAY);
118     		
119     		/* Set DTR, Set RTS */
120     		self->set_dtr_rts(self->dev, TRUE, TRUE);
121     		
122     		/* Sleep a minimum of 15 us */
123     		udelay(MIN_DELAY);
124             }
125     	irda_task_next_state(task, IRDA_TASK_DONE);
126     
127     	return 0;
128     }
129     
130     /*
131      * Function litelink_reset (task)
132      *
133      *      Reset the Litelink type dongle.
134      *
135      */
136     static int litelink_reset(struct irda_task *task)
137     {
138     	dongle_t *self = (dongle_t *) task->instance;
139     
140     	/* Power on dongle */
141     	self->set_dtr_rts(self->dev, TRUE, TRUE);
142     
143     	/* Sleep a minimum of 15 us */
144     	udelay(MIN_DELAY);
145     
146     	/* Clear RTS to reset dongle */
147     	self->set_dtr_rts(self->dev, TRUE, FALSE);
148     
149     	/* Sleep a minimum of 15 us */
150     	udelay(MIN_DELAY);
151     
152     	/* Go back to normal mode */
153     	self->set_dtr_rts(self->dev, TRUE, TRUE);
154     	
155     	/* Sleep a minimum of 15 us */
156     	udelay(MIN_DELAY);
157     
158     	/* This dongles speed defaults to 115200 bps */
159     	self->speed = 115200;
160     
161     	irda_task_next_state(task, IRDA_TASK_DONE);
162     
163     	return 0;
164     }
165     
166     #ifdef MODULE
167     MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
168     MODULE_DESCRIPTION("Parallax Litelink dongle driver");	
169     		
170     /*
171      * Function init_module (void)
172      *
173      *    Initialize Litelink module
174      *
175      */
176     int init_module(void)
177     {
178     	return litelink_init();
179     }
180     
181     /*
182      * Function cleanup_module (void)
183      *
184      *    Cleanup Litelink module
185      *
186      */
187     void cleanup_module(void)
188     {
189     	litelink_cleanup();
190     }
191     #endif /* MODULE */
192