Lines Matching full:video

39 #define DEVICE_NAME			"aspeed-video"
250 * flags: holds the state of video
258 * frame_bottom: end position of video data in vertical direction
259 * frame_left: start position of video data in horizontal direction
260 * frame_right: end position of video data in horizontal direction
261 * frame_top: start position of video data in vertical direction
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()
544 static int aspeed_video_start_frame(struct aspeed_video *video) in aspeed_video_start_frame() argument
549 u32 seq_ctrl = aspeed_video_read(video, VE_SEQ_CTRL); in aspeed_video_start_frame()
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()
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()
571 set_bit(VIDEO_FRAME_INPRG, &video->flags); in aspeed_video_start_frame()
573 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_start_frame()
575 aspeed_video_write(video, VE_COMP_PROC_OFFSET, 0); in aspeed_video_start_frame()
576 aspeed_video_write(video, VE_COMP_OFFSET, 0); in aspeed_video_start_frame()
577 aspeed_video_write(video, VE_COMP_ADDR, addr); in aspeed_video_start_frame()
579 aspeed_video_update(video, VE_INTERRUPT_CTRL, 0, in aspeed_video_start_frame()
582 video->perf.last_sample = ktime_get(); in aspeed_video_start_frame()
584 aspeed_video_update(video, VE_SEQ_CTRL, 0, in aspeed_video_start_frame()
590 static void aspeed_video_enable_mode_detect(struct aspeed_video *video) in aspeed_video_enable_mode_detect() argument
593 aspeed_video_update(video, VE_INTERRUPT_CTRL, 0, in aspeed_video_enable_mode_detect()
597 aspeed_video_update(video, VE_SEQ_CTRL, in aspeed_video_enable_mode_detect()
601 aspeed_video_update(video, VE_SEQ_CTRL, 0, VE_SEQ_CTRL_TRIG_MODE_DET); in aspeed_video_enable_mode_detect()
604 static void aspeed_video_off(struct aspeed_video *video) in aspeed_video_off() argument
606 if (!test_bit(VIDEO_CLOCKS_ON, &video->flags)) in aspeed_video_off()
610 aspeed_video_write(video, VE_INTERRUPT_CTRL, 0); in aspeed_video_off()
611 aspeed_video_write(video, VE_INTERRUPT_STATUS, 0xffffffff); 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()
620 static void aspeed_video_on(struct aspeed_video *video) in aspeed_video_on() argument
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()
632 static void aspeed_video_bufs_done(struct aspeed_video *video, in aspeed_video_bufs_done() argument
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()
641 INIT_LIST_HEAD(&video->buffers); in aspeed_video_bufs_done()
642 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_bufs_done()
645 static void aspeed_video_irq_res_change(struct aspeed_video *video, ulong delay) in aspeed_video_irq_res_change() argument
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()
654 aspeed_video_off(video); in aspeed_video_irq_res_change()
655 aspeed_video_bufs_done(video, VB2_BUF_STATE_ERROR); in aspeed_video_irq_res_change()
657 schedule_delayed_work(&video->res_work, delay); in aspeed_video_irq_res_change()
662 struct aspeed_video *video = arg; in aspeed_video_irq() local
663 u32 sts = aspeed_video_read(video, VE_INTERRUPT_STATUS); in aspeed_video_irq()
669 sts &= aspeed_video_read(video, VE_INTERRUPT_CTRL); in aspeed_video_irq()
671 v4l2_dbg(2, debug, &video->v4l2_dev, "irq sts=%#x %s%s%s%s\n", sts, in aspeed_video_irq()
682 aspeed_video_irq_res_change(video, 0); in aspeed_video_irq()
687 if (test_bit(VIDEO_RES_DETECT, &video->flags)) { in aspeed_video_irq()
688 aspeed_video_update(video, VE_INTERRUPT_CTRL, in aspeed_video_irq()
690 aspeed_video_write(video, VE_INTERRUPT_STATUS, 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()
700 aspeed_video_irq_res_change(video, in aspeed_video_irq()
708 u32 frame_size = aspeed_video_read(video, 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()
721 if (!list_is_last(&buf->link, &video->buffers)) { in aspeed_video_irq()
723 buf->vb.sequence = video->sequence++; in aspeed_video_irq()
730 spin_unlock(&video->lock); in aspeed_video_irq()
732 aspeed_video_update(video, VE_SEQ_CTRL, in aspeed_video_irq()
736 aspeed_video_update(video, VE_INTERRUPT_CTRL, in aspeed_video_irq()
738 aspeed_video_write(video, VE_INTERRUPT_STATUS, in aspeed_video_irq()
741 if (test_bit(VIDEO_STREAMING, &video->flags) && buf) in aspeed_video_irq()
742 aspeed_video_start_frame(video); in aspeed_video_irq()
748 static void aspeed_video_check_and_set_polarity(struct aspeed_video *video) in aspeed_video_check_and_set_polarity() argument
756 sts = aspeed_video_read(video, VE_MODE_DETECT_STATUS); in aspeed_video_check_and_set_polarity()
768 ctrl = aspeed_video_read(video, VE_CTRL); 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()
790 aspeed_video_write(video, VE_CTRL, ctrl); in aspeed_video_check_and_set_polarity()
793 static bool aspeed_video_alloc_buf(struct aspeed_video *video, in aspeed_video_alloc_buf() argument
797 addr->virt = dma_alloc_coherent(video->dev, size, &addr->dma, in aspeed_video_alloc_buf()
806 static void aspeed_video_free_buf(struct aspeed_video *video, in aspeed_video_free_buf() argument
809 dma_free_coherent(video->dev, addr->size, addr->virt, addr->dma); in aspeed_video_free_buf()
821 static void aspeed_video_calc_compressed_size(struct aspeed_video *video, in aspeed_video_calc_compressed_size() argument
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()
847 aspeed_video_write(video, VE_STREAM_BUF_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()
915 * of sync would be larger than video's active area if negative. in aspeed_video_get_timings()
949 static void aspeed_video_get_resolution(struct aspeed_video *video) in aspeed_video_get_resolution() argument
957 struct v4l2_bt_timings *det = &video->detected_timings; 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()
972 aspeed_video_update(video, VE_CTRL, in aspeed_video_get_resolution()
974 aspeed_video_enable_mode_detect(video); in aspeed_video_get_resolution()
976 rc = wait_event_interruptible_timeout(video->wait, in aspeed_video_get_resolution()
977 res_check(video), 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()
985 mds = aspeed_video_read(video, VE_MODE_DETECT_STATUS); in aspeed_video_get_resolution()
992 aspeed_video_check_and_set_polarity(video); in aspeed_video_get_resolution()
994 aspeed_video_enable_mode_detect(video); in aspeed_video_get_resolution()
996 rc = wait_event_interruptible_timeout(video->wait, in aspeed_video_get_resolution()
997 res_check(video), 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()
1005 src_lr_edge = aspeed_video_read(video, VE_SRC_LR_EDGE_DET); in aspeed_video_get_resolution()
1006 src_tb_edge = aspeed_video_read(video, VE_SRC_TB_EDGE_DET); 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()
1032 aspeed_video_get_timings(video, det); in aspeed_video_get_resolution()
1038 aspeed_video_update(video, VE_INTERRUPT_CTRL, 0, in aspeed_video_get_resolution()
1040 aspeed_video_update(video, VE_SEQ_CTRL, 0, in aspeed_video_get_resolution()
1043 v4l2_dbg(1, debug, &video->v4l2_dev, "Got resolution: %dx%d\n", in aspeed_video_get_resolution()
1047 static void aspeed_video_set_resolution(struct aspeed_video *video) in aspeed_video_set_resolution() argument
1049 struct v4l2_bt_timings *act = &video->active_timings; in aspeed_video_set_resolution()
1053 aspeed_video_calc_compressed_size(video, size); in aspeed_video_set_resolution()
1062 * and to get better access speed from video engine. in aspeed_video_set_resolution()
1066 aspeed_video_write(video, VE_CAP_WINDOW, width << 16 | act->height); in aspeed_video_set_resolution()
1069 aspeed_video_write(video, VE_CAP_WINDOW, in aspeed_video_set_resolution()
1072 aspeed_video_write(video, VE_COMP_WINDOW, 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()
1079 aspeed_video_write(video, VE_TGS_0, in aspeed_video_set_resolution()
1081 video->frame_left - 1) | in aspeed_video_set_resolution()
1083 video->frame_right)); in aspeed_video_set_resolution()
1084 aspeed_video_write(video, VE_TGS_1, 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()
1088 aspeed_video_update(video, VE_CTRL, 0, VE_CTRL_INT_DE); in aspeed_video_set_resolution()
1090 v4l2_dbg(1, debug, &video->v4l2_dev, "Capture: Direct Mode\n"); in aspeed_video_set_resolution()
1091 aspeed_video_update(video, VE_CTRL, 0, VE_CTRL_DIRECT_FETCH); 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()
1124 static void aspeed_video_init_regs(struct aspeed_video *video) in aspeed_video_init_regs() argument
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()
1140 aspeed_video_write(video, VE_PROTECTION_KEY, VE_PROTECTION_KEY_UNLOCK); in aspeed_video_init_regs()
1143 aspeed_video_write(video, VE_INTERRUPT_CTRL, 0); in aspeed_video_init_regs()
1144 aspeed_video_write(video, VE_INTERRUPT_STATUS, 0xffffffff); in aspeed_video_init_regs()
1147 aspeed_video_write(video, VE_COMP_PROC_OFFSET, 0); in aspeed_video_init_regs()
1148 aspeed_video_write(video, VE_COMP_OFFSET, 0); in aspeed_video_init_regs()
1150 aspeed_video_write(video, VE_JPEG_ADDR, video->jpeg.dma); in aspeed_video_init_regs()
1153 aspeed_video_write(video, VE_SEQ_CTRL, seq_ctrl); in aspeed_video_init_regs()
1154 aspeed_video_write(video, VE_CTRL, ctrl); in aspeed_video_init_regs()
1155 aspeed_video_write(video, VE_COMP_CTRL, comp_ctrl); in aspeed_video_init_regs()
1158 aspeed_video_write(video, VE_SCALING_FACTOR, 0x10001000); in aspeed_video_init_regs()
1159 aspeed_video_write(video, VE_SCALING_FILTER0, 0x00200000); in aspeed_video_init_regs()
1160 aspeed_video_write(video, VE_SCALING_FILTER1, 0x00200000); in aspeed_video_init_regs()
1161 aspeed_video_write(video, VE_SCALING_FILTER2, 0x00200000); in aspeed_video_init_regs()
1162 aspeed_video_write(video, VE_SCALING_FILTER3, 0x00200000); in aspeed_video_init_regs()
1165 aspeed_video_write(video, VE_MODE_DETECT, in aspeed_video_init_regs()
1173 static void aspeed_video_start(struct aspeed_video *video) in aspeed_video_start() argument
1175 aspeed_video_on(video); in aspeed_video_start()
1177 aspeed_video_init_regs(video); in aspeed_video_start()
1180 aspeed_video_get_resolution(video); in aspeed_video_start()
1183 video->active_timings = video->detected_timings; in aspeed_video_start()
1184 aspeed_video_set_resolution(video); 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()
1191 static void aspeed_video_stop(struct aspeed_video *video) in aspeed_video_stop() argument
1193 set_bit(VIDEO_STOPPED, &video->flags); in aspeed_video_stop()
1194 cancel_delayed_work_sync(&video->res_work); in aspeed_video_stop()
1196 aspeed_video_off(video); 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()
1212 strscpy(cap->card, "Aspeed Video Engine", sizeof(cap->card)); in aspeed_video_querycap()
1233 struct aspeed_video *video = video_drvdata(file); in aspeed_video_get_format() local
1235 f->fmt.pix = video->pix_fmt; in aspeed_video_get_format()
1243 struct aspeed_video *video = video_drvdata(file); in aspeed_video_enum_input() local
1251 inp->status = video->v4l2_input_status; in aspeed_video_enum_input()
1274 struct aspeed_video *video = video_drvdata(file); in aspeed_video_get_parm() local
1279 if (!video->frame_rate) in aspeed_video_get_parm()
1282 a->parm.capture.timeperframe.denominator = video->frame_rate; in aspeed_video_get_parm()
1291 struct aspeed_video *video = video_drvdata(file); in aspeed_video_set_parm() local
1306 if (video->frame_rate != frame_rate) { in aspeed_video_set_parm()
1307 video->frame_rate = frame_rate; in aspeed_video_set_parm()
1308 aspeed_video_update(video, VE_CTRL, VE_CTRL_FRC, in aspeed_video_set_parm()
1318 struct aspeed_video *video = video_drvdata(file); in aspeed_video_enum_framesizes() local
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()
1336 struct aspeed_video *video = video_drvdata(file); in aspeed_video_enum_frameintervals() local
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()
1362 struct aspeed_video *video = video_drvdata(file); in aspeed_video_set_dv_timings() local
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()
1371 video->active_timings = timings->bt; in aspeed_video_set_dv_timings()
1373 aspeed_video_set_resolution(video); 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()
1381 v4l2_dbg(1, debug, &video->v4l2_dev, "set new timings(%dx%d)\n", in aspeed_video_set_dv_timings()
1390 struct aspeed_video *video = video_drvdata(file); in aspeed_video_get_dv_timings() local
1393 timings->bt = video->active_timings; in aspeed_video_get_dv_timings()
1402 struct aspeed_video *video = video_drvdata(file); in aspeed_video_query_dv_timings() local
1410 if (test_bit(VIDEO_RES_CHANGE, &video->flags)) 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()
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()
1489 static void aspeed_video_update_jpeg_quality(struct aspeed_video *video) in aspeed_video_update_jpeg_quality() argument
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()
1494 aspeed_video_update(video, VE_COMP_CTRL, in aspeed_video_update_jpeg_quality()
1499 static void aspeed_video_update_subsampling(struct aspeed_video *video) in aspeed_video_update_subsampling() argument
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()
1505 aspeed_video_update(video, VE_SEQ_CTRL, 0, VE_SEQ_CTRL_YUV420); in aspeed_video_update_subsampling()
1507 aspeed_video_update(video, VE_SEQ_CTRL, VE_SEQ_CTRL_YUV420, 0); in aspeed_video_update_subsampling()
1512 struct aspeed_video *video = container_of(ctrl->handler, in aspeed_video_set_ctrl() local
1518 video->jpeg_quality = ctrl->val; in aspeed_video_set_ctrl()
1519 aspeed_video_update_jpeg_quality(video); in aspeed_video_set_ctrl()
1523 video->yuv420 = true; in aspeed_video_set_ctrl()
1524 aspeed_video_update_subsampling(video); in aspeed_video_set_ctrl()
1526 video->yuv420 = false; in aspeed_video_set_ctrl()
1527 aspeed_video_update_subsampling(video); in aspeed_video_set_ctrl()
1544 struct aspeed_video *video = container_of(dwork, struct aspeed_video, in aspeed_video_resolution_work() local
1547 aspeed_video_on(video); in aspeed_video_resolution_work()
1550 if (test_bit(VIDEO_STOPPED, &video->flags)) in aspeed_video_resolution_work()
1553 aspeed_video_init_regs(video); in aspeed_video_resolution_work()
1555 aspeed_video_get_resolution(video); 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()
1568 aspeed_video_start_frame(video); 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()
1579 struct aspeed_video *video = video_drvdata(file); in aspeed_video_open() local
1581 mutex_lock(&video->video_lock); in aspeed_video_open()
1585 mutex_unlock(&video->video_lock); in aspeed_video_open()
1590 aspeed_video_start(video); in aspeed_video_open()
1592 mutex_unlock(&video->video_lock); in aspeed_video_open()
1600 struct aspeed_video *video = video_drvdata(file); in aspeed_video_release() local
1602 mutex_lock(&video->video_lock); in aspeed_video_release()
1605 aspeed_video_stop(video); in aspeed_video_release()
1609 mutex_unlock(&video->video_lock); in aspeed_video_release()
1630 struct aspeed_video *video = vb2_get_drv_priv(q); in aspeed_video_queue_setup() local
1633 if (sizes[0] < video->max_compressed_size) 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() local
1649 if (vb2_plane_size(vb, 0) < video->max_compressed_size) in aspeed_video_buf_prepare()
1659 struct aspeed_video *video = vb2_get_drv_priv(q); in aspeed_video_start_streaming() local
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()
1665 rc = aspeed_video_start_frame(video); in aspeed_video_start_streaming()
1667 aspeed_video_bufs_done(video, VB2_BUF_STATE_QUEUED); in aspeed_video_start_streaming()
1671 set_bit(VIDEO_STREAMING, &video->flags); in aspeed_video_start_streaming()
1678 struct aspeed_video *video = vb2_get_drv_priv(q); in aspeed_video_stop_streaming() local
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()
1692 aspeed_video_off(video); in aspeed_video_stop_streaming()
1693 aspeed_video_on(video); in aspeed_video_stop_streaming()
1695 aspeed_video_init_regs(video); in aspeed_video_stop_streaming()
1697 aspeed_video_get_resolution(video); in aspeed_video_stop_streaming()
1700 aspeed_video_bufs_done(video, VB2_BUF_STATE_ERROR); in aspeed_video_stop_streaming()
1706 struct aspeed_video *video = vb2_get_drv_priv(vb->vb2_queue); in aspeed_video_buf_queue() local
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()
1718 aspeed_video_start_frame(video); in aspeed_video_buf_queue()
1772 static void aspeed_video_debugfs_remove(struct aspeed_video *video) in aspeed_video_debugfs_remove() argument
1778 static int aspeed_video_debugfs_create(struct aspeed_video *video) in aspeed_video_debugfs_create() argument
1781 video, in aspeed_video_debugfs_create()
1784 aspeed_video_debugfs_remove(video); in aspeed_video_debugfs_create()
1789 static void aspeed_video_debugfs_remove(struct aspeed_video *video) { } in aspeed_video_debugfs_remove() argument
1790 static int aspeed_video_debugfs_create(struct aspeed_video *video) in aspeed_video_debugfs_create() argument
1796 static int aspeed_video_setup_video(struct aspeed_video *video) in aspeed_video_setup_video() argument
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()
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()
1840 vbq->lock = &video->video_lock; in aspeed_video_setup_video()
1843 vbq->drv_priv = video; 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()
1867 vdev->lock = &video->video_lock; in aspeed_video_setup_video()
1869 video_set_drvdata(vdev, video); 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()
1882 static int aspeed_video_init(struct aspeed_video *video) in aspeed_video_init() argument
1886 struct device *dev = video->dev; in aspeed_video_init()
1895 IRQF_ONESHOT, DEVICE_NAME, video); 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()
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 },
1964 struct aspeed_video *video; in aspeed_video_probe() local
1967 video = devm_kzalloc(&pdev->dev, sizeof(*video), GFP_KERNEL); in aspeed_video_probe()
1968 if (!video) 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()
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()
1990 rc = aspeed_video_init(video); in aspeed_video_probe()
1994 rc = aspeed_video_setup_video(video); 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()
2002 rc = aspeed_video_debugfs_create(video); in aspeed_video_probe()
2004 dev_err(video->dev, "debugfs create failed\n"); in aspeed_video_probe()
2013 struct aspeed_video *video = to_aspeed_video(v4l2_dev); in aspeed_video_remove() local
2015 aspeed_video_off(video); in aspeed_video_remove()
2017 aspeed_video_debugfs_remove(video); 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()
2049 MODULE_DESCRIPTION("ASPEED Video Engine Driver");