Lines Matching full:video
3 * Driver for Video Capture/Differentiation Engine (VCD) and Encoding
40 #include <uapi/linux/npcm-video.h>
43 #define DEVICE_NAME "npcm-video"
69 * VIDEO_STREAMING: a flag indicating if the video has started streaming
72 * VIDEO_STOPPED: a flag indicating if the video has stopped streaming
211 static unsigned int npcm_video_ece_get_ed_size(struct npcm_video *video, in npcm_video_ece_get_ed_size() argument
214 struct regmap *ece = video->ece.regmap; in npcm_video_ece_get_ed_size()
223 dev_warn(video->dev, "Wait for ECE_DDA_STS_CDREADY timeout\n"); in npcm_video_ece_get_ed_size()
231 dev_dbg(video->dev, "offset = %u, ed_size = %u, gap = %u\n", offset, in npcm_video_ece_get_ed_size()
237 static void npcm_video_ece_enc_rect(struct npcm_video *video, in npcm_video_ece_enc_rect() argument
241 struct regmap *ece = video->ece.regmap; in npcm_video_ece_enc_rect()
242 unsigned int rect_offset = (r_off_y * video->bytesperline) + (r_off_x * 2); in npcm_video_ece_enc_rect()
271 static unsigned int npcm_video_ece_read_rect_offset(struct npcm_video *video) in npcm_video_ece_read_rect_offset() argument
273 struct regmap *ece = video->ece.regmap; in npcm_video_ece_read_rect_offset()
284 static void npcm_video_ece_set_lp(struct npcm_video *video, unsigned int pitch) in npcm_video_ece_set_lp() argument
286 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_lp()
312 static inline void npcm_video_ece_set_fb_addr(struct npcm_video *video, in npcm_video_ece_set_fb_addr() argument
315 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_fb_addr()
320 static inline void npcm_video_ece_set_enc_dba(struct npcm_video *video, in npcm_video_ece_set_enc_dba() argument
323 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_enc_dba()
328 static inline void npcm_video_ece_clear_rect_offset(struct npcm_video *video) in npcm_video_ece_clear_rect_offset() argument
330 struct regmap *ece = video->ece.regmap; in npcm_video_ece_clear_rect_offset()
335 static void npcm_video_ece_ctrl_reset(struct npcm_video *video) in npcm_video_ece_ctrl_reset() argument
337 struct regmap *ece = video->ece.regmap; in npcm_video_ece_ctrl_reset()
344 npcm_video_ece_clear_rect_offset(video); in npcm_video_ece_ctrl_reset()
347 static void npcm_video_ece_ip_reset(struct npcm_video *video) in npcm_video_ece_ip_reset() argument
353 reset_control_assert(video->ece.reset); in npcm_video_ece_ip_reset()
355 reset_control_deassert(video->ece.reset); in npcm_video_ece_ip_reset()
359 static void npcm_video_ece_stop(struct npcm_video *video) in npcm_video_ece_stop() argument
361 struct regmap *ece = video->ece.regmap; in npcm_video_ece_stop()
366 npcm_video_ece_clear_rect_offset(video); in npcm_video_ece_stop()
369 static bool npcm_video_alloc_fb(struct npcm_video *video, in npcm_video_alloc_fb() argument
372 addr->virt = dma_alloc_coherent(video->dev, VCD_FB_SIZE, &addr->dma, in npcm_video_alloc_fb()
381 static void npcm_video_free_fb(struct npcm_video *video, in npcm_video_free_fb() argument
384 dma_free_coherent(video->dev, addr->size, addr->virt, addr->dma); in npcm_video_free_fb()
390 static void npcm_video_free_diff_table(struct npcm_video *video) in npcm_video_free_diff_table() argument
396 for (i = 0; i < video->queue.num_buffers; i++) { in npcm_video_free_diff_table()
397 head = &video->list[i]; in npcm_video_free_diff_table()
406 static unsigned int npcm_video_add_rect(struct npcm_video *video, in npcm_video_add_rect() argument
411 struct list_head *head = &video->list[index]; in npcm_video_add_rect()
429 static void npcm_video_merge_rect(struct npcm_video *video, in npcm_video_merge_rect() argument
440 video->rect_cnt++; in npcm_video_merge_rect()
456 video->rect_cnt++; in npcm_video_merge_rect()
462 static struct rect_list *npcm_video_new_rect(struct npcm_video *video, in npcm_video_new_rect() argument
466 struct v4l2_bt_timings *act = &video->active_timings; in npcm_video_new_rect()
488 static int npcm_video_find_rect(struct npcm_video *video, in npcm_video_find_rect() argument
493 info->list = npcm_video_new_rect(video, offset, info->index); in npcm_video_find_rect()
495 dev_err(video->dev, "Failed to allocate rect_list\n"); in npcm_video_find_rect()
499 npcm_video_merge_rect(video, info); in npcm_video_find_rect()
504 static int npcm_video_build_table(struct npcm_video *video, in npcm_video_build_table() argument
507 struct regmap *vcd = video->vcd_regmap; in npcm_video_build_table()
517 ret = npcm_video_find_rect(video, info, bit + (j << 3)); in npcm_video_build_table()
526 static void npcm_video_get_rect_list(struct npcm_video *video, unsigned int index) in npcm_video_get_rect_list() argument
528 struct v4l2_bt_timings *act = &video->active_timings; in npcm_video_get_rect_list()
534 info.head = &video->list[index]; in npcm_video_get_rect_list()
556 ret = npcm_video_build_table(video, &info); in npcm_video_get_rect_list()
564 static unsigned int npcm_video_is_mga(struct npcm_video *video) in npcm_video_is_mga() argument
566 struct regmap *gfxi = video->gfx_regmap; in npcm_video_is_mga()
573 static unsigned int npcm_video_hres(struct npcm_video *video) in npcm_video_hres() argument
575 struct regmap *gfxi = video->gfx_regmap; in npcm_video_hres()
585 static unsigned int npcm_video_vres(struct npcm_video *video) in npcm_video_vres() argument
587 struct regmap *gfxi = video->gfx_regmap; in npcm_video_vres()
598 static int npcm_video_capres(struct npcm_video *video, unsigned int hor_res, in npcm_video_capres() argument
601 struct regmap *vcd = video->vcd_regmap; in npcm_video_capres()
619 static void npcm_video_vcd_ip_reset(struct npcm_video *video) in npcm_video_vcd_ip_reset() argument
625 reset_control_assert(video->reset); in npcm_video_vcd_ip_reset()
627 reset_control_deassert(video->reset); in npcm_video_vcd_ip_reset()
631 static void npcm_video_vcd_state_machine_reset(struct npcm_video *video) in npcm_video_vcd_state_machine_reset() argument
633 struct regmap *vcd = video->vcd_regmap; in npcm_video_vcd_state_machine_reset()
650 static void npcm_video_gfx_reset(struct npcm_video *video) in npcm_video_gfx_reset() argument
652 struct regmap *gcr = video->gcr_regmap; in npcm_video_gfx_reset()
655 npcm_video_vcd_state_machine_reset(video); in npcm_video_gfx_reset()
659 static void npcm_video_kvm_bw(struct npcm_video *video, bool set_bw) in npcm_video_kvm_bw() argument
661 struct regmap *vcd = video->vcd_regmap; in npcm_video_kvm_bw()
663 if (set_bw || !npcm_video_is_mga(video)) in npcm_video_kvm_bw()
670 static unsigned int npcm_video_pclk(struct npcm_video *video) in npcm_video_pclk() argument
672 struct regmap *gfxi = video->gfx_regmap; in npcm_video_pclk()
697 static unsigned int npcm_video_get_bpp(struct npcm_video *video) in npcm_video_get_bpp() argument
704 if (fmt->fourcc == video->pix_fmt.pixelformat) in npcm_video_get_bpp()
715 static void npcm_video_set_linepitch(struct npcm_video *video, in npcm_video_set_linepitch() argument
718 struct regmap *vcd = video->vcd_regmap; in npcm_video_set_linepitch()
728 static unsigned int npcm_video_get_linepitch(struct npcm_video *video) in npcm_video_get_linepitch() argument
730 struct regmap *vcd = video->vcd_regmap; in npcm_video_get_linepitch()
737 static void npcm_video_command(struct npcm_video *video, unsigned int value) in npcm_video_command() argument
739 struct regmap *vcd = video->vcd_regmap; in npcm_video_command()
748 video->op_cmd = value; in npcm_video_command()
751 static void npcm_video_init_reg(struct npcm_video *video) in npcm_video_init_reg() argument
753 struct regmap *gcr = video->gcr_regmap, *vcd = video->vcd_regmap; in npcm_video_init_reg()
765 /* Reset video modules */ in npcm_video_init_reg()
766 npcm_video_vcd_ip_reset(video); in npcm_video_init_reg()
767 npcm_video_gfx_reset(video); in npcm_video_init_reg()
776 /* Set video mode */ in npcm_video_init_reg()
781 static int npcm_video_start_frame(struct npcm_video *video) in npcm_video_start_frame() argument
784 struct regmap *vcd = video->vcd_regmap; in npcm_video_start_frame()
789 if (video->v4l2_input_status) { in npcm_video_start_frame()
790 dev_dbg(video->dev, "No video signal; skip capture frame\n"); in npcm_video_start_frame()
797 dev_err(video->dev, "Wait for VCD_STAT_BUSY timeout\n"); in npcm_video_start_frame()
801 spin_lock_irqsave(&video->lock, flags); in npcm_video_start_frame()
802 buf = list_first_entry_or_null(&video->buffers, in npcm_video_start_frame()
805 spin_unlock_irqrestore(&video->lock, flags); in npcm_video_start_frame()
806 dev_dbg(video->dev, "No empty buffers; skip capture frame\n"); in npcm_video_start_frame()
810 set_bit(VIDEO_CAPTURING, &video->flags); in npcm_video_start_frame()
811 spin_unlock_irqrestore(&video->lock, flags); in npcm_video_start_frame()
813 npcm_video_vcd_state_machine_reset(video); in npcm_video_start_frame()
828 npcm_video_command(video, video->ctrl_cmd); in npcm_video_start_frame()
833 static void npcm_video_bufs_done(struct npcm_video *video, in npcm_video_bufs_done() argument
839 spin_lock_irqsave(&video->lock, flags); in npcm_video_bufs_done()
840 list_for_each_entry(buf, &video->buffers, link) in npcm_video_bufs_done()
843 INIT_LIST_HEAD(&video->buffers); in npcm_video_bufs_done()
844 spin_unlock_irqrestore(&video->lock, flags); in npcm_video_bufs_done()
847 static void npcm_video_get_diff_rect(struct npcm_video *video, unsigned int index) in npcm_video_get_diff_rect() argument
849 unsigned int width = video->active_timings.width; in npcm_video_get_diff_rect()
850 unsigned int height = video->active_timings.height; in npcm_video_get_diff_rect()
852 if (video->op_cmd != VCD_CMD_OPERATION_CAPTURE) { in npcm_video_get_diff_rect()
853 video->rect_cnt = 0; in npcm_video_get_diff_rect()
854 npcm_video_get_rect_list(video, index); in npcm_video_get_diff_rect()
855 video->rect[index] = video->rect_cnt; in npcm_video_get_diff_rect()
857 video->rect[index] = npcm_video_add_rect(video, index, 0, 0, in npcm_video_get_diff_rect()
862 static void npcm_video_detect_resolution(struct npcm_video *video) in npcm_video_detect_resolution() argument
864 struct v4l2_bt_timings *act = &video->active_timings; in npcm_video_detect_resolution()
865 struct v4l2_bt_timings *det = &video->detected_timings; in npcm_video_detect_resolution()
866 struct regmap *gfxi = video->gfx_regmap; in npcm_video_detect_resolution()
869 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in npcm_video_detect_resolution()
870 det->width = npcm_video_hres(video); in npcm_video_detect_resolution()
871 det->height = npcm_video_vres(video); in npcm_video_detect_resolution()
874 dev_dbg(video->dev, "Resolution changed\n"); in npcm_video_detect_resolution()
876 if (npcm_video_hres(video) > 0 && npcm_video_vres(video) > 0) { in npcm_video_detect_resolution()
877 if (test_bit(VIDEO_STREAMING, &video->flags)) { in npcm_video_detect_resolution()
885 } while (npcm_video_vres(video) < 100 || in npcm_video_detect_resolution()
886 npcm_video_pclk(video) == 0 || in npcm_video_detect_resolution()
890 det->width = npcm_video_hres(video); in npcm_video_detect_resolution()
891 det->height = npcm_video_vres(video); in npcm_video_detect_resolution()
892 det->pixelclock = npcm_video_pclk(video); in npcm_video_detect_resolution()
895 clear_bit(VIDEO_RES_CHANGING, &video->flags); in npcm_video_detect_resolution()
899 video->v4l2_input_status = 0; in npcm_video_detect_resolution()
901 dev_dbg(video->dev, "Got resolution[%dx%d] -> [%dx%d], status %d\n", in npcm_video_detect_resolution()
903 video->v4l2_input_status); in npcm_video_detect_resolution()
906 static int npcm_video_set_resolution(struct npcm_video *video, in npcm_video_set_resolution() argument
909 struct regmap *vcd = video->vcd_regmap; in npcm_video_set_resolution()
912 if (npcm_video_capres(video, timing->width, timing->height)) { in npcm_video_set_resolution()
913 dev_err(video->dev, "Failed to set VCD_CAP_RES\n"); in npcm_video_set_resolution()
917 video->active_timings = *timing; in npcm_video_set_resolution()
918 video->bytesperpixel = npcm_video_get_bpp(video); in npcm_video_set_resolution()
919 npcm_video_set_linepitch(video, timing->width * video->bytesperpixel); in npcm_video_set_resolution()
920 video->bytesperline = npcm_video_get_linepitch(video); in npcm_video_set_resolution()
921 video->pix_fmt.width = timing->width ? timing->width : MIN_WIDTH; in npcm_video_set_resolution()
922 video->pix_fmt.height = timing->height ? timing->height : MIN_HEIGHT; in npcm_video_set_resolution()
923 video->pix_fmt.sizeimage = video->pix_fmt.width * video->pix_fmt.height * in npcm_video_set_resolution()
924 video->bytesperpixel; in npcm_video_set_resolution()
925 video->pix_fmt.bytesperline = video->bytesperline; in npcm_video_set_resolution()
927 npcm_video_kvm_bw(video, timing->pixelclock > VCD_KVM_BW_PCLK); in npcm_video_set_resolution()
928 npcm_video_gfx_reset(video); in npcm_video_set_resolution()
931 dev_dbg(video->dev, "VCD mode = 0x%x, %s mode\n", mode, in npcm_video_set_resolution()
932 npcm_video_is_mga(video) ? "Hi Res" : "VGA"); in npcm_video_set_resolution()
934 dev_dbg(video->dev, in npcm_video_set_resolution()
936 timing->width, timing->height, video->bytesperpixel, in npcm_video_set_resolution()
937 timing->pixelclock, video->bytesperline); in npcm_video_set_resolution()
942 static void npcm_video_start(struct npcm_video *video) in npcm_video_start() argument
944 npcm_video_init_reg(video); in npcm_video_start()
946 if (!npcm_video_alloc_fb(video, &video->src)) { in npcm_video_start()
947 dev_err(video->dev, "Failed to allocate VCD frame buffer\n"); in npcm_video_start()
951 npcm_video_detect_resolution(video); in npcm_video_start()
952 if (npcm_video_set_resolution(video, &video->detected_timings)) { in npcm_video_start()
953 dev_err(video->dev, "Failed to set resolution\n"); in npcm_video_start()
958 regmap_write(video->vcd_regmap, VCD_FBA_ADR, video->src.dma); in npcm_video_start()
959 regmap_write(video->vcd_regmap, VCD_FBB_ADR, video->src.dma); in npcm_video_start()
961 if (video->ece.enable && atomic_inc_return(&video->ece.clients) == 1) { in npcm_video_start()
962 npcm_video_ece_ip_reset(video); in npcm_video_start()
963 npcm_video_ece_ctrl_reset(video); in npcm_video_start()
964 npcm_video_ece_set_fb_addr(video, video->src.dma); in npcm_video_start()
965 npcm_video_ece_set_lp(video, video->bytesperline); in npcm_video_start()
967 dev_dbg(video->dev, "ECE open: client %d\n", in npcm_video_start()
968 atomic_read(&video->ece.clients)); in npcm_video_start()
972 static void npcm_video_stop(struct npcm_video *video) in npcm_video_stop() argument
974 struct regmap *vcd = video->vcd_regmap; in npcm_video_stop()
976 set_bit(VIDEO_STOPPED, &video->flags); in npcm_video_stop()
983 if (video->src.size) in npcm_video_stop()
984 npcm_video_free_fb(video, &video->src); in npcm_video_stop()
986 npcm_video_free_diff_table(video); in npcm_video_stop()
987 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in npcm_video_stop()
988 video->flags = 0; in npcm_video_stop()
989 video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; in npcm_video_stop()
991 if (video->ece.enable && atomic_dec_return(&video->ece.clients) == 0) { in npcm_video_stop()
992 npcm_video_ece_stop(video); in npcm_video_stop()
993 dev_dbg(video->dev, "ECE close: client %d\n", in npcm_video_stop()
994 atomic_read(&video->ece.clients)); in npcm_video_stop()
998 static unsigned int npcm_video_raw(struct npcm_video *video, int index, void *addr) in npcm_video_raw() argument
1000 unsigned int width = video->active_timings.width; in npcm_video_raw()
1001 unsigned int height = video->active_timings.height; in npcm_video_raw()
1004 video->rect[index] = npcm_video_add_rect(video, index, 0, 0, width, height); in npcm_video_raw()
1007 len = width * video->bytesperpixel; in npcm_video_raw()
1008 offset = i * video->bytesperline; in npcm_video_raw()
1010 memcpy(addr + bytes, video->src.virt + offset, len); in npcm_video_raw()
1017 static unsigned int npcm_video_hextile(struct npcm_video *video, unsigned int index, in npcm_video_hextile() argument
1024 npcm_video_ece_ctrl_reset(video); in npcm_video_hextile()
1025 npcm_video_ece_clear_rect_offset(video); in npcm_video_hextile()
1026 npcm_video_ece_set_fb_addr(video, video->src.dma); in npcm_video_hextile()
1028 /* Set base address of encoded data to video buffer */ in npcm_video_hextile()
1029 npcm_video_ece_set_enc_dba(video, dma_addr); in npcm_video_hextile()
1031 npcm_video_ece_set_lp(video, video->bytesperline); in npcm_video_hextile()
1032 npcm_video_get_diff_rect(video, index); in npcm_video_hextile()
1034 list_for_each_entry(rect_list, &video->list[index], list) { in npcm_video_hextile()
1036 offset = npcm_video_ece_read_rect_offset(video); in npcm_video_hextile()
1037 npcm_video_ece_enc_rect(video, rect->left, rect->top, in npcm_video_hextile()
1040 len = npcm_video_ece_get_ed_size(video, offset, vaddr); in npcm_video_hextile()
1052 struct npcm_video *video = arg; in npcm_video_irq() local
1053 struct regmap *vcd = video->vcd_regmap; in npcm_video_irq()
1064 dev_dbg(video->dev, "VCD irq status 0x%x\n", status); in npcm_video_irq()
1068 if (test_bit(VIDEO_STOPPED, &video->flags) || in npcm_video_irq()
1069 !test_bit(VIDEO_STREAMING, &video->flags)) in npcm_video_irq()
1074 spin_lock(&video->lock); in npcm_video_irq()
1075 clear_bit(VIDEO_CAPTURING, &video->flags); in npcm_video_irq()
1076 buf = list_first_entry_or_null(&video->buffers, in npcm_video_irq()
1079 spin_unlock(&video->lock); in npcm_video_irq()
1085 fmt = video->pix_fmt.pixelformat; in npcm_video_irq()
1089 size = npcm_video_raw(video, index, addr); in npcm_video_irq()
1093 size = npcm_video_hextile(video, index, dma_addr, addr); in npcm_video_irq()
1096 spin_unlock(&video->lock); in npcm_video_irq()
1102 buf->vb.sequence = video->sequence++; in npcm_video_irq()
1107 spin_unlock(&video->lock); in npcm_video_irq()
1109 if (npcm_video_start_frame(video)) in npcm_video_irq()
1110 dev_err(video->dev, "Failed to capture next frame\n"); in npcm_video_irq()
1115 if (!test_bit(VIDEO_RES_CHANGING, &video->flags)) { in npcm_video_irq()
1116 set_bit(VIDEO_RES_CHANGING, &video->flags); in npcm_video_irq()
1118 vb2_queue_error(&video->queue); in npcm_video_irq()
1119 v4l2_event_queue(&video->vdev, &ev); in npcm_video_irq()
1124 dev_warn(video->dev, "VCD FIFO overrun or over thresholds\n"); in npcm_video_irq()
1125 if (npcm_video_start_frame(video)) in npcm_video_irq()
1126 dev_err(video->dev, "Failed to recover from FIFO overrun\n"); in npcm_video_irq()
1136 strscpy(cap->card, "NPCM Video Engine", sizeof(cap->card)); in npcm_video_querycap()
1144 struct npcm_video *video = video_drvdata(file); in npcm_video_enum_format() local
1151 if (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable) in npcm_video_enum_format()
1161 struct npcm_video *video = video_drvdata(file); in npcm_video_try_format() local
1167 if (!fmt || (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable)) in npcm_video_try_format()
1173 f->fmt.pix.width = video->pix_fmt.width; in npcm_video_try_format()
1174 f->fmt.pix.height = video->pix_fmt.height; in npcm_video_try_format()
1175 f->fmt.pix.bytesperline = video->bytesperline; in npcm_video_try_format()
1176 f->fmt.pix.sizeimage = video->pix_fmt.sizeimage; in npcm_video_try_format()
1184 struct npcm_video *video = video_drvdata(file); in npcm_video_get_format() local
1186 f->fmt.pix = video->pix_fmt; in npcm_video_get_format()
1193 struct npcm_video *video = video_drvdata(file); in npcm_video_set_format() local
1200 if (vb2_is_busy(&video->queue)) { in npcm_video_set_format()
1201 dev_err(video->dev, "%s device busy\n", __func__); in npcm_video_set_format()
1205 video->pix_fmt.pixelformat = f->fmt.pix.pixelformat; in npcm_video_set_format()
1212 struct npcm_video *video = video_drvdata(file); in npcm_video_enum_input() local
1220 inp->status = video->v4l2_input_status; in npcm_video_enum_input()
1243 struct npcm_video *video = video_drvdata(file); in npcm_video_set_dv_timings() local
1246 if (timings->bt.width == video->active_timings.width && in npcm_video_set_dv_timings()
1247 timings->bt.height == video->active_timings.height) in npcm_video_set_dv_timings()
1250 if (vb2_is_busy(&video->queue)) { in npcm_video_set_dv_timings()
1251 dev_err(video->dev, "%s device busy\n", __func__); in npcm_video_set_dv_timings()
1255 rc = npcm_video_set_resolution(video, &timings->bt); in npcm_video_set_dv_timings()
1267 struct npcm_video *video = video_drvdata(file); in npcm_video_get_dv_timings() local
1270 timings->bt = video->active_timings; in npcm_video_get_dv_timings()
1278 struct npcm_video *video = video_drvdata(file); in npcm_video_query_dv_timings() local
1280 npcm_video_detect_resolution(video); in npcm_video_query_dv_timings()
1282 timings->bt = video->detected_timings; in npcm_video_query_dv_timings()
1284 return video->v4l2_input_status ? -ENOLINK : 0; in npcm_video_query_dv_timings()
1347 struct npcm_video *video = container_of(ctrl->handler, struct npcm_video, in npcm_video_set_ctrl() local
1353 video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; in npcm_video_set_ctrl()
1355 video->ctrl_cmd = VCD_CMD_OPERATION_COMPARE; in npcm_video_set_ctrl()
1377 .name = "NPCM Video Capture Mode",
1401 struct npcm_video *video = video_drvdata(file); in npcm_video_open() local
1404 mutex_lock(&video->video_lock); in npcm_video_open()
1407 mutex_unlock(&video->video_lock); in npcm_video_open()
1412 npcm_video_start(video); in npcm_video_open()
1414 mutex_unlock(&video->video_lock); in npcm_video_open()
1420 struct npcm_video *video = video_drvdata(file); in npcm_video_release() local
1423 mutex_lock(&video->video_lock); in npcm_video_release()
1425 npcm_video_stop(video); in npcm_video_release()
1429 mutex_unlock(&video->video_lock); in npcm_video_release()
1447 struct npcm_video *video = vb2_get_drv_priv(q); in npcm_video_queue_setup() local
1451 if (sizes[0] < video->pix_fmt.sizeimage) in npcm_video_queue_setup()
1458 sizes[0] = video->pix_fmt.sizeimage; in npcm_video_queue_setup()
1461 INIT_LIST_HEAD(&video->list[i]); in npcm_video_queue_setup()
1468 struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); in npcm_video_buf_prepare() local
1470 if (vb2_plane_size(vb, 0) < video->pix_fmt.sizeimage) in npcm_video_buf_prepare()
1478 struct npcm_video *video = vb2_get_drv_priv(q); in npcm_video_start_streaming() local
1481 video->sequence = 0; in npcm_video_start_streaming()
1482 rc = npcm_video_start_frame(video); in npcm_video_start_streaming()
1484 npcm_video_bufs_done(video, VB2_BUF_STATE_QUEUED); in npcm_video_start_streaming()
1488 set_bit(VIDEO_STREAMING, &video->flags); in npcm_video_start_streaming()
1494 struct npcm_video *video = vb2_get_drv_priv(q); in npcm_video_stop_streaming() local
1495 struct regmap *vcd = video->vcd_regmap; in npcm_video_stop_streaming()
1497 clear_bit(VIDEO_STREAMING, &video->flags); in npcm_video_stop_streaming()
1500 npcm_video_gfx_reset(video); in npcm_video_stop_streaming()
1501 npcm_video_bufs_done(video, VB2_BUF_STATE_ERROR); in npcm_video_stop_streaming()
1502 video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; in npcm_video_stop_streaming()
1503 v4l2_ctrl_s_ctrl(video->rect_cnt_ctrl, 0); in npcm_video_stop_streaming()
1508 struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); in npcm_video_buf_queue() local
1514 spin_lock_irqsave(&video->lock, flags); in npcm_video_buf_queue()
1515 empty = list_empty(&video->buffers); in npcm_video_buf_queue()
1516 list_add_tail(&nvb->link, &video->buffers); in npcm_video_buf_queue()
1517 spin_unlock_irqrestore(&video->lock, flags); in npcm_video_buf_queue()
1519 if (test_bit(VIDEO_STREAMING, &video->flags) && in npcm_video_buf_queue()
1520 !test_bit(VIDEO_CAPTURING, &video->flags) && empty) { in npcm_video_buf_queue()
1521 if (npcm_video_start_frame(video)) in npcm_video_buf_queue()
1522 dev_err(video->dev, "Failed to capture next frame\n"); in npcm_video_buf_queue()
1528 struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); in npcm_video_buf_finish() local
1537 if (test_bit(VIDEO_STREAMING, &video->flags)) { in npcm_video_buf_finish()
1538 v4l2_ctrl_s_ctrl(video->rect_cnt_ctrl, video->rect[vb->index]); in npcm_video_buf_finish()
1540 head = &video->list[vb->index]; in npcm_video_buf_finish()
1574 static int npcm_video_setup_video(struct npcm_video *video) in npcm_video_setup_video() argument
1576 struct v4l2_device *v4l2_dev = &video->v4l2_dev; in npcm_video_setup_video()
1577 struct video_device *vdev = &video->vdev; in npcm_video_setup_video()
1578 struct vb2_queue *vbq = &video->queue; in npcm_video_setup_video()
1581 if (video->ece.enable) in npcm_video_setup_video()
1582 video->pix_fmt.pixelformat = V4L2_PIX_FMT_HEXTILE; in npcm_video_setup_video()
1584 video->pix_fmt.pixelformat = V4L2_PIX_FMT_RGB565; in npcm_video_setup_video()
1586 video->pix_fmt.field = V4L2_FIELD_NONE; in npcm_video_setup_video()
1587 video->pix_fmt.colorspace = V4L2_COLORSPACE_SRGB; in npcm_video_setup_video()
1588 video->pix_fmt.quantization = V4L2_QUANTIZATION_FULL_RANGE; in npcm_video_setup_video()
1589 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in npcm_video_setup_video()
1591 rc = v4l2_device_register(video->dev, v4l2_dev); in npcm_video_setup_video()
1593 dev_err(video->dev, "Failed to register v4l2 device\n"); in npcm_video_setup_video()
1597 v4l2_ctrl_handler_init(&video->ctrl_handler, 2); in npcm_video_setup_video()
1598 v4l2_ctrl_new_custom(&video->ctrl_handler, &npcm_ctrl_capture_mode, NULL); in npcm_video_setup_video()
1599 video->rect_cnt_ctrl = v4l2_ctrl_new_custom(&video->ctrl_handler, in npcm_video_setup_video()
1601 if (video->ctrl_handler.error) { in npcm_video_setup_video()
1602 dev_err(video->dev, "Failed to init controls: %d\n", in npcm_video_setup_video()
1603 video->ctrl_handler.error); in npcm_video_setup_video()
1605 rc = video->ctrl_handler.error; in npcm_video_setup_video()
1608 v4l2_dev->ctrl_handler = &video->ctrl_handler; in npcm_video_setup_video()
1613 vbq->lock = &video->video_lock; in npcm_video_setup_video()
1616 vbq->drv_priv = video; in npcm_video_setup_video()
1623 dev_err(video->dev, "Failed to init vb2 queue\n"); in npcm_video_setup_video()
1635 vdev->lock = &video->video_lock; in npcm_video_setup_video()
1637 video_set_drvdata(vdev, video); in npcm_video_setup_video()
1640 dev_err(video->dev, "Failed to register video device\n"); in npcm_video_setup_video()
1649 v4l2_ctrl_handler_free(&video->ctrl_handler); in npcm_video_setup_video()
1655 static int npcm_video_ece_init(struct npcm_video *video) in npcm_video_ece_init() argument
1657 struct device *dev = video->dev; in npcm_video_ece_init()
1662 ece_node = of_parse_phandle(video->dev->of_node, "nuvoton,ece", 0); in npcm_video_ece_init()
1668 video->ece.enable = of_device_is_available(ece_node); in npcm_video_ece_init()
1670 if (video->ece.enable) { in npcm_video_ece_init()
1686 video->ece.regmap = devm_regmap_init_mmio(dev, regs, in npcm_video_ece_init()
1688 if (IS_ERR(video->ece.regmap)) { in npcm_video_ece_init()
1690 return PTR_ERR(video->ece.regmap); in npcm_video_ece_init()
1693 video->ece.reset = devm_reset_control_get(&ece_pdev->dev, NULL); in npcm_video_ece_init()
1694 if (IS_ERR(video->ece.reset)) { in npcm_video_ece_init()
1696 return PTR_ERR(video->ece.reset); in npcm_video_ece_init()
1703 static int npcm_video_init(struct npcm_video *video) in npcm_video_init() argument
1705 struct device *dev = video->dev; in npcm_video_init()
1715 IRQF_ONESHOT, DEVICE_NAME, video); in npcm_video_init()
1728 rc = npcm_video_ece_init(video); in npcm_video_init()
1739 struct npcm_video *video = kzalloc(sizeof(*video), GFP_KERNEL); in npcm_video_probe() local
1743 if (!video) in npcm_video_probe()
1746 video->dev = &pdev->dev; in npcm_video_probe()
1747 spin_lock_init(&video->lock); in npcm_video_probe()
1748 mutex_init(&video->video_lock); in npcm_video_probe()
1749 INIT_LIST_HEAD(&video->buffers); in npcm_video_probe()
1757 video->vcd_regmap = devm_regmap_init_mmio(&pdev->dev, regs, in npcm_video_probe()
1759 if (IS_ERR(video->vcd_regmap)) { in npcm_video_probe()
1761 return PTR_ERR(video->vcd_regmap); in npcm_video_probe()
1764 video->reset = devm_reset_control_get(&pdev->dev, NULL); in npcm_video_probe()
1765 if (IS_ERR(video->reset)) { in npcm_video_probe()
1767 return PTR_ERR(video->reset); in npcm_video_probe()
1770 video->gcr_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in npcm_video_probe()
1772 if (IS_ERR(video->gcr_regmap)) in npcm_video_probe()
1773 return PTR_ERR(video->gcr_regmap); in npcm_video_probe()
1775 video->gfx_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in npcm_video_probe()
1777 if (IS_ERR(video->gfx_regmap)) in npcm_video_probe()
1778 return PTR_ERR(video->gfx_regmap); in npcm_video_probe()
1780 rc = npcm_video_init(video); in npcm_video_probe()
1784 rc = npcm_video_setup_video(video); in npcm_video_probe()
1788 dev_info(video->dev, "NPCM video driver probed\n"); in npcm_video_probe()
1796 struct npcm_video *video = to_npcm_video(v4l2_dev); in npcm_video_remove() local
1798 video_unregister_device(&video->vdev); in npcm_video_remove()
1799 vb2_queue_release(&video->queue); in npcm_video_remove()
1800 v4l2_ctrl_handler_free(&video->ctrl_handler); in npcm_video_remove()
1802 if (video->ece.enable) in npcm_video_remove()
1803 npcm_video_ece_stop(video); in npcm_video_remove()
1830 MODULE_DESCRIPTION("Driver for Nuvoton NPCM Video Capture/Encode Engine");