Commit e99a7cfe authored by Sean Young's avatar Sean Young Committed by Mauro Carvalho Chehab

[media] iguanair: reuse existing urb callback for command responses

Rather than using usb_interrupt_msg() to receive responses, reuse the
urb callback we already have in place.
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent c6afbf29
...@@ -35,7 +35,7 @@ struct iguanair { ...@@ -35,7 +35,7 @@ struct iguanair {
struct device *dev; struct device *dev;
struct usb_device *udev; struct usb_device *udev;
int pipe_in, pipe_out; int pipe_out;
uint8_t bufsize; uint8_t bufsize;
uint8_t version[2]; uint8_t version[2];
...@@ -82,11 +82,6 @@ struct packet { ...@@ -82,11 +82,6 @@ struct packet {
uint8_t cmd; uint8_t cmd;
}; };
struct response_packet {
struct packet header;
uint8_t data[4];
};
struct send_packet { struct send_packet {
struct packet header; struct packet header;
uint8_t length; uint8_t length;
...@@ -100,6 +95,26 @@ static void process_ir_data(struct iguanair *ir, unsigned len) ...@@ -100,6 +95,26 @@ static void process_ir_data(struct iguanair *ir, unsigned len)
{ {
if (len >= 4 && ir->buf_in[0] == 0 && ir->buf_in[1] == 0) { if (len >= 4 && ir->buf_in[0] == 0 && ir->buf_in[1] == 0) {
switch (ir->buf_in[3]) { switch (ir->buf_in[3]) {
case CMD_GET_VERSION:
if (len == 6) {
ir->version[0] = ir->buf_in[4];
ir->version[1] = ir->buf_in[5];
complete(&ir->completion);
}
break;
case CMD_GET_BUFSIZE:
if (len >= 5) {
ir->bufsize = ir->buf_in[4];
complete(&ir->completion);
}
break;
case CMD_GET_FEATURES:
if (len > 5) {
if (ir->version[0] >= 4)
ir->cycle_overhead = ir->buf_in[5];
complete(&ir->completion);
}
break;
case CMD_TX_OVERFLOW: case CMD_TX_OVERFLOW:
ir->tx_overflow = true; ir->tx_overflow = true;
case CMD_RECEIVER_OFF: case CMD_RECEIVER_OFF:
...@@ -169,31 +184,22 @@ static void iguanair_rx(struct urb *urb) ...@@ -169,31 +184,22 @@ static void iguanair_rx(struct urb *urb)
usb_submit_urb(urb, GFP_ATOMIC); usb_submit_urb(urb, GFP_ATOMIC);
} }
static int iguanair_send(struct iguanair *ir, void *data, unsigned size, static int iguanair_send(struct iguanair *ir, void *data, unsigned size)
struct response_packet *response, unsigned *res_len)
{ {
unsigned offset, len;
int rc, transferred; int rc, transferred;
for (offset = 0; offset < size; offset += MAX_PACKET_SIZE) { INIT_COMPLETION(ir->completion);
len = min(size - offset, MAX_PACKET_SIZE);
if (ir->tx_overflow)
return -EOVERFLOW;
rc = usb_interrupt_msg(ir->udev, ir->pipe_out, data + offset, rc = usb_interrupt_msg(ir->udev, ir->pipe_out, data, size,
len, &transferred, TIMEOUT); &transferred, TIMEOUT);
if (rc) if (rc)
return rc; return rc;
if (transferred != len) if (transferred != size)
return -EIO; return -EIO;
}
if (response) { if (wait_for_completion_timeout(&ir->completion, TIMEOUT) == 0)
rc = usb_interrupt_msg(ir->udev, ir->pipe_in, response, return -ETIMEDOUT;
sizeof(*response), res_len, TIMEOUT);
}
return rc; return rc;
} }
...@@ -201,66 +207,40 @@ static int iguanair_send(struct iguanair *ir, void *data, unsigned size, ...@@ -201,66 +207,40 @@ static int iguanair_send(struct iguanair *ir, void *data, unsigned size,
static int iguanair_get_features(struct iguanair *ir) static int iguanair_get_features(struct iguanair *ir)
{ {
struct packet packet; struct packet packet;
struct response_packet response; int rc;
int rc, len;
packet.start = 0; packet.start = 0;
packet.direction = DIR_OUT; packet.direction = DIR_OUT;
packet.cmd = CMD_GET_VERSION; packet.cmd = CMD_GET_VERSION;
rc = iguanair_send(ir, &packet, sizeof(packet), &response, &len); rc = iguanair_send(ir, &packet, sizeof(packet));
if (rc) { if (rc) {
dev_info(ir->dev, "failed to get version\n"); dev_info(ir->dev, "failed to get version\n");
goto out; goto out;
} }
if (len != 6) {
dev_info(ir->dev, "failed to get version\n");
rc = -EIO;
goto out;
}
ir->version[0] = response.data[0];
ir->version[1] = response.data[1];
ir->bufsize = 150; ir->bufsize = 150;
ir->cycle_overhead = 65; ir->cycle_overhead = 65;
packet.cmd = CMD_GET_BUFSIZE; packet.cmd = CMD_GET_BUFSIZE;
rc = iguanair_send(ir, &packet, sizeof(packet), &response, &len); rc = iguanair_send(ir, &packet, sizeof(packet));
if (rc) { if (rc) {
dev_info(ir->dev, "failed to get buffer size\n"); dev_info(ir->dev, "failed to get buffer size\n");
goto out; goto out;
} }
if (len != 5) {
dev_info(ir->dev, "failed to get buffer size\n");
rc = -EIO;
goto out;
}
ir->bufsize = response.data[0];
if (ir->version[0] == 0 || ir->version[1] == 0) if (ir->version[0] == 0 || ir->version[1] == 0)
goto out; goto out;
packet.cmd = CMD_GET_FEATURES; packet.cmd = CMD_GET_FEATURES;
rc = iguanair_send(ir, &packet, sizeof(packet), &response, &len); rc = iguanair_send(ir, &packet, sizeof(packet));
if (rc) { if (rc) {
dev_info(ir->dev, "failed to get features\n"); dev_info(ir->dev, "failed to get features\n");
goto out; goto out;
} }
if (len < 5) {
dev_info(ir->dev, "failed to get features\n");
rc = -EIO;
goto out;
}
if (len > 5 && ir->version[0] >= 4)
ir->cycle_overhead = response.data[1];
out: out:
return rc; return rc;
} }
...@@ -269,17 +249,8 @@ static int iguanair_receiver(struct iguanair *ir, bool enable) ...@@ -269,17 +249,8 @@ static int iguanair_receiver(struct iguanair *ir, bool enable)
{ {
struct packet packet = { 0, DIR_OUT, enable ? struct packet packet = { 0, DIR_OUT, enable ?
CMD_RECEIVER_ON : CMD_RECEIVER_OFF }; CMD_RECEIVER_ON : CMD_RECEIVER_OFF };
int rc;
INIT_COMPLETION(ir->completion);
rc = iguanair_send(ir, &packet, sizeof(packet), NULL, NULL);
if (rc)
return rc;
wait_for_completion_timeout(&ir->completion, TIMEOUT);
return 0; return iguanair_send(ir, &packet, sizeof(packet));
} }
/* /*
...@@ -406,17 +377,10 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count) ...@@ -406,17 +377,10 @@ static int iguanair_tx(struct rc_dev *dev, unsigned *txbuf, unsigned count)
ir->tx_overflow = false; ir->tx_overflow = false;
INIT_COMPLETION(ir->completion); rc = iguanair_send(ir, packet, size + 8);
rc = iguanair_send(ir, packet, size + 8, NULL, NULL);
if (rc == 0) { if (rc == 0 && ir->tx_overflow)
wait_for_completion_timeout(&ir->completion, TIMEOUT); rc = -EOVERFLOW;
if (ir->tx_overflow)
rc = -EOVERFLOW;
}
ir->tx_overflow = false;
if (ir->receiver_on) { if (ir->receiver_on) {
if (iguanair_receiver(ir, true)) if (iguanair_receiver(ir, true))
...@@ -437,8 +401,6 @@ static int iguanair_open(struct rc_dev *rdev) ...@@ -437,8 +401,6 @@ static int iguanair_open(struct rc_dev *rdev)
mutex_lock(&ir->lock); mutex_lock(&ir->lock);
usb_submit_urb(ir->urb_in, GFP_KERNEL);
BUG_ON(ir->receiver_on); BUG_ON(ir->receiver_on);
rc = iguanair_receiver(ir, true); rc = iguanair_receiver(ir, true);
...@@ -462,8 +424,6 @@ static void iguanair_close(struct rc_dev *rdev) ...@@ -462,8 +424,6 @@ static void iguanair_close(struct rc_dev *rdev)
if (rc) if (rc)
dev_warn(ir->dev, "failed to disable receiver: %d\n", rc); dev_warn(ir->dev, "failed to disable receiver: %d\n", rc);
usb_kill_urb(ir->urb_in);
mutex_unlock(&ir->lock); mutex_unlock(&ir->lock);
} }
...@@ -473,7 +433,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf, ...@@ -473,7 +433,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
struct usb_device *udev = interface_to_usbdev(intf); struct usb_device *udev = interface_to_usbdev(intf);
struct iguanair *ir; struct iguanair *ir;
struct rc_dev *rc; struct rc_dev *rc;
int ret; int ret, pipein;
struct usb_host_interface *idesc; struct usb_host_interface *idesc;
ir = kzalloc(sizeof(*ir), GFP_KERNEL); ir = kzalloc(sizeof(*ir), GFP_KERNEL);
...@@ -483,7 +443,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf, ...@@ -483,7 +443,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
goto out; goto out;
} }
ir->buf_in = usb_alloc_coherent(udev, MAX_PACKET_SIZE, GFP_ATOMIC, ir->buf_in = usb_alloc_coherent(udev, MAX_PACKET_SIZE, GFP_KERNEL,
&ir->dma_in); &ir->dma_in);
ir->urb_in = usb_alloc_urb(0, GFP_KERNEL); ir->urb_in = usb_alloc_urb(0, GFP_KERNEL);
...@@ -502,25 +462,28 @@ static int __devinit iguanair_probe(struct usb_interface *intf, ...@@ -502,25 +462,28 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
ir->rc = rc; ir->rc = rc;
ir->dev = &intf->dev; ir->dev = &intf->dev;
ir->udev = udev; ir->udev = udev;
ir->pipe_in = usb_rcvintpipe(udev,
idesc->endpoint[0].desc.bEndpointAddress);
ir->pipe_out = usb_sndintpipe(udev, ir->pipe_out = usb_sndintpipe(udev,
idesc->endpoint[1].desc.bEndpointAddress); idesc->endpoint[1].desc.bEndpointAddress);
mutex_init(&ir->lock); mutex_init(&ir->lock);
init_completion(&ir->completion); init_completion(&ir->completion);
ret = iguanair_get_features(ir); pipein = usb_rcvintpipe(udev, idesc->endpoint[0].desc.bEndpointAddress);
if (ret) { usb_fill_int_urb(ir->urb_in, udev, pipein, ir->buf_in,
dev_warn(&intf->dev, "failed to get device features");
goto out;
}
usb_fill_int_urb(ir->urb_in, ir->udev, ir->pipe_in, ir->buf_in,
MAX_PACKET_SIZE, iguanair_rx, ir, MAX_PACKET_SIZE, iguanair_rx, ir,
idesc->endpoint[0].desc.bInterval); idesc->endpoint[0].desc.bInterval);
ir->urb_in->transfer_dma = ir->dma_in; ir->urb_in->transfer_dma = ir->dma_in;
ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
ret = usb_submit_urb(ir->urb_in, GFP_KERNEL);
if (ret) {
dev_warn(&intf->dev, "failed to submit urb: %d\n", ret);
goto out;
}
ret = iguanair_get_features(ir);
if (ret)
goto out2;
snprintf(ir->name, sizeof(ir->name), snprintf(ir->name, sizeof(ir->name),
"IguanaWorks USB IR Transceiver version %d.%d", "IguanaWorks USB IR Transceiver version %d.%d",
ir->version[0], ir->version[1]); ir->version[0], ir->version[1]);
...@@ -547,7 +510,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf, ...@@ -547,7 +510,7 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
ret = rc_register_device(rc); ret = rc_register_device(rc);
if (ret < 0) { if (ret < 0) {
dev_err(&intf->dev, "failed to register rc device %d", ret); dev_err(&intf->dev, "failed to register rc device %d", ret);
goto out; goto out2;
} }
usb_set_intfdata(intf, ir); usb_set_intfdata(intf, ir);
...@@ -555,6 +518,8 @@ static int __devinit iguanair_probe(struct usb_interface *intf, ...@@ -555,6 +518,8 @@ static int __devinit iguanair_probe(struct usb_interface *intf,
dev_info(&intf->dev, "Registered %s", ir->name); dev_info(&intf->dev, "Registered %s", ir->name);
return 0; return 0;
out2:
usb_kill_urb(ir->urb_in);
out: out:
if (ir) { if (ir) {
usb_free_urb(ir->urb_in); usb_free_urb(ir->urb_in);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment