Lines Matching full:vip

203 /* Write VIP register */
204 static inline void reg_write(struct sta2x11_vip *vip, unsigned int reg, u32 val) in reg_write() argument
206 iowrite32((val), (vip->iomem)+(reg)); in reg_write()
208 /* Read VIP register */
209 static inline u32 reg_read(struct sta2x11_vip *vip, unsigned int reg) in reg_read() argument
211 return ioread32((vip->iomem)+(reg)); in reg_read()
214 static void start_dma(struct sta2x11_vip *vip, struct vip_buffer *vip_buf) in start_dma() argument
218 if (vip->format.field == V4L2_FIELD_INTERLACED) in start_dma()
219 offset = vip->format.width * 2; in start_dma()
221 spin_lock_irq(&vip->slock); in start_dma()
223 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) | DVP_CTL_ENA); in start_dma()
225 reg_write(vip, DVP_VTP, (u32)vip_buf->dma); in start_dma()
226 reg_write(vip, DVP_VBP, (u32)vip_buf->dma + offset); in start_dma()
227 spin_unlock_irq(&vip->slock); in start_dma()
231 static void vip_active_buf_next(struct sta2x11_vip *vip) in vip_active_buf_next() argument
234 spin_lock(&vip->lock); in vip_active_buf_next()
235 if (list_empty(&vip->buffer_list)) {/* No available buffer */ in vip_active_buf_next()
236 spin_unlock(&vip->lock); in vip_active_buf_next()
239 vip->active = list_first_entry(&vip->buffer_list, in vip_active_buf_next()
243 vip->tcount = 0; in vip_active_buf_next()
244 vip->bcount = 0; in vip_active_buf_next()
245 spin_unlock(&vip->lock); in vip_active_buf_next()
246 if (vb2_is_streaming(&vip->vb_vidq)) { /* streaming is on */ in vip_active_buf_next()
247 start_dma(vip, vip->active); /* start dma capture */ in vip_active_buf_next()
257 struct sta2x11_vip *vip = vb2_get_drv_priv(vq); in queue_setup() local
263 sizes[0] = vip->format.sizeimage; in queue_setup()
265 vip->sequence = 0; in queue_setup()
266 vip->active = NULL; in queue_setup()
267 vip->tcount = 0; in queue_setup()
268 vip->bcount = 0; in queue_setup()
285 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare() local
289 size = vip->format.sizeimage; in buffer_prepare()
291 v4l2_err(&vip->v4l2_dev, "buffer too small (%lu < %lu)\n", in buffer_prepare()
303 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue() local
306 spin_lock(&vip->lock); in buffer_queue()
307 list_add_tail(&vip_buf->list, &vip->buffer_list); in buffer_queue()
308 if (!vip->active) { /* No active buffer, active the first one */ in buffer_queue()
309 vip->active = list_first_entry(&vip->buffer_list, in buffer_queue()
312 if (vb2_is_streaming(&vip->vb_vidq)) /* streaming is on */ in buffer_queue()
313 start_dma(vip, vip_buf); /* start dma capture */ in buffer_queue()
315 spin_unlock(&vip->lock); in buffer_queue()
320 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue); in buffer_finish() local
324 spin_lock(&vip->lock); in buffer_finish()
326 spin_unlock(&vip->lock); in buffer_finish()
329 vip_active_buf_next(vip); in buffer_finish()
334 struct sta2x11_vip *vip = vb2_get_drv_priv(vq); in start_streaming() local
336 spin_lock_irq(&vip->slock); in start_streaming()
338 reg_write(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST); in start_streaming()
339 spin_unlock_irq(&vip->slock); in start_streaming()
342 start_dma(vip, vip->active); in start_streaming()
350 struct sta2x11_vip *vip = vb2_get_drv_priv(vq); in stop_streaming() local
354 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA); in stop_streaming()
356 reg_write(vip, DVP_ITM, 0); in stop_streaming()
359 spin_lock(&vip->lock); in stop_streaming()
360 list_for_each_entry_safe(vip_buf, node, &vip->buffer_list, list) { in stop_streaming()
364 spin_unlock(&vip->lock); in stop_streaming()
426 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_s_std() local
433 v4l2_subdev_call(vip->decoder, video, querystd, &std); in vidioc_s_std()
438 if (vip->std != std) { in vidioc_s_std()
439 vip->std = std; in vidioc_s_std()
441 vip->format = formats_60[0]; in vidioc_s_std()
443 vip->format = formats_50[0]; in vidioc_s_std()
446 return v4l2_subdev_call(vip->decoder, video, s_std, std); in vidioc_s_std()
461 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_g_std() local
463 *std = vip->std; in vidioc_g_std()
479 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_querystd() local
481 return v4l2_subdev_call(vip->decoder, video, querystd, std); in vidioc_querystd()
511 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_s_input() local
516 ret = v4l2_subdev_call(vip->decoder, video, s_routing, i, 0, 0); in vidioc_s_input()
519 vip->input = i; in vidioc_s_input()
536 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_g_input() local
538 *i = vip->input; in vidioc_g_input()
583 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_try_fmt_vid_cap() local
587 v4l2_warn(&vip->v4l2_dev, "Invalid format, only UYVY supported\n"); in vidioc_try_fmt_vid_cap()
591 if (V4L2_STD_525_60 & vip->std) in vidioc_try_fmt_vid_cap()
641 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_s_fmt_vid_cap() local
649 if (vb2_is_busy(&vip->vb_vidq)) { in vidioc_s_fmt_vid_cap()
651 v4l2_err(&vip->v4l2_dev, "device busy\n"); in vidioc_s_fmt_vid_cap()
654 vip->format = f->fmt.pix; in vidioc_s_fmt_vid_cap()
655 switch (vip->format.field) { in vidioc_s_fmt_vid_cap()
657 t_stop = ((vip->format.height / 2 - 1) << 16) | in vidioc_s_fmt_vid_cap()
658 (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
660 pitch = 4 * vip->format.width; in vidioc_s_fmt_vid_cap()
663 t_stop = ((vip->format.height - 1) << 16) | in vidioc_s_fmt_vid_cap()
664 (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
665 b_stop = (0 << 16) | (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
666 pitch = 2 * vip->format.width; in vidioc_s_fmt_vid_cap()
669 t_stop = (0 << 16) | (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
670 b_stop = (vip->format.height << 16) | in vidioc_s_fmt_vid_cap()
671 (2 * vip->format.width - 1); in vidioc_s_fmt_vid_cap()
672 pitch = 2 * vip->format.width; in vidioc_s_fmt_vid_cap()
675 v4l2_err(&vip->v4l2_dev, "unknown field format\n"); in vidioc_s_fmt_vid_cap()
679 spin_lock_irq(&vip->slock); in vidioc_s_fmt_vid_cap()
681 reg_write(vip, DVP_TFO, 0); in vidioc_s_fmt_vid_cap()
683 reg_write(vip, DVP_BFO, 0); in vidioc_s_fmt_vid_cap()
685 reg_write(vip, DVP_TFS, t_stop); in vidioc_s_fmt_vid_cap()
687 reg_write(vip, DVP_BFS, b_stop); in vidioc_s_fmt_vid_cap()
689 reg_write(vip, DVP_VMP, pitch); in vidioc_s_fmt_vid_cap()
690 spin_unlock_irq(&vip->slock); in vidioc_s_fmt_vid_cap()
708 struct sta2x11_vip *vip = video_drvdata(file); in vidioc_g_fmt_vid_cap() local
710 f->fmt.pix = vip->format; in vidioc_g_fmt_vid_cap()
766 * return value: IRQ_NONE, interrupt was not generated by VIP
772 struct sta2x11_vip *vip = data; in vip_irq() local
775 status = reg_read(vip, DVP_ITS); in vip_irq()
781 if (vip->overflow++ > 5) in vip_irq()
782 pr_info("VIP: fifo overflow\n"); in vip_irq()
791 if ((++vip->tcount) < 2) in vip_irq()
794 vip->bcount++; in vip_irq()
798 if (vip->active) { /* Acquisition is over on this buffer */ in vip_irq()
800 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA); in vip_irq()
802 vip->active->vb.vb2_buf.timestamp = ktime_get_ns(); in vip_irq()
803 vip->active->vb.sequence = vip->sequence++; in vip_irq()
804 vb2_buffer_done(&vip->active->vb.vb2_buf, VB2_BUF_STATE_DONE); in vip_irq()
810 static void sta2x11_vip_init_register(struct sta2x11_vip *vip) in sta2x11_vip_init_register() argument
813 spin_lock_irq(&vip->slock); in sta2x11_vip_init_register()
815 reg_read(vip, DVP_ITS); in sta2x11_vip_init_register()
817 reg_write(vip, DVP_HLFLN, DVP_HLFLN_SD); in sta2x11_vip_init_register()
818 /* Reset VIP control */ in sta2x11_vip_init_register()
819 reg_write(vip, DVP_CTL, DVP_CTL_RST); in sta2x11_vip_init_register()
820 /* Clear VIP control */ in sta2x11_vip_init_register()
821 reg_write(vip, DVP_CTL, 0); in sta2x11_vip_init_register()
822 spin_unlock_irq(&vip->slock); in sta2x11_vip_init_register()
824 static void sta2x11_vip_clear_register(struct sta2x11_vip *vip) in sta2x11_vip_clear_register() argument
826 spin_lock_irq(&vip->slock); in sta2x11_vip_clear_register()
828 reg_write(vip, DVP_ITM, 0); in sta2x11_vip_clear_register()
829 /* Reset VIP Control */ in sta2x11_vip_clear_register()
830 reg_write(vip, DVP_CTL, DVP_CTL_RST); in sta2x11_vip_clear_register()
831 /* Clear VIP Control */ in sta2x11_vip_clear_register()
832 reg_write(vip, DVP_CTL, 0); in sta2x11_vip_clear_register()
833 /* Clean VIP Interrupt */ in sta2x11_vip_clear_register()
834 reg_read(vip, DVP_ITS); in sta2x11_vip_clear_register()
835 spin_unlock_irq(&vip->slock); in sta2x11_vip_clear_register()
837 static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip) in sta2x11_vip_init_buffer() argument
841 err = dma_set_coherent_mask(&vip->pdev->dev, DMA_BIT_MASK(29)); in sta2x11_vip_init_buffer()
843 v4l2_err(&vip->v4l2_dev, "Cannot configure coherent mask"); in sta2x11_vip_init_buffer()
846 memset(&vip->vb_vidq, 0, sizeof(struct vb2_queue)); in sta2x11_vip_init_buffer()
847 vip->vb_vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in sta2x11_vip_init_buffer()
848 vip->vb_vidq.io_modes = VB2_MMAP | VB2_READ; in sta2x11_vip_init_buffer()
849 vip->vb_vidq.drv_priv = vip; in sta2x11_vip_init_buffer()
850 vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer); in sta2x11_vip_init_buffer()
851 vip->vb_vidq.ops = &vip_video_qops; in sta2x11_vip_init_buffer()
852 vip->vb_vidq.mem_ops = &vb2_dma_contig_memops; in sta2x11_vip_init_buffer()
853 vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in sta2x11_vip_init_buffer()
854 vip->vb_vidq.dev = &vip->pdev->dev; in sta2x11_vip_init_buffer()
855 vip->vb_vidq.lock = &vip->v4l_lock; in sta2x11_vip_init_buffer()
856 err = vb2_queue_init(&vip->vb_vidq); in sta2x11_vip_init_buffer()
859 INIT_LIST_HEAD(&vip->buffer_list); in sta2x11_vip_init_buffer()
860 spin_lock_init(&vip->lock); in sta2x11_vip_init_buffer()
864 static int sta2x11_vip_init_controls(struct sta2x11_vip *vip) in sta2x11_vip_init_controls() argument
867 * Inititialize an empty control so VIP can inerithing controls in sta2x11_vip_init_controls()
870 v4l2_ctrl_handler_init(&vip->ctrl_hdl, 0); in sta2x11_vip_init_controls()
872 vip->v4l2_dev.ctrl_handler = &vip->ctrl_hdl; in sta2x11_vip_init_controls()
873 if (vip->ctrl_hdl.error) { in sta2x11_vip_init_controls()
874 int err = vip->ctrl_hdl.error; in sta2x11_vip_init_controls()
876 v4l2_ctrl_handler_free(&vip->ctrl_hdl); in sta2x11_vip_init_controls()
965 struct sta2x11_vip *vip; in sta2x11_vip_init_one() local
978 /* Get VIP platform data */ in sta2x11_vip_init_one()
981 dev_info(&pdev->dev, "VIP slot disabled\n"); in sta2x11_vip_init_one()
1013 /* Allocate a new VIP instance */ in sta2x11_vip_init_one()
1014 vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL); in sta2x11_vip_init_one()
1015 if (!vip) { in sta2x11_vip_init_one()
1019 vip->pdev = pdev; in sta2x11_vip_init_one()
1020 vip->std = V4L2_STD_PAL; in sta2x11_vip_init_one()
1021 vip->format = formats_50[0]; in sta2x11_vip_init_one()
1022 vip->config = config; in sta2x11_vip_init_one()
1023 mutex_init(&vip->v4l_lock); in sta2x11_vip_init_one()
1025 ret = sta2x11_vip_init_controls(vip); in sta2x11_vip_init_one()
1028 ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev); in sta2x11_vip_init_one()
1042 vip->iomem = pci_iomap(pdev, 0, 0x100); in sta2x11_vip_init_one()
1043 if (!vip->iomem) { in sta2x11_vip_init_one()
1051 ret = sta2x11_vip_init_buffer(vip); in sta2x11_vip_init_one()
1055 spin_lock_init(&vip->slock); in sta2x11_vip_init_one()
1057 ret = request_irq(pdev->irq, vip_irq, IRQF_SHARED, KBUILD_MODNAME, vip); in sta2x11_vip_init_one()
1065 vip->video_dev = video_dev_template; in sta2x11_vip_init_one()
1066 vip->video_dev.v4l2_dev = &vip->v4l2_dev; in sta2x11_vip_init_one()
1067 vip->video_dev.queue = &vip->vb_vidq; in sta2x11_vip_init_one()
1068 vip->video_dev.lock = &vip->v4l_lock; in sta2x11_vip_init_one()
1069 video_set_drvdata(&vip->video_dev, vip); in sta2x11_vip_init_one()
1071 ret = video_register_device(&vip->video_dev, VFL_TYPE_VIDEO, -1); in sta2x11_vip_init_one()
1076 vip->adapter = i2c_get_adapter(vip->config->i2c_id); in sta2x11_vip_init_one()
1077 if (!vip->adapter) { in sta2x11_vip_init_one()
1083 vip->decoder = v4l2_i2c_new_subdev(&vip->v4l2_dev, vip->adapter, in sta2x11_vip_init_one()
1084 "adv7180", vip->config->i2c_addr, in sta2x11_vip_init_one()
1086 if (!vip->decoder) { in sta2x11_vip_init_one()
1092 i2c_put_adapter(vip->adapter); in sta2x11_vip_init_one()
1093 v4l2_subdev_call(vip->decoder, core, init, 0); in sta2x11_vip_init_one()
1095 sta2x11_vip_init_register(vip); in sta2x11_vip_init_one()
1097 dev_info(&pdev->dev, "STA2X11 Video Input Port (VIP) loaded\n"); in sta2x11_vip_init_one()
1101 video_set_drvdata(&vip->video_dev, NULL); in sta2x11_vip_init_one()
1103 vb2_video_unregister_device(&vip->video_dev); in sta2x11_vip_init_one()
1104 free_irq(pdev->irq, vip); in sta2x11_vip_init_one()
1108 pci_iounmap(pdev, vip->iomem); in sta2x11_vip_init_one()
1112 v4l2_device_unregister(&vip->v4l2_dev); in sta2x11_vip_init_one()
1114 kfree(vip); in sta2x11_vip_init_one()
1141 struct sta2x11_vip *vip = in sta2x11_vip_remove_one() local
1144 sta2x11_vip_clear_register(vip); in sta2x11_vip_remove_one()
1146 video_set_drvdata(&vip->video_dev, NULL); in sta2x11_vip_remove_one()
1147 vb2_video_unregister_device(&vip->video_dev); in sta2x11_vip_remove_one()
1148 free_irq(pdev->irq, vip); in sta2x11_vip_remove_one()
1150 pci_iounmap(pdev, vip->iomem); in sta2x11_vip_remove_one()
1153 v4l2_device_unregister(&vip->v4l2_dev); in sta2x11_vip_remove_one()
1155 vip_gpio_release(&pdev->dev, vip->config->pwr_pin, in sta2x11_vip_remove_one()
1156 vip->config->pwr_name); in sta2x11_vip_remove_one()
1157 vip_gpio_release(&pdev->dev, vip->config->reset_pin, in sta2x11_vip_remove_one()
1158 vip->config->reset_name); in sta2x11_vip_remove_one()
1160 kfree(vip); in sta2x11_vip_remove_one()
1179 struct sta2x11_vip *vip = in sta2x11_vip_suspend() local
1184 spin_lock_irqsave(&vip->slock, flags); in sta2x11_vip_suspend()
1185 vip->register_save_area[0] = reg_read(vip, DVP_CTL); in sta2x11_vip_suspend()
1186 reg_write(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS); in sta2x11_vip_suspend()
1187 vip->register_save_area[SAVE_COUNT] = reg_read(vip, DVP_ITM); in sta2x11_vip_suspend()
1188 reg_write(vip, DVP_ITM, 0); in sta2x11_vip_suspend()
1190 vip->register_save_area[i] = reg_read(vip, 4 * i); in sta2x11_vip_suspend()
1192 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] = in sta2x11_vip_suspend()
1193 reg_read(vip, registers_to_save[i]); in sta2x11_vip_suspend()
1194 spin_unlock_irqrestore(&vip->slock, flags); in sta2x11_vip_suspend()
1196 vip->disabled = 1; in sta2x11_vip_suspend()
1198 pr_info("VIP: suspend\n"); in sta2x11_vip_suspend()
1213 struct sta2x11_vip *vip = in sta2x11_vip_resume() local
1218 pr_info("VIP: resume\n"); in sta2x11_vip_resume()
1220 vip->disabled = 0; in sta2x11_vip_resume()
1222 spin_lock_irqsave(&vip->slock, flags); in sta2x11_vip_resume()
1224 reg_write(vip, 4 * i, vip->register_save_area[i]); in sta2x11_vip_resume()
1226 reg_write(vip, registers_to_save[i], in sta2x11_vip_resume()
1227 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]); in sta2x11_vip_resume()
1228 reg_write(vip, DVP_CTL, vip->register_save_area[0]); in sta2x11_vip_resume()
1229 reg_write(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]); in sta2x11_vip_resume()
1230 spin_unlock_irqrestore(&vip->slock, flags); in sta2x11_vip_resume()