Lines Matching refs:vip

219 static inline void reg_write(struct sta2x11_vip *vip, unsigned int reg, u32 val)  in reg_write()  argument
221 iowrite32((val), (vip->iomem)+(reg)); in reg_write()
224 static inline u32 reg_read(struct sta2x11_vip *vip, unsigned int reg) in reg_read() argument
226 return ioread32((vip->iomem)+(reg)); in reg_read()
229 static void start_dma(struct sta2x11_vip *vip, struct vip_buffer *vip_buf) in start_dma() argument
233 if (vip->format.field == V4L2_FIELD_INTERLACED) in start_dma()
234 offset = vip->format.width * 2; in start_dma()
236 spin_lock_irq(&vip->slock); in start_dma()
238 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) | DVP_CTL_ENA); in start_dma()
240 reg_write(vip, DVP_VTP, (u32)vip_buf->dma); in start_dma()
241 reg_write(vip, DVP_VBP, (u32)vip_buf->dma + offset); in start_dma()
242 spin_unlock_irq(&vip->slock); in start_dma()
246 static void vip_active_buf_next(struct sta2x11_vip *vip) in vip_active_buf_next() argument
249 spin_lock(&vip->lock); in vip_active_buf_next()
250 if (list_empty(&vip->buffer_list)) {/* No available buffer */ in vip_active_buf_next()
251 spin_unlock(&vip->lock); in vip_active_buf_next()
254 vip->active = list_first_entry(&vip->buffer_list, in vip_active_buf_next()
258 vip->tcount = 0; in vip_active_buf_next()
259 vip->bcount = 0; in vip_active_buf_next()
260 spin_unlock(&vip->lock); in vip_active_buf_next()
261 if (vb2_is_streaming(&vip->vb_vidq)) { /* streaming is on */ in vip_active_buf_next()
262 start_dma(vip, vip->active); /* start dma capture */ in vip_active_buf_next()
272 struct sta2x11_vip *vip = vb2_get_drv_priv(vq); in queue_setup() local
278 sizes[0] = vip->format.sizeimage; in queue_setup()
279 alloc_ctxs[0] = vip->alloc_ctx; in queue_setup()
281 vip->sequence = 0; in queue_setup()
282 vip->active = NULL; in queue_setup()
283 vip->tcount = 0; in queue_setup()
284 vip->bcount = 0; in queue_setup()
301 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare() local
305 size = vip->format.sizeimage; in buffer_prepare()
307 v4l2_err(&vip->v4l2_dev, "buffer too small (%lu < %lu)\n", in buffer_prepare()
319 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue() local
322 spin_lock(&vip->lock); in buffer_queue()
323 list_add_tail(&vip_buf->list, &vip->buffer_list); in buffer_queue()
324 if (!vip->active) { /* No active buffer, active the first one */ in buffer_queue()
325 vip->active = list_first_entry(&vip->buffer_list, in buffer_queue()
328 if (vb2_is_streaming(&vip->vb_vidq)) /* streaming is on */ in buffer_queue()
329 start_dma(vip, vip_buf); /* start dma capture */ in buffer_queue()
331 spin_unlock(&vip->lock); in buffer_queue()
336 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue); in buffer_finish() local
340 spin_lock(&vip->lock); in buffer_finish()
342 spin_unlock(&vip->lock); in buffer_finish()
345 vip_active_buf_next(vip); in buffer_finish()
350 struct sta2x11_vip *vip = vb2_get_drv_priv(vq); in start_streaming() local
352 spin_lock_irq(&vip->slock); in start_streaming()
354 reg_write(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST); in start_streaming()
355 spin_unlock_irq(&vip->slock); in start_streaming()
358 start_dma(vip, vip->active); in start_streaming()
366 struct sta2x11_vip *vip = vb2_get_drv_priv(vq); in stop_streaming() local
370 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA); in stop_streaming()
372 reg_write(vip, DVP_ITM, 0); in stop_streaming()
375 spin_lock(&vip->lock); in stop_streaming()
376 list_for_each_entry_safe(vip_buf, node, &vip->buffer_list, list) { in stop_streaming()
380 spin_unlock(&vip->lock); in stop_streaming()
418 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_querycap() local
423 pci_name(vip->pdev)); in vidioc_querycap()
446 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_s_std() local
447 v4l2_std_id oldstd = vip->std, newstd; in vidioc_s_std()
451 v4l2_subdev_call(vip->decoder, video, s_std, std); in vidioc_s_std()
453 v4l2_subdev_call(vip->decoder, video, querystd, &newstd); in vidioc_s_std()
454 v4l2_subdev_call(vip->decoder, video, g_input_status, &status); in vidioc_s_std()
457 std = vip->std = newstd; in vidioc_s_std()
460 vip->format = formats_60[0]; in vidioc_s_std()
462 vip->format = formats_50[0]; in vidioc_s_std()
469 vip->format = formats_60[0]; in vidioc_s_std()
471 vip->format = formats_50[0]; in vidioc_s_std()
474 return v4l2_subdev_call(vip->decoder, video, s_std, std); in vidioc_s_std()
488 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_g_std() local
490 *std = vip->std; in vidioc_g_std()
505 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_querystd() local
507 return v4l2_subdev_call(vip->decoder, video, querystd, std); in vidioc_querystd()
536 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_s_input() local
541 ret = v4l2_subdev_call(vip->decoder, video, s_routing, i, 0, 0); in vidioc_s_input()
544 vip->input = i; in vidioc_s_input()
560 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_g_input() local
562 *i = vip->input; in vidioc_g_input()
606 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_try_fmt_vid_cap() local
610 v4l2_warn(&vip->v4l2_dev, "Invalid format, only UYVY supported\n"); in vidioc_try_fmt_vid_cap()
614 if (V4L2_STD_525_60 & vip->std) in vidioc_try_fmt_vid_cap()
663 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_s_fmt_vid_cap() local
671 if (vb2_is_busy(&vip->vb_vidq)) { in vidioc_s_fmt_vid_cap()
673 v4l2_err(&vip->v4l2_dev, "device busy\n"); in vidioc_s_fmt_vid_cap()
676 vip->format = f->fmt.pix; in vidioc_s_fmt_vid_cap()
677 switch (vip->format.field) { in vidioc_s_fmt_vid_cap()
679 t_stop = ((vip->format.height / 2 - 1) << 16) | in vidioc_s_fmt_vid_cap()
680 (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
682 pitch = 4 * vip->format.width; in vidioc_s_fmt_vid_cap()
685 t_stop = ((vip->format.height - 1) << 16) | in vidioc_s_fmt_vid_cap()
686 (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
687 b_stop = (0 << 16) | (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
688 pitch = 2 * vip->format.width; in vidioc_s_fmt_vid_cap()
691 t_stop = (0 << 16) | (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
692 b_stop = (vip->format.height << 16) | in vidioc_s_fmt_vid_cap()
693 (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
694 pitch = 2 * vip->format.width; in vidioc_s_fmt_vid_cap()
697 v4l2_err(&vip->v4l2_dev, "unknown field format\n"); in vidioc_s_fmt_vid_cap()
701 spin_lock_irq(&vip->slock); in vidioc_s_fmt_vid_cap()
703 reg_write(vip, DVP_TFO, 0); in vidioc_s_fmt_vid_cap()
705 reg_write(vip, DVP_BFO, 0); in vidioc_s_fmt_vid_cap()
707 reg_write(vip, DVP_TFS, t_stop); in vidioc_s_fmt_vid_cap()
709 reg_write(vip, DVP_BFS, b_stop); in vidioc_s_fmt_vid_cap()
711 reg_write(vip, DVP_VMP, pitch); in vidioc_s_fmt_vid_cap()
712 spin_unlock_irq(&vip->slock); in vidioc_s_fmt_vid_cap()
729 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_g_fmt_vid_cap() local
731 f->fmt.pix = vip->format; in vidioc_g_fmt_vid_cap()
789 static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip) in vip_irq() argument
793 status = reg_read(vip, DVP_ITS); in vip_irq()
799 if (vip->overflow++ > 5) in vip_irq()
809 if ((++vip->tcount) < 2) in vip_irq()
812 vip->bcount++; in vip_irq()
816 if (vip->active) { /* Acquisition is over on this buffer */ in vip_irq()
818 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA); in vip_irq()
820 v4l2_get_timestamp(&vip->active->vb.timestamp); in vip_irq()
821 vip->active->vb.sequence = vip->sequence++; in vip_irq()
822 vb2_buffer_done(&vip->active->vb.vb2_buf, VB2_BUF_STATE_DONE); in vip_irq()
828 static void sta2x11_vip_init_register(struct sta2x11_vip *vip) in sta2x11_vip_init_register() argument
831 spin_lock_irq(&vip->slock); in sta2x11_vip_init_register()
833 reg_read(vip, DVP_ITS); in sta2x11_vip_init_register()
835 reg_write(vip, DVP_HLFLN, DVP_HLFLN_SD); in sta2x11_vip_init_register()
837 reg_write(vip, DVP_CTL, DVP_CTL_RST); in sta2x11_vip_init_register()
839 reg_write(vip, DVP_CTL, 0); in sta2x11_vip_init_register()
840 spin_unlock_irq(&vip->slock); in sta2x11_vip_init_register()
842 static void sta2x11_vip_clear_register(struct sta2x11_vip *vip) in sta2x11_vip_clear_register() argument
844 spin_lock_irq(&vip->slock); in sta2x11_vip_clear_register()
846 reg_write(vip, DVP_ITM, 0); in sta2x11_vip_clear_register()
848 reg_write(vip, DVP_CTL, DVP_CTL_RST); in sta2x11_vip_clear_register()
850 reg_write(vip, DVP_CTL, 0); in sta2x11_vip_clear_register()
852 reg_read(vip, DVP_ITS); in sta2x11_vip_clear_register()
853 spin_unlock_irq(&vip->slock); in sta2x11_vip_clear_register()
855 static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip) in sta2x11_vip_init_buffer() argument
859 err = dma_set_coherent_mask(&vip->pdev->dev, DMA_BIT_MASK(29)); in sta2x11_vip_init_buffer()
861 v4l2_err(&vip->v4l2_dev, "Cannot configure coherent mask"); in sta2x11_vip_init_buffer()
864 memset(&vip->vb_vidq, 0, sizeof(struct vb2_queue)); in sta2x11_vip_init_buffer()
865 vip->vb_vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in sta2x11_vip_init_buffer()
866 vip->vb_vidq.io_modes = VB2_MMAP | VB2_READ; in sta2x11_vip_init_buffer()
867 vip->vb_vidq.drv_priv = vip; in sta2x11_vip_init_buffer()
868 vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer); in sta2x11_vip_init_buffer()
869 vip->vb_vidq.ops = &vip_video_qops; in sta2x11_vip_init_buffer()
870 vip->vb_vidq.mem_ops = &vb2_dma_contig_memops; in sta2x11_vip_init_buffer()
871 vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in sta2x11_vip_init_buffer()
872 err = vb2_queue_init(&vip->vb_vidq); in sta2x11_vip_init_buffer()
875 INIT_LIST_HEAD(&vip->buffer_list); in sta2x11_vip_init_buffer()
876 spin_lock_init(&vip->lock); in sta2x11_vip_init_buffer()
879 vip->alloc_ctx = vb2_dma_contig_init_ctx(&vip->pdev->dev); in sta2x11_vip_init_buffer()
880 if (IS_ERR(vip->alloc_ctx)) { in sta2x11_vip_init_buffer()
881 v4l2_err(&vip->v4l2_dev, "Can't allocate buffer context"); in sta2x11_vip_init_buffer()
882 return PTR_ERR(vip->alloc_ctx); in sta2x11_vip_init_buffer()
887 static void sta2x11_vip_release_buffer(struct sta2x11_vip *vip) in sta2x11_vip_release_buffer() argument
889 vb2_dma_contig_cleanup_ctx(vip->alloc_ctx); in sta2x11_vip_release_buffer()
891 static int sta2x11_vip_init_controls(struct sta2x11_vip *vip) in sta2x11_vip_init_controls() argument
897 v4l2_ctrl_handler_init(&vip->ctrl_hdl, 0); in sta2x11_vip_init_controls()
899 vip->v4l2_dev.ctrl_handler = &vip->ctrl_hdl; in sta2x11_vip_init_controls()
900 if (vip->ctrl_hdl.error) { in sta2x11_vip_init_controls()
901 int err = vip->ctrl_hdl.error; in sta2x11_vip_init_controls()
903 v4l2_ctrl_handler_free(&vip->ctrl_hdl); in sta2x11_vip_init_controls()
989 struct sta2x11_vip *vip; in sta2x11_vip_init_one() local
1039 vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL); in sta2x11_vip_init_one()
1040 if (!vip) { in sta2x11_vip_init_one()
1044 vip->pdev = pdev; in sta2x11_vip_init_one()
1045 vip->std = V4L2_STD_PAL; in sta2x11_vip_init_one()
1046 vip->format = formats_50[0]; in sta2x11_vip_init_one()
1047 vip->config = config; in sta2x11_vip_init_one()
1049 ret = sta2x11_vip_init_controls(vip); in sta2x11_vip_init_one()
1052 ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev); in sta2x11_vip_init_one()
1066 vip->iomem = pci_iomap(pdev, 0, 0x100); in sta2x11_vip_init_one()
1067 if (!vip->iomem) { in sta2x11_vip_init_one()
1075 ret = sta2x11_vip_init_buffer(vip); in sta2x11_vip_init_one()
1079 spin_lock_init(&vip->slock); in sta2x11_vip_init_one()
1083 IRQF_SHARED, KBUILD_MODNAME, vip); in sta2x11_vip_init_one()
1091 vip->video_dev = video_dev_template; in sta2x11_vip_init_one()
1092 vip->video_dev.v4l2_dev = &vip->v4l2_dev; in sta2x11_vip_init_one()
1093 vip->video_dev.queue = &vip->vb_vidq; in sta2x11_vip_init_one()
1094 video_set_drvdata(&vip->video_dev, vip); in sta2x11_vip_init_one()
1096 ret = video_register_device(&vip->video_dev, VFL_TYPE_GRABBER, -1); in sta2x11_vip_init_one()
1101 vip->adapter = i2c_get_adapter(vip->config->i2c_id); in sta2x11_vip_init_one()
1102 if (!vip->adapter) { in sta2x11_vip_init_one()
1108 vip->decoder = v4l2_i2c_new_subdev(&vip->v4l2_dev, vip->adapter, in sta2x11_vip_init_one()
1109 "adv7180", vip->config->i2c_addr, in sta2x11_vip_init_one()
1111 if (!vip->decoder) { in sta2x11_vip_init_one()
1117 i2c_put_adapter(vip->adapter); in sta2x11_vip_init_one()
1118 v4l2_subdev_call(vip->decoder, core, init, 0); in sta2x11_vip_init_one()
1120 sta2x11_vip_init_register(vip); in sta2x11_vip_init_one()
1126 video_set_drvdata(&vip->video_dev, NULL); in sta2x11_vip_init_one()
1128 video_unregister_device(&vip->video_dev); in sta2x11_vip_init_one()
1129 free_irq(pdev->irq, vip); in sta2x11_vip_init_one()
1131 sta2x11_vip_release_buffer(vip); in sta2x11_vip_init_one()
1134 vb2_queue_release(&vip->vb_vidq); in sta2x11_vip_init_one()
1135 pci_iounmap(pdev, vip->iomem); in sta2x11_vip_init_one()
1139 v4l2_device_unregister(&vip->v4l2_dev); in sta2x11_vip_init_one()
1141 kfree(vip); in sta2x11_vip_init_one()
1168 struct sta2x11_vip *vip = in sta2x11_vip_remove_one() local
1171 sta2x11_vip_clear_register(vip); in sta2x11_vip_remove_one()
1173 video_set_drvdata(&vip->video_dev, NULL); in sta2x11_vip_remove_one()
1174 video_unregister_device(&vip->video_dev); in sta2x11_vip_remove_one()
1175 free_irq(pdev->irq, vip); in sta2x11_vip_remove_one()
1177 vb2_queue_release(&vip->vb_vidq); in sta2x11_vip_remove_one()
1178 pci_iounmap(pdev, vip->iomem); in sta2x11_vip_remove_one()
1181 v4l2_device_unregister(&vip->v4l2_dev); in sta2x11_vip_remove_one()
1183 vip_gpio_release(&pdev->dev, vip->config->pwr_pin, in sta2x11_vip_remove_one()
1184 vip->config->pwr_name); in sta2x11_vip_remove_one()
1185 vip_gpio_release(&pdev->dev, vip->config->reset_pin, in sta2x11_vip_remove_one()
1186 vip->config->reset_name); in sta2x11_vip_remove_one()
1188 kfree(vip); in sta2x11_vip_remove_one()
1210 struct sta2x11_vip *vip = in sta2x11_vip_suspend() local
1215 spin_lock_irqsave(&vip->slock, flags); in sta2x11_vip_suspend()
1216 vip->register_save_area[0] = reg_read(vip, DVP_CTL); in sta2x11_vip_suspend()
1217 reg_write(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS); in sta2x11_vip_suspend()
1218 vip->register_save_area[SAVE_COUNT] = reg_read(vip, DVP_ITM); in sta2x11_vip_suspend()
1219 reg_write(vip, DVP_ITM, 0); in sta2x11_vip_suspend()
1221 vip->register_save_area[i] = reg_read(vip, 4 * i); in sta2x11_vip_suspend()
1223 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] = in sta2x11_vip_suspend()
1224 reg_read(vip, registers_to_save[i]); in sta2x11_vip_suspend()
1225 spin_unlock_irqrestore(&vip->slock, flags); in sta2x11_vip_suspend()
1233 vip->disabled = 1; in sta2x11_vip_suspend()
1254 struct sta2x11_vip *vip = in sta2x11_vip_resume() local
1261 if (vip->disabled) { in sta2x11_vip_resume()
1267 vip->disabled = 0; in sta2x11_vip_resume()
1276 vip->disabled = 1; in sta2x11_vip_resume()
1282 spin_lock_irqsave(&vip->slock, flags); in sta2x11_vip_resume()
1284 reg_write(vip, 4 * i, vip->register_save_area[i]); in sta2x11_vip_resume()
1286 reg_write(vip, registers_to_save[i], in sta2x11_vip_resume()
1287 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]); in sta2x11_vip_resume()
1288 reg_write(vip, DVP_CTL, vip->register_save_area[0]); in sta2x11_vip_resume()
1289 reg_write(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]); in sta2x11_vip_resume()
1290 spin_unlock_irqrestore(&vip->slock, flags); in sta2x11_vip_resume()