From patchwork Wed Sep 29 01:16:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jammy Huang X-Patchwork-Id: 1534177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HJz4v0ptcz9t0J for ; Wed, 29 Sep 2021 11:17:34 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HJz4s0L6Tz2yWR for ; Wed, 29 Sep 2021 11:17:33 +1000 (AEST) X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=aspeedtech.com (client-ip=211.20.114.71; helo=twspam01.aspeedtech.com; envelope-from=jammy_huang@aspeedtech.com; receiver=) Received: from twspam01.aspeedtech.com (twspam01.aspeedtech.com [211.20.114.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HJz4p1Scwz2xtZ; Wed, 29 Sep 2021 11:17:28 +1000 (AEST) Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 18T0uCkR095684; Wed, 29 Sep 2021 08:56:12 +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; Wed, 29 Sep 2021 09:16:56 +0800 From: Jammy Huang To: , , , , , , , , Subject: [RESEND PATCH] media: aspeed: add debugfs Date: Wed, 29 Sep 2021 09:16:53 +0800 Message-ID: <20210929011652.1709-1-jammy_huang@aspeedtech.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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 18T0uCkR095684 X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: BMC-SW@aspeedtech.com Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" To show video real-time information as below: Signal| Resolution| FRC | Width Height| Lock| 1920 1080| 0 Frame#| Frame Duration| FPS | Now Min Max| 496| 26 25 30| 40 Signed-off-by: Jammy Huang --- drivers/media/platform/aspeed-video.c | 100 ++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/drivers/media/platform/aspeed-video.c b/drivers/media/platform/aspeed-video.c index 8b3939b8052d..5b98dc7b7b15 100644 --- a/drivers/media/platform/aspeed-video.c +++ b/drivers/media/platform/aspeed-video.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -203,6 +205,14 @@ struct aspeed_video_buffer { struct list_head link; }; +struct aspeed_video_perf { + ktime_t last_sample; + u32 totaltime; + u32 duration; + u32 duration_min; + u32 duration_max; +}; + #define to_aspeed_video_buffer(x) \ container_of((x), struct aspeed_video_buffer, vb) @@ -241,6 +251,8 @@ struct aspeed_video { unsigned int frame_left; unsigned int frame_right; unsigned int frame_top; + + struct aspeed_video_perf perf; }; #define to_aspeed_video(x) container_of((x), struct aspeed_video, v4l2_dev) @@ -444,6 +456,18 @@ static void aspeed_video_write(struct aspeed_video *video, u32 reg, u32 val) readl(video->base + reg)); } +static void update_perf(struct aspeed_video *v) +{ + v->perf.duration = + ktime_to_ms(ktime_sub(ktime_get(), v->perf.last_sample)); + v->perf.totaltime += v->perf.duration; + + if (!v->perf.duration_max || v->perf.duration > v->perf.duration_max) + v->perf.duration_max = v->perf.duration; + if (!v->perf.duration_min || v->perf.duration < v->perf.duration_min) + v->perf.duration_min = v->perf.duration; +} + static int aspeed_video_start_frame(struct aspeed_video *video) { dma_addr_t addr; @@ -482,6 +506,8 @@ static int aspeed_video_start_frame(struct aspeed_video *video) aspeed_video_update(video, VE_INTERRUPT_CTRL, 0, VE_INTERRUPT_COMP_COMPLETE); + video->perf.last_sample = ktime_get(); + aspeed_video_update(video, VE_SEQ_CTRL, 0, VE_SEQ_CTRL_TRIG_CAPTURE | VE_SEQ_CTRL_TRIG_COMP); @@ -600,6 +626,8 @@ static irqreturn_t aspeed_video_irq(int irq, void *arg) u32 frame_size = aspeed_video_read(video, VE_JPEG_COMP_SIZE_READ_BACK); + update_perf(video); + spin_lock(&video->lock); clear_bit(VIDEO_FRAME_INPRG, &video->flags); buf = list_first_entry_or_null(&video->buffers, @@ -760,6 +788,7 @@ static void aspeed_video_get_resolution(struct aspeed_video *video) det->width = MIN_WIDTH; det->height = MIN_HEIGHT; video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; + memset(&video->perf, 0, sizeof(video->perf)); do { if (tries) { @@ -1517,6 +1546,71 @@ static const struct vb2_ops aspeed_video_vb2_ops = { .buf_queue = aspeed_video_buf_queue, }; +#ifdef CONFIG_DEBUG_FS +static int aspeed_video_debugfs_show(struct seq_file *s, void *data) +{ + struct aspeed_video *v = s->private; + + seq_printf(s, "%10s|%21s|%10s\n", + "Signal", "Resolution", "FRC"); + seq_printf(s, "%10s|%10s%11s|%10s\n", + "", "Width", "Height", ""); + seq_printf(s, "%10s|%10d%11d|%10d\n", + v->v4l2_input_status ? "Unlock" : "Lock", + v->pix_fmt.width, v->pix_fmt.height, v->frame_rate); + + seq_puts(s, "\n"); + + seq_printf(s, "%10s|%21s|%10s\n", + "Frame#", "Frame Duration", "FPS"); + seq_printf(s, "%10s|%7s%7s%7s|%10s\n", + "", "Now", "Min", "Max", ""); + seq_printf(s, "%10d|%7d%7d%7d|%10d\n", + v->sequence, v->perf.duration, v->perf.duration_min, + v->perf.duration_max, 1000/(v->perf.totaltime/v->sequence)); + + return 0; +} + +int aspeed_video_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, aspeed_video_debugfs_show, inode->i_private); +} + +static const struct file_operations aspeed_video_debugfs_ops = { + .owner = THIS_MODULE, + .open = aspeed_video_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static struct dentry *debugfs_entry; + +static void aspeed_video_debugfs_remove(struct aspeed_video *video) +{ + debugfs_remove_recursive(debugfs_entry); + debugfs_entry = NULL; +} + +static int aspeed_video_debugfs_create(struct aspeed_video *video) +{ + debugfs_entry = debugfs_create_file(DEVICE_NAME, 0444, NULL, + video, + &aspeed_video_debugfs_ops); + if (!debugfs_entry) + aspeed_video_debugfs_remove(video); + + return debugfs_entry == NULL ? -EIO : 0; +} +#else +static void aspeed_video_debugfs_remove(struct aspeed_video *video) { } +static int aspeed_video_debugfs_create(struct aspeed_video *video) +{ + return 0; +} +#endif /* CONFIG_DEBUG_FS */ + static int aspeed_video_setup_video(struct aspeed_video *video) { const u64 mask = ~(BIT(V4L2_JPEG_CHROMA_SUBSAMPLING_444) | @@ -1708,6 +1802,10 @@ static int aspeed_video_probe(struct platform_device *pdev) return rc; } + rc = aspeed_video_debugfs_create(video); + if (rc) + dev_err(video->dev, "debugfs create failed\n"); + return 0; } @@ -1719,6 +1817,8 @@ static int aspeed_video_remove(struct platform_device *pdev) aspeed_video_off(video); + aspeed_video_debugfs_remove(video); + clk_unprepare(video->vclk); clk_unprepare(video->eclk);