15 #include <linux/slab.h>
18 static int st5481_isoc_flatten(
struct urb *
urb);
28 static void usb_next_ctrl_msg(
struct urb *
urb,
38 if ((r_index = fifo_remove(&ctrl->
msg_fifo.f)) < 0) {
43 (
unsigned char *)&ctrl->
msg_fifo.data[r_index];
45 DBG(1,
"request=0x%02x,value=0x%04x,index=%x",
46 ((
struct ctrl_msg *)urb->setup_packet)->dr.bRequest,
47 ((
struct ctrl_msg *)urb->setup_packet)->dr.wValue,
48 ((
struct ctrl_msg *)urb->setup_packet)->dr.wIndex);
68 if ((w_index = fifo_add(&ctrl->
msg_fifo.f)) < 0) {
69 WARNING(
"control msg FIFO full");
72 ctrl_msg = &ctrl->
msg_fifo.data[w_index];
74 ctrl_msg->
dr.bRequestType = requesttype;
78 ctrl_msg->
dr.wLength = 0;
82 usb_next_ctrl_msg(ctrl->
urb, adapter);
89 u8 request,
u16 value,
92 usb_ctrl_msg(adapter, request,
94 value, 0, complete, context);
104 DBG(1,
"pipe=%02x", pipe);
106 usb_ctrl_msg(adapter,
108 0, pipe, complete, context);
118 DBG(8,
"command=%s", ST5481_CMD_string(command));
128 static void usb_ctrl_complete(
struct urb *urb)
135 switch (urb->status) {
139 DBG(1,
"urb killed status %d", urb->status);
142 WARNING(
"urb status %d", urb->status);
147 ctrl_msg = (
struct ctrl_msg *)urb->setup_packet;
161 usb_next_ctrl_msg(urb, adapter);
175 static void usb_int_complete(
struct urb *urb)
177 u8 *
data = urb->transfer_buffer;
183 switch (urb->status) {
191 DBG(2,
"urb shutting down with status: %d", urb->status);
194 WARNING(
"nonzero urb status received: %d", urb->status);
201 if (urb->actual_length == 0) {
205 irqbyte = data[
MPINT];
219 irqbyte = data[
MPINT];
223 for (j = 0; j < 2; j++)
224 adapter->
bcs[j].b_out.flow_event |= data[
FFINT_B1 + j];
226 urb->actual_length = 0;
231 WARNING(
"usb_submit_urb failed with result %d", status);
244 struct usb_host_interface *altsetting =
NULL;
253 WARNING(
"reset_configuration failed,status=%d", status);
264 if (altsetting->desc.bNumEndpoints != 7) {
265 WARNING(
"expecting 7 got %d endpoints!", altsetting->desc.bNumEndpoints);
275 WARNING(
"usb_set_interface failed,status=%d", status);
287 usb_fill_control_urb(urb, dev,
288 usb_sndctrlpipe(dev, 0),
289 NULL,
NULL, 0, usb_ctrl_complete, adapter);
306 endpoint = &altsetting->endpoint[
EP_INT-1];
309 usb_fill_int_urb(urb, dev,
310 usb_rcvintpipe(dev, endpoint->desc.bEndpointAddress),
312 usb_int_complete, adapter,
313 endpoint->desc.bInterval);
346 static const u8 init_cmd_table[] = {
374 while ((request = init_cmd_table[i++])) {
375 value = init_cmd_table[i++];
396 fill_isoc_urb(
struct urb *urb,
struct usb_device *
dev,
397 unsigned int pipe,
void *
buf,
int num_packets,
398 int packet_size, usb_complete_t complete,
406 urb->transfer_buffer =
buf;
407 urb->number_of_packets = num_packets;
408 urb->transfer_buffer_length = num_packets * packet_size;
409 urb->actual_length = 0;
412 urb->transfer_flags = URB_ISO_ASAP;
413 for (k = 0; k < num_packets; k++) {
414 urb->iso_frame_desc[
k].offset = packet_size *
k;
415 urb->iso_frame_desc[
k].length = packet_size;
416 urb->iso_frame_desc[
k].actual_length = 0;
422 unsigned int pipe,
int num_packets,
424 usb_complete_t complete,
void *context)
429 for (j = 0; j < 2; j++) {
441 fill_isoc_urb(urb[j], dev, pipe, buf,
442 num_packets, packet_size, complete,
448 for (j = 0; j < 2; j++) {
451 urb[
j]->transfer_buffer =
NULL;
463 for (j = 0; j < 2; j++) {
478 static void usb_in_complete(
struct urb *urb)
486 switch (urb->status) {
490 DBG(1,
"urb killed status %d", urb->status);
493 WARNING(
"urb status %d", urb->status);
500 len = st5481_isoc_flatten(urb);
501 ptr = urb->transfer_buffer;
516 DBG(4,
"count=%d", status);
518 if (!(skb = dev_alloc_skb(status))) {
519 WARNING(
"receive out of memory\n");
527 INFO(
"framing error");
529 INFO(
"length error");
534 urb->dev = in->
adapter->usb_dev;
535 urb->actual_length = 0;
542 struct usb_device *dev = in->
adapter->usb_dev;
553 usb_rcvisocpipe(dev, in->
ep),
556 usb_in_complete, in);
578 static int st5481_isoc_flatten(
struct urb *urb)
580 struct usb_iso_packet_descriptor *pipd, *
pend;
584 if (urb->status < 0) {
587 for (pipd = &urb->iso_frame_desc[0],
588 pend = &urb->iso_frame_desc[urb->number_of_packets],
589 dst = urb->transfer_buffer;
593 if (pipd->status < 0) {
594 return (pipd->status);
597 len = pipd->actual_length;
598 pipd->actual_length = 0;
599 src = urb->transfer_buffer + pipd->offset;
612 return (dst - (
unsigned char *)urb->transfer_buffer);
615 static void st5481_start_rcv(
void *context)
631 if (in->
mode == mode)
651 st5481_start_rcv(in);