libertas: convert SNMP_MIB to a direct command
[linux/fpc-iii.git] / drivers / net / irda / girbil-sir.c
bloba31b8fa8aaa991e3aa70e7d74223036600af84c6
1 /*********************************************************************
3 * Filename: girbil.c
4 * Version: 1.2
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>
31 #include "sir-dev.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 emmited 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 = {
66 .owner = THIS_MODULE,
67 .driver_name = "Greenwich GIrBIL",
68 .type = IRDA_GIRBIL_DONGLE,
69 .open = girbil_open,
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__);
91 /* Power on dongle */
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 */
100 return 0;
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);
110 return 0;
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;
125 unsigned delay = 0;
126 u8 control[2];
127 static int ret = 0;
129 IRDA_DEBUG(2, "%s()\n", __func__);
131 /* dongle alread reset - port and dongle at default speed */
133 switch(state) {
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 */
142 ret = 0;
143 switch (speed) {
144 default:
145 ret = -EINVAL;
146 /* fall through */
147 case 9600:
148 control[0] = GIRBIL_9600;
149 break;
150 case 19200:
151 control[0] = GIRBIL_19200;
152 break;
153 case 34800:
154 control[0] = GIRBIL_38400;
155 break;
156 case 57600:
157 control[0] = GIRBIL_57600;
158 break;
159 case 115200:
160 control[0] = GIRBIL_115200;
161 break;
163 control[1] = GIRBIL_LOAD;
165 /* Write control bytes */
166 sirdev_raw_write(dev, control, 2);
168 dev->speed = speed;
170 state = GIRBIL_STATE_WAIT_SPEED;
171 delay = 100;
172 break;
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 */
179 break;
181 default:
182 IRDA_ERROR("%s - undefined state %d\n", __func__, state);
183 ret = -EINVAL;
184 break;
186 dev->fsm.substate = state;
187 return (delay > 0) ? delay : ret;
191 * Function girbil_reset (driver)
193 * This function resets the girbil dongle.
195 * Algorithm:
196 * 0. set RTS, and wait at least 5 ms
197 * 1. clear RTS
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;
208 unsigned delay = 0;
209 u8 control = GIRBIL_TXEN | GIRBIL_RXEN;
210 int ret = 0;
212 IRDA_DEBUG(2, "%s()\n", __func__);
214 switch (state) {
215 case SIRDEV_STATE_DONGLE_RESET:
216 /* Reset dongle */
217 sirdev_set_dtr_rts(dev, TRUE, FALSE);
218 /* Sleep at least 5 ms */
219 delay = 20;
220 state = GIRBIL_STATE_WAIT1_RESET;
221 break;
223 case GIRBIL_STATE_WAIT1_RESET:
224 /* Set DTR and clear RTS to enter command mode */
225 sirdev_set_dtr_rts(dev, FALSE, TRUE);
226 delay = 20;
227 state = GIRBIL_STATE_WAIT2_RESET;
228 break;
230 case GIRBIL_STATE_WAIT2_RESET:
231 /* Write control byte */
232 sirdev_raw_write(dev, &control, 1);
233 delay = 20;
234 state = GIRBIL_STATE_WAIT3_RESET;
235 break;
237 case GIRBIL_STATE_WAIT3_RESET:
238 /* Go back to normal mode */
239 sirdev_set_dtr_rts(dev, TRUE, TRUE);
240 dev->speed = 9600;
241 break;
243 default:
244 IRDA_ERROR("%s(), undefined state %d\n", __func__, state);
245 ret = -1;
246 break;
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);