Lines Matching full:sdr

27  * driver exposes the device as a V4L2 SDR device. In order to qualify as
28 * a V4L2 SDR device, it should possess a tuner interface as mandated by the
31 * a V4L2 compliant SDR device. The DRIF driver is independent of the
127 #define to_rcar_drif_buf_pair(sdr, ch_num, idx) \ argument
128 (&((sdr)->ch[!(ch_num)]->buf[(idx)]))
134 #define rdrif_dbg(sdr, fmt, arg...) \ argument
135 dev_dbg(sdr->v4l2_dev.dev, fmt, ## arg)
137 #define rdrif_err(sdr, fmt, arg...) \ argument
138 dev_err(sdr->v4l2_dev.dev, fmt, ## arg)
194 struct rcar_drif_sdr *sdr; /* Group device */ member
203 bool acting_sdr; /* Channel acting as SDR device */
206 /* DRIF V4L2 SDR */
209 struct video_device *vdev; /* V4L2 SDR device */
220 struct v4l2_ctrl_handler ctrl_hdl; /* SDR control handler */
224 /* Current V4L2 SDR format ptr */
233 unsigned long cur_ch_mask; /* Used channels for an SDR FMT */
237 u32 produced; /* Buffers produced by sdr dev */
252 static void rcar_drif_release_dmachannels(struct rcar_drif_sdr *sdr) in rcar_drif_release_dmachannels() argument
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()
264 static int rcar_drif_alloc_dmachannels(struct rcar_drif_sdr *sdr) in rcar_drif_alloc_dmachannels() argument
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()
277 rdrif_err(sdr, in rcar_drif_alloc_dmachannels()
290 rdrif_err(sdr, "ch%u: dma slave config failed\n", i); in rcar_drif_alloc_dmachannels()
297 rcar_drif_release_dmachannels(sdr); in rcar_drif_alloc_dmachannels()
302 static void rcar_drif_release_queued_bufs(struct rcar_drif_sdr *sdr, in rcar_drif_release_queued_bufs() argument
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()
313 spin_unlock_irqrestore(&sdr->queued_bufs_lock, flags); in rcar_drif_release_queued_bufs()
317 static inline void rcar_drif_set_mdr1(struct rcar_drif_sdr *sdr) in rcar_drif_set_mdr1() argument
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()
330 rdrif_dbg(sdr, "ch%u: mdr1 = 0x%08x", in rcar_drif_set_mdr1()
331 i, rcar_drif_read(sdr->ch[i], RCAR_DRIF_SIRMDR1)); in rcar_drif_set_mdr1()
336 static int rcar_drif_set_format(struct rcar_drif_sdr *sdr) in rcar_drif_set_format() argument
340 rdrif_dbg(sdr, "setfmt: bitlen %u wdcnt %u num_ch %u\n", in rcar_drif_set_format()
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()
345 rdrif_err(sdr, "fmt num_ch %u cur_ch %u mismatch\n", in rcar_drif_set_format()
346 sdr->fmt->num_ch, sdr->num_cur_ch); 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()
364 rdrif_dbg(sdr, "ch%u: new mdr[2,3] = 0x%08x, 0x%08x\n", 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()
372 static void rcar_drif_release_buf(struct rcar_drif_sdr *sdr) in rcar_drif_release_buf() argument
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()
382 sdr->hwbuf_size * RCAR_DRIF_NUM_HWBUFS, in rcar_drif_release_buf()
390 static int rcar_drif_request_buf(struct rcar_drif_sdr *sdr) in rcar_drif_request_buf() argument
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()
401 sdr->hwbuf_size * RCAR_DRIF_NUM_HWBUFS, in rcar_drif_request_buf()
404 rdrif_err(sdr, 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()
426 struct rcar_drif_sdr *sdr = vb2_get_drv_priv(vq); in rcar_drif_queue_setup() local
434 sizes[0] = PAGE_ALIGN(sdr->fmt->buffersize); in rcar_drif_queue_setup()
435 rdrif_dbg(sdr, "num_bufs %d sizes[0] %d\n", *num_buffers, sizes[0]); in rcar_drif_queue_setup()
444 struct rcar_drif_sdr *sdr = vb2_get_drv_priv(vb->vb2_queue); in rcar_drif_buf_queue() local
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()
457 rcar_drif_get_fbuf(struct rcar_drif_sdr *sdr) in rcar_drif_get_fbuf() argument
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()
475 spin_unlock_irqrestore(&sdr->queued_bufs_lock, flags); in rcar_drif_get_fbuf()
522 struct rcar_drif_sdr *sdr = ch->sdr; in rcar_drif_dma_complete() local
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()
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()
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()
576 fbuf = rcar_drif_get_fbuf(sdr); in rcar_drif_dma_complete()
582 i * sdr->hwbuf_size, buf[i]->addr, sdr->hwbuf_size); in rcar_drif_dma_complete()
587 vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, sdr->fmt->buffersize); in rcar_drif_dma_complete()
596 struct rcar_drif_sdr *sdr = ch->sdr; in rcar_drif_qbuf() local
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()
617 rdrif_err(sdr, "ch%u: dma submit failed\n", ch->num); in rcar_drif_qbuf()
626 static int rcar_drif_enable_rx(struct rcar_drif_sdr *sdr) in rcar_drif_enable_rx() argument
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()
650 rdrif_err(sdr, "ch%u: rx en failed. ctr 0x%08x\n", i, in rcar_drif_enable_rx()
651 rcar_drif_read(sdr->ch[i], RCAR_DRIF_SICTR)); in rcar_drif_enable_rx()
659 static void rcar_drif_disable_rx(struct rcar_drif_sdr *sdr) in rcar_drif_disable_rx() argument
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()
694 static void rcar_drif_stop(struct rcar_drif_sdr *sdr) in rcar_drif_stop() argument
699 rcar_drif_disable_rx(sdr); in rcar_drif_stop()
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() local
717 rdrif_err(sdr, "ch%u: failed to reset rx. ctr 0x%08x\n", in rcar_drif_start_channel()
739 static int rcar_drif_start(struct rcar_drif_sdr *sdr) in rcar_drif_start() argument
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()
752 ret = rcar_drif_enable_rx(sdr); in rcar_drif_start()
756 sdr->produced = 0; in rcar_drif_start()
760 rcar_drif_disable_rx(sdr); in rcar_drif_start()
763 rcar_drif_stop_channel(sdr->ch[i]); in rcar_drif_start()
771 struct rcar_drif_sdr *sdr = vb2_get_drv_priv(vq); in rcar_drif_start_streaming() local
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()
786 rcar_drif_set_mdr1(sdr); in rcar_drif_start_streaming()
789 ret = rcar_drif_set_format(sdr); 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()
802 ret = rcar_drif_alloc_dmachannels(sdr); in rcar_drif_start_streaming()
807 ret = rcar_drif_request_buf(sdr); in rcar_drif_start_streaming()
812 ret = rcar_drif_start(sdr); in rcar_drif_start_streaming()
816 mutex_unlock(&sdr->v4l2_mutex); in rcar_drif_start_streaming()
821 rcar_drif_release_queued_bufs(sdr, VB2_BUF_STATE_QUEUED); in rcar_drif_start_streaming()
822 rcar_drif_release_buf(sdr); in rcar_drif_start_streaming()
823 rcar_drif_release_dmachannels(sdr); 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()
835 struct rcar_drif_sdr *sdr = vb2_get_drv_priv(vq); in rcar_drif_stop_streaming() local
838 mutex_lock(&sdr->v4l2_mutex); in rcar_drif_stop_streaming()
841 rcar_drif_stop(sdr); in rcar_drif_stop_streaming()
844 rcar_drif_release_queued_bufs(sdr, VB2_BUF_STATE_ERROR); in rcar_drif_stop_streaming()
847 rcar_drif_release_buf(sdr); in rcar_drif_stop_streaming()
850 rcar_drif_release_dmachannels(sdr); 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()
871 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_querycap() local
874 strscpy(cap->card, sdr->vdev->name, sizeof(cap->card)); in rcar_drif_querycap()
880 static int rcar_drif_set_default_format(struct rcar_drif_sdr *sdr) in rcar_drif_set_default_format() argument
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()
912 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_g_fmt_sdr_cap() local
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()
923 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_s_fmt_sdr_cap() local
924 struct vb2_queue *q = &sdr->vb_queue; 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()
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()
984 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_enum_freq_bands() local
986 return v4l2_subdev_call(sdr->ep.subdev, tuner, enum_freq_bands, band); in rcar_drif_enum_freq_bands()
992 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_g_frequency() local
994 return v4l2_subdev_call(sdr->ep.subdev, tuner, g_frequency, f); in rcar_drif_g_frequency()
1000 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_s_frequency() local
1002 return v4l2_subdev_call(sdr->ep.subdev, tuner, s_frequency, f); in rcar_drif_s_frequency()
1008 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_g_tuner() local
1010 return v4l2_subdev_call(sdr->ep.subdev, tuner, g_tuner, vt); in rcar_drif_g_tuner()
1016 struct rcar_drif_sdr *sdr = video_drvdata(file); in rcar_drif_s_tuner() local
1018 return v4l2_subdev_call(sdr->ep.subdev, tuner, s_tuner, vt); in rcar_drif_s_tuner()
1059 static int rcar_drif_sdr_register(struct rcar_drif_sdr *sdr) in rcar_drif_sdr_register() argument
1064 sdr->vdev = video_device_alloc(); in rcar_drif_sdr_register()
1065 if (!sdr->vdev) 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()
1081 /* Register V4L2 SDR device */ 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()
1092 static void rcar_drif_sdr_unregister(struct rcar_drif_sdr *sdr) in rcar_drif_sdr_unregister() argument
1094 video_unregister_device(sdr->vdev); in rcar_drif_sdr_unregister()
1095 sdr->vdev = NULL; in rcar_drif_sdr_unregister()
1103 struct rcar_drif_sdr *sdr = in rcar_drif_notify_bound() local
1106 v4l2_set_subdev_hostdata(subdev, sdr); in rcar_drif_notify_bound()
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()
1118 struct rcar_drif_sdr *sdr = in rcar_drif_notify_unbind() local
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()
1131 rcar_drif_sdr_unregister(sdr); in rcar_drif_notify_unbind()
1132 rdrif_dbg(sdr, "unbind asd %s\n", subdev->name); in rcar_drif_notify_unbind()
1138 struct rcar_drif_sdr *sdr = in rcar_drif_notify_complete() local
1148 ret = v4l2_ctrl_handler_init(&sdr->ctrl_hdl, 10); 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()
1155 rdrif_err(sdr, "failed: register subdev nodes ret %d\n", ret); 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()
1162 rdrif_err(sdr, "failed: ctrl add hdlr ret %d\n", ret); in rcar_drif_notify_complete()
1166 ret = rcar_drif_sdr_register(sdr); in rcar_drif_notify_complete()
1173 v4l2_ctrl_handler_free(&sdr->ctrl_hdl); in rcar_drif_notify_complete()
1185 static void rcar_drif_get_ep_properties(struct rcar_drif_sdr *sdr, in rcar_drif_get_ep_properties() argument
1191 sdr->mdr1 = RCAR_DRIF_SIRMDR1_SYNCMD_LR | RCAR_DRIF_SIRMDR1_MSB_FIRST | 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()
1205 static int rcar_drif_parse_subdevs(struct rcar_drif_sdr *sdr) in rcar_drif_parse_subdevs() argument
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()
1219 rcar_drif_get_ep_properties(sdr, ep); in rcar_drif_parse_subdevs()
1224 dev_warn(sdr->dev, "bad remote port parent\n"); in rcar_drif_parse_subdevs()
1256 static int rcar_drif_bond_available(struct rcar_drif_sdr *sdr, in rcar_drif_bond_available() argument
1265 dev_err(sdr->dev, "failed to get bonded device from node\n"); in rcar_drif_bond_available()
1272 /* Update sdr data in the bonded device */ in rcar_drif_bond_available()
1273 ch->sdr = sdr; in rcar_drif_bond_available()
1275 /* Update sdr with bonded device data */ 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()
1290 /* V4L2 SDR device probe */
1291 static int rcar_drif_sdr_probe(struct rcar_drif_sdr *sdr) in rcar_drif_sdr_probe() argument
1296 ret = rcar_drif_set_default_format(sdr); 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()
1338 ret = rcar_drif_parse_subdevs(sdr); 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()
1361 /* V4L2 SDR device remove */
1362 static void rcar_drif_sdr_remove(struct rcar_drif_sdr *sdr) in rcar_drif_sdr_remove() argument
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()
1372 struct rcar_drif_sdr *sdr; in rcar_drif_probe() local
1412 /* Reserve memory for SDR structure */ in rcar_drif_probe()
1413 sdr = devm_kzalloc(&pdev->dev, sizeof(*sdr), GFP_KERNEL); in rcar_drif_probe()
1414 if (!sdr) { in rcar_drif_probe()
1418 ch->sdr = sdr; in rcar_drif_probe()
1419 sdr->dev = &pdev->dev; in rcar_drif_probe()
1421 /* Establish links between SDR and channel(s) */ 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()
1426 ret = rcar_drif_bond_available(sdr, np); in rcar_drif_probe()
1431 sdr->num_hw_ch = hweight_long(sdr->hw_ch_mask); in rcar_drif_probe()
1433 return rcar_drif_sdr_probe(sdr); in rcar_drif_probe()
1440 struct rcar_drif_sdr *sdr = ch->sdr; in rcar_drif_remove() local
1442 /* Channel 0 will be the SDR instance */ in rcar_drif_remove()
1446 /* SDR instance */ in rcar_drif_remove()
1447 rcar_drif_sdr_remove(sdr); in rcar_drif_remove()