diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/irda/act200l.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/net/irda/act200l.c')
-rw-r--r-- | drivers/net/irda/act200l.c | 297 |
1 files changed, 297 insertions, 0 deletions
diff --git a/drivers/net/irda/act200l.c b/drivers/net/irda/act200l.c new file mode 100644 index 000000000000..756cd44e857a --- /dev/null +++ b/drivers/net/irda/act200l.c | |||
@@ -0,0 +1,297 @@ | |||
1 | /********************************************************************* | ||
2 | * | ||
3 | * Filename: act200l.c | ||
4 | * Version: 0.8 | ||
5 | * Description: Implementation for the ACTiSYS ACT-IR200L dongle | ||
6 | * Status: Experimental. | ||
7 | * Author: SHIMIZU Takuya <tshimizu@ga2.so-net.ne.jp> | ||
8 | * Created at: Fri Aug 3 17:35:42 2001 | ||
9 | * Modified at: Fri Aug 17 10:22:40 2001 | ||
10 | * Modified by: SHIMIZU Takuya <tshimizu@ga2.so-net.ne.jp> | ||
11 | * | ||
12 | * Copyright (c) 2001 SHIMIZU Takuya, 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 | ********************************************************************/ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/tty.h> | ||
24 | #include <linux/init.h> | ||
25 | |||
26 | #include <net/irda/irda.h> | ||
27 | #include <net/irda/irda_device.h> | ||
28 | |||
29 | static int act200l_reset(struct irda_task *task); | ||
30 | static void act200l_open(dongle_t *self, struct qos_info *qos); | ||
31 | static void act200l_close(dongle_t *self); | ||
32 | static int act200l_change_speed(struct irda_task *task); | ||
33 | |||
34 | /* Regsiter 0: Control register #1 */ | ||
35 | #define ACT200L_REG0 0x00 | ||
36 | #define ACT200L_TXEN 0x01 /* Enable transmitter */ | ||
37 | #define ACT200L_RXEN 0x02 /* Enable receiver */ | ||
38 | |||
39 | /* Register 1: Control register #2 */ | ||
40 | #define ACT200L_REG1 0x10 | ||
41 | #define ACT200L_LODB 0x01 /* Load new baud rate count value */ | ||
42 | #define ACT200L_WIDE 0x04 /* Expand the maximum allowable pulse */ | ||
43 | |||
44 | /* Register 4: Output Power register */ | ||
45 | #define ACT200L_REG4 0x40 | ||
46 | #define ACT200L_OP0 0x01 /* Enable LED1C output */ | ||
47 | #define ACT200L_OP1 0x02 /* Enable LED2C output */ | ||
48 | #define ACT200L_BLKR 0x04 | ||
49 | |||
50 | /* Register 5: Receive Mode register */ | ||
51 | #define ACT200L_REG5 0x50 | ||
52 | #define ACT200L_RWIDL 0x01 /* fixed 1.6us pulse mode */ | ||
53 | |||
54 | /* Register 6: Receive Sensitivity register #1 */ | ||
55 | #define ACT200L_REG6 0x60 | ||
56 | #define ACT200L_RS0 0x01 /* receive threshold bit 0 */ | ||
57 | #define ACT200L_RS1 0x02 /* receive threshold bit 1 */ | ||
58 | |||
59 | /* Register 7: Receive Sensitivity register #2 */ | ||
60 | #define ACT200L_REG7 0x70 | ||
61 | #define ACT200L_ENPOS 0x04 /* Ignore the falling edge */ | ||
62 | |||
63 | /* Register 8,9: Baud Rate Dvider register #1,#2 */ | ||
64 | #define ACT200L_REG8 0x80 | ||
65 | #define ACT200L_REG9 0x90 | ||
66 | |||
67 | #define ACT200L_2400 0x5f | ||
68 | #define ACT200L_9600 0x17 | ||
69 | #define ACT200L_19200 0x0b | ||
70 | #define ACT200L_38400 0x05 | ||
71 | #define ACT200L_57600 0x03 | ||
72 | #define ACT200L_115200 0x01 | ||
73 | |||
74 | /* Register 13: Control register #3 */ | ||
75 | #define ACT200L_REG13 0xd0 | ||
76 | #define ACT200L_SHDW 0x01 /* Enable access to shadow registers */ | ||
77 | |||
78 | /* Register 15: Status register */ | ||
79 | #define ACT200L_REG15 0xf0 | ||
80 | |||
81 | /* Register 21: Control register #4 */ | ||
82 | #define ACT200L_REG21 0x50 | ||
83 | #define ACT200L_EXCK 0x02 /* Disable clock output driver */ | ||
84 | #define ACT200L_OSCL 0x04 /* oscillator in low power, medium accuracy mode */ | ||
85 | |||
86 | static struct dongle_reg dongle = { | ||
87 | .type = IRDA_ACT200L_DONGLE, | ||
88 | .open = act200l_open, | ||
89 | .close = act200l_close, | ||
90 | .reset = act200l_reset, | ||
91 | .change_speed = act200l_change_speed, | ||
92 | .owner = THIS_MODULE, | ||
93 | }; | ||
94 | |||
95 | static int __init act200l_init(void) | ||
96 | { | ||
97 | return irda_device_register_dongle(&dongle); | ||
98 | } | ||
99 | |||
100 | static void __exit act200l_cleanup(void) | ||
101 | { | ||
102 | irda_device_unregister_dongle(&dongle); | ||
103 | } | ||
104 | |||
105 | static void act200l_open(dongle_t *self, struct qos_info *qos) | ||
106 | { | ||
107 | IRDA_DEBUG(2, "%s()\n", __FUNCTION__ ); | ||
108 | |||
109 | /* Power on the dongle */ | ||
110 | self->set_dtr_rts(self->dev, TRUE, TRUE); | ||
111 | |||
112 | /* Set the speeds we can accept */ | ||
113 | qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200; | ||
114 | qos->min_turn_time.bits = 0x03; | ||
115 | } | ||
116 | |||
117 | static void act200l_close(dongle_t *self) | ||
118 | { | ||
119 | IRDA_DEBUG(2, "%s()\n", __FUNCTION__ ); | ||
120 | |||
121 | /* Power off the dongle */ | ||
122 | self->set_dtr_rts(self->dev, FALSE, FALSE); | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * Function act200l_change_speed (dev, speed) | ||
127 | * | ||
128 | * Set the speed for the ACTiSYS ACT-IR200L type dongle. | ||
129 | * | ||
130 | */ | ||
131 | static int act200l_change_speed(struct irda_task *task) | ||
132 | { | ||
133 | dongle_t *self = (dongle_t *) task->instance; | ||
134 | __u32 speed = (__u32) task->param; | ||
135 | __u8 control[3]; | ||
136 | int ret = 0; | ||
137 | |||
138 | IRDA_DEBUG(2, "%s()\n", __FUNCTION__ ); | ||
139 | |||
140 | self->speed_task = task; | ||
141 | |||
142 | switch (task->state) { | ||
143 | case IRDA_TASK_INIT: | ||
144 | if (irda_task_execute(self, act200l_reset, NULL, task, | ||
145 | (void *) speed)) | ||
146 | { | ||
147 | /* Dongle need more time to reset */ | ||
148 | irda_task_next_state(task, IRDA_TASK_CHILD_WAIT); | ||
149 | |||
150 | /* Give reset 1 sec to finish */ | ||
151 | ret = msecs_to_jiffies(1000); | ||
152 | } | ||
153 | break; | ||
154 | case IRDA_TASK_CHILD_WAIT: | ||
155 | IRDA_WARNING("%s(), resetting dongle timed out!\n", | ||
156 | __FUNCTION__); | ||
157 | ret = -1; | ||
158 | break; | ||
159 | case IRDA_TASK_CHILD_DONE: | ||
160 | /* Clear DTR and set RTS to enter command mode */ | ||
161 | self->set_dtr_rts(self->dev, FALSE, TRUE); | ||
162 | |||
163 | switch (speed) { | ||
164 | case 9600: | ||
165 | default: | ||
166 | control[0] = ACT200L_REG8 | (ACT200L_9600 & 0x0f); | ||
167 | control[1] = ACT200L_REG9 | ((ACT200L_9600 >> 4) & 0x0f); | ||
168 | break; | ||
169 | case 19200: | ||
170 | control[0] = ACT200L_REG8 | (ACT200L_19200 & 0x0f); | ||
171 | control[1] = ACT200L_REG9 | ((ACT200L_19200 >> 4) & 0x0f); | ||
172 | break; | ||
173 | case 38400: | ||
174 | control[0] = ACT200L_REG8 | (ACT200L_38400 & 0x0f); | ||
175 | control[1] = ACT200L_REG9 | ((ACT200L_38400 >> 4) & 0x0f); | ||
176 | break; | ||
177 | case 57600: | ||
178 | control[0] = ACT200L_REG8 | (ACT200L_57600 & 0x0f); | ||
179 | control[1] = ACT200L_REG9 | ((ACT200L_57600 >> 4) & 0x0f); | ||
180 | break; | ||
181 | case 115200: | ||
182 | control[0] = ACT200L_REG8 | (ACT200L_115200 & 0x0f); | ||
183 | control[1] = ACT200L_REG9 | ((ACT200L_115200 >> 4) & 0x0f); | ||
184 | break; | ||
185 | } | ||
186 | control[2] = ACT200L_REG1 | ACT200L_LODB | ACT200L_WIDE; | ||
187 | |||
188 | /* Write control bytes */ | ||
189 | self->write(self->dev, control, 3); | ||
190 | irda_task_next_state(task, IRDA_TASK_WAIT); | ||
191 | ret = msecs_to_jiffies(5); | ||
192 | break; | ||
193 | case IRDA_TASK_WAIT: | ||
194 | /* Go back to normal mode */ | ||
195 | self->set_dtr_rts(self->dev, TRUE, TRUE); | ||
196 | |||
197 | irda_task_next_state(task, IRDA_TASK_DONE); | ||
198 | self->speed_task = NULL; | ||
199 | break; | ||
200 | default: | ||
201 | IRDA_ERROR("%s(), unknown state %d\n", | ||
202 | __FUNCTION__, task->state); | ||
203 | irda_task_next_state(task, IRDA_TASK_DONE); | ||
204 | self->speed_task = NULL; | ||
205 | ret = -1; | ||
206 | break; | ||
207 | } | ||
208 | return ret; | ||
209 | } | ||
210 | |||
211 | /* | ||
212 | * Function act200l_reset (driver) | ||
213 | * | ||
214 | * Reset the ACTiSYS ACT-IR200L type dongle. | ||
215 | */ | ||
216 | static int act200l_reset(struct irda_task *task) | ||
217 | { | ||
218 | dongle_t *self = (dongle_t *) task->instance; | ||
219 | __u8 control[9] = { | ||
220 | ACT200L_REG15, | ||
221 | ACT200L_REG13 | ACT200L_SHDW, | ||
222 | ACT200L_REG21 | ACT200L_EXCK | ACT200L_OSCL, | ||
223 | ACT200L_REG13, | ||
224 | ACT200L_REG7 | ACT200L_ENPOS, | ||
225 | ACT200L_REG6 | ACT200L_RS0 | ACT200L_RS1, | ||
226 | ACT200L_REG5 | ACT200L_RWIDL, | ||
227 | ACT200L_REG4 | ACT200L_OP0 | ACT200L_OP1 | ACT200L_BLKR, | ||
228 | ACT200L_REG0 | ACT200L_TXEN | ACT200L_RXEN | ||
229 | }; | ||
230 | int ret = 0; | ||
231 | |||
232 | IRDA_DEBUG(2, "%s()\n", __FUNCTION__ ); | ||
233 | |||
234 | self->reset_task = task; | ||
235 | |||
236 | switch (task->state) { | ||
237 | case IRDA_TASK_INIT: | ||
238 | /* Power on the dongle */ | ||
239 | self->set_dtr_rts(self->dev, TRUE, TRUE); | ||
240 | |||
241 | irda_task_next_state(task, IRDA_TASK_WAIT1); | ||
242 | ret = msecs_to_jiffies(50); | ||
243 | break; | ||
244 | case IRDA_TASK_WAIT1: | ||
245 | /* Reset the dongle : set RTS low for 25 ms */ | ||
246 | self->set_dtr_rts(self->dev, TRUE, FALSE); | ||
247 | |||
248 | irda_task_next_state(task, IRDA_TASK_WAIT2); | ||
249 | ret = msecs_to_jiffies(50); | ||
250 | break; | ||
251 | case IRDA_TASK_WAIT2: | ||
252 | /* Clear DTR and set RTS to enter command mode */ | ||
253 | self->set_dtr_rts(self->dev, FALSE, TRUE); | ||
254 | |||
255 | /* Write control bytes */ | ||
256 | self->write(self->dev, control, 9); | ||
257 | irda_task_next_state(task, IRDA_TASK_WAIT3); | ||
258 | ret = msecs_to_jiffies(15); | ||
259 | break; | ||
260 | case IRDA_TASK_WAIT3: | ||
261 | /* Go back to normal mode */ | ||
262 | self->set_dtr_rts(self->dev, TRUE, TRUE); | ||
263 | |||
264 | irda_task_next_state(task, IRDA_TASK_DONE); | ||
265 | self->reset_task = NULL; | ||
266 | break; | ||
267 | default: | ||
268 | IRDA_ERROR("%s(), unknown state %d\n", | ||
269 | __FUNCTION__, task->state); | ||
270 | irda_task_next_state(task, IRDA_TASK_DONE); | ||
271 | self->reset_task = NULL; | ||
272 | ret = -1; | ||
273 | break; | ||
274 | } | ||
275 | return ret; | ||
276 | } | ||
277 | |||
278 | MODULE_AUTHOR("SHIMIZU Takuya <tshimizu@ga2.so-net.ne.jp>"); | ||
279 | MODULE_DESCRIPTION("ACTiSYS ACT-IR200L dongle driver"); | ||
280 | MODULE_LICENSE("GPL"); | ||
281 | MODULE_ALIAS("irda-dongle-10"); /* IRDA_ACT200L_DONGLE */ | ||
282 | |||
283 | /* | ||
284 | * Function init_module (void) | ||
285 | * | ||
286 | * Initialize ACTiSYS ACT-IR200L module | ||
287 | * | ||
288 | */ | ||
289 | module_init(act200l_init); | ||
290 | |||
291 | /* | ||
292 | * Function cleanup_module (void) | ||
293 | * | ||
294 | * Cleanup ACTiSYS ACT-IR200L module | ||
295 | * | ||
296 | */ | ||
297 | module_exit(act200l_cleanup); | ||