Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20687770rwd; Thu, 29 Jun 2023 05:56:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6gGmyHMgkfoGrxLC2DOAQp1xmOfg6gX3zkN68OjBBzDZzzh4d6Mlo0Upg8wlzCMVWBoF+i X-Received: by 2002:a05:6871:4c7:b0:1aa:30e3:6a5e with SMTP id n7-20020a05687104c700b001aa30e36a5emr22395958oai.22.1688043405546; Thu, 29 Jun 2023 05:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688043405; cv=none; d=google.com; s=arc-20160816; b=hIYGlweNzb3/WPNK4uPt7K+61oS1PbuuhrMxK9HQoa2mSGPooKJMIH1OY4oAA6Vbp/ hl9I6kufwVQWYEei35ZIZZQdQ6AfnD0yuZfd6OR8g62hKmbWWKkBOTz6a0DIPIQqY0ti fMI2j954OOEtLBl8hzsscphm5bFVrQ077sjX99KzXJldhisTdCFv5nkZ5geybplCUEgF +XtYrLYZrom9jsTBJg3LUmbzIkSy8yIoM0tr22GxNuW45QXykiR6MzIIfOf25c9xc+VR p4tO4+s+e3FR7lOKPE6F824FOV2pSRemz2vE/XQ8rS927VnDGLkF0eRTsBK3ld60hqCQ 9KqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vibqGgTSkZNI78S50QxrbWxjy/o83ic28jzcG95Wy2Q=; fh=UU71DBBjCJucxaBrDK66unW5KFHkl3JLjolnqhLE1Oc=; b=sEnKNMOqsZrrq1RTO6rqK4TKz4sAX5LEjgvOUj2+sQdXS6sPwW2AEV1Isn5ITmFnT/ DQ35+Anweojrac+UDVkaKRETHlwiABcp4qf78tVtDIjg6BlPFOHivdrrs+52x26Pay5i smSwXTBZsmabYUhVQo02ymVjzFxfzG461uRsX+Bv21oB5tskvo1UwqIOzCVd6QvuvV+0 h7EOSPn22ZYNxqP3/3XnljOCPANHbrX26jRc0V+bsOigRz0KP2xVhxK8m4PI+5Wr6C/1 3YDRrmSiaC2SzTqU7aTAyo74xZnRLYgFfuQQUSvJlb5IHuBqFF0KL5Pm2Vop28xSPatK +ssw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=P3EPMDYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a634b15000000b0055af0729456si6175328pga.399.2023.06.29.05.56.31; Thu, 29 Jun 2023 05:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=P3EPMDYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231691AbjF2MtP (ORCPT + 99 others); Thu, 29 Jun 2023 08:49:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbjF2MtK (ORCPT ); Thu, 29 Jun 2023 08:49:10 -0400 Received: from mail-vk1-xa32.google.com (mail-vk1-xa32.google.com [IPv6:2607:f8b0:4864:20::a32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96EE21FD8; Thu, 29 Jun 2023 05:49:08 -0700 (PDT) Received: by mail-vk1-xa32.google.com with SMTP id 71dfb90a1353d-4717089ae5bso240095e0c.0; Thu, 29 Jun 2023 05:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688042947; x=1690634947; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=vibqGgTSkZNI78S50QxrbWxjy/o83ic28jzcG95Wy2Q=; b=P3EPMDYmvOSSNO9IpZqusoOBhARr6/ZEj3M9vLeC2NLXktdqWrxRP6VCiBJB2OfVNO poEVY6xEQCXTliwFgS7PtM5HIu6UcG9AeFUQT9d3+0PK1E8f5g3lD/9H8L8gZ3jvqgyq E3MATdkd4sCHDdQIL8RznP6cNlvtmN34rMtE+aUmE7aDTLDM+xoyod8fJ+HpUMWjmc7C LDWLNoZa81W3LdFza0scs6+quKYp5DrvUtWbvDybN9e4w5ER1pqgVhtpQ2KQt0cq84to eh+Ot6kJKqTWzN1RoCAGL6YJsKiOw2Cjut2vNti/xl6r2ofFasHqv0v7msfHvoyhYpxE JIzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688042947; x=1690634947; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vibqGgTSkZNI78S50QxrbWxjy/o83ic28jzcG95Wy2Q=; b=XJr369u5Yr2eVqs1qAc4UNjYY4jo//0GoQCdb1rKN7ZloVB7r74ZqtmViZ65u8xGoK RiycA+zo633XJhI7Jw1u8wbc1OJGwBow5Ln9WtXOMOGYT5c1f5aX/vxjxQqZQEi63hjN /eWd6HPevbi3b6uzY3LokG/1zPsmdnvPLufLcbCxlwHTIVyv0wyp54ksDwc/15cL4nMK ny5kwhHT8TWk0t+R070oBzYO9rvgVxkLjcGXnLJAFjhXyaoPSwrsiNtkgPjSRFHXup0H H9z4kfkSICKgoa4zgdAbqvnhA+XW+WFrN7O9R/x19Ry/redTrp16Yk1MukaMhXPR7N1c yvTw== X-Gm-Message-State: AC+VfDx7gT4j243fUkQZe3G6hYDAjpwHxiWV+MUVrPG1ppKAmDwrrRwo YoIQ3VpCzevqrz7em2PPRy3Eq0hiJ1NUZOoOqts= X-Received: by 2002:a1f:c1c3:0:b0:471:5224:bbdf with SMTP id r186-20020a1fc1c3000000b004715224bbdfmr19495635vkf.3.1688042947552; Thu, 29 Jun 2023 05:49:07 -0700 (PDT) MIME-Version: 1.0 References: <20230502084430.234182-1-milkfafa@gmail.com> <20230502084430.234182-8-milkfafa@gmail.com> In-Reply-To: From: Kun-Fa Lin Date: Thu, 29 Jun 2023 20:48:56 +0800 Message-ID: Subject: Re: [PATCH v12 7/7] media: nuvoton: Add driver for NPCM video capture and encode engine To: Hans Verkuil Cc: mchehab@kernel.org, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com, devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hans, > Apologies for the delay in reviewing this. As you may have noticed, we > have too many incoming patches and not enough reviewers, so it takes > too often way too long before I have time to review drivers like this. That's OK. I appreciate your time and comments. > > + /* Resolution changed */ > > + if (status & VCD_STAT_VHT_CHG || status & VCD_STAT_HAC_CHG) > > + schedule_work(&video->res_work); > > I don't think you need to schedule work. If the resolution changed, > then you can just call vb2_queue_error and queue the SOURCE_CHANGED > event here. You don't need to detect the resolution, you know it has changed, > so just inform userspace and that will call QUERY_DV_TIMINGS. OK. Will modify it as you suggested. > > + if (status & VCD_STAT_IFOR || status & VCD_STAT_IFOT) { > > + dev_warn(video->dev, "VCD FIFO overrun or over thresholds\n"); > > + npcm_video_stop(video); > > + npcm_video_start(video); > > This is dangerous: video_start detects the resolution and can update the > width/height. So now there can be a mismatch between what userspace expects > and what the DMA sends. > > I would make a new npcm_video_init(video) function that does the initial > timings detection. Call that on the first open. The npcm_video_start drops > that code and just uses the last set timings. > > Feel free to use an alternative to this, as long as restarting the video > here doesn't change the width/height/format as a side-effect. Understood. I've checked that it can just call npcm_video_start_frame (in which npcm_video_vcd_state_machine_reset will be called to reset VCD state machine and FIFOs) and the width/height/format will not be changed. > > + if (*num_buffers > MAX_REQ_BUFS) > > + *num_buffers = MAX_REQ_BUFS; > > Why limit this? Can't you just use rect[VIDEO_MAX_FRAME]? I just realized VIDEO_MAX_FRAME is a common define in videodev2.h. Will change to use it. > > + /* > > + * When a video buffer is dequeued, free associated rect_list and > > + * capture next frame. > > + */ > > + head = &video->list[video->vb_index]; > > + list_for_each_safe(pos, nx, head) { > > + tmp = list_entry(pos, struct rect_list, list); > > + list_del(&tmp->list); > > + kfree(tmp); > > + } > > + > > + if (npcm_video_start_frame(video)) { > > This is weird. This is not normally done here since you never know when > userspace will dequeue a buffer. > > I would expect to see this called: > > 1) In start_streaming (so that works) > 2) When a buffer is captured and vb2_buffer_done is called: if another > empty buffer is available, then use that. > 3) in buf_queue: if the buffer list was empty, and vb2_start_streaming_called() > is true, then you can start capturing again. Will modify as you suggested. Thanks for the guide. Regards, Marvin