Lines Matching +full:reg +full:- +full:spacing

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 // Copyright (c) 2019-2020 Intel Corporation
10 #include <linux/dma-mapping.h>
23 #include <linux/v4l2-controls.h>
29 #include <media/v4l2-ctrls.h>
30 #include <media/v4l2-dev.h>
31 #include <media/v4l2-device.h>
32 #include <media/v4l2-dv-timings.h>
33 #include <media/v4l2-event.h>
34 #include <media/v4l2-ioctl.h>
35 #include <media/videobuf2-dma-contig.h>
39 #define DEVICE_NAME "aspeed-video"
197 * VIDEO_RES_CHANGE: a flag raised if res_change work on-going
198 * VIDEO_RES_DETECT: a flag raised if res. detection on-going
199 * VIDEO_STREAMING: a flag raised if user requires stream-on
246 * struct aspeed_video - driver data
248 * res_work: holds the delayed_work for res-detection if unlock
469 base = 256 * i; /* AST HW requires this header spacing */ in aspeed_video_init_jpeg_table()
493 base = 256 * i; /* AST HW requires this header spacing */ in aspeed_video_update_jpeg_table()
501 static void aspeed_video_update(struct aspeed_video *video, u32 reg, u32 clear, in aspeed_video_update() argument
504 u32 t = readl(video->base + reg); in aspeed_video_update()
509 writel(t, video->base + reg); in aspeed_video_update()
510 v4l2_dbg(3, debug, &video->v4l2_dev, "update %03x[%08x -> %08x]\n", in aspeed_video_update()
511 reg, before, readl(video->base + reg)); in aspeed_video_update()
514 static u32 aspeed_video_read(struct aspeed_video *video, u32 reg) in aspeed_video_read() argument
516 u32 t = readl(video->base + reg); in aspeed_video_read()
518 v4l2_dbg(3, debug, &video->v4l2_dev, "read %03x[%08x]\n", reg, t); in aspeed_video_read()
522 static void aspeed_video_write(struct aspeed_video *video, u32 reg, u32 val) in aspeed_video_write() argument
524 writel(val, video->base + reg); in aspeed_video_write()
525 v4l2_dbg(3, debug, &video->v4l2_dev, "write %03x[%08x]\n", reg, in aspeed_video_write()
526 readl(video->base + reg)); in aspeed_video_write()
534 p->duration = in update_perf()
535 ktime_to_ms(ktime_sub(ktime_get(), p->last_sample)); in update_perf()
536 p->totaltime += p->duration; in update_perf()
538 p->duration_max = max(p->duration, p->duration_max); in update_perf()
539 p->duration_min = min(p->duration, p->duration_min); in update_perf()
540 v4l2_dbg(2, debug, &v->v4l2_dev, "time consumed: %d ms\n", in update_perf()
541 p->duration); in update_perf()
551 if (video->v4l2_input_status) { in aspeed_video_start_frame()
552 v4l2_warn(&video->v4l2_dev, "No signal; don't start frame\n"); in aspeed_video_start_frame()
558 v4l2_warn(&video->v4l2_dev, "Engine busy; don't start frame\n"); in aspeed_video_start_frame()
559 return -EBUSY; in aspeed_video_start_frame()
562 spin_lock_irqsave(&video->lock, flags); in aspeed_video_start_frame()
563 buf = list_first_entry_or_null(&video->buffers, in aspeed_video_start_frame()
566 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_start_frame()
567 v4l2_warn(&video->v4l2_dev, "No buffers; don't start frame\n"); in aspeed_video_start_frame()
568 return -EPROTO; in aspeed_video_start_frame()
571 set_bit(VIDEO_FRAME_INPRG, &video->flags); in aspeed_video_start_frame()
572 addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0); in aspeed_video_start_frame()
573 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_start_frame()
582 video->perf.last_sample = ktime_get(); in aspeed_video_start_frame()
596 /* Disable mode detect in order to re-trigger */ in aspeed_video_enable_mode_detect()
606 if (!test_bit(VIDEO_CLOCKS_ON, &video->flags)) in aspeed_video_off()
614 clk_disable(video->eclk); in aspeed_video_off()
615 clk_disable(video->vclk); in aspeed_video_off()
617 clear_bit(VIDEO_CLOCKS_ON, &video->flags); in aspeed_video_off()
622 if (test_bit(VIDEO_CLOCKS_ON, &video->flags)) in aspeed_video_on()
626 clk_enable(video->vclk); in aspeed_video_on()
627 clk_enable(video->eclk); in aspeed_video_on()
629 set_bit(VIDEO_CLOCKS_ON, &video->flags); in aspeed_video_on()
638 spin_lock_irqsave(&video->lock, flags); in aspeed_video_bufs_done()
639 list_for_each_entry(buf, &video->buffers, link) in aspeed_video_bufs_done()
640 vb2_buffer_done(&buf->vb.vb2_buf, state); in aspeed_video_bufs_done()
641 INIT_LIST_HEAD(&video->buffers); in aspeed_video_bufs_done()
642 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_bufs_done()
647 v4l2_dbg(1, debug, &video->v4l2_dev, "Resolution changed; resetting\n"); in aspeed_video_irq_res_change()
649 set_bit(VIDEO_RES_CHANGE, &video->flags); in aspeed_video_irq_res_change()
650 clear_bit(VIDEO_FRAME_INPRG, &video->flags); in aspeed_video_irq_res_change()
652 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_irq_res_change()
657 schedule_delayed_work(&video->res_work, delay); in aspeed_video_irq_res_change()
671 v4l2_dbg(2, debug, &video->v4l2_dev, "irq sts=%#x %s%s%s%s\n", sts, in aspeed_video_irq()
674 sts & VE_INTERRUPT_CAPTURE_COMPLETE ? ", capture-done" : "", in aspeed_video_irq()
675 sts & VE_INTERRUPT_COMP_COMPLETE ? ", comp-done" : ""); in aspeed_video_irq()
679 * re-initialize in aspeed_video_irq()
687 if (test_bit(VIDEO_RES_DETECT, &video->flags)) { in aspeed_video_irq()
693 set_bit(VIDEO_MODE_DETECT_DONE, &video->flags); in aspeed_video_irq()
694 wake_up_interruptible_all(&video->wait); in aspeed_video_irq()
698 * detection; reset the engine and re-initialize in aspeed_video_irq()
709 video->comp_size_read); in aspeed_video_irq()
711 update_perf(&video->perf); in aspeed_video_irq()
713 spin_lock(&video->lock); in aspeed_video_irq()
714 clear_bit(VIDEO_FRAME_INPRG, &video->flags); in aspeed_video_irq()
715 buf = list_first_entry_or_null(&video->buffers, in aspeed_video_irq()
719 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, frame_size); in aspeed_video_irq()
721 if (!list_is_last(&buf->link, &video->buffers)) { in aspeed_video_irq()
722 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in aspeed_video_irq()
723 buf->vb.sequence = video->sequence++; in aspeed_video_irq()
724 buf->vb.field = V4L2_FIELD_NONE; in aspeed_video_irq()
725 vb2_buffer_done(&buf->vb.vb2_buf, in aspeed_video_irq()
727 list_del(&buf->link); in aspeed_video_irq()
730 spin_unlock(&video->lock); in aspeed_video_irq()
741 if (test_bit(VIDEO_STREAMING, &video->flags) && buf) in aspeed_video_irq()
758 vsync_counter--; in aspeed_video_check_and_set_polarity()
763 hsync_counter--; in aspeed_video_check_and_set_polarity()
772 video->detected_timings.polarities &= in aspeed_video_check_and_set_polarity()
776 video->detected_timings.polarities |= in aspeed_video_check_and_set_polarity()
782 video->detected_timings.polarities &= in aspeed_video_check_and_set_polarity()
786 video->detected_timings.polarities |= in aspeed_video_check_and_set_polarity()
797 addr->virt = dma_alloc_coherent(video->dev, size, &addr->dma, in aspeed_video_alloc_buf()
799 if (!addr->virt) in aspeed_video_alloc_buf()
802 addr->size = size; in aspeed_video_alloc_buf()
809 dma_free_coherent(video->dev, addr->size, addr->virt, addr->dma); in aspeed_video_free_buf()
810 addr->size = 0; in aspeed_video_free_buf()
811 addr->dma = 0ULL; in aspeed_video_free_buf()
812 addr->virt = NULL; in aspeed_video_free_buf()
816 * Get the minimum HW-supported compression buffer size for the frame size.
817 * Assume worst-case JPEG compression size is 1/8 raw size. This should be
831 video->max_compressed_size = UINT_MAX; in aspeed_video_calc_compressed_size()
840 if (size < video->max_compressed_size) { in aspeed_video_calc_compressed_size()
842 video->max_compressed_size = size; in aspeed_video_calc_compressed_size()
850 v4l2_dbg(1, debug, &video->v4l2_dev, "Max compressed size: %#x\n", in aspeed_video_calc_compressed_size()
851 video->max_compressed_size); in aspeed_video_calc_compressed_size()
864 * +--+ +-------------------+ +--+
866 * +--+ +-----+ +-----+ +---+
867 * vsync+--+
868 * frame_top+--------+
869 * frame_bottom+----------------------------+
871 * +-------------------+
873 * +--+ +-----+ +-----+ +---+
875 * +--+ +--+
876 * vsync+-------------------------------+
877 * frame_top+-----+
878 * frame_bottom+-------------------------+
881 * +--+ +-------------------+ +--+
883 * +--+ +-----+ +-----+ +---+
884 * hsync+--+
885 * frame_left+--------+
886 * frame_right+----------------------------+
888 * +-------------------+
890 * +--+ +-----+ +-----+ +---+
892 * +--+ +--+
893 * hsync+-------------------------------+
894 * frame_left+-----+
895 * frame_right+-------------------------+
914 * Because ast-soc counts sync from sync's rising edge, the reg value in aspeed_video_get_timings()
917 if (vsync > det->height) in aspeed_video_get_timings()
918 det->polarities &= ~V4L2_DV_VSYNC_POS_POL; in aspeed_video_get_timings()
920 det->polarities |= V4L2_DV_VSYNC_POS_POL; in aspeed_video_get_timings()
921 if (hsync > det->width) in aspeed_video_get_timings()
922 det->polarities &= ~V4L2_DV_HSYNC_POS_POL; in aspeed_video_get_timings()
924 det->polarities |= V4L2_DV_HSYNC_POS_POL; in aspeed_video_get_timings()
926 if (det->polarities & V4L2_DV_VSYNC_POS_POL) { in aspeed_video_get_timings()
927 det->vbackporch = v->frame_top - vsync; in aspeed_video_get_timings()
928 det->vfrontporch = vtotal - v->frame_bottom; in aspeed_video_get_timings()
929 det->vsync = vsync; in aspeed_video_get_timings()
931 det->vbackporch = v->frame_top; in aspeed_video_get_timings()
932 det->vfrontporch = vsync - v->frame_bottom; in aspeed_video_get_timings()
933 det->vsync = vtotal - vsync; in aspeed_video_get_timings()
936 if (det->polarities & V4L2_DV_HSYNC_POS_POL) { in aspeed_video_get_timings()
937 det->hbackporch = v->frame_left - hsync; in aspeed_video_get_timings()
938 det->hfrontporch = htotal - v->frame_right; in aspeed_video_get_timings()
939 det->hsync = hsync; in aspeed_video_get_timings()
941 det->hbackporch = v->frame_left; in aspeed_video_get_timings()
942 det->hfrontporch = hsync - v->frame_right; in aspeed_video_get_timings()
943 det->hsync = htotal - hsync; in aspeed_video_get_timings()
947 #define res_check(v) test_and_clear_bit(VIDEO_MODE_DETECT_DONE, &(v)->flags)
957 struct v4l2_bt_timings *det = &video->detected_timings; in aspeed_video_get_resolution()
959 det->width = MIN_WIDTH; in aspeed_video_get_resolution()
960 det->height = MIN_HEIGHT; in aspeed_video_get_resolution()
961 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_get_resolution()
962 memset(&video->perf, 0, sizeof(video->perf)); in aspeed_video_get_resolution()
971 set_bit(VIDEO_RES_DETECT, &video->flags); in aspeed_video_get_resolution()
976 rc = wait_event_interruptible_timeout(video->wait, in aspeed_video_get_resolution()
980 v4l2_warn(&video->v4l2_dev, "Timed out; first mode detect\n"); in aspeed_video_get_resolution()
981 clear_bit(VIDEO_RES_DETECT, &video->flags); in aspeed_video_get_resolution()
996 rc = wait_event_interruptible_timeout(video->wait, in aspeed_video_get_resolution()
999 clear_bit(VIDEO_RES_DETECT, &video->flags); in aspeed_video_get_resolution()
1001 v4l2_warn(&video->v4l2_dev, "Timed out; second mode detect\n"); in aspeed_video_get_resolution()
1008 video->frame_bottom = FIELD_GET(VE_SRC_TB_EDGE_DET_BOT, src_tb_edge); in aspeed_video_get_resolution()
1009 video->frame_top = FIELD_GET(VE_SRC_TB_EDGE_DET_TOP, src_tb_edge); in aspeed_video_get_resolution()
1011 if (video->frame_top > video->frame_bottom) in aspeed_video_get_resolution()
1014 video->frame_right = FIELD_GET(VE_SRC_LR_EDGE_DET_RT, src_lr_edge); in aspeed_video_get_resolution()
1015 video->frame_left = FIELD_GET(VE_SRC_LR_EDGE_DET_LEFT, src_lr_edge); in aspeed_video_get_resolution()
1017 if (video->frame_left > video->frame_right) in aspeed_video_get_resolution()
1024 v4l2_warn(&video->v4l2_dev, "Invalid resolution detected\n"); in aspeed_video_get_resolution()
1028 det->height = (video->frame_bottom - video->frame_top) + 1; in aspeed_video_get_resolution()
1029 det->width = (video->frame_right - video->frame_left) + 1; in aspeed_video_get_resolution()
1030 video->v4l2_input_status = 0; in aspeed_video_get_resolution()
1035 * Enable mode-detect watchdog, resolution-change watchdog and in aspeed_video_get_resolution()
1043 v4l2_dbg(1, debug, &video->v4l2_dev, "Got resolution: %dx%d\n", in aspeed_video_get_resolution()
1044 det->width, det->height); in aspeed_video_get_resolution()
1049 struct v4l2_bt_timings *act = &video->active_timings; in aspeed_video_set_resolution()
1050 unsigned int size = act->width * act->height; in aspeed_video_set_resolution()
1055 if (!IS_ALIGNED(act->width, 64)) { in aspeed_video_set_resolution()
1061 * 64-pixels aligned value to minimize memory bandwidth in aspeed_video_set_resolution()
1064 u32 width = ALIGN(act->width, 64); in aspeed_video_set_resolution()
1066 aspeed_video_write(video, VE_CAP_WINDOW, width << 16 | act->height); in aspeed_video_set_resolution()
1067 size = width * act->height; in aspeed_video_set_resolution()
1070 act->width << 16 | act->height); in aspeed_video_set_resolution()
1073 act->width << 16 | act->height); in aspeed_video_set_resolution()
1074 aspeed_video_write(video, VE_SRC_SCANLINE_OFFSET, act->width * 4); in aspeed_video_set_resolution()
1078 v4l2_dbg(1, debug, &video->v4l2_dev, "Capture: Sync Mode\n"); in aspeed_video_set_resolution()
1081 video->frame_left - 1) | in aspeed_video_set_resolution()
1083 video->frame_right)); in aspeed_video_set_resolution()
1085 FIELD_PREP(VE_TGS_FIRST, video->frame_top) | in aspeed_video_set_resolution()
1087 video->frame_bottom + 1)); in aspeed_video_set_resolution()
1090 v4l2_dbg(1, debug, &video->v4l2_dev, "Capture: Direct Mode\n"); in aspeed_video_set_resolution()
1096 if (size != video->srcs[0].size) { in aspeed_video_set_resolution()
1097 if (video->srcs[0].size) in aspeed_video_set_resolution()
1098 aspeed_video_free_buf(video, &video->srcs[0]); in aspeed_video_set_resolution()
1099 if (video->srcs[1].size) in aspeed_video_set_resolution()
1100 aspeed_video_free_buf(video, &video->srcs[1]); in aspeed_video_set_resolution()
1102 if (!aspeed_video_alloc_buf(video, &video->srcs[0], size)) in aspeed_video_set_resolution()
1104 if (!aspeed_video_alloc_buf(video, &video->srcs[1], size)) in aspeed_video_set_resolution()
1107 v4l2_dbg(1, debug, &video->v4l2_dev, "src buf0 addr(%pad) size(%d)\n", in aspeed_video_set_resolution()
1108 &video->srcs[0].dma, video->srcs[0].size); in aspeed_video_set_resolution()
1109 v4l2_dbg(1, debug, &video->v4l2_dev, "src buf1 addr(%pad) size(%d)\n", in aspeed_video_set_resolution()
1110 &video->srcs[1].dma, video->srcs[1].size); in aspeed_video_set_resolution()
1111 aspeed_video_write(video, VE_SRC0_ADDR, video->srcs[0].dma); in aspeed_video_set_resolution()
1112 aspeed_video_write(video, VE_SRC1_ADDR, video->srcs[1].dma); in aspeed_video_set_resolution()
1118 dev_err(video->dev, "Failed to allocate source buffers\n"); in aspeed_video_set_resolution()
1120 if (video->srcs[0].size) in aspeed_video_set_resolution()
1121 aspeed_video_free_buf(video, &video->srcs[0]); in aspeed_video_set_resolution()
1127 FIELD_PREP(VE_COMP_CTRL_DCT_LUM, video->jpeg_quality) | in aspeed_video_init_regs()
1128 FIELD_PREP(VE_COMP_CTRL_DCT_CHR, video->jpeg_quality | 0x10); in aspeed_video_init_regs()
1131 u32 seq_ctrl = video->jpeg_mode; in aspeed_video_init_regs()
1133 if (video->frame_rate) in aspeed_video_init_regs()
1134 ctrl |= FIELD_PREP(VE_CTRL_FRC, video->frame_rate); in aspeed_video_init_regs()
1136 if (video->yuv420) in aspeed_video_init_regs()
1150 aspeed_video_write(video, VE_JPEG_ADDR, video->jpeg.dma); in aspeed_video_init_regs()
1183 video->active_timings = video->detected_timings; in aspeed_video_start()
1186 video->pix_fmt.width = video->active_timings.width; in aspeed_video_start()
1187 video->pix_fmt.height = video->active_timings.height; in aspeed_video_start()
1188 video->pix_fmt.sizeimage = video->max_compressed_size; in aspeed_video_start()
1193 set_bit(VIDEO_STOPPED, &video->flags); in aspeed_video_stop()
1194 cancel_delayed_work_sync(&video->res_work); in aspeed_video_stop()
1198 if (video->srcs[0].size) in aspeed_video_stop()
1199 aspeed_video_free_buf(video, &video->srcs[0]); in aspeed_video_stop()
1201 if (video->srcs[1].size) in aspeed_video_stop()
1202 aspeed_video_free_buf(video, &video->srcs[1]); in aspeed_video_stop()
1204 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_stop()
1205 video->flags = 0; in aspeed_video_stop()
1211 strscpy(cap->driver, DEVICE_NAME, sizeof(cap->driver)); in aspeed_video_querycap()
1212 strscpy(cap->card, "Aspeed Video Engine", sizeof(cap->card)); in aspeed_video_querycap()
1213 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", in aspeed_video_querycap()
1222 if (f->index) in aspeed_video_enum_format()
1223 return -EINVAL; in aspeed_video_enum_format()
1225 f->pixelformat = V4L2_PIX_FMT_JPEG; in aspeed_video_enum_format()
1235 f->fmt.pix = video->pix_fmt; in aspeed_video_get_format()
1245 if (inp->index) in aspeed_video_enum_input()
1246 return -EINVAL; in aspeed_video_enum_input()
1248 strscpy(inp->name, "Host VGA capture", sizeof(inp->name)); in aspeed_video_enum_input()
1249 inp->type = V4L2_INPUT_TYPE_CAMERA; in aspeed_video_enum_input()
1250 inp->capabilities = V4L2_IN_CAP_DV_TIMINGS; in aspeed_video_enum_input()
1251 inp->status = video->v4l2_input_status; in aspeed_video_enum_input()
1266 return -EINVAL; in aspeed_video_set_input()
1276 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in aspeed_video_get_parm()
1277 a->parm.capture.readbuffers = ASPEED_VIDEO_V4L2_MIN_BUF_REQ; in aspeed_video_get_parm()
1278 a->parm.capture.timeperframe.numerator = 1; in aspeed_video_get_parm()
1279 if (!video->frame_rate) in aspeed_video_get_parm()
1280 a->parm.capture.timeperframe.denominator = MAX_FRAME_RATE; in aspeed_video_get_parm()
1282 a->parm.capture.timeperframe.denominator = video->frame_rate; in aspeed_video_get_parm()
1293 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in aspeed_video_set_parm()
1294 a->parm.capture.readbuffers = ASPEED_VIDEO_V4L2_MIN_BUF_REQ; in aspeed_video_set_parm()
1296 if (a->parm.capture.timeperframe.numerator) in aspeed_video_set_parm()
1297 frame_rate = a->parm.capture.timeperframe.denominator / in aspeed_video_set_parm()
1298 a->parm.capture.timeperframe.numerator; in aspeed_video_set_parm()
1302 a->parm.capture.timeperframe.denominator = MAX_FRAME_RATE; in aspeed_video_set_parm()
1303 a->parm.capture.timeperframe.numerator = 1; in aspeed_video_set_parm()
1306 if (video->frame_rate != frame_rate) { in aspeed_video_set_parm()
1307 video->frame_rate = frame_rate; in aspeed_video_set_parm()
1320 if (fsize->index) in aspeed_video_enum_framesizes()
1321 return -EINVAL; in aspeed_video_enum_framesizes()
1323 if (fsize->pixel_format != V4L2_PIX_FMT_JPEG) in aspeed_video_enum_framesizes()
1324 return -EINVAL; in aspeed_video_enum_framesizes()
1326 fsize->discrete.width = video->pix_fmt.width; in aspeed_video_enum_framesizes()
1327 fsize->discrete.height = video->pix_fmt.height; in aspeed_video_enum_framesizes()
1328 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; in aspeed_video_enum_framesizes()
1338 if (fival->index) in aspeed_video_enum_frameintervals()
1339 return -EINVAL; in aspeed_video_enum_frameintervals()
1341 if (fival->width != video->detected_timings.width || in aspeed_video_enum_frameintervals()
1342 fival->height != video->detected_timings.height) in aspeed_video_enum_frameintervals()
1343 return -EINVAL; in aspeed_video_enum_frameintervals()
1345 if (fival->pixel_format != V4L2_PIX_FMT_JPEG) in aspeed_video_enum_frameintervals()
1346 return -EINVAL; in aspeed_video_enum_frameintervals()
1348 fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS; in aspeed_video_enum_frameintervals()
1350 fival->stepwise.min.denominator = MAX_FRAME_RATE; in aspeed_video_enum_frameintervals()
1351 fival->stepwise.min.numerator = 1; in aspeed_video_enum_frameintervals()
1352 fival->stepwise.max.denominator = 1; in aspeed_video_enum_frameintervals()
1353 fival->stepwise.max.numerator = 1; in aspeed_video_enum_frameintervals()
1354 fival->stepwise.step = fival->stepwise.max; in aspeed_video_enum_frameintervals()
1364 if (timings->bt.width == video->active_timings.width && in aspeed_video_set_dv_timings()
1365 timings->bt.height == video->active_timings.height) in aspeed_video_set_dv_timings()
1368 if (vb2_is_busy(&video->queue)) in aspeed_video_set_dv_timings()
1369 return -EBUSY; in aspeed_video_set_dv_timings()
1371 video->active_timings = timings->bt; in aspeed_video_set_dv_timings()
1375 video->pix_fmt.width = timings->bt.width; in aspeed_video_set_dv_timings()
1376 video->pix_fmt.height = timings->bt.height; in aspeed_video_set_dv_timings()
1377 video->pix_fmt.sizeimage = video->max_compressed_size; in aspeed_video_set_dv_timings()
1379 timings->type = V4L2_DV_BT_656_1120; in aspeed_video_set_dv_timings()
1381 v4l2_dbg(1, debug, &video->v4l2_dev, "set new timings(%dx%d)\n", in aspeed_video_set_dv_timings()
1382 timings->bt.width, timings->bt.height); in aspeed_video_set_dv_timings()
1392 timings->type = V4L2_DV_BT_656_1120; in aspeed_video_get_dv_timings()
1393 timings->bt = video->active_timings; in aspeed_video_get_dv_timings()
1409 if (file->f_flags & O_NONBLOCK) { in aspeed_video_query_dv_timings()
1410 if (test_bit(VIDEO_RES_CHANGE, &video->flags)) in aspeed_video_query_dv_timings()
1411 return -EAGAIN; in aspeed_video_query_dv_timings()
1413 rc = wait_event_interruptible(video->wait, in aspeed_video_query_dv_timings()
1415 &video->flags)); in aspeed_video_query_dv_timings()
1417 return -EINTR; in aspeed_video_query_dv_timings()
1420 timings->type = V4L2_DV_BT_656_1120; in aspeed_video_query_dv_timings()
1421 timings->bt = video->detected_timings; in aspeed_video_query_dv_timings()
1423 return video->v4l2_input_status ? -ENOLINK : 0; in aspeed_video_query_dv_timings()
1444 switch (sub->type) { in aspeed_video_sub_event()
1491 u32 comp_ctrl = FIELD_PREP(VE_COMP_CTRL_DCT_LUM, video->jpeg_quality) | in aspeed_video_update_jpeg_quality()
1492 FIELD_PREP(VE_COMP_CTRL_DCT_CHR, video->jpeg_quality | 0x10); in aspeed_video_update_jpeg_quality()
1501 if (video->jpeg.virt) in aspeed_video_update_subsampling()
1502 aspeed_video_update_jpeg_table(video->jpeg.virt, video->yuv420); in aspeed_video_update_subsampling()
1504 if (video->yuv420) in aspeed_video_update_subsampling()
1512 struct aspeed_video *video = container_of(ctrl->handler, in aspeed_video_set_ctrl()
1516 switch (ctrl->id) { in aspeed_video_set_ctrl()
1518 video->jpeg_quality = ctrl->val; in aspeed_video_set_ctrl()
1522 if (ctrl->val == V4L2_JPEG_CHROMA_SUBSAMPLING_420) { in aspeed_video_set_ctrl()
1523 video->yuv420 = true; in aspeed_video_set_ctrl()
1526 video->yuv420 = false; in aspeed_video_set_ctrl()
1531 return -EINVAL; in aspeed_video_set_ctrl()
1550 if (test_bit(VIDEO_STOPPED, &video->flags)) in aspeed_video_resolution_work()
1557 if (video->detected_timings.width != video->active_timings.width || in aspeed_video_resolution_work()
1558 video->detected_timings.height != video->active_timings.height) { in aspeed_video_resolution_work()
1564 v4l2_dbg(1, debug, &video->v4l2_dev, "fire source change event\n"); in aspeed_video_resolution_work()
1565 v4l2_event_queue(&video->vdev, &ev); in aspeed_video_resolution_work()
1566 } else if (test_bit(VIDEO_STREAMING, &video->flags)) { in aspeed_video_resolution_work()
1572 clear_bit(VIDEO_RES_CHANGE, &video->flags); in aspeed_video_resolution_work()
1573 wake_up_interruptible_all(&video->wait); in aspeed_video_resolution_work()
1581 mutex_lock(&video->video_lock); in aspeed_video_open()
1585 mutex_unlock(&video->video_lock); in aspeed_video_open()
1592 mutex_unlock(&video->video_lock); in aspeed_video_open()
1602 mutex_lock(&video->video_lock); in aspeed_video_release()
1609 mutex_unlock(&video->video_lock); in aspeed_video_release()
1633 if (sizes[0] < video->max_compressed_size) in aspeed_video_queue_setup()
1634 return -EINVAL; in aspeed_video_queue_setup()
1640 sizes[0] = video->max_compressed_size; in aspeed_video_queue_setup()
1647 struct aspeed_video *video = vb2_get_drv_priv(vb->vb2_queue); in aspeed_video_buf_prepare()
1649 if (vb2_plane_size(vb, 0) < video->max_compressed_size) in aspeed_video_buf_prepare()
1650 return -EINVAL; in aspeed_video_buf_prepare()
1661 video->sequence = 0; in aspeed_video_start_streaming()
1662 video->perf.duration_max = 0; in aspeed_video_start_streaming()
1663 video->perf.duration_min = 0xffffffff; in aspeed_video_start_streaming()
1671 set_bit(VIDEO_STREAMING, &video->flags); in aspeed_video_start_streaming()
1680 clear_bit(VIDEO_STREAMING, &video->flags); in aspeed_video_stop_streaming()
1682 rc = wait_event_timeout(video->wait, in aspeed_video_stop_streaming()
1683 !test_bit(VIDEO_FRAME_INPRG, &video->flags), in aspeed_video_stop_streaming()
1686 v4l2_warn(&video->v4l2_dev, "Timed out when stopping streaming\n"); in aspeed_video_stop_streaming()
1706 struct aspeed_video *video = vb2_get_drv_priv(vb->vb2_queue); in aspeed_video_buf_queue()
1711 spin_lock_irqsave(&video->lock, flags); in aspeed_video_buf_queue()
1712 empty = list_empty(&video->buffers); in aspeed_video_buf_queue()
1713 list_add_tail(&avb->link, &video->buffers); in aspeed_video_buf_queue()
1714 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_buf_queue()
1716 if (test_bit(VIDEO_STREAMING, &video->flags) && in aspeed_video_buf_queue()
1717 !test_bit(VIDEO_FRAME_INPRG, &video->flags) && empty) in aspeed_video_buf_queue()
1734 struct aspeed_video *v = s->private; in aspeed_video_debugfs_show()
1738 seq_printf(s, " %-20s:\t%s\n", "Signal", in aspeed_video_debugfs_show()
1739 v->v4l2_input_status ? "Unlock" : "Lock"); in aspeed_video_debugfs_show()
1740 seq_printf(s, " %-20s:\t%d\n", "Width", v->pix_fmt.width); in aspeed_video_debugfs_show()
1741 seq_printf(s, " %-20s:\t%d\n", "Height", v->pix_fmt.height); in aspeed_video_debugfs_show()
1742 seq_printf(s, " %-20s:\t%d\n", "FRC", v->frame_rate); in aspeed_video_debugfs_show()
1747 seq_printf(s, " %-20s:\t%d\n", "Frame#", v->sequence); in aspeed_video_debugfs_show()
1748 seq_printf(s, " %-20s:\n", "Frame Duration(ms)"); in aspeed_video_debugfs_show()
1749 seq_printf(s, " %-18s:\t%d\n", "Now", v->perf.duration); in aspeed_video_debugfs_show()
1750 seq_printf(s, " %-18s:\t%d\n", "Min", v->perf.duration_min); in aspeed_video_debugfs_show()
1751 seq_printf(s, " %-18s:\t%d\n", "Max", v->perf.duration_max); in aspeed_video_debugfs_show()
1752 seq_printf(s, " %-20s:\t%d\n", "FPS", 1000 / (v->perf.totaltime / v->sequence)); in aspeed_video_debugfs_show()
1759 return single_open(file, aspeed_video_debugfs_show, inode->i_private); in aspeed_video_proc_open()
1786 return !debugfs_entry ? -EIO : 0; in aspeed_video_debugfs_create()
1800 struct v4l2_device *v4l2_dev = &video->v4l2_dev; in aspeed_video_setup_video()
1801 struct vb2_queue *vbq = &video->queue; in aspeed_video_setup_video()
1802 struct video_device *vdev = &video->vdev; in aspeed_video_setup_video()
1805 video->pix_fmt.pixelformat = V4L2_PIX_FMT_JPEG; in aspeed_video_setup_video()
1806 video->pix_fmt.field = V4L2_FIELD_NONE; in aspeed_video_setup_video()
1807 video->pix_fmt.colorspace = V4L2_COLORSPACE_SRGB; in aspeed_video_setup_video()
1808 video->pix_fmt.quantization = V4L2_QUANTIZATION_FULL_RANGE; in aspeed_video_setup_video()
1809 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_setup_video()
1811 rc = v4l2_device_register(video->dev, v4l2_dev); in aspeed_video_setup_video()
1813 dev_err(video->dev, "Failed to register v4l2 device\n"); in aspeed_video_setup_video()
1817 v4l2_ctrl_handler_init(&video->ctrl_handler, 2); in aspeed_video_setup_video()
1818 v4l2_ctrl_new_std(&video->ctrl_handler, &aspeed_video_ctrl_ops, in aspeed_video_setup_video()
1820 ASPEED_VIDEO_JPEG_NUM_QUALITIES - 1, 1, 0); in aspeed_video_setup_video()
1821 v4l2_ctrl_new_std_menu(&video->ctrl_handler, &aspeed_video_ctrl_ops, in aspeed_video_setup_video()
1826 rc = video->ctrl_handler.error; in aspeed_video_setup_video()
1828 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_setup_video()
1831 dev_err(video->dev, "Failed to init controls: %d\n", rc); in aspeed_video_setup_video()
1835 v4l2_dev->ctrl_handler = &video->ctrl_handler; in aspeed_video_setup_video()
1837 vbq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in aspeed_video_setup_video()
1838 vbq->io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF; in aspeed_video_setup_video()
1839 vbq->dev = v4l2_dev->dev; in aspeed_video_setup_video()
1840 vbq->lock = &video->video_lock; in aspeed_video_setup_video()
1841 vbq->ops = &aspeed_video_vb2_ops; in aspeed_video_setup_video()
1842 vbq->mem_ops = &vb2_dma_contig_memops; in aspeed_video_setup_video()
1843 vbq->drv_priv = video; in aspeed_video_setup_video()
1844 vbq->buf_struct_size = sizeof(struct aspeed_video_buffer); in aspeed_video_setup_video()
1845 vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in aspeed_video_setup_video()
1846 vbq->min_buffers_needed = ASPEED_VIDEO_V4L2_MIN_BUF_REQ; in aspeed_video_setup_video()
1850 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_setup_video()
1853 dev_err(video->dev, "Failed to init vb2 queue\n"); in aspeed_video_setup_video()
1857 vdev->queue = vbq; in aspeed_video_setup_video()
1858 vdev->fops = &aspeed_video_v4l2_fops; in aspeed_video_setup_video()
1859 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in aspeed_video_setup_video()
1861 vdev->v4l2_dev = v4l2_dev; in aspeed_video_setup_video()
1862 strscpy(vdev->name, DEVICE_NAME, sizeof(vdev->name)); in aspeed_video_setup_video()
1863 vdev->vfl_type = VFL_TYPE_VIDEO; in aspeed_video_setup_video()
1864 vdev->vfl_dir = VFL_DIR_RX; in aspeed_video_setup_video()
1865 vdev->release = video_device_release_empty; in aspeed_video_setup_video()
1866 vdev->ioctl_ops = &aspeed_video_ioctl_ops; in aspeed_video_setup_video()
1867 vdev->lock = &video->video_lock; in aspeed_video_setup_video()
1872 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_setup_video()
1875 dev_err(video->dev, "Failed to register video device\n"); in aspeed_video_setup_video()
1886 struct device *dev = video->dev; in aspeed_video_init()
1888 irq = irq_of_parse_and_map(dev->of_node, 0); in aspeed_video_init()
1891 return -ENODEV; in aspeed_video_init()
1900 dev_info(video->dev, "irq %d\n", irq); in aspeed_video_init()
1902 video->eclk = devm_clk_get(dev, "eclk"); in aspeed_video_init()
1903 if (IS_ERR(video->eclk)) { in aspeed_video_init()
1905 return PTR_ERR(video->eclk); in aspeed_video_init()
1908 rc = clk_prepare(video->eclk); in aspeed_video_init()
1912 video->vclk = devm_clk_get(dev, "vclk"); in aspeed_video_init()
1913 if (IS_ERR(video->vclk)) { in aspeed_video_init()
1915 rc = PTR_ERR(video->vclk); in aspeed_video_init()
1919 rc = clk_prepare(video->vclk); in aspeed_video_init()
1931 if (!aspeed_video_alloc_buf(video, &video->jpeg, in aspeed_video_init()
1934 rc = -ENOMEM; in aspeed_video_init()
1937 dev_info(video->dev, "alloc mem size(%d) at %pad for jpeg header\n", in aspeed_video_init()
1938 VE_JPEG_HEADER_SIZE, &video->jpeg.dma); in aspeed_video_init()
1940 aspeed_video_init_jpeg_table(video->jpeg.virt, video->yuv420); in aspeed_video_init()
1946 clk_unprepare(video->vclk); in aspeed_video_init()
1948 clk_unprepare(video->eclk); in aspeed_video_init()
1954 { .compatible = "aspeed,ast2400-video-engine", .data = &ast2400_config },
1955 { .compatible = "aspeed,ast2500-video-engine", .data = &ast2500_config },
1956 { .compatible = "aspeed,ast2600-video-engine", .data = &ast2600_config },
1967 video = devm_kzalloc(&pdev->dev, sizeof(*video), GFP_KERNEL); in aspeed_video_probe()
1969 return -ENOMEM; in aspeed_video_probe()
1971 video->base = devm_platform_ioremap_resource(pdev, 0); in aspeed_video_probe()
1972 if (IS_ERR(video->base)) in aspeed_video_probe()
1973 return PTR_ERR(video->base); in aspeed_video_probe()
1975 config = of_device_get_match_data(&pdev->dev); in aspeed_video_probe()
1977 return -ENODEV; in aspeed_video_probe()
1979 video->jpeg_mode = config->jpeg_mode; in aspeed_video_probe()
1980 video->comp_size_read = config->comp_size_read; in aspeed_video_probe()
1982 video->frame_rate = 30; in aspeed_video_probe()
1983 video->dev = &pdev->dev; in aspeed_video_probe()
1984 spin_lock_init(&video->lock); in aspeed_video_probe()
1985 mutex_init(&video->video_lock); in aspeed_video_probe()
1986 init_waitqueue_head(&video->wait); in aspeed_video_probe()
1987 INIT_DELAYED_WORK(&video->res_work, aspeed_video_resolution_work); in aspeed_video_probe()
1988 INIT_LIST_HEAD(&video->buffers); in aspeed_video_probe()
1996 aspeed_video_free_buf(video, &video->jpeg); in aspeed_video_probe()
1997 clk_unprepare(video->vclk); in aspeed_video_probe()
1998 clk_unprepare(video->eclk); in aspeed_video_probe()
2004 dev_err(video->dev, "debugfs create failed\n"); in aspeed_video_probe()
2011 struct device *dev = &pdev->dev; in aspeed_video_remove()
2019 clk_unprepare(video->vclk); in aspeed_video_remove()
2020 clk_unprepare(video->eclk); in aspeed_video_remove()
2022 vb2_video_unregister_device(&video->vdev); in aspeed_video_remove()
2024 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_remove()
2028 aspeed_video_free_buf(video, &video->jpeg); in aspeed_video_remove()
2047 MODULE_PARM_DESC(debug, "Debug level (0=off,1=info,2=debug,3=reg ops)");