Deleted Added
sdiff udiff text old ( 187176 ) new ( 187259 )
full compact
1#include <sys/cdefs.h>
2__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/ulpt2.c 187176 2009-01-13 19:03:47Z thompsa $");
3
4/* $NetBSD: ulpt.c,v 1.60 2003/10/04 21:19:50 augustss Exp $ */
5
6/*-
7 * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to The NetBSD Foundation

--- 59 unchanged lines hidden (view full) ---

70
71SYSCTL_NODE(_hw_usb2, OID_AUTO, ulpt, CTLFLAG_RW, 0, "USB ulpt");
72SYSCTL_INT(_hw_usb2_ulpt, OID_AUTO, debug, CTLFLAG_RW,
73 &ulpt_debug, 0, "Debug level");
74#endif
75
76#define ULPT_BSIZE (1<<15) /* bytes */
77#define ULPT_IFQ_MAXLEN 2 /* units */
78#define ULPT_N_TRANSFER 5 /* units */
79
80#define UR_GET_DEVICE_ID 0x00
81#define UR_GET_PORT_STATUS 0x01
82#define UR_SOFT_RESET 0x02
83
84#define LPS_NERR 0x08 /* printer no error */
85#define LPS_SELECT 0x10 /* printer selected */
86#define LPS_NOPAPER 0x20 /* printer out of paper */
87#define LPS_INVERT (LPS_SELECT|LPS_NERR)
88#define LPS_MASK (LPS_SELECT|LPS_NERR|LPS_NOPAPER)
89
90struct ulpt_softc {
91 struct usb2_fifo_sc sc_fifo;
92 struct usb2_fifo_sc sc_fifo_noreset;
93 struct mtx sc_mtx;
94 struct usb2_callout sc_watchdog;
95
96 device_t sc_dev;
97 struct usb2_device *sc_udev;

--- 104 unchanged lines hidden (view full) ---

202 return;
203 }
204 DPRINTF("state=0x%x\n", USB_GET_STATE(xfer));
205
206 switch (USB_GET_STATE(xfer)) {
207 case USB_ST_TRANSFERRED:
208 case USB_ST_SETUP:
209 if (sc->sc_flags & ULPT_FLAG_WRITE_STALL) {
210 usb2_transfer_start(sc->sc_xfer[3]);
211 break;
212 }
213 if (usb2_fifo_get_data(f, xfer->frbuffers,
214 0, xfer->max_data_length, &actlen, 0)) {
215
216 xfer->frlengths[0] = actlen;
217 usb2_start_hardware(xfer);
218 }
219 break;
220
221 default: /* Error */
222 if (xfer->error != USB_ERR_CANCELLED) {
223 /* try to clear stall first */
224 sc->sc_flags |= ULPT_FLAG_WRITE_STALL;
225 usb2_transfer_start(sc->sc_xfer[3]);
226 }
227 break;
228 }
229}
230
231static void
232ulpt_write_clear_stall_callback(struct usb2_xfer *xfer)
233{
234 struct ulpt_softc *sc = xfer->priv_sc;
235 struct usb2_xfer *xfer_other = sc->sc_xfer[0];
236
237 if (usb2_clear_stall_callback(xfer, xfer_other)) {
238 DPRINTF("stall cleared\n");
239 sc->sc_flags &= ~ULPT_FLAG_WRITE_STALL;
240 usb2_transfer_start(xfer_other);
241 }
242}
243

--- 28 unchanged lines hidden (view full) ---

272 sc->sc_zlps = 0;
273 }
274
275 usb2_fifo_put_data(f, xfer->frbuffers,
276 0, xfer->actlen, 1);
277
278 case USB_ST_SETUP:
279 if (sc->sc_flags & ULPT_FLAG_READ_STALL) {
280 usb2_transfer_start(sc->sc_xfer[4]);
281 break;
282 }
283 if (usb2_fifo_put_bytes_max(f) != 0) {
284 xfer->frlengths[0] = xfer->max_data_length;
285 usb2_start_hardware(xfer);
286 }
287 break;
288
289 default: /* Error */
290 /* disable BULK throttle */
291 xfer->interval = 0;
292 sc->sc_zlps = 0;
293
294 if (xfer->error != USB_ERR_CANCELLED) {
295 /* try to clear stall first */
296 sc->sc_flags |= ULPT_FLAG_READ_STALL;
297 usb2_transfer_start(sc->sc_xfer[4]);
298 }
299 break;
300 }
301}
302
303static void
304ulpt_read_clear_stall_callback(struct usb2_xfer *xfer)
305{
306 struct ulpt_softc *sc = xfer->priv_sc;
307 struct usb2_xfer *xfer_other = sc->sc_xfer[1];
308
309 if (usb2_clear_stall_callback(xfer, xfer_other)) {
310 DPRINTF("stall cleared\n");
311 sc->sc_flags &= ~ULPT_FLAG_READ_STALL;
312 usb2_transfer_start(xfer_other);
313 }
314}
315

--- 46 unchanged lines hidden (view full) ---

362 if (xfer->error != USB_ERR_CANCELLED) {
363 /* wait for next watchdog timeout */
364 }
365 break;
366 }
367}
368
369static const struct usb2_config ulpt_config[ULPT_N_TRANSFER] = {
370 [0] = {
371 .type = UE_BULK,
372 .endpoint = UE_ADDR_ANY,
373 .direction = UE_DIR_OUT,
374 .mh.bufsize = ULPT_BSIZE,
375 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,.proxy_buffer = 1},
376 .mh.callback = &ulpt_write_callback,
377 },
378
379 [1] = {
380 .type = UE_BULK,
381 .endpoint = UE_ADDR_ANY,
382 .direction = UE_DIR_IN,
383 .mh.bufsize = ULPT_BSIZE,
384 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,.proxy_buffer = 1},
385 .mh.callback = &ulpt_read_callback,
386 },
387
388 [2] = {
389 .type = UE_CONTROL,
390 .endpoint = 0x00, /* Control pipe */
391 .direction = UE_DIR_ANY,
392 .mh.bufsize = sizeof(struct usb2_device_request) + 1,
393 .mh.callback = &ulpt_status_callback,
394 .mh.timeout = 1000, /* 1 second */
395 },
396
397 [3] = {
398 .type = UE_CONTROL,
399 .endpoint = 0x00, /* Control pipe */
400 .direction = UE_DIR_ANY,
401 .mh.bufsize = sizeof(struct usb2_device_request),
402 .mh.callback = &ulpt_write_clear_stall_callback,
403 .mh.timeout = 1000, /* 1 second */
404 .mh.interval = 50, /* 50ms */
405 },
406
407 [4] = {
408 .type = UE_CONTROL,
409 .endpoint = 0x00, /* Control pipe */
410 .direction = UE_DIR_ANY,
411 .mh.bufsize = sizeof(struct usb2_device_request),
412 .mh.callback = &ulpt_read_clear_stall_callback,
413 .mh.timeout = 1000, /* 1 second */
414 .mh.interval = 50, /* 50ms */
415 },
416};
417
418static void
419ulpt_start_read(struct usb2_fifo *fifo)
420{
421 struct ulpt_softc *sc = fifo->priv_sc0;
422
423 usb2_transfer_start(sc->sc_xfer[1]);
424}
425
426static void
427ulpt_stop_read(struct usb2_fifo *fifo)
428{
429 struct ulpt_softc *sc = fifo->priv_sc0;
430
431 usb2_transfer_stop(sc->sc_xfer[4]);
432 usb2_transfer_stop(sc->sc_xfer[1]);
433}
434
435static void
436ulpt_start_write(struct usb2_fifo *fifo)
437{
438 struct ulpt_softc *sc = fifo->priv_sc0;
439
440 usb2_transfer_start(sc->sc_xfer[0]);
441}
442
443static void
444ulpt_stop_write(struct usb2_fifo *fifo)
445{
446 struct ulpt_softc *sc = fifo->priv_sc0;
447
448 usb2_transfer_stop(sc->sc_xfer[3]);
449 usb2_transfer_stop(sc->sc_xfer[0]);
450}
451
452static int
453ulpt_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
454{
455 struct ulpt_softc *sc = fifo->priv_sc0;
456
457 /* we assume that open is a serial process */

--- 13 unchanged lines hidden (view full) ---

471 return (EBUSY);
472 }
473 if (fflags & FREAD) {
474 /* clear stall first */
475 mtx_lock(&sc->sc_mtx);
476 sc->sc_flags |= ULPT_FLAG_READ_STALL;
477 mtx_unlock(&sc->sc_mtx);
478 if (usb2_fifo_alloc_buffer(fifo,
479 sc->sc_xfer[1]->max_data_length,
480 ULPT_IFQ_MAXLEN)) {
481 return (ENOMEM);
482 }
483 /* set which FIFO is opened */
484 sc->sc_fifo_open[USB_FIFO_RX] = fifo;
485 }
486 if (fflags & FWRITE) {
487 /* clear stall first */
488 mtx_lock(&sc->sc_mtx);
489 sc->sc_flags |= ULPT_FLAG_WRITE_STALL;
490 mtx_unlock(&sc->sc_mtx);
491 if (usb2_fifo_alloc_buffer(fifo,
492 sc->sc_xfer[0]->max_data_length,
493 ULPT_IFQ_MAXLEN)) {
494 return (ENOMEM);
495 }
496 /* set which FIFO is opened */
497 sc->sc_fifo_open[USB_FIFO_TX] = fifo;
498 }
499 sc->sc_fflags |= fflags & (FREAD | FWRITE);
500 return (0);

--- 249 unchanged lines hidden (view full) ---

750
751static void
752ulpt_watchdog(void *arg)
753{
754 struct ulpt_softc *sc = arg;
755
756 mtx_assert(&sc->sc_mtx, MA_OWNED);
757
758 usb2_transfer_start(sc->sc_xfer[2]);
759
760 usb2_callout_reset(&sc->sc_watchdog,
761 hz, &ulpt_watchdog, sc);
762}
763
764static devclass_t ulpt_devclass;
765
766static device_method_t ulpt_methods[] = {

--- 15 unchanged lines hidden ---