Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | |
e8478de3 | 25 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
1da177e4 LT |
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 | ||
47 | static int litelink_open(struct sir_dev *dev); | |
48 | static int litelink_close(struct sir_dev *dev); | |
49 | static int litelink_change_speed(struct sir_dev *dev, unsigned speed); | |
50 | static int litelink_reset(struct sir_dev *dev); | |
51 | ||
52 | /* These are the baudrates supported - 9600 must be last one! */ | |
53 | static unsigned baud_rates[] = { 115200, 57600, 38400, 19200, 9600 }; | |
54 | ||
55 | static 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 | ||
65 | static int __init litelink_sir_init(void) | |
66 | { | |
67 | return irda_register_dongle(&litelink); | |
68 | } | |
69 | ||
70 | static void __exit litelink_sir_cleanup(void) | |
71 | { | |
72 | irda_unregister_dongle(&litelink); | |
73 | } | |
74 | ||
75 | static int litelink_open(struct sir_dev *dev) | |
76 | { | |
77 | struct qos_info *qos = &dev->qos; | |
78 | ||
a97a6f10 | 79 | IRDA_DEBUG(2, "%s()\n", __func__); |
1da177e4 LT |
80 | |
81 | /* Power up dongle */ | |
82 | sirdev_set_dtr_rts(dev, TRUE, TRUE); | |
83 | ||
84 | /* Set the speeds we can accept */ | |
85 | qos->baud_rate.bits &= IR_115200|IR_57600|IR_38400|IR_19200|IR_9600; | |
86 | qos->min_turn_time.bits = 0x7f; /* Needs 0.01 ms */ | |
87 | irda_qos_bits_to_value(qos); | |
88 | ||
89 | /* irda thread waits 50 msec for power settling */ | |
90 | ||
91 | return 0; | |
92 | } | |
93 | ||
94 | static int litelink_close(struct sir_dev *dev) | |
95 | { | |
a97a6f10 | 96 | IRDA_DEBUG(2, "%s()\n", __func__); |
1da177e4 LT |
97 | |
98 | /* Power off dongle */ | |
99 | sirdev_set_dtr_rts(dev, FALSE, FALSE); | |
100 | ||
101 | return 0; | |
102 | } | |
103 | ||
104 | /* | |
105 | * Function litelink_change_speed (task) | |
106 | * | |
107 | * Change speed of the Litelink dongle. To cycle through the available | |
108 | * baud rates, pulse RTS low for a few ms. | |
109 | */ | |
110 | static int litelink_change_speed(struct sir_dev *dev, unsigned speed) | |
111 | { | |
112 | int i; | |
113 | ||
a97a6f10 | 114 | IRDA_DEBUG(2, "%s()\n", __func__); |
1da177e4 LT |
115 | |
116 | /* dongle already reset by irda-thread - current speed (dongle and | |
117 | * port) is the default speed (115200 for litelink!) | |
118 | */ | |
119 | ||
120 | /* Cycle through avaiable baudrates until we reach the correct one */ | |
121 | for (i = 0; baud_rates[i] != speed; i++) { | |
122 | ||
123 | /* end-of-list reached due to invalid speed request */ | |
124 | if (baud_rates[i] == 9600) | |
125 | break; | |
126 | ||
127 | /* Set DTR, clear RTS */ | |
128 | sirdev_set_dtr_rts(dev, FALSE, TRUE); | |
129 | ||
130 | /* Sleep a minimum of 15 us */ | |
131 | udelay(MIN_DELAY); | |
132 | ||
133 | /* Set DTR, Set RTS */ | |
134 | sirdev_set_dtr_rts(dev, TRUE, TRUE); | |
135 | ||
136 | /* Sleep a minimum of 15 us */ | |
137 | udelay(MIN_DELAY); | |
138 | } | |
139 | ||
140 | dev->speed = baud_rates[i]; | |
141 | ||
142 | /* invalid baudrate should not happen - but if, we return -EINVAL and | |
143 | * the dongle configured for 9600 so the stack has a chance to recover | |
144 | */ | |
145 | ||
146 | return (dev->speed == speed) ? 0 : -EINVAL; | |
147 | } | |
148 | ||
149 | /* | |
150 | * Function litelink_reset (task) | |
151 | * | |
152 | * Reset the Litelink type dongle. | |
153 | * | |
154 | */ | |
155 | static int litelink_reset(struct sir_dev *dev) | |
156 | { | |
a97a6f10 | 157 | IRDA_DEBUG(2, "%s()\n", __func__); |
1da177e4 LT |
158 | |
159 | /* probably the power-up can be dropped here, but with only | |
160 | * 15 usec delay it's not worth the risk unless somebody with | |
161 | * the hardware confirms it doesn't break anything... | |
162 | */ | |
163 | ||
164 | /* Power on dongle */ | |
165 | sirdev_set_dtr_rts(dev, TRUE, TRUE); | |
166 | ||
167 | /* Sleep a minimum of 15 us */ | |
168 | udelay(MIN_DELAY); | |
169 | ||
170 | /* Clear RTS to reset dongle */ | |
171 | sirdev_set_dtr_rts(dev, TRUE, FALSE); | |
172 | ||
173 | /* Sleep a minimum of 15 us */ | |
174 | udelay(MIN_DELAY); | |
175 | ||
176 | /* Go back to normal mode */ | |
177 | sirdev_set_dtr_rts(dev, TRUE, TRUE); | |
178 | ||
179 | /* Sleep a minimum of 15 us */ | |
180 | udelay(MIN_DELAY); | |
181 | ||
182 | /* This dongles speed defaults to 115200 bps */ | |
183 | dev->speed = 115200; | |
184 | ||
185 | return 0; | |
186 | } | |
187 | ||
188 | MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>"); | |
189 | MODULE_DESCRIPTION("Parallax Litelink dongle driver"); | |
190 | MODULE_LICENSE("GPL"); | |
191 | MODULE_ALIAS("irda-dongle-5"); /* IRDA_LITELINK_DONGLE */ | |
192 | ||
193 | /* | |
194 | * Function init_module (void) | |
195 | * | |
196 | * Initialize Litelink module | |
197 | * | |
198 | */ | |
199 | module_init(litelink_sir_init); | |
200 | ||
201 | /* | |
202 | * Function cleanup_module (void) | |
203 | * | |
204 | * Cleanup Litelink module | |
205 | * | |
206 | */ | |
207 | module_exit(litelink_sir_cleanup); |