1 /*********************************************************************
5 * Description: Implementation for the Greenwich GIrBIL dongle
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sat Feb 6 21:02:33 1999
9 * Modified at: Sun Jul 18 12:09:26 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 * 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/irmod.h>
33 #include <net/irda/irda_device.h>
34 #include <net/irda/irtty.h>
35 #include <net/irda/dongle.h>
37 static void girbil_reset(struct irda_device
*dev
);
38 static void girbil_open(struct irda_device
*dev
, int type
);
39 static void girbil_close(struct irda_device
*dev
);
40 static void girbil_change_speed(struct irda_device
*dev
, __u32 speed
);
41 static void girbil_init_qos(struct irda_device
*idev
, struct qos_info
*qos
);
43 /* Control register 1 */
44 #define GIRBIL_TXEN 0x01 /* Enable transmitter */
45 #define GIRBIL_RXEN 0x02 /* Enable receiver */
46 #define GIRBIL_ECAN 0x04 /* Cancel self emmited data */
47 #define GIRBIL_ECHO 0x08 /* Echo control characters */
49 /* LED Current Register (0x2) */
50 #define GIRBIL_HIGH 0x20
51 #define GIRBIL_MEDIUM 0x21
52 #define GIRBIL_LOW 0x22
54 /* Baud register (0x3) */
55 #define GIRBIL_2400 0x30
56 #define GIRBIL_4800 0x31
57 #define GIRBIL_9600 0x32
58 #define GIRBIL_19200 0x33
59 #define GIRBIL_38400 0x34
60 #define GIRBIL_57600 0x35
61 #define GIRBIL_115200 0x36
63 /* Mode register (0x4) */
64 #define GIRBIL_IRDA 0x40
65 #define GIRBIL_ASK 0x41
67 /* Control register 2 (0x5) */
68 #define GIRBIL_LOAD 0x51 /* Load the new baud rate value */
70 static struct dongle dongle
= {
79 int __init
girbil_init(void)
81 return irda_device_register_dongle(&dongle
);
84 void girbil_cleanup(void)
86 irda_device_unregister_dongle(&dongle
);
89 static void girbil_open(struct irda_device
*idev
, int type
)
91 strcat(idev
->description
, " <-> girbil");
93 idev
->io
.dongle_id
= type
;
94 idev
->flags
|= IFF_DONGLE
;
99 static void girbil_close(struct irda_device
*idev
)
101 /* Power off dongle */
102 irda_device_set_dtr_rts(idev
, FALSE
, FALSE
);
108 * Function girbil_change_speed (dev, speed)
110 * Set the speed for the Girbil type dongle. Warning, this
111 * function must be called with a process context!
114 static void girbil_change_speed(struct irda_device
*idev
, __u32 speed
)
118 ASSERT(idev
!= NULL
, return;);
119 ASSERT(idev
->magic
== IRDA_DEVICE_MAGIC
, return;);
124 control
[0] = GIRBIL_9600
;
127 control
[0] = GIRBIL_19200
;
130 control
[0] = GIRBIL_38400
;
133 control
[0] = GIRBIL_57600
;
136 control
[0] = GIRBIL_115200
;
139 control
[1] = GIRBIL_LOAD
;
141 /* Need to reset the dongle and go to 9600 bps before programming */
144 /* Set DTR and Clear RTS to enter command mode */
145 irda_device_set_dtr_rts(idev
, FALSE
, TRUE
);
147 /* Write control bytes */
148 irda_device_raw_write(idev
, control
, 2);
150 current
->state
= TASK_INTERRUPTIBLE
;
151 schedule_timeout(MSECS_TO_JIFFIES(100));
153 /* Go back to normal mode */
154 irda_device_set_dtr_rts(idev
, TRUE
, TRUE
);
158 * Function girbil_reset (driver)
160 * This function resets the girbil dongle. Warning, this function
161 * must be called with a process context!!
164 * 0. set RTS, and wait at least 5 ms
167 void girbil_reset(struct irda_device
*idev
)
169 __u8 control
= GIRBIL_TXEN
| GIRBIL_RXEN
;
171 ASSERT(idev
!= NULL
, return;);
172 ASSERT(idev
->magic
== IRDA_DEVICE_MAGIC
, return;);
174 /* Make sure the IrDA chip also goes to defalt speed */
175 if (idev
->change_speed
)
176 idev
->change_speed(idev
, 9600);
179 irda_device_set_dtr_rts(idev
, TRUE
, FALSE
);
181 /* Sleep at least 5 ms */
182 current
->state
= TASK_INTERRUPTIBLE
;
183 schedule_timeout(MSECS_TO_JIFFIES(10));
185 /* Set DTR and clear RTS to enter command mode */
186 irda_device_set_dtr_rts(idev
, FALSE
, TRUE
);
188 current
->state
= TASK_INTERRUPTIBLE
;
189 schedule_timeout(MSECS_TO_JIFFIES(10));
191 /* Write control byte */
192 irda_device_raw_write(idev
, &control
, 1);
194 current
->state
= TASK_INTERRUPTIBLE
;
195 schedule_timeout(MSECS_TO_JIFFIES(20));
197 /* Go back to normal mode */
198 irda_device_set_dtr_rts(idev
, TRUE
, TRUE
);
202 * Function girbil_init_qos (qos)
204 * Initialize QoS capabilities
207 static void girbil_init_qos(struct irda_device
*idev
, struct qos_info
*qos
)
209 qos
->baud_rate
.bits
&= IR_9600
|IR_19200
|IR_38400
|IR_57600
|IR_115200
;
210 qos
->min_turn_time
.bits
&= 0x03;
215 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
216 MODULE_DESCRIPTION("Greenwich GIrBIL dongle driver");
219 * Function init_module (void)
221 * Initialize Girbil module
224 int init_module(void)
226 return girbil_init();
230 * Function cleanup_module (void)
232 * Cleanup Girbil module
235 void cleanup_module(void)