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>
22 #include <linux/v4l2-controls.h>
28 #include <media/v4l2-ctrls.h>
29 #include <media/v4l2-dev.h>
30 #include <media/v4l2-device.h>
31 #include <media/v4l2-dv-timings.h>
32 #include <media/v4l2-event.h>
33 #include <media/v4l2-ioctl.h>
34 #include <media/videobuf2-dma-contig.h>
35 #include <uapi/linux/aspeed-video.h>
39 #define DEVICE_NAME "aspeed-video"
208 * VIDEO_RES_CHANGE: a flag raised if res_change work on-going
209 * VIDEO_RES_DETECT: a flag raised if res. detection on-going
210 * VIDEO_STREAMING: a flag raised if user requires stream-on
263 * struct aspeed_video - driver data
265 * res_work: holds the delayed_work for res-detection if unlock
504 base = 256 * i; /* AST HW requires this header spacing */ in aspeed_video_init_jpeg_table()
528 base = 256 * i; /* AST HW requires this header spacing */ in aspeed_video_update_jpeg_table()
536 static void aspeed_video_update(struct aspeed_video *video, u32 reg, u32 clear, in aspeed_video_update() argument
539 u32 t = readl(video->base + reg); in aspeed_video_update()
544 writel(t, video->base + reg); in aspeed_video_update()
545 v4l2_dbg(3, debug, &video->v4l2_dev, "update %03x[%08x -> %08x]\n", in aspeed_video_update()
546 reg, before, readl(video->base + reg)); in aspeed_video_update()
549 static u32 aspeed_video_read(struct aspeed_video *video, u32 reg) in aspeed_video_read() argument
551 u32 t = readl(video->base + reg); in aspeed_video_read()
553 v4l2_dbg(3, debug, &video->v4l2_dev, "read %03x[%08x]\n", reg, t); in aspeed_video_read()
557 static void aspeed_video_write(struct aspeed_video *video, u32 reg, u32 val) in aspeed_video_write() argument
559 writel(val, video->base + reg); in aspeed_video_write()
560 v4l2_dbg(3, debug, &video->v4l2_dev, "write %03x[%08x]\n", reg, in aspeed_video_write()
561 readl(video->base + reg)); in aspeed_video_write()
569 p->duration = in update_perf()
570 ktime_to_ms(ktime_sub(ktime_get(), p->last_sample)); in update_perf()
571 p->totaltime += p->duration; in update_perf()
573 p->duration_max = max(p->duration, p->duration_max); in update_perf()
574 p->duration_min = min(p->duration, p->duration_min); in update_perf()
575 v4l2_dbg(2, debug, &v->v4l2_dev, "time consumed: %d ms\n", in update_perf()
576 p->duration); in update_perf()
585 bool bcd_buf_need = (video->format != VIDEO_FMT_STANDARD); in aspeed_video_start_frame()
587 if (video->v4l2_input_status) { in aspeed_video_start_frame()
588 v4l2_dbg(1, debug, &video->v4l2_dev, "No signal; don't start frame\n"); in aspeed_video_start_frame()
594 v4l2_dbg(1, debug, &video->v4l2_dev, "Engine busy; don't start frame\n"); in aspeed_video_start_frame()
595 return -EBUSY; in aspeed_video_start_frame()
598 if (bcd_buf_need && !video->bcd.size) { in aspeed_video_start_frame()
599 if (!aspeed_video_alloc_buf(video, &video->bcd, in aspeed_video_start_frame()
601 dev_err(video->dev, "Failed to allocate BCD buffer\n"); in aspeed_video_start_frame()
602 dev_err(video->dev, "don't start frame\n"); in aspeed_video_start_frame()
603 return -ENOMEM; in aspeed_video_start_frame()
605 aspeed_video_write(video, VE_BCD_ADDR, video->bcd.dma); in aspeed_video_start_frame()
606 v4l2_dbg(1, debug, &video->v4l2_dev, "bcd addr(%pad) size(%d)\n", in aspeed_video_start_frame()
607 &video->bcd.dma, video->bcd.size); in aspeed_video_start_frame()
608 } else if (!bcd_buf_need && video->bcd.size) { in aspeed_video_start_frame()
609 aspeed_video_free_buf(video, &video->bcd); in aspeed_video_start_frame()
612 spin_lock_irqsave(&video->lock, flags); in aspeed_video_start_frame()
613 buf = list_first_entry_or_null(&video->buffers, in aspeed_video_start_frame()
616 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_start_frame()
617 v4l2_dbg(1, debug, &video->v4l2_dev, "No buffers; don't start frame\n"); in aspeed_video_start_frame()
618 return -EPROTO; in aspeed_video_start_frame()
621 set_bit(VIDEO_FRAME_INPRG, &video->flags); in aspeed_video_start_frame()
622 addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0); in aspeed_video_start_frame()
623 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_start_frame()
632 video->perf.last_sample = ktime_get(); in aspeed_video_start_frame()
646 /* Disable mode detect in order to re-trigger */ in aspeed_video_enable_mode_detect()
656 if (!test_bit(VIDEO_CLOCKS_ON, &video->flags)) in aspeed_video_off()
664 clk_disable(video->eclk); in aspeed_video_off()
665 clk_disable(video->vclk); in aspeed_video_off()
667 clear_bit(VIDEO_CLOCKS_ON, &video->flags); in aspeed_video_off()
672 if (test_bit(VIDEO_CLOCKS_ON, &video->flags)) in aspeed_video_on()
676 clk_enable(video->vclk); in aspeed_video_on()
677 clk_enable(video->eclk); in aspeed_video_on()
679 set_bit(VIDEO_CLOCKS_ON, &video->flags); in aspeed_video_on()
688 spin_lock_irqsave(&video->lock, flags); in aspeed_video_bufs_done()
689 list_for_each_entry(buf, &video->buffers, link) in aspeed_video_bufs_done()
690 vb2_buffer_done(&buf->vb.vb2_buf, state); in aspeed_video_bufs_done()
691 INIT_LIST_HEAD(&video->buffers); in aspeed_video_bufs_done()
692 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_bufs_done()
697 v4l2_dbg(1, debug, &video->v4l2_dev, "Resolution changed; resetting\n"); in aspeed_video_irq_res_change()
699 set_bit(VIDEO_RES_CHANGE, &video->flags); in aspeed_video_irq_res_change()
700 clear_bit(VIDEO_FRAME_INPRG, &video->flags); in aspeed_video_irq_res_change()
702 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_irq_res_change()
707 schedule_delayed_work(&video->res_work, delay); in aspeed_video_irq_res_change()
712 if (v->format == VIDEO_FMT_STANDARD) in aspeed_video_swap_src_buf()
716 if (IS_ALIGNED(v->sequence, 8)) in aspeed_video_swap_src_buf()
717 memset((u8 *)v->bcd.virt, 0x00, VE_BCD_BUFF_SIZE); in aspeed_video_swap_src_buf()
719 if (v->sequence & 0x01) { in aspeed_video_swap_src_buf()
720 aspeed_video_write(v, VE_SRC0_ADDR, v->srcs[1].dma); in aspeed_video_swap_src_buf()
721 aspeed_video_write(v, VE_SRC1_ADDR, v->srcs[0].dma); in aspeed_video_swap_src_buf()
723 aspeed_video_write(v, VE_SRC0_ADDR, v->srcs[0].dma); in aspeed_video_swap_src_buf()
724 aspeed_video_write(v, VE_SRC1_ADDR, v->srcs[1].dma); in aspeed_video_swap_src_buf()
739 v4l2_dbg(2, debug, &video->v4l2_dev, "irq sts=%#x %s%s%s%s\n", sts, in aspeed_video_irq()
742 sts & VE_INTERRUPT_CAPTURE_COMPLETE ? ", capture-done" : "", in aspeed_video_irq()
743 sts & VE_INTERRUPT_COMP_COMPLETE ? ", comp-done" : ""); in aspeed_video_irq()
747 * re-initialize in aspeed_video_irq()
755 if (test_bit(VIDEO_RES_DETECT, &video->flags)) { in aspeed_video_irq()
761 set_bit(VIDEO_MODE_DETECT_DONE, &video->flags); in aspeed_video_irq()
762 wake_up_interruptible_all(&video->wait); in aspeed_video_irq()
766 * detection; reset the engine and re-initialize in aspeed_video_irq()
778 video->comp_size_read); in aspeed_video_irq()
780 update_perf(&video->perf); in aspeed_video_irq()
782 spin_lock(&video->lock); in aspeed_video_irq()
783 clear_bit(VIDEO_FRAME_INPRG, &video->flags); in aspeed_video_irq()
784 buf = list_first_entry_or_null(&video->buffers, in aspeed_video_irq()
788 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, frame_size); in aspeed_video_irq()
795 if (video->format == VIDEO_FMT_STANDARD && in aspeed_video_irq()
796 list_is_last(&buf->link, &video->buffers)) { in aspeed_video_irq()
798 v4l2_dbg(1, debug, &video->v4l2_dev, "skip to keep last frame updated\n"); in aspeed_video_irq()
800 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in aspeed_video_irq()
801 buf->vb.sequence = video->sequence++; in aspeed_video_irq()
802 buf->vb.field = V4L2_FIELD_NONE; in aspeed_video_irq()
803 vb2_buffer_done(&buf->vb.vb2_buf, in aspeed_video_irq()
805 list_del(&buf->link); in aspeed_video_irq()
806 empty = list_empty(&video->buffers); in aspeed_video_irq()
809 spin_unlock(&video->lock); in aspeed_video_irq()
823 if (test_bit(VIDEO_STREAMING, &video->flags) && !empty) in aspeed_video_irq()
840 vsync_counter--; in aspeed_video_check_and_set_polarity()
845 hsync_counter--; in aspeed_video_check_and_set_polarity()
854 video->detected_timings.polarities &= in aspeed_video_check_and_set_polarity()
858 video->detected_timings.polarities |= in aspeed_video_check_and_set_polarity()
864 video->detected_timings.polarities &= in aspeed_video_check_and_set_polarity()
868 video->detected_timings.polarities |= in aspeed_video_check_and_set_polarity()
879 addr->virt = dma_alloc_coherent(video->dev, size, &addr->dma, in aspeed_video_alloc_buf()
881 if (!addr->virt) in aspeed_video_alloc_buf()
884 addr->size = size; in aspeed_video_alloc_buf()
891 dma_free_coherent(video->dev, addr->size, addr->virt, addr->dma); in aspeed_video_free_buf()
892 addr->size = 0; in aspeed_video_free_buf()
893 addr->dma = 0ULL; in aspeed_video_free_buf()
894 addr->virt = NULL; in aspeed_video_free_buf()
898 * Get the minimum HW-supported compression buffer size for the frame size.
899 * Assume worst-case JPEG compression size is 1/8 raw size. This should be
913 video->max_compressed_size = UINT_MAX; in aspeed_video_calc_compressed_size()
922 if (size < video->max_compressed_size) { in aspeed_video_calc_compressed_size()
924 video->max_compressed_size = size; in aspeed_video_calc_compressed_size()
932 v4l2_dbg(1, debug, &video->v4l2_dev, "Max compressed size: %#x\n", in aspeed_video_calc_compressed_size()
933 video->max_compressed_size); in aspeed_video_calc_compressed_size()
946 * +--+ +-------------------+ +--+
948 * +--+ +-----+ +-----+ +---+
949 * vsync+--+
950 * frame_top+--------+
951 * frame_bottom+----------------------------+
953 * +-------------------+
955 * +--+ +-----+ +-----+ +---+
957 * +--+ +--+
958 * vsync+-------------------------------+
959 * frame_top+-----+
960 * frame_bottom+-------------------------+
963 * +--+ +-------------------+ +--+
965 * +--+ +-----+ +-----+ +---+
966 * hsync+--+
967 * frame_left+--------+
968 * frame_right+----------------------------+
970 * +-------------------+
972 * +--+ +-----+ +-----+ +---+
974 * +--+ +--+
975 * hsync+-------------------------------+
976 * frame_left+-----+
977 * frame_right+-------------------------+
996 * Because ast-soc counts sync from sync's rising edge, the reg value in aspeed_video_get_timings()
999 if (vsync > det->height) in aspeed_video_get_timings()
1000 det->polarities &= ~V4L2_DV_VSYNC_POS_POL; in aspeed_video_get_timings()
1002 det->polarities |= V4L2_DV_VSYNC_POS_POL; in aspeed_video_get_timings()
1003 if (hsync > det->width) in aspeed_video_get_timings()
1004 det->polarities &= ~V4L2_DV_HSYNC_POS_POL; in aspeed_video_get_timings()
1006 det->polarities |= V4L2_DV_HSYNC_POS_POL; in aspeed_video_get_timings()
1008 if (det->polarities & V4L2_DV_VSYNC_POS_POL) { in aspeed_video_get_timings()
1009 det->vbackporch = v->frame_top - vsync; in aspeed_video_get_timings()
1010 det->vfrontporch = vtotal - v->frame_bottom; in aspeed_video_get_timings()
1011 det->vsync = vsync; in aspeed_video_get_timings()
1013 det->vbackporch = v->frame_top; in aspeed_video_get_timings()
1014 det->vfrontporch = vsync - v->frame_bottom; in aspeed_video_get_timings()
1015 det->vsync = vtotal - vsync; in aspeed_video_get_timings()
1018 if (det->polarities & V4L2_DV_HSYNC_POS_POL) { in aspeed_video_get_timings()
1019 det->hbackporch = v->frame_left - hsync; in aspeed_video_get_timings()
1020 det->hfrontporch = htotal - v->frame_right; in aspeed_video_get_timings()
1021 det->hsync = hsync; in aspeed_video_get_timings()
1023 det->hbackporch = v->frame_left; in aspeed_video_get_timings()
1024 det->hfrontporch = hsync - v->frame_right; in aspeed_video_get_timings()
1025 det->hsync = htotal - hsync; in aspeed_video_get_timings()
1029 #define res_check(v) test_and_clear_bit(VIDEO_MODE_DETECT_DONE, &(v)->flags)
1039 struct v4l2_bt_timings *det = &video->detected_timings; in aspeed_video_get_resolution()
1041 det->width = MIN_WIDTH; in aspeed_video_get_resolution()
1042 det->height = MIN_HEIGHT; in aspeed_video_get_resolution()
1043 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_get_resolution()
1044 memset(&video->perf, 0, sizeof(video->perf)); in aspeed_video_get_resolution()
1053 set_bit(VIDEO_RES_DETECT, &video->flags); in aspeed_video_get_resolution()
1058 rc = wait_event_interruptible_timeout(video->wait, in aspeed_video_get_resolution()
1062 v4l2_dbg(1, debug, &video->v4l2_dev, "Timed out; first mode detect\n"); in aspeed_video_get_resolution()
1063 clear_bit(VIDEO_RES_DETECT, &video->flags); in aspeed_video_get_resolution()
1078 rc = wait_event_interruptible_timeout(video->wait, in aspeed_video_get_resolution()
1081 clear_bit(VIDEO_RES_DETECT, &video->flags); in aspeed_video_get_resolution()
1083 v4l2_dbg(1, debug, &video->v4l2_dev, "Timed out; second mode detect\n"); in aspeed_video_get_resolution()
1090 video->frame_bottom = FIELD_GET(VE_SRC_TB_EDGE_DET_BOT, src_tb_edge); in aspeed_video_get_resolution()
1091 video->frame_top = FIELD_GET(VE_SRC_TB_EDGE_DET_TOP, src_tb_edge); in aspeed_video_get_resolution()
1093 if (video->frame_top > video->frame_bottom) in aspeed_video_get_resolution()
1096 video->frame_right = FIELD_GET(VE_SRC_LR_EDGE_DET_RT, src_lr_edge); in aspeed_video_get_resolution()
1097 video->frame_left = FIELD_GET(VE_SRC_LR_EDGE_DET_LEFT, src_lr_edge); in aspeed_video_get_resolution()
1099 if (video->frame_left > video->frame_right) in aspeed_video_get_resolution()
1106 v4l2_dbg(1, debug, &video->v4l2_dev, "Invalid resolution detected\n"); in aspeed_video_get_resolution()
1110 det->height = (video->frame_bottom - video->frame_top) + 1; in aspeed_video_get_resolution()
1111 det->width = (video->frame_right - video->frame_left) + 1; in aspeed_video_get_resolution()
1112 video->v4l2_input_status = 0; in aspeed_video_get_resolution()
1117 * Enable mode-detect watchdog, resolution-change watchdog and in aspeed_video_get_resolution()
1125 v4l2_dbg(1, debug, &video->v4l2_dev, "Got resolution: %dx%d\n", in aspeed_video_get_resolution()
1126 det->width, det->height); in aspeed_video_get_resolution()
1131 struct v4l2_bt_timings *act = &video->active_timings; in aspeed_video_set_resolution()
1132 unsigned int size = act->width * ALIGN(act->height, 8); in aspeed_video_set_resolution()
1137 if (!IS_ALIGNED(act->width, 64)) { in aspeed_video_set_resolution()
1143 * 64-pixels aligned value to minimize memory bandwidth in aspeed_video_set_resolution()
1146 u32 width = ALIGN(act->width, 64); in aspeed_video_set_resolution()
1148 aspeed_video_write(video, VE_CAP_WINDOW, width << 16 | act->height); in aspeed_video_set_resolution()
1149 size = width * ALIGN(act->height, 8); in aspeed_video_set_resolution()
1152 act->width << 16 | act->height); in aspeed_video_set_resolution()
1155 act->width << 16 | act->height); in aspeed_video_set_resolution()
1156 aspeed_video_write(video, VE_SRC_SCANLINE_OFFSET, act->width * 4); in aspeed_video_set_resolution()
1160 v4l2_dbg(1, debug, &video->v4l2_dev, "Capture: Sync Mode\n"); in aspeed_video_set_resolution()
1163 video->frame_left - 1) | in aspeed_video_set_resolution()
1165 video->frame_right)); in aspeed_video_set_resolution()
1167 FIELD_PREP(VE_TGS_FIRST, video->frame_top) | in aspeed_video_set_resolution()
1169 video->frame_bottom + 1)); in aspeed_video_set_resolution()
1174 v4l2_dbg(1, debug, &video->v4l2_dev, "Capture: Direct Mode\n"); in aspeed_video_set_resolution()
1182 if (size != video->srcs[0].size) { in aspeed_video_set_resolution()
1183 if (video->srcs[0].size) in aspeed_video_set_resolution()
1184 aspeed_video_free_buf(video, &video->srcs[0]); in aspeed_video_set_resolution()
1185 if (video->srcs[1].size) in aspeed_video_set_resolution()
1186 aspeed_video_free_buf(video, &video->srcs[1]); in aspeed_video_set_resolution()
1188 if (!aspeed_video_alloc_buf(video, &video->srcs[0], size)) in aspeed_video_set_resolution()
1190 if (!aspeed_video_alloc_buf(video, &video->srcs[1], size)) in aspeed_video_set_resolution()
1193 v4l2_dbg(1, debug, &video->v4l2_dev, "src buf0 addr(%pad) size(%d)\n", in aspeed_video_set_resolution()
1194 &video->srcs[0].dma, video->srcs[0].size); in aspeed_video_set_resolution()
1195 v4l2_dbg(1, debug, &video->v4l2_dev, "src buf1 addr(%pad) size(%d)\n", in aspeed_video_set_resolution()
1196 &video->srcs[1].dma, video->srcs[1].size); in aspeed_video_set_resolution()
1197 aspeed_video_write(video, VE_SRC0_ADDR, video->srcs[0].dma); in aspeed_video_set_resolution()
1198 aspeed_video_write(video, VE_SRC1_ADDR, video->srcs[1].dma); in aspeed_video_set_resolution()
1204 dev_err(video->dev, "Failed to allocate source buffers\n"); in aspeed_video_set_resolution()
1206 if (video->srcs[0].size) in aspeed_video_set_resolution()
1207 aspeed_video_free_buf(video, &video->srcs[0]); in aspeed_video_set_resolution()
1212 u8 jpeg_hq_quality = clamp((int)video->jpeg_hq_quality - 1, 0, in aspeed_video_update_regs()
1213 ASPEED_VIDEO_JPEG_NUM_QUALITIES - 1); in aspeed_video_update_regs()
1214 u32 comp_ctrl = FIELD_PREP(VE_COMP_CTRL_DCT_LUM, video->jpeg_quality) | in aspeed_video_update_regs()
1215 FIELD_PREP(VE_COMP_CTRL_DCT_CHR, video->jpeg_quality | 0x10) | in aspeed_video_update_regs()
1216 FIELD_PREP(VE_COMP_CTRL_EN_HQ, video->hq_mode) | in aspeed_video_update_regs()
1222 v4l2_dbg(1, debug, &video->v4l2_dev, "framerate(%d)\n", in aspeed_video_update_regs()
1223 video->frame_rate); in aspeed_video_update_regs()
1224 v4l2_dbg(1, debug, &video->v4l2_dev, "jpeg format(%s) subsample(%s)\n", in aspeed_video_update_regs()
1225 format_str[video->format], in aspeed_video_update_regs()
1226 video->yuv420 ? "420" : "444"); in aspeed_video_update_regs()
1227 v4l2_dbg(1, debug, &video->v4l2_dev, "compression quality(%d)\n", in aspeed_video_update_regs()
1228 video->jpeg_quality); in aspeed_video_update_regs()
1229 v4l2_dbg(1, debug, &video->v4l2_dev, "hq_mode(%s) hq_quality(%d)\n", in aspeed_video_update_regs()
1230 video->hq_mode ? "on" : "off", video->jpeg_hq_quality); in aspeed_video_update_regs()
1232 if (video->format == VIDEO_FMT_ASPEED) in aspeed_video_update_regs()
1237 if (video->frame_rate) in aspeed_video_update_regs()
1238 ctrl |= FIELD_PREP(VE_CTRL_FRC, video->frame_rate); in aspeed_video_update_regs()
1240 if (video->format == VIDEO_FMT_STANDARD) { in aspeed_video_update_regs()
1241 comp_ctrl &= ~FIELD_PREP(VE_COMP_CTRL_EN_HQ, video->hq_mode); in aspeed_video_update_regs()
1242 seq_ctrl |= video->jpeg_mode; in aspeed_video_update_regs()
1245 if (video->yuv420) in aspeed_video_update_regs()
1248 if (video->jpeg.virt) in aspeed_video_update_regs()
1249 aspeed_video_update_jpeg_table(video->jpeg.virt, video->yuv420); in aspeed_video_update_regs()
1253 video->jpeg_mode | VE_SEQ_CTRL_YUV420, in aspeed_video_update_regs()
1280 aspeed_video_write(video, VE_JPEG_ADDR, video->jpeg.dma); in aspeed_video_init_regs()
1314 video->active_timings = video->detected_timings; in aspeed_video_start()
1317 video->pix_fmt.width = video->active_timings.width; in aspeed_video_start()
1318 video->pix_fmt.height = video->active_timings.height; in aspeed_video_start()
1319 video->pix_fmt.sizeimage = video->max_compressed_size; in aspeed_video_start()
1324 set_bit(VIDEO_STOPPED, &video->flags); in aspeed_video_stop()
1325 cancel_delayed_work_sync(&video->res_work); in aspeed_video_stop()
1329 if (video->srcs[0].size) in aspeed_video_stop()
1330 aspeed_video_free_buf(video, &video->srcs[0]); in aspeed_video_stop()
1332 if (video->srcs[1].size) in aspeed_video_stop()
1333 aspeed_video_free_buf(video, &video->srcs[1]); in aspeed_video_stop()
1335 if (video->bcd.size) in aspeed_video_stop()
1336 aspeed_video_free_buf(video, &video->bcd); in aspeed_video_stop()
1338 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_stop()
1339 video->flags = 0; in aspeed_video_stop()
1345 strscpy(cap->driver, DEVICE_NAME, sizeof(cap->driver)); in aspeed_video_querycap()
1346 strscpy(cap->card, "Aspeed Video Engine", sizeof(cap->card)); in aspeed_video_querycap()
1347 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", in aspeed_video_querycap()
1358 if (f->index) in aspeed_video_enum_format()
1359 return -EINVAL; in aspeed_video_enum_format()
1361 f->pixelformat = video->pix_fmt.pixelformat; in aspeed_video_enum_format()
1371 f->fmt.pix = video->pix_fmt; in aspeed_video_get_format()
1381 if (vb2_is_busy(&video->queue)) in aspeed_video_set_format()
1382 return -EBUSY; in aspeed_video_set_format()
1384 switch (f->fmt.pix.pixelformat) { in aspeed_video_set_format()
1386 video->format = VIDEO_FMT_STANDARD; in aspeed_video_set_format()
1389 video->format = VIDEO_FMT_ASPEED; in aspeed_video_set_format()
1392 return -EINVAL; in aspeed_video_set_format()
1394 video->pix_fmt.pixelformat = f->fmt.pix.pixelformat; in aspeed_video_set_format()
1404 if (inp->index) in aspeed_video_enum_input()
1405 return -EINVAL; in aspeed_video_enum_input()
1407 strscpy(inp->name, "Host VGA capture", sizeof(inp->name)); in aspeed_video_enum_input()
1408 inp->type = V4L2_INPUT_TYPE_CAMERA; in aspeed_video_enum_input()
1409 inp->capabilities = V4L2_IN_CAP_DV_TIMINGS; in aspeed_video_enum_input()
1410 inp->status = video->v4l2_input_status; in aspeed_video_enum_input()
1425 return -EINVAL; in aspeed_video_set_input()
1435 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in aspeed_video_get_parm()
1436 a->parm.capture.readbuffers = ASPEED_VIDEO_V4L2_MIN_BUF_REQ; in aspeed_video_get_parm()
1437 a->parm.capture.timeperframe.numerator = 1; in aspeed_video_get_parm()
1438 if (!video->frame_rate) in aspeed_video_get_parm()
1439 a->parm.capture.timeperframe.denominator = MAX_FRAME_RATE; in aspeed_video_get_parm()
1441 a->parm.capture.timeperframe.denominator = video->frame_rate; in aspeed_video_get_parm()
1452 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in aspeed_video_set_parm()
1453 a->parm.capture.readbuffers = ASPEED_VIDEO_V4L2_MIN_BUF_REQ; in aspeed_video_set_parm()
1455 if (a->parm.capture.timeperframe.numerator) in aspeed_video_set_parm()
1456 frame_rate = a->parm.capture.timeperframe.denominator / in aspeed_video_set_parm()
1457 a->parm.capture.timeperframe.numerator; in aspeed_video_set_parm()
1461 a->parm.capture.timeperframe.denominator = MAX_FRAME_RATE; in aspeed_video_set_parm()
1462 a->parm.capture.timeperframe.numerator = 1; in aspeed_video_set_parm()
1465 if (video->frame_rate != frame_rate) { in aspeed_video_set_parm()
1466 video->frame_rate = frame_rate; in aspeed_video_set_parm()
1479 if (fsize->index) in aspeed_video_enum_framesizes()
1480 return -EINVAL; in aspeed_video_enum_framesizes()
1482 if (fsize->pixel_format != V4L2_PIX_FMT_JPEG) in aspeed_video_enum_framesizes()
1483 return -EINVAL; in aspeed_video_enum_framesizes()
1485 fsize->discrete.width = video->pix_fmt.width; in aspeed_video_enum_framesizes()
1486 fsize->discrete.height = video->pix_fmt.height; in aspeed_video_enum_framesizes()
1487 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; in aspeed_video_enum_framesizes()
1497 if (fival->index) in aspeed_video_enum_frameintervals()
1498 return -EINVAL; in aspeed_video_enum_frameintervals()
1500 if (fival->width != video->detected_timings.width || in aspeed_video_enum_frameintervals()
1501 fival->height != video->detected_timings.height) in aspeed_video_enum_frameintervals()
1502 return -EINVAL; in aspeed_video_enum_frameintervals()
1504 if (fival->pixel_format != V4L2_PIX_FMT_JPEG) in aspeed_video_enum_frameintervals()
1505 return -EINVAL; in aspeed_video_enum_frameintervals()
1507 fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS; in aspeed_video_enum_frameintervals()
1509 fival->stepwise.min.denominator = MAX_FRAME_RATE; in aspeed_video_enum_frameintervals()
1510 fival->stepwise.min.numerator = 1; in aspeed_video_enum_frameintervals()
1511 fival->stepwise.max.denominator = 1; in aspeed_video_enum_frameintervals()
1512 fival->stepwise.max.numerator = 1; in aspeed_video_enum_frameintervals()
1513 fival->stepwise.step = fival->stepwise.max; in aspeed_video_enum_frameintervals()
1523 if (timings->bt.width == video->active_timings.width && in aspeed_video_set_dv_timings()
1524 timings->bt.height == video->active_timings.height) in aspeed_video_set_dv_timings()
1527 if (vb2_is_busy(&video->queue)) in aspeed_video_set_dv_timings()
1528 return -EBUSY; in aspeed_video_set_dv_timings()
1530 video->active_timings = timings->bt; in aspeed_video_set_dv_timings()
1534 video->pix_fmt.width = timings->bt.width; in aspeed_video_set_dv_timings()
1535 video->pix_fmt.height = timings->bt.height; in aspeed_video_set_dv_timings()
1536 video->pix_fmt.sizeimage = video->max_compressed_size; in aspeed_video_set_dv_timings()
1538 timings->type = V4L2_DV_BT_656_1120; in aspeed_video_set_dv_timings()
1540 v4l2_dbg(1, debug, &video->v4l2_dev, "set new timings(%dx%d)\n", in aspeed_video_set_dv_timings()
1541 timings->bt.width, timings->bt.height); in aspeed_video_set_dv_timings()
1551 timings->type = V4L2_DV_BT_656_1120; in aspeed_video_get_dv_timings()
1552 timings->bt = video->active_timings; in aspeed_video_get_dv_timings()
1568 if (file->f_flags & O_NONBLOCK) { in aspeed_video_query_dv_timings()
1569 if (test_bit(VIDEO_RES_CHANGE, &video->flags)) in aspeed_video_query_dv_timings()
1570 return -EAGAIN; in aspeed_video_query_dv_timings()
1572 rc = wait_event_interruptible(video->wait, in aspeed_video_query_dv_timings()
1574 &video->flags)); in aspeed_video_query_dv_timings()
1576 return -EINTR; in aspeed_video_query_dv_timings()
1579 timings->type = V4L2_DV_BT_656_1120; in aspeed_video_query_dv_timings()
1580 timings->bt = video->detected_timings; in aspeed_video_query_dv_timings()
1582 return video->v4l2_input_status ? -ENOLINK : 0; in aspeed_video_query_dv_timings()
1603 switch (sub->type) { in aspeed_video_sub_event()
1650 struct aspeed_video *video = container_of(ctrl->handler, in aspeed_video_set_ctrl()
1654 switch (ctrl->id) { in aspeed_video_set_ctrl()
1656 video->jpeg_quality = ctrl->val; in aspeed_video_set_ctrl()
1657 if (test_bit(VIDEO_STREAMING, &video->flags)) in aspeed_video_set_ctrl()
1661 video->yuv420 = (ctrl->val == V4L2_JPEG_CHROMA_SUBSAMPLING_420); in aspeed_video_set_ctrl()
1662 if (test_bit(VIDEO_STREAMING, &video->flags)) in aspeed_video_set_ctrl()
1666 video->hq_mode = ctrl->val; in aspeed_video_set_ctrl()
1667 if (test_bit(VIDEO_STREAMING, &video->flags)) in aspeed_video_set_ctrl()
1671 video->jpeg_hq_quality = ctrl->val; in aspeed_video_set_ctrl()
1672 if (test_bit(VIDEO_STREAMING, &video->flags)) in aspeed_video_set_ctrl()
1676 return -EINVAL; in aspeed_video_set_ctrl()
1717 if (test_bit(VIDEO_STOPPED, &video->flags)) in aspeed_video_resolution_work()
1726 if (video->detected_timings.width != video->active_timings.width || in aspeed_video_resolution_work()
1727 video->detected_timings.height != video->active_timings.height) { in aspeed_video_resolution_work()
1733 v4l2_dbg(1, debug, &video->v4l2_dev, "fire source change event\n"); in aspeed_video_resolution_work()
1734 v4l2_event_queue(&video->vdev, &ev); in aspeed_video_resolution_work()
1735 } else if (test_bit(VIDEO_STREAMING, &video->flags)) { in aspeed_video_resolution_work()
1741 clear_bit(VIDEO_RES_CHANGE, &video->flags); in aspeed_video_resolution_work()
1742 wake_up_interruptible_all(&video->wait); in aspeed_video_resolution_work()
1750 mutex_lock(&video->video_lock); in aspeed_video_open()
1754 mutex_unlock(&video->video_lock); in aspeed_video_open()
1761 mutex_unlock(&video->video_lock); in aspeed_video_open()
1771 mutex_lock(&video->video_lock); in aspeed_video_release()
1778 mutex_unlock(&video->video_lock); in aspeed_video_release()
1802 if (sizes[0] < video->max_compressed_size) in aspeed_video_queue_setup()
1803 return -EINVAL; in aspeed_video_queue_setup()
1809 sizes[0] = video->max_compressed_size; in aspeed_video_queue_setup()
1816 struct aspeed_video *video = vb2_get_drv_priv(vb->vb2_queue); in aspeed_video_buf_prepare()
1818 if (vb2_plane_size(vb, 0) < video->max_compressed_size) in aspeed_video_buf_prepare()
1819 return -EINVAL; in aspeed_video_buf_prepare()
1830 video->sequence = 0; in aspeed_video_start_streaming()
1831 video->perf.duration_max = 0; in aspeed_video_start_streaming()
1832 video->perf.duration_min = 0xffffffff; in aspeed_video_start_streaming()
1842 set_bit(VIDEO_STREAMING, &video->flags); in aspeed_video_start_streaming()
1851 clear_bit(VIDEO_STREAMING, &video->flags); in aspeed_video_stop_streaming()
1853 rc = wait_event_timeout(video->wait, in aspeed_video_stop_streaming()
1854 !test_bit(VIDEO_FRAME_INPRG, &video->flags), in aspeed_video_stop_streaming()
1857 v4l2_dbg(1, debug, &video->v4l2_dev, "Timed out when stopping streaming\n"); in aspeed_video_stop_streaming()
1877 struct aspeed_video *video = vb2_get_drv_priv(vb->vb2_queue); in aspeed_video_buf_queue()
1882 spin_lock_irqsave(&video->lock, flags); in aspeed_video_buf_queue()
1883 empty = list_empty(&video->buffers); in aspeed_video_buf_queue()
1884 list_add_tail(&avb->link, &video->buffers); in aspeed_video_buf_queue()
1885 spin_unlock_irqrestore(&video->lock, flags); in aspeed_video_buf_queue()
1887 if (test_bit(VIDEO_STREAMING, &video->flags) && in aspeed_video_buf_queue()
1888 !test_bit(VIDEO_FRAME_INPRG, &video->flags) && empty) in aspeed_video_buf_queue()
1905 struct aspeed_video *v = s->private; in aspeed_video_debugfs_show()
1913 seq_printf(s, " %-20s:\tDirect fetch\n", "Mode"); in aspeed_video_debugfs_show()
1914 seq_printf(s, " %-20s:\t%s\n", "VGA bpp mode", in aspeed_video_debugfs_show()
1917 seq_printf(s, " %-20s:\tSync\n", "Mode"); in aspeed_video_debugfs_show()
1918 seq_printf(s, " %-20s:\t%s\n", "Video source", in aspeed_video_debugfs_show()
1921 seq_printf(s, " %-20s:\t%s\n", "DE source", in aspeed_video_debugfs_show()
1924 seq_printf(s, " %-20s:\t%s\n", "Cursor overlay", in aspeed_video_debugfs_show()
1929 seq_printf(s, " %-20s:\t%s\n", "Signal", in aspeed_video_debugfs_show()
1930 v->v4l2_input_status ? "Unlock" : "Lock"); in aspeed_video_debugfs_show()
1931 seq_printf(s, " %-20s:\t%d\n", "Width", v->pix_fmt.width); in aspeed_video_debugfs_show()
1932 seq_printf(s, " %-20s:\t%d\n", "Height", v->pix_fmt.height); in aspeed_video_debugfs_show()
1933 seq_printf(s, " %-20s:\t%d\n", "FRC", v->frame_rate); in aspeed_video_debugfs_show()
1938 seq_printf(s, " %-20s:\t%s\n", "Format", format_str[v->format]); in aspeed_video_debugfs_show()
1939 seq_printf(s, " %-20s:\t%s\n", "Subsampling", in aspeed_video_debugfs_show()
1940 v->yuv420 ? "420" : "444"); in aspeed_video_debugfs_show()
1941 seq_printf(s, " %-20s:\t%d\n", "Quality", v->jpeg_quality); in aspeed_video_debugfs_show()
1942 if (v->format == VIDEO_FMT_ASPEED) { in aspeed_video_debugfs_show()
1943 seq_printf(s, " %-20s:\t%s\n", "HQ Mode", in aspeed_video_debugfs_show()
1944 v->hq_mode ? "on" : "off"); in aspeed_video_debugfs_show()
1945 seq_printf(s, " %-20s:\t%d\n", "HQ Quality", in aspeed_video_debugfs_show()
1946 v->hq_mode ? v->jpeg_hq_quality : 0); in aspeed_video_debugfs_show()
1952 seq_printf(s, " %-20s:\t%d\n", "Frame#", v->sequence); in aspeed_video_debugfs_show()
1953 seq_printf(s, " %-20s:\n", "Frame Duration(ms)"); in aspeed_video_debugfs_show()
1954 seq_printf(s, " %-18s:\t%d\n", "Now", v->perf.duration); in aspeed_video_debugfs_show()
1955 seq_printf(s, " %-18s:\t%d\n", "Min", v->perf.duration_min); in aspeed_video_debugfs_show()
1956 seq_printf(s, " %-18s:\t%d\n", "Max", v->perf.duration_max); in aspeed_video_debugfs_show()
1957 seq_printf(s, " %-20s:\t%d\n", "FPS", in aspeed_video_debugfs_show()
1958 (v->perf.totaltime && v->sequence) ? in aspeed_video_debugfs_show()
1959 1000 / (v->perf.totaltime / v->sequence) : 0); in aspeed_video_debugfs_show()
1988 struct v4l2_device *v4l2_dev = &video->v4l2_dev; in aspeed_video_setup_video()
1989 struct vb2_queue *vbq = &video->queue; in aspeed_video_setup_video()
1990 struct video_device *vdev = &video->vdev; in aspeed_video_setup_video()
1991 struct v4l2_ctrl_handler *hdl = &video->ctrl_handler; in aspeed_video_setup_video()
1994 video->pix_fmt.pixelformat = V4L2_PIX_FMT_JPEG; in aspeed_video_setup_video()
1995 video->pix_fmt.field = V4L2_FIELD_NONE; in aspeed_video_setup_video()
1996 video->pix_fmt.colorspace = V4L2_COLORSPACE_SRGB; in aspeed_video_setup_video()
1997 video->pix_fmt.quantization = V4L2_QUANTIZATION_FULL_RANGE; in aspeed_video_setup_video()
1998 video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; in aspeed_video_setup_video()
2000 rc = v4l2_device_register(video->dev, v4l2_dev); in aspeed_video_setup_video()
2002 dev_err(video->dev, "Failed to register v4l2 device\n"); in aspeed_video_setup_video()
2009 ASPEED_VIDEO_JPEG_NUM_QUALITIES - 1, 1, 0); in aspeed_video_setup_video()
2017 rc = hdl->error; in aspeed_video_setup_video()
2019 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_setup_video()
2022 dev_err(video->dev, "Failed to init controls: %d\n", rc); in aspeed_video_setup_video()
2026 v4l2_dev->ctrl_handler = hdl; in aspeed_video_setup_video()
2028 vbq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in aspeed_video_setup_video()
2029 vbq->io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF; in aspeed_video_setup_video()
2030 vbq->dev = v4l2_dev->dev; in aspeed_video_setup_video()
2031 vbq->lock = &video->video_lock; in aspeed_video_setup_video()
2032 vbq->ops = &aspeed_video_vb2_ops; in aspeed_video_setup_video()
2033 vbq->mem_ops = &vb2_dma_contig_memops; in aspeed_video_setup_video()
2034 vbq->drv_priv = video; in aspeed_video_setup_video()
2035 vbq->buf_struct_size = sizeof(struct aspeed_video_buffer); in aspeed_video_setup_video()
2036 vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in aspeed_video_setup_video()
2037 vbq->min_queued_buffers = ASPEED_VIDEO_V4L2_MIN_BUF_REQ; in aspeed_video_setup_video()
2041 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_setup_video()
2044 dev_err(video->dev, "Failed to init vb2 queue\n"); in aspeed_video_setup_video()
2048 vdev->queue = vbq; in aspeed_video_setup_video()
2049 vdev->fops = &aspeed_video_v4l2_fops; in aspeed_video_setup_video()
2050 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in aspeed_video_setup_video()
2052 vdev->v4l2_dev = v4l2_dev; in aspeed_video_setup_video()
2053 strscpy(vdev->name, DEVICE_NAME, sizeof(vdev->name)); in aspeed_video_setup_video()
2054 vdev->vfl_type = VFL_TYPE_VIDEO; in aspeed_video_setup_video()
2055 vdev->vfl_dir = VFL_DIR_RX; in aspeed_video_setup_video()
2056 vdev->release = video_device_release_empty; in aspeed_video_setup_video()
2057 vdev->ioctl_ops = &aspeed_video_ioctl_ops; in aspeed_video_setup_video()
2058 vdev->lock = &video->video_lock; in aspeed_video_setup_video()
2063 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_setup_video()
2066 dev_err(video->dev, "Failed to register video device\n"); in aspeed_video_setup_video()
2077 struct device *dev = video->dev; in aspeed_video_init()
2079 irq = irq_of_parse_and_map(dev->of_node, 0); in aspeed_video_init()
2082 return -ENODEV; in aspeed_video_init()
2091 dev_info(video->dev, "irq %d\n", irq); in aspeed_video_init()
2093 video->eclk = devm_clk_get(dev, "eclk"); in aspeed_video_init()
2094 if (IS_ERR(video->eclk)) { in aspeed_video_init()
2096 return PTR_ERR(video->eclk); in aspeed_video_init()
2099 rc = clk_prepare(video->eclk); in aspeed_video_init()
2103 video->vclk = devm_clk_get(dev, "vclk"); in aspeed_video_init()
2104 if (IS_ERR(video->vclk)) { in aspeed_video_init()
2106 rc = PTR_ERR(video->vclk); in aspeed_video_init()
2110 rc = clk_prepare(video->vclk); in aspeed_video_init()
2122 if (!aspeed_video_alloc_buf(video, &video->jpeg, in aspeed_video_init()
2125 rc = -ENOMEM; in aspeed_video_init()
2128 dev_info(video->dev, "alloc mem size(%d) at %pad for jpeg header\n", in aspeed_video_init()
2129 VE_JPEG_HEADER_SIZE, &video->jpeg.dma); in aspeed_video_init()
2131 aspeed_video_init_jpeg_table(video->jpeg.virt, video->yuv420); in aspeed_video_init()
2137 clk_unprepare(video->vclk); in aspeed_video_init()
2139 clk_unprepare(video->eclk); in aspeed_video_init()
2145 { .compatible = "aspeed,ast2400-video-engine", .data = &ast2400_config },
2146 { .compatible = "aspeed,ast2500-video-engine", .data = &ast2500_config },
2147 { .compatible = "aspeed,ast2600-video-engine", .data = &ast2600_config },
2158 video = devm_kzalloc(&pdev->dev, sizeof(*video), GFP_KERNEL); in aspeed_video_probe()
2160 return -ENOMEM; in aspeed_video_probe()
2162 video->base = devm_platform_ioremap_resource(pdev, 0); in aspeed_video_probe()
2163 if (IS_ERR(video->base)) in aspeed_video_probe()
2164 return PTR_ERR(video->base); in aspeed_video_probe()
2166 config = of_device_get_match_data(&pdev->dev); in aspeed_video_probe()
2168 return -ENODEV; in aspeed_video_probe()
2170 video->jpeg_mode = config->jpeg_mode; in aspeed_video_probe()
2171 video->comp_size_read = config->comp_size_read; in aspeed_video_probe()
2173 video->frame_rate = 30; in aspeed_video_probe()
2174 video->jpeg_hq_quality = 1; in aspeed_video_probe()
2175 video->dev = &pdev->dev; in aspeed_video_probe()
2176 spin_lock_init(&video->lock); in aspeed_video_probe()
2177 mutex_init(&video->video_lock); in aspeed_video_probe()
2178 init_waitqueue_head(&video->wait); in aspeed_video_probe()
2179 INIT_DELAYED_WORK(&video->res_work, aspeed_video_resolution_work); in aspeed_video_probe()
2180 INIT_LIST_HEAD(&video->buffers); in aspeed_video_probe()
2188 aspeed_video_free_buf(video, &video->jpeg); in aspeed_video_probe()
2189 clk_unprepare(video->vclk); in aspeed_video_probe()
2190 clk_unprepare(video->eclk); in aspeed_video_probe()
2201 struct device *dev = &pdev->dev; in aspeed_video_remove()
2209 clk_unprepare(video->vclk); in aspeed_video_remove()
2210 clk_unprepare(video->eclk); in aspeed_video_remove()
2212 vb2_video_unregister_device(&video->vdev); in aspeed_video_remove()
2214 v4l2_ctrl_handler_free(&video->ctrl_handler); in aspeed_video_remove()
2218 aspeed_video_free_buf(video, &video->jpeg); in aspeed_video_remove()
2235 MODULE_PARM_DESC(debug, "Debug level (0=off,1=info,2=debug,3=reg ops)");