Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp964336pxb; Thu, 30 Sep 2021 23:40:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0/opxkuYClju7qsGiaVwuCJ7Nap+A/ynI3bshBnzJlp0m4xzlkGdLRiHq/nO9e9vl0z4z X-Received: by 2002:a63:720d:: with SMTP id n13mr8348119pgc.470.1633070409380; Thu, 30 Sep 2021 23:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633070409; cv=none; d=google.com; s=arc-20160816; b=jBulgTfpB3/qE8d6JkWDgH9VRONFDBCqylFTJ39BlMPTcz14rt5zYx26nBepRG8Ms7 OhIGhuS2uOTSCRcG2ZhR9sdw2D9Is9w1ioKdjM8K0bB6hWZU56ym1yW+MZjs7jyyRYEm TvdbxfekMs05DiY5tD+bRcDUagLiB65WxEM75M5nJ1kvww9Y2ufzilyWg11+LaDR6LF+ I30H762X4HFsZvsKFZYE0i2N2/RDC3ywJqCGA/CcBi7xhYaPuDC6QNc1w2GRDzuzK/2H XbK5j1vE1FISJFmBPjyokOowLNEqBC4DUGeOed1ZTOKDw57AYnRnlOdHbwI/UXiGv9i8 pSjg== 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 :message-id:date:subject:cc:to:from; bh=2wbHNst6qJBiFZeIE3whMj6gGgyJxkVhxIp2ngp9Ewk=; b=e9YZttMHxAdXDzNHYmeWxxZmzOrsD8VhpBXYfixG0Hpoo/XYVIFG/96FjJuul/nifB sSFV5i262n/fjznFvCu60dBdVW5841/bFvQrWLJ9sjhkjtAPKyO9QHi3Mjw0egMoKZVJ Ryb/+2G0A34YH+8ZuSgEvFRyH7RUOR0Sk49XC9ix0V8dS/fh79wwQ08EH2VVQCuTni4C KlGlzXDml4VMNNIpoCdxQBb1DC/gQJNl8tnJU70eOTAe49YZiJuPnmSUGqEi0pEDP+hj sr4Escv1jau9cP8p+O4J7XMtAyY2Wp1TKJGtwpgBp150g/R52HgZwDQBWc2oP1Tt1obc tSjA== 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 b2si5589353plx.384.2021.09.30.23.39.55; Thu, 30 Sep 2021 23:40:09 -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 S231169AbhJAGks (ORCPT + 99 others); Fri, 1 Oct 2021 02:40:48 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:13836 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbhJAGkq (ORCPT ); Fri, 1 Oct 2021 02:40:46 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 1916Ht6c088858; Fri, 1 Oct 2021 14:17:56 +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, 1 Oct 2021 14:38:45 +0800 From: Jammy Huang To: , , , , , , , , CC: Subject: [PATCH v3] media: aspeed: add debugfs Date: Fri, 1 Oct 2021 14:34:32 +0800 Message-ID: <20211001063431.8446-1-jammy_huang@aspeedtech.com> X-Mailer: git-send-email 2.25.1 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 1916Ht6c088858 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To show video real-time information as below: Caputre: Signal : Unlock Width : 1920 Height : 1080 FRC : 30 Performance: Frame# : 0 Frame Duration(ms) : Now : 0 Min : 0 Max : 0 FPS : 0 Signed-off-by: Jammy Huang --- v3: - let struct, aspeed_video_debugfs_ops, be const v2: - Change the style of debugfs information - Use Min/Max to remove test and branch cases --- drivers/media/platform/aspeed-video.c | 101 ++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/drivers/media/platform/aspeed-video.c b/drivers/media/platform/aspeed-video.c index 8b3939b8052d..c5c413844441 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,16 @@ static void aspeed_video_write(struct aspeed_video *video, u32 reg, u32 val) readl(video->base + reg)); } +static void update_perf(struct aspeed_video_perf *p) +{ + p->duration = + ktime_to_ms(ktime_sub(ktime_get(), p->last_sample)); + p->totaltime += p->duration; + + p->duration_max = max(p->duration, p->duration_max); + p->duration_min = min(p->duration, p->duration_min); +} + static int aspeed_video_start_frame(struct aspeed_video *video) { dma_addr_t addr; @@ -482,6 +504,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 +624,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->perf); + spin_lock(&video->lock); clear_bit(VIDEO_FRAME_INPRG, &video->flags); buf = list_first_entry_or_null(&video->buffers, @@ -760,6 +786,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) { @@ -1450,6 +1477,8 @@ static int aspeed_video_start_streaming(struct vb2_queue *q, struct aspeed_video *video = vb2_get_drv_priv(q); video->sequence = 0; + video->perf.duration_max = 0; + video->perf.duration_min = 0xffffffff; rc = aspeed_video_start_frame(video); if (rc) { @@ -1517,6 +1546,72 @@ 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_puts(s, "\n"); + + seq_printf(s, " %-20s:\t%s\n", "Signal", + v->v4l2_input_status ? "Unlock" : "Lock"); + seq_printf(s, " %-20s:\t%d\n", "Width", v->pix_fmt.width); + seq_printf(s, " %-20s:\t%d\n", "Height", v->pix_fmt.height); + seq_printf(s, " %-20s:\t%d\n", "FRC", v->frame_rate); + + seq_puts(s, "\n"); + + seq_puts(s, "Performance:\n"); + seq_printf(s, " %-20s:\t%d\n", "Frame#", v->sequence); + seq_printf(s, " %-20s:\n", "Frame Duration(ms)"); + seq_printf(s, " %-18s:\t%d\n", "Now", v->perf.duration); + seq_printf(s, " %-18s:\t%d\n", "Min", v->perf.duration_min); + seq_printf(s, " %-18s:\t%d\n", "Max", v->perf.duration_max); + seq_printf(s, " %-20s:\t%d\n", "FPS", 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 +1803,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 +1818,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); -- 2.25.1