Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1416122pxb; Thu, 21 Oct 2021 23:58:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoyWWFNusfB6ESv1Jupd7h/19K7k6GbXH+l3jni+P7pYOZkl36ZZvvhgO1EpsV8lnTSbYD X-Received: by 2002:a17:90a:a586:: with SMTP id b6mr12128009pjq.244.1634885898348; Thu, 21 Oct 2021 23:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634885898; cv=none; d=google.com; s=arc-20160816; b=IcMe/c75BAxP2gzTR9Uz+hkPPIYCd1ifdeLvq3aNWPCdcIjodzpV9uMNEgB4CGAIDg yjFumWfiKPF9g5DIhgWHMbqZeXGbANqqvev5KgcZLGhxpoBtSV68TDY/VMvbGGByENxb wTYhuGSQRk8chJVEB8yjABVNMqQ3jGDUP1lQnYByqTab3ltPfw6Zd7+7T6MprvIJKllr +7shh64pE5Ou0cpmjMTKCUyWVRVZc0MJz/60JD8ZeIK2cS/4Du+LD9suethBuqxTsr3p B1JcECf+JD5yF7YPKBwizenF08VKnMnJpVg4oyp7IdPdMB0UHBTUTc4COYycRplIzqKG pMzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=JrJeBqR1V/oLXaJyVdZkdcgTy2BRR9CgWYAKD15FT8E=; b=YruLzXglns225SjcrPJlpb4rMkYpTVj1n1QV9GWnbFtFTIOoYsF8kr2yDjIv1gOGAG NBgJeT5dYKR1Lp9JCgkp0S8jWde6cHgm7Nm1UtF7droS/Jy2GxlmFi9eqBEhvPsTDb22 4KOjE5R41+W2m08rR4gQ2JA8ZzodvA/SlUscy7baEbtgRWiJj2qFIbdeE9+WExZI71GF Xz9/Z06JCHcxYMcoUrlFW09/2JJRblGZtIoFAb+Ur4RGirvk4h1YgRQY4pAIW7CnLKC3 0B3OXBl/wikK3yEtAbH0WOxxAd6pSPqtH0j1TFey7jOwlLna0R3gGfH6mGDOWkVPDe+7 9xbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y2si11950980pfi.335.2021.10.21.23.58.03; Thu, 21 Oct 2021 23:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232435AbhJVG6d (ORCPT + 99 others); Fri, 22 Oct 2021 02:58:33 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:10220 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232464AbhJVG6V (ORCPT ); Fri, 22 Oct 2021 02:58:21 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 19M6XGfJ087036; Fri, 22 Oct 2021 14:33:16 +0800 (GMT-8) (envelope-from jammy_huang@aspeedtech.com) Received: from JammyHuang-PC.aspeed.com (192.168.2.115) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 22 Oct 2021 14:55:22 +0800 From: Jammy Huang To: , , , , , , , , Subject: [PATCH v3 4/7] media: aspeed: refactor to gather format/compress settings Date: Fri, 22 Oct 2021 14:55:36 +0800 Message-ID: <20211022065539.12392-5-jammy_huang@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211022065539.12392-1-jammy_huang@aspeedtech.com> References: <20211022065539.12392-1-jammy_huang@aspeedtech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.2.115] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 19M6XGfJ087036 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add API, aspeed_video_update_regs(), to gather format/compress settings which are controlled by user. Signed-off-by: Jammy Huang --- drivers/media/platform/aspeed-video.c | 69 ++++++++++++++------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/drivers/media/platform/aspeed-video.c b/drivers/media/platform/aspeed-video.c index 328f3ec125e2..cafbffe1ef69 100644 --- a/drivers/media/platform/aspeed-video.c +++ b/drivers/media/platform/aspeed-video.c @@ -967,20 +967,42 @@ static void aspeed_video_set_resolution(struct aspeed_video *video) aspeed_video_free_buf(video, &video->srcs[0]); } -static void aspeed_video_init_regs(struct aspeed_video *video) +static void aspeed_video_update_regs(struct aspeed_video *video) { u32 comp_ctrl = VE_COMP_CTRL_RSVD | FIELD_PREP(VE_COMP_CTRL_DCT_LUM, video->jpeg_quality) | FIELD_PREP(VE_COMP_CTRL_DCT_CHR, video->jpeg_quality | 0x10); - u32 ctrl = VE_CTRL_AUTO_OR_CURSOR; + u32 ctrl = 0; u32 seq_ctrl = VE_SEQ_CTRL_JPEG_MODE; + v4l2_dbg(1, debug, &video->v4l2_dev, "framerate(%d)\n", + video->frame_rate); + v4l2_dbg(1, debug, &video->v4l2_dev, "subsample(%s)\n", + video->yuv420 ? "420" : "444"); + v4l2_dbg(1, debug, &video->v4l2_dev, "compression quality(%d)\n", + video->jpeg_quality); + if (video->frame_rate) ctrl |= FIELD_PREP(VE_CTRL_FRC, video->frame_rate); if (video->yuv420) seq_ctrl |= VE_SEQ_CTRL_YUV420; + if (video->jpeg.virt) + aspeed_video_update_jpeg_table(video->jpeg.virt, video->yuv420); + + /* Set control registers */ + aspeed_video_update(video, VE_SEQ_CTRL, + VE_SEQ_CTRL_JPEG_MODE | VE_SEQ_CTRL_YUV420, + seq_ctrl); + aspeed_video_update(video, VE_CTRL, VE_CTRL_FRC, ctrl); + aspeed_video_update(video, VE_COMP_CTRL, + VE_COMP_CTRL_DCT_LUM | VE_COMP_CTRL_DCT_CHR, + comp_ctrl); +} + +static void aspeed_video_init_regs(struct aspeed_video *video) +{ /* Unlock VE registers */ aspeed_video_write(video, VE_PROTECTION_KEY, VE_PROTECTION_KEY_UNLOCK); @@ -995,9 +1017,8 @@ static void aspeed_video_init_regs(struct aspeed_video *video) aspeed_video_write(video, VE_JPEG_ADDR, video->jpeg.dma); /* Set control registers */ - aspeed_video_write(video, VE_SEQ_CTRL, seq_ctrl); - aspeed_video_write(video, VE_CTRL, ctrl); - aspeed_video_write(video, VE_COMP_CTRL, comp_ctrl); + aspeed_video_write(video, VE_CTRL, VE_CTRL_AUTO_OR_CURSOR); + aspeed_video_write(video, VE_COMP_CTRL, VE_COMP_CTRL_RSVD); /* Don't downscale */ aspeed_video_write(video, VE_SCALING_FACTOR, 0x10001000); @@ -1326,27 +1347,6 @@ static const struct v4l2_ioctl_ops aspeed_video_ioctl_ops = { .vidioc_unsubscribe_event = v4l2_event_unsubscribe, }; -static void aspeed_video_update_jpeg_quality(struct aspeed_video *video) -{ - u32 comp_ctrl = FIELD_PREP(VE_COMP_CTRL_DCT_LUM, video->jpeg_quality) | - FIELD_PREP(VE_COMP_CTRL_DCT_CHR, video->jpeg_quality | 0x10); - - aspeed_video_update(video, VE_COMP_CTRL, - VE_COMP_CTRL_DCT_LUM | VE_COMP_CTRL_DCT_CHR, - comp_ctrl); -} - -static void aspeed_video_update_subsampling(struct aspeed_video *video) -{ - if (video->jpeg.virt) - aspeed_video_update_jpeg_table(video->jpeg.virt, video->yuv420); - - if (video->yuv420) - aspeed_video_update(video, VE_SEQ_CTRL, 0, VE_SEQ_CTRL_YUV420); - else - aspeed_video_update(video, VE_SEQ_CTRL, VE_SEQ_CTRL_YUV420, 0); -} - static int aspeed_video_set_ctrl(struct v4l2_ctrl *ctrl) { struct aspeed_video *video = container_of(ctrl->handler, @@ -1356,16 +1356,13 @@ static int aspeed_video_set_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_JPEG_COMPRESSION_QUALITY: video->jpeg_quality = ctrl->val; - aspeed_video_update_jpeg_quality(video); + if (test_bit(VIDEO_STREAMING, &video->flags)) + aspeed_video_update_regs(video); break; case V4L2_CID_JPEG_CHROMA_SUBSAMPLING: - if (ctrl->val == V4L2_JPEG_CHROMA_SUBSAMPLING_420) { - video->yuv420 = true; - aspeed_video_update_subsampling(video); - } else { - video->yuv420 = false; - aspeed_video_update_subsampling(video); - } + video->yuv420 = (ctrl->val == V4L2_JPEG_CHROMA_SUBSAMPLING_420); + if (test_bit(VIDEO_STREAMING, &video->flags)) + aspeed_video_update_regs(video); break; default: return -EINVAL; @@ -1393,6 +1390,8 @@ static void aspeed_video_resolution_work(struct work_struct *work) aspeed_video_init_regs(video); + aspeed_video_update_regs(video); + aspeed_video_get_resolution(video); if (video->detected_timings.width != video->active_timings.width || @@ -1504,6 +1503,8 @@ static int aspeed_video_start_streaming(struct vb2_queue *q, video->perf.duration_max = 0; video->perf.duration_min = 0xffffffff; + aspeed_video_update_regs(video); + rc = aspeed_video_start_frame(video); if (rc) { aspeed_video_bufs_done(video, VB2_BUF_STATE_QUEUED); -- 2.25.1