Lines Matching +full:num +full:- +full:channels

1 // SPDX-License-Identifier: GPL-2.0+
3 * R-Car Gen3 Digital Radio Interface (DRIF) driver
9 * The R-Car DRIF is a receive only MSIOF like controller with an
11 * then this driver uses the SYS-DMAC engine to move the data from
15 * channels DRIFx0 & DRIFx1 within itself with each having its own resources
16 * like module clk, register set, irq and dma. These internal channels share
18 * considered to represent the two internal channels. This internal split
22 * (1) both internal channels (D0 & D1) to receive data in parallel (or)
29 * framework. This driver expects a tuner driver (sub-device) to bind
42 #include <linux/dma-mapping.h>
52 #include <media/v4l2-async.h>
53 #include <media/v4l2-ctrls.h>
54 #include <media/v4l2-device.h>
55 #include <media/v4l2-event.h>
56 #include <media/v4l2-fh.h>
57 #include <media/v4l2-ioctl.h>
58 #include <media/videobuf2-v4l2.h>
59 #include <media/videobuf2-vmalloc.h>
104 #define RCAR_DRIF_MDR_GRPCNT(n) (((n) - 1) << 30)
105 #define RCAR_DRIF_MDR_BITLEN(n) (((n) - 1) << 24)
106 #define RCAR_DRIF_MDR_WDCNT(n) (((n) - 1) << 16)
128 (&((sdr)->ch[!(ch_num)]->buf[(idx)]))
135 dev_dbg(sdr->v4l2_dev.dev, fmt, ## arg)
138 dev_err(sdr->v4l2_dev.dev, fmt, ## arg)
174 /* Buffer for a received frame from one or both internal channels */
176 /* Common v4l buffer stuff -- must be first */
188 void *addr; /* CPU-side address */
202 unsigned int num; /* Channel number */ member
216 spinlock_t dma_lock; /* To serialize DMA cb of channels */
232 unsigned long hw_ch_mask; /* Enabled channels per DT */
233 unsigned long cur_ch_mask; /* Used channels for an SDR FMT */
234 u32 num_hw_ch; /* Num of DT enabled channels */
235 u32 num_cur_ch; /* Num of used channels */
243 writel(data, ch->base + offset); in rcar_drif_write()
248 return readl(ch->base + offset); in rcar_drif_read()
251 /* Release DMA channels */
256 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) in rcar_drif_release_dmachannels()
257 if (sdr->ch[i]->dmach) { in rcar_drif_release_dmachannels()
258 dma_release_channel(sdr->ch[i]->dmach); in rcar_drif_release_dmachannels()
259 sdr->ch[i]->dmach = NULL; in rcar_drif_release_dmachannels()
263 /* Allocate DMA channels */
270 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_alloc_dmachannels()
271 struct rcar_drif *ch = sdr->ch[i]; in rcar_drif_alloc_dmachannels()
273 ch->dmach = dma_request_chan(&ch->pdev->dev, "rx"); in rcar_drif_alloc_dmachannels()
274 if (IS_ERR(ch->dmach)) { in rcar_drif_alloc_dmachannels()
275 ret = PTR_ERR(ch->dmach); in rcar_drif_alloc_dmachannels()
276 if (ret != -EPROBE_DEFER) in rcar_drif_alloc_dmachannels()
279 i, ch->dmach); in rcar_drif_alloc_dmachannels()
280 ch->dmach = NULL; in rcar_drif_alloc_dmachannels()
286 dma_cfg.src_addr = (phys_addr_t)(ch->start + RCAR_DRIF_SIRFDR); in rcar_drif_alloc_dmachannels()
288 ret = dmaengine_slave_config(ch->dmach, &dma_cfg); in rcar_drif_alloc_dmachannels()
308 spin_lock_irqsave(&sdr->queued_bufs_lock, flags); in rcar_drif_release_queued_bufs()
309 list_for_each_entry_safe(fbuf, tmp, &sdr->queued_bufs, list) { in rcar_drif_release_queued_bufs()
310 list_del(&fbuf->list); in rcar_drif_release_queued_bufs()
311 vb2_buffer_done(&fbuf->vb.vb2_buf, state); in rcar_drif_release_queued_bufs()
313 spin_unlock_irqrestore(&sdr->queued_bufs_lock, flags); in rcar_drif_release_queued_bufs()
321 /* Set defaults for enabled internal channels */ in rcar_drif_set_mdr1()
322 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_set_mdr1()
324 rcar_drif_write(sdr->ch[i], RCAR_DRIF_SITMDR1, in rcar_drif_set_mdr1()
328 rcar_drif_write(sdr->ch[i], RCAR_DRIF_SIRMDR1, sdr->mdr1); in rcar_drif_set_mdr1()
331 i, rcar_drif_read(sdr->ch[i], RCAR_DRIF_SIRMDR1)); in rcar_drif_set_mdr1()
341 sdr->fmt->bitlen, sdr->fmt->wdcnt, sdr->fmt->num_ch); in rcar_drif_set_format()
344 if (sdr->fmt->num_ch > sdr->num_cur_ch) { in rcar_drif_set_format()
346 sdr->fmt->num_ch, sdr->num_cur_ch); in rcar_drif_set_format()
347 return -EINVAL; in rcar_drif_set_format()
351 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_set_format()
356 RCAR_DRIF_MDR_BITLEN(sdr->fmt->bitlen) | in rcar_drif_set_format()
357 RCAR_DRIF_MDR_WDCNT(sdr->fmt->wdcnt); in rcar_drif_set_format()
358 rcar_drif_write(sdr->ch[i], RCAR_DRIF_SIRMDR2, mdr); in rcar_drif_set_format()
360 mdr = RCAR_DRIF_MDR_BITLEN(sdr->fmt->bitlen) | in rcar_drif_set_format()
361 RCAR_DRIF_MDR_WDCNT(sdr->fmt->wdcnt); in rcar_drif_set_format()
362 rcar_drif_write(sdr->ch[i], RCAR_DRIF_SIRMDR3, mdr); in rcar_drif_set_format()
365 i, rcar_drif_read(sdr->ch[i], RCAR_DRIF_SIRMDR2), in rcar_drif_set_format()
366 rcar_drif_read(sdr->ch[i], RCAR_DRIF_SIRMDR3)); in rcar_drif_set_format()
376 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_release_buf()
377 struct rcar_drif *ch = sdr->ch[i]; in rcar_drif_release_buf()
380 if (ch->buf[0].addr) { in rcar_drif_release_buf()
381 dma_free_coherent(&ch->pdev->dev, in rcar_drif_release_buf()
382 sdr->hwbuf_size * RCAR_DRIF_NUM_HWBUFS, in rcar_drif_release_buf()
383 ch->buf[0].addr, ch->dma_handle); in rcar_drif_release_buf()
384 ch->buf[0].addr = NULL; in rcar_drif_release_buf()
392 int ret = -ENOMEM; in rcar_drif_request_buf()
396 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_request_buf()
397 struct rcar_drif *ch = sdr->ch[i]; in rcar_drif_request_buf()
400 addr = dma_alloc_coherent(&ch->pdev->dev, in rcar_drif_request_buf()
401 sdr->hwbuf_size * RCAR_DRIF_NUM_HWBUFS, in rcar_drif_request_buf()
402 &ch->dma_handle, GFP_KERNEL); in rcar_drif_request_buf()
405 "ch%u: dma alloc failed. num hwbufs %u size %u\n", in rcar_drif_request_buf()
406 i, RCAR_DRIF_NUM_HWBUFS, sdr->hwbuf_size); in rcar_drif_request_buf()
412 ch->buf[j].addr = addr + (j * sdr->hwbuf_size); in rcar_drif_request_buf()
413 ch->buf[j].status = 0; in rcar_drif_request_buf()
431 *num_buffers = 16 - q_num_bufs; in rcar_drif_queue_setup()
434 sizes[0] = PAGE_ALIGN(sdr->fmt->buffersize); in rcar_drif_queue_setup()
444 struct rcar_drif_sdr *sdr = vb2_get_drv_priv(vb->vb2_queue); in rcar_drif_buf_queue()
449 rdrif_dbg(sdr, "buf_queue idx %u\n", vb->index); in rcar_drif_buf_queue()
450 spin_lock_irqsave(&sdr->queued_bufs_lock, flags); in rcar_drif_buf_queue()
451 list_add_tail(&fbuf->list, &sdr->queued_bufs); in rcar_drif_buf_queue()
452 spin_unlock_irqrestore(&sdr->queued_bufs_lock, flags); in rcar_drif_buf_queue()
462 spin_lock_irqsave(&sdr->queued_bufs_lock, flags); in rcar_drif_get_fbuf()
463 fbuf = list_first_entry_or_null(&sdr->queued_bufs, struct in rcar_drif_get_fbuf()
470 rdrif_dbg(sdr, "\napp late: prod %u\n", sdr->produced); in rcar_drif_get_fbuf()
471 spin_unlock_irqrestore(&sdr->queued_bufs_lock, flags); in rcar_drif_get_fbuf()
474 list_del(&fbuf->list); in rcar_drif_get_fbuf()
475 spin_unlock_irqrestore(&sdr->queued_bufs_lock, flags); in rcar_drif_get_fbuf()
483 return (buf[0]->status & buf[1]->status & RCAR_DRIF_BUF_DONE); in rcar_drif_bufs_done()
488 return ((buf[0]->status | buf[1]->status) & RCAR_DRIF_BUF_OVERFLOW); in rcar_drif_bufs_overflow()
497 buf[i]->status &= ~bit; in rcar_drif_bufs_clear()
505 ch->buf[idx].status |= RCAR_DRIF_BUF_DONE; in rcar_drif_channel_complete()
514 ch->buf[idx].status |= RCAR_DRIF_BUF_OVERFLOW; in rcar_drif_channel_complete()
522 struct rcar_drif_sdr *sdr = ch->sdr; in rcar_drif_dma_complete()
529 spin_lock(&sdr->dma_lock); in rcar_drif_dma_complete()
532 if (!vb2_is_streaming(&sdr->vb_queue)) { in rcar_drif_dma_complete()
533 spin_unlock(&sdr->dma_lock); in rcar_drif_dma_complete()
537 idx = sdr->produced % RCAR_DRIF_NUM_HWBUFS; in rcar_drif_dma_complete()
540 if (sdr->num_cur_ch == RCAR_DRIF_MAX_CHANNEL) { in rcar_drif_dma_complete()
541 buf[0] = ch->num ? to_rcar_drif_buf_pair(sdr, ch->num, idx) : in rcar_drif_dma_complete()
542 &ch->buf[idx]; in rcar_drif_dma_complete()
543 buf[1] = ch->num ? &ch->buf[idx] : in rcar_drif_dma_complete()
544 to_rcar_drif_buf_pair(sdr, ch->num, idx); in rcar_drif_dma_complete()
548 spin_unlock(&sdr->dma_lock); in rcar_drif_dma_complete()
561 buf[0] = &ch->buf[idx]; in rcar_drif_dma_complete()
562 if (buf[0]->status & RCAR_DRIF_BUF_OVERFLOW) { in rcar_drif_dma_complete()
565 buf[0]->status &= ~RCAR_DRIF_BUF_OVERFLOW; in rcar_drif_dma_complete()
570 produced = sdr->produced++; in rcar_drif_dma_complete()
571 spin_unlock(&sdr->dma_lock); in rcar_drif_dma_complete()
573 rdrif_dbg(sdr, "ch%u: prod %u\n", ch->num, produced); in rcar_drif_dma_complete()
581 memcpy(vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0) + in rcar_drif_dma_complete()
582 i * sdr->hwbuf_size, buf[i]->addr, sdr->hwbuf_size); in rcar_drif_dma_complete()
584 fbuf->vb.field = V4L2_FIELD_NONE; in rcar_drif_dma_complete()
585 fbuf->vb.sequence = produced; in rcar_drif_dma_complete()
586 fbuf->vb.vb2_buf.timestamp = ktime_get_ns(); in rcar_drif_dma_complete()
587 vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, sdr->fmt->buffersize); in rcar_drif_dma_complete()
590 vb2_buffer_done(&fbuf->vb.vb2_buf, in rcar_drif_dma_complete()
596 struct rcar_drif_sdr *sdr = ch->sdr; in rcar_drif_qbuf()
597 dma_addr_t addr = ch->dma_handle; in rcar_drif_qbuf()
600 int ret = -EIO; in rcar_drif_qbuf()
603 rxd = dmaengine_prep_dma_cyclic(ch->dmach, addr, in rcar_drif_qbuf()
604 sdr->hwbuf_size * RCAR_DRIF_NUM_HWBUFS, in rcar_drif_qbuf()
605 sdr->hwbuf_size, DMA_DEV_TO_MEM, in rcar_drif_qbuf()
608 rdrif_err(sdr, "ch%u: prep dma cyclic failed\n", ch->num); in rcar_drif_qbuf()
613 rxd->callback = rcar_drif_dma_complete; in rcar_drif_qbuf()
614 rxd->callback_param = ch; in rcar_drif_qbuf()
617 rdrif_err(sdr, "ch%u: dma submit failed\n", ch->num); in rcar_drif_qbuf()
621 dma_async_issue_pending(ch->dmach); in rcar_drif_qbuf()
630 int ret = -EINVAL; in rcar_drif_enable_rx()
633 * When both internal channels are enabled, they can be synchronized in rcar_drif_enable_rx()
638 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_enable_rx()
639 ctr = rcar_drif_read(sdr->ch[i], RCAR_DRIF_SICTR); in rcar_drif_enable_rx()
642 rcar_drif_write(sdr->ch[i], RCAR_DRIF_SICTR, ctr); in rcar_drif_enable_rx()
646 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_enable_rx()
647 ret = readl_poll_timeout(sdr->ch[i]->base + RCAR_DRIF_SICTR, in rcar_drif_enable_rx()
651 rcar_drif_read(sdr->ch[i], RCAR_DRIF_SICTR)); in rcar_drif_enable_rx()
666 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_disable_rx()
667 ctr = rcar_drif_read(sdr->ch[i], RCAR_DRIF_SICTR); in rcar_drif_disable_rx()
669 rcar_drif_write(sdr->ch[i], RCAR_DRIF_SICTR, ctr); in rcar_drif_disable_rx()
673 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_disable_rx()
674 ret = readl_poll_timeout(sdr->ch[i]->base + RCAR_DRIF_SICTR, in rcar_drif_disable_rx()
677 dev_warn(&sdr->vdev->dev, in rcar_drif_disable_rx()
679 i, rcar_drif_read(sdr->ch[i], RCAR_DRIF_SICTR)); in rcar_drif_disable_rx()
690 dmaengine_terminate_sync(ch->dmach); in rcar_drif_stop_channel()
701 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) in rcar_drif_stop()
702 rcar_drif_stop_channel(sdr->ch[i]); in rcar_drif_stop()
708 struct rcar_drif_sdr *sdr = ch->sdr; in rcar_drif_start_channel()
714 ret = readl_poll_timeout(ch->base + RCAR_DRIF_SICTR, ctr, in rcar_drif_start_channel()
718 ch->num, rcar_drif_read(ch, RCAR_DRIF_SICTR)); in rcar_drif_start_channel()
745 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_start()
746 ret = rcar_drif_start_channel(sdr->ch[i]); in rcar_drif_start()
756 sdr->produced = 0; in rcar_drif_start()
763 rcar_drif_stop_channel(sdr->ch[i]); in rcar_drif_start()
776 mutex_lock(&sdr->v4l2_mutex); in rcar_drif_start_streaming()
778 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) { in rcar_drif_start_streaming()
779 ret = clk_prepare_enable(sdr->ch[i]->clk); in rcar_drif_start_streaming()
793 if (sdr->num_cur_ch == RCAR_DRIF_MAX_CHANNEL) in rcar_drif_start_streaming()
794 sdr->hwbuf_size = sdr->fmt->buffersize / RCAR_DRIF_MAX_CHANNEL; in rcar_drif_start_streaming()
796 sdr->hwbuf_size = sdr->fmt->buffersize; in rcar_drif_start_streaming()
798 rdrif_dbg(sdr, "num hwbufs %u, hwbuf_size %u\n", in rcar_drif_start_streaming()
799 RCAR_DRIF_NUM_HWBUFS, sdr->hwbuf_size); in rcar_drif_start_streaming()
816 mutex_unlock(&sdr->v4l2_mutex); in rcar_drif_start_streaming()
825 clk_disable_unprepare(sdr->ch[i]->clk); in rcar_drif_start_streaming()
827 mutex_unlock(&sdr->v4l2_mutex); in rcar_drif_start_streaming()
838 mutex_lock(&sdr->v4l2_mutex); in rcar_drif_stop_streaming()
852 for_each_rcar_drif_channel(i, &sdr->cur_ch_mask) in rcar_drif_stop_streaming()
853 clk_disable_unprepare(sdr->ch[i]->clk); in rcar_drif_stop_streaming()
855 mutex_unlock(&sdr->v4l2_mutex); in rcar_drif_stop_streaming()
873 strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); in rcar_drif_querycap()
874 strscpy(cap->card, sdr->vdev->name, sizeof(cap->card)); in rcar_drif_querycap()
875 strscpy(cap->bus_info, "platform:R-Car DRIF", sizeof(cap->bus_info)); in rcar_drif_querycap()
885 /* Matching fmt based on required channels is set as default */ in rcar_drif_set_default_format()
886 if (sdr->num_hw_ch == formats[i].num_ch) { in rcar_drif_set_default_format()
887 sdr->fmt = &formats[i]; in rcar_drif_set_default_format()
888 sdr->cur_ch_mask = sdr->hw_ch_mask; in rcar_drif_set_default_format()
889 sdr->num_cur_ch = sdr->num_hw_ch; in rcar_drif_set_default_format()
890 dev_dbg(sdr->dev, "default fmt[%u]: mask %lu num %u\n", in rcar_drif_set_default_format()
891 i, sdr->cur_ch_mask, sdr->num_cur_ch); in rcar_drif_set_default_format()
895 return -EINVAL; in rcar_drif_set_default_format()
901 if (f->index >= ARRAY_SIZE(formats)) in rcar_drif_enum_fmt_sdr_cap()
902 return -EINVAL; in rcar_drif_enum_fmt_sdr_cap()
904 f->pixelformat = formats[f->index].pixelformat; in rcar_drif_enum_fmt_sdr_cap()
914 f->fmt.sdr.pixelformat = sdr->fmt->pixelformat; in rcar_drif_g_fmt_sdr_cap()
915 f->fmt.sdr.buffersize = sdr->fmt->buffersize; in rcar_drif_g_fmt_sdr_cap()
924 struct vb2_queue *q = &sdr->vb_queue; in rcar_drif_s_fmt_sdr_cap()
928 return -EBUSY; in rcar_drif_s_fmt_sdr_cap()
931 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) in rcar_drif_s_fmt_sdr_cap()
938 sdr->fmt = &formats[i]; in rcar_drif_s_fmt_sdr_cap()
939 f->fmt.sdr.pixelformat = sdr->fmt->pixelformat; in rcar_drif_s_fmt_sdr_cap()
940 f->fmt.sdr.buffersize = formats[i].buffersize; in rcar_drif_s_fmt_sdr_cap()
941 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); in rcar_drif_s_fmt_sdr_cap()
945 * enabled channels, pick the 0th channel. in rcar_drif_s_fmt_sdr_cap()
947 if (formats[i].num_ch < sdr->num_hw_ch) { in rcar_drif_s_fmt_sdr_cap()
948 sdr->cur_ch_mask = BIT(0); in rcar_drif_s_fmt_sdr_cap()
949 sdr->num_cur_ch = formats[i].num_ch; in rcar_drif_s_fmt_sdr_cap()
951 sdr->cur_ch_mask = sdr->hw_ch_mask; in rcar_drif_s_fmt_sdr_cap()
952 sdr->num_cur_ch = sdr->num_hw_ch; in rcar_drif_s_fmt_sdr_cap()
955 rdrif_dbg(sdr, "cur: idx %u mask %lu num %u\n", in rcar_drif_s_fmt_sdr_cap()
956 i, sdr->cur_ch_mask, sdr->num_cur_ch); in rcar_drif_s_fmt_sdr_cap()
967 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { in rcar_drif_try_fmt_sdr_cap()
968 f->fmt.sdr.buffersize = formats[i].buffersize; in rcar_drif_try_fmt_sdr_cap()
973 f->fmt.sdr.pixelformat = formats[0].pixelformat; in rcar_drif_try_fmt_sdr_cap()
974 f->fmt.sdr.buffersize = formats[0].buffersize; in rcar_drif_try_fmt_sdr_cap()
975 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); in rcar_drif_try_fmt_sdr_cap()
986 return v4l2_subdev_call(sdr->ep.subdev, tuner, enum_freq_bands, band); in rcar_drif_enum_freq_bands()
994 return v4l2_subdev_call(sdr->ep.subdev, tuner, g_frequency, f); in rcar_drif_g_frequency()
1002 return v4l2_subdev_call(sdr->ep.subdev, tuner, s_frequency, f); in rcar_drif_s_frequency()
1010 return v4l2_subdev_call(sdr->ep.subdev, tuner, g_tuner, vt); in rcar_drif_g_tuner()
1018 return v4l2_subdev_call(sdr->ep.subdev, tuner, s_tuner, vt); in rcar_drif_s_tuner()
1064 sdr->vdev = video_device_alloc(); in rcar_drif_sdr_register()
1065 if (!sdr->vdev) in rcar_drif_sdr_register()
1066 return -ENOMEM; in rcar_drif_sdr_register()
1068 snprintf(sdr->vdev->name, sizeof(sdr->vdev->name), "R-Car DRIF"); in rcar_drif_sdr_register()
1069 sdr->vdev->fops = &rcar_drif_fops; in rcar_drif_sdr_register()
1070 sdr->vdev->ioctl_ops = &rcar_drif_ioctl_ops; in rcar_drif_sdr_register()
1071 sdr->vdev->release = video_device_release; in rcar_drif_sdr_register()
1072 sdr->vdev->lock = &sdr->v4l2_mutex; in rcar_drif_sdr_register()
1073 sdr->vdev->queue = &sdr->vb_queue; in rcar_drif_sdr_register()
1074 sdr->vdev->queue->lock = &sdr->vb_queue_mutex; in rcar_drif_sdr_register()
1075 sdr->vdev->ctrl_handler = &sdr->ctrl_hdl; in rcar_drif_sdr_register()
1076 sdr->vdev->v4l2_dev = &sdr->v4l2_dev; in rcar_drif_sdr_register()
1077 sdr->vdev->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_TUNER | in rcar_drif_sdr_register()
1079 video_set_drvdata(sdr->vdev, sdr); in rcar_drif_sdr_register()
1082 ret = video_register_device(sdr->vdev, VFL_TYPE_SDR, -1); in rcar_drif_sdr_register()
1084 video_device_release(sdr->vdev); in rcar_drif_sdr_register()
1085 sdr->vdev = NULL; in rcar_drif_sdr_register()
1086 dev_err(sdr->dev, "failed video_register_device (%d)\n", ret); in rcar_drif_sdr_register()
1094 video_unregister_device(sdr->vdev); in rcar_drif_sdr_unregister()
1095 sdr->vdev = NULL; in rcar_drif_sdr_unregister()
1098 /* Sub-device bound callback */
1107 sdr->ep.subdev = subdev; in rcar_drif_notify_bound()
1108 rdrif_dbg(sdr, "bound asd %s\n", subdev->name); in rcar_drif_notify_bound()
1113 /* Sub-device unbind callback */
1121 if (sdr->ep.subdev != subdev) { in rcar_drif_notify_unbind()
1122 rdrif_err(sdr, "subdev %s is not bound\n", subdev->name); in rcar_drif_notify_unbind()
1127 v4l2_ctrl_handler_free(&sdr->ctrl_hdl); in rcar_drif_notify_unbind()
1128 sdr->v4l2_dev.ctrl_handler = NULL; in rcar_drif_notify_unbind()
1129 sdr->ep.subdev = NULL; in rcar_drif_notify_unbind()
1132 rdrif_dbg(sdr, "unbind asd %s\n", subdev->name); in rcar_drif_notify_unbind()
1135 /* Sub-device registered notification callback */
1148 ret = v4l2_ctrl_handler_init(&sdr->ctrl_hdl, 10); in rcar_drif_notify_complete()
1150 return -ENOMEM; in rcar_drif_notify_complete()
1152 sdr->v4l2_dev.ctrl_handler = &sdr->ctrl_hdl; in rcar_drif_notify_complete()
1153 ret = v4l2_device_register_subdev_nodes(&sdr->v4l2_dev); in rcar_drif_notify_complete()
1159 ret = v4l2_ctrl_add_handler(&sdr->ctrl_hdl, in rcar_drif_notify_complete()
1160 sdr->ep.subdev->ctrl_handler, NULL, true); in rcar_drif_notify_complete()
1173 v4l2_ctrl_handler_free(&sdr->ctrl_hdl); in rcar_drif_notify_complete()
1191 sdr->mdr1 = RCAR_DRIF_SIRMDR1_SYNCMD_LR | RCAR_DRIF_SIRMDR1_MSB_FIRST | in rcar_drif_get_ep_properties()
1195 if (!fwnode_property_read_u32(fwnode, "sync-active", &val)) in rcar_drif_get_ep_properties()
1196 sdr->mdr1 |= val ? RCAR_DRIF_SIRMDR1_SYNCAC_POL_HIGH : in rcar_drif_get_ep_properties()
1199 sdr->mdr1 |= RCAR_DRIF_SIRMDR1_SYNCAC_POL_HIGH; /* default */ in rcar_drif_get_ep_properties()
1201 dev_dbg(sdr->dev, "mdr1 0x%08x\n", sdr->mdr1); in rcar_drif_get_ep_properties()
1204 /* Parse sub-devs (tuner) to find a matching device */
1207 struct v4l2_async_notifier *notifier = &sdr->notifier; in rcar_drif_parse_subdevs()
1211 v4l2_async_nf_init(&sdr->notifier, &sdr->v4l2_dev); in rcar_drif_parse_subdevs()
1213 ep = fwnode_graph_get_next_endpoint(of_fwnode_handle(sdr->dev->of_node), in rcar_drif_parse_subdevs()
1224 dev_warn(sdr->dev, "bad remote port parent\n"); in rcar_drif_parse_subdevs()
1225 return -EINVAL; in rcar_drif_parse_subdevs()
1240 return of_property_read_bool(pdev->dev.of_node, "renesas,primary-bond"); in rcar_drif_primary_bond()
1248 np = of_parse_phandle(p->dev.of_node, "renesas,bonding", 0); in rcar_drif_bond_enabled()
1265 dev_err(sdr->dev, "failed to get bonded device from node\n"); in rcar_drif_bond_available()
1266 return -ENODEV; in rcar_drif_bond_available()
1269 device_lock(&pdev->dev); in rcar_drif_bond_available()
1273 ch->sdr = sdr; in rcar_drif_bond_available()
1276 sdr->ch[ch->num] = ch; in rcar_drif_bond_available()
1277 sdr->hw_ch_mask |= BIT(ch->num); in rcar_drif_bond_available()
1280 dev_info(sdr->dev, "defer probe\n"); in rcar_drif_bond_available()
1281 ret = -EPROBE_DEFER; in rcar_drif_bond_available()
1283 device_unlock(&pdev->dev); in rcar_drif_bond_available()
1285 put_device(&pdev->dev); in rcar_drif_bond_available()
1295 /* Validate any supported format for enabled channels */ in rcar_drif_sdr_probe()
1298 dev_err(sdr->dev, "failed to set default format\n"); in rcar_drif_sdr_probe()
1303 sdr->hwbuf_size = RCAR_DRIF_DEFAULT_HWBUF_SIZE; in rcar_drif_sdr_probe()
1305 mutex_init(&sdr->v4l2_mutex); in rcar_drif_sdr_probe()
1306 mutex_init(&sdr->vb_queue_mutex); in rcar_drif_sdr_probe()
1307 spin_lock_init(&sdr->queued_bufs_lock); in rcar_drif_sdr_probe()
1308 spin_lock_init(&sdr->dma_lock); in rcar_drif_sdr_probe()
1309 INIT_LIST_HEAD(&sdr->queued_bufs); in rcar_drif_sdr_probe()
1312 sdr->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; in rcar_drif_sdr_probe()
1313 sdr->vb_queue.io_modes = VB2_READ | VB2_MMAP | VB2_DMABUF; in rcar_drif_sdr_probe()
1314 sdr->vb_queue.drv_priv = sdr; in rcar_drif_sdr_probe()
1315 sdr->vb_queue.buf_struct_size = sizeof(struct rcar_drif_frame_buf); in rcar_drif_sdr_probe()
1316 sdr->vb_queue.ops = &rcar_drif_vb2_ops; in rcar_drif_sdr_probe()
1317 sdr->vb_queue.mem_ops = &vb2_vmalloc_memops; in rcar_drif_sdr_probe()
1318 sdr->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in rcar_drif_sdr_probe()
1321 ret = vb2_queue_init(&sdr->vb_queue); in rcar_drif_sdr_probe()
1323 dev_err(sdr->dev, "failed: vb2_queue_init ret %d\n", ret); in rcar_drif_sdr_probe()
1328 ret = v4l2_device_register(sdr->dev, &sdr->v4l2_dev); in rcar_drif_sdr_probe()
1330 dev_err(sdr->dev, "failed: v4l2_device_register ret %d\n", ret); in rcar_drif_sdr_probe()
1342 sdr->notifier.ops = &rcar_drif_notify_ops; in rcar_drif_sdr_probe()
1345 ret = v4l2_async_nf_register(&sdr->notifier); in rcar_drif_sdr_probe()
1347 dev_err(sdr->dev, "failed: notifier register ret %d\n", ret); in rcar_drif_sdr_probe()
1354 v4l2_async_nf_cleanup(&sdr->notifier); in rcar_drif_sdr_probe()
1356 v4l2_device_unregister(&sdr->v4l2_dev); in rcar_drif_sdr_probe()
1364 v4l2_async_nf_unregister(&sdr->notifier); in rcar_drif_sdr_remove()
1365 v4l2_async_nf_cleanup(&sdr->notifier); in rcar_drif_sdr_remove()
1366 v4l2_device_unregister(&sdr->v4l2_dev); in rcar_drif_sdr_remove()
1379 ch = devm_kzalloc(&pdev->dev, sizeof(*ch), GFP_KERNEL); in rcar_drif_probe()
1381 return -ENOMEM; in rcar_drif_probe()
1383 ch->pdev = pdev; in rcar_drif_probe()
1386 ch->clk = devm_clk_get(&pdev->dev, "fck"); in rcar_drif_probe()
1387 if (IS_ERR(ch->clk)) { in rcar_drif_probe()
1388 ret = PTR_ERR(ch->clk); in rcar_drif_probe()
1389 dev_err(&pdev->dev, "clk get failed (%d)\n", ret); in rcar_drif_probe()
1394 ch->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in rcar_drif_probe()
1395 if (IS_ERR(ch->base)) in rcar_drif_probe()
1396 return PTR_ERR(ch->base); in rcar_drif_probe()
1398 ch->start = res->start; in rcar_drif_probe()
1401 /* Check if both channels of the bond are enabled */ in rcar_drif_probe()
1404 /* Check if current channel acting as primary-bond */ in rcar_drif_probe()
1406 ch->num = 1; /* Primary bond is channel 0 always */ in rcar_drif_probe()
1413 sdr = devm_kzalloc(&pdev->dev, sizeof(*sdr), GFP_KERNEL); in rcar_drif_probe()
1416 return -ENOMEM; in rcar_drif_probe()
1418 ch->sdr = sdr; in rcar_drif_probe()
1419 sdr->dev = &pdev->dev; in rcar_drif_probe()
1422 sdr->ch[ch->num] = ch; in rcar_drif_probe()
1423 sdr->hw_ch_mask = BIT(ch->num); in rcar_drif_probe()
1431 sdr->num_hw_ch = hweight_long(sdr->hw_ch_mask); in rcar_drif_probe()
1440 struct rcar_drif_sdr *sdr = ch->sdr; in rcar_drif_remove()
1443 if (ch->num) in rcar_drif_remove()
1465 { .compatible = "renesas,rcar-gen3-drif" },
1483 MODULE_DESCRIPTION("Renesas R-Car Gen3 DRIF driver");