1 /*********************************************************************
5 * Description: Implementation of the MA600 dongle
6 * Status: Experimental.
7 * Author: Leung <95Etwl@alumni.ee.ust.hk> http://www.engsvr.ust/~eetwl95
8 * Created at: Sat Jun 10 20:02:35 2000
12 * Note: very thanks to Mr. Maru Wang <maru@mobileaction.com.tw> for providing
13 * information on the MA600 dongle
15 * Copyright (c) 2000 Leung, All Rights Reserved.
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 ********************************************************************/
34 /* define this macro for release version */
37 #include <linux/module.h>
38 #include <linux/delay.h>
39 #include <linux/tty.h>
40 #include <linux/init.h>
42 #include <net/irda/irda.h>
43 #include <net/irda/irda_device.h>
47 #define IRDA_DEBUG(n, args...) (printk(KERN_DEBUG args))
50 #define ASSERT(expr, func) \
52 printk( "Assertion failed! %s,%s,%s,line=%d\n",\
53 #expr,__FILE__,__FUNCTION__,__LINE__); \
57 /* convert hex value to ascii hex */
58 static const char hexTbl[] = "0123456789ABCDEF";
61 static void ma600_open(dongle_t *self, struct qos_info *qos);
62 static void ma600_close(dongle_t *self);
63 static int ma600_change_speed(struct irda_task *task);
64 static int ma600_reset(struct irda_task *task);
66 /* control byte for MA600 */
67 #define MA600_9600 0x00
68 #define MA600_19200 0x01
69 #define MA600_38400 0x02
70 #define MA600_57600 0x03
71 #define MA600_115200 0x04
72 #define MA600_DEV_ID1 0x05
73 #define MA600_DEV_ID2 0x06
74 #define MA600_2400 0x08
76 static struct dongle_reg dongle = {
77 .type = IRDA_MA600_DONGLE,
81 .change_speed = ma600_change_speed,
85 static int __init ma600_init(void)
87 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
88 return irda_device_register_dongle(&dongle);
91 static void __exit ma600_cleanup(void)
93 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
94 irda_device_unregister_dongle(&dongle);
99 (0) Clear RTS and DTR for 1 second
100 (1) Set RTS and DTR for 1 second
102 Note: assume RTS, DTR are clear before
104 static void ma600_open(dongle_t *self, struct qos_info *qos)
106 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
108 qos->baud_rate.bits &= IR_2400|IR_9600|IR_19200|IR_38400
110 qos->min_turn_time.bits = 0x01; /* Needs at least 1 ms */
111 irda_qos_bits_to_value(qos);
113 //self->set_dtr_rts(self->dev, FALSE, FALSE);
114 // should wait 1 second
116 self->set_dtr_rts(self->dev, TRUE, TRUE);
117 // should wait 1 second
120 static void ma600_close(dongle_t *self)
122 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
124 /* Power off dongle */
125 self->set_dtr_rts(self->dev, FALSE, FALSE);
128 static __u8 get_control_byte(__u32 speed)
158 * Function ma600_change_speed (dev, state, speed)
160 * Set the speed for the MA600 type dongle. Warning, this
161 * function must be called with a process context!
165 * 2. clear RTS, set DTR and wait for 1ms
166 * 3. send Control Byte to the MA600 through TXD to set new baud rate
167 * wait until the stop bit of Control Byte is sent (for 9600 baud rate,
168 * it takes about 10 msec)
169 * 4. set RTS, set DTR (return to NORMAL Operation)
170 * 5. wait at least 10 ms, new setting (baud rate, etc) takes effect here
173 static int ma600_change_speed(struct irda_task *task)
175 dongle_t *self = (dongle_t *) task->instance;
176 __u32 speed = (__u32) task->param;
181 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
183 ASSERT(task != NULL, return -1;);
185 if (self->speed_task && self->speed_task != task) {
186 IRDA_DEBUG(0, "%s(), busy!\n", __FUNCTION__);
187 return msecs_to_jiffies(10);
189 self->speed_task = task;
192 switch (task->state) {
194 case IRDA_TASK_CHILD_INIT:
196 * Need to reset the dongle and go to 9600 bps before
199 if (irda_task_execute(self, ma600_reset, NULL, task,
201 /* Dongle need more time to reset */
202 irda_task_next_state(task, IRDA_TASK_CHILD_WAIT);
204 /* give 1 second to finish */
205 ret = msecs_to_jiffies(1000);
207 irda_task_next_state(task, IRDA_TASK_CHILD_DONE);
211 case IRDA_TASK_CHILD_WAIT:
212 WARNING("%s(), resetting dongle timed out!\n", __FUNCTION__);
216 case IRDA_TASK_CHILD_DONE:
217 /* Set DTR, Clear RTS */
218 self->set_dtr_rts(self->dev, TRUE, FALSE);
220 ret = msecs_to_jiffies(1); /* Sleep 1 ms */
221 irda_task_next_state(task, IRDA_TASK_WAIT);
225 speed = (__u32) task->param;
226 byte = get_control_byte(speed);
228 /* Write control byte */
229 self->write(self->dev, &byte, sizeof(byte));
231 irda_task_next_state(task, IRDA_TASK_WAIT1);
233 /* Wait at least 10 ms */
234 ret = msecs_to_jiffies(15);
237 case IRDA_TASK_WAIT1:
238 /* Read control byte echo */
239 self->read(self->dev, &byte_echo, sizeof(byte_echo));
241 if(byte != byte_echo) {
242 /* if control byte != echo, I don't know what to do */
243 printk(KERN_WARNING "%s() control byte written != read!\n", __FUNCTION__);
244 printk(KERN_WARNING "control byte = 0x%c%c\n",
245 hexTbl[(byte>>4)&0x0f], hexTbl[byte&0x0f]);
246 printk(KERN_WARNING "byte echo = 0x%c%c\n",
247 hexTbl[(byte_echo>>4) & 0x0f],
248 hexTbl[byte_echo & 0x0f]);
251 IRDA_DEBUG(2, "%s() control byte write read OK\n", __FUNCTION__);
255 /* Set DTR, Set RTS */
256 self->set_dtr_rts(self->dev, TRUE, TRUE);
258 irda_task_next_state(task, IRDA_TASK_WAIT2);
260 /* Wait at least 10 ms */
261 ret = msecs_to_jiffies(10);
264 case IRDA_TASK_WAIT2:
265 irda_task_next_state(task, IRDA_TASK_DONE);
266 self->speed_task = NULL;
270 ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state);
271 irda_task_next_state(task, IRDA_TASK_DONE);
272 self->speed_task = NULL;
280 * Function ma600_reset (driver)
282 * This function resets the ma600 dongle. Warning, this function
283 * must be called with a process context!!
286 * 0. DTR=0, RTS=1 and wait 10 ms
287 * 1. DTR=1, RTS=1 and wait 10 ms
290 int ma600_reset(struct irda_task *task)
292 dongle_t *self = (dongle_t *) task->instance;
295 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
297 ASSERT(task != NULL, return -1;);
299 if (self->reset_task && self->reset_task != task) {
300 IRDA_DEBUG(0, "%s(), busy!\n", __FUNCTION__);
301 return msecs_to_jiffies(10);
303 self->reset_task = task;
305 switch (task->state) {
307 /* Clear DTR and Set RTS */
308 self->set_dtr_rts(self->dev, FALSE, TRUE);
309 irda_task_next_state(task, IRDA_TASK_WAIT1);
310 ret = msecs_to_jiffies(10); /* Sleep 10 ms */
312 case IRDA_TASK_WAIT1:
313 /* Set DTR and RTS */
314 self->set_dtr_rts(self->dev, TRUE, TRUE);
315 irda_task_next_state(task, IRDA_TASK_WAIT2);
316 ret = msecs_to_jiffies(10); /* Sleep 10 ms */
318 case IRDA_TASK_WAIT2:
319 irda_task_next_state(task, IRDA_TASK_DONE);
320 self->reset_task = NULL;
323 ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state);
324 irda_task_next_state(task, IRDA_TASK_DONE);
325 self->reset_task = NULL;
331 MODULE_AUTHOR("Leung <95Etwl@alumni.ee.ust.hk> http://www.engsvr.ust/~eetwl95");
332 MODULE_DESCRIPTION("MA600 dongle driver version 0.1");
333 MODULE_LICENSE("GPL");
334 MODULE_ALIAS("irda-dongle-11"); /* IRDA_MA600_DONGLE */
337 * Function init_module (void)
339 * Initialize MA600 module
342 module_init(ma600_init);
345 * Function cleanup_module (void)
347 * Cleanup MA600 module
350 module_exit(ma600_cleanup);