Loading...
1/*********************************************************************
2 *
3 * Filename: litelink.c
4 * Version: 1.1
5 * Description: Driver for the Parallax LiteLink dongle
6 * Status: Stable
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Fri May 7 12:50:33 1999
9 * Modified at: Fri Dec 17 09:14:23 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 *
12 * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
13 *
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.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 *
29 ********************************************************************/
30
31/*
32 * Modified at: Thu Jan 15 2003
33 * Modified by: Eugene Crosser <crosser@average.org>
34 *
35 * Convert to "new" IRDA infrastructure for kernel 2.6
36 */
37
38#include <linux/module.h>
39#include <linux/delay.h>
40#include <linux/init.h>
41
42#include <net/irda/irda.h>
43
44#include "sir-dev.h"
45
46#define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
47#define MAX_DELAY 10000 /* 1 ms */
48
49static int litelink_open(struct sir_dev *dev);
50static int litelink_close(struct sir_dev *dev);
51static int litelink_change_speed(struct sir_dev *dev, unsigned speed);
52static int litelink_reset(struct sir_dev *dev);
53
54/* These are the baudrates supported - 9600 must be last one! */
55static unsigned baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
56
57static struct dongle_driver litelink = {
58 .owner = THIS_MODULE,
59 .driver_name = "Parallax LiteLink",
60 .type = IRDA_LITELINK_DONGLE,
61 .open = litelink_open,
62 .close = litelink_close,
63 .reset = litelink_reset,
64 .set_speed = litelink_change_speed,
65};
66
67static int __init litelink_sir_init(void)
68{
69 return irda_register_dongle(&litelink);
70}
71
72static void __exit litelink_sir_cleanup(void)
73{
74 irda_unregister_dongle(&litelink);
75}
76
77static int litelink_open(struct sir_dev *dev)
78{
79 struct qos_info *qos = &dev->qos;
80
81 IRDA_DEBUG(2, "%s()\n", __func__);
82
83 /* Power up dongle */
84 sirdev_set_dtr_rts(dev, TRUE, TRUE);
85
86 /* Set the speeds we can accept */
87 qos->baud_rate.bits &= IR_115200|IR_57600|IR_38400|IR_19200|IR_9600;
88 qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
89 irda_qos_bits_to_value(qos);
90
91 /* irda thread waits 50 msec for power settling */
92
93 return 0;
94}
95
96static int litelink_close(struct sir_dev *dev)
97{
98 IRDA_DEBUG(2, "%s()\n", __func__);
99
100 /* Power off dongle */
101 sirdev_set_dtr_rts(dev, FALSE, FALSE);
102
103 return 0;
104}
105
106/*
107 * Function litelink_change_speed (task)
108 *
109 * Change speed of the Litelink dongle. To cycle through the available
110 * baud rates, pulse RTS low for a few ms.
111 */
112static int litelink_change_speed(struct sir_dev *dev, unsigned speed)
113{
114 int i;
115
116 IRDA_DEBUG(2, "%s()\n", __func__);
117
118 /* dongle already reset by irda-thread - current speed (dongle and
119 * port) is the default speed (115200 for litelink!)
120 */
121
122 /* Cycle through avaiable baudrates until we reach the correct one */
123 for (i = 0; baud_rates[i] != speed; i++) {
124
125 /* end-of-list reached due to invalid speed request */
126 if (baud_rates[i] == 9600)
127 break;
128
129 /* Set DTR, clear RTS */
130 sirdev_set_dtr_rts(dev, FALSE, TRUE);
131
132 /* Sleep a minimum of 15 us */
133 udelay(MIN_DELAY);
134
135 /* Set DTR, Set RTS */
136 sirdev_set_dtr_rts(dev, TRUE, TRUE);
137
138 /* Sleep a minimum of 15 us */
139 udelay(MIN_DELAY);
140 }
141
142 dev->speed = baud_rates[i];
143
144 /* invalid baudrate should not happen - but if, we return -EINVAL and
145 * the dongle configured for 9600 so the stack has a chance to recover
146 */
147
148 return (dev->speed == speed) ? 0 : -EINVAL;
149}
150
151/*
152 * Function litelink_reset (task)
153 *
154 * Reset the Litelink type dongle.
155 *
156 */
157static int litelink_reset(struct sir_dev *dev)
158{
159 IRDA_DEBUG(2, "%s()\n", __func__);
160
161 /* probably the power-up can be dropped here, but with only
162 * 15 usec delay it's not worth the risk unless somebody with
163 * the hardware confirms it doesn't break anything...
164 */
165
166 /* Power on dongle */
167 sirdev_set_dtr_rts(dev, TRUE, TRUE);
168
169 /* Sleep a minimum of 15 us */
170 udelay(MIN_DELAY);
171
172 /* Clear RTS to reset dongle */
173 sirdev_set_dtr_rts(dev, TRUE, FALSE);
174
175 /* Sleep a minimum of 15 us */
176 udelay(MIN_DELAY);
177
178 /* Go back to normal mode */
179 sirdev_set_dtr_rts(dev, TRUE, TRUE);
180
181 /* Sleep a minimum of 15 us */
182 udelay(MIN_DELAY);
183
184 /* This dongles speed defaults to 115200 bps */
185 dev->speed = 115200;
186
187 return 0;
188}
189
190MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
191MODULE_DESCRIPTION("Parallax Litelink dongle driver");
192MODULE_LICENSE("GPL");
193MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */
194
195/*
196 * Function init_module (void)
197 *
198 * Initialize Litelink module
199 *
200 */
201module_init(litelink_sir_init);
202
203/*
204 * Function cleanup_module (void)
205 *
206 * Cleanup Litelink module
207 *
208 */
209module_exit(litelink_sir_cleanup);
1/*********************************************************************
2 *
3 * Filename: litelink.c
4 * Version: 1.1
5 * Description: Driver for the Parallax LiteLink dongle
6 * Status: Stable
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Fri May 7 12:50:33 1999
9 * Modified at: Fri Dec 17 09:14:23 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 *
12 * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
13 *
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.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 *
27 ********************************************************************/
28
29/*
30 * Modified at: Thu Jan 15 2003
31 * Modified by: Eugene Crosser <crosser@average.org>
32 *
33 * Convert to "new" IRDA infrastructure for kernel 2.6
34 */
35
36#include <linux/module.h>
37#include <linux/delay.h>
38#include <linux/init.h>
39
40#include <net/irda/irda.h>
41
42#include "sir-dev.h"
43
44#define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
45#define MAX_DELAY 10000 /* 1 ms */
46
47static int litelink_open(struct sir_dev *dev);
48static int litelink_close(struct sir_dev *dev);
49static int litelink_change_speed(struct sir_dev *dev, unsigned speed);
50static int litelink_reset(struct sir_dev *dev);
51
52/* These are the baudrates supported - 9600 must be last one! */
53static unsigned baud_rates[] = { 115200, 57600, 38400, 19200, 9600 };
54
55static struct dongle_driver litelink = {
56 .owner = THIS_MODULE,
57 .driver_name = "Parallax LiteLink",
58 .type = IRDA_LITELINK_DONGLE,
59 .open = litelink_open,
60 .close = litelink_close,
61 .reset = litelink_reset,
62 .set_speed = litelink_change_speed,
63};
64
65static int __init litelink_sir_init(void)
66{
67 return irda_register_dongle(&litelink);
68}
69
70static void __exit litelink_sir_cleanup(void)
71{
72 irda_unregister_dongle(&litelink);
73}
74
75static int litelink_open(struct sir_dev *dev)
76{
77 struct qos_info *qos = &dev->qos;
78
79 /* Power up dongle */
80 sirdev_set_dtr_rts(dev, TRUE, TRUE);
81
82 /* Set the speeds we can accept */
83 qos->baud_rate.bits &= IR_115200|IR_57600|IR_38400|IR_19200|IR_9600;
84 qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */
85 irda_qos_bits_to_value(qos);
86
87 /* irda thread waits 50 msec for power settling */
88
89 return 0;
90}
91
92static int litelink_close(struct sir_dev *dev)
93{
94 /* Power off dongle */
95 sirdev_set_dtr_rts(dev, FALSE, FALSE);
96
97 return 0;
98}
99
100/*
101 * Function litelink_change_speed (task)
102 *
103 * Change speed of the Litelink dongle. To cycle through the available
104 * baud rates, pulse RTS low for a few ms.
105 */
106static int litelink_change_speed(struct sir_dev *dev, unsigned speed)
107{
108 int i;
109
110 /* dongle already reset by irda-thread - current speed (dongle and
111 * port) is the default speed (115200 for litelink!)
112 */
113
114 /* Cycle through avaiable baudrates until we reach the correct one */
115 for (i = 0; baud_rates[i] != speed; i++) {
116
117 /* end-of-list reached due to invalid speed request */
118 if (baud_rates[i] == 9600)
119 break;
120
121 /* Set DTR, clear RTS */
122 sirdev_set_dtr_rts(dev, FALSE, TRUE);
123
124 /* Sleep a minimum of 15 us */
125 udelay(MIN_DELAY);
126
127 /* Set DTR, Set RTS */
128 sirdev_set_dtr_rts(dev, TRUE, TRUE);
129
130 /* Sleep a minimum of 15 us */
131 udelay(MIN_DELAY);
132 }
133
134 dev->speed = baud_rates[i];
135
136 /* invalid baudrate should not happen - but if, we return -EINVAL and
137 * the dongle configured for 9600 so the stack has a chance to recover
138 */
139
140 return (dev->speed == speed) ? 0 : -EINVAL;
141}
142
143/*
144 * Function litelink_reset (task)
145 *
146 * Reset the Litelink type dongle.
147 *
148 */
149static int litelink_reset(struct sir_dev *dev)
150{
151 /* probably the power-up can be dropped here, but with only
152 * 15 usec delay it's not worth the risk unless somebody with
153 * the hardware confirms it doesn't break anything...
154 */
155
156 /* Power on dongle */
157 sirdev_set_dtr_rts(dev, TRUE, TRUE);
158
159 /* Sleep a minimum of 15 us */
160 udelay(MIN_DELAY);
161
162 /* Clear RTS to reset dongle */
163 sirdev_set_dtr_rts(dev, TRUE, FALSE);
164
165 /* Sleep a minimum of 15 us */
166 udelay(MIN_DELAY);
167
168 /* Go back to normal mode */
169 sirdev_set_dtr_rts(dev, TRUE, TRUE);
170
171 /* Sleep a minimum of 15 us */
172 udelay(MIN_DELAY);
173
174 /* This dongles speed defaults to 115200 bps */
175 dev->speed = 115200;
176
177 return 0;
178}
179
180MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
181MODULE_DESCRIPTION("Parallax Litelink dongle driver");
182MODULE_LICENSE("GPL");
183MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */
184
185/*
186 * Function init_module (void)
187 *
188 * Initialize Litelink module
189 *
190 */
191module_init(litelink_sir_init);
192
193/*
194 * Function cleanup_module (void)
195 *
196 * Cleanup Litelink module
197 *
198 */
199module_exit(litelink_sir_cleanup);