Lines Matching full:ir
3 * IguanaWorks USB IR Transceiver support
79 static void process_ir_data(struct iguanair *ir, unsigned len) in process_ir_data() argument
81 if (len >= 4 && ir->buf_in[0] == 0 && ir->buf_in[1] == 0) { in process_ir_data()
82 switch (ir->buf_in[3]) { in process_ir_data()
85 ir->version = (ir->buf_in[5] << 8) | in process_ir_data()
86 ir->buf_in[4]; in process_ir_data()
87 complete(&ir->completion); in process_ir_data()
92 ir->bufsize = ir->buf_in[4]; in process_ir_data()
93 complete(&ir->completion); in process_ir_data()
98 ir->cycle_overhead = ir->buf_in[5]; in process_ir_data()
99 complete(&ir->completion); in process_ir_data()
103 ir->tx_overflow = true; in process_ir_data()
108 complete(&ir->completion); in process_ir_data()
111 dev_warn(ir->dev, "receive overflow\n"); in process_ir_data()
112 ir_raw_event_overflow(ir->rc); in process_ir_data()
115 dev_warn(ir->dev, "control code %02x received\n", in process_ir_data()
116 ir->buf_in[3]); in process_ir_data()
125 if (ir->buf_in[i] == 0x80) { in process_ir_data()
129 rawir.pulse = (ir->buf_in[i] & 0x80) == 0; in process_ir_data()
130 rawir.duration = ((ir->buf_in[i] & 0x7f) + 1) * in process_ir_data()
134 if (ir_raw_event_store_with_filter(ir->rc, &rawir)) in process_ir_data()
139 ir_raw_event_handle(ir->rc); in process_ir_data()
145 struct iguanair *ir; in iguanair_rx() local
151 ir = urb->context; in iguanair_rx()
152 if (!ir) in iguanair_rx()
157 process_ir_data(ir, urb->actual_length); in iguanair_rx()
165 dev_dbg(ir->dev, "Error: urb status = %d\n", urb->status); in iguanair_rx()
171 dev_warn(ir->dev, "failed to resubmit urb: %d\n", rc); in iguanair_rx()
176 struct iguanair *ir = urb->context; in iguanair_irq_out() local
179 dev_dbg(ir->dev, "Error: out urb status = %d\n", urb->status); in iguanair_irq_out()
182 if (urb->status == 0 && ir->packet->header.cmd == CMD_NOP) in iguanair_irq_out()
183 complete(&ir->completion); in iguanair_irq_out()
186 static int iguanair_send(struct iguanair *ir, unsigned size) in iguanair_send() argument
190 reinit_completion(&ir->completion); in iguanair_send()
192 ir->urb_out->transfer_buffer_length = size; in iguanair_send()
193 rc = usb_submit_urb(ir->urb_out, GFP_KERNEL); in iguanair_send()
197 if (wait_for_completion_timeout(&ir->completion, TIMEOUT) == 0) in iguanair_send()
203 static int iguanair_get_features(struct iguanair *ir) in iguanair_get_features() argument
212 ir->packet->header.start = 0; in iguanair_get_features()
213 ir->packet->header.direction = DIR_OUT; in iguanair_get_features()
214 ir->packet->header.cmd = CMD_NOP; in iguanair_get_features()
215 iguanair_send(ir, sizeof(ir->packet->header)); in iguanair_get_features()
217 ir->packet->header.cmd = CMD_GET_VERSION; in iguanair_get_features()
218 rc = iguanair_send(ir, sizeof(ir->packet->header)); in iguanair_get_features()
220 dev_info(ir->dev, "failed to get version\n"); in iguanair_get_features()
224 if (ir->version < 0x205) { in iguanair_get_features()
225 dev_err(ir->dev, "firmware 0x%04x is too old\n", ir->version); in iguanair_get_features()
230 ir->bufsize = 150; in iguanair_get_features()
231 ir->cycle_overhead = 65; in iguanair_get_features()
233 ir->packet->header.cmd = CMD_GET_BUFSIZE; in iguanair_get_features()
235 rc = iguanair_send(ir, sizeof(ir->packet->header)); in iguanair_get_features()
237 dev_info(ir->dev, "failed to get buffer size\n"); in iguanair_get_features()
241 if (ir->bufsize > BUF_SIZE) { in iguanair_get_features()
242 dev_info(ir->dev, "buffer size %u larger than expected\n", in iguanair_get_features()
243 ir->bufsize); in iguanair_get_features()
244 ir->bufsize = BUF_SIZE; in iguanair_get_features()
247 ir->packet->header.cmd = CMD_GET_FEATURES; in iguanair_get_features()
249 rc = iguanair_send(ir, sizeof(ir->packet->header)); in iguanair_get_features()
251 dev_info(ir->dev, "failed to get features\n"); in iguanair_get_features()
256 static int iguanair_receiver(struct iguanair *ir, bool enable) in iguanair_receiver() argument
258 ir->packet->header.start = 0; in iguanair_receiver()
259 ir->packet->header.direction = DIR_OUT; in iguanair_receiver()
260 ir->packet->header.cmd = enable ? CMD_RECEIVER_ON : CMD_RECEIVER_OFF; in iguanair_receiver()
262 return iguanair_send(ir, sizeof(ir->packet->header)); in iguanair_receiver()
273 struct iguanair *ir = dev->priv; in iguanair_set_tx_carrier() local
278 if (carrier != ir->carrier) { in iguanair_set_tx_carrier()
281 ir->carrier = carrier; in iguanair_set_tx_carrier()
284 ir->cycle_overhead; in iguanair_set_tx_carrier()
302 ir->packet->busy7 = (4 - sevens) * 2; in iguanair_set_tx_carrier()
303 ir->packet->busy4 = 110 - fours; in iguanair_set_tx_carrier()
311 struct iguanair *ir = dev->priv; in iguanair_set_tx_mask() local
316 ir->packet->channels = mask << 4; in iguanair_set_tx_mask()
323 struct iguanair *ir = dev->priv; in iguanair_tx() local
329 periods = DIV_ROUND_CLOSEST(txbuf[i] * ir->carrier, 1000000); in iguanair_tx()
332 if (size >= ir->bufsize) { in iguanair_tx()
336 ir->packet->payload[size++] = p | ((i & 1) ? 0x80 : 0); in iguanair_tx()
341 ir->packet->header.start = 0; in iguanair_tx()
342 ir->packet->header.direction = DIR_OUT; in iguanair_tx()
343 ir->packet->header.cmd = CMD_SEND; in iguanair_tx()
344 ir->packet->length = size; in iguanair_tx()
346 ir->tx_overflow = false; in iguanair_tx()
348 rc = iguanair_send(ir, sizeof(*ir->packet) + size); in iguanair_tx()
350 if (rc == 0 && ir->tx_overflow) in iguanair_tx()
359 struct iguanair *ir = rdev->priv; in iguanair_open() local
362 rc = iguanair_receiver(ir, true); in iguanair_open()
364 ir->receiver_on = true; in iguanair_open()
371 struct iguanair *ir = rdev->priv; in iguanair_close() local
374 rc = iguanair_receiver(ir, false); in iguanair_close()
375 ir->receiver_on = false; in iguanair_close()
377 dev_warn(ir->dev, "failed to disable receiver: %d\n", rc); in iguanair_close()
384 struct iguanair *ir; in iguanair_probe() local
393 ir = kzalloc(sizeof(*ir), GFP_KERNEL); in iguanair_probe()
395 if (!ir || !rc) { in iguanair_probe()
400 ir->buf_in = usb_alloc_coherent(udev, MAX_IN_PACKET, GFP_KERNEL, in iguanair_probe()
401 &ir->dma_in); in iguanair_probe()
402 ir->packet = usb_alloc_coherent(udev, MAX_OUT_PACKET, GFP_KERNEL, in iguanair_probe()
403 &ir->dma_out); in iguanair_probe()
404 ir->urb_in = usb_alloc_urb(0, GFP_KERNEL); in iguanair_probe()
405 ir->urb_out = usb_alloc_urb(0, GFP_KERNEL); in iguanair_probe()
407 if (!ir->buf_in || !ir->packet || !ir->urb_in || !ir->urb_out || in iguanair_probe()
414 ir->rc = rc; in iguanair_probe()
415 ir->dev = &intf->dev; in iguanair_probe()
416 ir->udev = udev; in iguanair_probe()
418 init_completion(&ir->completion); in iguanair_probe()
421 usb_fill_int_urb(ir->urb_out, udev, pipeout, ir->packet, MAX_OUT_PACKET, in iguanair_probe()
422 iguanair_irq_out, ir, 1); in iguanair_probe()
423 ir->urb_out->transfer_dma = ir->dma_out; in iguanair_probe()
424 ir->urb_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in iguanair_probe()
427 usb_fill_int_urb(ir->urb_in, udev, pipein, ir->buf_in, MAX_IN_PACKET, in iguanair_probe()
428 iguanair_rx, ir, 1); in iguanair_probe()
429 ir->urb_in->transfer_dma = ir->dma_in; in iguanair_probe()
430 ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in iguanair_probe()
432 ret = usb_submit_urb(ir->urb_in, GFP_KERNEL); in iguanair_probe()
438 ret = iguanair_get_features(ir); in iguanair_probe()
442 snprintf(ir->name, sizeof(ir->name), in iguanair_probe()
443 "IguanaWorks USB IR Transceiver version 0x%04x", ir->version); in iguanair_probe()
445 usb_make_path(ir->udev, ir->phys, sizeof(ir->phys)); in iguanair_probe()
447 rc->device_name = ir->name; in iguanair_probe()
448 rc->input_phys = ir->phys; in iguanair_probe()
449 usb_to_input_id(ir->udev, &rc->input_id); in iguanair_probe()
452 rc->priv = ir; in iguanair_probe()
474 usb_set_intfdata(intf, ir); in iguanair_probe()
478 usb_kill_urb(ir->urb_in); in iguanair_probe()
479 usb_kill_urb(ir->urb_out); in iguanair_probe()
481 if (ir) { in iguanair_probe()
482 usb_free_urb(ir->urb_in); in iguanair_probe()
483 usb_free_urb(ir->urb_out); in iguanair_probe()
484 usb_free_coherent(udev, MAX_IN_PACKET, ir->buf_in, ir->dma_in); in iguanair_probe()
485 usb_free_coherent(udev, MAX_OUT_PACKET, ir->packet, in iguanair_probe()
486 ir->dma_out); in iguanair_probe()
489 kfree(ir); in iguanair_probe()
495 struct iguanair *ir = usb_get_intfdata(intf); in iguanair_disconnect() local
497 rc_unregister_device(ir->rc); in iguanair_disconnect()
499 usb_kill_urb(ir->urb_in); in iguanair_disconnect()
500 usb_kill_urb(ir->urb_out); in iguanair_disconnect()
501 usb_free_urb(ir->urb_in); in iguanair_disconnect()
502 usb_free_urb(ir->urb_out); in iguanair_disconnect()
503 usb_free_coherent(ir->udev, MAX_IN_PACKET, ir->buf_in, ir->dma_in); in iguanair_disconnect()
504 usb_free_coherent(ir->udev, MAX_OUT_PACKET, ir->packet, ir->dma_out); in iguanair_disconnect()
505 kfree(ir); in iguanair_disconnect()
510 struct iguanair *ir = usb_get_intfdata(intf); in iguanair_suspend() local
513 if (ir->receiver_on) { in iguanair_suspend()
514 rc = iguanair_receiver(ir, false); in iguanair_suspend()
516 dev_warn(ir->dev, "failed to disable receiver for suspend\n"); in iguanair_suspend()
519 usb_kill_urb(ir->urb_in); in iguanair_suspend()
520 usb_kill_urb(ir->urb_out); in iguanair_suspend()
527 struct iguanair *ir = usb_get_intfdata(intf); in iguanair_resume() local
530 rc = usb_submit_urb(ir->urb_in, GFP_KERNEL); in iguanair_resume()
534 if (ir->receiver_on) { in iguanair_resume()
535 rc = iguanair_receiver(ir, true); in iguanair_resume()
537 dev_warn(ir->dev, "failed to enable receiver after resume\n"); in iguanair_resume()
561 MODULE_DESCRIPTION("IguanaWorks USB IR Transceiver");