initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / net / irda / girbil.c
blobecac87df93f2b4d94e2ad2c0effdf2748af22719
1 /*********************************************************************
2 *
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/tty.h>
28 #include <linux/init.h>
30 #include <net/irda/irda.h>
31 #include <net/irda/irda_device.h>
33 static int girbil_reset(struct irda_task *task);
34 static void girbil_open(dongle_t *self, struct qos_info *qos);
35 static void girbil_close(dongle_t *self);
36 static int girbil_change_speed(struct irda_task *task);
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_reg dongle = {
66 .type = IRDA_GIRBIL_DONGLE,
67 .open = girbil_open,
68 .close = girbil_close,
69 .reset = girbil_reset,
70 .change_speed = girbil_change_speed,
71 .owner = THIS_MODULE,
74 static int __init girbil_init(void)
76 return irda_device_register_dongle(&dongle);
79 static void __exit girbil_cleanup(void)
81 irda_device_unregister_dongle(&dongle);
84 static void girbil_open(dongle_t *self, struct qos_info *qos)
86 qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
87 qos->min_turn_time.bits = 0x03;
90 static void girbil_close(dongle_t *self)
92 /* Power off dongle */
93 self->set_dtr_rts(self->dev, FALSE, FALSE);
97 * Function girbil_change_speed (dev, speed)
99 * Set the speed for the Girbil type dongle.
102 static int girbil_change_speed(struct irda_task *task)
104 dongle_t *self = (dongle_t *) task->instance;
105 __u32 speed = (__u32) task->param;
106 __u8 control[2];
107 int ret = 0;
109 self->speed_task = task;
111 switch (task->state) {
112 case IRDA_TASK_INIT:
113 /* Need to reset the dongle and go to 9600 bps before
114 programming */
115 if (irda_task_execute(self, girbil_reset, NULL, task,
116 (void *) speed))
118 /* Dongle need more time to reset */
119 irda_task_next_state(task, IRDA_TASK_CHILD_WAIT);
121 /* Give reset 1 sec to finish */
122 ret = msecs_to_jiffies(1000);
124 break;
125 case IRDA_TASK_CHILD_WAIT:
126 WARNING("%s(), resetting dongle timed out!\n", __FUNCTION__);
127 ret = -1;
128 break;
129 case IRDA_TASK_CHILD_DONE:
130 /* Set DTR and Clear RTS to enter command mode */
131 self->set_dtr_rts(self->dev, FALSE, TRUE);
133 switch (speed) {
134 case 9600:
135 default:
136 control[0] = GIRBIL_9600;
137 break;
138 case 19200:
139 control[0] = GIRBIL_19200;
140 break;
141 case 34800:
142 control[0] = GIRBIL_38400;
143 break;
144 case 57600:
145 control[0] = GIRBIL_57600;
146 break;
147 case 115200:
148 control[0] = GIRBIL_115200;
149 break;
151 control[1] = GIRBIL_LOAD;
153 /* Write control bytes */
154 self->write(self->dev, control, 2);
155 irda_task_next_state(task, IRDA_TASK_WAIT);
156 ret = msecs_to_jiffies(100);
157 break;
158 case IRDA_TASK_WAIT:
159 /* Go back to normal mode */
160 self->set_dtr_rts(self->dev, TRUE, TRUE);
161 irda_task_next_state(task, IRDA_TASK_DONE);
162 self->speed_task = NULL;
163 break;
164 default:
165 ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state);
166 irda_task_next_state(task, IRDA_TASK_DONE);
167 self->speed_task = NULL;
168 ret = -1;
169 break;
171 return ret;
175 * Function girbil_reset (driver)
177 * This function resets the girbil dongle.
179 * Algorithm:
180 * 0. set RTS, and wait at least 5 ms
181 * 1. clear RTS
183 static int girbil_reset(struct irda_task *task)
185 dongle_t *self = (dongle_t *) task->instance;
186 __u8 control = GIRBIL_TXEN | GIRBIL_RXEN;
187 int ret = 0;
189 self->reset_task = task;
191 switch (task->state) {
192 case IRDA_TASK_INIT:
193 /* Reset dongle */
194 self->set_dtr_rts(self->dev, TRUE, FALSE);
195 irda_task_next_state(task, IRDA_TASK_WAIT1);
196 /* Sleep at least 5 ms */
197 ret = msecs_to_jiffies(20);
198 break;
199 case IRDA_TASK_WAIT1:
200 /* Set DTR and clear RTS to enter command mode */
201 self->set_dtr_rts(self->dev, FALSE, TRUE);
202 irda_task_next_state(task, IRDA_TASK_WAIT2);
203 ret = msecs_to_jiffies(20);
204 break;
205 case IRDA_TASK_WAIT2:
206 /* Write control byte */
207 self->write(self->dev, &control, 1);
208 irda_task_next_state(task, IRDA_TASK_WAIT3);
209 ret = msecs_to_jiffies(20);
210 break;
211 case IRDA_TASK_WAIT3:
212 /* Go back to normal mode */
213 self->set_dtr_rts(self->dev, TRUE, TRUE);
214 irda_task_next_state(task, IRDA_TASK_DONE);
215 self->reset_task = NULL;
216 break;
217 default:
218 ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state);
219 irda_task_next_state(task, IRDA_TASK_DONE);
220 self->reset_task = NULL;
221 ret = -1;
222 break;
224 return ret;
227 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
228 MODULE_DESCRIPTION("Greenwich GIrBIL dongle driver");
229 MODULE_LICENSE("GPL");
230 MODULE_ALIAS("irda-dongle-4"); /* IRDA_GIRBIL_DONGLE */
233 * Function init_module (void)
235 * Initialize Girbil module
238 module_init(girbil_init);
241 * Function cleanup_module (void)
243 * Cleanup Girbil module
246 module_exit(girbil_cleanup);