Lines Matching full:video
3 * Driver for Video Capture/Differentiation Engine (VCD) and Encoding
39 #include <uapi/linux/npcm-video.h>
42 #define DEVICE_NAME "npcm-video"
68 * VIDEO_STREAMING: a flag indicating if the video has started streaming
71 * VIDEO_STOPPED: a flag indicating if the video has stopped streaming
210 static unsigned int npcm_video_ece_get_ed_size(struct npcm_video *video, in npcm_video_ece_get_ed_size() argument
213 struct regmap *ece = video->ece.regmap; in npcm_video_ece_get_ed_size()
222 dev_warn(video->dev, "Wait for ECE_DDA_STS_CDREADY timeout\n"); in npcm_video_ece_get_ed_size()
230 dev_dbg(video->dev, "offset = %u, ed_size = %u, gap = %u\n", offset, in npcm_video_ece_get_ed_size()
236 static void npcm_video_ece_enc_rect(struct npcm_video *video, in npcm_video_ece_enc_rect() argument
240 struct regmap *ece = video->ece.regmap; in npcm_video_ece_enc_rect()
241 unsigned int rect_offset = (r_off_y * video->bytesperline) + (r_off_x * 2); in npcm_video_ece_enc_rect()
270 static unsigned int npcm_video_ece_read_rect_offset(struct npcm_video *video) in npcm_video_ece_read_rect_offset() argument
272 struct regmap *ece = video->ece.regmap; in npcm_video_ece_read_rect_offset()
283 static void npcm_video_ece_set_lp(struct npcm_video *video, unsigned int pitch) in npcm_video_ece_set_lp() argument
285 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_lp()
311 static inline void npcm_video_ece_set_fb_addr(struct npcm_video *video, in npcm_video_ece_set_fb_addr() argument
314 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_fb_addr()
319 static inline void npcm_video_ece_set_enc_dba(struct npcm_video *video, in npcm_video_ece_set_enc_dba() argument
322 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_enc_dba()
327 static inline void npcm_video_ece_clear_rect_offset(struct npcm_video *video) in npcm_video_ece_clear_rect_offset() argument
329 struct regmap *ece = video->ece.regmap; in npcm_video_ece_clear_rect_offset()
334 static void npcm_video_ece_ctrl_reset(struct npcm_video *video) in npcm_video_ece_ctrl_reset() argument
336 struct regmap *ece = video->ece.regmap; in npcm_video_ece_ctrl_reset()
343 npcm_video_ece_clear_rect_offset(video); in npcm_video_ece_ctrl_reset()
346 static void npcm_video_ece_ip_reset(struct npcm_video *video) in npcm_video_ece_ip_reset() argument
352 reset_control_assert(video->ece.reset); in npcm_video_ece_ip_reset()
354 reset_control_deassert(video->ece.reset); in npcm_video_ece_ip_reset()
358 static void npcm_video_ece_stop(struct npcm_video *video) in npcm_video_ece_stop() argument
360 struct regmap *ece = video->ece.regmap; in npcm_video_ece_stop()
365 npcm_video_ece_clear_rect_offset(video); in npcm_video_ece_stop()
368 static bool npcm_video_alloc_fb(struct npcm_video *video, in npcm_video_alloc_fb() argument
371 addr->virt = dma_alloc_coherent(video->dev, VCD_FB_SIZE, &addr->dma, in npcm_video_alloc_fb()
380 static void npcm_video_free_fb(struct npcm_video *video, in npcm_video_free_fb() argument
383 dma_free_coherent(video->dev, addr->size, addr->virt, addr->dma); in npcm_video_free_fb()
389 static void npcm_video_free_diff_table(struct npcm_video *video) in npcm_video_free_diff_table() argument
395 for (i = 0; i < vb2_get_num_buffers(&video->queue); i++) { in npcm_video_free_diff_table()
396 head = &video->list[i]; in npcm_video_free_diff_table()
405 static unsigned int npcm_video_add_rect(struct npcm_video *video, in npcm_video_add_rect() argument
410 struct list_head *head = &video->list[index]; in npcm_video_add_rect()
428 static void npcm_video_merge_rect(struct npcm_video *video, in npcm_video_merge_rect() argument
439 video->rect_cnt++; in npcm_video_merge_rect()
455 video->rect_cnt++; in npcm_video_merge_rect()
461 static struct rect_list *npcm_video_new_rect(struct npcm_video *video, in npcm_video_new_rect() argument
465 struct v4l2_bt_timings *act = &video->active_timings; in npcm_video_new_rect()
487 static int npcm_video_find_rect(struct npcm_video *video, in npcm_video_find_rect() argument
492 info->list = npcm_video_new_rect(video, offset, info->index); in npcm_video_find_rect()
494 dev_err(video->dev, "Failed to allocate rect_list\n"); in npcm_video_find_rect()
498 npcm_video_merge_rect(video, info); in npcm_video_find_rect()
503 static int npcm_video_build_table(struct npcm_video *video, in npcm_video_build_table() argument
506 struct regmap *vcd = video->vcd_regmap; in npcm_video_build_table()
516 ret = npcm_video_find_rect(video, info, bit + (j << 3)); in npcm_video_build_table()
525 static void npcm_video_get_rect_list(struct npcm_video *video, unsigned int index) in npcm_video_get_rect_list() argument
527 struct v4l2_bt_timings *act = &video->active_timings; in npcm_video_get_rect_list()
533 info.head = &video->list[index]; in npcm_video_get_rect_list()
555 ret = npcm_video_build_table(video, &info); in npcm_video_get_rect_list()
563 static unsigned int npcm_video_is_mga(struct npcm_video *video) in npcm_video_is_mga() argument
565 struct regmap *gfxi = video->gfx_regmap; in npcm_video_is_mga()
572 static unsigned int npcm_video_hres(struct npcm_video *video) in npcm_video_hres() argument
574 struct regmap *gfxi = video->gfx_regmap; in npcm_video_hres()
584 static unsigned int npcm_video_vres(struct npcm_video *video) in npcm_video_vres() argument
586 struct regmap *gfxi = video->gfx_regmap; in npcm_video_vres()
597 static int npcm_video_capres(struct npcm_video *video, unsigned int hor_res, in npcm_video_capres() argument
600 struct regmap *vcd = video->vcd_regmap; in npcm_video_capres()
618 static void npcm_video_vcd_ip_reset(struct npcm_video *video) in npcm_video_vcd_ip_reset() argument
624 reset_control_assert(video->reset); in npcm_video_vcd_ip_reset()
626 reset_control_deassert(video->reset); in npcm_video_vcd_ip_reset()
630 static void npcm_video_vcd_state_machine_reset(struct npcm_video *video) in npcm_video_vcd_state_machine_reset() argument
632 struct regmap *vcd = video->vcd_regmap; in npcm_video_vcd_state_machine_reset()
649 static void npcm_video_gfx_reset(struct npcm_video *video) in npcm_video_gfx_reset() argument
651 struct regmap *gcr = video->gcr_regmap; in npcm_video_gfx_reset()
654 npcm_video_vcd_state_machine_reset(video); in npcm_video_gfx_reset()
658 static void npcm_video_kvm_bw(struct npcm_video *video, bool set_bw) in npcm_video_kvm_bw() argument
660 struct regmap *vcd = video->vcd_regmap; in npcm_video_kvm_bw()
662 if (set_bw || !npcm_video_is_mga(video)) in npcm_video_kvm_bw()
669 static unsigned int npcm_video_pclk(struct npcm_video *video) in npcm_video_pclk() argument
671 struct regmap *gfxi = video->gfx_regmap; in npcm_video_pclk()
696 static unsigned int npcm_video_get_bpp(struct npcm_video *video) in npcm_video_get_bpp() argument
703 if (fmt->fourcc == video->pix_fmt.pixelformat) in npcm_video_get_bpp()
714 static void npcm_video_set_linepitch(struct npcm_video *video, in npcm_video_set_linepitch() argument
717 struct regmap *vcd = video->vcd_regmap; in npcm_video_set_linepitch()
727 static unsigned int npcm_video_get_linepitch(struct npcm_video *video) in npcm_video_get_linepitch() argument
729 struct regmap *vcd = video->vcd_regmap; in npcm_video_get_linepitch()
736 static void npcm_video_command(struct npcm_video *video, unsigned int value) in npcm_video_command() argument
738 struct regmap *vcd = video->vcd_regmap; in npcm_video_command()
747 video->op_cmd = value; in npcm_video_command()
750 static void npcm_video_init_reg(struct npcm_video *video) in npcm_video_init_reg() argument
752 struct regmap *gcr = video->gcr_regmap, *vcd = video->vcd_regmap; in npcm_video_init_reg()
764 /* Reset video modules */ in npcm_video_init_reg()
765 npcm_video_vcd_ip_reset(video); in npcm_video_init_reg()
766 npcm_video_gfx_reset(video); in npcm_video_init_reg()
775 /* Set video mode */ in npcm_video_init_reg()
780 static int npcm_video_start_frame(struct npcm_video *video) in npcm_video_start_frame() argument
783 struct regmap *vcd = video->vcd_regmap; in npcm_video_start_frame()
787 if (video->v4l2_input_status) { in npcm_video_start_frame()
788 dev_dbg(video->dev, "No video signal; skip capture frame\n"); in npcm_video_start_frame()
795 dev_err(video->dev, "Wait for VCD_STAT_BUSY timeout\n"); in npcm_video_start_frame()
799 mutex_lock(&video->buffer_lock); in npcm_video_start_frame()
800 buf = list_first_entry_or_null(&video->buffers, in npcm_video_start_frame()
803 mutex_unlock(&video->buffer_lock); in npcm_video_start_frame()
804 dev_dbg(video->dev, "No empty buffers; skip capture frame\n"); in npcm_video_start_frame()
808 set_bit(VIDEO_CAPTURING, &video->flags); in npcm_video_start_frame()
809 mutex_unlock(&video->buffer_lock); in npcm_video_start_frame()
811 npcm_video_vcd_state_machine_reset(video); in npcm_video_start_frame()
826 npcm_video_command(video, video->ctrl_cmd); in npcm_video_start_frame()
831 static void npcm_video_bufs_done(struct npcm_video *video, in npcm_video_bufs_done() argument
836 mutex_lock(&video->buffer_lock); in npcm_video_bufs_done()
837 list_for_each_entry(buf, &video->buffers, link) in npcm_video_bufs_done()
840 INIT_LIST_HEAD(&video->buffers); in npcm_video_bufs_done()
841 mutex_unlock(&video->buffer_lock); in npcm_video_bufs_done()
844 static void npcm_video_get_diff_rect(struct npcm_video *video, unsigned int index) in npcm_video_get_diff_rect() argument
846 unsigned int width = video->active_timings.width; in npcm_video_get_diff_rect()
847 unsigned int height = video->active_timings.height; in npcm_video_get_diff_rect()
849 if (video->op_cmd != VCD_CMD_OPERATION_CAPTURE) { in npcm_video_get_diff_rect()
850 video->rect_cnt = 0; in npcm_video_get_diff_rect()
851 npcm_video_get_rect_list(video, index); in npcm_video_get_diff_rect()
852 video->rect[index] = video->rect_cnt; in npcm_video_get_diff_rect()
854 video->rect[index] = npcm_video_add_rect(video, index, 0, 0, in npcm_video_get_diff_rect()
859 static void npcm_video_detect_resolution(struct npcm_video *video) in npcm_video_detect_resolution() argument
861 struct v4l2_bt_timings *act = &video->active_timings; in npcm_video_detect_resolution()
862 struct v4l2_bt_timings *det = &video->detected_timings; in npcm_video_detect_resolution()
863 struct regmap *gfxi = video->gfx_regmap; in npcm_video_detect_resolution()
866 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in npcm_video_detect_resolution()
867 det->width = npcm_video_hres(video); in npcm_video_detect_resolution()
868 det->height = npcm_video_vres(video); in npcm_video_detect_resolution()
871 dev_dbg(video->dev, "Resolution changed\n"); in npcm_video_detect_resolution()
873 if (npcm_video_hres(video) > 0 && npcm_video_vres(video) > 0) { in npcm_video_detect_resolution()
874 if (test_bit(VIDEO_STREAMING, &video->flags)) { in npcm_video_detect_resolution()
882 } while (npcm_video_vres(video) < 100 || in npcm_video_detect_resolution()
883 npcm_video_pclk(video) == 0 || in npcm_video_detect_resolution()
887 det->width = npcm_video_hres(video); in npcm_video_detect_resolution()
888 det->height = npcm_video_vres(video); in npcm_video_detect_resolution()
889 det->pixelclock = npcm_video_pclk(video); in npcm_video_detect_resolution()
892 clear_bit(VIDEO_RES_CHANGING, &video->flags); in npcm_video_detect_resolution()
896 video->v4l2_input_status = 0; in npcm_video_detect_resolution()
898 dev_dbg(video->dev, "Got resolution[%dx%d] -> [%dx%d], status %d\n", in npcm_video_detect_resolution()
900 video->v4l2_input_status); in npcm_video_detect_resolution()
903 static int npcm_video_set_resolution(struct npcm_video *video, in npcm_video_set_resolution() argument
906 struct regmap *vcd = video->vcd_regmap; in npcm_video_set_resolution()
909 if (npcm_video_capres(video, timing->width, timing->height)) { in npcm_video_set_resolution()
910 dev_err(video->dev, "Failed to set VCD_CAP_RES\n"); in npcm_video_set_resolution()
914 video->active_timings = *timing; in npcm_video_set_resolution()
915 video->bytesperpixel = npcm_video_get_bpp(video); in npcm_video_set_resolution()
916 npcm_video_set_linepitch(video, timing->width * video->bytesperpixel); in npcm_video_set_resolution()
917 video->bytesperline = npcm_video_get_linepitch(video); in npcm_video_set_resolution()
918 video->pix_fmt.width = timing->width ? timing->width : MIN_WIDTH; in npcm_video_set_resolution()
919 video->pix_fmt.height = timing->height ? timing->height : MIN_HEIGHT; in npcm_video_set_resolution()
920 video->pix_fmt.sizeimage = video->pix_fmt.width * video->pix_fmt.height * in npcm_video_set_resolution()
921 video->bytesperpixel; in npcm_video_set_resolution()
922 video->pix_fmt.bytesperline = video->bytesperline; in npcm_video_set_resolution()
924 npcm_video_kvm_bw(video, timing->pixelclock > VCD_KVM_BW_PCLK); in npcm_video_set_resolution()
925 npcm_video_gfx_reset(video); in npcm_video_set_resolution()
928 dev_dbg(video->dev, "VCD mode = 0x%x, %s mode\n", mode, in npcm_video_set_resolution()
929 npcm_video_is_mga(video) ? "Hi Res" : "VGA"); in npcm_video_set_resolution()
931 dev_dbg(video->dev, in npcm_video_set_resolution()
933 timing->width, timing->height, video->bytesperpixel, in npcm_video_set_resolution()
934 timing->pixelclock, video->bytesperline); in npcm_video_set_resolution()
939 static void npcm_video_start(struct npcm_video *video) in npcm_video_start() argument
941 npcm_video_init_reg(video); in npcm_video_start()
943 if (!npcm_video_alloc_fb(video, &video->src)) { in npcm_video_start()
944 dev_err(video->dev, "Failed to allocate VCD frame buffer\n"); in npcm_video_start()
948 npcm_video_detect_resolution(video); in npcm_video_start()
949 if (npcm_video_set_resolution(video, &video->detected_timings)) { in npcm_video_start()
950 dev_err(video->dev, "Failed to set resolution\n"); in npcm_video_start()
955 regmap_write(video->vcd_regmap, VCD_FBA_ADR, video->src.dma); in npcm_video_start()
956 regmap_write(video->vcd_regmap, VCD_FBB_ADR, video->src.dma); in npcm_video_start()
958 if (video->ece.enable && atomic_inc_return(&video->ece.clients) == 1) { in npcm_video_start()
959 npcm_video_ece_ip_reset(video); in npcm_video_start()
960 npcm_video_ece_ctrl_reset(video); in npcm_video_start()
961 npcm_video_ece_set_fb_addr(video, video->src.dma); in npcm_video_start()
962 npcm_video_ece_set_lp(video, video->bytesperline); in npcm_video_start()
964 dev_dbg(video->dev, "ECE open: client %d\n", in npcm_video_start()
965 atomic_read(&video->ece.clients)); in npcm_video_start()
969 static void npcm_video_stop(struct npcm_video *video) in npcm_video_stop() argument
971 struct regmap *vcd = video->vcd_regmap; in npcm_video_stop()
973 set_bit(VIDEO_STOPPED, &video->flags); in npcm_video_stop()
980 if (video->src.size) in npcm_video_stop()
981 npcm_video_free_fb(video, &video->src); in npcm_video_stop()
983 npcm_video_free_diff_table(video); in npcm_video_stop()
984 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in npcm_video_stop()
985 video->flags = 0; in npcm_video_stop()
986 video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; in npcm_video_stop()
988 if (video->ece.enable && atomic_dec_return(&video->ece.clients) == 0) { in npcm_video_stop()
989 npcm_video_ece_stop(video); in npcm_video_stop()
990 dev_dbg(video->dev, "ECE close: client %d\n", in npcm_video_stop()
991 atomic_read(&video->ece.clients)); in npcm_video_stop()
995 static unsigned int npcm_video_raw(struct npcm_video *video, int index, void *addr) in npcm_video_raw() argument
997 unsigned int width = video->active_timings.width; in npcm_video_raw()
998 unsigned int height = video->active_timings.height; in npcm_video_raw()
1001 video->rect[index] = npcm_video_add_rect(video, index, 0, 0, width, height); in npcm_video_raw()
1004 len = width * video->bytesperpixel; in npcm_video_raw()
1005 offset = i * video->bytesperline; in npcm_video_raw()
1007 memcpy(addr + bytes, video->src.virt + offset, len); in npcm_video_raw()
1014 static unsigned int npcm_video_hextile(struct npcm_video *video, unsigned int index, in npcm_video_hextile() argument
1021 npcm_video_ece_ctrl_reset(video); in npcm_video_hextile()
1022 npcm_video_ece_clear_rect_offset(video); in npcm_video_hextile()
1023 npcm_video_ece_set_fb_addr(video, video->src.dma); in npcm_video_hextile()
1025 /* Set base address of encoded data to video buffer */ in npcm_video_hextile()
1026 npcm_video_ece_set_enc_dba(video, dma_addr); in npcm_video_hextile()
1028 npcm_video_ece_set_lp(video, video->bytesperline); in npcm_video_hextile()
1029 npcm_video_get_diff_rect(video, index); in npcm_video_hextile()
1031 list_for_each_entry(rect_list, &video->list[index], list) { in npcm_video_hextile()
1033 offset = npcm_video_ece_read_rect_offset(video); in npcm_video_hextile()
1034 npcm_video_ece_enc_rect(video, rect->left, rect->top, in npcm_video_hextile()
1037 len = npcm_video_ece_get_ed_size(video, offset, vaddr); in npcm_video_hextile()
1049 struct npcm_video *video = arg; in npcm_video_irq() local
1050 struct regmap *vcd = video->vcd_regmap; in npcm_video_irq()
1061 dev_dbg(video->dev, "VCD irq status 0x%x\n", status); in npcm_video_irq()
1065 if (test_bit(VIDEO_STOPPED, &video->flags) || in npcm_video_irq()
1066 !test_bit(VIDEO_STREAMING, &video->flags)) in npcm_video_irq()
1071 mutex_lock(&video->buffer_lock); in npcm_video_irq()
1072 clear_bit(VIDEO_CAPTURING, &video->flags); in npcm_video_irq()
1073 buf = list_first_entry_or_null(&video->buffers, in npcm_video_irq()
1076 mutex_unlock(&video->buffer_lock); in npcm_video_irq()
1082 fmt = video->pix_fmt.pixelformat; in npcm_video_irq()
1086 size = npcm_video_raw(video, index, addr); in npcm_video_irq()
1090 size = npcm_video_hextile(video, index, dma_addr, addr); in npcm_video_irq()
1093 mutex_unlock(&video->buffer_lock); in npcm_video_irq()
1099 buf->vb.sequence = video->sequence++; in npcm_video_irq()
1104 mutex_unlock(&video->buffer_lock); in npcm_video_irq()
1106 if (npcm_video_start_frame(video)) in npcm_video_irq()
1107 dev_err(video->dev, "Failed to capture next frame\n"); in npcm_video_irq()
1112 if (!test_bit(VIDEO_RES_CHANGING, &video->flags)) { in npcm_video_irq()
1113 set_bit(VIDEO_RES_CHANGING, &video->flags); in npcm_video_irq()
1115 vb2_queue_error(&video->queue); in npcm_video_irq()
1116 v4l2_event_queue(&video->vdev, &ev); in npcm_video_irq()
1121 dev_warn(video->dev, "VCD FIFO overrun or over thresholds\n"); in npcm_video_irq()
1122 if (npcm_video_start_frame(video)) in npcm_video_irq()
1123 dev_err(video->dev, "Failed to recover from FIFO overrun\n"); in npcm_video_irq()
1133 strscpy(cap->card, "NPCM Video Engine", sizeof(cap->card)); in npcm_video_querycap()
1141 struct npcm_video *video = video_drvdata(file); in npcm_video_enum_format() local
1148 if (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable) in npcm_video_enum_format()
1158 struct npcm_video *video = video_drvdata(file); in npcm_video_try_format() local
1164 if (!fmt || (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable)) in npcm_video_try_format()
1170 f->fmt.pix.width = video->pix_fmt.width; in npcm_video_try_format()
1171 f->fmt.pix.height = video->pix_fmt.height; in npcm_video_try_format()
1172 f->fmt.pix.bytesperline = video->bytesperline; in npcm_video_try_format()
1173 f->fmt.pix.sizeimage = video->pix_fmt.sizeimage; in npcm_video_try_format()
1181 struct npcm_video *video = video_drvdata(file); in npcm_video_get_format() local
1183 f->fmt.pix = video->pix_fmt; in npcm_video_get_format()
1190 struct npcm_video *video = video_drvdata(file); in npcm_video_set_format() local
1197 if (vb2_is_busy(&video->queue)) { in npcm_video_set_format()
1198 dev_err(video->dev, "%s device busy\n", __func__); in npcm_video_set_format()
1202 video->pix_fmt.pixelformat = f->fmt.pix.pixelformat; in npcm_video_set_format()
1209 struct npcm_video *video = video_drvdata(file); in npcm_video_enum_input() local
1217 inp->status = video->v4l2_input_status; in npcm_video_enum_input()
1240 struct npcm_video *video = video_drvdata(file); in npcm_video_set_dv_timings() local
1243 if (timings->bt.width == video->active_timings.width && in npcm_video_set_dv_timings()
1244 timings->bt.height == video->active_timings.height) in npcm_video_set_dv_timings()
1247 if (vb2_is_busy(&video->queue)) { in npcm_video_set_dv_timings()
1248 dev_err(video->dev, "%s device busy\n", __func__); in npcm_video_set_dv_timings()
1252 rc = npcm_video_set_resolution(video, &timings->bt); in npcm_video_set_dv_timings()
1264 struct npcm_video *video = video_drvdata(file); in npcm_video_get_dv_timings() local
1267 timings->bt = video->active_timings; in npcm_video_get_dv_timings()
1275 struct npcm_video *video = video_drvdata(file); in npcm_video_query_dv_timings() local
1277 npcm_video_detect_resolution(video); in npcm_video_query_dv_timings()
1279 timings->bt = video->detected_timings; in npcm_video_query_dv_timings()
1281 return video->v4l2_input_status ? -ENOLINK : 0; in npcm_video_query_dv_timings()
1344 struct npcm_video *video = container_of(ctrl->handler, struct npcm_video, in npcm_video_set_ctrl() local
1350 video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; in npcm_video_set_ctrl()
1352 video->ctrl_cmd = VCD_CMD_OPERATION_COMPARE; in npcm_video_set_ctrl()
1374 .name = "NPCM Video Capture Mode",
1398 struct npcm_video *video = video_drvdata(file); in npcm_video_open() local
1401 mutex_lock(&video->video_lock); in npcm_video_open()
1404 mutex_unlock(&video->video_lock); in npcm_video_open()
1409 npcm_video_start(video); in npcm_video_open()
1411 mutex_unlock(&video->video_lock); in npcm_video_open()
1417 struct npcm_video *video = video_drvdata(file); in npcm_video_release() local
1420 mutex_lock(&video->video_lock); in npcm_video_release()
1422 npcm_video_stop(video); in npcm_video_release()
1426 mutex_unlock(&video->video_lock); in npcm_video_release()
1444 struct npcm_video *video = vb2_get_drv_priv(q); in npcm_video_queue_setup() local
1448 if (sizes[0] < video->pix_fmt.sizeimage) in npcm_video_queue_setup()
1455 sizes[0] = video->pix_fmt.sizeimage; in npcm_video_queue_setup()
1458 INIT_LIST_HEAD(&video->list[i]); in npcm_video_queue_setup()
1465 struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); in npcm_video_buf_prepare() local
1467 if (vb2_plane_size(vb, 0) < video->pix_fmt.sizeimage) in npcm_video_buf_prepare()
1475 struct npcm_video *video = vb2_get_drv_priv(q); in npcm_video_start_streaming() local
1478 video->sequence = 0; in npcm_video_start_streaming()
1479 rc = npcm_video_start_frame(video); in npcm_video_start_streaming()
1481 npcm_video_bufs_done(video, VB2_BUF_STATE_QUEUED); in npcm_video_start_streaming()
1485 set_bit(VIDEO_STREAMING, &video->flags); in npcm_video_start_streaming()
1491 struct npcm_video *video = vb2_get_drv_priv(q); in npcm_video_stop_streaming() local
1492 struct regmap *vcd = video->vcd_regmap; in npcm_video_stop_streaming()
1494 clear_bit(VIDEO_STREAMING, &video->flags); in npcm_video_stop_streaming()
1497 npcm_video_gfx_reset(video); in npcm_video_stop_streaming()
1498 npcm_video_bufs_done(video, VB2_BUF_STATE_ERROR); in npcm_video_stop_streaming()
1499 video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; in npcm_video_stop_streaming()
1500 v4l2_ctrl_s_ctrl(video->rect_cnt_ctrl, 0); in npcm_video_stop_streaming()
1505 struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); in npcm_video_buf_queue() local
1510 mutex_lock(&video->buffer_lock); in npcm_video_buf_queue()
1511 empty = list_empty(&video->buffers); in npcm_video_buf_queue()
1512 list_add_tail(&nvb->link, &video->buffers); in npcm_video_buf_queue()
1513 mutex_unlock(&video->buffer_lock); in npcm_video_buf_queue()
1515 if (test_bit(VIDEO_STREAMING, &video->flags) && in npcm_video_buf_queue()
1516 !test_bit(VIDEO_CAPTURING, &video->flags) && empty) { in npcm_video_buf_queue()
1517 if (npcm_video_start_frame(video)) in npcm_video_buf_queue()
1518 dev_err(video->dev, "Failed to capture next frame\n"); in npcm_video_buf_queue()
1524 struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); in npcm_video_buf_finish() local
1533 if (test_bit(VIDEO_STREAMING, &video->flags)) { in npcm_video_buf_finish()
1534 v4l2_ctrl_s_ctrl(video->rect_cnt_ctrl, video->rect[vb->index]); in npcm_video_buf_finish()
1536 head = &video->list[vb->index]; in npcm_video_buf_finish()
1570 static int npcm_video_setup_video(struct npcm_video *video) in npcm_video_setup_video() argument
1572 struct v4l2_device *v4l2_dev = &video->v4l2_dev; in npcm_video_setup_video()
1573 struct video_device *vdev = &video->vdev; in npcm_video_setup_video()
1574 struct vb2_queue *vbq = &video->queue; in npcm_video_setup_video()
1577 if (video->ece.enable) in npcm_video_setup_video()
1578 video->pix_fmt.pixelformat = V4L2_PIX_FMT_HEXTILE; in npcm_video_setup_video()
1580 video->pix_fmt.pixelformat = V4L2_PIX_FMT_RGB565; in npcm_video_setup_video()
1582 video->pix_fmt.field = V4L2_FIELD_NONE; in npcm_video_setup_video()
1583 video->pix_fmt.colorspace = V4L2_COLORSPACE_SRGB; in npcm_video_setup_video()
1584 video->pix_fmt.quantization = V4L2_QUANTIZATION_FULL_RANGE; in npcm_video_setup_video()
1585 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in npcm_video_setup_video()
1587 rc = v4l2_device_register(video->dev, v4l2_dev); in npcm_video_setup_video()
1589 dev_err(video->dev, "Failed to register v4l2 device\n"); in npcm_video_setup_video()
1593 v4l2_ctrl_handler_init(&video->ctrl_handler, 2); in npcm_video_setup_video()
1594 v4l2_ctrl_new_custom(&video->ctrl_handler, &npcm_ctrl_capture_mode, NULL); in npcm_video_setup_video()
1595 video->rect_cnt_ctrl = v4l2_ctrl_new_custom(&video->ctrl_handler, in npcm_video_setup_video()
1597 if (video->ctrl_handler.error) { in npcm_video_setup_video()
1598 dev_err(video->dev, "Failed to init controls: %d\n", in npcm_video_setup_video()
1599 video->ctrl_handler.error); in npcm_video_setup_video()
1601 rc = video->ctrl_handler.error; in npcm_video_setup_video()
1604 v4l2_dev->ctrl_handler = &video->ctrl_handler; in npcm_video_setup_video()
1609 vbq->lock = &video->video_lock; in npcm_video_setup_video()
1612 vbq->drv_priv = video; in npcm_video_setup_video()
1619 dev_err(video->dev, "Failed to init vb2 queue\n"); in npcm_video_setup_video()
1631 vdev->lock = &video->video_lock; in npcm_video_setup_video()
1633 video_set_drvdata(vdev, video); in npcm_video_setup_video()
1636 dev_err(video->dev, "Failed to register video device\n"); in npcm_video_setup_video()
1645 v4l2_ctrl_handler_free(&video->ctrl_handler); in npcm_video_setup_video()
1651 static int npcm_video_ece_init(struct npcm_video *video) in npcm_video_ece_init() argument
1653 struct device *dev = video->dev; in npcm_video_ece_init()
1658 ece_node = of_parse_phandle(video->dev->of_node, "nuvoton,ece", 0); in npcm_video_ece_init()
1664 video->ece.enable = of_device_is_available(ece_node); in npcm_video_ece_init()
1666 if (video->ece.enable) { in npcm_video_ece_init()
1682 video->ece.regmap = devm_regmap_init_mmio(dev, regs, in npcm_video_ece_init()
1684 if (IS_ERR(video->ece.regmap)) { in npcm_video_ece_init()
1686 return PTR_ERR(video->ece.regmap); in npcm_video_ece_init()
1689 video->ece.reset = devm_reset_control_get(&ece_pdev->dev, NULL); in npcm_video_ece_init()
1690 if (IS_ERR(video->ece.reset)) { in npcm_video_ece_init()
1692 return PTR_ERR(video->ece.reset); in npcm_video_ece_init()
1699 static int npcm_video_init(struct npcm_video *video) in npcm_video_init() argument
1701 struct device *dev = video->dev; in npcm_video_init()
1711 IRQF_ONESHOT, DEVICE_NAME, video); in npcm_video_init()
1724 rc = npcm_video_ece_init(video); in npcm_video_init()
1735 struct npcm_video *video = kzalloc(sizeof(*video), GFP_KERNEL); in npcm_video_probe() local
1739 if (!video) in npcm_video_probe()
1742 video->dev = &pdev->dev; in npcm_video_probe()
1743 mutex_init(&video->video_lock); in npcm_video_probe()
1744 mutex_init(&video->buffer_lock); in npcm_video_probe()
1745 INIT_LIST_HEAD(&video->buffers); in npcm_video_probe()
1753 video->vcd_regmap = devm_regmap_init_mmio(&pdev->dev, regs, in npcm_video_probe()
1755 if (IS_ERR(video->vcd_regmap)) { in npcm_video_probe()
1757 return PTR_ERR(video->vcd_regmap); in npcm_video_probe()
1760 video->reset = devm_reset_control_get(&pdev->dev, NULL); in npcm_video_probe()
1761 if (IS_ERR(video->reset)) { in npcm_video_probe()
1763 return PTR_ERR(video->reset); in npcm_video_probe()
1766 video->gcr_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in npcm_video_probe()
1768 if (IS_ERR(video->gcr_regmap)) in npcm_video_probe()
1769 return PTR_ERR(video->gcr_regmap); in npcm_video_probe()
1771 video->gfx_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in npcm_video_probe()
1773 if (IS_ERR(video->gfx_regmap)) in npcm_video_probe()
1774 return PTR_ERR(video->gfx_regmap); in npcm_video_probe()
1776 rc = npcm_video_init(video); in npcm_video_probe()
1780 rc = npcm_video_setup_video(video); in npcm_video_probe()
1784 dev_info(video->dev, "NPCM video driver probed\n"); in npcm_video_probe()
1792 struct npcm_video *video = to_npcm_video(v4l2_dev); in npcm_video_remove() local
1794 video_unregister_device(&video->vdev); in npcm_video_remove()
1795 vb2_queue_release(&video->queue); in npcm_video_remove()
1796 v4l2_ctrl_handler_free(&video->ctrl_handler); in npcm_video_remove()
1798 if (video->ece.enable) in npcm_video_remove()
1799 npcm_video_ece_stop(video); in npcm_video_remove()
1824 MODULE_DESCRIPTION("Driver for Nuvoton NPCM Video Capture/Encode Engine");