irframe_tty.c revision 1.19 1 1.19 augustss /* $NetBSD: irframe_tty.c,v 1.19 2001/12/26 10:56:58 augustss Exp $ */
2 1.5 augustss
3 1.5 augustss /*
4 1.5 augustss * TODO
5 1.15 augustss * Test dongle code.
6 1.5 augustss */
7 1.1 augustss
8 1.1 augustss /*
9 1.1 augustss * Copyright (c) 2001 The NetBSD Foundation, Inc.
10 1.1 augustss * All rights reserved.
11 1.1 augustss *
12 1.1 augustss * This code is derived from software contributed to The NetBSD Foundation
13 1.6 augustss * by Lennart Augustsson (lennart (at) augustsson.net) and Tommy Bohlin
14 1.6 augustss * (tommy (at) gatespace.com).
15 1.1 augustss *
16 1.1 augustss * Redistribution and use in source and binary forms, with or without
17 1.1 augustss * modification, are permitted provided that the following conditions
18 1.1 augustss * are met:
19 1.1 augustss * 1. Redistributions of source code must retain the above copyright
20 1.1 augustss * notice, this list of conditions and the following disclaimer.
21 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 augustss * notice, this list of conditions and the following disclaimer in the
23 1.1 augustss * documentation and/or other materials provided with the distribution.
24 1.1 augustss * 3. All advertising materials mentioning features or use of this software
25 1.1 augustss * must display the following acknowledgement:
26 1.1 augustss * This product includes software developed by the NetBSD
27 1.1 augustss * Foundation, Inc. and its contributors.
28 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
29 1.1 augustss * contributors may be used to endorse or promote products derived
30 1.1 augustss * from this software without specific prior written permission.
31 1.1 augustss *
32 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
33 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
34 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
36 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
43 1.1 augustss */
44 1.1 augustss
45 1.1 augustss /*
46 1.1 augustss * Loosely based on ppp_tty.c.
47 1.9 augustss * Framing and dongle handling written by Tommy Bohlin.
48 1.1 augustss */
49 1.1 augustss
50 1.1 augustss #include <sys/param.h>
51 1.1 augustss #include <sys/proc.h>
52 1.1 augustss #include <sys/ioctl.h>
53 1.1 augustss #include <sys/tty.h>
54 1.1 augustss #include <sys/kernel.h>
55 1.16 augustss #include <sys/lock.h>
56 1.2 augustss #include <sys/malloc.h>
57 1.1 augustss #include <sys/conf.h>
58 1.1 augustss #include <sys/systm.h>
59 1.1 augustss #include <sys/device.h>
60 1.1 augustss #include <sys/file.h>
61 1.2 augustss #include <sys/vnode.h>
62 1.1 augustss #include <sys/poll.h>
63 1.1 augustss
64 1.1 augustss #include <dev/ir/ir.h>
65 1.9 augustss #include <dev/ir/sir.h>
66 1.1 augustss #include <dev/ir/irdaio.h>
67 1.1 augustss #include <dev/ir/irframevar.h>
68 1.1 augustss
69 1.1 augustss /* Macros to clear/set/test flags. */
70 1.1 augustss #define SET(t, f) (t) |= (f)
71 1.2 augustss #define CLR(t, f) (t) &= ~(f)
72 1.1 augustss #define ISSET(t, f) ((t) & (f))
73 1.1 augustss
74 1.1 augustss #ifdef IRFRAMET_DEBUG
75 1.1 augustss #define DPRINTF(x) if (irframetdebug) printf x
76 1.2 augustss #define Static
77 1.8 augustss int irframetdebug = 0;
78 1.1 augustss #else
79 1.1 augustss #define DPRINTF(x)
80 1.2 augustss #define Static static
81 1.1 augustss #endif
82 1.1 augustss
83 1.1 augustss /*****/
84 1.1 augustss
85 1.14 augustss /* Max size with framing. */
86 1.14 augustss #define MAX_IRDA_FRAME (2*IRDA_MAX_FRAME_SIZE + IRDA_MAX_EBOFS + 4)
87 1.1 augustss
88 1.2 augustss struct frame {
89 1.2 augustss u_char *buf;
90 1.2 augustss u_int len;
91 1.2 augustss };
92 1.16 augustss #define MAXFRAMES 8
93 1.2 augustss
94 1.1 augustss struct irframet_softc {
95 1.1 augustss struct irframe_softc sc_irp;
96 1.1 augustss struct tty *sc_tp;
97 1.2 augustss
98 1.5 augustss int sc_dongle;
99 1.10 augustss int sc_dongle_private;
100 1.5 augustss
101 1.2 augustss int sc_state;
102 1.2 augustss #define IRT_RSLP 0x01 /* waiting for data (read) */
103 1.2 augustss #if 0
104 1.2 augustss #define IRT_WSLP 0x02 /* waiting for data (write) */
105 1.2 augustss #define IRT_CLOSING 0x04 /* waiting for output to drain */
106 1.2 augustss #endif
107 1.16 augustss struct lock sc_wr_lk;
108 1.2 augustss
109 1.16 augustss struct irda_params sc_params;
110 1.2 augustss
111 1.2 augustss u_char* sc_inbuf;
112 1.2 augustss int sc_framestate;
113 1.2 augustss #define FRAME_OUTSIDE 0
114 1.2 augustss #define FRAME_INSIDE 1
115 1.2 augustss #define FRAME_ESCAPE 2
116 1.2 augustss int sc_inchars;
117 1.2 augustss int sc_inFCS;
118 1.2 augustss struct callout sc_timeout;
119 1.2 augustss
120 1.2 augustss u_int sc_nframes;
121 1.2 augustss u_int sc_framei;
122 1.2 augustss u_int sc_frameo;
123 1.2 augustss struct frame sc_frames[MAXFRAMES];
124 1.2 augustss struct selinfo sc_rsel;
125 1.1 augustss };
126 1.1 augustss
127 1.1 augustss /* line discipline methods */
128 1.1 augustss int irframetopen(dev_t dev, struct tty *tp);
129 1.1 augustss int irframetclose(struct tty *tp, int flag);
130 1.1 augustss int irframetioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
131 1.5 augustss struct proc *);
132 1.1 augustss int irframetinput(int c, struct tty *tp);
133 1.1 augustss int irframetstart(struct tty *tp);
134 1.1 augustss
135 1.2 augustss /* pseudo device init */
136 1.2 augustss void irframettyattach(int);
137 1.2 augustss
138 1.1 augustss /* irframe methods */
139 1.2 augustss Static int irframet_open(void *h, int flag, int mode, struct proc *p);
140 1.2 augustss Static int irframet_close(void *h, int flag, int mode, struct proc *p);
141 1.2 augustss Static int irframet_read(void *h, struct uio *uio, int flag);
142 1.2 augustss Static int irframet_write(void *h, struct uio *uio, int flag);
143 1.2 augustss Static int irframet_poll(void *h, int events, struct proc *p);
144 1.2 augustss Static int irframet_set_params(void *h, struct irda_params *params);
145 1.2 augustss Static int irframet_get_speeds(void *h, int *speeds);
146 1.2 augustss Static int irframet_get_turnarounds(void *h, int *times);
147 1.2 augustss
148 1.2 augustss /* internal */
149 1.10 augustss Static int irt_write_frame(struct tty *tp, u_int8_t *buf, size_t len);
150 1.10 augustss Static int irt_putc(struct tty *tp, int c);
151 1.2 augustss Static void irt_frame(struct irframet_softc *sc, u_char *buf, u_int len);
152 1.2 augustss Static void irt_timeout(void *v);
153 1.17 augustss Static void irt_ioctl(struct tty *tp, u_long cmd, void *arg);
154 1.10 augustss Static void irt_setspeed(struct tty *tp, u_int speed);
155 1.10 augustss Static void irt_setline(struct tty *tp, u_int line);
156 1.10 augustss Static void irt_delay(struct tty *tp, u_int delay);
157 1.1 augustss
158 1.10 augustss Static const struct irframe_methods irframet_methods = {
159 1.1 augustss irframet_open, irframet_close, irframet_read, irframet_write,
160 1.2 augustss irframet_poll, irframet_set_params,
161 1.2 augustss irframet_get_speeds, irframet_get_turnarounds
162 1.1 augustss };
163 1.1 augustss
164 1.10 augustss Static void irts_none(struct tty *tp, u_int speed);
165 1.10 augustss Static void irts_tekram(struct tty *tp, u_int speed);
166 1.10 augustss Static void irts_jeteye(struct tty *tp, u_int speed);
167 1.10 augustss Static void irts_actisys(struct tty *tp, u_int speed);
168 1.10 augustss Static void irts_litelink(struct tty *tp, u_int speed);
169 1.10 augustss Static void irts_girbil(struct tty *tp, u_int speed);
170 1.10 augustss
171 1.10 augustss #define NORMAL_SPEEDS (IRDA_SPEEDS_SIR & ~IRDA_SPEED_2400)
172 1.10 augustss #define TURNT_POS (IRDA_TURNT_10000 | IRDA_TURNT_5000 | IRDA_TURNT_1000 | \
173 1.10 augustss IRDA_TURNT_500 | IRDA_TURNT_100 | IRDA_TURNT_50 | IRDA_TURNT_10)
174 1.10 augustss Static const struct dongle {
175 1.10 augustss void (*setspeed)(struct tty *tp, u_int speed);
176 1.10 augustss u_int speedmask;
177 1.10 augustss u_int turnmask;
178 1.10 augustss } irt_dongles[DONGLE_MAX] = {
179 1.10 augustss /* Indexed by dongle number from irdaio.h */
180 1.10 augustss { irts_none, IRDA_SPEEDS_SIR, IRDA_TURNT_10000 },
181 1.10 augustss { irts_tekram, IRDA_SPEEDS_SIR, IRDA_TURNT_10000 },
182 1.10 augustss { irts_jeteye, IRDA_SPEED_9600|IRDA_SPEED_19200|IRDA_SPEED_115200,
183 1.10 augustss IRDA_TURNT_10000 },
184 1.10 augustss { irts_actisys, NORMAL_SPEEDS & ~IRDA_SPEED_38400, TURNT_POS },
185 1.10 augustss { irts_actisys, NORMAL_SPEEDS, TURNT_POS },
186 1.10 augustss { irts_litelink, NORMAL_SPEEDS, TURNT_POS },
187 1.10 augustss { irts_girbil, IRDA_SPEEDS_SIR, IRDA_TURNT_10000 | IRDA_TURNT_5000 },
188 1.10 augustss };
189 1.10 augustss
190 1.1 augustss void
191 1.1 augustss irframettyattach(int n)
192 1.1 augustss {
193 1.1 augustss }
194 1.1 augustss
195 1.1 augustss /*
196 1.1 augustss * Line specific open routine for async tty devices.
197 1.1 augustss * Attach the given tty to the first available irframe unit.
198 1.1 augustss * Called from device open routine or ttioctl.
199 1.1 augustss */
200 1.1 augustss /* ARGSUSED */
201 1.1 augustss int
202 1.1 augustss irframetopen(dev_t dev, struct tty *tp)
203 1.1 augustss {
204 1.1 augustss struct proc *p = curproc; /* XXX */
205 1.1 augustss struct irframet_softc *sc;
206 1.1 augustss int error, s;
207 1.1 augustss
208 1.1 augustss DPRINTF(("%s\n", __FUNCTION__));
209 1.1 augustss
210 1.1 augustss if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
211 1.1 augustss return (error);
212 1.1 augustss
213 1.1 augustss s = spltty();
214 1.1 augustss
215 1.7 augustss DPRINTF(("%s: linesw=%p disc=%s\n", __FUNCTION__, tp->t_linesw,
216 1.7 augustss tp->t_linesw->l_name));
217 1.7 augustss if (strcmp(tp->t_linesw->l_name, "irframe") == 0) { /* XXX */
218 1.1 augustss sc = (struct irframet_softc *)tp->t_sc;
219 1.1 augustss DPRINTF(("%s: sc=%p sc_tp=%p\n", __FUNCTION__, sc, sc->sc_tp));
220 1.1 augustss if (sc != NULL) {
221 1.1 augustss splx(s);
222 1.1 augustss return (EBUSY);
223 1.1 augustss }
224 1.1 augustss }
225 1.1 augustss
226 1.1 augustss tp->t_sc = irframe_alloc(sizeof (struct irframet_softc),
227 1.1 augustss &irframet_methods, tp);
228 1.1 augustss sc = (struct irframet_softc *)tp->t_sc;
229 1.1 augustss sc->sc_tp = tp;
230 1.7 augustss printf("%s attached at tty%02d\n", sc->sc_irp.sc_dev.dv_xname,
231 1.7 augustss minor(tp->t_dev));
232 1.1 augustss
233 1.1 augustss DPRINTF(("%s: set sc=%p\n", __FUNCTION__, sc));
234 1.1 augustss
235 1.1 augustss ttyflush(tp, FREAD | FWRITE);
236 1.1 augustss
237 1.5 augustss sc->sc_dongle = DONGLE_NONE;
238 1.10 augustss sc->sc_dongle_private = 0;
239 1.5 augustss
240 1.1 augustss splx(s);
241 1.2 augustss
242 1.1 augustss return (0);
243 1.1 augustss }
244 1.1 augustss
245 1.1 augustss /*
246 1.1 augustss * Line specific close routine, called from device close routine
247 1.1 augustss * and from ttioctl.
248 1.1 augustss * Detach the tty from the irframe unit.
249 1.1 augustss * Mimics part of ttyclose().
250 1.1 augustss */
251 1.1 augustss int
252 1.1 augustss irframetclose(struct tty *tp, int flag)
253 1.1 augustss {
254 1.1 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
255 1.1 augustss int s;
256 1.1 augustss
257 1.1 augustss DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
258 1.1 augustss
259 1.1 augustss s = spltty();
260 1.1 augustss ttyflush(tp, FREAD | FWRITE);
261 1.1 augustss tp->t_linesw = linesw[0]; /* default line discipline */
262 1.1 augustss if (sc != NULL) {
263 1.1 augustss tp->t_sc = NULL;
264 1.2 augustss printf("%s detached from tty%02d\n", sc->sc_irp.sc_dev.dv_xname,
265 1.1 augustss minor(tp->t_dev));
266 1.1 augustss
267 1.1 augustss if (sc->sc_tp == tp)
268 1.1 augustss irframe_dealloc(&sc->sc_irp.sc_dev);
269 1.1 augustss }
270 1.1 augustss splx(s);
271 1.1 augustss return (0);
272 1.1 augustss }
273 1.1 augustss
274 1.1 augustss /*
275 1.1 augustss * Line specific (tty) ioctl routine.
276 1.1 augustss * This discipline requires that tty device drivers call
277 1.1 augustss * the line specific l_ioctl routine from their ioctl routines.
278 1.1 augustss */
279 1.1 augustss /* ARGSUSED */
280 1.1 augustss int
281 1.1 augustss irframetioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
282 1.1 augustss struct proc *p)
283 1.1 augustss {
284 1.1 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
285 1.1 augustss int error;
286 1.10 augustss int d;
287 1.1 augustss
288 1.1 augustss DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
289 1.1 augustss
290 1.1 augustss if (sc == NULL || tp != sc->sc_tp)
291 1.1 augustss return (-1);
292 1.1 augustss
293 1.1 augustss error = 0;
294 1.1 augustss switch (cmd) {
295 1.5 augustss case IRFRAMETTY_GET_DEVICE:
296 1.5 augustss *(int *)data = sc->sc_irp.sc_dev.dv_unit;
297 1.5 augustss break;
298 1.5 augustss case IRFRAMETTY_GET_DONGLE:
299 1.5 augustss *(int *)data = sc->sc_dongle;
300 1.5 augustss break;
301 1.5 augustss case IRFRAMETTY_SET_DONGLE:
302 1.10 augustss d = *(int *)data;
303 1.10 augustss if (d < 0 || d >= DONGLE_MAX)
304 1.10 augustss return (EINVAL);
305 1.10 augustss sc->sc_dongle = d;
306 1.5 augustss break;
307 1.1 augustss default:
308 1.17 augustss error = -1;
309 1.1 augustss break;
310 1.1 augustss }
311 1.1 augustss
312 1.1 augustss return (error);
313 1.1 augustss }
314 1.1 augustss
315 1.1 augustss /*
316 1.9 augustss * Start output on async tty interface.
317 1.1 augustss */
318 1.1 augustss int
319 1.1 augustss irframetstart(struct tty *tp)
320 1.1 augustss {
321 1.1 augustss /*struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;*/
322 1.18 augustss int s;
323 1.1 augustss
324 1.1 augustss DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
325 1.1 augustss
326 1.18 augustss s = spltty();
327 1.1 augustss if (tp->t_oproc != NULL)
328 1.1 augustss (*tp->t_oproc)(tp);
329 1.18 augustss splx(s);
330 1.1 augustss
331 1.1 augustss return (0);
332 1.1 augustss }
333 1.1 augustss
334 1.2 augustss void
335 1.2 augustss irt_frame(struct irframet_softc *sc, u_char *buf, u_int len)
336 1.2 augustss {
337 1.7 augustss DPRINTF(("%s: nframe=%d framei=%d frameo=%d\n",
338 1.7 augustss __FUNCTION__, sc->sc_nframes, sc->sc_framei, sc->sc_frameo));
339 1.7 augustss
340 1.19 augustss if (sc->sc_inbuf == NULL) /* XXX happens if device is closed? */
341 1.19 augustss return;
342 1.2 augustss if (sc->sc_nframes >= MAXFRAMES) {
343 1.2 augustss #ifdef IRFRAMET_DEBUG
344 1.2 augustss printf("%s: dropped frame\n", __FUNCTION__);
345 1.2 augustss #endif
346 1.2 augustss return;
347 1.2 augustss }
348 1.2 augustss if (sc->sc_frames[sc->sc_framei].buf == NULL)
349 1.2 augustss return;
350 1.2 augustss memcpy(sc->sc_frames[sc->sc_framei].buf, buf, len);
351 1.2 augustss sc->sc_frames[sc->sc_framei].len = len;
352 1.2 augustss sc->sc_framei = (sc->sc_framei+1) % MAXFRAMES;
353 1.2 augustss sc->sc_nframes++;
354 1.2 augustss if (sc->sc_state & IRT_RSLP) {
355 1.2 augustss sc->sc_state &= ~IRT_RSLP;
356 1.2 augustss DPRINTF(("%s: waking up reader\n", __FUNCTION__));
357 1.2 augustss wakeup(sc->sc_frames);
358 1.2 augustss }
359 1.2 augustss selwakeup(&sc->sc_rsel);
360 1.2 augustss }
361 1.2 augustss
362 1.2 augustss void
363 1.2 augustss irt_timeout(void *v)
364 1.2 augustss {
365 1.2 augustss struct irframet_softc *sc = v;
366 1.2 augustss
367 1.2 augustss #ifdef IRFRAMET_DEBUG
368 1.2 augustss if (sc->sc_framestate != FRAME_OUTSIDE)
369 1.2 augustss printf("%s: input frame timeout\n", __FUNCTION__);
370 1.2 augustss #endif
371 1.2 augustss sc->sc_framestate = FRAME_OUTSIDE;
372 1.2 augustss }
373 1.2 augustss
374 1.1 augustss int
375 1.1 augustss irframetinput(int c, struct tty *tp)
376 1.1 augustss {
377 1.1 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
378 1.1 augustss
379 1.7 augustss c &= 0xff;
380 1.7 augustss
381 1.7 augustss #if IRFRAMET_DEBUG
382 1.7 augustss if (irframetdebug > 1)
383 1.7 augustss DPRINTF(("%s: tp=%p c=0x%02x\n", __FUNCTION__, tp, c));
384 1.7 augustss #endif
385 1.1 augustss
386 1.1 augustss if (sc == NULL || tp != (struct tty *)sc->sc_tp)
387 1.1 augustss return (0);
388 1.1 augustss
389 1.2 augustss if (sc->sc_inbuf == NULL)
390 1.2 augustss return (0);
391 1.1 augustss
392 1.2 augustss switch (c) {
393 1.2 augustss case SIR_BOF:
394 1.7 augustss DPRINTF(("%s: BOF\n", __FUNCTION__));
395 1.2 augustss sc->sc_framestate = FRAME_INSIDE;
396 1.2 augustss sc->sc_inchars = 0;
397 1.2 augustss sc->sc_inFCS = INITFCS;
398 1.2 augustss break;
399 1.2 augustss case SIR_EOF:
400 1.7 augustss DPRINTF(("%s: EOF state=%d inchars=%d fcs=0x%04x\n",
401 1.7 augustss __FUNCTION__,
402 1.7 augustss sc->sc_framestate, sc->sc_inchars, sc->sc_inFCS));
403 1.2 augustss if (sc->sc_framestate == FRAME_INSIDE &&
404 1.2 augustss sc->sc_inchars >= 4 && sc->sc_inFCS == GOODFCS) {
405 1.2 augustss irt_frame(sc, sc->sc_inbuf, sc->sc_inchars - 2);
406 1.2 augustss } else if (sc->sc_framestate != FRAME_OUTSIDE) {
407 1.2 augustss #ifdef IRFRAMET_DEBUG
408 1.2 augustss printf("%s: malformed input frame\n", __FUNCTION__);
409 1.2 augustss #endif
410 1.2 augustss }
411 1.2 augustss sc->sc_framestate = FRAME_OUTSIDE;
412 1.2 augustss break;
413 1.2 augustss case SIR_CE:
414 1.7 augustss DPRINTF(("%s: CE\n", __FUNCTION__));
415 1.2 augustss if (sc->sc_framestate == FRAME_INSIDE)
416 1.2 augustss sc->sc_framestate = FRAME_ESCAPE;
417 1.2 augustss break;
418 1.2 augustss default:
419 1.8 augustss #if IRFRAMET_DEBUG
420 1.8 augustss if (irframetdebug > 1)
421 1.7 augustss DPRINTF(("%s: c=0x%02x, inchar=%d state=%d\n", __FUNCTION__, c,
422 1.7 augustss sc->sc_inchars, sc->sc_state));
423 1.8 augustss #endif
424 1.2 augustss if (sc->sc_framestate != FRAME_OUTSIDE) {
425 1.2 augustss if (sc->sc_framestate == FRAME_ESCAPE) {
426 1.2 augustss sc->sc_framestate = FRAME_INSIDE;
427 1.2 augustss c ^= SIR_ESC_BIT;
428 1.2 augustss }
429 1.16 augustss if (sc->sc_inchars < sc->sc_params.maxsize + 2) {
430 1.2 augustss sc->sc_inbuf[sc->sc_inchars++] = c;
431 1.2 augustss sc->sc_inFCS = updateFCS(sc->sc_inFCS, c);
432 1.2 augustss } else {
433 1.2 augustss sc->sc_framestate = FRAME_OUTSIDE;
434 1.2 augustss #ifdef IRFRAMET_DEBUG
435 1.2 augustss printf("%s: input frame overrun\n",
436 1.2 augustss __FUNCTION__);
437 1.2 augustss #endif
438 1.2 augustss }
439 1.2 augustss }
440 1.2 augustss break;
441 1.1 augustss }
442 1.1 augustss
443 1.7 augustss #if 1
444 1.2 augustss if (sc->sc_framestate != FRAME_OUTSIDE) {
445 1.7 augustss callout_reset(&sc->sc_timeout, hz/20, irt_timeout, sc);
446 1.1 augustss }
447 1.7 augustss #endif
448 1.1 augustss
449 1.2 augustss return (0);
450 1.1 augustss }
451 1.1 augustss
452 1.1 augustss
453 1.1 augustss /*** irframe methods ***/
454 1.1 augustss
455 1.1 augustss int
456 1.1 augustss irframet_open(void *h, int flag, int mode, struct proc *p)
457 1.1 augustss {
458 1.1 augustss struct tty *tp = h;
459 1.3 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
460 1.1 augustss
461 1.1 augustss DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
462 1.3 augustss
463 1.16 augustss sc->sc_params.speed = 0;
464 1.16 augustss sc->sc_params.ebofs = IRDA_DEFAULT_EBOFS;
465 1.16 augustss sc->sc_params.maxsize = 0;
466 1.3 augustss sc->sc_framestate = FRAME_OUTSIDE;
467 1.3 augustss sc->sc_nframes = 0;
468 1.3 augustss sc->sc_framei = 0;
469 1.3 augustss sc->sc_frameo = 0;
470 1.3 augustss callout_init(&sc->sc_timeout);
471 1.16 augustss lockinit(&sc->sc_wr_lk, PZERO, "irfrtl", 0, 0);
472 1.3 augustss
473 1.1 augustss return (0);
474 1.1 augustss }
475 1.1 augustss
476 1.1 augustss int
477 1.1 augustss irframet_close(void *h, int flag, int mode, struct proc *p)
478 1.1 augustss {
479 1.1 augustss struct tty *tp = h;
480 1.3 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
481 1.3 augustss int i, s;
482 1.1 augustss
483 1.1 augustss DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
484 1.3 augustss
485 1.3 augustss callout_stop(&sc->sc_timeout);
486 1.3 augustss s = splir();
487 1.3 augustss if (sc->sc_inbuf != NULL) {
488 1.3 augustss free(sc->sc_inbuf, M_DEVBUF);
489 1.3 augustss sc->sc_inbuf = NULL;
490 1.3 augustss }
491 1.3 augustss for (i = 0; i < MAXFRAMES; i++) {
492 1.3 augustss if (sc->sc_frames[i].buf != NULL) {
493 1.3 augustss free(sc->sc_frames[i].buf, M_DEVBUF);
494 1.3 augustss sc->sc_frames[i].buf = NULL;
495 1.3 augustss }
496 1.3 augustss }
497 1.3 augustss splx(s);
498 1.3 augustss
499 1.1 augustss return (0);
500 1.1 augustss }
501 1.1 augustss
502 1.1 augustss int
503 1.1 augustss irframet_read(void *h, struct uio *uio, int flag)
504 1.1 augustss {
505 1.1 augustss struct tty *tp = h;
506 1.2 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
507 1.2 augustss int error = 0;
508 1.2 augustss int s;
509 1.1 augustss
510 1.2 augustss DPRINTF(("%s: resid=%d, iovcnt=%d, offset=%ld\n",
511 1.2 augustss __FUNCTION__, uio->uio_resid, uio->uio_iovcnt,
512 1.2 augustss (long)uio->uio_offset));
513 1.7 augustss DPRINTF(("%s: nframe=%d framei=%d frameo=%d\n",
514 1.7 augustss __FUNCTION__, sc->sc_nframes, sc->sc_framei, sc->sc_frameo));
515 1.7 augustss
516 1.2 augustss
517 1.2 augustss s = splir();
518 1.2 augustss while (sc->sc_nframes == 0) {
519 1.2 augustss if (flag & IO_NDELAY) {
520 1.2 augustss splx(s);
521 1.2 augustss return (EWOULDBLOCK);
522 1.2 augustss }
523 1.2 augustss sc->sc_state |= IRT_RSLP;
524 1.2 augustss DPRINTF(("%s: sleep\n", __FUNCTION__));
525 1.2 augustss error = tsleep(sc->sc_frames, PZERO | PCATCH, "irtrd", 0);
526 1.2 augustss DPRINTF(("%s: woke, error=%d\n", __FUNCTION__, error));
527 1.2 augustss if (error) {
528 1.2 augustss sc->sc_state &= ~IRT_RSLP;
529 1.2 augustss break;
530 1.2 augustss }
531 1.2 augustss }
532 1.2 augustss
533 1.2 augustss /* Do just one frame transfer per read */
534 1.2 augustss if (!error) {
535 1.2 augustss if (uio->uio_resid < sc->sc_frames[sc->sc_frameo].len) {
536 1.16 augustss DPRINTF(("%s: uio buffer smaller than frame size "
537 1.16 augustss "(%d < %d)\n", __FUNCTION__, uio->uio_resid,
538 1.16 augustss sc->sc_frames[sc->sc_frameo].len));
539 1.2 augustss error = EINVAL;
540 1.2 augustss } else {
541 1.2 augustss DPRINTF(("%s: moving %d bytes\n", __FUNCTION__,
542 1.2 augustss sc->sc_frames[sc->sc_frameo].len));
543 1.7 augustss error = uiomove(sc->sc_frames[sc->sc_frameo].buf,
544 1.2 augustss sc->sc_frames[sc->sc_frameo].len, uio);
545 1.7 augustss DPRINTF(("%s: error=%d\n", __FUNCTION__, error));
546 1.2 augustss }
547 1.7 augustss sc->sc_frameo = (sc->sc_frameo+1) % MAXFRAMES;
548 1.2 augustss sc->sc_nframes--;
549 1.2 augustss }
550 1.2 augustss splx(s);
551 1.2 augustss
552 1.2 augustss return (error);
553 1.1 augustss }
554 1.1 augustss
555 1.2 augustss int
556 1.10 augustss irt_putc(struct tty *tp, int c)
557 1.1 augustss {
558 1.1 augustss int s;
559 1.1 augustss int error;
560 1.1 augustss
561 1.9 augustss #if IRFRAMET_DEBUG
562 1.9 augustss if (irframetdebug > 3)
563 1.9 augustss DPRINTF(("%s: tp=%p c=0x%02x cc=%d\n", __FUNCTION__, tp, c,
564 1.9 augustss tp->t_outq.c_cc));
565 1.9 augustss #endif
566 1.1 augustss if (tp->t_outq.c_cc > tp->t_hiwat) {
567 1.1 augustss irframetstart(tp);
568 1.1 augustss s = spltty();
569 1.1 augustss /*
570 1.1 augustss * This can only occur if FLUSHO is set in t_lflag,
571 1.1 augustss * or if ttstart/oproc is synchronous (or very fast).
572 1.1 augustss */
573 1.1 augustss if (tp->t_outq.c_cc <= tp->t_hiwat) {
574 1.1 augustss splx(s);
575 1.1 augustss goto go;
576 1.1 augustss }
577 1.1 augustss SET(tp->t_state, TS_ASLEEP);
578 1.1 augustss error = ttysleep(tp, &tp->t_outq, TTOPRI | PCATCH, ttyout, 0);
579 1.1 augustss splx(s);
580 1.1 augustss if (error)
581 1.1 augustss return (error);
582 1.1 augustss }
583 1.1 augustss go:
584 1.8 augustss if (putc(c, &tp->t_outq) < 0) {
585 1.1 augustss printf("irframe: putc failed\n");
586 1.1 augustss return (EIO);
587 1.1 augustss }
588 1.1 augustss return (0);
589 1.1 augustss }
590 1.1 augustss
591 1.2 augustss int
592 1.1 augustss irframet_write(void *h, struct uio *uio, int flag)
593 1.1 augustss {
594 1.9 augustss struct tty *tp = h;
595 1.9 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
596 1.1 augustss u_int8_t buf[MAX_IRDA_FRAME];
597 1.9 augustss int n;
598 1.1 augustss
599 1.7 augustss DPRINTF(("%s: resid=%d, iovcnt=%d, offset=%ld\n",
600 1.7 augustss __FUNCTION__, uio->uio_resid, uio->uio_iovcnt,
601 1.7 augustss (long)uio->uio_offset));
602 1.1 augustss
603 1.16 augustss n = irda_sir_frame(buf, MAX_IRDA_FRAME, uio, sc->sc_params.ebofs);
604 1.11 augustss if (n < 0) {
605 1.11 augustss #ifdef IRFRAMET_DEBUG
606 1.11 augustss printf("%s: irda_sir_frame() error=%d\n", __FUNCTION__, -n);
607 1.11 augustss #endif
608 1.9 augustss return (-n);
609 1.11 augustss }
610 1.10 augustss return (irt_write_frame(tp, buf, n));
611 1.1 augustss }
612 1.1 augustss
613 1.1 augustss int
614 1.10 augustss irt_write_frame(struct tty *tp, u_int8_t *buf, size_t len)
615 1.1 augustss {
616 1.16 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
617 1.9 augustss int error, i;
618 1.1 augustss
619 1.1 augustss DPRINTF(("%s: tp=%p len=%d\n", __FUNCTION__, tp, len));
620 1.1 augustss
621 1.16 augustss lockmgr(&sc->sc_wr_lk, LK_EXCLUSIVE, NULL);
622 1.1 augustss error = 0;
623 1.9 augustss for (i = 0; !error && i < len; i++)
624 1.10 augustss error = irt_putc(tp, buf[i]);
625 1.16 augustss lockmgr(&sc->sc_wr_lk, LK_RELEASE, NULL);
626 1.1 augustss
627 1.1 augustss irframetstart(tp);
628 1.1 augustss
629 1.9 augustss DPRINTF(("%s: done, error=%d\n", __FUNCTION__, error));
630 1.7 augustss
631 1.1 augustss return (error);
632 1.1 augustss }
633 1.1 augustss
634 1.1 augustss int
635 1.1 augustss irframet_poll(void *h, int events, struct proc *p)
636 1.1 augustss {
637 1.2 augustss struct tty *tp = h;
638 1.2 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
639 1.1 augustss int revents = 0;
640 1.1 augustss int s;
641 1.1 augustss
642 1.1 augustss DPRINTF(("%s: sc=%p\n", __FUNCTION__, sc));
643 1.1 augustss
644 1.1 augustss s = splir();
645 1.9 augustss /* XXX is this a good check? */
646 1.1 augustss if (events & (POLLOUT | POLLWRNORM))
647 1.9 augustss if (tp->t_outq.c_cc <= tp->t_lowat)
648 1.9 augustss revents |= events & (POLLOUT | POLLWRNORM);
649 1.9 augustss
650 1.1 augustss if (events & (POLLIN | POLLRDNORM)) {
651 1.2 augustss if (sc->sc_nframes > 0) {
652 1.1 augustss DPRINTF(("%s: have data\n", __FUNCTION__));
653 1.1 augustss revents |= events & (POLLIN | POLLRDNORM);
654 1.1 augustss } else {
655 1.7 augustss DPRINTF(("%s: recording select\n", __FUNCTION__));
656 1.1 augustss selrecord(p, &sc->sc_rsel);
657 1.1 augustss }
658 1.1 augustss }
659 1.1 augustss splx(s);
660 1.1 augustss
661 1.1 augustss return (revents);
662 1.1 augustss }
663 1.1 augustss
664 1.1 augustss int
665 1.1 augustss irframet_set_params(void *h, struct irda_params *p)
666 1.1 augustss {
667 1.1 augustss struct tty *tp = h;
668 1.3 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
669 1.2 augustss int i;
670 1.1 augustss
671 1.7 augustss DPRINTF(("%s: tp=%p speed=%d ebofs=%d maxsize=%d\n",
672 1.7 augustss __FUNCTION__, tp, p->speed, p->ebofs, p->maxsize));
673 1.1 augustss
674 1.16 augustss if (p->speed != sc->sc_params.speed) {
675 1.14 augustss /* Checked in irframe.c */
676 1.16 augustss lockmgr(&sc->sc_wr_lk, LK_EXCLUSIVE, NULL);
677 1.10 augustss irt_dongles[sc->sc_dongle].setspeed(tp, p->speed);
678 1.16 augustss lockmgr(&sc->sc_wr_lk, LK_RELEASE, NULL);
679 1.16 augustss sc->sc_params.speed = p->speed;
680 1.3 augustss }
681 1.3 augustss
682 1.14 augustss /* Max size checked in irframe.c */
683 1.16 augustss sc->sc_params.ebofs = p->ebofs;
684 1.14 augustss /* Max size checked in irframe.c */
685 1.16 augustss if (sc->sc_params.maxsize != p->maxsize) {
686 1.16 augustss sc->sc_params.maxsize = p->maxsize;
687 1.2 augustss if (sc->sc_inbuf != NULL)
688 1.2 augustss free(sc->sc_inbuf, M_DEVBUF);
689 1.2 augustss for (i = 0; i < MAXFRAMES; i++)
690 1.2 augustss if (sc->sc_frames[i].buf != NULL)
691 1.2 augustss free(sc->sc_frames[i].buf, M_DEVBUF);
692 1.16 augustss if (sc->sc_params.maxsize != 0) {
693 1.16 augustss sc->sc_inbuf = malloc(sc->sc_params.maxsize+2,
694 1.16 augustss M_DEVBUF, M_WAITOK);
695 1.2 augustss for (i = 0; i < MAXFRAMES; i++)
696 1.16 augustss sc->sc_frames[i].buf =
697 1.16 augustss malloc(sc->sc_params.maxsize,
698 1.16 augustss M_DEVBUF, M_WAITOK);
699 1.2 augustss } else {
700 1.2 augustss sc->sc_inbuf = NULL;
701 1.2 augustss for (i = 0; i < MAXFRAMES; i++)
702 1.2 augustss sc->sc_frames[i].buf = NULL;
703 1.2 augustss }
704 1.2 augustss }
705 1.2 augustss sc->sc_framestate = FRAME_OUTSIDE;
706 1.1 augustss
707 1.1 augustss return (0);
708 1.1 augustss }
709 1.1 augustss
710 1.1 augustss int
711 1.1 augustss irframet_get_speeds(void *h, int *speeds)
712 1.1 augustss {
713 1.1 augustss struct tty *tp = h;
714 1.10 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
715 1.1 augustss
716 1.1 augustss DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
717 1.10 augustss
718 1.11 augustss if (sc == NULL) /* during attach */
719 1.11 augustss *speeds = IRDA_SPEEDS_SIR;
720 1.11 augustss else
721 1.11 augustss *speeds = irt_dongles[sc->sc_dongle].speedmask;
722 1.1 augustss return (0);
723 1.1 augustss }
724 1.1 augustss
725 1.1 augustss int
726 1.1 augustss irframet_get_turnarounds(void *h, int *turnarounds)
727 1.1 augustss {
728 1.1 augustss struct tty *tp = h;
729 1.10 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
730 1.1 augustss
731 1.1 augustss DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
732 1.10 augustss
733 1.10 augustss *turnarounds = irt_dongles[sc->sc_dongle].turnmask;
734 1.1 augustss return (0);
735 1.10 augustss }
736 1.10 augustss
737 1.10 augustss void
738 1.17 augustss irt_ioctl(struct tty *tp, u_long cmd, void *arg)
739 1.17 augustss {
740 1.17 augustss int error;
741 1.17 augustss dev_t dev;
742 1.17 augustss
743 1.17 augustss dev = tp->t_dev;
744 1.17 augustss error = cdevsw[major(dev)].d_ioctl(dev, cmd, arg, 0, curproc);
745 1.17 augustss #ifdef DIAGNOSTIC
746 1.17 augustss if (error)
747 1.17 augustss printf("irt_ioctl: cmd=0x%08lx error=%d\n", cmd, error);
748 1.17 augustss #endif
749 1.17 augustss }
750 1.17 augustss
751 1.17 augustss void
752 1.10 augustss irt_setspeed(struct tty *tp, u_int speed)
753 1.10 augustss {
754 1.10 augustss struct termios tt;
755 1.10 augustss
756 1.17 augustss irt_ioctl(tp, TIOCGETA, &tt);
757 1.10 augustss tt.c_ispeed = tt.c_ospeed = speed;
758 1.18 augustss tt.c_cflag &= ~HUPCL;
759 1.18 augustss tt.c_cflag |= CLOCAL;
760 1.17 augustss irt_ioctl(tp, TIOCSETAF, &tt);
761 1.10 augustss }
762 1.10 augustss
763 1.10 augustss void
764 1.10 augustss irt_setline(struct tty *tp, u_int line)
765 1.10 augustss {
766 1.17 augustss int mline;
767 1.17 augustss
768 1.17 augustss irt_ioctl(tp, TIOCMGET, &mline);
769 1.17 augustss mline &= ~(TIOCM_DTR | TIOCM_RTS);
770 1.17 augustss mline |= line;
771 1.17 augustss irt_ioctl(tp, TIOCMSET, (caddr_t)&mline);
772 1.10 augustss }
773 1.10 augustss
774 1.10 augustss void
775 1.10 augustss irt_delay(struct tty *tp, u_int ms)
776 1.10 augustss {
777 1.10 augustss if (cold)
778 1.10 augustss delay(ms * 1000);
779 1.10 augustss else
780 1.12 augustss tsleep(&irt_delay, PZERO, "irtdly", ms * hz / 1000 + 1);
781 1.10 augustss
782 1.10 augustss }
783 1.10 augustss
784 1.10 augustss /**********************************************************************
785 1.10 augustss * No dongle
786 1.10 augustss **********************************************************************/
787 1.10 augustss void
788 1.10 augustss irts_none(struct tty *tp, u_int speed)
789 1.10 augustss {
790 1.10 augustss irt_setspeed(tp, speed);
791 1.10 augustss }
792 1.10 augustss
793 1.10 augustss /**********************************************************************
794 1.10 augustss * Tekram
795 1.10 augustss **********************************************************************/
796 1.10 augustss #define TEKRAM_PW 0x10
797 1.10 augustss
798 1.10 augustss #define TEKRAM_115200 (TEKRAM_PW|0x00)
799 1.10 augustss #define TEKRAM_57600 (TEKRAM_PW|0x01)
800 1.10 augustss #define TEKRAM_38400 (TEKRAM_PW|0x02)
801 1.10 augustss #define TEKRAM_19200 (TEKRAM_PW|0x03)
802 1.10 augustss #define TEKRAM_9600 (TEKRAM_PW|0x04)
803 1.10 augustss #define TEKRAM_2400 (TEKRAM_PW|0x08)
804 1.10 augustss
805 1.10 augustss #define TEKRAM_TV (TEKRAM_PW|0x05)
806 1.10 augustss
807 1.10 augustss void
808 1.10 augustss irts_tekram(struct tty *tp, u_int speed)
809 1.10 augustss {
810 1.10 augustss int s;
811 1.10 augustss
812 1.10 augustss irt_setspeed(tp, 9600);
813 1.10 augustss irt_setline(tp, 0);
814 1.10 augustss irt_delay(tp, 50);
815 1.17 augustss
816 1.10 augustss irt_setline(tp, TIOCM_RTS);
817 1.10 augustss irt_delay(tp, 1);
818 1.17 augustss
819 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
820 1.10 augustss irt_delay(tp, 1); /* 50 us */
821 1.17 augustss
822 1.10 augustss irt_setline(tp, TIOCM_DTR);
823 1.10 augustss irt_delay(tp, 1); /* 7 us */
824 1.17 augustss
825 1.10 augustss switch(speed) {
826 1.10 augustss case 115200: s = TEKRAM_115200; break;
827 1.10 augustss case 57600: s = TEKRAM_57600; break;
828 1.10 augustss case 38400: s = TEKRAM_38400; break;
829 1.10 augustss case 19200: s = TEKRAM_19200; break;
830 1.10 augustss case 2400: s = TEKRAM_2400; break;
831 1.10 augustss default: s = TEKRAM_9600; break;
832 1.10 augustss }
833 1.10 augustss irt_putc(tp, s);
834 1.18 augustss irframetstart(tp);
835 1.18 augustss
836 1.13 augustss irt_delay(tp, 100);
837 1.17 augustss
838 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
839 1.10 augustss if (speed != 9600)
840 1.10 augustss irt_setspeed(tp, speed);
841 1.10 augustss irt_delay(tp, 1); /* 50 us */
842 1.10 augustss }
843 1.10 augustss
844 1.10 augustss /**********************************************************************
845 1.10 augustss * Jeteye
846 1.10 augustss **********************************************************************/
847 1.10 augustss void
848 1.10 augustss irts_jeteye(struct tty *tp, u_int speed)
849 1.10 augustss {
850 1.10 augustss switch (speed) {
851 1.10 augustss case 19200:
852 1.10 augustss irt_setline(tp, TIOCM_DTR);
853 1.10 augustss break;
854 1.10 augustss case 115200:
855 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
856 1.10 augustss break;
857 1.10 augustss default: /*9600*/
858 1.10 augustss irt_setline(tp, TIOCM_RTS);
859 1.10 augustss break;
860 1.10 augustss }
861 1.10 augustss irt_setspeed(tp, speed);
862 1.10 augustss }
863 1.10 augustss
864 1.10 augustss /**********************************************************************
865 1.10 augustss * Actisys
866 1.10 augustss **********************************************************************/
867 1.10 augustss void
868 1.10 augustss irts_actisys(struct tty *tp, u_int speed)
869 1.10 augustss {
870 1.10 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
871 1.10 augustss int pulses;
872 1.10 augustss
873 1.10 augustss irt_setspeed(tp, speed);
874 1.10 augustss
875 1.10 augustss switch(speed) {
876 1.10 augustss case 19200: pulses=1; break;
877 1.10 augustss case 57600: pulses=2; break;
878 1.10 augustss case 115200: pulses=3; break;
879 1.10 augustss case 38400: pulses=4; break;
880 1.10 augustss default: /* 9600 */ pulses=0; break;
881 1.10 augustss }
882 1.10 augustss
883 1.10 augustss if (sc->sc_dongle_private == 0) {
884 1.10 augustss sc->sc_dongle_private = 1;
885 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
886 1.10 augustss /*
887 1.10 augustss * Must wait at least 50ms after initial
888 1.10 augustss * power on to charge internal capacitor
889 1.10 augustss */
890 1.10 augustss irt_delay(tp, 50);
891 1.10 augustss }
892 1.10 augustss irt_setline(tp, TIOCM_RTS);
893 1.10 augustss delay(2);
894 1.10 augustss for (;;) {
895 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
896 1.10 augustss delay(2);
897 1.10 augustss if (--pulses <= 0)
898 1.10 augustss break;
899 1.10 augustss irt_setline(tp, TIOCM_DTR);
900 1.10 augustss delay(2);
901 1.10 augustss }
902 1.10 augustss }
903 1.10 augustss
904 1.10 augustss /**********************************************************************
905 1.10 augustss * Litelink
906 1.10 augustss **********************************************************************/
907 1.10 augustss void
908 1.10 augustss irts_litelink(struct tty *tp, u_int speed)
909 1.10 augustss {
910 1.10 augustss struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
911 1.10 augustss int pulses;
912 1.10 augustss
913 1.10 augustss irt_setspeed(tp, speed);
914 1.10 augustss
915 1.10 augustss switch(speed) {
916 1.10 augustss case 57600: pulses=1; break;
917 1.10 augustss case 38400: pulses=2; break;
918 1.10 augustss case 19200: pulses=3; break;
919 1.10 augustss case 9600: pulses=4; break;
920 1.10 augustss default: /* 115200 */ pulses=0; break;
921 1.10 augustss }
922 1.10 augustss
923 1.10 augustss if (sc->sc_dongle_private == 0) {
924 1.10 augustss sc->sc_dongle_private = 1;
925 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
926 1.10 augustss }
927 1.10 augustss irt_setline(tp, TIOCM_RTS);
928 1.10 augustss irt_delay(tp, 1); /* 15 us */;
929 1.10 augustss for (;;) {
930 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
931 1.10 augustss irt_delay(tp, 1); /* 15 us */;
932 1.10 augustss if (--pulses <= 0)
933 1.10 augustss break;
934 1.10 augustss irt_setline(tp, TIOCM_DTR);
935 1.10 augustss irt_delay(tp, 1); /* 15 us */;
936 1.10 augustss }
937 1.10 augustss }
938 1.10 augustss
939 1.10 augustss /**********************************************************************
940 1.10 augustss * Girbil
941 1.10 augustss **********************************************************************/
942 1.10 augustss /* Control register 1 */
943 1.10 augustss #define GIRBIL_TXEN 0x01 /* Enable transmitter */
944 1.10 augustss #define GIRBIL_RXEN 0x02 /* Enable receiver */
945 1.10 augustss #define GIRBIL_ECAN 0x04 /* Cancel self emmited data */
946 1.10 augustss #define GIRBIL_ECHO 0x08 /* Echo control characters */
947 1.10 augustss
948 1.10 augustss /* LED Current Register */
949 1.10 augustss #define GIRBIL_HIGH 0x20
950 1.10 augustss #define GIRBIL_MEDIUM 0x21
951 1.10 augustss #define GIRBIL_LOW 0x22
952 1.10 augustss
953 1.10 augustss /* Baud register */
954 1.10 augustss #define GIRBIL_2400 0x30
955 1.10 augustss #define GIRBIL_4800 0x31
956 1.10 augustss #define GIRBIL_9600 0x32
957 1.10 augustss #define GIRBIL_19200 0x33
958 1.10 augustss #define GIRBIL_38400 0x34
959 1.10 augustss #define GIRBIL_57600 0x35
960 1.10 augustss #define GIRBIL_115200 0x36
961 1.10 augustss
962 1.10 augustss /* Mode register */
963 1.10 augustss #define GIRBIL_IRDA 0x40
964 1.10 augustss #define GIRBIL_ASK 0x41
965 1.10 augustss
966 1.10 augustss /* Control register 2 */
967 1.10 augustss #define GIRBIL_LOAD 0x51 /* Load the new baud rate value */
968 1.10 augustss
969 1.10 augustss void
970 1.10 augustss irts_girbil(struct tty *tp, u_int speed)
971 1.10 augustss {
972 1.10 augustss int s;
973 1.10 augustss
974 1.10 augustss irt_setspeed(tp, 9600);
975 1.10 augustss irt_setline(tp, TIOCM_DTR);
976 1.10 augustss irt_delay(tp, 5);
977 1.10 augustss irt_setline(tp, TIOCM_RTS);
978 1.10 augustss irt_delay(tp, 20);
979 1.10 augustss switch(speed) {
980 1.10 augustss case 115200: s = GIRBIL_115200; break;
981 1.10 augustss case 57600: s = GIRBIL_57600; break;
982 1.10 augustss case 38400: s = GIRBIL_38400; break;
983 1.10 augustss case 19200: s = GIRBIL_19200; break;
984 1.10 augustss case 4800: s = GIRBIL_4800; break;
985 1.10 augustss case 2400: s = GIRBIL_2400; break;
986 1.10 augustss default: s = GIRBIL_9600; break;
987 1.10 augustss }
988 1.10 augustss irt_putc(tp, GIRBIL_TXEN|GIRBIL_RXEN);
989 1.10 augustss irt_putc(tp, s);
990 1.10 augustss irt_putc(tp, GIRBIL_LOAD);
991 1.18 augustss irframetstart(tp);
992 1.10 augustss irt_delay(tp, 100);
993 1.10 augustss irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
994 1.10 augustss if (speed != 9600)
995 1.10 augustss irt_setspeed(tp, speed);
996 1.1 augustss }
997