Lines Matching refs:dev
122 struct device *dev; member
160 struct msi2500_dev *dev) in msi2500_get_next_fill_buf() argument
165 spin_lock_irqsave(&dev->queued_bufs_lock, flags); in msi2500_get_next_fill_buf()
166 if (list_empty(&dev->queued_bufs)) in msi2500_get_next_fill_buf()
169 buf = list_entry(dev->queued_bufs.next, struct msi2500_frame_buf, list); in msi2500_get_next_fill_buf()
172 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); in msi2500_get_next_fill_buf()
258 static int msi2500_convert_stream(struct msi2500_dev *dev, u8 *dst, u8 *src, in msi2500_convert_stream() argument
270 if (i == 0 && dev->next_sample != sample[0]) { in msi2500_convert_stream()
271 dev_dbg_ratelimited(dev->dev, in msi2500_convert_stream()
273 sample[0] - dev->next_sample, in msi2500_convert_stream()
274 src_len, dev->next_sample, in msi2500_convert_stream()
282 dev_dbg_ratelimited(dev->dev, "%*ph\n", 12, &src[4]); in msi2500_convert_stream()
286 switch (dev->pixelformat) { in msi2500_convert_stream()
298 dev->next_sample = sample[i] + 504; in msi2500_convert_stream()
320 dev->next_sample = sample[i] + 252; in msi2500_convert_stream()
325 dev_dbg_ratelimited(dev->dev, "%*ph\n", 24, &src[1000]); in msi2500_convert_stream()
330 dev->next_sample = sample[i] + 384; in msi2500_convert_stream()
337 dev->next_sample = sample[i] + 504; in msi2500_convert_stream()
344 dev->next_sample = sample[i] + 336; in msi2500_convert_stream()
351 dev->next_sample = sample[i] + 252; in msi2500_convert_stream()
359 if (unlikely(time_is_before_jiffies(dev->jiffies_next))) { in msi2500_convert_stream()
362 dev->jiffies_next + msecs_to_jiffies(MSECS)); in msi2500_convert_stream()
363 unsigned int samples = dev->next_sample - dev->sample; in msi2500_convert_stream()
365 dev->jiffies_next = jiffies + msecs_to_jiffies(MSECS); in msi2500_convert_stream()
366 dev->sample = dev->next_sample; in msi2500_convert_stream()
367 dev_dbg(dev->dev, "size=%u samples=%u msecs=%u sample rate=%lu\n", in msi2500_convert_stream()
381 struct msi2500_dev *dev = (struct msi2500_dev *)urb->context; in msi2500_isoc_handler() local
389 dev_dbg(dev->dev, "URB (%p) unlinked %ssynchronuously\n", in msi2500_isoc_handler()
395 dev_dbg(dev->dev, "called with status %d\n", urb->status); in msi2500_isoc_handler()
397 if (++dev->isoc_errors > MAX_ISOC_ERRORS) in msi2500_isoc_handler()
398 dev_dbg(dev->dev, "Too many ISOC errors, bailing out\n"); in msi2500_isoc_handler()
402 dev->isoc_errors = 0; in msi2500_isoc_handler()
412 dev_dbg_ratelimited(dev->dev, in msi2500_isoc_handler()
426 fbuf = msi2500_get_next_fill_buf(dev); in msi2500_isoc_handler()
428 dev->vb_full++; in msi2500_isoc_handler()
429 dev_dbg_ratelimited(dev->dev, in msi2500_isoc_handler()
431 dev->vb_full); in msi2500_isoc_handler()
437 flen = msi2500_convert_stream(dev, ptr, iso_buf, flen); in msi2500_isoc_handler()
445 dev_dbg(dev->dev, "Error (%d) re-submitting urb\n", i); in msi2500_isoc_handler()
448 static void msi2500_iso_stop(struct msi2500_dev *dev) in msi2500_iso_stop() argument
452 dev_dbg(dev->dev, "\n"); in msi2500_iso_stop()
456 if (dev->urbs[i]) { in msi2500_iso_stop()
457 dev_dbg(dev->dev, "Unlinking URB %p\n", dev->urbs[i]); in msi2500_iso_stop()
458 usb_kill_urb(dev->urbs[i]); in msi2500_iso_stop()
463 static void msi2500_iso_free(struct msi2500_dev *dev) in msi2500_iso_free() argument
467 dev_dbg(dev->dev, "\n"); in msi2500_iso_free()
471 if (dev->urbs[i]) { in msi2500_iso_free()
472 dev_dbg(dev->dev, "Freeing URB\n"); in msi2500_iso_free()
473 if (dev->urbs[i]->transfer_buffer) { in msi2500_iso_free()
474 usb_free_coherent(dev->udev, in msi2500_iso_free()
475 dev->urbs[i]->transfer_buffer_length, in msi2500_iso_free()
476 dev->urbs[i]->transfer_buffer, in msi2500_iso_free()
477 dev->urbs[i]->transfer_dma); in msi2500_iso_free()
479 usb_free_urb(dev->urbs[i]); in msi2500_iso_free()
480 dev->urbs[i] = NULL; in msi2500_iso_free()
486 static void msi2500_isoc_cleanup(struct msi2500_dev *dev) in msi2500_isoc_cleanup() argument
488 dev_dbg(dev->dev, "\n"); in msi2500_isoc_cleanup()
490 msi2500_iso_stop(dev); in msi2500_isoc_cleanup()
491 msi2500_iso_free(dev); in msi2500_isoc_cleanup()
495 static int msi2500_isoc_init(struct msi2500_dev *dev) in msi2500_isoc_init() argument
500 dev_dbg(dev->dev, "\n"); in msi2500_isoc_init()
502 dev->isoc_errors = 0; in msi2500_isoc_init()
504 ret = usb_set_interface(dev->udev, 0, 1); in msi2500_isoc_init()
512 dev_err(dev->dev, "Failed to allocate urb %d\n", i); in msi2500_isoc_init()
513 msi2500_isoc_cleanup(dev); in msi2500_isoc_init()
516 dev->urbs[i] = urb; in msi2500_isoc_init()
517 dev_dbg(dev->dev, "Allocated URB at 0x%p\n", urb); in msi2500_isoc_init()
520 urb->dev = dev->udev; in msi2500_isoc_init()
521 urb->pipe = usb_rcvisocpipe(dev->udev, 0x81); in msi2500_isoc_init()
523 urb->transfer_buffer = usb_alloc_coherent(dev->udev, in msi2500_isoc_init()
527 dev_err(dev->dev, in msi2500_isoc_init()
529 msi2500_isoc_cleanup(dev); in msi2500_isoc_init()
534 urb->context = dev; in msi2500_isoc_init()
545 ret = usb_submit_urb(dev->urbs[i], GFP_KERNEL); in msi2500_isoc_init()
547 dev_err(dev->dev, in msi2500_isoc_init()
550 msi2500_isoc_cleanup(dev); in msi2500_isoc_init()
553 dev_dbg(dev->dev, "URB 0x%p submitted.\n", dev->urbs[i]); in msi2500_isoc_init()
561 static void msi2500_cleanup_queued_bufs(struct msi2500_dev *dev) in msi2500_cleanup_queued_bufs() argument
565 dev_dbg(dev->dev, "\n"); in msi2500_cleanup_queued_bufs()
567 spin_lock_irqsave(&dev->queued_bufs_lock, flags); in msi2500_cleanup_queued_bufs()
568 while (!list_empty(&dev->queued_bufs)) { in msi2500_cleanup_queued_bufs()
571 buf = list_entry(dev->queued_bufs.next, in msi2500_cleanup_queued_bufs()
576 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); in msi2500_cleanup_queued_bufs()
583 struct msi2500_dev *dev = in msi2500_disconnect() local
586 dev_dbg(dev->dev, "\n"); in msi2500_disconnect()
588 mutex_lock(&dev->vb_queue_lock); in msi2500_disconnect()
589 mutex_lock(&dev->v4l2_lock); in msi2500_disconnect()
591 dev->udev = NULL; in msi2500_disconnect()
592 v4l2_device_disconnect(&dev->v4l2_dev); in msi2500_disconnect()
593 video_unregister_device(&dev->vdev); in msi2500_disconnect()
594 spi_unregister_master(dev->master); in msi2500_disconnect()
595 mutex_unlock(&dev->v4l2_lock); in msi2500_disconnect()
596 mutex_unlock(&dev->vb_queue_lock); in msi2500_disconnect()
598 v4l2_device_put(&dev->v4l2_dev); in msi2500_disconnect()
604 struct msi2500_dev *dev = video_drvdata(file); in msi2500_querycap() local
606 dev_dbg(dev->dev, "\n"); in msi2500_querycap()
609 strlcpy(cap->card, dev->vdev.name, sizeof(cap->card)); in msi2500_querycap()
610 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); in msi2500_querycap()
624 struct msi2500_dev *dev = vb2_get_drv_priv(vq); in msi2500_queue_setup() local
626 dev_dbg(dev->dev, "nbuffers=%d\n", *nbuffers); in msi2500_queue_setup()
631 sizes[0] = PAGE_ALIGN(dev->buffersize); in msi2500_queue_setup()
632 dev_dbg(dev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); in msi2500_queue_setup()
639 struct msi2500_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in msi2500_buf_queue() local
646 if (unlikely(!dev->udev)) { in msi2500_buf_queue()
651 spin_lock_irqsave(&dev->queued_bufs_lock, flags); in msi2500_buf_queue()
652 list_add_tail(&buf->list, &dev->queued_bufs); in msi2500_buf_queue()
653 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); in msi2500_buf_queue()
672 static int msi2500_ctrl_msg(struct msi2500_dev *dev, u8 cmd, u32 data) in msi2500_ctrl_msg() argument
680 msi2500_dbg_usb_control_msg(dev->dev, request, requesttype, in msi2500_ctrl_msg()
682 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), request, in msi2500_ctrl_msg()
685 dev_err(dev->dev, "failed %d, cmd %02x, data %04x\n", in msi2500_ctrl_msg()
691 static int msi2500_set_usb_adc(struct msi2500_dev *dev) in msi2500_set_usb_adc() argument
699 f_sr = dev->f_adc; in msi2500_set_usb_adc()
702 bandwidth_auto = v4l2_ctrl_find(&dev->hdl, in msi2500_set_usb_adc()
705 bandwidth = v4l2_ctrl_find(&dev->hdl, in msi2500_set_usb_adc()
707 v4l2_ctrl_s_ctrl(bandwidth, dev->f_adc); in msi2500_set_usb_adc()
711 switch (dev->pixelformat) { in msi2500_set_usb_adc()
796 dev_dbg(dev->dev, "div_out=%u f_vco=%u\n", div_out, f_vco); in msi2500_set_usb_adc()
810 dev_dbg(dev->dev, in msi2500_set_usb_adc()
814 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00608008); in msi2500_set_usb_adc()
818 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00000c05); in msi2500_set_usb_adc()
822 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00020000); in msi2500_set_usb_adc()
826 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00480102); in msi2500_set_usb_adc()
830 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00f38008); in msi2500_set_usb_adc()
834 ret = msi2500_ctrl_msg(dev, CMD_WREG, reg7); in msi2500_set_usb_adc()
838 ret = msi2500_ctrl_msg(dev, CMD_WREG, reg4); in msi2500_set_usb_adc()
842 ret = msi2500_ctrl_msg(dev, CMD_WREG, reg3); in msi2500_set_usb_adc()
851 struct msi2500_dev *dev = vb2_get_drv_priv(vq); in msi2500_start_streaming() local
854 dev_dbg(dev->dev, "\n"); in msi2500_start_streaming()
856 if (!dev->udev) in msi2500_start_streaming()
859 if (mutex_lock_interruptible(&dev->v4l2_lock)) in msi2500_start_streaming()
863 v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 1); in msi2500_start_streaming()
865 ret = msi2500_set_usb_adc(dev); in msi2500_start_streaming()
867 ret = msi2500_isoc_init(dev); in msi2500_start_streaming()
869 msi2500_cleanup_queued_bufs(dev); in msi2500_start_streaming()
871 ret = msi2500_ctrl_msg(dev, CMD_START_STREAMING, 0); in msi2500_start_streaming()
873 mutex_unlock(&dev->v4l2_lock); in msi2500_start_streaming()
880 struct msi2500_dev *dev = vb2_get_drv_priv(vq); in msi2500_stop_streaming() local
882 dev_dbg(dev->dev, "\n"); in msi2500_stop_streaming()
884 mutex_lock(&dev->v4l2_lock); in msi2500_stop_streaming()
886 if (dev->udev) in msi2500_stop_streaming()
887 msi2500_isoc_cleanup(dev); in msi2500_stop_streaming()
889 msi2500_cleanup_queued_bufs(dev); in msi2500_stop_streaming()
893 if (!msi2500_ctrl_msg(dev, CMD_STOP_STREAMING, 0)) { in msi2500_stop_streaming()
895 msi2500_ctrl_msg(dev, CMD_WREG, 0x01000003); in msi2500_stop_streaming()
899 v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 0); in msi2500_stop_streaming()
901 mutex_unlock(&dev->v4l2_lock); in msi2500_stop_streaming()
916 struct msi2500_dev *dev = video_drvdata(file); in msi2500_enum_fmt_sdr_cap() local
918 dev_dbg(dev->dev, "index=%d\n", f->index); in msi2500_enum_fmt_sdr_cap()
920 if (f->index >= dev->num_formats) in msi2500_enum_fmt_sdr_cap()
932 struct msi2500_dev *dev = video_drvdata(file); in msi2500_g_fmt_sdr_cap() local
934 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", in msi2500_g_fmt_sdr_cap()
935 (char *)&dev->pixelformat); in msi2500_g_fmt_sdr_cap()
937 f->fmt.sdr.pixelformat = dev->pixelformat; in msi2500_g_fmt_sdr_cap()
938 f->fmt.sdr.buffersize = dev->buffersize; in msi2500_g_fmt_sdr_cap()
947 struct msi2500_dev *dev = video_drvdata(file); in msi2500_s_fmt_sdr_cap() local
948 struct vb2_queue *q = &dev->vb_queue; in msi2500_s_fmt_sdr_cap()
951 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", in msi2500_s_fmt_sdr_cap()
958 for (i = 0; i < dev->num_formats; i++) { in msi2500_s_fmt_sdr_cap()
960 dev->pixelformat = formats[i].pixelformat; in msi2500_s_fmt_sdr_cap()
961 dev->buffersize = formats[i].buffersize; in msi2500_s_fmt_sdr_cap()
967 dev->pixelformat = formats[0].pixelformat; in msi2500_s_fmt_sdr_cap()
968 dev->buffersize = formats[0].buffersize; in msi2500_s_fmt_sdr_cap()
978 struct msi2500_dev *dev = video_drvdata(file); in msi2500_try_fmt_sdr_cap() local
981 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n", in msi2500_try_fmt_sdr_cap()
985 for (i = 0; i < dev->num_formats; i++) { in msi2500_try_fmt_sdr_cap()
1001 struct msi2500_dev *dev = video_drvdata(file); in msi2500_s_tuner() local
1004 dev_dbg(dev->dev, "index=%d\n", v->index); in msi2500_s_tuner()
1009 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_tuner, v); in msi2500_s_tuner()
1018 struct msi2500_dev *dev = video_drvdata(file); in msi2500_g_tuner() local
1021 dev_dbg(dev->dev, "index=%d\n", v->index); in msi2500_g_tuner()
1031 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_tuner, v); in msi2500_g_tuner()
1042 struct msi2500_dev *dev = video_drvdata(file); in msi2500_g_frequency() local
1045 dev_dbg(dev->dev, "tuner=%d type=%d\n", f->tuner, f->type); in msi2500_g_frequency()
1048 f->frequency = dev->f_adc; in msi2500_g_frequency()
1052 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_frequency, f); in msi2500_g_frequency()
1063 struct msi2500_dev *dev = video_drvdata(file); in msi2500_s_frequency() local
1066 dev_dbg(dev->dev, "tuner=%d type=%d frequency=%u\n", in msi2500_s_frequency()
1070 dev->f_adc = clamp_t(unsigned int, f->frequency, in msi2500_s_frequency()
1073 dev_dbg(dev->dev, "ADC frequency=%u Hz\n", dev->f_adc); in msi2500_s_frequency()
1074 ret = msi2500_set_usb_adc(dev); in msi2500_s_frequency()
1076 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_frequency, f); in msi2500_s_frequency()
1087 struct msi2500_dev *dev = video_drvdata(file); in msi2500_enum_freq_bands() local
1090 dev_dbg(dev->dev, "tuner=%d type=%d index=%d\n", in msi2500_enum_freq_bands()
1101 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, in msi2500_enum_freq_bands()
1159 struct msi2500_dev *dev = container_of(v, struct msi2500_dev, v4l2_dev); in msi2500_video_release() local
1161 v4l2_ctrl_handler_free(&dev->hdl); in msi2500_video_release()
1162 v4l2_device_unregister(&dev->v4l2_dev); in msi2500_video_release()
1163 kfree(dev); in msi2500_video_release()
1169 struct msi2500_dev *dev = spi_master_get_devdata(master); in msi2500_transfer_one_message() local
1175 dev_dbg(dev->dev, "msg=%*ph\n", t->len, t->tx_buf); in msi2500_transfer_one_message()
1180 ret = msi2500_ctrl_msg(dev, CMD_WREG, data); in msi2500_transfer_one_message()
1191 struct msi2500_dev *dev; in msi2500_probe() local
1202 dev = kzalloc(sizeof(*dev), GFP_KERNEL); in msi2500_probe()
1203 if (!dev) { in msi2500_probe()
1208 mutex_init(&dev->v4l2_lock); in msi2500_probe()
1209 mutex_init(&dev->vb_queue_lock); in msi2500_probe()
1210 spin_lock_init(&dev->queued_bufs_lock); in msi2500_probe()
1211 INIT_LIST_HEAD(&dev->queued_bufs); in msi2500_probe()
1212 dev->dev = &intf->dev; in msi2500_probe()
1213 dev->udev = interface_to_usbdev(intf); in msi2500_probe()
1214 dev->f_adc = bands[0].rangelow; in msi2500_probe()
1215 dev->pixelformat = formats[0].pixelformat; in msi2500_probe()
1216 dev->buffersize = formats[0].buffersize; in msi2500_probe()
1217 dev->num_formats = NUM_FORMATS; in msi2500_probe()
1219 dev->num_formats -= 2; in msi2500_probe()
1222 dev->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; in msi2500_probe()
1223 dev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; in msi2500_probe()
1224 dev->vb_queue.drv_priv = dev; in msi2500_probe()
1225 dev->vb_queue.buf_struct_size = sizeof(struct msi2500_frame_buf); in msi2500_probe()
1226 dev->vb_queue.ops = &msi2500_vb2_ops; in msi2500_probe()
1227 dev->vb_queue.mem_ops = &vb2_vmalloc_memops; in msi2500_probe()
1228 dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in msi2500_probe()
1229 ret = vb2_queue_init(&dev->vb_queue); in msi2500_probe()
1231 dev_err(dev->dev, "Could not initialize vb2 queue\n"); in msi2500_probe()
1236 dev->vdev = msi2500_template; in msi2500_probe()
1237 dev->vdev.queue = &dev->vb_queue; in msi2500_probe()
1238 dev->vdev.queue->lock = &dev->vb_queue_lock; in msi2500_probe()
1239 video_set_drvdata(&dev->vdev, dev); in msi2500_probe()
1242 dev->v4l2_dev.release = msi2500_video_release; in msi2500_probe()
1243 ret = v4l2_device_register(&intf->dev, &dev->v4l2_dev); in msi2500_probe()
1245 dev_err(dev->dev, "Failed to register v4l2-device (%d)\n", ret); in msi2500_probe()
1250 master = spi_alloc_master(dev->dev, 0); in msi2500_probe()
1256 dev->master = master; in msi2500_probe()
1260 spi_master_set_devdata(master, dev); in msi2500_probe()
1268 sd = v4l2_spi_new_subdev(&dev->v4l2_dev, master, &board_info); in msi2500_probe()
1269 dev->v4l2_subdev = sd; in msi2500_probe()
1271 dev_err(dev->dev, "cannot get v4l2 subdevice\n"); in msi2500_probe()
1277 v4l2_ctrl_handler_init(&dev->hdl, 0); in msi2500_probe()
1278 if (dev->hdl.error) { in msi2500_probe()
1279 ret = dev->hdl.error; in msi2500_probe()
1280 dev_err(dev->dev, "Could not initialize controls\n"); in msi2500_probe()
1285 v4l2_ctrl_add_handler(&dev->hdl, sd->ctrl_handler, NULL); in msi2500_probe()
1287 dev->v4l2_dev.ctrl_handler = &dev->hdl; in msi2500_probe()
1288 dev->vdev.v4l2_dev = &dev->v4l2_dev; in msi2500_probe()
1289 dev->vdev.lock = &dev->v4l2_lock; in msi2500_probe()
1291 ret = video_register_device(&dev->vdev, VFL_TYPE_SDR, -1); in msi2500_probe()
1293 dev_err(dev->dev, in msi2500_probe()
1297 dev_info(dev->dev, "Registered as %s\n", in msi2500_probe()
1298 video_device_node_name(&dev->vdev)); in msi2500_probe()
1299 dev_notice(dev->dev, in msi2500_probe()
1303 v4l2_ctrl_handler_free(&dev->hdl); in msi2500_probe()
1305 spi_unregister_master(dev->master); in msi2500_probe()
1307 v4l2_device_unregister(&dev->v4l2_dev); in msi2500_probe()
1309 kfree(dev); in msi2500_probe()