• Home
  • Raw
  • Download

Lines Matching refs:s

172 static int airspy_ctrl_msg(struct airspy *s, u8 request, u16 value, u16 index,  in airspy_ctrl_msg()  argument
182 pipe = usb_sndctrlpipe(s->udev, 0); in airspy_ctrl_msg()
193 pipe = usb_rcvctrlpipe(s->udev, 0); in airspy_ctrl_msg()
197 dev_err(s->dev, "Unknown command %02x\n", request); in airspy_ctrl_msg()
204 memcpy(s->buf, data, size); in airspy_ctrl_msg()
206 ret = usb_control_msg(s->udev, pipe, request, requesttype, value, in airspy_ctrl_msg()
207 index, s->buf, size, 1000); in airspy_ctrl_msg()
208 airspy_dbg_usb_control_msg(s->dev, request, requesttype, value, in airspy_ctrl_msg()
209 index, s->buf, size); in airspy_ctrl_msg()
211 dev_err(s->dev, "usb_control_msg() failed %d request %02x\n", in airspy_ctrl_msg()
218 memcpy(data, s->buf, size); in airspy_ctrl_msg()
226 static struct airspy_frame_buf *airspy_get_next_fill_buf(struct airspy *s) in airspy_get_next_fill_buf() argument
231 spin_lock_irqsave(&s->queued_bufs_lock, flags); in airspy_get_next_fill_buf()
232 if (list_empty(&s->queued_bufs)) in airspy_get_next_fill_buf()
235 buf = list_entry(s->queued_bufs.next, in airspy_get_next_fill_buf()
239 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); in airspy_get_next_fill_buf()
243 static unsigned int airspy_convert_stream(struct airspy *s, in airspy_convert_stream() argument
248 if (s->pixelformat == V4L2_SDR_FMT_RU12LE) { in airspy_convert_stream()
256 if (unlikely(time_is_before_jiffies(s->jiffies_next))) { in airspy_convert_stream()
259 s->jiffies_next + msecs_to_jiffies(MSECS)); in airspy_convert_stream()
260 unsigned int samples = s->sample - s->sample_measured; in airspy_convert_stream()
262 s->jiffies_next = jiffies + msecs_to_jiffies(MSECS); in airspy_convert_stream()
263 s->sample_measured = s->sample; in airspy_convert_stream()
264 dev_dbg(s->dev, "slen=%u samples=%u msecs=%u sample rate=%lu\n", in airspy_convert_stream()
270 s->sample += src_len / 2; in airspy_convert_stream()
281 struct airspy *s = urb->context; in airspy_urb_complete() local
284 dev_dbg_ratelimited(s->dev, "status=%d length=%d/%d errors=%d\n", in airspy_urb_complete()
297 dev_err_ratelimited(s->dev, "URB failed %d\n", urb->status); in airspy_urb_complete()
305 fbuf = airspy_get_next_fill_buf(s); in airspy_urb_complete()
307 s->vb_full++; in airspy_urb_complete()
308 dev_notice_ratelimited(s->dev, in airspy_urb_complete()
310 s->vb_full); in airspy_urb_complete()
316 len = airspy_convert_stream(s, ptr, urb->transfer_buffer, in airspy_urb_complete()
320 fbuf->vb.sequence = s->sequence++; in airspy_urb_complete()
327 static int airspy_kill_urbs(struct airspy *s) in airspy_kill_urbs() argument
331 for (i = s->urbs_submitted - 1; i >= 0; i--) { in airspy_kill_urbs()
332 dev_dbg(s->dev, "kill urb=%d\n", i); in airspy_kill_urbs()
334 usb_kill_urb(s->urb_list[i]); in airspy_kill_urbs()
336 s->urbs_submitted = 0; in airspy_kill_urbs()
341 static int airspy_submit_urbs(struct airspy *s) in airspy_submit_urbs() argument
345 for (i = 0; i < s->urbs_initialized; i++) { in airspy_submit_urbs()
346 dev_dbg(s->dev, "submit urb=%d\n", i); in airspy_submit_urbs()
347 ret = usb_submit_urb(s->urb_list[i], GFP_ATOMIC); in airspy_submit_urbs()
349 dev_err(s->dev, "Could not submit URB no. %d - get them all back\n", in airspy_submit_urbs()
351 airspy_kill_urbs(s); in airspy_submit_urbs()
354 s->urbs_submitted++; in airspy_submit_urbs()
360 static int airspy_free_stream_bufs(struct airspy *s) in airspy_free_stream_bufs() argument
362 if (s->flags & USB_STATE_URB_BUF) { in airspy_free_stream_bufs()
363 while (s->buf_num) { in airspy_free_stream_bufs()
364 s->buf_num--; in airspy_free_stream_bufs()
365 dev_dbg(s->dev, "free buf=%d\n", s->buf_num); in airspy_free_stream_bufs()
366 usb_free_coherent(s->udev, s->buf_size, in airspy_free_stream_bufs()
367 s->buf_list[s->buf_num], in airspy_free_stream_bufs()
368 s->dma_addr[s->buf_num]); in airspy_free_stream_bufs()
371 s->flags &= ~USB_STATE_URB_BUF; in airspy_free_stream_bufs()
376 static int airspy_alloc_stream_bufs(struct airspy *s) in airspy_alloc_stream_bufs() argument
378 s->buf_num = 0; in airspy_alloc_stream_bufs()
379 s->buf_size = BULK_BUFFER_SIZE; in airspy_alloc_stream_bufs()
381 dev_dbg(s->dev, "all in all I will use %u bytes for streaming\n", in airspy_alloc_stream_bufs()
384 for (s->buf_num = 0; s->buf_num < MAX_BULK_BUFS; s->buf_num++) { in airspy_alloc_stream_bufs()
385 s->buf_list[s->buf_num] = usb_alloc_coherent(s->udev, in airspy_alloc_stream_bufs()
387 &s->dma_addr[s->buf_num]); in airspy_alloc_stream_bufs()
388 if (!s->buf_list[s->buf_num]) { in airspy_alloc_stream_bufs()
389 dev_dbg(s->dev, "alloc buf=%d failed\n", s->buf_num); in airspy_alloc_stream_bufs()
390 airspy_free_stream_bufs(s); in airspy_alloc_stream_bufs()
394 dev_dbg(s->dev, "alloc buf=%d %p (dma %llu)\n", s->buf_num, in airspy_alloc_stream_bufs()
395 s->buf_list[s->buf_num], in airspy_alloc_stream_bufs()
396 (long long)s->dma_addr[s->buf_num]); in airspy_alloc_stream_bufs()
397 s->flags |= USB_STATE_URB_BUF; in airspy_alloc_stream_bufs()
403 static int airspy_free_urbs(struct airspy *s) in airspy_free_urbs() argument
407 airspy_kill_urbs(s); in airspy_free_urbs()
409 for (i = s->urbs_initialized - 1; i >= 0; i--) { in airspy_free_urbs()
410 if (s->urb_list[i]) { in airspy_free_urbs()
411 dev_dbg(s->dev, "free urb=%d\n", i); in airspy_free_urbs()
413 usb_free_urb(s->urb_list[i]); in airspy_free_urbs()
416 s->urbs_initialized = 0; in airspy_free_urbs()
421 static int airspy_alloc_urbs(struct airspy *s) in airspy_alloc_urbs() argument
427 dev_dbg(s->dev, "alloc urb=%d\n", i); in airspy_alloc_urbs()
428 s->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); in airspy_alloc_urbs()
429 if (!s->urb_list[i]) { in airspy_alloc_urbs()
430 dev_dbg(s->dev, "failed\n"); in airspy_alloc_urbs()
432 usb_free_urb(s->urb_list[j]); in airspy_alloc_urbs()
435 usb_fill_bulk_urb(s->urb_list[i], in airspy_alloc_urbs()
436 s->udev, in airspy_alloc_urbs()
437 usb_rcvbulkpipe(s->udev, 0x81), in airspy_alloc_urbs()
438 s->buf_list[i], in airspy_alloc_urbs()
440 airspy_urb_complete, s); in airspy_alloc_urbs()
442 s->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; in airspy_alloc_urbs()
443 s->urb_list[i]->transfer_dma = s->dma_addr[i]; in airspy_alloc_urbs()
444 s->urbs_initialized++; in airspy_alloc_urbs()
451 static void airspy_cleanup_queued_bufs(struct airspy *s) in airspy_cleanup_queued_bufs() argument
455 dev_dbg(s->dev, "\n"); in airspy_cleanup_queued_bufs()
457 spin_lock_irqsave(&s->queued_bufs_lock, flags); in airspy_cleanup_queued_bufs()
458 while (!list_empty(&s->queued_bufs)) { in airspy_cleanup_queued_bufs()
461 buf = list_entry(s->queued_bufs.next, in airspy_cleanup_queued_bufs()
466 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); in airspy_cleanup_queued_bufs()
473 struct airspy *s = container_of(v, struct airspy, v4l2_dev); in airspy_disconnect() local
475 dev_dbg(s->dev, "\n"); in airspy_disconnect()
477 mutex_lock(&s->vb_queue_lock); in airspy_disconnect()
478 mutex_lock(&s->v4l2_lock); in airspy_disconnect()
480 s->udev = NULL; in airspy_disconnect()
481 v4l2_device_disconnect(&s->v4l2_dev); in airspy_disconnect()
482 video_unregister_device(&s->vdev); in airspy_disconnect()
483 mutex_unlock(&s->v4l2_lock); in airspy_disconnect()
484 mutex_unlock(&s->vb_queue_lock); in airspy_disconnect()
486 v4l2_device_put(&s->v4l2_dev); in airspy_disconnect()
494 struct airspy *s = vb2_get_drv_priv(vq); in airspy_queue_setup() local
496 dev_dbg(s->dev, "nbuffers=%d\n", *nbuffers); in airspy_queue_setup()
502 sizes[0] = PAGE_ALIGN(s->buffersize); in airspy_queue_setup()
504 dev_dbg(s->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); in airspy_queue_setup()
511 struct airspy *s = vb2_get_drv_priv(vb->vb2_queue); in airspy_buf_queue() local
517 if (unlikely(!s->udev)) { in airspy_buf_queue()
522 spin_lock_irqsave(&s->queued_bufs_lock, flags); in airspy_buf_queue()
523 list_add_tail(&buf->list, &s->queued_bufs); in airspy_buf_queue()
524 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); in airspy_buf_queue()
529 struct airspy *s = vb2_get_drv_priv(vq); in airspy_start_streaming() local
532 dev_dbg(s->dev, "\n"); in airspy_start_streaming()
534 if (!s->udev) in airspy_start_streaming()
537 mutex_lock(&s->v4l2_lock); in airspy_start_streaming()
539 s->sequence = 0; in airspy_start_streaming()
541 set_bit(POWER_ON, &s->flags); in airspy_start_streaming()
543 ret = airspy_alloc_stream_bufs(s); in airspy_start_streaming()
547 ret = airspy_alloc_urbs(s); in airspy_start_streaming()
551 ret = airspy_submit_urbs(s); in airspy_start_streaming()
556 ret = airspy_ctrl_msg(s, CMD_RECEIVER_MODE, 1, 0, NULL, 0); in airspy_start_streaming()
563 airspy_kill_urbs(s); in airspy_start_streaming()
565 airspy_free_urbs(s); in airspy_start_streaming()
567 airspy_free_stream_bufs(s); in airspy_start_streaming()
569 clear_bit(POWER_ON, &s->flags); in airspy_start_streaming()
575 list_for_each_entry_safe(buf, tmp, &s->queued_bufs, list) { in airspy_start_streaming()
583 mutex_unlock(&s->v4l2_lock); in airspy_start_streaming()
590 struct airspy *s = vb2_get_drv_priv(vq); in airspy_stop_streaming() local
592 dev_dbg(s->dev, "\n"); in airspy_stop_streaming()
594 mutex_lock(&s->v4l2_lock); in airspy_stop_streaming()
597 airspy_ctrl_msg(s, CMD_RECEIVER_MODE, 0, 0, NULL, 0); in airspy_stop_streaming()
599 airspy_kill_urbs(s); in airspy_stop_streaming()
600 airspy_free_urbs(s); in airspy_stop_streaming()
601 airspy_free_stream_bufs(s); in airspy_stop_streaming()
603 airspy_cleanup_queued_bufs(s); in airspy_stop_streaming()
605 clear_bit(POWER_ON, &s->flags); in airspy_stop_streaming()
607 mutex_unlock(&s->v4l2_lock); in airspy_stop_streaming()
622 struct airspy *s = video_drvdata(file); in airspy_querycap() local
625 strlcpy(cap->card, s->vdev.name, sizeof(cap->card)); in airspy_querycap()
626 usb_make_path(s->udev, cap->bus_info, sizeof(cap->bus_info)); in airspy_querycap()
649 struct airspy *s = video_drvdata(file); in airspy_g_fmt_sdr_cap() local
651 f->fmt.sdr.pixelformat = s->pixelformat; in airspy_g_fmt_sdr_cap()
652 f->fmt.sdr.buffersize = s->buffersize; in airspy_g_fmt_sdr_cap()
661 struct airspy *s = video_drvdata(file); in airspy_s_fmt_sdr_cap() local
662 struct vb2_queue *q = &s->vb_queue; in airspy_s_fmt_sdr_cap()
671 s->pixelformat = formats[i].pixelformat; in airspy_s_fmt_sdr_cap()
672 s->buffersize = formats[i].buffersize; in airspy_s_fmt_sdr_cap()
678 s->pixelformat = formats[0].pixelformat; in airspy_s_fmt_sdr_cap()
679 s->buffersize = formats[0].buffersize; in airspy_s_fmt_sdr_cap()
748 struct airspy *s = video_drvdata(file); in airspy_g_frequency() local
753 f->frequency = s->f_adc; in airspy_g_frequency()
754 dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc); in airspy_g_frequency()
758 f->frequency = s->f_rf; in airspy_g_frequency()
759 dev_dbg(s->dev, "RF frequency=%u Hz\n", s->f_rf); in airspy_g_frequency()
771 struct airspy *s = video_drvdata(file); in airspy_s_frequency() local
776 s->f_adc = clamp_t(unsigned int, f->frequency, in airspy_s_frequency()
779 dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc); in airspy_s_frequency()
782 s->f_rf = clamp_t(unsigned int, f->frequency, in airspy_s_frequency()
785 dev_dbg(s->dev, "RF frequency=%u Hz\n", s->f_rf); in airspy_s_frequency()
786 buf[0] = (s->f_rf >> 0) & 0xff; in airspy_s_frequency()
787 buf[1] = (s->f_rf >> 8) & 0xff; in airspy_s_frequency()
788 buf[2] = (s->f_rf >> 16) & 0xff; in airspy_s_frequency()
789 buf[3] = (s->f_rf >> 24) & 0xff; in airspy_s_frequency()
790 ret = airspy_ctrl_msg(s, CMD_SET_FREQ, 0, 0, buf, 4); in airspy_s_frequency()
873 struct airspy *s = container_of(v, struct airspy, v4l2_dev); in airspy_video_release() local
875 v4l2_ctrl_handler_free(&s->hdl); in airspy_video_release()
876 v4l2_device_unregister(&s->v4l2_dev); in airspy_video_release()
877 kfree(s); in airspy_video_release()
880 static int airspy_set_lna_gain(struct airspy *s) in airspy_set_lna_gain() argument
885 dev_dbg(s->dev, "lna auto=%d->%d val=%d->%d\n", in airspy_set_lna_gain()
886 s->lna_gain_auto->cur.val, s->lna_gain_auto->val, in airspy_set_lna_gain()
887 s->lna_gain->cur.val, s->lna_gain->val); in airspy_set_lna_gain()
889 ret = airspy_ctrl_msg(s, CMD_SET_LNA_AGC, 0, s->lna_gain_auto->val, in airspy_set_lna_gain()
894 if (s->lna_gain_auto->val == false) { in airspy_set_lna_gain()
895 ret = airspy_ctrl_msg(s, CMD_SET_LNA_GAIN, 0, s->lna_gain->val, in airspy_set_lna_gain()
902 dev_dbg(s->dev, "failed=%d\n", ret); in airspy_set_lna_gain()
907 static int airspy_set_mixer_gain(struct airspy *s) in airspy_set_mixer_gain() argument
912 dev_dbg(s->dev, "mixer auto=%d->%d val=%d->%d\n", in airspy_set_mixer_gain()
913 s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val, in airspy_set_mixer_gain()
914 s->mixer_gain->cur.val, s->mixer_gain->val); in airspy_set_mixer_gain()
916 ret = airspy_ctrl_msg(s, CMD_SET_MIXER_AGC, 0, s->mixer_gain_auto->val, in airspy_set_mixer_gain()
921 if (s->mixer_gain_auto->val == false) { in airspy_set_mixer_gain()
922 ret = airspy_ctrl_msg(s, CMD_SET_MIXER_GAIN, 0, in airspy_set_mixer_gain()
923 s->mixer_gain->val, &u8tmp, 1); in airspy_set_mixer_gain()
929 dev_dbg(s->dev, "failed=%d\n", ret); in airspy_set_mixer_gain()
934 static int airspy_set_if_gain(struct airspy *s) in airspy_set_if_gain() argument
939 dev_dbg(s->dev, "val=%d->%d\n", s->if_gain->cur.val, s->if_gain->val); in airspy_set_if_gain()
941 ret = airspy_ctrl_msg(s, CMD_SET_VGA_GAIN, 0, s->if_gain->val, in airspy_set_if_gain()
944 dev_dbg(s->dev, "failed=%d\n", ret); in airspy_set_if_gain()
951 struct airspy *s = container_of(ctrl->handler, struct airspy, hdl); in airspy_s_ctrl() local
957 ret = airspy_set_lna_gain(s); in airspy_s_ctrl()
961 ret = airspy_set_mixer_gain(s); in airspy_s_ctrl()
964 ret = airspy_set_if_gain(s); in airspy_s_ctrl()
967 dev_dbg(s->dev, "unknown ctrl: id=%d name=%s\n", in airspy_s_ctrl()
982 struct airspy *s; in airspy_probe() local
986 s = kzalloc(sizeof(struct airspy), GFP_KERNEL); in airspy_probe()
987 if (s == NULL) { in airspy_probe()
992 mutex_init(&s->v4l2_lock); in airspy_probe()
993 mutex_init(&s->vb_queue_lock); in airspy_probe()
994 spin_lock_init(&s->queued_bufs_lock); in airspy_probe()
995 INIT_LIST_HEAD(&s->queued_bufs); in airspy_probe()
996 s->dev = &intf->dev; in airspy_probe()
997 s->udev = interface_to_usbdev(intf); in airspy_probe()
998 s->f_adc = bands[0].rangelow; in airspy_probe()
999 s->f_rf = bands_rf[0].rangelow; in airspy_probe()
1000 s->pixelformat = formats[0].pixelformat; in airspy_probe()
1001 s->buffersize = formats[0].buffersize; in airspy_probe()
1004 ret = airspy_ctrl_msg(s, CMD_BOARD_ID_READ, 0, 0, &u8tmp, 1); in airspy_probe()
1006 ret = airspy_ctrl_msg(s, CMD_VERSION_STRING_READ, 0, 0, in airspy_probe()
1009 dev_err(s->dev, "Could not detect board\n"); in airspy_probe()
1015 dev_info(s->dev, "Board ID: %02x\n", u8tmp); in airspy_probe()
1016 dev_info(s->dev, "Firmware version: %s\n", buf); in airspy_probe()
1019 s->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; in airspy_probe()
1020 s->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; in airspy_probe()
1021 s->vb_queue.drv_priv = s; in airspy_probe()
1022 s->vb_queue.buf_struct_size = sizeof(struct airspy_frame_buf); in airspy_probe()
1023 s->vb_queue.ops = &airspy_vb2_ops; in airspy_probe()
1024 s->vb_queue.mem_ops = &vb2_vmalloc_memops; in airspy_probe()
1025 s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in airspy_probe()
1026 ret = vb2_queue_init(&s->vb_queue); in airspy_probe()
1028 dev_err(s->dev, "Could not initialize vb2 queue\n"); in airspy_probe()
1033 s->vdev = airspy_template; in airspy_probe()
1034 s->vdev.queue = &s->vb_queue; in airspy_probe()
1035 s->vdev.queue->lock = &s->vb_queue_lock; in airspy_probe()
1036 video_set_drvdata(&s->vdev, s); in airspy_probe()
1039 s->v4l2_dev.release = airspy_video_release; in airspy_probe()
1040 ret = v4l2_device_register(&intf->dev, &s->v4l2_dev); in airspy_probe()
1042 dev_err(s->dev, "Failed to register v4l2-device (%d)\n", ret); in airspy_probe()
1047 v4l2_ctrl_handler_init(&s->hdl, 5); in airspy_probe()
1048 s->lna_gain_auto = v4l2_ctrl_new_std(&s->hdl, &airspy_ctrl_ops, in airspy_probe()
1050 s->lna_gain = v4l2_ctrl_new_std(&s->hdl, &airspy_ctrl_ops, in airspy_probe()
1052 v4l2_ctrl_auto_cluster(2, &s->lna_gain_auto, 0, false); in airspy_probe()
1053 s->mixer_gain_auto = v4l2_ctrl_new_std(&s->hdl, &airspy_ctrl_ops, in airspy_probe()
1055 s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, &airspy_ctrl_ops, in airspy_probe()
1057 v4l2_ctrl_auto_cluster(2, &s->mixer_gain_auto, 0, false); in airspy_probe()
1058 s->if_gain = v4l2_ctrl_new_std(&s->hdl, &airspy_ctrl_ops, in airspy_probe()
1060 if (s->hdl.error) { in airspy_probe()
1061 ret = s->hdl.error; in airspy_probe()
1062 dev_err(s->dev, "Could not initialize controls\n"); in airspy_probe()
1066 v4l2_ctrl_handler_setup(&s->hdl); in airspy_probe()
1068 s->v4l2_dev.ctrl_handler = &s->hdl; in airspy_probe()
1069 s->vdev.v4l2_dev = &s->v4l2_dev; in airspy_probe()
1070 s->vdev.lock = &s->v4l2_lock; in airspy_probe()
1072 ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1); in airspy_probe()
1074 dev_err(s->dev, "Failed to register as video device (%d)\n", in airspy_probe()
1078 dev_info(s->dev, "Registered as %s\n", in airspy_probe()
1079 video_device_node_name(&s->vdev)); in airspy_probe()
1080 …dev_notice(s->dev, "SDR API is still slightly experimental and functionality changes may follow\n"… in airspy_probe()
1084 v4l2_ctrl_handler_free(&s->hdl); in airspy_probe()
1085 v4l2_device_unregister(&s->v4l2_dev); in airspy_probe()
1087 kfree(s); in airspy_probe()