Lines Matching +full:0 +full:- +full:dev
1 // SPDX-License-Identifier: GPL-2.0-or-later
11 #include <media/v4l2-device.h>
12 #include <media/v4l2-ioctl.h>
13 #include <media/v4l2-ctrls.h>
14 #include <media/v4l2-event.h>
15 #include <media/videobuf2-v4l2.h>
16 #include <media/videobuf2-vmalloc.h>
19 * Used Avago MGA-81563 RF amplifier could be destroyed pretty easily with too
29 CMD_SET_TRANSCEIVER_MODE = 0x01,
30 CMD_SAMPLE_RATE_SET = 0x06,
31 CMD_BASEBAND_FILTER_BANDWIDTH_SET = 0x07,
32 CMD_BOARD_ID_READ = 0x0e,
33 CMD_VERSION_STRING_READ = 0x0f,
34 CMD_SET_FREQ = 0x10,
35 CMD_AMP_ENABLE = 0x11,
36 CMD_SET_LNA_GAIN = 0x13,
37 CMD_SET_VGA_GAIN = 0x14,
38 CMD_SET_TXVGA_GAIN = 0x15,
42 * bEndpointAddress 0x81 EP 1 IN
44 * wMaxPacketSize 0x0200 1x 512 bytes
51 .tuner = 0,
53 .index = 0,
64 .index = 0,
111 struct device *dev; member
177 _t, _r, _v & 0xff, _v >> 8, _i & 0xff, \
178 _i >> 8, _l & 0xff, _l >> 8, _direction, _l, _b); \
182 static int hackrf_ctrl_msg(struct hackrf_dev *dev, u8 request, u16 value, in hackrf_ctrl_msg() argument
195 pipe = usb_sndctrlpipe(dev->udev, 0); in hackrf_ctrl_msg()
203 pipe = usb_rcvctrlpipe(dev->udev, 0); in hackrf_ctrl_msg()
207 dev_err(dev->dev, "Unknown command %02x\n", request); in hackrf_ctrl_msg()
208 ret = -EINVAL; in hackrf_ctrl_msg()
214 memcpy(dev->buf, data, size); in hackrf_ctrl_msg()
216 ret = usb_control_msg(dev->udev, pipe, request, requesttype, value, in hackrf_ctrl_msg()
217 index, dev->buf, size, 1000); in hackrf_ctrl_msg()
218 hackrf_dbg_usb_control_msg(dev->dev, request, requesttype, value, in hackrf_ctrl_msg()
219 index, dev->buf, size); in hackrf_ctrl_msg()
220 if (ret < 0) { in hackrf_ctrl_msg()
221 dev_err(dev->dev, "usb_control_msg() failed %d request %02x\n", in hackrf_ctrl_msg()
228 memcpy(data, dev->buf, size); in hackrf_ctrl_msg()
230 return 0; in hackrf_ctrl_msg()
235 static int hackrf_set_params(struct hackrf_dev *dev) in hackrf_set_params() argument
237 struct usb_interface *intf = dev->intf; in hackrf_set_params()
241 const bool rx = test_bit(RX_ON, &dev->flags); in hackrf_set_params()
242 const bool tx = test_bit(TX_ON, &dev->flags); in hackrf_set_params()
265 dev_dbg(&intf->dev, "device is sleeping\n"); in hackrf_set_params()
266 return 0; in hackrf_set_params()
270 if (rx && test_and_clear_bit(RX_ADC_FREQUENCY, &dev->flags)) { in hackrf_set_params()
271 dev_dbg(&intf->dev, "RX ADC frequency=%u Hz\n", dev->f_adc); in hackrf_set_params()
272 uitmp1 = dev->f_adc; in hackrf_set_params()
274 set_bit(TX_DAC_FREQUENCY, &dev->flags); in hackrf_set_params()
275 } else if (tx && test_and_clear_bit(TX_DAC_FREQUENCY, &dev->flags)) { in hackrf_set_params()
276 dev_dbg(&intf->dev, "TX DAC frequency=%u Hz\n", dev->f_dac); in hackrf_set_params()
277 uitmp1 = dev->f_dac; in hackrf_set_params()
279 set_bit(RX_ADC_FREQUENCY, &dev->flags); in hackrf_set_params()
281 uitmp1 = uitmp2 = 0; in hackrf_set_params()
284 buf[0] = (uitmp1 >> 0) & 0xff; in hackrf_set_params()
285 buf[1] = (uitmp1 >> 8) & 0xff; in hackrf_set_params()
286 buf[2] = (uitmp1 >> 16) & 0xff; in hackrf_set_params()
287 buf[3] = (uitmp1 >> 24) & 0xff; in hackrf_set_params()
288 buf[4] = (uitmp2 >> 0) & 0xff; in hackrf_set_params()
289 buf[5] = (uitmp2 >> 8) & 0xff; in hackrf_set_params()
290 buf[6] = (uitmp2 >> 16) & 0xff; in hackrf_set_params()
291 buf[7] = (uitmp2 >> 24) & 0xff; in hackrf_set_params()
292 ret = hackrf_ctrl_msg(dev, CMD_SAMPLE_RATE_SET, 0, 0, buf, 8); in hackrf_set_params()
298 if (rx && test_and_clear_bit(RX_BANDWIDTH, &dev->flags)) { in hackrf_set_params()
299 if (dev->rx_bandwidth_auto->val == true) in hackrf_set_params()
300 uitmp = dev->f_adc; in hackrf_set_params()
302 uitmp = dev->rx_bandwidth->val; in hackrf_set_params()
304 for (i = 0; i < ARRAY_SIZE(bandwidth_lut); i++) { in hackrf_set_params()
310 dev->rx_bandwidth->val = uitmp; in hackrf_set_params()
311 dev->rx_bandwidth->cur.val = uitmp; in hackrf_set_params()
312 dev_dbg(&intf->dev, "RX bandwidth selected=%u\n", uitmp); in hackrf_set_params()
313 set_bit(TX_BANDWIDTH, &dev->flags); in hackrf_set_params()
314 } else if (tx && test_and_clear_bit(TX_BANDWIDTH, &dev->flags)) { in hackrf_set_params()
315 if (dev->tx_bandwidth_auto->val == true) in hackrf_set_params()
316 uitmp = dev->f_dac; in hackrf_set_params()
318 uitmp = dev->tx_bandwidth->val; in hackrf_set_params()
320 for (i = 0; i < ARRAY_SIZE(bandwidth_lut); i++) { in hackrf_set_params()
326 dev->tx_bandwidth->val = uitmp; in hackrf_set_params()
327 dev->tx_bandwidth->cur.val = uitmp; in hackrf_set_params()
328 dev_dbg(&intf->dev, "TX bandwidth selected=%u\n", uitmp); in hackrf_set_params()
329 set_bit(RX_BANDWIDTH, &dev->flags); in hackrf_set_params()
331 uitmp = 0; in hackrf_set_params()
334 uitmp1 = uitmp2 = 0; in hackrf_set_params()
335 uitmp1 |= ((uitmp >> 0) & 0xff) << 0; in hackrf_set_params()
336 uitmp1 |= ((uitmp >> 8) & 0xff) << 8; in hackrf_set_params()
337 uitmp2 |= ((uitmp >> 16) & 0xff) << 0; in hackrf_set_params()
338 uitmp2 |= ((uitmp >> 24) & 0xff) << 8; in hackrf_set_params()
339 ret = hackrf_ctrl_msg(dev, CMD_BASEBAND_FILTER_BANDWIDTH_SET, in hackrf_set_params()
340 uitmp1, uitmp2, NULL, 0); in hackrf_set_params()
346 if (rx && test_and_clear_bit(RX_RF_FREQUENCY, &dev->flags)) { in hackrf_set_params()
347 dev_dbg(&intf->dev, "RX RF frequency=%u Hz\n", dev->f_rx); in hackrf_set_params()
348 uitmp1 = dev->f_rx / 1000000; in hackrf_set_params()
349 uitmp2 = dev->f_rx % 1000000; in hackrf_set_params()
350 set_bit(TX_RF_FREQUENCY, &dev->flags); in hackrf_set_params()
351 } else if (tx && test_and_clear_bit(TX_RF_FREQUENCY, &dev->flags)) { in hackrf_set_params()
352 dev_dbg(&intf->dev, "TX RF frequency=%u Hz\n", dev->f_tx); in hackrf_set_params()
353 uitmp1 = dev->f_tx / 1000000; in hackrf_set_params()
354 uitmp2 = dev->f_tx % 1000000; in hackrf_set_params()
355 set_bit(RX_RF_FREQUENCY, &dev->flags); in hackrf_set_params()
357 uitmp1 = uitmp2 = 0; in hackrf_set_params()
360 buf[0] = (uitmp1 >> 0) & 0xff; in hackrf_set_params()
361 buf[1] = (uitmp1 >> 8) & 0xff; in hackrf_set_params()
362 buf[2] = (uitmp1 >> 16) & 0xff; in hackrf_set_params()
363 buf[3] = (uitmp1 >> 24) & 0xff; in hackrf_set_params()
364 buf[4] = (uitmp2 >> 0) & 0xff; in hackrf_set_params()
365 buf[5] = (uitmp2 >> 8) & 0xff; in hackrf_set_params()
366 buf[6] = (uitmp2 >> 16) & 0xff; in hackrf_set_params()
367 buf[7] = (uitmp2 >> 24) & 0xff; in hackrf_set_params()
368 ret = hackrf_ctrl_msg(dev, CMD_SET_FREQ, 0, 0, buf, 8); in hackrf_set_params()
374 if (rx && test_and_clear_bit(RX_RF_GAIN, &dev->flags)) { in hackrf_set_params()
375 dev_dbg(&intf->dev, "RX RF gain val=%d->%d\n", in hackrf_set_params()
376 dev->rx_rf_gain->cur.val, dev->rx_rf_gain->val); in hackrf_set_params()
378 u8tmp = (dev->rx_rf_gain->val) ? 1 : 0; in hackrf_set_params()
379 ret = hackrf_ctrl_msg(dev, CMD_AMP_ENABLE, u8tmp, 0, NULL, 0); in hackrf_set_params()
382 set_bit(TX_RF_GAIN, &dev->flags); in hackrf_set_params()
386 if (tx && test_and_clear_bit(TX_RF_GAIN, &dev->flags)) { in hackrf_set_params()
387 dev_dbg(&intf->dev, "TX RF gain val=%d->%d\n", in hackrf_set_params()
388 dev->tx_rf_gain->cur.val, dev->tx_rf_gain->val); in hackrf_set_params()
390 u8tmp = (dev->tx_rf_gain->val) ? 1 : 0; in hackrf_set_params()
391 ret = hackrf_ctrl_msg(dev, CMD_AMP_ENABLE, u8tmp, 0, NULL, 0); in hackrf_set_params()
394 set_bit(RX_RF_GAIN, &dev->flags); in hackrf_set_params()
398 if (rx && test_and_clear_bit(RX_LNA_GAIN, &dev->flags)) { in hackrf_set_params()
399 dev_dbg(dev->dev, "RX LNA gain val=%d->%d\n", in hackrf_set_params()
400 dev->rx_lna_gain->cur.val, dev->rx_lna_gain->val); in hackrf_set_params()
402 ret = hackrf_ctrl_msg(dev, CMD_SET_LNA_GAIN, 0, in hackrf_set_params()
403 dev->rx_lna_gain->val, &u8tmp, 1); in hackrf_set_params()
409 if (rx && test_and_clear_bit(RX_IF_GAIN, &dev->flags)) { in hackrf_set_params()
410 dev_dbg(&intf->dev, "IF gain val=%d->%d\n", in hackrf_set_params()
411 dev->rx_if_gain->cur.val, dev->rx_if_gain->val); in hackrf_set_params()
413 ret = hackrf_ctrl_msg(dev, CMD_SET_VGA_GAIN, 0, in hackrf_set_params()
414 dev->rx_if_gain->val, &u8tmp, 1); in hackrf_set_params()
420 if (tx && test_and_clear_bit(TX_LNA_GAIN, &dev->flags)) { in hackrf_set_params()
421 dev_dbg(&intf->dev, "TX LNA gain val=%d->%d\n", in hackrf_set_params()
422 dev->tx_lna_gain->cur.val, dev->tx_lna_gain->val); in hackrf_set_params()
424 ret = hackrf_ctrl_msg(dev, CMD_SET_TXVGA_GAIN, 0, in hackrf_set_params()
425 dev->tx_lna_gain->val, &u8tmp, 1); in hackrf_set_params()
430 return 0; in hackrf_set_params()
432 dev_dbg(&intf->dev, "failed=%d\n", ret); in hackrf_set_params()
437 static struct hackrf_buffer *hackrf_get_next_buffer(struct hackrf_dev *dev, in hackrf_get_next_buffer() argument
443 spin_lock_irqsave(&dev->buffer_list_lock, flags); in hackrf_get_next_buffer()
447 buffer = list_entry(buffer_list->next, struct hackrf_buffer, list); in hackrf_get_next_buffer()
448 list_del(&buffer->list); in hackrf_get_next_buffer()
450 spin_unlock_irqrestore(&dev->buffer_list_lock, flags); in hackrf_get_next_buffer()
454 static void hackrf_copy_stream(struct hackrf_dev *dev, void *dst, void *src, in hackrf_copy_stream() argument
460 if (unlikely(time_is_before_jiffies(dev->jiffies_next))) { in hackrf_copy_stream()
462 unsigned int msecs = jiffies_to_msecs(jiffies - in hackrf_copy_stream()
463 dev->jiffies_next + msecs_to_jiffies(MSECS)); in hackrf_copy_stream()
464 unsigned int samples = dev->sample - dev->sample_measured; in hackrf_copy_stream()
466 dev->jiffies_next = jiffies + msecs_to_jiffies(MSECS); in hackrf_copy_stream()
467 dev->sample_measured = dev->sample; in hackrf_copy_stream()
468 dev_dbg(dev->dev, "slen=%u samples=%u msecs=%u sample rate=%lu\n", in hackrf_copy_stream()
474 dev->sample += src_len / 2; in hackrf_copy_stream()
483 struct hackrf_dev *dev = urb->context; in hackrf_urb_complete_in() local
484 struct usb_interface *intf = dev->intf; in hackrf_urb_complete_in()
488 dev_dbg_ratelimited(&intf->dev, "status=%d length=%u/%u\n", urb->status, in hackrf_urb_complete_in()
489 urb->actual_length, urb->transfer_buffer_length); in hackrf_urb_complete_in()
491 switch (urb->status) { in hackrf_urb_complete_in()
492 case 0: /* success */ in hackrf_urb_complete_in()
493 case -ETIMEDOUT: /* NAK */ in hackrf_urb_complete_in()
495 case -ECONNRESET: /* kill */ in hackrf_urb_complete_in()
496 case -ENOENT: in hackrf_urb_complete_in()
497 case -ESHUTDOWN: in hackrf_urb_complete_in()
500 dev_err_ratelimited(&intf->dev, "URB failed %d\n", urb->status); in hackrf_urb_complete_in()
505 buffer = hackrf_get_next_buffer(dev, &dev->rx_buffer_list); in hackrf_urb_complete_in()
507 dev->vb_full++; in hackrf_urb_complete_in()
508 dev_notice_ratelimited(&intf->dev, in hackrf_urb_complete_in()
509 "buffer is full - %u packets dropped\n", in hackrf_urb_complete_in()
510 dev->vb_full); in hackrf_urb_complete_in()
514 len = min_t(unsigned long, vb2_plane_size(&buffer->vb.vb2_buf, 0), in hackrf_urb_complete_in()
515 urb->actual_length); in hackrf_urb_complete_in()
516 hackrf_copy_stream(dev, vb2_plane_vaddr(&buffer->vb.vb2_buf, 0), in hackrf_urb_complete_in()
517 urb->transfer_buffer, len); in hackrf_urb_complete_in()
518 vb2_set_plane_payload(&buffer->vb.vb2_buf, 0, len); in hackrf_urb_complete_in()
519 buffer->vb.sequence = dev->sequence++; in hackrf_urb_complete_in()
520 buffer->vb.vb2_buf.timestamp = ktime_get_ns(); in hackrf_urb_complete_in()
521 vb2_buffer_done(&buffer->vb.vb2_buf, VB2_BUF_STATE_DONE); in hackrf_urb_complete_in()
528 struct hackrf_dev *dev = urb->context; in hackrf_urb_complete_out() local
529 struct usb_interface *intf = dev->intf; in hackrf_urb_complete_out()
533 dev_dbg_ratelimited(&intf->dev, "status=%d length=%u/%u\n", urb->status, in hackrf_urb_complete_out()
534 urb->actual_length, urb->transfer_buffer_length); in hackrf_urb_complete_out()
536 switch (urb->status) { in hackrf_urb_complete_out()
537 case 0: /* success */ in hackrf_urb_complete_out()
538 case -ETIMEDOUT: /* NAK */ in hackrf_urb_complete_out()
540 case -ECONNRESET: /* kill */ in hackrf_urb_complete_out()
541 case -ENOENT: in hackrf_urb_complete_out()
542 case -ESHUTDOWN: in hackrf_urb_complete_out()
545 dev_err_ratelimited(&intf->dev, "URB failed %d\n", urb->status); in hackrf_urb_complete_out()
549 buffer = hackrf_get_next_buffer(dev, &dev->tx_buffer_list); in hackrf_urb_complete_out()
551 dev->vb_empty++; in hackrf_urb_complete_out()
552 dev_notice_ratelimited(&intf->dev, in hackrf_urb_complete_out()
553 "buffer is empty - %u packets dropped\n", in hackrf_urb_complete_out()
554 dev->vb_empty); in hackrf_urb_complete_out()
555 urb->actual_length = 0; in hackrf_urb_complete_out()
559 len = min_t(unsigned long, urb->transfer_buffer_length, in hackrf_urb_complete_out()
560 vb2_get_plane_payload(&buffer->vb.vb2_buf, 0)); in hackrf_urb_complete_out()
561 hackrf_copy_stream(dev, urb->transfer_buffer, in hackrf_urb_complete_out()
562 vb2_plane_vaddr(&buffer->vb.vb2_buf, 0), len); in hackrf_urb_complete_out()
563 urb->actual_length = len; in hackrf_urb_complete_out()
564 buffer->vb.sequence = dev->sequence++; in hackrf_urb_complete_out()
565 buffer->vb.vb2_buf.timestamp = ktime_get_ns(); in hackrf_urb_complete_out()
566 vb2_buffer_done(&buffer->vb.vb2_buf, VB2_BUF_STATE_DONE); in hackrf_urb_complete_out()
571 static int hackrf_kill_urbs(struct hackrf_dev *dev) in hackrf_kill_urbs() argument
575 for (i = dev->urbs_submitted - 1; i >= 0; i--) { in hackrf_kill_urbs()
576 dev_dbg(dev->dev, "kill urb=%d\n", i); in hackrf_kill_urbs()
578 usb_kill_urb(dev->urb_list[i]); in hackrf_kill_urbs()
580 dev->urbs_submitted = 0; in hackrf_kill_urbs()
582 return 0; in hackrf_kill_urbs()
585 static int hackrf_submit_urbs(struct hackrf_dev *dev) in hackrf_submit_urbs() argument
589 for (i = 0; i < dev->urbs_initialized; i++) { in hackrf_submit_urbs()
590 dev_dbg(dev->dev, "submit urb=%d\n", i); in hackrf_submit_urbs()
591 ret = usb_submit_urb(dev->urb_list[i], GFP_KERNEL); in hackrf_submit_urbs()
593 dev_err(dev->dev, "Could not submit URB no. %d - get them all back\n", in hackrf_submit_urbs()
595 hackrf_kill_urbs(dev); in hackrf_submit_urbs()
598 dev->urbs_submitted++; in hackrf_submit_urbs()
601 return 0; in hackrf_submit_urbs()
604 static int hackrf_free_stream_bufs(struct hackrf_dev *dev) in hackrf_free_stream_bufs() argument
606 if (dev->flags & USB_STATE_URB_BUF) { in hackrf_free_stream_bufs()
607 while (dev->buf_num) { in hackrf_free_stream_bufs()
608 dev->buf_num--; in hackrf_free_stream_bufs()
609 dev_dbg(dev->dev, "free buf=%d\n", dev->buf_num); in hackrf_free_stream_bufs()
610 usb_free_coherent(dev->udev, dev->buf_size, in hackrf_free_stream_bufs()
611 dev->buf_list[dev->buf_num], in hackrf_free_stream_bufs()
612 dev->dma_addr[dev->buf_num]); in hackrf_free_stream_bufs()
615 dev->flags &= ~USB_STATE_URB_BUF; in hackrf_free_stream_bufs()
617 return 0; in hackrf_free_stream_bufs()
620 static int hackrf_alloc_stream_bufs(struct hackrf_dev *dev) in hackrf_alloc_stream_bufs() argument
622 dev->buf_num = 0; in hackrf_alloc_stream_bufs()
623 dev->buf_size = BULK_BUFFER_SIZE; in hackrf_alloc_stream_bufs()
625 dev_dbg(dev->dev, "all in all I will use %u bytes for streaming\n", in hackrf_alloc_stream_bufs()
628 for (dev->buf_num = 0; dev->buf_num < MAX_BULK_BUFS; dev->buf_num++) { in hackrf_alloc_stream_bufs()
629 dev->buf_list[dev->buf_num] = usb_alloc_coherent(dev->udev, in hackrf_alloc_stream_bufs()
631 &dev->dma_addr[dev->buf_num]); in hackrf_alloc_stream_bufs()
632 if (!dev->buf_list[dev->buf_num]) { in hackrf_alloc_stream_bufs()
633 dev_dbg(dev->dev, "alloc buf=%d failed\n", in hackrf_alloc_stream_bufs()
634 dev->buf_num); in hackrf_alloc_stream_bufs()
635 hackrf_free_stream_bufs(dev); in hackrf_alloc_stream_bufs()
636 return -ENOMEM; in hackrf_alloc_stream_bufs()
639 dev_dbg(dev->dev, "alloc buf=%d %p (dma %llu)\n", dev->buf_num, in hackrf_alloc_stream_bufs()
640 dev->buf_list[dev->buf_num], in hackrf_alloc_stream_bufs()
641 (long long)dev->dma_addr[dev->buf_num]); in hackrf_alloc_stream_bufs()
642 dev->flags |= USB_STATE_URB_BUF; in hackrf_alloc_stream_bufs()
645 return 0; in hackrf_alloc_stream_bufs()
648 static int hackrf_free_urbs(struct hackrf_dev *dev) in hackrf_free_urbs() argument
652 hackrf_kill_urbs(dev); in hackrf_free_urbs()
654 for (i = dev->urbs_initialized - 1; i >= 0; i--) { in hackrf_free_urbs()
655 if (dev->urb_list[i]) { in hackrf_free_urbs()
656 dev_dbg(dev->dev, "free urb=%d\n", i); in hackrf_free_urbs()
658 usb_free_urb(dev->urb_list[i]); in hackrf_free_urbs()
661 dev->urbs_initialized = 0; in hackrf_free_urbs()
663 return 0; in hackrf_free_urbs()
666 static int hackrf_alloc_urbs(struct hackrf_dev *dev, bool rcv) in hackrf_alloc_urbs() argument
673 pipe = usb_rcvbulkpipe(dev->udev, 0x81); in hackrf_alloc_urbs()
676 pipe = usb_sndbulkpipe(dev->udev, 0x02); in hackrf_alloc_urbs()
681 for (i = 0; i < MAX_BULK_BUFS; i++) { in hackrf_alloc_urbs()
682 dev_dbg(dev->dev, "alloc urb=%d\n", i); in hackrf_alloc_urbs()
683 dev->urb_list[i] = usb_alloc_urb(0, GFP_KERNEL); in hackrf_alloc_urbs()
684 if (!dev->urb_list[i]) { in hackrf_alloc_urbs()
685 for (j = 0; j < i; j++) in hackrf_alloc_urbs()
686 usb_free_urb(dev->urb_list[j]); in hackrf_alloc_urbs()
687 return -ENOMEM; in hackrf_alloc_urbs()
689 usb_fill_bulk_urb(dev->urb_list[i], in hackrf_alloc_urbs()
690 dev->udev, in hackrf_alloc_urbs()
692 dev->buf_list[i], in hackrf_alloc_urbs()
694 complete, dev); in hackrf_alloc_urbs()
696 dev->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; in hackrf_alloc_urbs()
697 dev->urb_list[i]->transfer_dma = dev->dma_addr[i]; in hackrf_alloc_urbs()
698 dev->urbs_initialized++; in hackrf_alloc_urbs()
701 return 0; in hackrf_alloc_urbs()
708 struct hackrf_dev *dev = container_of(v, struct hackrf_dev, v4l2_dev); in hackrf_disconnect() local
710 dev_dbg(dev->dev, "\n"); in hackrf_disconnect()
712 mutex_lock(&dev->vb_queue_lock); in hackrf_disconnect()
713 mutex_lock(&dev->v4l2_lock); in hackrf_disconnect()
715 dev->udev = NULL; in hackrf_disconnect()
716 v4l2_device_disconnect(&dev->v4l2_dev); in hackrf_disconnect()
717 video_unregister_device(&dev->tx_vdev); in hackrf_disconnect()
718 video_unregister_device(&dev->rx_vdev); in hackrf_disconnect()
719 mutex_unlock(&dev->v4l2_lock); in hackrf_disconnect()
720 mutex_unlock(&dev->vb_queue_lock); in hackrf_disconnect()
722 v4l2_device_put(&dev->v4l2_dev); in hackrf_disconnect()
729 struct hackrf_dev *dev = vb2_get_drv_priv(vq); in hackrf_return_all_buffers() local
730 struct usb_interface *intf = dev->intf; in hackrf_return_all_buffers()
735 dev_dbg(&intf->dev, "\n"); in hackrf_return_all_buffers()
737 if (vq->type == V4L2_BUF_TYPE_SDR_CAPTURE) in hackrf_return_all_buffers()
738 buffer_list = &dev->rx_buffer_list; in hackrf_return_all_buffers()
740 buffer_list = &dev->tx_buffer_list; in hackrf_return_all_buffers()
742 spin_lock_irqsave(&dev->buffer_list_lock, flags); in hackrf_return_all_buffers()
744 dev_dbg(&intf->dev, "list_for_each_entry_safe\n"); in hackrf_return_all_buffers()
745 vb2_buffer_done(&buffer->vb.vb2_buf, state); in hackrf_return_all_buffers()
746 list_del(&buffer->list); in hackrf_return_all_buffers()
748 spin_unlock_irqrestore(&dev->buffer_list_lock, flags); in hackrf_return_all_buffers()
755 struct hackrf_dev *dev = vb2_get_drv_priv(vq); in hackrf_queue_setup() local
757 dev_dbg(dev->dev, "nbuffers=%d\n", *nbuffers); in hackrf_queue_setup()
760 if (vq->num_buffers + *nbuffers < 8) in hackrf_queue_setup()
761 *nbuffers = 8 - vq->num_buffers; in hackrf_queue_setup()
763 sizes[0] = PAGE_ALIGN(dev->buffersize); in hackrf_queue_setup()
765 dev_dbg(dev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); in hackrf_queue_setup()
766 return 0; in hackrf_queue_setup()
772 struct vb2_queue *vq = vb->vb2_queue; in hackrf_buf_queue()
773 struct hackrf_dev *dev = vb2_get_drv_priv(vq); in hackrf_buf_queue() local
778 dev_dbg_ratelimited(&dev->intf->dev, "\n"); in hackrf_buf_queue()
780 if (vq->type == V4L2_BUF_TYPE_SDR_CAPTURE) in hackrf_buf_queue()
781 buffer_list = &dev->rx_buffer_list; in hackrf_buf_queue()
783 buffer_list = &dev->tx_buffer_list; in hackrf_buf_queue()
785 spin_lock_irqsave(&dev->buffer_list_lock, flags); in hackrf_buf_queue()
786 list_add_tail(&buffer->list, buffer_list); in hackrf_buf_queue()
787 spin_unlock_irqrestore(&dev->buffer_list_lock, flags); in hackrf_buf_queue()
792 struct hackrf_dev *dev = vb2_get_drv_priv(vq); in hackrf_start_streaming() local
793 struct usb_interface *intf = dev->intf; in hackrf_start_streaming()
797 dev_dbg(&intf->dev, "count=%i\n", count); in hackrf_start_streaming()
799 mutex_lock(&dev->v4l2_lock); in hackrf_start_streaming()
802 if (vq->type == V4L2_BUF_TYPE_SDR_CAPTURE) { in hackrf_start_streaming()
803 if (test_bit(TX_ON, &dev->flags)) { in hackrf_start_streaming()
804 ret = -EBUSY; in hackrf_start_streaming()
809 set_bit(RX_ON, &dev->flags); in hackrf_start_streaming()
811 if (test_bit(RX_ON, &dev->flags)) { in hackrf_start_streaming()
812 ret = -EBUSY; in hackrf_start_streaming()
817 set_bit(TX_ON, &dev->flags); in hackrf_start_streaming()
820 dev->sequence = 0; in hackrf_start_streaming()
822 ret = hackrf_alloc_stream_bufs(dev); in hackrf_start_streaming()
826 ret = hackrf_alloc_urbs(dev, (mode == 1)); in hackrf_start_streaming()
830 ret = hackrf_submit_urbs(dev); in hackrf_start_streaming()
834 ret = hackrf_set_params(dev); in hackrf_start_streaming()
839 ret = hackrf_ctrl_msg(dev, CMD_SET_TRANSCEIVER_MODE, mode, 0, NULL, 0); in hackrf_start_streaming()
843 mutex_unlock(&dev->v4l2_lock); in hackrf_start_streaming()
845 return 0; in hackrf_start_streaming()
847 hackrf_kill_urbs(dev); in hackrf_start_streaming()
848 hackrf_free_urbs(dev); in hackrf_start_streaming()
849 hackrf_free_stream_bufs(dev); in hackrf_start_streaming()
850 clear_bit(RX_ON, &dev->flags); in hackrf_start_streaming()
851 clear_bit(TX_ON, &dev->flags); in hackrf_start_streaming()
854 mutex_unlock(&dev->v4l2_lock); in hackrf_start_streaming()
855 dev_dbg(&intf->dev, "failed=%d\n", ret); in hackrf_start_streaming()
861 struct hackrf_dev *dev = vb2_get_drv_priv(vq); in hackrf_stop_streaming() local
862 struct usb_interface *intf = dev->intf; in hackrf_stop_streaming()
864 dev_dbg(&intf->dev, "\n"); in hackrf_stop_streaming()
866 mutex_lock(&dev->v4l2_lock); in hackrf_stop_streaming()
869 hackrf_ctrl_msg(dev, CMD_SET_TRANSCEIVER_MODE, 0, 0, NULL, 0); in hackrf_stop_streaming()
871 hackrf_kill_urbs(dev); in hackrf_stop_streaming()
872 hackrf_free_urbs(dev); in hackrf_stop_streaming()
873 hackrf_free_stream_bufs(dev); in hackrf_stop_streaming()
877 if (vq->type == V4L2_BUF_TYPE_SDR_CAPTURE) in hackrf_stop_streaming()
878 clear_bit(RX_ON, &dev->flags); in hackrf_stop_streaming()
880 clear_bit(TX_ON, &dev->flags); in hackrf_stop_streaming()
882 mutex_unlock(&dev->v4l2_lock); in hackrf_stop_streaming()
897 struct hackrf_dev *dev = video_drvdata(file); in hackrf_querycap() local
898 struct usb_interface *intf = dev->intf; in hackrf_querycap()
900 dev_dbg(&intf->dev, "\n"); in hackrf_querycap()
902 cap->capabilities = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_TUNER | in hackrf_querycap()
906 strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); in hackrf_querycap()
907 strscpy(cap->card, dev->rx_vdev.name, sizeof(cap->card)); in hackrf_querycap()
908 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); in hackrf_querycap()
910 return 0; in hackrf_querycap()
916 struct hackrf_dev *dev = video_drvdata(file); in hackrf_s_fmt_sdr() local
921 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", in hackrf_s_fmt_sdr()
922 (char *)&f->fmt.sdr.pixelformat); in hackrf_s_fmt_sdr()
924 if (vdev->vfl_dir == VFL_DIR_RX) in hackrf_s_fmt_sdr()
925 q = &dev->rx_vb2_queue; in hackrf_s_fmt_sdr()
927 q = &dev->tx_vb2_queue; in hackrf_s_fmt_sdr()
930 return -EBUSY; in hackrf_s_fmt_sdr()
932 for (i = 0; i < NUM_FORMATS; i++) { in hackrf_s_fmt_sdr()
933 if (f->fmt.sdr.pixelformat == formats[i].pixelformat) { in hackrf_s_fmt_sdr()
934 dev->pixelformat = formats[i].pixelformat; in hackrf_s_fmt_sdr()
935 dev->buffersize = formats[i].buffersize; in hackrf_s_fmt_sdr()
936 f->fmt.sdr.buffersize = formats[i].buffersize; in hackrf_s_fmt_sdr()
937 return 0; in hackrf_s_fmt_sdr()
941 dev->pixelformat = formats[0].pixelformat; in hackrf_s_fmt_sdr()
942 dev->buffersize = formats[0].buffersize; in hackrf_s_fmt_sdr()
943 f->fmt.sdr.pixelformat = formats[0].pixelformat; in hackrf_s_fmt_sdr()
944 f->fmt.sdr.buffersize = formats[0].buffersize; in hackrf_s_fmt_sdr()
946 return 0; in hackrf_s_fmt_sdr()
952 struct hackrf_dev *dev = video_drvdata(file); in hackrf_g_fmt_sdr() local
954 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", in hackrf_g_fmt_sdr()
955 (char *)&dev->pixelformat); in hackrf_g_fmt_sdr()
957 f->fmt.sdr.pixelformat = dev->pixelformat; in hackrf_g_fmt_sdr()
958 f->fmt.sdr.buffersize = dev->buffersize; in hackrf_g_fmt_sdr()
960 return 0; in hackrf_g_fmt_sdr()
966 struct hackrf_dev *dev = video_drvdata(file); in hackrf_try_fmt_sdr() local
969 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", in hackrf_try_fmt_sdr()
970 (char *)&f->fmt.sdr.pixelformat); in hackrf_try_fmt_sdr()
972 for (i = 0; i < NUM_FORMATS; i++) { in hackrf_try_fmt_sdr()
973 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { in hackrf_try_fmt_sdr()
974 f->fmt.sdr.buffersize = formats[i].buffersize; in hackrf_try_fmt_sdr()
975 return 0; in hackrf_try_fmt_sdr()
979 f->fmt.sdr.pixelformat = formats[0].pixelformat; in hackrf_try_fmt_sdr()
980 f->fmt.sdr.buffersize = formats[0].buffersize; in hackrf_try_fmt_sdr()
982 return 0; in hackrf_try_fmt_sdr()
988 struct hackrf_dev *dev = video_drvdata(file); in hackrf_enum_fmt_sdr() local
990 dev_dbg(dev->dev, "index=%d\n", f->index); in hackrf_enum_fmt_sdr()
992 if (f->index >= NUM_FORMATS) in hackrf_enum_fmt_sdr()
993 return -EINVAL; in hackrf_enum_fmt_sdr()
995 f->pixelformat = formats[f->index].pixelformat; in hackrf_enum_fmt_sdr()
997 return 0; in hackrf_enum_fmt_sdr()
1003 struct hackrf_dev *dev = video_drvdata(file); in hackrf_s_tuner() local
1006 dev_dbg(dev->dev, "index=%d\n", v->index); in hackrf_s_tuner()
1008 if (v->index == 0) in hackrf_s_tuner()
1009 ret = 0; in hackrf_s_tuner()
1010 else if (v->index == 1) in hackrf_s_tuner()
1011 ret = 0; in hackrf_s_tuner()
1013 ret = -EINVAL; in hackrf_s_tuner()
1020 struct hackrf_dev *dev = video_drvdata(file); in hackrf_g_tuner() local
1023 dev_dbg(dev->dev, "index=%d\n", v->index); in hackrf_g_tuner()
1025 if (v->index == 0) { in hackrf_g_tuner()
1026 strscpy(v->name, "HackRF ADC", sizeof(v->name)); in hackrf_g_tuner()
1027 v->type = V4L2_TUNER_SDR; in hackrf_g_tuner()
1028 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; in hackrf_g_tuner()
1029 v->rangelow = bands_adc_dac[0].rangelow; in hackrf_g_tuner()
1030 v->rangehigh = bands_adc_dac[0].rangehigh; in hackrf_g_tuner()
1031 ret = 0; in hackrf_g_tuner()
1032 } else if (v->index == 1) { in hackrf_g_tuner()
1033 strscpy(v->name, "HackRF RF", sizeof(v->name)); in hackrf_g_tuner()
1034 v->type = V4L2_TUNER_RF; in hackrf_g_tuner()
1035 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; in hackrf_g_tuner()
1036 v->rangelow = bands_rx_tx[0].rangelow; in hackrf_g_tuner()
1037 v->rangehigh = bands_rx_tx[0].rangehigh; in hackrf_g_tuner()
1038 ret = 0; in hackrf_g_tuner()
1040 ret = -EINVAL; in hackrf_g_tuner()
1049 struct hackrf_dev *dev = video_drvdata(file); in hackrf_s_modulator() local
1051 dev_dbg(dev->dev, "index=%d\n", a->index); in hackrf_s_modulator()
1053 return a->index > 1 ? -EINVAL : 0; in hackrf_s_modulator()
1059 struct hackrf_dev *dev = video_drvdata(file); in hackrf_g_modulator() local
1062 dev_dbg(dev->dev, "index=%d\n", a->index); in hackrf_g_modulator()
1064 if (a->index == 0) { in hackrf_g_modulator()
1065 strscpy(a->name, "HackRF DAC", sizeof(a->name)); in hackrf_g_modulator()
1066 a->type = V4L2_TUNER_SDR; in hackrf_g_modulator()
1067 a->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; in hackrf_g_modulator()
1068 a->rangelow = bands_adc_dac[0].rangelow; in hackrf_g_modulator()
1069 a->rangehigh = bands_adc_dac[0].rangehigh; in hackrf_g_modulator()
1070 ret = 0; in hackrf_g_modulator()
1071 } else if (a->index == 1) { in hackrf_g_modulator()
1072 strscpy(a->name, "HackRF RF", sizeof(a->name)); in hackrf_g_modulator()
1073 a->type = V4L2_TUNER_RF; in hackrf_g_modulator()
1074 a->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; in hackrf_g_modulator()
1075 a->rangelow = bands_rx_tx[0].rangelow; in hackrf_g_modulator()
1076 a->rangehigh = bands_rx_tx[0].rangehigh; in hackrf_g_modulator()
1077 ret = 0; in hackrf_g_modulator()
1079 ret = -EINVAL; in hackrf_g_modulator()
1088 struct hackrf_dev *dev = video_drvdata(file); in hackrf_s_frequency() local
1089 struct usb_interface *intf = dev->intf; in hackrf_s_frequency()
1094 dev_dbg(&intf->dev, "tuner=%d type=%d frequency=%u\n", in hackrf_s_frequency()
1095 f->tuner, f->type, f->frequency); in hackrf_s_frequency()
1097 if (f->tuner == 0) { in hackrf_s_frequency()
1098 uitmp = clamp(f->frequency, bands_adc_dac[0].rangelow, in hackrf_s_frequency()
1099 bands_adc_dac[0].rangehigh); in hackrf_s_frequency()
1100 if (vdev->vfl_dir == VFL_DIR_RX) { in hackrf_s_frequency()
1101 dev->f_adc = uitmp; in hackrf_s_frequency()
1102 set_bit(RX_ADC_FREQUENCY, &dev->flags); in hackrf_s_frequency()
1104 dev->f_dac = uitmp; in hackrf_s_frequency()
1105 set_bit(TX_DAC_FREQUENCY, &dev->flags); in hackrf_s_frequency()
1107 } else if (f->tuner == 1) { in hackrf_s_frequency()
1108 uitmp = clamp(f->frequency, bands_rx_tx[0].rangelow, in hackrf_s_frequency()
1109 bands_rx_tx[0].rangehigh); in hackrf_s_frequency()
1110 if (vdev->vfl_dir == VFL_DIR_RX) { in hackrf_s_frequency()
1111 dev->f_rx = uitmp; in hackrf_s_frequency()
1112 set_bit(RX_RF_FREQUENCY, &dev->flags); in hackrf_s_frequency()
1114 dev->f_tx = uitmp; in hackrf_s_frequency()
1115 set_bit(TX_RF_FREQUENCY, &dev->flags); in hackrf_s_frequency()
1118 ret = -EINVAL; in hackrf_s_frequency()
1122 ret = hackrf_set_params(dev); in hackrf_s_frequency()
1126 return 0; in hackrf_s_frequency()
1128 dev_dbg(&intf->dev, "failed=%d\n", ret); in hackrf_s_frequency()
1135 struct hackrf_dev *dev = video_drvdata(file); in hackrf_g_frequency() local
1136 struct usb_interface *intf = dev->intf; in hackrf_g_frequency()
1140 dev_dbg(dev->dev, "tuner=%d type=%d\n", f->tuner, f->type); in hackrf_g_frequency()
1142 if (f->tuner == 0) { in hackrf_g_frequency()
1143 f->type = V4L2_TUNER_SDR; in hackrf_g_frequency()
1144 if (vdev->vfl_dir == VFL_DIR_RX) in hackrf_g_frequency()
1145 f->frequency = dev->f_adc; in hackrf_g_frequency()
1147 f->frequency = dev->f_dac; in hackrf_g_frequency()
1148 } else if (f->tuner == 1) { in hackrf_g_frequency()
1149 f->type = V4L2_TUNER_RF; in hackrf_g_frequency()
1150 if (vdev->vfl_dir == VFL_DIR_RX) in hackrf_g_frequency()
1151 f->frequency = dev->f_rx; in hackrf_g_frequency()
1153 f->frequency = dev->f_tx; in hackrf_g_frequency()
1155 ret = -EINVAL; in hackrf_g_frequency()
1159 return 0; in hackrf_g_frequency()
1161 dev_dbg(&intf->dev, "failed=%d\n", ret); in hackrf_g_frequency()
1168 struct hackrf_dev *dev = video_drvdata(file); in hackrf_enum_freq_bands() local
1171 dev_dbg(dev->dev, "tuner=%d type=%d index=%d\n", in hackrf_enum_freq_bands()
1172 band->tuner, band->type, band->index); in hackrf_enum_freq_bands()
1174 if (band->tuner == 0) { in hackrf_enum_freq_bands()
1175 if (band->index >= ARRAY_SIZE(bands_adc_dac)) { in hackrf_enum_freq_bands()
1176 ret = -EINVAL; in hackrf_enum_freq_bands()
1178 *band = bands_adc_dac[band->index]; in hackrf_enum_freq_bands()
1179 ret = 0; in hackrf_enum_freq_bands()
1181 } else if (band->tuner == 1) { in hackrf_enum_freq_bands()
1182 if (band->index >= ARRAY_SIZE(bands_rx_tx)) { in hackrf_enum_freq_bands()
1183 ret = -EINVAL; in hackrf_enum_freq_bands()
1185 *band = bands_rx_tx[band->index]; in hackrf_enum_freq_bands()
1186 ret = 0; in hackrf_enum_freq_bands()
1189 ret = -EINVAL; in hackrf_enum_freq_bands()
1254 struct hackrf_dev *dev = container_of(v, struct hackrf_dev, v4l2_dev); in hackrf_video_release() local
1256 dev_dbg(dev->dev, "\n"); in hackrf_video_release()
1258 v4l2_ctrl_handler_free(&dev->rx_ctrl_handler); in hackrf_video_release()
1259 v4l2_ctrl_handler_free(&dev->tx_ctrl_handler); in hackrf_video_release()
1260 v4l2_device_unregister(&dev->v4l2_dev); in hackrf_video_release()
1261 kfree(dev); in hackrf_video_release()
1266 struct hackrf_dev *dev = container_of(ctrl->handler, in hackrf_s_ctrl_rx() local
1268 struct usb_interface *intf = dev->intf; in hackrf_s_ctrl_rx()
1271 switch (ctrl->id) { in hackrf_s_ctrl_rx()
1274 set_bit(RX_BANDWIDTH, &dev->flags); in hackrf_s_ctrl_rx()
1277 set_bit(RX_RF_GAIN, &dev->flags); in hackrf_s_ctrl_rx()
1280 set_bit(RX_LNA_GAIN, &dev->flags); in hackrf_s_ctrl_rx()
1283 set_bit(RX_IF_GAIN, &dev->flags); in hackrf_s_ctrl_rx()
1286 dev_dbg(&intf->dev, "unknown ctrl: id=%d name=%s\n", in hackrf_s_ctrl_rx()
1287 ctrl->id, ctrl->name); in hackrf_s_ctrl_rx()
1288 ret = -EINVAL; in hackrf_s_ctrl_rx()
1292 ret = hackrf_set_params(dev); in hackrf_s_ctrl_rx()
1296 return 0; in hackrf_s_ctrl_rx()
1298 dev_dbg(&intf->dev, "failed=%d\n", ret); in hackrf_s_ctrl_rx()
1304 struct hackrf_dev *dev = container_of(ctrl->handler, in hackrf_s_ctrl_tx() local
1306 struct usb_interface *intf = dev->intf; in hackrf_s_ctrl_tx()
1309 switch (ctrl->id) { in hackrf_s_ctrl_tx()
1312 set_bit(TX_BANDWIDTH, &dev->flags); in hackrf_s_ctrl_tx()
1315 set_bit(TX_LNA_GAIN, &dev->flags); in hackrf_s_ctrl_tx()
1318 set_bit(TX_RF_GAIN, &dev->flags); in hackrf_s_ctrl_tx()
1321 dev_dbg(&intf->dev, "unknown ctrl: id=%d name=%s\n", in hackrf_s_ctrl_tx()
1322 ctrl->id, ctrl->name); in hackrf_s_ctrl_tx()
1323 ret = -EINVAL; in hackrf_s_ctrl_tx()
1327 ret = hackrf_set_params(dev); in hackrf_s_ctrl_tx()
1331 return 0; in hackrf_s_ctrl_tx()
1333 dev_dbg(&intf->dev, "failed=%d\n", ret); in hackrf_s_ctrl_tx()
1348 struct hackrf_dev *dev; in hackrf_probe() local
1352 dev = kzalloc(sizeof(*dev), GFP_KERNEL); in hackrf_probe()
1353 if (!dev) { in hackrf_probe()
1354 ret = -ENOMEM; in hackrf_probe()
1358 mutex_init(&dev->v4l2_lock); in hackrf_probe()
1359 mutex_init(&dev->vb_queue_lock); in hackrf_probe()
1360 spin_lock_init(&dev->buffer_list_lock); in hackrf_probe()
1361 INIT_LIST_HEAD(&dev->rx_buffer_list); in hackrf_probe()
1362 INIT_LIST_HEAD(&dev->tx_buffer_list); in hackrf_probe()
1363 dev->intf = intf; in hackrf_probe()
1364 dev->dev = &intf->dev; in hackrf_probe()
1365 dev->udev = interface_to_usbdev(intf); in hackrf_probe()
1366 dev->pixelformat = formats[0].pixelformat; in hackrf_probe()
1367 dev->buffersize = formats[0].buffersize; in hackrf_probe()
1368 dev->f_adc = bands_adc_dac[0].rangelow; in hackrf_probe()
1369 dev->f_dac = bands_adc_dac[0].rangelow; in hackrf_probe()
1370 dev->f_rx = bands_rx_tx[0].rangelow; in hackrf_probe()
1371 dev->f_tx = bands_rx_tx[0].rangelow; in hackrf_probe()
1372 set_bit(RX_ADC_FREQUENCY, &dev->flags); in hackrf_probe()
1373 set_bit(TX_DAC_FREQUENCY, &dev->flags); in hackrf_probe()
1374 set_bit(RX_RF_FREQUENCY, &dev->flags); in hackrf_probe()
1375 set_bit(TX_RF_FREQUENCY, &dev->flags); in hackrf_probe()
1378 ret = hackrf_ctrl_msg(dev, CMD_BOARD_ID_READ, 0, 0, &u8tmp, 1); in hackrf_probe()
1379 if (ret == 0) in hackrf_probe()
1380 ret = hackrf_ctrl_msg(dev, CMD_VERSION_STRING_READ, 0, 0, in hackrf_probe()
1383 dev_err(dev->dev, "Could not detect board\n"); in hackrf_probe()
1387 buf[BUF_SIZE - 1] = '\0'; in hackrf_probe()
1388 dev_info(dev->dev, "Board ID: %02x\n", u8tmp); in hackrf_probe()
1389 dev_info(dev->dev, "Firmware version: %s\n", buf); in hackrf_probe()
1392 dev->rx_vb2_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; in hackrf_probe()
1393 dev->rx_vb2_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | in hackrf_probe()
1395 dev->rx_vb2_queue.ops = &hackrf_vb2_ops; in hackrf_probe()
1396 dev->rx_vb2_queue.mem_ops = &vb2_vmalloc_memops; in hackrf_probe()
1397 dev->rx_vb2_queue.drv_priv = dev; in hackrf_probe()
1398 dev->rx_vb2_queue.buf_struct_size = sizeof(struct hackrf_buffer); in hackrf_probe()
1399 dev->rx_vb2_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in hackrf_probe()
1400 ret = vb2_queue_init(&dev->rx_vb2_queue); in hackrf_probe()
1402 dev_err(dev->dev, "Could not initialize rx vb2 queue\n"); in hackrf_probe()
1407 dev->tx_vb2_queue.type = V4L2_BUF_TYPE_SDR_OUTPUT; in hackrf_probe()
1408 dev->tx_vb2_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | in hackrf_probe()
1410 dev->tx_vb2_queue.ops = &hackrf_vb2_ops; in hackrf_probe()
1411 dev->tx_vb2_queue.mem_ops = &vb2_vmalloc_memops; in hackrf_probe()
1412 dev->tx_vb2_queue.drv_priv = dev; in hackrf_probe()
1413 dev->tx_vb2_queue.buf_struct_size = sizeof(struct hackrf_buffer); in hackrf_probe()
1414 dev->tx_vb2_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in hackrf_probe()
1415 ret = vb2_queue_init(&dev->tx_vb2_queue); in hackrf_probe()
1417 dev_err(dev->dev, "Could not initialize tx vb2 queue\n"); in hackrf_probe()
1422 v4l2_ctrl_handler_init(&dev->rx_ctrl_handler, 5); in hackrf_probe()
1423 dev->rx_bandwidth_auto = v4l2_ctrl_new_std(&dev->rx_ctrl_handler, in hackrf_probe()
1425 0, 1, 0, 1); in hackrf_probe()
1426 dev->rx_bandwidth = v4l2_ctrl_new_std(&dev->rx_ctrl_handler, in hackrf_probe()
1429 v4l2_ctrl_auto_cluster(2, &dev->rx_bandwidth_auto, 0, false); in hackrf_probe()
1430 dev->rx_rf_gain = v4l2_ctrl_new_std(&dev->rx_ctrl_handler, in hackrf_probe()
1431 &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_RF_GAIN, 0, 12, 12, 0); in hackrf_probe()
1432 dev->rx_lna_gain = v4l2_ctrl_new_std(&dev->rx_ctrl_handler, in hackrf_probe()
1433 &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_LNA_GAIN, 0, 40, 8, 0); in hackrf_probe()
1434 dev->rx_if_gain = v4l2_ctrl_new_std(&dev->rx_ctrl_handler, in hackrf_probe()
1435 &hackrf_ctrl_ops_rx, V4L2_CID_RF_TUNER_IF_GAIN, 0, 62, 2, 0); in hackrf_probe()
1436 if (dev->rx_ctrl_handler.error) { in hackrf_probe()
1437 ret = dev->rx_ctrl_handler.error; in hackrf_probe()
1438 dev_err(dev->dev, "Could not initialize controls\n"); in hackrf_probe()
1441 v4l2_ctrl_grab(dev->rx_rf_gain, !hackrf_enable_rf_gain_ctrl); in hackrf_probe()
1442 v4l2_ctrl_handler_setup(&dev->rx_ctrl_handler); in hackrf_probe()
1445 v4l2_ctrl_handler_init(&dev->tx_ctrl_handler, 4); in hackrf_probe()
1446 dev->tx_bandwidth_auto = v4l2_ctrl_new_std(&dev->tx_ctrl_handler, in hackrf_probe()
1448 0, 1, 0, 1); in hackrf_probe()
1449 dev->tx_bandwidth = v4l2_ctrl_new_std(&dev->tx_ctrl_handler, in hackrf_probe()
1452 v4l2_ctrl_auto_cluster(2, &dev->tx_bandwidth_auto, 0, false); in hackrf_probe()
1453 dev->tx_lna_gain = v4l2_ctrl_new_std(&dev->tx_ctrl_handler, in hackrf_probe()
1454 &hackrf_ctrl_ops_tx, V4L2_CID_RF_TUNER_LNA_GAIN, 0, 47, 1, 0); in hackrf_probe()
1455 dev->tx_rf_gain = v4l2_ctrl_new_std(&dev->tx_ctrl_handler, in hackrf_probe()
1456 &hackrf_ctrl_ops_tx, V4L2_CID_RF_TUNER_RF_GAIN, 0, 15, 15, 0); in hackrf_probe()
1457 if (dev->tx_ctrl_handler.error) { in hackrf_probe()
1458 ret = dev->tx_ctrl_handler.error; in hackrf_probe()
1459 dev_err(dev->dev, "Could not initialize controls\n"); in hackrf_probe()
1462 v4l2_ctrl_grab(dev->tx_rf_gain, !hackrf_enable_rf_gain_ctrl); in hackrf_probe()
1463 v4l2_ctrl_handler_setup(&dev->tx_ctrl_handler); in hackrf_probe()
1466 dev->v4l2_dev.release = hackrf_video_release; in hackrf_probe()
1467 ret = v4l2_device_register(&intf->dev, &dev->v4l2_dev); in hackrf_probe()
1469 dev_err(dev->dev, "Failed to register v4l2-device (%d)\n", ret); in hackrf_probe()
1474 dev->rx_vdev = hackrf_template; in hackrf_probe()
1475 dev->rx_vdev.queue = &dev->rx_vb2_queue; in hackrf_probe()
1476 dev->rx_vdev.queue->lock = &dev->vb_queue_lock; in hackrf_probe()
1477 dev->rx_vdev.v4l2_dev = &dev->v4l2_dev; in hackrf_probe()
1478 dev->rx_vdev.ctrl_handler = &dev->rx_ctrl_handler; in hackrf_probe()
1479 dev->rx_vdev.lock = &dev->v4l2_lock; in hackrf_probe()
1480 dev->rx_vdev.vfl_dir = VFL_DIR_RX; in hackrf_probe()
1481 dev->rx_vdev.device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE | in hackrf_probe()
1483 video_set_drvdata(&dev->rx_vdev, dev); in hackrf_probe()
1484 ret = video_register_device(&dev->rx_vdev, VFL_TYPE_SDR, -1); in hackrf_probe()
1486 dev_err(dev->dev, in hackrf_probe()
1490 dev_info(dev->dev, "Registered as %s\n", in hackrf_probe()
1491 video_device_node_name(&dev->rx_vdev)); in hackrf_probe()
1494 dev->tx_vdev = hackrf_template; in hackrf_probe()
1495 dev->tx_vdev.queue = &dev->tx_vb2_queue; in hackrf_probe()
1496 dev->tx_vdev.queue->lock = &dev->vb_queue_lock; in hackrf_probe()
1497 dev->tx_vdev.v4l2_dev = &dev->v4l2_dev; in hackrf_probe()
1498 dev->tx_vdev.ctrl_handler = &dev->tx_ctrl_handler; in hackrf_probe()
1499 dev->tx_vdev.lock = &dev->v4l2_lock; in hackrf_probe()
1500 dev->tx_vdev.vfl_dir = VFL_DIR_TX; in hackrf_probe()
1501 dev->tx_vdev.device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE | in hackrf_probe()
1503 video_set_drvdata(&dev->tx_vdev, dev); in hackrf_probe()
1504 ret = video_register_device(&dev->tx_vdev, VFL_TYPE_SDR, -1); in hackrf_probe()
1506 dev_err(dev->dev, in hackrf_probe()
1510 dev_info(dev->dev, "Registered as %s\n", in hackrf_probe()
1511 video_device_node_name(&dev->tx_vdev)); in hackrf_probe()
1513 …dev_notice(dev->dev, "SDR API is still slightly experimental and functionality changes may follow\… in hackrf_probe()
1514 return 0; in hackrf_probe()
1516 video_unregister_device(&dev->rx_vdev); in hackrf_probe()
1518 v4l2_device_unregister(&dev->v4l2_dev); in hackrf_probe()
1520 v4l2_ctrl_handler_free(&dev->tx_ctrl_handler); in hackrf_probe()
1522 v4l2_ctrl_handler_free(&dev->rx_ctrl_handler); in hackrf_probe()
1524 kfree(dev); in hackrf_probe()
1526 dev_dbg(&intf->dev, "failed=%d\n", ret); in hackrf_probe()
1532 { USB_DEVICE(0x1d50, 0x6089) }, /* HackRF One */