Lines Matching +full:npcm845 +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/clk.h>
15 #include <linux/dma-mapping.h>
30 #include <linux/v4l2-controls.h>
32 #include <media/v4l2-ctrls.h>
33 #include <media/v4l2-dev.h>
34 #include <media/v4l2-device.h>
35 #include <media/v4l2-dv-timings.h>
36 #include <media/v4l2-event.h>
37 #include <media/v4l2-ioctl.h>
38 #include <media/videobuf2-dma-contig.h>
39 #include <uapi/linux/npcm-video.h>
40 #include "npcm-regs.h"
42 #define DEVICE_NAME "npcm-video"
185 if (fmt->fourcc == f->fmt.pix.pixelformat) in npcm_video_find_format()
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()
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()
262 temp = FIELD_PREP(ECE_RECT_DIMEN_WLTR, w_size - 1) | in npcm_video_ece_enc_rect()
263 FIELD_PREP(ECE_RECT_DIMEN_HLTR, h_size - 1) | in npcm_video_ece_enc_rect()
264 FIELD_PREP(ECE_RECT_DIMEN_WR, w_tile - 1) | in npcm_video_ece_enc_rect()
265 FIELD_PREP(ECE_RECT_DIMEN_HR, h_tile - 1); in npcm_video_ece_enc_rect()
272 struct regmap *ece = video->ece.regmap; in npcm_video_ece_read_rect_offset()
285 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_lp()
314 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_fb_addr()
322 struct regmap *ece = video->ece.regmap; in npcm_video_ece_set_enc_dba()
329 struct regmap *ece = video->ece.regmap; in npcm_video_ece_clear_rect_offset()
336 struct regmap *ece = video->ece.regmap; in npcm_video_ece_ctrl_reset()
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()
360 struct regmap *ece = video->ece.regmap; in npcm_video_ece_stop()
371 addr->virt = dma_alloc_coherent(video->dev, VCD_FB_SIZE, &addr->dma, in npcm_video_alloc_fb()
373 if (!addr->virt) in npcm_video_alloc_fb()
376 addr->size = VCD_FB_SIZE; in npcm_video_alloc_fb()
383 dma_free_coherent(video->dev, addr->size, addr->virt, addr->dma); in npcm_video_free_fb()
384 addr->size = 0; in npcm_video_free_fb()
385 addr->dma = 0ULL; in npcm_video_free_fb()
386 addr->virt = NULL; in npcm_video_free_fb()
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()
399 list_del(&tmp->list); in npcm_video_free_diff_table()
410 struct list_head *head = &video->list[index]; in npcm_video_add_rect()
418 r = &list->clip.c; in npcm_video_add_rect()
419 r->left = x; in npcm_video_add_rect()
420 r->top = y; in npcm_video_add_rect()
421 r->width = w; in npcm_video_add_rect()
422 r->height = h; in npcm_video_add_rect()
424 list_add_tail(&list->list, head); in npcm_video_add_rect()
431 struct list_head *head = info->head; in npcm_video_merge_rect()
432 struct rect_list *list = info->list, *first = info->first; in npcm_video_merge_rect()
433 struct v4l2_rect *r = &list->clip.c, *f = &first->clip.c; in npcm_video_merge_rect()
437 info->first = first; in npcm_video_merge_rect()
438 list_add_tail(&list->list, head); in npcm_video_merge_rect()
439 video->rect_cnt++; in npcm_video_merge_rect()
441 if ((r->left == (f->left + f->width)) && r->top == f->top) { in npcm_video_merge_rect()
442 f->width += r->width; in npcm_video_merge_rect()
444 } else if ((r->top == (f->top + f->height)) && in npcm_video_merge_rect()
445 (r->left == f->left)) { in npcm_video_merge_rect()
446 f->height += r->height; in npcm_video_merge_rect()
448 } else if (((r->top > f->top) && in npcm_video_merge_rect()
449 (r->top < (f->top + f->height))) && in npcm_video_merge_rect()
450 ((r->left > f->left) && in npcm_video_merge_rect()
451 (r->left < (f->left + f->width)))) { in npcm_video_merge_rect()
454 list_add_tail(&list->list, head); in npcm_video_merge_rect()
455 video->rect_cnt++; in npcm_video_merge_rect()
456 info->first = list; in npcm_video_merge_rect()
465 struct v4l2_bt_timings *act = &video->active_timings; in npcm_video_new_rect()
473 r = &list->clip.c; in npcm_video_new_rect()
475 r->left = (offset << 4); in npcm_video_new_rect()
476 r->top = (index >> 2); in npcm_video_new_rect()
477 r->width = RECT_W; in npcm_video_new_rect()
478 r->height = RECT_H; in npcm_video_new_rect()
479 if ((r->left + RECT_W) > act->width) in npcm_video_new_rect()
480 r->width = act->width - r->left; in npcm_video_new_rect()
481 if ((r->top + RECT_H) > act->height) in npcm_video_new_rect()
482 r->height = act->height - r->top; in npcm_video_new_rect()
491 if (offset < info->tile_perline) { in npcm_video_find_rect()
492 info->list = npcm_video_new_rect(video, offset, info->index); in npcm_video_find_rect()
493 if (!info->list) { in npcm_video_find_rect()
494 dev_err(video->dev, "Failed to allocate rect_list\n"); in npcm_video_find_rect()
495 return -ENOMEM; in npcm_video_find_rect()
506 struct regmap *vcd = video->vcd_regmap; in npcm_video_build_table()
510 for (j = 0; j < info->offset_perline; j += 4) { in npcm_video_build_table()
511 regmap_read(vcd, VCD_DIFF_TBL + (j + info->index), &value); in npcm_video_build_table()
521 info->index += 64; in npcm_video_build_table()
522 return info->tile_perline; in npcm_video_build_table()
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()
535 info.tile_perline = act->width >> 4; in npcm_video_get_rect_list()
536 mod = act->width % RECT_W; in npcm_video_get_rect_list()
540 info.tile_perrow = act->height >> 4; in npcm_video_get_rect_list()
541 mod = act->height % RECT_H; in npcm_video_get_rect_list()
565 struct regmap *gfxi = video->gfx_regmap; in npcm_video_is_mga()
574 struct regmap *gfxi = video->gfx_regmap; in npcm_video_hres()
586 struct regmap *gfxi = video->gfx_regmap; in npcm_video_vres()
600 struct regmap *vcd = video->vcd_regmap; in npcm_video_capres()
604 return -EINVAL; in npcm_video_capres()
613 return -EINVAL; in npcm_video_capres()
624 reset_control_assert(video->reset); in npcm_video_vcd_ip_reset()
626 reset_control_deassert(video->reset); in npcm_video_vcd_ip_reset()
632 struct regmap *vcd = video->vcd_regmap; in npcm_video_vcd_state_machine_reset()
651 struct regmap *gcr = video->gcr_regmap; in npcm_video_gfx_reset()
660 struct regmap *vcd = video->vcd_regmap; in npcm_video_kvm_bw()
671 struct regmap *gfxi = video->gfx_regmap; in npcm_video_pclk()
703 if (fmt->fourcc == video->pix_fmt.pixelformat) in npcm_video_get_bpp()
707 return fmt->bpp; in npcm_video_get_bpp()
717 struct regmap *vcd = video->vcd_regmap; in npcm_video_set_linepitch()
729 struct regmap *vcd = video->vcd_regmap; in npcm_video_get_linepitch()
738 struct regmap *vcd = video->vcd_regmap; in npcm_video_command()
747 video->op_cmd = value; in npcm_video_command()
752 struct regmap *gcr = video->gcr_regmap, *vcd = video->vcd_regmap; in npcm_video_init_reg()
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()
796 return -EBUSY; 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()
826 npcm_video_command(video, video->ctrl_cmd); in npcm_video_start_frame()
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()
838 vb2_buffer_done(&buf->vb.vb2_buf, state); 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()
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()
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()
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()
870 if (act->width != det->width || act->height != det->height) { in npcm_video_detect_resolution()
871 dev_dbg(video->dev, "Resolution changed\n"); in npcm_video_detect_resolution()
874 if (test_bit(VIDEO_STREAMING, &video->flags)) { 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()
895 if (det->width && det->height) 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()
899 act->width, act->height, det->width, det->height, in npcm_video_detect_resolution()
900 video->v4l2_input_status); in npcm_video_detect_resolution()
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()
911 return -EINVAL; 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()
928 dev_dbg(video->dev, "VCD mode = 0x%x, %s mode\n", mode, 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()
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()
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()
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()
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()
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()
990 dev_dbg(video->dev, "ECE close: client %d\n", in npcm_video_stop()
991 atomic_read(&video->ece.clients)); in npcm_video_stop()
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()
1023 npcm_video_ece_set_fb_addr(video, video->src.dma); in npcm_video_hextile()
1028 npcm_video_ece_set_lp(video, video->bytesperline); in npcm_video_hextile()
1031 list_for_each_entry(rect_list, &video->list[index], list) { in npcm_video_hextile()
1032 rect = &rect_list->clip.c; in npcm_video_hextile()
1034 npcm_video_ece_enc_rect(video, rect->left, rect->top, in npcm_video_hextile()
1035 rect->width, rect->height); in npcm_video_hextile()
1039 rect->left, rect->top, in npcm_video_hextile()
1040 rect->width, rect->height); in npcm_video_hextile()
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()
1080 addr = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); in npcm_video_irq()
1081 index = buf->vb.vb2_buf.index; in npcm_video_irq()
1082 fmt = video->pix_fmt.pixelformat; in npcm_video_irq()
1089 dma_addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0); in npcm_video_irq()
1093 mutex_unlock(&video->buffer_lock); in npcm_video_irq()
1097 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size); in npcm_video_irq()
1098 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in npcm_video_irq()
1099 buf->vb.sequence = video->sequence++; in npcm_video_irq()
1100 buf->vb.field = V4L2_FIELD_NONE; in npcm_video_irq()
1102 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); in npcm_video_irq()
1103 list_del(&buf->link); in npcm_video_irq()
1104 mutex_unlock(&video->buffer_lock); 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()
1123 dev_err(video->dev, "Failed to recover from FIFO overrun\n"); in npcm_video_irq()
1132 strscpy(cap->driver, DEVICE_NAME, sizeof(cap->driver)); in npcm_video_querycap()
1133 strscpy(cap->card, "NPCM Video Engine", sizeof(cap->card)); in npcm_video_querycap()
1144 if (f->index >= NUM_FORMATS) in npcm_video_enum_format()
1145 return -EINVAL; in npcm_video_enum_format()
1147 fmt = &npcm_fmt_list[f->index]; in npcm_video_enum_format()
1148 if (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable) in npcm_video_enum_format()
1149 return -EINVAL; in npcm_video_enum_format()
1151 f->pixelformat = fmt->fourcc; in npcm_video_enum_format()
1164 if (!fmt || (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable)) in npcm_video_try_format()
1165 f->fmt.pix.pixelformat = npcm_fmt_list[0].fourcc; in npcm_video_try_format()
1167 f->fmt.pix.field = V4L2_FIELD_NONE; in npcm_video_try_format()
1168 f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; in npcm_video_try_format()
1169 f->fmt.pix.quantization = V4L2_QUANTIZATION_FULL_RANGE; 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()
1183 f->fmt.pix = video->pix_fmt; in npcm_video_get_format()
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()
1199 return -EBUSY; in npcm_video_set_format()
1202 video->pix_fmt.pixelformat = f->fmt.pix.pixelformat; in npcm_video_set_format()
1211 if (inp->index) in npcm_video_enum_input()
1212 return -EINVAL; in npcm_video_enum_input()
1214 strscpy(inp->name, "Host VGA capture", sizeof(inp->name)); in npcm_video_enum_input()
1215 inp->type = V4L2_INPUT_TYPE_CAMERA; in npcm_video_enum_input()
1216 inp->capabilities = V4L2_IN_CAP_DV_TIMINGS; in npcm_video_enum_input()
1217 inp->status = video->v4l2_input_status; in npcm_video_enum_input()
1232 return -EINVAL; in npcm_video_set_input()
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()
1249 return -EBUSY; in npcm_video_set_dv_timings()
1252 rc = npcm_video_set_resolution(video, &timings->bt); in npcm_video_set_dv_timings()
1256 timings->type = V4L2_DV_BT_656_1120; in npcm_video_set_dv_timings()
1266 timings->type = V4L2_DV_BT_656_1120; in npcm_video_get_dv_timings()
1267 timings->bt = video->active_timings; in npcm_video_get_dv_timings()
1278 timings->type = V4L2_DV_BT_656_1120; 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()
1302 switch (sub->type) { in npcm_video_sub_event()
1344 struct npcm_video *video = container_of(ctrl->handler, struct npcm_video, in npcm_video_set_ctrl()
1347 switch (ctrl->id) { in npcm_video_set_ctrl()
1349 if (ctrl->val == V4L2_NPCM_CAPTURE_MODE_COMPLETE) in npcm_video_set_ctrl()
1350 video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; in npcm_video_set_ctrl()
1351 else if (ctrl->val == V4L2_NPCM_CAPTURE_MODE_DIFF) in npcm_video_set_ctrl()
1352 video->ctrl_cmd = VCD_CMD_OPERATION_COMPARE; in npcm_video_set_ctrl()
1355 return -EINVAL; in npcm_video_set_ctrl()
1401 mutex_lock(&video->video_lock); in npcm_video_open()
1404 mutex_unlock(&video->video_lock); in npcm_video_open()
1411 mutex_unlock(&video->video_lock); in npcm_video_open()
1420 mutex_lock(&video->video_lock); in npcm_video_release()
1426 mutex_unlock(&video->video_lock); in npcm_video_release()
1448 if (sizes[0] < video->pix_fmt.sizeimage) in npcm_video_queue_setup()
1449 return -EINVAL; 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()
1467 if (vb2_plane_size(vb, 0) < video->pix_fmt.sizeimage) in npcm_video_buf_prepare()
1468 return -EINVAL; in npcm_video_buf_prepare()
1478 video->sequence = 0; in npcm_video_start_streaming()
1485 set_bit(VIDEO_STREAMING, &video->flags); in npcm_video_start_streaming()
1492 struct regmap *vcd = video->vcd_regmap; in npcm_video_stop_streaming()
1494 clear_bit(VIDEO_STREAMING, &video->flags); 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()
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()
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()
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()
1539 list_del(&tmp->list); in npcm_video_buf_finish()
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()
1606 vbq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in npcm_video_setup_video()
1607 vbq->io_modes = VB2_MMAP | VB2_DMABUF; in npcm_video_setup_video()
1608 vbq->dev = v4l2_dev->dev; in npcm_video_setup_video()
1609 vbq->lock = &video->video_lock; in npcm_video_setup_video()
1610 vbq->ops = &npcm_video_vb2_ops; in npcm_video_setup_video()
1611 vbq->mem_ops = &vb2_dma_contig_memops; in npcm_video_setup_video()
1612 vbq->drv_priv = video; in npcm_video_setup_video()
1613 vbq->buf_struct_size = sizeof(struct npcm_video_buffer); in npcm_video_setup_video()
1614 vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in npcm_video_setup_video()
1615 vbq->min_queued_buffers = 3; in npcm_video_setup_video()
1619 dev_err(video->dev, "Failed to init vb2 queue\n"); in npcm_video_setup_video()
1622 vdev->queue = vbq; in npcm_video_setup_video()
1623 vdev->fops = &npcm_video_v4l2_fops; in npcm_video_setup_video()
1624 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; in npcm_video_setup_video()
1625 vdev->v4l2_dev = v4l2_dev; in npcm_video_setup_video()
1626 strscpy(vdev->name, DEVICE_NAME, sizeof(vdev->name)); in npcm_video_setup_video()
1627 vdev->vfl_type = VFL_TYPE_VIDEO; in npcm_video_setup_video()
1628 vdev->vfl_dir = VFL_DIR_RX; in npcm_video_setup_video()
1629 vdev->release = video_device_release_empty; in npcm_video_setup_video()
1630 vdev->ioctl_ops = &npcm_video_ioctls; in npcm_video_setup_video()
1631 vdev->lock = &video->video_lock; 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()
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()
1661 return -ENODEV; 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()
1701 struct device *dev = video->dev; in npcm_video_init()
1704 irq = irq_of_parse_and_map(dev->of_node, 0); in npcm_video_init()
1707 return -ENODEV; in npcm_video_init()
1740 return -ENOMEM; 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()
1749 dev_err(&pdev->dev, "Failed to parse VCD reg in DTS\n"); 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()
1756 dev_err(&pdev->dev, "Failed to initialize VCD regmap\n"); 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()
1762 dev_err(&pdev->dev, "Failed to get VCD reset control in DTS\n"); 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()
1784 dev_info(video->dev, "NPCM video driver probed\n"); in npcm_video_probe()
1790 struct device *dev = &pdev->dev; in npcm_video_remove()
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()
1804 { .compatible = "nuvoton,npcm750-vcd" },
1805 { .compatible = "nuvoton,npcm845-vcd" },