Skip to content

Commit 0d930e5

Browse files
Alon Zivgregkh
authored andcommitted
USB: opticon: Add Opticon OPN2001 write support
OPN2001 expects write operations to arrive as a vendor-specific command through the control pipe (instead of using a separate bulk-out pipe). Signed-off-by: Alon Ziv <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 97cd8dc commit 0d930e5

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

drivers/usb/serial/opticon.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ static void opticon_write_bulk_callback(struct urb *urb)
187187
/* free up the transfer buffer, as usb_free_urb() does not do this */
188188
kfree(urb->transfer_buffer);
189189

190+
/* setup packet may be set if we're using it for writing */
191+
kfree(urb->setup_packet);
192+
190193
if (status)
191194
dbg("%s - nonzero write bulk status received: %d",
192195
__func__, status);
@@ -237,10 +240,29 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
237240

238241
usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
239242

240-
usb_fill_bulk_urb(urb, serial->dev,
241-
usb_sndbulkpipe(serial->dev,
242-
port->bulk_out_endpointAddress),
243-
buffer, count, opticon_write_bulk_callback, priv);
243+
if (port->bulk_out_endpointAddress) {
244+
usb_fill_bulk_urb(urb, serial->dev,
245+
usb_sndbulkpipe(serial->dev,
246+
port->bulk_out_endpointAddress),
247+
buffer, count, opticon_write_bulk_callback, priv);
248+
} else {
249+
struct usb_ctrlrequest *dr;
250+
251+
dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
252+
if (!dr)
253+
return -ENOMEM;
254+
255+
dr->bRequestType = USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT;
256+
dr->bRequest = 0x01;
257+
dr->wValue = 0;
258+
dr->wIndex = 0;
259+
dr->wLength = cpu_to_le16(count);
260+
261+
usb_fill_control_urb(urb, serial->dev,
262+
usb_sndctrlpipe(serial->dev, 0),
263+
(unsigned char *)dr, buffer, count,
264+
opticon_write_bulk_callback, priv);
265+
}
244266

245267
/* send it down the pipe */
246268
status = usb_submit_urb(urb, GFP_ATOMIC);

0 commit comments

Comments
 (0)