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: Fri Dec 17 09:13:20 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/init.h>
29 #include <net/irda/irda.h>
33 static int girbil_reset(struct sir_dev
*dev
);
34 static int girbil_open(struct sir_dev
*dev
);
35 static int girbil_close(struct sir_dev
*dev
);
36 static int girbil_change_speed(struct sir_dev
*dev
, unsigned speed
);
38 /* Control register 1 */
39 #define GIRBIL_TXEN 0x01 /* Enable transmitter */
40 #define GIRBIL_RXEN 0x02 /* Enable receiver */
41 #define GIRBIL_ECAN 0x04 /* Cancel self emitted data */
42 #define GIRBIL_ECHO 0x08 /* Echo control characters */
44 /* LED Current Register (0x2) */
45 #define GIRBIL_HIGH 0x20
46 #define GIRBIL_MEDIUM 0x21
47 #define GIRBIL_LOW 0x22
49 /* Baud register (0x3) */
50 #define GIRBIL_2400 0x30
51 #define GIRBIL_4800 0x31
52 #define GIRBIL_9600 0x32
53 #define GIRBIL_19200 0x33
54 #define GIRBIL_38400 0x34
55 #define GIRBIL_57600 0x35
56 #define GIRBIL_115200 0x36
58 /* Mode register (0x4) */
59 #define GIRBIL_IRDA 0x40
60 #define GIRBIL_ASK 0x41
62 /* Control register 2 (0x5) */
63 #define GIRBIL_LOAD 0x51 /* Load the new baud rate value */
65 static struct dongle_driver girbil
= {
67 .driver_name
= "Greenwich GIrBIL",
68 .type
= IRDA_GIRBIL_DONGLE
,
70 .close
= girbil_close
,
71 .reset
= girbil_reset
,
72 .set_speed
= girbil_change_speed
,
75 static int __init
girbil_sir_init(void)
77 return irda_register_dongle(&girbil
);
80 static void __exit
girbil_sir_cleanup(void)
82 irda_unregister_dongle(&girbil
);
85 static int girbil_open(struct sir_dev
*dev
)
87 struct qos_info
*qos
= &dev
->qos
;
89 IRDA_DEBUG(2, "%s()\n", __func__
);
92 sirdev_set_dtr_rts(dev
, TRUE
, TRUE
);
94 qos
->baud_rate
.bits
&= IR_9600
|IR_19200
|IR_38400
|IR_57600
|IR_115200
;
95 qos
->min_turn_time
.bits
= 0x03;
96 irda_qos_bits_to_value(qos
);
98 /* irda thread waits 50 msec for power settling */
103 static int girbil_close(struct sir_dev
*dev
)
105 IRDA_DEBUG(2, "%s()\n", __func__
);
107 /* Power off dongle */
108 sirdev_set_dtr_rts(dev
, FALSE
, FALSE
);
114 * Function girbil_change_speed (dev, speed)
116 * Set the speed for the Girbil type dongle.
120 #define GIRBIL_STATE_WAIT_SPEED (SIRDEV_STATE_DONGLE_SPEED + 1)
122 static int girbil_change_speed(struct sir_dev
*dev
, unsigned speed
)
124 unsigned state
= dev
->fsm
.substate
;
129 IRDA_DEBUG(2, "%s()\n", __func__
);
131 /* dongle alread reset - port and dongle at default speed */
135 case SIRDEV_STATE_DONGLE_SPEED
:
137 /* Set DTR and Clear RTS to enter command mode */
138 sirdev_set_dtr_rts(dev
, FALSE
, TRUE
);
140 udelay(25); /* better wait a little while */
148 control
[0] = GIRBIL_9600
;
151 control
[0] = GIRBIL_19200
;
154 control
[0] = GIRBIL_38400
;
157 control
[0] = GIRBIL_57600
;
160 control
[0] = GIRBIL_115200
;
163 control
[1] = GIRBIL_LOAD
;
165 /* Write control bytes */
166 sirdev_raw_write(dev
, control
, 2);
170 state
= GIRBIL_STATE_WAIT_SPEED
;
174 case GIRBIL_STATE_WAIT_SPEED
:
175 /* Go back to normal mode */
176 sirdev_set_dtr_rts(dev
, TRUE
, TRUE
);
178 udelay(25); /* better wait a little while */
182 IRDA_ERROR("%s - undefined state %d\n", __func__
, state
);
186 dev
->fsm
.substate
= state
;
187 return (delay
> 0) ? delay
: ret
;
191 * Function girbil_reset (driver)
193 * This function resets the girbil dongle.
196 * 0. set RTS, and wait at least 5 ms
201 #define GIRBIL_STATE_WAIT1_RESET (SIRDEV_STATE_DONGLE_RESET + 1)
202 #define GIRBIL_STATE_WAIT2_RESET (SIRDEV_STATE_DONGLE_RESET + 2)
203 #define GIRBIL_STATE_WAIT3_RESET (SIRDEV_STATE_DONGLE_RESET + 3)
205 static int girbil_reset(struct sir_dev
*dev
)
207 unsigned state
= dev
->fsm
.substate
;
209 u8 control
= GIRBIL_TXEN
| GIRBIL_RXEN
;
212 IRDA_DEBUG(2, "%s()\n", __func__
);
215 case SIRDEV_STATE_DONGLE_RESET
:
217 sirdev_set_dtr_rts(dev
, TRUE
, FALSE
);
218 /* Sleep at least 5 ms */
220 state
= GIRBIL_STATE_WAIT1_RESET
;
223 case GIRBIL_STATE_WAIT1_RESET
:
224 /* Set DTR and clear RTS to enter command mode */
225 sirdev_set_dtr_rts(dev
, FALSE
, TRUE
);
227 state
= GIRBIL_STATE_WAIT2_RESET
;
230 case GIRBIL_STATE_WAIT2_RESET
:
231 /* Write control byte */
232 sirdev_raw_write(dev
, &control
, 1);
234 state
= GIRBIL_STATE_WAIT3_RESET
;
237 case GIRBIL_STATE_WAIT3_RESET
:
238 /* Go back to normal mode */
239 sirdev_set_dtr_rts(dev
, TRUE
, TRUE
);
244 IRDA_ERROR("%s(), undefined state %d\n", __func__
, state
);
248 dev
->fsm
.substate
= state
;
249 return (delay
> 0) ? delay
: ret
;
252 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
253 MODULE_DESCRIPTION("Greenwich GIrBIL dongle driver");
254 MODULE_LICENSE("GPL");
255 MODULE_ALIAS("irda-dongle-4"); /* IRDA_GIRBIL_DONGLE */
257 module_init(girbil_sir_init
);
258 module_exit(girbil_sir_cleanup
);