2 * $NetBSD: ulpt.c,v 1.55 2002/10/23 09:14:01 jdolecek Exp $
3 * $FreeBSD: src/sys/dev/usb/ulpt.c,v 1.59 2003/09/28 20:48:13 phk Exp $
4 * $DragonFly: src/sys/dev/usbmisc/ulpt/ulpt.c,v 1.15 2006/12/23 00:26:26 swildner Exp $
8 * Copyright (c) 1998 The NetBSD Foundation, Inc.
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Lennart Augustsson (lennart@augustsson.net) at
13 * Carlstedt Research & Technology.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the NetBSD
26 * Foundation, Inc. and its contributors.
27 * 4. Neither the name of The NetBSD Foundation nor the names of its
28 * contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
32 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
35 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
45 * Printer Class spec: http://www.usb.org/developers/data/devclass/usbprint109.PDF
48 #include <sys/param.h>
49 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #if defined(__NetBSD__) || defined(__OpenBSD__)
53 #include <sys/device.h>
54 #include <sys/ioctl.h>
55 #elif defined(__FreeBSD__) || defined(__DragonFly__)
56 #include <sys/ioccom.h>
57 #include <sys/module.h>
62 #include <sys/device.h>
63 #include <sys/syslog.h>
64 #include <sys/sysctl.h>
65 #include <sys/thread2.h>
67 #include <bus/usb/usb.h>
68 #include <bus/usb/usbdi.h>
69 #include <bus/usb/usbdi_util.h>
70 #include <bus/usb/usbdevs.h>
71 #include <bus/usb/usb_quirks.h>
73 #define TIMEOUT hz*16 /* wait up to 16 seconds for a ready */
76 #define ULPT_BSIZE 16384
79 #define DPRINTF(x) if (ulptdebug) logprintf x
80 #define DPRINTFN(n,x) if (ulptdebug>(n)) logprintf x
82 SYSCTL_NODE(_hw_usb
, OID_AUTO
, ulpt
, CTLFLAG_RW
, 0, "USB ulpt");
83 SYSCTL_INT(_hw_usb_ulpt
, OID_AUTO
, debug
, CTLFLAG_RW
,
84 &ulptdebug
, 0, "ulpt debug level");
90 #define UR_GET_DEVICE_ID 0
91 #define UR_GET_PORT_STATUS 1
92 #define UR_SOFT_RESET 2
94 #define LPS_NERR 0x08 /* printer no error */
95 #define LPS_SELECT 0x10 /* printer selected */
96 #define LPS_NOPAPER 0x20 /* printer out of paper */
97 #define LPS_INVERT (LPS_SELECT|LPS_NERR)
98 #define LPS_MASK (LPS_SELECT|LPS_NERR|LPS_NOPAPER)
101 USBBASEDEVICE sc_dev
;
102 usbd_device_handle sc_udev
; /* device */
103 usbd_interface_handle sc_iface
; /* interface */
107 usbd_pipe_handle sc_out_pipe
; /* bulk out pipe */
110 usbd_pipe_handle sc_in_pipe
; /* bulk in pipe */
111 usbd_xfer_handle sc_in_xfer1
;
112 usbd_xfer_handle sc_in_xfer2
;
113 u_char sc_junk
[64]; /* somewhere to dump input */
116 #define ULPT_OPEN 0x01 /* device is open */
117 #define ULPT_OBUSY 0x02 /* printer is busy doing output */
118 #define ULPT_INIT 0x04 /* waiting to initialize for open */
120 #define ULPT_NOPRIME 0x40 /* don't prime on open */
121 u_char sc_laststatus
;
127 #if defined(__NetBSD__)
128 dev_type_open(ulptopen
);
129 dev_type_close(ulptclose
);
130 dev_type_write(ulptwrite
);
131 dev_type_ioctl(ulptioctl
);
133 const struct cdevsw ulpt_cdevsw
= {
134 ulptopen
, ulptclose
, noread
, ulptwrite
, ulptioctl
,
135 nostop
, notty
, nopoll
, nommap
, nokqfilter
,
137 #elif defined(__OpenBSD__)
139 #elif defined(__FreeBSD__) || defined(__DragonFly__)
140 Static d_open_t ulptopen
;
141 Static d_close_t ulptclose
;
142 Static d_write_t ulptwrite
;
143 Static d_ioctl_t ulptioctl
;
145 #define ULPT_CDEV_MAJOR 113
147 Static
struct dev_ops ulpt_ops
= {
148 { "ulpt", ULPT_CDEV_MAJOR
, 0 },
150 .d_close
= ulptclose
,
151 .d_write
= ulptwrite
,
152 .d_ioctl
= ulptioctl
,
156 void ulpt_disco(void *);
158 int ulpt_do_write(struct ulpt_softc
*, struct uio
*uio
, int);
159 int ulpt_status(struct ulpt_softc
*);
160 void ulpt_reset(struct ulpt_softc
*);
161 int ulpt_statusmsg(u_char
, struct ulpt_softc
*);
164 void ieee1284_print_id(char *);
167 #define ULPTUNIT(s) (minor(s) & 0x1f)
168 #define ULPTFLAGS(s) (minor(s) & 0xe0)
171 USB_DECLARE_DRIVER(ulpt
);
175 USB_MATCH_START(ulpt
, uaa
);
176 usb_interface_descriptor_t
*id
;
178 DPRINTFN(10,("ulpt_match\n"));
179 if (uaa
->iface
== NULL
)
180 return (UMATCH_NONE
);
181 id
= usbd_get_interface_descriptor(uaa
->iface
);
183 id
->bInterfaceClass
== UICLASS_PRINTER
&&
184 id
->bInterfaceSubClass
== UISUBCLASS_PRINTER
&&
185 (id
->bInterfaceProtocol
== UIPROTO_PRINTER_UNI
||
186 id
->bInterfaceProtocol
== UIPROTO_PRINTER_BI
||
187 id
->bInterfaceProtocol
== UIPROTO_PRINTER_1284
))
188 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO
);
189 return (UMATCH_NONE
);
194 USB_ATTACH_START(ulpt
, sc
, uaa
);
195 usbd_device_handle dev
= uaa
->device
;
196 usbd_interface_handle iface
= uaa
->iface
;
197 usb_interface_descriptor_t
*ifcd
= usbd_get_interface_descriptor(iface
);
198 usb_interface_descriptor_t
*id
, *iend
;
199 usb_config_descriptor_t
*cdesc
;
202 usb_endpoint_descriptor_t
*ed
;
206 DPRINTFN(10,("ulpt_attach: sc=%p\n", sc
));
207 usbd_devinfo(dev
, 0, devinfo
);
209 kprintf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc
->sc_dev
),
210 devinfo
, ifcd
->bInterfaceClass
, ifcd
->bInterfaceSubClass
);
213 * Stepping through the alternate settings needs to be abstracted out.
215 cdesc
= usbd_get_config_descriptor(dev
);
217 kprintf("%s: failed to get configuration descriptor\n",
218 USBDEVNAME(sc
->sc_dev
));
219 USB_ATTACH_ERROR_RETURN
;
221 iend
= (usb_interface_descriptor_t
*)
222 ((char *)cdesc
+ UGETW(cdesc
->wTotalLength
));
224 if (ifcd
< (usb_interface_descriptor_t
*)cdesc
||
226 panic("ulpt: iface desc out of range");
228 /* Step through all the descriptors looking for bidir mode */
229 for (id
= ifcd
, altno
= 0;
231 id
= (void *)((char *)id
+ id
->bLength
)) {
232 if (id
->bDescriptorType
== UDESC_INTERFACE
&&
233 id
->bInterfaceNumber
== ifcd
->bInterfaceNumber
) {
234 if (id
->bInterfaceClass
== UICLASS_PRINTER
&&
235 id
->bInterfaceSubClass
== UISUBCLASS_PRINTER
&&
236 (id
->bInterfaceProtocol
== UIPROTO_PRINTER_BI
/* ||
237 id->bInterfaceProtocol == UIPROTO_PRINTER_1284 */))
242 id
= ifcd
; /* not found, use original */
245 /* Found a new bidir setting */
246 DPRINTF(("ulpt_attach: set altno = %d\n", altno
));
247 err
= usbd_set_interface(iface
, altno
);
249 kprintf("%s: setting alternate interface failed\n",
250 USBDEVNAME(sc
->sc_dev
));
252 USB_ATTACH_ERROR_RETURN
;
257 (void)usbd_endpoint_count(iface
, &epcount
);
261 for (i
= 0; i
< epcount
; i
++) {
262 ed
= usbd_interface2endpoint_descriptor(iface
, i
);
264 kprintf("%s: couldn't get ep %d\n",
265 USBDEVNAME(sc
->sc_dev
), i
);
266 USB_ATTACH_ERROR_RETURN
;
268 if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
&&
269 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
) {
270 sc
->sc_in
= ed
->bEndpointAddress
;
271 } else if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_OUT
&&
272 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
) {
273 sc
->sc_out
= ed
->bEndpointAddress
;
276 if (sc
->sc_out
== -1) {
277 kprintf("%s: could not find bulk out endpoint\n",
278 USBDEVNAME(sc
->sc_dev
));
280 USB_ATTACH_ERROR_RETURN
;
283 if (usbd_get_quirks(dev
)->uq_flags
& UQ_BROKEN_BIDIR
) {
284 /* This device doesn't handle reading properly. */
288 kprintf("%s: using %s-directional mode\n", USBDEVNAME(sc
->sc_dev
),
289 sc
->sc_in
>= 0 ? "bi" : "uni");
291 DPRINTFN(10, ("ulpt_attach: bulk=%d\n", sc
->sc_out
));
293 sc
->sc_iface
= iface
;
294 sc
->sc_ifaceno
= id
->bInterfaceNumber
;
299 * This code is disabled because for some mysterious reason it causes
300 * printing not to work. But only sometimes, and mostly with
301 * UHCI and less often with OHCI. *sigh*
304 usb_config_descriptor_t
*cd
= usbd_get_config_descriptor(dev
);
305 usb_device_request_t req
;
308 req
.bmRequestType
= UT_READ_CLASS_INTERFACE
;
309 req
.bRequest
= UR_GET_DEVICE_ID
;
310 USETW(req
.wValue
, cd
->bConfigurationValue
);
311 USETW2(req
.wIndex
, id
->bInterfaceNumber
, id
->bAlternateSetting
);
312 USETW(req
.wLength
, sizeof devinfo
- 1);
313 err
= usbd_do_request_flags(dev
, &req
, devinfo
, USBD_SHORT_XFER_OK
,
314 &alen
, USBD_DEFAULT_TIMEOUT
);
316 kprintf("%s: cannot get device id\n", USBDEVNAME(sc
->sc_dev
));
317 } else if (alen
<= 2) {
318 kprintf("%s: empty device id, no printer connected?\n",
319 USBDEVNAME(sc
->sc_dev
));
321 /* devinfo now contains an IEEE-1284 device ID */
322 len
= ((devinfo
[0] & 0xff) << 8) | (devinfo
[1] & 0xff);
323 if (len
> sizeof devinfo
- 3)
324 len
= sizeof devinfo
- 3;
326 kprintf("%s: device id <", USBDEVNAME(sc
->sc_dev
));
327 ieee1284_print_id(devinfo
+2);
333 #if defined(__FreeBSD__) || defined(__DragonFly__)
334 dev_ops_add(&ulpt_ops
, -1, device_get_unit(self
));
335 make_dev(&ulpt_ops
, device_get_unit(self
),
336 UID_ROOT
, GID_OPERATOR
, 0644, "ulpt%d", device_get_unit(self
));
338 device_get_unit(self
)|ULPT_NOPRIME
,
339 UID_ROOT
, GID_OPERATOR
, 0644, "unlpt%d", device_get_unit(self
));
342 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH
, sc
->sc_udev
,
345 USB_ATTACH_SUCCESS_RETURN
;
348 #if defined(__NetBSD__) || defined(__OpenBSD__)
350 ulpt_activate(device_ptr_t self
, enum devact act
)
352 struct ulpt_softc
*sc
= (struct ulpt_softc
*)self
;
358 case DVACT_DEACTIVATE
:
368 USB_DETACH_START(ulpt
, sc
);
369 #if defined(__NetBSD__) || defined(__OpenBSD__)
373 #if defined(__NetBSD__) || defined(__OpenBSD__)
374 DPRINTF(("ulpt_detach: sc=%p flags=%d\n", sc
, flags
));
375 #elif defined(__FreeBSD__) || defined(__DragonFly__)
376 DPRINTF(("ulpt_detach: sc=%p\n", sc
));
380 if (sc
->sc_out_pipe
!= NULL
)
381 usbd_abort_pipe(sc
->sc_out_pipe
);
382 if (sc
->sc_in_pipe
!= NULL
)
383 usbd_abort_pipe(sc
->sc_in_pipe
);
386 * Wait for any ongoing operations to complete before we actually
392 if (sc
->sc_refcnt
>= 0) {
393 kprintf("%s: waiting for idle\n", USBDEVNAME(sc
->sc_dev
));
394 while (sc
->sc_refcnt
>= 0)
395 usb_detach_wait(USBDEV(sc
->sc_dev
));
396 kprintf("%s: idle wait done\n", USBDEVNAME(sc
->sc_dev
));
400 #if defined(__NetBSD__) || defined(__OpenBSD__)
401 /* locate the major number */
402 #if defined(__NetBSD__)
403 maj
= cdevsw_lookup_major(&ulpt_cdevsw
);
404 #elif defined(__OpenBSD__)
405 for (maj
= 0; maj
< nchrdev
; maj
++)
406 if (cdevsw
[maj
].d_open
== ulptopen
)
410 /* Nuke the vnodes for any open instances (calls close). */
412 vdevgone(maj
, mn
, mn
, VCHR
);
413 #elif defined(__FreeBSD__) || defined(__DragonFly__)
414 dev_ops_remove(&ulpt_ops
, -1, device_get_unit(self
));
417 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH
, sc
->sc_udev
,
424 ulpt_status(struct ulpt_softc
*sc
)
426 usb_device_request_t req
;
430 req
.bmRequestType
= UT_READ_CLASS_INTERFACE
;
431 req
.bRequest
= UR_GET_PORT_STATUS
;
432 USETW(req
.wValue
, 0);
433 USETW(req
.wIndex
, sc
->sc_ifaceno
);
434 USETW(req
.wLength
, 1);
435 err
= usbd_do_request(sc
->sc_udev
, &req
, &status
);
436 DPRINTFN(1, ("ulpt_status: status=0x%02x err=%d\n", status
, err
));
444 ulpt_reset(struct ulpt_softc
*sc
)
446 usb_device_request_t req
;
448 DPRINTFN(1, ("ulpt_reset\n"));
449 req
.bRequest
= UR_SOFT_RESET
;
450 USETW(req
.wValue
, 0);
451 USETW(req
.wIndex
, sc
->sc_ifaceno
);
452 USETW(req
.wLength
, 0);
455 * There was a mistake in the USB printer 1.0 spec that gave the
456 * request type as UT_WRITE_CLASS_OTHER; it should have been
457 * UT_WRITE_CLASS_INTERFACE. Many printers use the old one,
460 req
.bmRequestType
= UT_WRITE_CLASS_OTHER
;
461 if (usbd_do_request(sc
->sc_udev
, &req
, 0)) { /* 1.0 */
462 req
.bmRequestType
= UT_WRITE_CLASS_INTERFACE
;
463 (void)usbd_do_request(sc
->sc_udev
, &req
, 0); /* 1.1 */
468 ulpt_input(usbd_xfer_handle xfer
, usbd_private_handle priv
, usbd_status status
)
470 struct ulpt_softc
*sc
= priv
;
473 /* Don't loop on errors or 0-length input. */
474 usbd_get_xfer_status(xfer
, NULL
, NULL
, &count
, NULL
);
475 if (status
!= USBD_NORMAL_COMPLETION
|| count
== 0)
478 DPRINTFN(2,("ulpt_input: got some data\n"));
480 if (xfer
== sc
->sc_in_xfer1
)
481 usbd_transfer(sc
->sc_in_xfer2
);
483 usbd_transfer(sc
->sc_in_xfer1
);
489 * Reset the printer, then wait until it's selected and not busy.
492 ulptopen(struct dev_open_args
*ap
)
494 cdev_t dev
= ap
->a_head
.a_dev
;
495 u_char flags
= ULPTFLAGS(dev
);
496 struct ulpt_softc
*sc
;
500 USB_GET_SC_OPEN(ulpt
, ULPTUNIT(dev
), sc
);
502 if (sc
== NULL
|| sc
->sc_iface
== NULL
|| sc
->sc_dying
)
508 sc
->sc_state
= ULPT_INIT
;
509 sc
->sc_flags
= flags
;
510 DPRINTF(("ulptopen: flags=0x%x\n", (unsigned)flags
));
512 #if defined(USB_DEBUG) && (defined(__FreeBSD__) || defined(__DragonFly__))
513 /* Ignoring these flags might not be a good idea */
514 if ((flags
& ~ULPT_NOPRIME
) != 0)
515 kprintf("ulptopen: flags ignored: %b\n", flags
,
516 "\20\3POS_INIT\4POS_ACK\6PRIME_OPEN\7AUTOLF\10BYPASS");
522 if ((flags
& ULPT_NOPRIME
) == 0) {
531 for (spin
= 0; (ulpt_status(sc
) & LPS_SELECT
) == 0; spin
+= STEP
) {
532 DPRINTF(("ulpt_open: waiting a while\n"));
533 if (spin
>= TIMEOUT
) {
539 /* wait 1/4 second, give up if we get a signal */
540 error
= tsleep((caddr_t
)sc
, PCATCH
, "ulptop", STEP
);
541 if (error
!= EWOULDBLOCK
) {
553 err
= usbd_open_pipe(sc
->sc_iface
, sc
->sc_out
, 0, &sc
->sc_out_pipe
);
560 if (ulptusein
&& sc
->sc_in
!= -1) {
561 DPRINTF(("ulpt_open: open input pipe\n"));
562 err
= usbd_open_pipe(sc
->sc_iface
, sc
->sc_in
,0,&sc
->sc_in_pipe
);
565 usbd_close_pipe(sc
->sc_out_pipe
);
566 sc
->sc_out_pipe
= NULL
;
570 sc
->sc_in_xfer1
= usbd_alloc_xfer(sc
->sc_udev
);
571 sc
->sc_in_xfer2
= usbd_alloc_xfer(sc
->sc_udev
);
572 if (sc
->sc_in_xfer1
== NULL
|| sc
->sc_in_xfer2
== NULL
) {
574 if (sc
->sc_in_xfer1
!= NULL
) {
575 usbd_free_xfer(sc
->sc_in_xfer1
);
576 sc
->sc_in_xfer1
= NULL
;
578 if (sc
->sc_in_xfer2
!= NULL
) {
579 usbd_free_xfer(sc
->sc_in_xfer2
);
580 sc
->sc_in_xfer2
= NULL
;
582 usbd_close_pipe(sc
->sc_out_pipe
);
583 sc
->sc_out_pipe
= NULL
;
584 usbd_close_pipe(sc
->sc_in_pipe
);
585 sc
->sc_in_pipe
= NULL
;
589 usbd_setup_xfer(sc
->sc_in_xfer1
, sc
->sc_in_pipe
, sc
,
590 sc
->sc_junk
, sizeof sc
->sc_junk
, USBD_SHORT_XFER_OK
,
591 USBD_NO_TIMEOUT
, ulpt_input
);
592 usbd_setup_xfer(sc
->sc_in_xfer2
, sc
->sc_in_pipe
, sc
,
593 sc
->sc_junk
, sizeof sc
->sc_junk
, USBD_SHORT_XFER_OK
,
594 USBD_NO_TIMEOUT
, ulpt_input
);
595 usbd_transfer(sc
->sc_in_xfer1
); /* ignore failed start */
598 sc
->sc_state
= ULPT_OPEN
;
601 if (--sc
->sc_refcnt
< 0)
602 usb_detach_wakeup(USBDEV(sc
->sc_dev
));
604 DPRINTF(("ulptopen: done, error=%d\n", error
));
609 ulpt_statusmsg(u_char status
, struct ulpt_softc
*sc
)
613 status
= (status
^ LPS_INVERT
) & LPS_MASK
;
614 new = status
& ~sc
->sc_laststatus
;
615 sc
->sc_laststatus
= status
;
617 if (new & LPS_SELECT
)
618 log(LOG_NOTICE
, "%s: offline\n", USBDEVNAME(sc
->sc_dev
));
619 else if (new & LPS_NOPAPER
)
620 log(LOG_NOTICE
, "%s: out of paper\n", USBDEVNAME(sc
->sc_dev
));
621 else if (new & LPS_NERR
)
622 log(LOG_NOTICE
, "%s: output error\n", USBDEVNAME(sc
->sc_dev
));
628 ulptclose(struct dev_close_args
*ap
)
630 cdev_t dev
= ap
->a_head
.a_dev
;
631 struct ulpt_softc
*sc
;
633 USB_GET_SC(ulpt
, ULPTUNIT(dev
), sc
);
635 if (sc
->sc_state
!= ULPT_OPEN
)
636 /* We are being forced to close before the open completed. */
639 if (sc
->sc_out_pipe
!= NULL
) {
640 usbd_close_pipe(sc
->sc_out_pipe
);
641 sc
->sc_out_pipe
= NULL
;
643 if (sc
->sc_in_pipe
!= NULL
) {
644 usbd_abort_pipe(sc
->sc_in_pipe
);
645 usbd_close_pipe(sc
->sc_in_pipe
);
646 sc
->sc_in_pipe
= NULL
;
647 if (sc
->sc_in_xfer1
!= NULL
) {
648 usbd_free_xfer(sc
->sc_in_xfer1
);
649 sc
->sc_in_xfer1
= NULL
;
651 if (sc
->sc_in_xfer2
!= NULL
) {
652 usbd_free_xfer(sc
->sc_in_xfer2
);
653 sc
->sc_in_xfer2
= NULL
;
659 DPRINTF(("ulptclose: closed\n"));
664 ulpt_do_write(struct ulpt_softc
*sc
, struct uio
*uio
, int flags
)
669 usbd_xfer_handle xfer
;
672 DPRINTF(("ulptwrite\n"));
673 xfer
= usbd_alloc_xfer(sc
->sc_udev
);
676 bufp
= usbd_alloc_buffer(xfer
, ULPT_BSIZE
);
678 usbd_free_xfer(xfer
);
681 while ((n
= min(ULPT_BSIZE
, uio
->uio_resid
)) != 0) {
682 ulpt_statusmsg(ulpt_status(sc
), sc
);
683 error
= uiomove(bufp
, n
, uio
);
686 DPRINTFN(1, ("ulptwrite: transfer %d bytes\n", n
));
687 err
= usbd_bulk_transfer(xfer
, sc
->sc_out_pipe
, USBD_NO_COPY
,
688 USBD_NO_TIMEOUT
, bufp
, &n
, "ulptwr");
690 DPRINTF(("ulptwrite: error=%d\n", err
));
695 usbd_free_xfer(xfer
);
701 ulptwrite(struct dev_write_args
*ap
)
703 cdev_t dev
= ap
->a_head
.a_dev
;
704 struct ulpt_softc
*sc
;
707 USB_GET_SC(ulpt
, ULPTUNIT(dev
), sc
);
713 error
= ulpt_do_write(sc
, ap
->a_uio
, ap
->a_ioflag
);
714 if (--sc
->sc_refcnt
< 0)
715 usb_detach_wakeup(USBDEV(sc
->sc_dev
));
720 ulptioctl(struct dev_ioctl_args
*ap
)
733 /* XXX This does not belong here. */
735 * Print select parts of an IEEE 1284 device ID.
738 ieee1284_print_id(char *str
)
742 for (p
= str
-1; p
; p
= strchr(p
, ';')) {
744 if (strncmp(p
, "MFG:", 4) == 0 ||
745 strncmp(p
, "MANUFACTURER:", 14) == 0 ||
746 strncmp(p
, "MDL:", 4) == 0 ||
747 strncmp(p
, "MODEL:", 6) == 0) {
750 kprintf("%.*s", (int)(q
- p
+ 1), p
);
756 #if defined(__FreeBSD__) || defined(__DragonFly__)
757 DRIVER_MODULE(ulpt
, uhub
, ulpt_driver
, ulpt_devclass
, usbd_driver_load
, 0);