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
9 * Modified at: Sat Aug 16 09:34:13 2003
10 * Modified by: Martin Diehl <mad@mdiehl.de> (modified for new sir_dev)
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, see <http://www.gnu.org/licenses/>.
30 ********************************************************************/
32 #include <linux/module.h>
33 #include <linux/delay.h>
34 #include <linux/init.h>
36 #include <net/irda/irda.h>
40 static int ma600_open(struct sir_dev
*);
41 static int ma600_close(struct sir_dev
*);
42 static int ma600_change_speed(struct sir_dev
*, unsigned);
43 static int ma600_reset(struct sir_dev
*);
45 /* control byte for MA600 */
46 #define MA600_9600 0x00
47 #define MA600_19200 0x01
48 #define MA600_38400 0x02
49 #define MA600_57600 0x03
50 #define MA600_115200 0x04
51 #define MA600_DEV_ID1 0x05
52 #define MA600_DEV_ID2 0x06
53 #define MA600_2400 0x08
55 static struct dongle_driver ma600
= {
57 .driver_name
= "MA600",
58 .type
= IRDA_MA600_DONGLE
,
62 .set_speed
= ma600_change_speed
,
66 static int __init
ma600_sir_init(void)
68 return irda_register_dongle(&ma600
);
71 static void __exit
ma600_sir_cleanup(void)
73 irda_unregister_dongle(&ma600
);
78 (0) Clear RTS and DTR for 1 second
79 (1) Set RTS and DTR for 1 second
81 Note: assume RTS, DTR are clear before
83 static int ma600_open(struct sir_dev
*dev
)
85 struct qos_info
*qos
= &dev
->qos
;
87 sirdev_set_dtr_rts(dev
, TRUE
, TRUE
);
89 /* Explicitly set the speeds we can accept */
90 qos
->baud_rate
.bits
&= IR_2400
|IR_9600
|IR_19200
|IR_38400
92 /* Hm, 0x01 means 10ms - for >= 1ms we would need 0x07 */
93 qos
->min_turn_time
.bits
= 0x01; /* Needs at least 1 ms */
94 irda_qos_bits_to_value(qos
);
96 /* irda thread waits 50 msec for power settling */
101 static int ma600_close(struct sir_dev
*dev
)
103 /* Power off dongle */
104 sirdev_set_dtr_rts(dev
, FALSE
, FALSE
);
109 static __u8
get_control_byte(__u32 speed
)
139 * Function ma600_change_speed (dev, speed)
141 * Set the speed for the MA600 type dongle.
143 * The dongle has already been reset to a known state (dongle default)
144 * We cycle through speeds by pulsing RTS low and then high.
148 * Function ma600_change_speed (dev, speed)
150 * Set the speed for the MA600 type dongle.
153 * 1. Reset (already done by irda thread state machine)
154 * 2. clear RTS, set DTR and wait for 1ms
155 * 3. send Control Byte to the MA600 through TXD to set new baud rate
156 * wait until the stop bit of Control Byte is sent (for 9600 baud rate,
157 * it takes about 10 msec)
158 * 4. set RTS, set DTR (return to NORMAL Operation)
159 * 5. wait at least 10 ms, new setting (baud rate, etc) takes effect here
163 /* total delays are only about 20ms - let's just sleep for now to
164 * avoid the state machine complexity before we get things working
167 static int ma600_change_speed(struct sir_dev
*dev
, unsigned speed
)
171 pr_debug("%s(), speed=%d (was %d)\n", __func__
,
174 /* dongle already reset, dongle and port at default speed (9600) */
176 /* Set RTS low for 1 ms */
177 sirdev_set_dtr_rts(dev
, TRUE
, FALSE
);
180 /* Write control byte */
181 byte
= get_control_byte(speed
);
182 sirdev_raw_write(dev
, &byte
, sizeof(byte
));
184 /* Wait at least 10ms: fake wait_until_sent - 10 bits at 9600 baud*/
185 msleep(15); /* old ma600 uses 15ms */
188 /* read-back of the control byte. ma600 is the first dongle driver
189 * which uses this so there might be some unidentified issues.
190 * Disable this in case of problems with readback.
193 sirdev_raw_read(dev
, &byte
, sizeof(byte
));
194 if (byte
!= get_control_byte(speed
)) {
195 net_warn_ratelimited("%s(): bad control byte read-back %02x != %02x\n",
196 __func__
, (unsigned)byte
,
197 (unsigned)get_control_byte(speed
));
201 pr_debug("%s() control byte write read OK\n", __func__
);
204 /* Set DTR, Set RTS */
205 sirdev_set_dtr_rts(dev
, TRUE
, TRUE
);
207 /* Wait at least 10ms */
210 /* dongle is now switched to the new speed */
217 * Function ma600_reset (dev)
219 * This function resets the ma600 dongle.
222 * 0. DTR=0, RTS=1 and wait 10 ms
223 * 1. DTR=1, RTS=1 and wait 10 ms
227 /* total delays are only about 20ms - let's just sleep for now to
228 * avoid the state machine complexity before we get things working
231 static int ma600_reset(struct sir_dev
*dev
)
233 /* Reset the dongle : set DTR low for 10 ms */
234 sirdev_set_dtr_rts(dev
, FALSE
, TRUE
);
237 /* Go back to normal mode */
238 sirdev_set_dtr_rts(dev
, TRUE
, TRUE
);
241 dev
->speed
= 9600; /* That's the dongle-default */
246 MODULE_AUTHOR("Leung <95Etwl@alumni.ee.ust.hk> http://www.engsvr.ust/~eetwl95");
247 MODULE_DESCRIPTION("MA600 dongle driver version 0.1");
248 MODULE_LICENSE("GPL");
249 MODULE_ALIAS("irda-dongle-11"); /* IRDA_MA600_DONGLE */
251 module_init(ma600_sir_init
);
252 module_exit(ma600_sir_cleanup
);