Lines Matching +full:usb +full:- +full:plugin

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * GNU Radio plugin "gr-kernel" for device usage will be on:
8 * https://git.linuxtv.org/anttip/gr-kernel.git
14 #include <media/v4l2-device.h>
15 #include <media/v4l2-ioctl.h>
16 #include <media/v4l2-ctrls.h>
17 #include <media/v4l2-event.h>
18 #include <media/videobuf2-v4l2.h>
19 #include <media/videobuf2-vmalloc.h>
32 ((sd) && (sd)->ops && (sd)->ops->o && (sd)->ops->o->f)
94 /* intermediate buffers with raw data from the USB device */
96 /* common v4l buffer stuff -- must be first */
159 spin_lock_irqsave(&dev->queued_bufs_lock, flags); in rtl2832_sdr_get_next_fill_buf()
160 if (list_empty(&dev->queued_bufs)) in rtl2832_sdr_get_next_fill_buf()
163 buf = list_entry(dev->queued_bufs.next, in rtl2832_sdr_get_next_fill_buf()
165 list_del(&buf->list); in rtl2832_sdr_get_next_fill_buf()
167 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); in rtl2832_sdr_get_next_fill_buf()
174 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_convert_stream()
177 if (dev->pixelformat == V4L2_SDR_FMT_CU8) { in rtl2832_sdr_convert_stream()
181 } else if (dev->pixelformat == V4L2_SDR_FMT_CU16LE) { in rtl2832_sdr_convert_stream()
194 if (unlikely(time_is_before_jiffies(dev->jiffies_next))) { in rtl2832_sdr_convert_stream()
196 unsigned int msecs = jiffies_to_msecs(jiffies - in rtl2832_sdr_convert_stream()
197 dev->jiffies_next + msecs_to_jiffies(MSECS)); in rtl2832_sdr_convert_stream()
198 unsigned int samples = dev->sample - dev->sample_measured; in rtl2832_sdr_convert_stream()
200 dev->jiffies_next = jiffies + msecs_to_jiffies(MSECS); in rtl2832_sdr_convert_stream()
201 dev->sample_measured = dev->sample; in rtl2832_sdr_convert_stream()
202 dev_dbg(&pdev->dev, in rtl2832_sdr_convert_stream()
208 dev->sample += src_len / 2; in rtl2832_sdr_convert_stream()
219 struct rtl2832_sdr_dev *dev = urb->context; in rtl2832_sdr_urb_complete()
220 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_urb_complete()
223 dev_dbg_ratelimited(&pdev->dev, "status=%d length=%d/%d errors=%d\n", in rtl2832_sdr_urb_complete()
224 urb->status, urb->actual_length, in rtl2832_sdr_urb_complete()
225 urb->transfer_buffer_length, urb->error_count); in rtl2832_sdr_urb_complete()
227 switch (urb->status) { in rtl2832_sdr_urb_complete()
229 case -ETIMEDOUT: /* NAK */ in rtl2832_sdr_urb_complete()
231 case -ECONNRESET: /* kill */ in rtl2832_sdr_urb_complete()
232 case -ENOENT: in rtl2832_sdr_urb_complete()
233 case -ESHUTDOWN: in rtl2832_sdr_urb_complete()
236 dev_err_ratelimited(&pdev->dev, "urb failed=%d\n", urb->status); in rtl2832_sdr_urb_complete()
240 if (likely(urb->actual_length > 0)) { in rtl2832_sdr_urb_complete()
246 dev->vb_full++; in rtl2832_sdr_urb_complete()
247 dev_notice_ratelimited(&pdev->dev, in rtl2832_sdr_urb_complete()
249 dev->vb_full); in rtl2832_sdr_urb_complete()
254 ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0); in rtl2832_sdr_urb_complete()
255 len = rtl2832_sdr_convert_stream(dev, ptr, urb->transfer_buffer, in rtl2832_sdr_urb_complete()
256 urb->actual_length); in rtl2832_sdr_urb_complete()
257 vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len); in rtl2832_sdr_urb_complete()
258 fbuf->vb.vb2_buf.timestamp = ktime_get_ns(); in rtl2832_sdr_urb_complete()
259 fbuf->vb.sequence = dev->sequence++; in rtl2832_sdr_urb_complete()
260 vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE); in rtl2832_sdr_urb_complete()
268 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_kill_urbs()
271 for (i = dev->urbs_submitted - 1; i >= 0; i--) { in rtl2832_sdr_kill_urbs()
272 dev_dbg(&pdev->dev, "kill urb=%d\n", i); in rtl2832_sdr_kill_urbs()
274 usb_kill_urb(dev->urb_list[i]); in rtl2832_sdr_kill_urbs()
276 dev->urbs_submitted = 0; in rtl2832_sdr_kill_urbs()
283 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_submit_urbs()
286 for (i = 0; i < dev->urbs_initialized; i++) { in rtl2832_sdr_submit_urbs()
287 dev_dbg(&pdev->dev, "submit urb=%d\n", i); in rtl2832_sdr_submit_urbs()
288 ret = usb_submit_urb(dev->urb_list[i], GFP_KERNEL); in rtl2832_sdr_submit_urbs()
290 dev_err(&pdev->dev, in rtl2832_sdr_submit_urbs()
291 "Could not submit urb no. %d - get them all back\n", in rtl2832_sdr_submit_urbs()
296 dev->urbs_submitted++; in rtl2832_sdr_submit_urbs()
304 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_free_stream_bufs()
306 if (test_bit(URB_BUF, &dev->flags)) { in rtl2832_sdr_free_stream_bufs()
307 while (dev->buf_num) { in rtl2832_sdr_free_stream_bufs()
308 dev->buf_num--; in rtl2832_sdr_free_stream_bufs()
309 dev_dbg(&pdev->dev, "free buf=%d\n", dev->buf_num); in rtl2832_sdr_free_stream_bufs()
310 usb_free_coherent(dev->udev, dev->buf_size, in rtl2832_sdr_free_stream_bufs()
311 dev->buf_list[dev->buf_num], in rtl2832_sdr_free_stream_bufs()
312 dev->dma_addr[dev->buf_num]); in rtl2832_sdr_free_stream_bufs()
315 clear_bit(URB_BUF, &dev->flags); in rtl2832_sdr_free_stream_bufs()
322 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_alloc_stream_bufs()
324 dev->buf_num = 0; in rtl2832_sdr_alloc_stream_bufs()
325 dev->buf_size = BULK_BUFFER_SIZE; in rtl2832_sdr_alloc_stream_bufs()
327 dev_dbg(&pdev->dev, "all in all I will use %u bytes for streaming\n", in rtl2832_sdr_alloc_stream_bufs()
330 for (dev->buf_num = 0; dev->buf_num < MAX_BULK_BUFS; dev->buf_num++) { in rtl2832_sdr_alloc_stream_bufs()
331 dev->buf_list[dev->buf_num] = usb_alloc_coherent(dev->udev, in rtl2832_sdr_alloc_stream_bufs()
333 &dev->dma_addr[dev->buf_num]); in rtl2832_sdr_alloc_stream_bufs()
334 if (!dev->buf_list[dev->buf_num]) { in rtl2832_sdr_alloc_stream_bufs()
335 dev_dbg(&pdev->dev, "alloc buf=%d failed\n", in rtl2832_sdr_alloc_stream_bufs()
336 dev->buf_num); in rtl2832_sdr_alloc_stream_bufs()
338 return -ENOMEM; in rtl2832_sdr_alloc_stream_bufs()
341 dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n", in rtl2832_sdr_alloc_stream_bufs()
342 dev->buf_num, dev->buf_list[dev->buf_num], in rtl2832_sdr_alloc_stream_bufs()
343 (long long)dev->dma_addr[dev->buf_num]); in rtl2832_sdr_alloc_stream_bufs()
344 set_bit(URB_BUF, &dev->flags); in rtl2832_sdr_alloc_stream_bufs()
352 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_free_urbs()
357 for (i = dev->urbs_initialized - 1; i >= 0; i--) { in rtl2832_sdr_free_urbs()
358 if (dev->urb_list[i]) { in rtl2832_sdr_free_urbs()
359 dev_dbg(&pdev->dev, "free urb=%d\n", i); in rtl2832_sdr_free_urbs()
361 usb_free_urb(dev->urb_list[i]); in rtl2832_sdr_free_urbs()
364 dev->urbs_initialized = 0; in rtl2832_sdr_free_urbs()
371 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_alloc_urbs()
376 dev_dbg(&pdev->dev, "alloc urb=%d\n", i); in rtl2832_sdr_alloc_urbs()
377 dev->urb_list[i] = usb_alloc_urb(0, GFP_KERNEL); in rtl2832_sdr_alloc_urbs()
378 if (!dev->urb_list[i]) { in rtl2832_sdr_alloc_urbs()
380 usb_free_urb(dev->urb_list[j]); in rtl2832_sdr_alloc_urbs()
381 dev->urb_list[j] = NULL; in rtl2832_sdr_alloc_urbs()
383 dev->urbs_initialized = 0; in rtl2832_sdr_alloc_urbs()
384 return -ENOMEM; in rtl2832_sdr_alloc_urbs()
386 usb_fill_bulk_urb(dev->urb_list[i], in rtl2832_sdr_alloc_urbs()
387 dev->udev, in rtl2832_sdr_alloc_urbs()
388 usb_rcvbulkpipe(dev->udev, 0x81), in rtl2832_sdr_alloc_urbs()
389 dev->buf_list[i], in rtl2832_sdr_alloc_urbs()
393 dev->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; in rtl2832_sdr_alloc_urbs()
394 dev->urb_list[i]->transfer_dma = dev->dma_addr[i]; in rtl2832_sdr_alloc_urbs()
395 dev->urbs_initialized++; in rtl2832_sdr_alloc_urbs()
404 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_cleanup_queued_bufs()
407 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_cleanup_queued_bufs()
409 spin_lock_irqsave(&dev->queued_bufs_lock, flags); in rtl2832_sdr_cleanup_queued_bufs()
410 while (!list_empty(&dev->queued_bufs)) { in rtl2832_sdr_cleanup_queued_bufs()
413 buf = list_entry(dev->queued_bufs.next, in rtl2832_sdr_cleanup_queued_bufs()
415 list_del(&buf->list); in rtl2832_sdr_cleanup_queued_bufs()
416 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in rtl2832_sdr_cleanup_queued_bufs()
418 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); in rtl2832_sdr_cleanup_queued_bufs()
425 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_querycap()
427 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_querycap()
429 strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); in rtl2832_sdr_querycap()
430 strscpy(cap->card, dev->vdev.name, sizeof(cap->card)); in rtl2832_sdr_querycap()
431 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); in rtl2832_sdr_querycap()
441 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_queue_setup()
444 dev_dbg(&pdev->dev, "nbuffers=%d\n", *nbuffers); in rtl2832_sdr_queue_setup()
448 *nbuffers = 8 - q_num_bufs; in rtl2832_sdr_queue_setup()
450 sizes[0] = PAGE_ALIGN(dev->buffersize); in rtl2832_sdr_queue_setup()
451 dev_dbg(&pdev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); in rtl2832_sdr_queue_setup()
457 struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in rtl2832_sdr_buf_prepare()
460 if (!dev->udev) in rtl2832_sdr_buf_prepare()
461 return -ENODEV; in rtl2832_sdr_buf_prepare()
469 struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in rtl2832_sdr_buf_queue()
475 if (!dev->udev) { in rtl2832_sdr_buf_queue()
476 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in rtl2832_sdr_buf_queue()
480 spin_lock_irqsave(&dev->queued_bufs_lock, flags); in rtl2832_sdr_buf_queue()
481 list_add_tail(&buf->list, &dev->queued_bufs); in rtl2832_sdr_buf_queue()
482 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags); in rtl2832_sdr_buf_queue()
487 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_set_adc()
488 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_set_adc()
489 struct dvb_frontend *fe = pdata->dvb_frontend; in rtl2832_sdr_set_adc()
496 dev_dbg(&pdev->dev, "f_adc=%u\n", dev->f_adc); in rtl2832_sdr_set_adc()
498 if (!test_bit(POWER_ON, &dev->flags)) in rtl2832_sdr_set_adc()
501 if (dev->f_adc == 0) in rtl2832_sdr_set_adc()
504 f_sr = dev->f_adc; in rtl2832_sdr_set_adc()
506 ret = regmap_bulk_write(dev->regmap, 0x13e, "\x00\x00", 2); in rtl2832_sdr_set_adc()
510 ret = regmap_bulk_write(dev->regmap, 0x115, "\x00\x00\x00\x00", 4); in rtl2832_sdr_set_adc()
515 if (fe->ops.tuner_ops.get_if_frequency) in rtl2832_sdr_set_adc()
516 ret = fe->ops.tuner_ops.get_if_frequency(fe, &f_if); in rtl2832_sdr_set_adc()
518 ret = -EINVAL; in rtl2832_sdr_set_adc()
524 u64tmp = f_if % pdata->clk; in rtl2832_sdr_set_adc()
526 u64tmp = div_u64(u64tmp, pdata->clk); in rtl2832_sdr_set_adc()
527 u64tmp = -u64tmp; in rtl2832_sdr_set_adc()
530 dev_dbg(&pdev->dev, "f_if=%u if_ctl=%08x\n", f_if, u32tmp); in rtl2832_sdr_set_adc()
536 ret = regmap_bulk_write(dev->regmap, 0x119, buf, 3); in rtl2832_sdr_set_adc()
543 u8tmp1 = 0x1a; /* disable Zero-IF */ in rtl2832_sdr_set_adc()
546 u8tmp1 = 0x1b; /* enable Zero-IF, DC, IQ */ in rtl2832_sdr_set_adc()
550 ret = regmap_write(dev->regmap, 0x1b1, u8tmp1); in rtl2832_sdr_set_adc()
554 ret = regmap_write(dev->regmap, 0x008, u8tmp2); in rtl2832_sdr_set_adc()
558 ret = regmap_write(dev->regmap, 0x006, 0x80); in rtl2832_sdr_set_adc()
563 u32tmp = div_u64(pdata->clk * 0x400000ULL, f_sr * 4U); in rtl2832_sdr_set_adc()
569 ret = regmap_bulk_write(dev->regmap, 0x19f, buf, 4); in rtl2832_sdr_set_adc()
573 /* low-pass filter */ in rtl2832_sdr_set_adc()
574 ret = regmap_bulk_write(dev->regmap, 0x11c, in rtl2832_sdr_set_adc()
580 ret = regmap_bulk_write(dev->regmap, 0x017, "\x11\x10", 2); in rtl2832_sdr_set_adc()
585 ret = regmap_write(dev->regmap, 0x019, 0x05); in rtl2832_sdr_set_adc()
589 ret = regmap_bulk_write(dev->regmap, 0x01a, in rtl2832_sdr_set_adc()
595 ret = regmap_bulk_write(dev->regmap, 0x192, "\x00\xf0\x0f", 3); in rtl2832_sdr_set_adc()
600 ret = regmap_write(dev->regmap, 0x061, 0x60); in rtl2832_sdr_set_adc()
605 switch (pdata->tuner) { in rtl2832_sdr_set_adc()
607 ret = regmap_write(dev->regmap, 0x112, 0x5a); in rtl2832_sdr_set_adc()
608 ret = regmap_write(dev->regmap, 0x102, 0x40); in rtl2832_sdr_set_adc()
609 ret = regmap_write(dev->regmap, 0x103, 0x5a); in rtl2832_sdr_set_adc()
610 ret = regmap_write(dev->regmap, 0x1c7, 0x30); in rtl2832_sdr_set_adc()
611 ret = regmap_write(dev->regmap, 0x104, 0xd0); in rtl2832_sdr_set_adc()
612 ret = regmap_write(dev->regmap, 0x105, 0xbe); in rtl2832_sdr_set_adc()
613 ret = regmap_write(dev->regmap, 0x1c8, 0x18); in rtl2832_sdr_set_adc()
614 ret = regmap_write(dev->regmap, 0x106, 0x35); in rtl2832_sdr_set_adc()
615 ret = regmap_write(dev->regmap, 0x1c9, 0x21); in rtl2832_sdr_set_adc()
616 ret = regmap_write(dev->regmap, 0x1ca, 0x21); in rtl2832_sdr_set_adc()
617 ret = regmap_write(dev->regmap, 0x1cb, 0x00); in rtl2832_sdr_set_adc()
618 ret = regmap_write(dev->regmap, 0x107, 0x40); in rtl2832_sdr_set_adc()
619 ret = regmap_write(dev->regmap, 0x1cd, 0x10); in rtl2832_sdr_set_adc()
620 ret = regmap_write(dev->regmap, 0x1ce, 0x10); in rtl2832_sdr_set_adc()
621 ret = regmap_write(dev->regmap, 0x108, 0x80); in rtl2832_sdr_set_adc()
622 ret = regmap_write(dev->regmap, 0x109, 0x7f); in rtl2832_sdr_set_adc()
623 ret = regmap_write(dev->regmap, 0x10a, 0x80); in rtl2832_sdr_set_adc()
624 ret = regmap_write(dev->regmap, 0x10b, 0x7f); in rtl2832_sdr_set_adc()
625 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
626 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
627 ret = regmap_write(dev->regmap, 0x011, 0xd4); in rtl2832_sdr_set_adc()
628 ret = regmap_write(dev->regmap, 0x1e5, 0xf0); in rtl2832_sdr_set_adc()
629 ret = regmap_write(dev->regmap, 0x1d9, 0x00); in rtl2832_sdr_set_adc()
630 ret = regmap_write(dev->regmap, 0x1db, 0x00); in rtl2832_sdr_set_adc()
631 ret = regmap_write(dev->regmap, 0x1dd, 0x14); in rtl2832_sdr_set_adc()
632 ret = regmap_write(dev->regmap, 0x1de, 0xec); in rtl2832_sdr_set_adc()
633 ret = regmap_write(dev->regmap, 0x1d8, 0x0c); in rtl2832_sdr_set_adc()
634 ret = regmap_write(dev->regmap, 0x1e6, 0x02); in rtl2832_sdr_set_adc()
635 ret = regmap_write(dev->regmap, 0x1d7, 0x09); in rtl2832_sdr_set_adc()
636 ret = regmap_write(dev->regmap, 0x00d, 0x83); in rtl2832_sdr_set_adc()
637 ret = regmap_write(dev->regmap, 0x010, 0x49); in rtl2832_sdr_set_adc()
638 ret = regmap_write(dev->regmap, 0x00d, 0x87); in rtl2832_sdr_set_adc()
639 ret = regmap_write(dev->regmap, 0x00d, 0x85); in rtl2832_sdr_set_adc()
640 ret = regmap_write(dev->regmap, 0x013, 0x02); in rtl2832_sdr_set_adc()
644 ret = regmap_write(dev->regmap, 0x112, 0x5a); in rtl2832_sdr_set_adc()
645 ret = regmap_write(dev->regmap, 0x102, 0x40); in rtl2832_sdr_set_adc()
646 ret = regmap_write(dev->regmap, 0x103, 0x5a); in rtl2832_sdr_set_adc()
647 ret = regmap_write(dev->regmap, 0x1c7, 0x2c); in rtl2832_sdr_set_adc()
648 ret = regmap_write(dev->regmap, 0x104, 0xcc); in rtl2832_sdr_set_adc()
649 ret = regmap_write(dev->regmap, 0x105, 0xbe); in rtl2832_sdr_set_adc()
650 ret = regmap_write(dev->regmap, 0x1c8, 0x16); in rtl2832_sdr_set_adc()
651 ret = regmap_write(dev->regmap, 0x106, 0x35); in rtl2832_sdr_set_adc()
652 ret = regmap_write(dev->regmap, 0x1c9, 0x21); in rtl2832_sdr_set_adc()
653 ret = regmap_write(dev->regmap, 0x1ca, 0x21); in rtl2832_sdr_set_adc()
654 ret = regmap_write(dev->regmap, 0x1cb, 0x00); in rtl2832_sdr_set_adc()
655 ret = regmap_write(dev->regmap, 0x107, 0x40); in rtl2832_sdr_set_adc()
656 ret = regmap_write(dev->regmap, 0x1cd, 0x10); in rtl2832_sdr_set_adc()
657 ret = regmap_write(dev->regmap, 0x1ce, 0x10); in rtl2832_sdr_set_adc()
658 ret = regmap_write(dev->regmap, 0x108, 0x80); in rtl2832_sdr_set_adc()
659 ret = regmap_write(dev->regmap, 0x109, 0x7f); in rtl2832_sdr_set_adc()
660 ret = regmap_write(dev->regmap, 0x10a, 0x80); in rtl2832_sdr_set_adc()
661 ret = regmap_write(dev->regmap, 0x10b, 0x7f); in rtl2832_sdr_set_adc()
662 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
663 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
664 ret = regmap_bulk_write(dev->regmap, 0x011, "\xe9\xbf", 2); in rtl2832_sdr_set_adc()
665 ret = regmap_write(dev->regmap, 0x1e5, 0xf0); in rtl2832_sdr_set_adc()
666 ret = regmap_write(dev->regmap, 0x1d9, 0x00); in rtl2832_sdr_set_adc()
667 ret = regmap_write(dev->regmap, 0x1db, 0x00); in rtl2832_sdr_set_adc()
668 ret = regmap_write(dev->regmap, 0x1dd, 0x11); in rtl2832_sdr_set_adc()
669 ret = regmap_write(dev->regmap, 0x1de, 0xef); in rtl2832_sdr_set_adc()
670 ret = regmap_write(dev->regmap, 0x1d8, 0x0c); in rtl2832_sdr_set_adc()
671 ret = regmap_write(dev->regmap, 0x1e6, 0x02); in rtl2832_sdr_set_adc()
672 ret = regmap_write(dev->regmap, 0x1d7, 0x09); in rtl2832_sdr_set_adc()
676 ret = regmap_write(dev->regmap, 0x112, 0x5a); in rtl2832_sdr_set_adc()
677 ret = regmap_write(dev->regmap, 0x102, 0x40); in rtl2832_sdr_set_adc()
678 ret = regmap_write(dev->regmap, 0x115, 0x01); in rtl2832_sdr_set_adc()
679 ret = regmap_write(dev->regmap, 0x103, 0x80); in rtl2832_sdr_set_adc()
680 ret = regmap_write(dev->regmap, 0x1c7, 0x24); in rtl2832_sdr_set_adc()
681 ret = regmap_write(dev->regmap, 0x104, 0xcc); in rtl2832_sdr_set_adc()
682 ret = regmap_write(dev->regmap, 0x105, 0xbe); in rtl2832_sdr_set_adc()
683 ret = regmap_write(dev->regmap, 0x1c8, 0x14); in rtl2832_sdr_set_adc()
684 ret = regmap_write(dev->regmap, 0x106, 0x35); in rtl2832_sdr_set_adc()
685 ret = regmap_write(dev->regmap, 0x1c9, 0x21); in rtl2832_sdr_set_adc()
686 ret = regmap_write(dev->regmap, 0x1ca, 0x21); in rtl2832_sdr_set_adc()
687 ret = regmap_write(dev->regmap, 0x1cb, 0x00); in rtl2832_sdr_set_adc()
688 ret = regmap_write(dev->regmap, 0x107, 0x40); in rtl2832_sdr_set_adc()
689 ret = regmap_write(dev->regmap, 0x1cd, 0x10); in rtl2832_sdr_set_adc()
690 ret = regmap_write(dev->regmap, 0x1ce, 0x10); in rtl2832_sdr_set_adc()
691 ret = regmap_write(dev->regmap, 0x108, 0x80); in rtl2832_sdr_set_adc()
692 ret = regmap_write(dev->regmap, 0x109, 0x7f); in rtl2832_sdr_set_adc()
693 ret = regmap_write(dev->regmap, 0x10a, 0x80); in rtl2832_sdr_set_adc()
694 ret = regmap_write(dev->regmap, 0x10b, 0x7f); in rtl2832_sdr_set_adc()
695 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
696 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
697 ret = regmap_write(dev->regmap, 0x011, 0xf4); in rtl2832_sdr_set_adc()
700 ret = regmap_write(dev->regmap, 0x112, 0x39); in rtl2832_sdr_set_adc()
701 ret = regmap_write(dev->regmap, 0x102, 0x40); in rtl2832_sdr_set_adc()
702 ret = regmap_write(dev->regmap, 0x103, 0x5a); in rtl2832_sdr_set_adc()
703 ret = regmap_write(dev->regmap, 0x1c7, 0x2c); in rtl2832_sdr_set_adc()
704 ret = regmap_write(dev->regmap, 0x104, 0xcc); in rtl2832_sdr_set_adc()
705 ret = regmap_write(dev->regmap, 0x105, 0xbe); in rtl2832_sdr_set_adc()
706 ret = regmap_write(dev->regmap, 0x1c8, 0x16); in rtl2832_sdr_set_adc()
707 ret = regmap_write(dev->regmap, 0x106, 0x35); in rtl2832_sdr_set_adc()
708 ret = regmap_write(dev->regmap, 0x1c9, 0x21); in rtl2832_sdr_set_adc()
709 ret = regmap_write(dev->regmap, 0x1ca, 0x21); in rtl2832_sdr_set_adc()
710 ret = regmap_write(dev->regmap, 0x1cb, 0x00); in rtl2832_sdr_set_adc()
711 ret = regmap_write(dev->regmap, 0x107, 0x40); in rtl2832_sdr_set_adc()
712 ret = regmap_write(dev->regmap, 0x1cd, 0x10); in rtl2832_sdr_set_adc()
713 ret = regmap_write(dev->regmap, 0x1ce, 0x10); in rtl2832_sdr_set_adc()
714 ret = regmap_write(dev->regmap, 0x108, 0x80); in rtl2832_sdr_set_adc()
715 ret = regmap_write(dev->regmap, 0x109, 0x7f); in rtl2832_sdr_set_adc()
716 ret = regmap_write(dev->regmap, 0x10a, 0x9c); in rtl2832_sdr_set_adc()
717 ret = regmap_write(dev->regmap, 0x10b, 0x7f); in rtl2832_sdr_set_adc()
718 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
719 ret = regmap_write(dev->regmap, 0x00e, 0xfc); in rtl2832_sdr_set_adc()
720 ret = regmap_bulk_write(dev->regmap, 0x011, "\xe9\xf4", 2); in rtl2832_sdr_set_adc()
723 dev_notice(&pdev->dev, "Unsupported tuner\n"); in rtl2832_sdr_set_adc()
727 ret = regmap_update_bits(dev->regmap, 0x101, 0x04, 0x04); in rtl2832_sdr_set_adc()
731 ret = regmap_update_bits(dev->regmap, 0x101, 0x04, 0x00); in rtl2832_sdr_set_adc()
740 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_unset_adc()
743 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_unset_adc()
746 ret = regmap_write(dev->regmap, 0x061, 0xe0); in rtl2832_sdr_unset_adc()
751 ret = regmap_write(dev->regmap, 0x019, 0x20); in rtl2832_sdr_unset_adc()
755 ret = regmap_bulk_write(dev->regmap, 0x017, "\x11\x10", 2); in rtl2832_sdr_unset_adc()
760 ret = regmap_bulk_write(dev->regmap, 0x192, "\x00\x0f\xff", 3); in rtl2832_sdr_unset_adc()
764 ret = regmap_bulk_write(dev->regmap, 0x13e, "\x40\x00", 2); in rtl2832_sdr_unset_adc()
768 ret = regmap_bulk_write(dev->regmap, 0x115, "\x06\x3f\xce\xcc", 4); in rtl2832_sdr_unset_adc()
777 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_set_tuner_freq()
778 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_set_tuner_freq()
779 struct dvb_frontend *fe = pdata->dvb_frontend; in rtl2832_sdr_set_tuner_freq()
780 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in rtl2832_sdr_set_tuner_freq()
787 if (dev->f_tuner == 0) in rtl2832_sdr_set_tuner_freq()
793 bandwidth_auto = v4l2_ctrl_find(&dev->hdl, in rtl2832_sdr_set_tuner_freq()
795 bandwidth = v4l2_ctrl_find(&dev->hdl, V4L2_CID_RF_TUNER_BANDWIDTH); in rtl2832_sdr_set_tuner_freq()
797 c->bandwidth_hz = dev->f_adc; in rtl2832_sdr_set_tuner_freq()
798 v4l2_ctrl_s_ctrl(bandwidth, dev->f_adc); in rtl2832_sdr_set_tuner_freq()
800 c->bandwidth_hz = v4l2_ctrl_g_ctrl(bandwidth); in rtl2832_sdr_set_tuner_freq()
803 c->frequency = dev->f_tuner; in rtl2832_sdr_set_tuner_freq()
804 c->delivery_system = SYS_DVBT; in rtl2832_sdr_set_tuner_freq()
806 dev_dbg(&pdev->dev, "frequency=%u bandwidth=%d\n", in rtl2832_sdr_set_tuner_freq()
807 c->frequency, c->bandwidth_hz); in rtl2832_sdr_set_tuner_freq()
809 if (!test_bit(POWER_ON, &dev->flags)) in rtl2832_sdr_set_tuner_freq()
812 if (!V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, s_frequency)) { in rtl2832_sdr_set_tuner_freq()
813 if (fe->ops.tuner_ops.set_params) in rtl2832_sdr_set_tuner_freq()
814 fe->ops.tuner_ops.set_params(fe); in rtl2832_sdr_set_tuner_freq()
822 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_set_tuner()
823 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_set_tuner()
824 struct dvb_frontend *fe = pdata->dvb_frontend; in rtl2832_sdr_set_tuner()
826 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_set_tuner()
828 if (fe->ops.tuner_ops.init) in rtl2832_sdr_set_tuner()
829 fe->ops.tuner_ops.init(fe); in rtl2832_sdr_set_tuner()
836 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_unset_tuner()
837 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_unset_tuner()
838 struct dvb_frontend *fe = pdata->dvb_frontend; in rtl2832_sdr_unset_tuner()
840 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_unset_tuner()
842 if (fe->ops.tuner_ops.sleep) in rtl2832_sdr_unset_tuner()
843 fe->ops.tuner_ops.sleep(fe); in rtl2832_sdr_unset_tuner()
851 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_start_streaming()
852 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_start_streaming()
853 struct dvb_usb_device *d = pdata->dvb_usb_device; in rtl2832_sdr_start_streaming()
856 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_start_streaming()
858 if (!dev->udev) in rtl2832_sdr_start_streaming()
859 return -ENODEV; in rtl2832_sdr_start_streaming()
861 if (mutex_lock_interruptible(&dev->v4l2_lock)) in rtl2832_sdr_start_streaming()
862 return -ERESTARTSYS; in rtl2832_sdr_start_streaming()
864 if (d->props->power_ctrl) in rtl2832_sdr_start_streaming()
865 d->props->power_ctrl(d, 1); in rtl2832_sdr_start_streaming()
868 if (d->props->frontend_ctrl) in rtl2832_sdr_start_streaming()
869 d->props->frontend_ctrl(pdata->dvb_frontend, 1); in rtl2832_sdr_start_streaming()
871 set_bit(POWER_ON, &dev->flags); in rtl2832_sdr_start_streaming()
873 /* wake-up tuner */ in rtl2832_sdr_start_streaming()
874 if (V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, core, s_power)) in rtl2832_sdr_start_streaming()
875 ret = v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 1); in rtl2832_sdr_start_streaming()
897 dev->sequence = 0; in rtl2832_sdr_start_streaming()
904 mutex_unlock(&dev->v4l2_lock); in rtl2832_sdr_start_streaming()
912 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_stop_streaming()
913 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_stop_streaming()
914 struct dvb_usb_device *d = pdata->dvb_usb_device; in rtl2832_sdr_stop_streaming()
916 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_stop_streaming()
918 mutex_lock(&dev->v4l2_lock); in rtl2832_sdr_stop_streaming()
927 if (V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, core, s_power)) in rtl2832_sdr_stop_streaming()
928 v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 0); in rtl2832_sdr_stop_streaming()
932 clear_bit(POWER_ON, &dev->flags); in rtl2832_sdr_stop_streaming()
935 if (d->props->frontend_ctrl) in rtl2832_sdr_stop_streaming()
936 d->props->frontend_ctrl(pdata->dvb_frontend, 0); in rtl2832_sdr_stop_streaming()
938 if (d->props->power_ctrl) in rtl2832_sdr_stop_streaming()
939 d->props->power_ctrl(d, 0); in rtl2832_sdr_stop_streaming()
941 mutex_unlock(&dev->v4l2_lock); in rtl2832_sdr_stop_streaming()
958 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_g_tuner()
961 dev_dbg(&pdev->dev, "index=%d type=%d\n", v->index, v->type); in rtl2832_sdr_g_tuner()
963 if (v->index == 0) { in rtl2832_sdr_g_tuner()
964 strscpy(v->name, "ADC: Realtek RTL2832", sizeof(v->name)); in rtl2832_sdr_g_tuner()
965 v->type = V4L2_TUNER_ADC; in rtl2832_sdr_g_tuner()
966 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; in rtl2832_sdr_g_tuner()
967 v->rangelow = 300000; in rtl2832_sdr_g_tuner()
968 v->rangehigh = 3200000; in rtl2832_sdr_g_tuner()
970 } else if (v->index == 1 && in rtl2832_sdr_g_tuner()
971 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, g_tuner)) { in rtl2832_sdr_g_tuner()
972 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_tuner, v); in rtl2832_sdr_g_tuner()
973 } else if (v->index == 1) { in rtl2832_sdr_g_tuner()
974 strscpy(v->name, "RF: <unknown>", sizeof(v->name)); in rtl2832_sdr_g_tuner()
975 v->type = V4L2_TUNER_RF; in rtl2832_sdr_g_tuner()
976 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; in rtl2832_sdr_g_tuner()
977 v->rangelow = 50000000; in rtl2832_sdr_g_tuner()
978 v->rangehigh = 2000000000; in rtl2832_sdr_g_tuner()
981 ret = -EINVAL; in rtl2832_sdr_g_tuner()
990 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_s_tuner()
993 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_s_tuner()
995 if (v->index == 0) { in rtl2832_sdr_s_tuner()
997 } else if (v->index == 1 && in rtl2832_sdr_s_tuner()
998 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, s_tuner)) { in rtl2832_sdr_s_tuner()
999 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_tuner, v); in rtl2832_sdr_s_tuner()
1000 } else if (v->index == 1) { in rtl2832_sdr_s_tuner()
1003 ret = -EINVAL; in rtl2832_sdr_s_tuner()
1012 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_enum_freq_bands()
1015 dev_dbg(&pdev->dev, "tuner=%d type=%d index=%d\n", in rtl2832_sdr_enum_freq_bands()
1016 band->tuner, band->type, band->index); in rtl2832_sdr_enum_freq_bands()
1018 if (band->tuner == 0) { in rtl2832_sdr_enum_freq_bands()
1019 if (band->index >= ARRAY_SIZE(bands_adc)) in rtl2832_sdr_enum_freq_bands()
1020 return -EINVAL; in rtl2832_sdr_enum_freq_bands()
1022 *band = bands_adc[band->index]; in rtl2832_sdr_enum_freq_bands()
1024 } else if (band->tuner == 1 && in rtl2832_sdr_enum_freq_bands()
1025 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, enum_freq_bands)) { in rtl2832_sdr_enum_freq_bands()
1026 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, enum_freq_bands, band); in rtl2832_sdr_enum_freq_bands()
1027 } else if (band->tuner == 1) { in rtl2832_sdr_enum_freq_bands()
1028 if (band->index >= ARRAY_SIZE(bands_fm)) in rtl2832_sdr_enum_freq_bands()
1029 return -EINVAL; in rtl2832_sdr_enum_freq_bands()
1031 *band = bands_fm[band->index]; in rtl2832_sdr_enum_freq_bands()
1034 ret = -EINVAL; in rtl2832_sdr_enum_freq_bands()
1043 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_g_frequency()
1046 dev_dbg(&pdev->dev, "tuner=%d type=%d\n", f->tuner, f->type); in rtl2832_sdr_g_frequency()
1048 if (f->tuner == 0) { in rtl2832_sdr_g_frequency()
1049 f->frequency = dev->f_adc; in rtl2832_sdr_g_frequency()
1050 f->type = V4L2_TUNER_ADC; in rtl2832_sdr_g_frequency()
1052 } else if (f->tuner == 1 && in rtl2832_sdr_g_frequency()
1053 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, g_frequency)) { in rtl2832_sdr_g_frequency()
1054 f->type = V4L2_TUNER_RF; in rtl2832_sdr_g_frequency()
1055 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_frequency, f); in rtl2832_sdr_g_frequency()
1056 } else if (f->tuner == 1) { in rtl2832_sdr_g_frequency()
1057 f->frequency = dev->f_tuner; in rtl2832_sdr_g_frequency()
1058 f->type = V4L2_TUNER_RF; in rtl2832_sdr_g_frequency()
1061 ret = -EINVAL; in rtl2832_sdr_g_frequency()
1070 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_s_frequency()
1073 dev_dbg(&pdev->dev, "tuner=%d type=%d frequency=%u\n", in rtl2832_sdr_s_frequency()
1074 f->tuner, f->type, f->frequency); in rtl2832_sdr_s_frequency()
1080 if (f->tuner == 0 && f->type == V4L2_TUNER_ADC) { in rtl2832_sdr_s_frequency()
1081 if (f->frequency < BAND_ADC_0) in rtl2832_sdr_s_frequency()
1083 else if (f->frequency < BAND_ADC_1) in rtl2832_sdr_s_frequency()
1088 dev->f_adc = clamp_t(unsigned int, f->frequency, in rtl2832_sdr_s_frequency()
1092 dev_dbg(&pdev->dev, "ADC frequency=%u Hz\n", dev->f_adc); in rtl2832_sdr_s_frequency()
1094 } else if (f->tuner == 1 && in rtl2832_sdr_s_frequency()
1095 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, s_frequency)) { in rtl2832_sdr_s_frequency()
1096 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_frequency, f); in rtl2832_sdr_s_frequency()
1097 } else if (f->tuner == 1) { in rtl2832_sdr_s_frequency()
1098 dev->f_tuner = clamp_t(unsigned int, f->frequency, in rtl2832_sdr_s_frequency()
1101 dev_dbg(&pdev->dev, "RF frequency=%u Hz\n", f->frequency); in rtl2832_sdr_s_frequency()
1105 ret = -EINVAL; in rtl2832_sdr_s_frequency()
1114 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_enum_fmt_sdr_cap()
1116 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_enum_fmt_sdr_cap()
1118 if (f->index >= dev->num_formats) in rtl2832_sdr_enum_fmt_sdr_cap()
1119 return -EINVAL; in rtl2832_sdr_enum_fmt_sdr_cap()
1121 f->pixelformat = formats[f->index].pixelformat; in rtl2832_sdr_enum_fmt_sdr_cap()
1130 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_g_fmt_sdr_cap()
1132 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_g_fmt_sdr_cap()
1134 f->fmt.sdr.pixelformat = dev->pixelformat; in rtl2832_sdr_g_fmt_sdr_cap()
1135 f->fmt.sdr.buffersize = dev->buffersize; in rtl2832_sdr_g_fmt_sdr_cap()
1144 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_s_fmt_sdr_cap()
1145 struct vb2_queue *q = &dev->vb_queue; in rtl2832_sdr_s_fmt_sdr_cap()
1148 dev_dbg(&pdev->dev, "pixelformat fourcc %4.4s\n", in rtl2832_sdr_s_fmt_sdr_cap()
1149 (char *)&f->fmt.sdr.pixelformat); in rtl2832_sdr_s_fmt_sdr_cap()
1152 return -EBUSY; in rtl2832_sdr_s_fmt_sdr_cap()
1154 for (i = 0; i < dev->num_formats; i++) { in rtl2832_sdr_s_fmt_sdr_cap()
1155 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { in rtl2832_sdr_s_fmt_sdr_cap()
1156 dev->pixelformat = formats[i].pixelformat; in rtl2832_sdr_s_fmt_sdr_cap()
1157 dev->buffersize = formats[i].buffersize; in rtl2832_sdr_s_fmt_sdr_cap()
1158 f->fmt.sdr.buffersize = formats[i].buffersize; in rtl2832_sdr_s_fmt_sdr_cap()
1163 dev->pixelformat = formats[0].pixelformat; in rtl2832_sdr_s_fmt_sdr_cap()
1164 dev->buffersize = formats[0].buffersize; in rtl2832_sdr_s_fmt_sdr_cap()
1165 f->fmt.sdr.pixelformat = formats[0].pixelformat; in rtl2832_sdr_s_fmt_sdr_cap()
1166 f->fmt.sdr.buffersize = formats[0].buffersize; in rtl2832_sdr_s_fmt_sdr_cap()
1175 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_try_fmt_sdr_cap()
1178 dev_dbg(&pdev->dev, "pixelformat fourcc %4.4s\n", in rtl2832_sdr_try_fmt_sdr_cap()
1179 (char *)&f->fmt.sdr.pixelformat); in rtl2832_sdr_try_fmt_sdr_cap()
1181 for (i = 0; i < dev->num_formats; i++) { in rtl2832_sdr_try_fmt_sdr_cap()
1182 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { in rtl2832_sdr_try_fmt_sdr_cap()
1183 f->fmt.sdr.buffersize = formats[i].buffersize; in rtl2832_sdr_try_fmt_sdr_cap()
1188 f->fmt.sdr.pixelformat = formats[0].pixelformat; in rtl2832_sdr_try_fmt_sdr_cap()
1189 f->fmt.sdr.buffersize = formats[0].buffersize; in rtl2832_sdr_try_fmt_sdr_cap()
1246 container_of(ctrl->handler, struct rtl2832_sdr_dev, in rtl2832_sdr_s_ctrl()
1248 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_s_ctrl()
1249 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_s_ctrl()
1250 struct dvb_frontend *fe = pdata->dvb_frontend; in rtl2832_sdr_s_ctrl()
1251 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in rtl2832_sdr_s_ctrl()
1254 dev_dbg(&pdev->dev, "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n", in rtl2832_sdr_s_ctrl()
1255 ctrl->id, ctrl->name, ctrl->val, ctrl->minimum, ctrl->maximum, in rtl2832_sdr_s_ctrl()
1256 ctrl->step); in rtl2832_sdr_s_ctrl()
1258 switch (ctrl->id) { in rtl2832_sdr_s_ctrl()
1262 if (dev->bandwidth_auto->val) { in rtl2832_sdr_s_ctrl()
1264 s32 val = dev->f_adc + div_u64(dev->bandwidth->step, 2); in rtl2832_sdr_s_ctrl()
1267 val = clamp_t(s32, val, dev->bandwidth->minimum, in rtl2832_sdr_s_ctrl()
1268 dev->bandwidth->maximum); in rtl2832_sdr_s_ctrl()
1269 offset = val - dev->bandwidth->minimum; in rtl2832_sdr_s_ctrl()
1270 offset = dev->bandwidth->step * in rtl2832_sdr_s_ctrl()
1271 div_u64(offset, dev->bandwidth->step); in rtl2832_sdr_s_ctrl()
1272 dev->bandwidth->val = dev->bandwidth->minimum + offset; in rtl2832_sdr_s_ctrl()
1274 c->bandwidth_hz = dev->bandwidth->val; in rtl2832_sdr_s_ctrl()
1276 if (!test_bit(POWER_ON, &dev->flags)) in rtl2832_sdr_s_ctrl()
1279 if (fe->ops.tuner_ops.set_params) in rtl2832_sdr_s_ctrl()
1280 ret = fe->ops.tuner_ops.set_params(fe); in rtl2832_sdr_s_ctrl()
1285 ret = -EINVAL; in rtl2832_sdr_s_ctrl()
1299 struct platform_device *pdev = dev->pdev; in rtl2832_sdr_video_release()
1301 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_video_release()
1303 v4l2_ctrl_handler_free(&dev->hdl); in rtl2832_sdr_video_release()
1304 v4l2_device_unregister(&dev->v4l2_dev); in rtl2832_sdr_video_release()
1312 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; in rtl2832_sdr_probe()
1317 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_probe()
1320 dev_err(&pdev->dev, "Cannot proceed without platform data\n"); in rtl2832_sdr_probe()
1321 ret = -EINVAL; in rtl2832_sdr_probe()
1324 if (!pdev->dev.parent->driver) { in rtl2832_sdr_probe()
1325 dev_dbg(&pdev->dev, "No parent device\n"); in rtl2832_sdr_probe()
1326 ret = -EINVAL; in rtl2832_sdr_probe()
1330 if (!try_module_get(pdev->dev.parent->driver->owner)) { in rtl2832_sdr_probe()
1331 dev_err(&pdev->dev, "Refcount fail"); in rtl2832_sdr_probe()
1332 ret = -EINVAL; in rtl2832_sdr_probe()
1337 ret = -ENOMEM; in rtl2832_sdr_probe()
1342 subdev = pdata->v4l2_subdev; in rtl2832_sdr_probe()
1343 dev->v4l2_subdev = pdata->v4l2_subdev; in rtl2832_sdr_probe()
1344 dev->pdev = pdev; in rtl2832_sdr_probe()
1345 dev->regmap = pdata->regmap; in rtl2832_sdr_probe()
1346 dev->udev = pdata->dvb_usb_device->udev; in rtl2832_sdr_probe()
1347 dev->f_adc = bands_adc[0].rangelow; in rtl2832_sdr_probe()
1348 dev->f_tuner = bands_fm[0].rangelow; in rtl2832_sdr_probe()
1349 dev->pixelformat = formats[0].pixelformat; in rtl2832_sdr_probe()
1350 dev->buffersize = formats[0].buffersize; in rtl2832_sdr_probe()
1351 dev->num_formats = NUM_FORMATS; in rtl2832_sdr_probe()
1353 dev->num_formats -= 1; in rtl2832_sdr_probe()
1355 mutex_init(&dev->v4l2_lock); in rtl2832_sdr_probe()
1356 mutex_init(&dev->vb_queue_lock); in rtl2832_sdr_probe()
1357 spin_lock_init(&dev->queued_bufs_lock); in rtl2832_sdr_probe()
1358 INIT_LIST_HEAD(&dev->queued_bufs); in rtl2832_sdr_probe()
1361 dev->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; in rtl2832_sdr_probe()
1362 dev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; in rtl2832_sdr_probe()
1363 dev->vb_queue.drv_priv = dev; in rtl2832_sdr_probe()
1364 dev->vb_queue.buf_struct_size = sizeof(struct rtl2832_sdr_frame_buf); in rtl2832_sdr_probe()
1365 dev->vb_queue.ops = &rtl2832_sdr_vb2_ops; in rtl2832_sdr_probe()
1366 dev->vb_queue.mem_ops = &vb2_vmalloc_memops; in rtl2832_sdr_probe()
1367 dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in rtl2832_sdr_probe()
1368 ret = vb2_queue_init(&dev->vb_queue); in rtl2832_sdr_probe()
1370 dev_err(&pdev->dev, "Could not initialize vb2 queue\n"); in rtl2832_sdr_probe()
1375 switch (pdata->tuner) { in rtl2832_sdr_probe()
1377 v4l2_ctrl_handler_init(&dev->hdl, 9); in rtl2832_sdr_probe()
1379 v4l2_ctrl_add_handler(&dev->hdl, subdev->ctrl_handler, in rtl2832_sdr_probe()
1384 v4l2_ctrl_handler_init(&dev->hdl, 2); in rtl2832_sdr_probe()
1385 dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, ops, in rtl2832_sdr_probe()
1388 dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, ops, in rtl2832_sdr_probe()
1391 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false); in rtl2832_sdr_probe()
1395 v4l2_ctrl_handler_init(&dev->hdl, 2); in rtl2832_sdr_probe()
1396 dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, ops, in rtl2832_sdr_probe()
1399 dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, ops, in rtl2832_sdr_probe()
1403 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false); in rtl2832_sdr_probe()
1406 v4l2_ctrl_handler_init(&dev->hdl, 2); in rtl2832_sdr_probe()
1408 v4l2_ctrl_add_handler(&dev->hdl, subdev->ctrl_handler, in rtl2832_sdr_probe()
1412 v4l2_ctrl_handler_init(&dev->hdl, 0); in rtl2832_sdr_probe()
1413 dev_err(&pdev->dev, "Unsupported tuner\n"); in rtl2832_sdr_probe()
1414 ret = -ENODEV; in rtl2832_sdr_probe()
1417 if (dev->hdl.error) { in rtl2832_sdr_probe()
1418 ret = dev->hdl.error; in rtl2832_sdr_probe()
1419 dev_err(&pdev->dev, "Could not initialize controls\n"); in rtl2832_sdr_probe()
1424 dev->vdev = rtl2832_sdr_template; in rtl2832_sdr_probe()
1425 dev->vdev.queue = &dev->vb_queue; in rtl2832_sdr_probe()
1426 dev->vdev.queue->lock = &dev->vb_queue_lock; in rtl2832_sdr_probe()
1427 video_set_drvdata(&dev->vdev, dev); in rtl2832_sdr_probe()
1430 dev->v4l2_dev.release = rtl2832_sdr_video_release; in rtl2832_sdr_probe()
1431 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); in rtl2832_sdr_probe()
1433 dev_err(&pdev->dev, "Failed to register v4l2-device %d\n", ret); in rtl2832_sdr_probe()
1437 dev->v4l2_dev.ctrl_handler = &dev->hdl; in rtl2832_sdr_probe()
1438 dev->vdev.v4l2_dev = &dev->v4l2_dev; in rtl2832_sdr_probe()
1439 dev->vdev.lock = &dev->v4l2_lock; in rtl2832_sdr_probe()
1440 dev->vdev.vfl_dir = VFL_DIR_RX; in rtl2832_sdr_probe()
1442 ret = video_register_device(&dev->vdev, VFL_TYPE_SDR, -1); in rtl2832_sdr_probe()
1444 dev_err(&pdev->dev, "Failed to register as video device %d\n", in rtl2832_sdr_probe()
1448 dev_info(&pdev->dev, "Registered as %s\n", in rtl2832_sdr_probe()
1449 video_device_node_name(&dev->vdev)); in rtl2832_sdr_probe()
1450 dev_info(&pdev->dev, "Realtek RTL2832 SDR attached\n"); in rtl2832_sdr_probe()
1451 dev_notice(&pdev->dev, in rtl2832_sdr_probe()
1456 v4l2_device_unregister(&dev->v4l2_dev); in rtl2832_sdr_probe()
1458 v4l2_ctrl_handler_free(&dev->hdl); in rtl2832_sdr_probe()
1462 module_put(pdev->dev.parent->driver->owner); in rtl2832_sdr_probe()
1471 dev_dbg(&pdev->dev, "\n"); in rtl2832_sdr_remove()
1473 mutex_lock(&dev->vb_queue_lock); in rtl2832_sdr_remove()
1474 mutex_lock(&dev->v4l2_lock); in rtl2832_sdr_remove()
1476 dev->udev = NULL; in rtl2832_sdr_remove()
1477 v4l2_device_disconnect(&dev->v4l2_dev); in rtl2832_sdr_remove()
1478 video_unregister_device(&dev->vdev); in rtl2832_sdr_remove()
1479 mutex_unlock(&dev->v4l2_lock); in rtl2832_sdr_remove()
1480 mutex_unlock(&dev->vb_queue_lock); in rtl2832_sdr_remove()
1481 v4l2_device_put(&dev->v4l2_dev); in rtl2832_sdr_remove()
1482 module_put(pdev->dev.parent->driver->owner); in rtl2832_sdr_remove()