From patchwork Wed Apr 10 12:35:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100684 Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXCL-0008Af-02 for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:37:06 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DC94A1F236DA for ; Wed, 10 Apr 2024 12:37:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3E65158DD4; Wed, 10 Apr 2024 12:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IQ87CtXM" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8F2F7C08F; Wed, 10 Apr 2024 12:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752614; cv=none; b=OJKv1x3rfEgc0Q91oi4siYFL62ePbNdutEaghg3hgF2ALo2lq5U5sylkvPxex9fBnxEL4BVT1lC+rSqFOdYyh/OJDOuTVPPLP2N9nEhPb4rej50ut+GtbD7WLXg6vcsajWqFvmGnWNRRQchxrshRoNCb8XKPt7kFQhjI21TFY6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752614; c=relaxed/simple; bh=le94SkkfW9uul6i34iKBtYi/Z7zUyGKKz208IU5JKeo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F9xoOzO6ZBM6183hSZk9fRFLs5lCV15vtMuc7r3VoYIDkUEFWQ8/vvhCXmSexZmQWHDj9O4fefjBsSzh1i50tg3St+IcCdi5rwdGmcSlERThsjsGI363tO+eZNb33Q5LXWZQa0R/zSQXsE9y4GNLUU+qPlQPIGlyvTBC+YYjQ+U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=IQ87CtXM; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 83A63A9A; Wed, 10 Apr 2024 14:36:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752568; bh=le94SkkfW9uul6i34iKBtYi/Z7zUyGKKz208IU5JKeo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IQ87CtXMneByaBE1UplzL+ChRadT04Wxs4X5ELeClwkifoDmB4eIWWz0+RslNHRg8 8V3IIcZMxzzG1PYowUBsKPwDCCEIlop5EWYTPKaa882zmaA8X+xBfsKCSUQCIeBn+Z H1RV9STkgANn1Ldo8X98DQu+hitimRycwUeVvaOg= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:48 +0300 Subject: [PATCH v3 1/9] media: subdev: Add privacy led helpers Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-1-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1863; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=le94SkkfW9uul6i34iKBtYi/Z7zUyGKKz208IU5JKeo=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFofe4ALeW0V6reIObLvxN7BsmmAxljaKE64ls fUDD22Sa12JAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH3gAKCRD6PaqMvJYe 9ZJKD/wPEWBbZICpfZqb+N3PQUtclfBIaOtSyuYdqwR5PjVNc/5Y+jhm8H3aRw/skXinKTdmxwD PI5u1/YhW1Q2Iu6n04VH/72ZcKyzlTcu/aPuyBp7gQUawdtW6N4FDb50eCACH4UHTOgbYNKhA23 CeupTngJj5dM8IDur7tYeNE+eJudtYnoEDnXwfWKsVTGZnxBW2Bg7jaVHaWxEwwT+Wc7e8g9KsN BDxSsZT5ErQLWSVHP80LU+Ock0ZD5j1pj0YtgV2/2LPEf+cBNFy19+2UTOvBgC7Qp3GwoY8ofu2 d/oWMFMbS+GA4Z57mlwxuSkf387ZieepUFfHPxgnHG7VLB7v0HoPtVnuWxoXDGG0m4RiG7xreGi j2gtzLY5QnL1+drUy7zlg5JLOtuOfXPqeG+OCxXxkTR90zRL7hQ6MnNeDs6zpElbmKuh/EP8pfl YspMgQgRRclJN0NTOnaz/l9oiO5o1hKYBi3HI64x8GzpGDVtPNsAFTNLnJRfXnEt4WnEEVobVLJ c/eA4WaDSECHjl+mUmM1WSJfeBuoM76beZTz9kcbysvoqtE0gD38iJRKt2mgsEwjdHpxO9bZMpu btymEE6QbabUtWQfONhju0vUSS7uI839dWoyKgguSD52UWRIEl/G7z9mL4SV1264ivJ5LsnrAG/ U4y26OxbTKT4seg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -3.3 (---) X-LSpam-Report: No, score=-3.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no Add helper functions to enable and disable the privacy led. This moves the #if from the call site to the privacy led functions, and makes adding privacy led support to v4l2_subdev_enable/disable_streams() cleaner. Signed-off-by: Tomi Valkeinen Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 012b757eac9f..13957543d153 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -148,6 +148,23 @@ static int subdev_close(struct file *file) } #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */ +static void v4l2_subdev_enable_privacy_led(struct v4l2_subdev *sd) +{ +#if IS_REACHABLE(CONFIG_LEDS_CLASS) + if (!IS_ERR_OR_NULL(sd->privacy_led)) + led_set_brightness(sd->privacy_led, + sd->privacy_led->max_brightness); +#endif +} + +static void v4l2_subdev_disable_privacy_led(struct v4l2_subdev *sd) +{ +#if IS_REACHABLE(CONFIG_LEDS_CLASS) + if (!IS_ERR_OR_NULL(sd->privacy_led)) + led_set_brightness(sd->privacy_led, 0); +#endif +} + static inline int check_which(u32 which) { if (which != V4L2_SUBDEV_FORMAT_TRY && @@ -422,15 +439,10 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable) if (!ret) { sd->enabled_streams = enable ? BIT(0) : 0; -#if IS_REACHABLE(CONFIG_LEDS_CLASS) - if (!IS_ERR_OR_NULL(sd->privacy_led)) { - if (enable) - led_set_brightness(sd->privacy_led, - sd->privacy_led->max_brightness); - else - led_set_brightness(sd->privacy_led, 0); - } -#endif + if (enable) + v4l2_subdev_enable_privacy_led(sd); + else + v4l2_subdev_disable_privacy_led(sd); } return ret; From patchwork Wed Apr 10 12:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100685 Received: from sv.mirrors.kernel.org ([139.178.88.99]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXCg-0008C6-2X for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:37:27 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3C54C2869CE for ; Wed, 10 Apr 2024 12:37:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB9F12BAEC; Wed, 10 Apr 2024 12:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OassZM3m" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D856315B990; Wed, 10 Apr 2024 12:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752617; cv=none; b=bjgUX4ioUbk/8PBvbgu+4Rdao4sg2HwJaSljCd8YVJni8v/EFIkXQz8ue1EScGXG9qZNio06Yp5kKcHf1OfWCUHEJh0m/xnFvrKb+N6FJTtqzXjFMNZrHTL/yw1dVghN/qcjGTaaFWwd/nR47UZc6XawU6mH4yMtY51CY+OabNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752617; c=relaxed/simple; bh=PIKaSKIrL14+cT0YwZSzOzP7fwNqRc3dWyIMQBcnsdU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ND1UaUvPy0WQm/su3Dqhp6diMr+Ys1moJnFy0XTwxKsyPqaoHiQv6831E9oz84NuJW0jo6hk22d60lWR1IZZw4a6er/apiWdx1up8Gng8I0GThJPMGGedMYDTlLNVGYfxn4O0qgGb/mXFbjUygZAQbxr/ro3cX/1ntq13javsGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=OassZM3m; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 14832BD1; Wed, 10 Apr 2024 14:36:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752569; bh=PIKaSKIrL14+cT0YwZSzOzP7fwNqRc3dWyIMQBcnsdU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OassZM3msmzoMCuZ3q0y6x2nwPWB0Cm5mVYkb7OXNu18aT3lyY9VrePhPTc4vOeNF FEoRZiW1vplY9qJeVB9ltFZGxrIs+hpZhqV8yPWgmYcepPMkSPtsZ09ODo3wVzCG9a 3HErywfgjdMPVX7+TRRLgHOZW5VwfxQRR8PB3CyI= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:49 +0300 Subject: [PATCH v3 2/9] media: subdev: Use v4l2_subdev_has_op() in v4l2_subdev_enable/disable_streams() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-2-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1222; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=PIKaSKIrL14+cT0YwZSzOzP7fwNqRc3dWyIMQBcnsdU=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFofe6DFtY8373avyY5sSM3N06UyAbApTjpJg4 P5EgU40fdqJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH3gAKCRD6PaqMvJYe 9e1ZD/wM6HRBNvozCkMRZ94pXuBR/ZK++ubSj1Tj2wpED87gpdMTtvt3sqP3ZoQx6vKLtHtZqHg iUTN4Ffabg1D9AtnoJ/2Lyxa/uEWqNGtEmSG6U2GIzfBAr3F1BdQQvcwg1ByibrXoOUJ1tkM4N5 ZukGiqa3XczAlfm0VHiM6A+j3+/7PPMMa++c1Z668SwqN/W3dqqWYu8uEN6cF3Z9cR7LPeTHWWD ZYsPeAmAccxAxpmoMJ9DJ7eyIBYuo1NnEB0uJlPGjkGPJBmQkijrotKhZPiqQ1QiK/nwIw2TG5s JxkMIqE/zmnXqlySRRaws1buBjNWL6jmkL8bU/7PGPrvQO+tAkge+pZ8MKhn2hK0UM6p+CrAjUF YjcWxP3gmhf0W5U34xbAdpgNlm2AhLaYnriQaw23LaI/Q6q3vk+HHVYnpol1zi5g1V5xZzS7OP+ WHiJNU01wv/p3nE+e7dupic18rxUTeXfHUDxMH9+fR9a/g7LSvw6hGxpGyMb8KHLN0aXTO70Ui8 XXo/ZuTVPHdYs8MalHm9NwFgAg5CzLp6O4pKQXx4TnrcHnksewHWMg6LrAaeubvwSB4CklcSMS9 sPPlm3D3Gh2GAfs8EaIZqxWd3gF/x8kThoftd0ICKSXAW/oUTAppNm6CyF84516QerXLnXaESjM GfEo1KCIbCEI03A== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -4.9 (----) X-LSpam-Report: No, score=-4.9 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no Use v4l2_subdev_has_op() in v4l2_subdev_enable/disable_streams(). Signed-off-by: Tomi Valkeinen Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 13957543d153..4a531c2b16c4 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2133,7 +2133,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, return 0; /* Fallback on .s_stream() if .enable_streams() isn't available. */ - if (!sd->ops->pad || !sd->ops->pad->enable_streams) + if (!v4l2_subdev_has_op(sd, pad, enable_streams)) return v4l2_subdev_enable_streams_fallback(sd, pad, streams_mask); @@ -2250,7 +2250,7 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, return 0; /* Fallback on .s_stream() if .disable_streams() isn't available. */ - if (!sd->ops->pad || !sd->ops->pad->disable_streams) + if (!v4l2_subdev_has_op(sd, pad, disable_streams)) return v4l2_subdev_disable_streams_fallback(sd, pad, streams_mask); From patchwork Wed Apr 10 12:35:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100686 Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXCr-0008CQ-17 for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:37:38 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4EC601C21243 for ; Wed, 10 Apr 2024 12:37:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22AA015E212; Wed, 10 Apr 2024 12:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nbh5FgLR" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D851F15B98E; Wed, 10 Apr 2024 12:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752618; cv=none; b=EydZ04+S2864K1conbfbEYRKWLODJWDQ7kSv8DfwLcXScB1n3uWfCncv1NuFiil8G8kEFuufED8gQTR/IDhVSkAnL7BJtc72tj0pjcc5Tu/6vpuxj01ylAQqS5jY+6cUL9ICJXf0cxxMmJO7TMueCOBrc27nfUGWhx3qJbHjulE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752618; c=relaxed/simple; bh=zlbes/C+mMf8GVzxf6IqNj9dh4TQOHZqYOjhpSbRxJU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HUq7/tBntvokTmEvjd6HYHRG7J+CanPtJ3EMJrh4BldnR62gQPQnyLGmkCItVysuhzZeprCpnnnPIqdMzpsaimI4KSpTh24M/48bAaUoafbrTMLPAUk8DmhxYIIBk5zn3ZOcik+jIgrCVLGS3gZzJc3MT8MUMql8RyGeGXYI0R8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=nbh5FgLR; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 97AE0EF2; Wed, 10 Apr 2024 14:36:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752570; bh=zlbes/C+mMf8GVzxf6IqNj9dh4TQOHZqYOjhpSbRxJU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nbh5FgLRr9QgO529JPOx8bcbulDPKSVrCfYqsTb+ZZG+sdDP/mLgNDoYC2f7dBdiH SbPSFclUn7YVJrW71n9t4XYh4S0n3Z5QYBoZ688jD1iicY4T6TZ4MfH05mj7m8Irol rAi3yXkxZxBtn9ePNa+wIZIavXZLqgbqdGQlbmNw= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:50 +0300 Subject: [PATCH v3 3/9] media: subdev: Add checks for subdev features Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-3-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2128; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=zlbes/C+mMf8GVzxf6IqNj9dh4TQOHZqYOjhpSbRxJU=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFoff/kjTBbtOZhZkZ3momcOP54yqy22hpg5Hv TYksusK13iJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH3wAKCRD6PaqMvJYe 9VxSD/9zspXhDGeS1SdhDaYQWjDLce1/O61zShRpW1xFDP0C6tVczRWN5t+gUblnTeObzZPVi4D /b0ZZjxs4hdzbR68eNIdjco6gYasupjRKt30N4NGi0pa5DKfCr2QLGPisKQOXB1fuRMZDzF05K4 RJCpdlUsZCidhnTsn7z5e04tVisGPGsRtu4OZyp5fNgOyGW/8Ey2lJ4mhsf43+KmNwtSabB2fwF bASHhaOZ6j2vcwE/SC7QA1g5Jph9/9gkr4QZWPv88whKj+3gY9CV6DoPAt9diA9Xa11hJdmtN5E vp7zJaTkxez0Vk/FzFZIUjWMVukZ0A5RIxpjpbeOCmPwC1FFUDRnqAqGVefdbUkINDHatjoS4MV 50OfBVEvY938855szvySdgNiAw+jpa4nnz/+AAVb2t1NKNgFXUQi3CarnBcD4phquIlHQ2QMbxV +2+behqbVRw6IYN5AJ3OfOiODd3vhbDrNnCwBxVEfry33Y5qr0KSyDMcRgJRoij/bcNR14Ldxjz Y6lh0/vTWzP2wxboWuP+KzJe+s/inLPfC/w60dWRDC+zYXT4SHONf+XjzqZfepnFlxdTa0wcZF0 1FcxaOBiDkSzcgUP8EnYZ7zCQOleWrnT2Zjad8b6FSmPQdP3vLa28CxsO7mPZTeCTCVdpAr6q7z Z/q1nGDdr8CfDTA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -3.3 (---) X-LSpam-Report: No, score=-3.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no Add some checks to verify that the subdev driver implements required features. A subdevice that supports streams (V4L2_SUBDEV_FL_STREAMS) must do one of the following: - Implement neither .enable/disable_streams() nor .s_stream(), if the subdev is part of a video driver that uses an internal method to enable the subdev. - Implement only .enable/disable_streams(), if support for legacy sink-side subdevices is not needed. - Implement .enable/disable_streams() and .s_stream(), if support for legacy sink-side subdevices is needed. At the moment the framework doesn't check this requirement. Add the check. Signed-off-by: Tomi Valkeinen Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 4a531c2b16c4..606a909cd778 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1533,6 +1533,33 @@ int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name, struct lock_class_key *key) { struct v4l2_subdev_state *state; + struct device *dev = sd->dev; + bool has_disable_streams; + bool has_enable_streams; + bool has_s_stream; + + /* Check that the subdevice implements the required features */ + + has_s_stream = v4l2_subdev_has_op(sd, video, s_stream); + has_enable_streams = v4l2_subdev_has_op(sd, pad, enable_streams); + has_disable_streams = v4l2_subdev_has_op(sd, pad, disable_streams); + + if (has_enable_streams != has_disable_streams) { + dev_err(dev, + "subdev '%s' must implement both or neither of .enable_streams() and .disable_streams()\n", + sd->name); + return -EINVAL; + } + + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + if (has_s_stream && !has_enable_streams) { + dev_err(dev, + "subdev '%s' must implement .enable/disable_streams()\n", + sd->name); + + return -EINVAL; + } + } state = __v4l2_subdev_state_alloc(sd, name, key); if (IS_ERR(state)) From patchwork Wed Apr 10 12:35:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100687 Received: from sv.mirrors.kernel.org ([139.178.88.99]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXD5-0008DL-2b for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:37:53 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1376E286A5F for ; Wed, 10 Apr 2024 12:37:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C585915E818; Wed, 10 Apr 2024 12:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ti0IwACB" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB6ED15E1E3; Wed, 10 Apr 2024 12:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752620; cv=none; b=sw7F2v4e/D6A+O1YsgyuzNQzpDlqIxtkIJzyjlZ1KU/YvjUPV3S1rFhDQuen3CIgPgq6ZB6YR+mjmKDH5/RAQEHCKWAdwmRUFJMghMevQcn4Pl1fDXsFB4Zaj/7pnWyJyPabCt9WejCXyv3b37LBZ9BxUIJ8M5S+5qDhtO6NLqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752620; c=relaxed/simple; bh=QbS01gh08Z29YLX90ucmDSlHlDaT/1Vd3a+BixCTC3g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PGvO53/bRrgfJU9o5Sioxhg2pSHDkdea+kSUA6TVR970HozQqMMaYJqvN6u7z2ji+vrRBz3bIEKdMhLPhrKeJtVFYj1lMPtAjk5XMmnnpAZTG0FjTAlycD9aBYGXgYqOj8tSoMi/DB0tfb2pm5ky6AV+fI/SRtcvnm5Zenaa46w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=ti0IwACB; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 31DCEFA8; Wed, 10 Apr 2024 14:36:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752570; bh=QbS01gh08Z29YLX90ucmDSlHlDaT/1Vd3a+BixCTC3g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ti0IwACB4yMM+jIbzp9ex2FSa7cdhllxoWwgGFmC4ic8hxtVJxrNHYalOzoXOdsNz xjYKekmDSEsIX4xD7SIJgQ67UxgUUtpCUNOyNeGPJizfzf+jqZh3qTOlV8vtEQ9lR+ N0PA9KOMmhzNFKzl3u2ZotqOfLpFXxkiVDG9WpNU= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:51 +0300 Subject: [PATCH v3 4/9] media: subdev: Fix use of sd->enabled_streams in call_s_stream() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-4-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2818; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=QbS01gh08Z29YLX90ucmDSlHlDaT/1Vd3a+BixCTC3g=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFoffBg3+O+EyAwS4Y/OqJrjkc58dNzc4GB72N eic9jsvg0iJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH3wAKCRD6PaqMvJYe 9WwWD/9al7iNCgWc4n800zPVJjUQm7LeiH0WkcsHRhAiFunjZTeP2QHQaTwof0zzRxskrIyrBv8 2udRWffFp13TQGWm5UGq5u5A+Q2P5mmmqfKkOZlNrJ4mo+uH2wlikb42P1Wrctxev4d9k6FviAP 9yNjLeYKYfpwB/a2oWjOPGJCpfiyKKtjXvQKGN+VGduT0phj+YkQ2BjHjK3IOMC+2BtKGh2kEJU 1qjoITgmYN9vST7+tKTQKaY+Qf2IeWtUBH3aIhVjsjr0VQ8HW5/jApzOvlfxSUnY76MlGJUWvph J9aprsIaYw2ovYhnmPCAmS5G74N4x/z8LyKBHik4JQqKCopIOdtFo8m6g3uaK8poMCHWCKABfAb SYGR/sWXQTje0E9VjK8+ZgqYA/24Dvbzf/b4mwcbH/i6OhGhXTEPuKy929er2Jv4yjkXHj/1BZ9 T84/+sFPhrIqyppqGRdA+S7BgofozO6WWhhMhog4Lcp041b7RQQq80p000XRkVnZ3NJMAehp9xT TAdn4fkVN+5xqa0Y2Ts//dN5vS1DZ+3EBUl9QqH88jgJlhkoOtE2vNudLuwEtysf30XKOGGVycu 9CxL8c4xXdQz2w2KRSgszV0fdqqZ48J6p8bFrBEzyZK1Zio1AqvEWjFlazs1N/EIfjonRp6ZQb8 aW/wxb3K3nEcgKA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -4.9 (----) X-LSpam-Report: No, score=-4.9 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no call_s_stream() uses sd->enabled_streams to track whether streaming has already been enabled. However, v4l2_subdev_enable/disable_streams_fallback(), which was the original user of this field, already uses it, and v4l2_subdev_enable/disable_streams_fallback() will call call_s_stream(). This leads to a conflict as both functions set the field. Afaics, both functions set the field to the same value, so it won't cause a runtime bug, but it's still wrong and if we, e.g., change how v4l2_subdev_enable/disable_streams_fallback() operates we might easily cause bugs. Fix this by adding a new field, 'streaming_enabled', for call_s_stream(). Signed-off-by: Tomi Valkeinen Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 8 ++------ include/media/v4l2-subdev.h | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 606a909cd778..6cd353d83dfc 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -421,12 +421,8 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable) * The .s_stream() operation must never be called to start or stop an * already started or stopped subdev. Catch offenders but don't return * an error yet to avoid regressions. - * - * As .s_stream() is mutually exclusive with the .enable_streams() and - * .disable_streams() operation, we can use the enabled_streams field - * to store the subdev streaming state. */ - if (WARN_ON(!!sd->enabled_streams == !!enable)) + if (WARN_ON(sd->streaming_enabled == !!enable)) return 0; ret = sd->ops->video->s_stream(sd, enable); @@ -437,7 +433,7 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable) } if (!ret) { - sd->enabled_streams = enable ? BIT(0) : 0; + sd->streaming_enabled = enable; if (enable) v4l2_subdev_enable_privacy_led(sd); diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index a9e6b8146279..f55d03e0acc1 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1043,6 +1043,8 @@ struct v4l2_subdev_platform_data { * v4l2_subdev_enable_streams() and * v4l2_subdev_disable_streams() helper functions for fallback * cases. + * @streaming_enabled: Tracks whether streaming has been enabled with s_stream. + * This is only for call_s_stream() internal use. * * Each instance of a subdev driver should create this struct, either * stand-alone or embedded in a larger struct. @@ -1091,6 +1093,7 @@ struct v4l2_subdev { */ struct v4l2_subdev_state *active_state; u64 enabled_streams; + bool streaming_enabled; }; From patchwork Wed Apr 10 12:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100688 Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXDJ-0008E5-1D for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:38:06 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2B9EC1C20C80 for ; Wed, 10 Apr 2024 12:38:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29C1915ECD5; Wed, 10 Apr 2024 12:37:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="olKpc5p1" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2344315E7FB; Wed, 10 Apr 2024 12:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752621; cv=none; b=GNiso0eX5S3ysq9ByHgbrQii0RaFUNrZVGB9GINh0kSn3YuMK3nx/FfIOLp3zDL0qauc6GIV3ub0vDa9R6YUs6o6vqYR7raCkVJD7ooFD3aO0DHv1xfO3SWb06sLQzcIHjJtunlCTce/evr/vMMEp40Rm4XlsCTMUg3onVIO1n8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752621; c=relaxed/simple; bh=uXIdlNOiCPH7wLnGs0l7FIpa16razcWfyX7yOHhjJPA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WJfjOaL2wtMvqqjbMPeLTEMgOzZ60hqqmSGbLfdMFJPtKXOVS7GOpxtSLdPCQVZaqwtkPlAWs8iIx8imOetO6aVQg7HdVRrI2Dblqiidx9HJGDrSQ8k218JBKUiQhzN7yVbhEqryq750zPg0O5VP2ivoxwIOorfhXd3dglmNquI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=olKpc5p1; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C0AE3149B; Wed, 10 Apr 2024 14:36:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752571; bh=uXIdlNOiCPH7wLnGs0l7FIpa16razcWfyX7yOHhjJPA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=olKpc5p1vl9YeHmufJ4FCgEXle/QH+I6NtPhjAZiKg78eorb1DDgxRCFrEjtjgyKc Omyxcsj5Mc4qeB4o7I8XTrauVeXxtMz6ngq/mtQNiMlhggxgv45d6D7MUXywdBnZn3 7ns5vt30fraXZw5DZ2QTlTahAl7PRacmzZ0dBH+c= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:52 +0300 Subject: [PATCH v3 5/9] media: subdev: Improve v4l2_subdev_enable/disable_streams_fallback Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-5-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6393; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=uXIdlNOiCPH7wLnGs0l7FIpa16razcWfyX7yOHhjJPA=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFoffrOrmb+9T5kD1Mik66U7kT05jRUJv8T+4Q QQf+3VJFk6JAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH3wAKCRD6PaqMvJYe 9ffoD/9qZwj/3vcR0KTbgA8JHtYHcaUZEM0+R86IgWziprU1EFZN73UOvOFmDAytAOaEBvxNvlA rZDsZAiqXFfWbo2Lh+oQQOZwIUHortkb6azielqYzH8CmUGSWB/o7AgZ85/NEUW3OoqO1fo6d0D j+MdOlfhGlb1ZTqmkNjf1ankgUF0kOdm/2yn+iKJkvF6u2wVSCPX24zha3Lpe/lV6wiXPl3iapI WVC+TlpOMVHlhFCykMngFnoxkgR5Sys/luTd1nIGxo8Wpbev3pqHWN7lho4lQekXtY0A4crlxFd Hqz7CzH6dlwCEjjByofA/hm+mXrZQmHH7BNDhbdjMu7+5CT/OyEuA5Usvb4eLPtTHWzu/dLxG36 fPUjDiD/mXwwtFVCM3bhSVLoAa8CUHeWz6PpKBnzs9S6IIYn1LQPeq8dZ3Stet9z3boz0HQu7Rq XtG0injIOhAe6krue24KbQ+7tXhUzTSBlgV029E1K8pTdv2RFC3IqDFolwHlC6Ad2rl2kfu57e1 pKJKHQroNGvU3eeftbBeVTsWD20J2y1R8vQdGLkdj3OiO1YU96b7aO9OtfkExfd5c2kmuLEDVNA q+vhrxdkwyuKcqj7rgx2Aoa/d7ETeeP7vv5O1YQmydPZfERVcK/4Raf0MRatJ/G7ncKpCj5GXjO fTl/pCSbbn5uHOQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -3.3 (---) X-LSpam-Report: No, score=-3.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no v4l2_subdev_enable/disable_streams_fallback() supports falling back to .s_stream() for subdevs with a single source pad. It also tracks the enabled streams for that one pad in the sd->enabled_streams field. Tracking the enabled streams with sd->enabled_streams does not make sense, as with .s_stream() there can only be a single stream per pad. Thus, as the v4l2_subdev_enable/disable_streams_fallback() only supports a single source pad, all we really need is a boolean which tells whether streaming has been enabled on this pad or not. However, as we only need a true/false state for a pad (instead of tracking which streams have been enabled for a pad), we can easily extend the fallback mechanism to support multiple source pads as we only need to keep track of which pads have been enabled. Change the sd->enabled_streams field to sd->enabled_pads, which is a 64-bit bitmask tracking the enabled source pads. With this change we can remove the restriction that v4l2_subdev_enable/disable_streams_fallback() only supports a single source pad. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 68 ++++++++++++++++++++--------------- include/media/v4l2-subdev.h | 9 +++-- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 6cd353d83dfc..3d2c9c224b8f 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2104,37 +2104,43 @@ static int v4l2_subdev_enable_streams_fallback(struct v4l2_subdev *sd, u32 pad, u64 streams_mask) { struct device *dev = sd->entity.graph_obj.mdev->dev; - unsigned int i; int ret; /* * The subdev doesn't implement pad-based stream enable, fall back - * on the .s_stream() operation. This can only be done for subdevs that - * have a single source pad, as sd->enabled_streams is global to the - * subdev. + * to the .s_stream() operation. */ if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) return -EOPNOTSUPP; - for (i = 0; i < sd->entity.num_pads; ++i) { - if (i != pad && sd->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE) - return -EOPNOTSUPP; - } + /* + * .s_stream() means there is no streams support, so only allowed stream + * is the implicit stream 0. + */ + if (streams_mask != BIT_ULL(0)) + return -EOPNOTSUPP; + + /* + * We use a 64-bit bitmask for tracking enabled pads, so only subdevices + * with 64 pads or less can be supported. + */ + if (pad >= sizeof(sd->enabled_pads) * BITS_PER_BYTE) + return -EOPNOTSUPP; - if (sd->enabled_streams & streams_mask) { - dev_dbg(dev, "set of streams %#llx already enabled on %s:%u\n", - streams_mask, sd->entity.name, pad); + if (sd->enabled_pads & BIT_ULL(pad)) { + dev_dbg(dev, "pad %u already enabled on %s\n", + pad, sd->entity.name); return -EALREADY; } - /* Start streaming when the first streams are enabled. */ - if (!sd->enabled_streams) { + /* Start streaming when the first pad is enabled. */ + if (!sd->enabled_pads) { ret = v4l2_subdev_call(sd, video, s_stream, 1); if (ret) return ret; } - sd->enabled_streams |= streams_mask; + sd->enabled_pads |= BIT_ULL(pad); return 0; } @@ -2221,37 +2227,43 @@ static int v4l2_subdev_disable_streams_fallback(struct v4l2_subdev *sd, u32 pad, u64 streams_mask) { struct device *dev = sd->entity.graph_obj.mdev->dev; - unsigned int i; int ret; /* - * If the subdev doesn't implement pad-based stream enable, fall back - * on the .s_stream() operation. This can only be done for subdevs that - * have a single source pad, as sd->enabled_streams is global to the - * subdev. + * If the subdev doesn't implement pad-based stream enable, fall back + * to the .s_stream() operation. */ if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) return -EOPNOTSUPP; - for (i = 0; i < sd->entity.num_pads; ++i) { - if (i != pad && sd->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE) - return -EOPNOTSUPP; - } + /* + * .s_stream() means there is no streams support, so only allowed stream + * is the implicit stream 0. + */ + if (streams_mask != BIT_ULL(0)) + return -EOPNOTSUPP; + + /* + * We use a 64-bit bitmask for tracking enabled pads, so only subdevices + * with 64 pads or less can be supported. + */ + if (pad >= sizeof(sd->enabled_pads) * BITS_PER_BYTE) + return -EOPNOTSUPP; - if ((sd->enabled_streams & streams_mask) != streams_mask) { - dev_dbg(dev, "set of streams %#llx already disabled on %s:%u\n", - streams_mask, sd->entity.name, pad); + if (!(sd->enabled_pads & BIT_ULL(pad))) { + dev_dbg(dev, "pad %u already disabled on %s\n", + pad, sd->entity.name); return -EALREADY; } /* Stop streaming when the last streams are disabled. */ - if (!(sd->enabled_streams & ~streams_mask)) { + if (!(sd->enabled_pads & ~BIT_ULL(pad))) { ret = v4l2_subdev_call(sd, video, s_stream, 0); if (ret) return ret; } - sd->enabled_streams &= ~streams_mask; + sd->enabled_pads &= ~BIT_ULL(pad); return 0; } diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index f55d03e0acc1..d6867511e9cf 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1039,10 +1039,9 @@ struct v4l2_subdev_platform_data { * @active_state: Active state for the subdev (NULL for subdevs tracking the * state internally). Initialized by calling * v4l2_subdev_init_finalize(). - * @enabled_streams: Bitmask of enabled streams used by - * v4l2_subdev_enable_streams() and - * v4l2_subdev_disable_streams() helper functions for fallback - * cases. + * @enabled_pads: Bitmask of enabled pads used by v4l2_subdev_enable_streams() + * and v4l2_subdev_disable_streams() helper functions for + * fallback cases. * @streaming_enabled: Tracks whether streaming has been enabled with s_stream. * This is only for call_s_stream() internal use. * @@ -1092,7 +1091,7 @@ struct v4l2_subdev { * doesn't support it. */ struct v4l2_subdev_state *active_state; - u64 enabled_streams; + u64 enabled_pads; bool streaming_enabled; }; From patchwork Wed Apr 10 12:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100689 Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXDY-0008EO-0N for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:38:21 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5B6571F2330D for ; Wed, 10 Apr 2024 12:38:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A149D15EFA4; Wed, 10 Apr 2024 12:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ufK+Hltk" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9690158DA7; Wed, 10 Apr 2024 12:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752623; cv=none; b=Nd1efu/S0qhNsqHZcrJO4iUahbFdgfWHeTZN3c5qTYlWUrFEjvB1QYCaUtxe8egARyry67ycVDnvQigWpzZ/qJI36gpNqZJOb5AilaZ7eLUQBC9RB+EP3M/Uazo0dxwUGCpi5AZAzMNrfm0GAqy2zIkrmaXWvo8i2Jewg3INKsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752623; c=relaxed/simple; bh=Z3y+DXom2sYBr8/nzth539braLdHBd1S/1ycd5blWaU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mqxnx7lGEDQmDbarE2Mmx/DseScCtThrQjE09Xrr5Whq8QHQVEbTnanyux6LargqIf8LDrslFzalu2bE0M5CnVEJuwp8rlZmmVE3aY3/u36wIJrw9F+4rRwOwhDj7d7+g79tvHpviQqQSSKWGCqb08/Gxhb4qA+T+9uZJqu+3tc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=ufK+Hltk; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5154814A1; Wed, 10 Apr 2024 14:36:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752571; bh=Z3y+DXom2sYBr8/nzth539braLdHBd1S/1ycd5blWaU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ufK+HltkNk0cfi9zcJ27bHL+aSkmYUT6URrXgh/OAGR0FUVlbamuVaCuJGqNQDa2C VhaJfK+O1DJ0ldB3Evb/dipOtLQ8CHH4ykwfWUJeyA0mVokU71dUqHJVfvDB/9Zdo6 02LUp2JuLrjwB54rE4snqJ4S9jMhoqGwM1s1xgTw= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:53 +0300 Subject: [PATCH v3 6/9] media: subdev: Add v4l2_subdev_is_streaming() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-6-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2396; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=Z3y+DXom2sYBr8/nzth539braLdHBd1S/1ycd5blWaU=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFofg25H4C/H696g20oiaJQWCJc7JycaFyTqTj voa/VWNsSKJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH4AAKCRD6PaqMvJYe 9Vw3D/9E33yQbqpZIEwhEi09si+Vo9tW//xdtzWPmqjDkCCpifeXjx1a5PlGLTev+WM04zRAI7Y WfW+Go15aMUCRZYbtdCXTZyLGB/JKozH+71w4rijSxg9aw3tohZ8eIfxeyezkmdqPQgc70NMdow vZRi6NQy29XVEZInkwZ1TnglRTaT4ZVy/FU7r6tEwsbMXpzg9eUrgmKuS6jeG8BTTYk0JgqQDcj AoXsR29LOcp4aUzdS7mbL1OJe/m/fta0J5iuXM7kDgidy10SnW9hmqGBrqkrn3y2BiRhMnl0SmY ra/d+dv3hRxQkZfluGhvJ8/KlDNmGnWuLwiPnTQrzh5x8QFIjul6xBKz8IV31ANk99QHUf/0gaR C0NPeZxnVWernqMmM8nuaUqIg9nS2PzQRAP9vKDYCoX7Ldu10oS60C69pV7o172YhfxPFKCdSh6 ev3NjpYFBL1gWwH1FGmVA+8uilCT+kehNlVcCCWTlNPMVZJUsKruIm2dReEu8VHuxw+ZJVBBKkJ LQxtOMdTdhNtjPSDUcCM7UT7IImoNK6/9W/EYzFG9yG0s6eEWf400MKnpt2J7EAKne+gs9vZ7op 05EAHR9EtZYP23lF8A2PDe28mW2jHRlVGZR9CzvVB9vY5OFaF90uoRw16O+I2iUa9WcZzOpDums Bk+ilIQZWjOwSlA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -3.3 (---) X-LSpam-Report: No, score=-3.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no Add a helper function which returns whether the subdevice is streaming, i.e. if .s_stream or .enable_streams has been called successfully. Signed-off-by: Tomi Valkeinen Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 25 +++++++++++++++++++++++++ include/media/v4l2-subdev.h | 13 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 3d2c9c224b8f..20b5a00cbeeb 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2419,6 +2419,31 @@ void v4l2_subdev_notify_event(struct v4l2_subdev *sd, } EXPORT_SYMBOL_GPL(v4l2_subdev_notify_event); +bool v4l2_subdev_is_streaming(struct v4l2_subdev *sd) +{ + struct v4l2_subdev_state *state; + + if (!v4l2_subdev_has_op(sd, pad, enable_streams)) + return sd->streaming_enabled; + + state = v4l2_subdev_get_locked_active_state(sd); + + if (!(sd->flags & V4L2_SUBDEV_FL_STREAMS)) + return !!sd->enabled_pads; + + for (unsigned int i = 0; i < state->stream_configs.num_configs; ++i) { + const struct v4l2_subdev_stream_config *cfg; + + cfg = &state->stream_configs.configs[i]; + + if (cfg->enabled) + return true; + } + + return false; +} +EXPORT_SYMBOL_GPL(v4l2_subdev_is_streaming); + int v4l2_subdev_get_privacy_led(struct v4l2_subdev *sd) { #if IS_REACHABLE(CONFIG_LEDS_CLASS) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index d6867511e9cf..270a4dfa5663 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1914,4 +1914,17 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers; void v4l2_subdev_notify_event(struct v4l2_subdev *sd, const struct v4l2_event *ev); +/** + * v4l2_subdev_is_streaming() - Returns if the subdevice is streaming + * @sd: The subdevice + * + * v4l2_subdev_is_streaming() tells if the subdevice is currently streaming. + * "Streaming" here means whether .s_stream() or .enable_streams() has been + * successfully called, and the streaming has not yet been disabled. + * + * If the subdevice implements .enable_streams() this function must be called + * while holding the active state lock. + */ +bool v4l2_subdev_is_streaming(struct v4l2_subdev *sd); + #endif /* _V4L2_SUBDEV_H */ From patchwork Wed Apr 10 12:35:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100690 Received: from sy.mirrors.kernel.org ([147.75.48.161]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXDm-0008Ez-2A for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:38:35 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 051E4B2510A for ; Wed, 10 Apr 2024 12:38:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2A5D15EFC7; Wed, 10 Apr 2024 12:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sfcDrSAC" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A6A215ECF6; Wed, 10 Apr 2024 12:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752624; cv=none; b=u36TFF0Dnq7WQVCe/YI6ZnGNYsku596obVUMIVrTjLfk9P58hCUBR1Bauv5DHiKM19Y7zYPl2URDx9UdmGSjLmq74NLxxxM3IHT+HUC2boi8ExYgz+SmKrzEv0vHY56s7VZADMkxLHgGZuz2/m8/eYE39nEL/6D9l6pF6EdS89U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752624; c=relaxed/simple; bh=hRB6xu4Gvrssh3hd8DJ5x+z0vwvdgTm2jJp20gCrEQE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QsSJQlxWGGYRRpTL+gfMCGkOgPI4Ppy1vYPBB1hLPRtvr1525/2Lj/vMMlh7nCJHRGEU7rwsiZa9TJWRleJbpNArQTdviJGGzkkiH/2vfO02qvCZXJQH3xyLNEl5F5p576iamAck4r0WzU4BDEmMYvMOsDqqlh3kMGNNUZKwd/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=sfcDrSAC; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EBFC714B0; Wed, 10 Apr 2024 14:36:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752572; bh=hRB6xu4Gvrssh3hd8DJ5x+z0vwvdgTm2jJp20gCrEQE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sfcDrSACz0htDyjgcxa2NuVtPM0+z3Umjmp2aC/NESaVoAi5v05mz1ypnzA1R61D0 efnOgMpXM8jGb/k1UJxfzkQ63TagxPCaqqdxIImFsD7uvJb61Y4AWJ+Q+QrOmg9DRJ JWMhb4qN9jtr0vA28cGtUcPZI0WHa7MqNIUiYa6c= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:54 +0300 Subject: [PATCH v3 7/9] media: subdev: Support privacy led in v4l2_subdev_enable/disable_streams() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-7-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1801; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=hRB6xu4Gvrssh3hd8DJ5x+z0vwvdgTm2jJp20gCrEQE=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFofgJyrv6yCOEWpoR3A9i+WJn9yQs39dAJLN9 KdT4u143kaJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH4AAKCRD6PaqMvJYe 9RMvD/9Ta8NNCGdrq4kkHx3nHJxgf7X/LGGWZGaEskyUklwvSkpvQjoUoheMtLyhkAfy/R/SgfH kn+OVqlpZP9cjfQ5nl56yzuYrwVRofxwg9Jm0snqsTgsGIhRlc3QDObyVbzsyI+xnUqKRXodEvb koQ/WglskmJ2uUawJThfxOAWZATA2NVLhZh7EgazbeWThgAb0WKGiGnI76K1cC7E68ZF0l+ye1O FcaU8LMhBqXuAwiYbH4G4qHEWB/hVnb3j2iVNmmtxhm6z80IPJBpM/uQhzXIknvdiSXqAjNvIVz Gkd8ZeGV5Kc5n3kIho3LVc7pyGTfUFf5i1oEPhr7op8cCqxnRSEWxDud/aYMOVg6a75QlF6Jz/3 GJuCvToxj2HGcS/JF5Jz1sahgm8bmf4O11JLrRIXpEdU+8a3dLCFE4DOiKrCQBSQwKl4spTw8JU Juf0YA9Dga7yyrstGMz6POGDSpieYuYy3lriHFVkohBXTAD193oKR3/T8Re7IWanNQKFEXGkhA/ v8xduF2xXQWL+gQhfzR97J0M69hEbbbqMOVk+YN63fVfURY2z2r3E6Q2Dkfrnh2dzGWr+VAo/Ky Y5NYWV8yRyqYBJeZz29XdooRpm8+iKsZjiKVT97v7+32pzrADO0xuVUI7yiuZcf7GSoeF4Nv8vS lZ7EQVzGzdtf3xg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -3.3 (---) X-LSpam-Report: No, score=-3.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no We support camera privacy leds with the .s_stream, in call_s_stream, but we don't have that support when the subdevice implements .enable/disable_streams. Add the support by enabling the led when the first stream for a subdevice is enabled, and disabling the led then the last stream is disabled. Signed-off-by: Tomi Valkeinen Reviewed-by: Umang Jain --- drivers/media/v4l2-core/v4l2-subdev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 20b5a00cbeeb..f44aaa4e1fab 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2150,6 +2150,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, { struct device *dev = sd->entity.graph_obj.mdev->dev; struct v4l2_subdev_state *state; + bool already_streaming; u64 found_streams = 0; unsigned int i; int ret; @@ -2198,6 +2199,8 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, dev_dbg(dev, "enable streams %u:%#llx\n", pad, streams_mask); + already_streaming = v4l2_subdev_is_streaming(sd); + /* Call the .enable_streams() operation. */ ret = v4l2_subdev_call(sd, pad, enable_streams, state, pad, streams_mask); @@ -2216,6 +2219,9 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, cfg->enabled = true; } + if (!already_streaming) + v4l2_subdev_enable_privacy_led(sd); + done: v4l2_subdev_unlock_state(state); @@ -2340,6 +2346,9 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, } done: + if (!v4l2_subdev_is_streaming(sd)) + v4l2_subdev_disable_privacy_led(sd); + v4l2_subdev_unlock_state(state); return ret; From patchwork Wed Apr 10 12:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100691 Received: from sy.mirrors.kernel.org ([147.75.48.161]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXE8-0008GA-2Q for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:38:57 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 19367B253B3 for ; Wed, 10 Apr 2024 12:38:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF4A5158DA7; Wed, 10 Apr 2024 12:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kW3hV9x9" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8B5215EFC4; Wed, 10 Apr 2024 12:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752626; cv=none; b=mrb/iTA+bZ2KAsr9rDzhMXOCYWpt8/soLaKSGFmI2OIFUH2KLmHJwJH69ZDJDVIME1PfHdfpL6wt/bj4c9Ev2GtkAZHBTgOIK1y6bEoDLDXYoaX8vCmIgtD0G13mM5XOk15LE6Yl19NyY6RRx/MwVXHqij57ovJqRb1DSdwxdsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752626; c=relaxed/simple; bh=hIT1XDENjpdRkRoM6FaZj9/JwzLPb3kW37UU3WDbkSg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c8+NxzDVYGXiBY3vFju+K4yccrdX7XK63WGDxNLRkS7Iocqbtx/FsqWswmwyACYoSPVzw9JbWZsCNSGHnGlvGMhaJUzRJrhaCL05XJFoA5wMKcalO6MgpnhCbh9td7fjMw621WWivsmMSTcPjNEBNODuBIhgKLHYA4I5pbjOw5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=kW3hV9x9; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7ACFF151C; Wed, 10 Apr 2024 14:36:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752572; bh=hIT1XDENjpdRkRoM6FaZj9/JwzLPb3kW37UU3WDbkSg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kW3hV9x9XScAFEwkqzJvvppZPNpcI5Z8a4LLFOtKWtb7RLARKBkMR1Df9LiGOV6Qe dT4mDUTLBXrbWPgFVueECCxkjN4+zuaYqOYjQk2swIxFgChBW/V1kgN9Bfma9AAQH9 DBMGxduCQ4uKWi73MuN0IMIJLF9HYVCHDq8HGDIo= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:55 +0300 Subject: [PATCH v3 8/9] media: subdev: Refactor v4l2_subdev_enable/disable_streams() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-8-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6373; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=hIT1XDENjpdRkRoM6FaZj9/JwzLPb3kW37UU3WDbkSg=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFofgo7pzmuWifhCsQb6bH1dxoJlcJ7YoPUSiH xCvBe86JIWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH4AAKCRD6PaqMvJYe 9evSEACbN0v7VCN1aaZLPfgepjPZhc+zcWV4aUV0IqwuhJgObnFJTDbOMgqzOP0K5mbdTojOPno bUicEsifQWenUUwkaZaoU0HLVmd614PLZC5wVDo1dX6wZp7b+nd10ns3tut0NuVSC1s+b5AX1Bw fAgehwIe7CE7juJ//0J16y9rm8k8LYi4UgfIArmVL6VB598ZnejrpIqPi6iPau0nJlj+zvG1i2Z 7H+qjTkx4HsF2oP4LUZc9qJ9rqLPgLgzl5eNM7tmf0o0ZsqYEjgvO4uOM6qYT+touQB6r/YcgKh ehDbwMXsDzzPJNJecJKaJCFKUCJXu22trtP1frTIs1q9RMOkXtxsxSP8bo3lAe96pjnP8rGbivW epimoim9nEtut1qTjVUGnQ6VBiM/mxjWZPbj1VHWL4k3FZztEx9ourkjMtVJY+eTtcEL1xuF7nK kXTQgi0QIzS0FA2s9FspIphvfpjVrgXHzk1y2/brbuPNH6P99S8zuG0rpTrK7Mknc7VzLHqarHu 7NzycT+BDKMtk6d6uNU31NEQoBCLhSgPyQhlNQkgltSh4RsEk9b6i4X58IZFS4qppAqoHv1YgBY lwLd/c9fD9vXTvZaPkOX1oLd3Iikp9BjPEM6aXcwhEv87xCWW/wRNBkQ1HwUzV4pKaj72dZa7E8 QjSrR5E3dzpPHaA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -3.3 (---) X-LSpam-Report: No, score=-3.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no Add two internal helper functions, v4l2_subdev_collect_streams() and v4l2_subdev_set_streams_enabled(), which allows us to refactor v4l2_subdev_enable/disable_streams() functions. This (I think) makes the code a bit easier to read, and lets us more easily add new functionality in the helper functions in the following patch. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 109 +++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 49 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index f44aaa4e1fab..0d376d72ecc7 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2100,6 +2100,42 @@ int v4l2_subdev_routing_validate(struct v4l2_subdev *sd, } EXPORT_SYMBOL_GPL(v4l2_subdev_routing_validate); +static void v4l2_subdev_collect_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + u32 pad, u64 streams_mask, + u64 *found_streams, + u64 *enabled_streams) +{ + *found_streams = 0; + *enabled_streams = 0; + + for (unsigned int i = 0; i < state->stream_configs.num_configs; ++i) { + const struct v4l2_subdev_stream_config *cfg = + &state->stream_configs.configs[i]; + + if (cfg->pad != pad || !(streams_mask & BIT_ULL(cfg->stream))) + continue; + + *found_streams |= BIT_ULL(cfg->stream); + if (cfg->enabled) + *enabled_streams |= BIT_ULL(cfg->stream); + } +} + +static void v4l2_subdev_set_streams_enabled(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + u32 pad, u64 streams_mask, + bool enabled) +{ + for (unsigned int i = 0; i < state->stream_configs.num_configs; ++i) { + struct v4l2_subdev_stream_config *cfg = + &state->stream_configs.configs[i]; + + if (cfg->pad == pad && (streams_mask & BIT_ULL(cfg->stream))) + cfg->enabled = enabled; + } +} + static int v4l2_subdev_enable_streams_fallback(struct v4l2_subdev *sd, u32 pad, u64 streams_mask) { @@ -2151,8 +2187,8 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, struct device *dev = sd->entity.graph_obj.mdev->dev; struct v4l2_subdev_state *state; bool already_streaming; - u64 found_streams = 0; - unsigned int i; + u64 enabled_streams; + u64 found_streams; int ret; /* A few basic sanity checks first. */ @@ -2173,22 +2209,9 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, * Verify that the requested streams exist and that they are not * already enabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; - if (cfg->pad != pad || !(streams_mask & BIT_ULL(cfg->stream))) - continue; - - found_streams |= BIT_ULL(cfg->stream); - - if (cfg->enabled) { - dev_dbg(dev, "stream %u already enabled on %s:%u\n", - cfg->stream, sd->entity.name, pad); - ret = -EALREADY; - goto done; - } - } + v4l2_subdev_collect_streams(sd, state, pad, streams_mask, + &found_streams, &enabled_streams); if (found_streams != streams_mask) { dev_dbg(dev, "streams 0x%llx not found on %s:%u\n", @@ -2197,6 +2220,13 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, goto done; } + if (enabled_streams) { + dev_dbg(dev, "streams 0x%llx already enabled on %s:%u\n", + enabled_streams, sd->entity.name, pad); + ret = -EINVAL; + goto done; + } + dev_dbg(dev, "enable streams %u:%#llx\n", pad, streams_mask); already_streaming = v4l2_subdev_is_streaming(sd); @@ -2211,13 +2241,7 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, } /* Mark the streams as enabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; - - if (cfg->pad == pad && (streams_mask & BIT_ULL(cfg->stream))) - cfg->enabled = true; - } + v4l2_subdev_set_streams_enabled(sd, state, pad, streams_mask, true); if (!already_streaming) v4l2_subdev_enable_privacy_led(sd); @@ -2279,8 +2303,8 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, { struct device *dev = sd->entity.graph_obj.mdev->dev; struct v4l2_subdev_state *state; - u64 found_streams = 0; - unsigned int i; + u64 enabled_streams; + u64 found_streams; int ret; /* A few basic sanity checks first. */ @@ -2301,22 +2325,9 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, * Verify that the requested streams exist and that they are not * already disabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; - - if (cfg->pad != pad || !(streams_mask & BIT_ULL(cfg->stream))) - continue; - found_streams |= BIT_ULL(cfg->stream); - - if (!cfg->enabled) { - dev_dbg(dev, "stream %u already disabled on %s:%u\n", - cfg->stream, sd->entity.name, pad); - ret = -EALREADY; - goto done; - } - } + v4l2_subdev_collect_streams(sd, state, pad, streams_mask, + &found_streams, &enabled_streams); if (found_streams != streams_mask) { dev_dbg(dev, "streams 0x%llx not found on %s:%u\n", @@ -2325,6 +2336,13 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, goto done; } + if (enabled_streams != streams_mask) { + dev_dbg(dev, "streams 0x%llx already disabled on %s:%u\n", + streams_mask & ~enabled_streams, sd->entity.name, pad); + ret = -EINVAL; + goto done; + } + dev_dbg(dev, "disable streams %u:%#llx\n", pad, streams_mask); /* Call the .disable_streams() operation. */ @@ -2336,14 +2354,7 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, goto done; } - /* Mark the streams as disabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; - - if (cfg->pad == pad && (streams_mask & BIT_ULL(cfg->stream))) - cfg->enabled = false; - } + v4l2_subdev_set_streams_enabled(sd, state, pad, streams_mask, false); done: if (!v4l2_subdev_is_streaming(sd)) From patchwork Wed Apr 10 12:35:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 100692 Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ruXEK-0008Hx-0p for patchwork@linuxtv.org; Wed, 10 Apr 2024 12:39:09 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3F5FD1F226E8 for ; Wed, 10 Apr 2024 12:39:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31EC015F406; Wed, 10 Apr 2024 12:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BTJi0m/n" X-Original-To: linux-media@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 191DA15F316; Wed, 10 Apr 2024 12:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752627; cv=none; b=HxXb5KugIghPj7wzWPK4hyKcmLtkLT9Xhy6cVaglWhG1/24vTfuuHYo5gxSLb2S84Wc6tIneVRn+HlCq20Se6BN6Ojw1M1oXWlL9lYSEHRzD+Zx9kPbtuMYFuSy8ratmyJqMCJfLWTmkAJ8PqR8nd8FvMjjFodLOoQWI53w12Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712752627; c=relaxed/simple; bh=RDRWk9cPd0EbkItiXklgU/yvzOSFezcQrKTTMoir4Ck=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tASlLdy5yVOi+y6Doun3XuTuo34UKCGb9FQzgG2yhCO73Mop6qa7x5/G5m22m+/OI1uYIBjCUWGyTOeHBhKtCI0JAwKSQGez71737Jxt6HevoKwDtTSt32ljjspjAK+JNYyor0NA9O5OqRSI2uPw7kdssQmlU9S/xnbtte2SvJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=BTJi0m/n; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B10D1570; Wed, 10 Apr 2024 14:36:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712752573; bh=RDRWk9cPd0EbkItiXklgU/yvzOSFezcQrKTTMoir4Ck=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BTJi0m/nJS13PHNqr7bS96cTu0JQl0Jms/tZqbUS7EOp21kYQYDt6COrKOte5VMgQ ydomjHXA+V+dj9eTC1P745dn4+cI0CbGD4yQkyviLSb5C0v/M9yrj2kUE7+x4ler/e YyV3geHeDK1m5E9MV5Y2xhHSNWYqEGSeEZWk/Ycc= From: Tomi Valkeinen Date: Wed, 10 Apr 2024 15:35:56 +0300 Subject: [PATCH v3 9/9] media: subdev: Support single-stream case in v4l2_subdev_enable/disable_streams() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240410-enable-streams-impro-v3-9-e5e7a5da7420@ideasonboard.com> References: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> In-Reply-To: <20240410-enable-streams-impro-v3-0-e5e7a5da7420@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=10470; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=RDRWk9cPd0EbkItiXklgU/yvzOSFezcQrKTTMoir4Ck=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmFofhhwW/yULL244EtwpJRVWfBEq4i74nmJo9Z FypvcBkqTCJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZhaH4QAKCRD6PaqMvJYe 9VifD/9dbLrFmBxSLSf4EP96Pjk0H42IQMW9XNW0a64Ihm+r0zYlvp3pVeEUTY1ra8aEV6VLiGP TwXRxrLCeKWHZ8eWNJNKRkeUdZSzHe48oAJ+bFGj+dboHc59GWg7TxuCWNspnbeDgwGeh+VfugQ N8zKsLgKKm6zUCMnv2TLUXKX/7AWfJNVa6SghURJtCUnDRXxJ2NrX9/uMCN4hlu0NqfV9Qeug7C 18bDbOrSFHFEdGyP9lbNsCZ+mTrtc4EMJMhHBzUoBsnAblkllFXg96eTiuQX1R1jjglERGwyK2O 2CQrXX6IBXTvdZ1RXBeV00XyBzhm3KHqtOYiAAuE3cuIYEhjBqJAVGo0e3i3CadUn1fTJQ82bTk sRJ7YH+noBnJOXokPFSmb9CVRQHAo0US63XTN4zYDaj67s+9ilHF5dN5EVovKKKdWYpUtpWoQAc 9jB6ebWMTlIQolp6DCUhPnvysDmEKJA2i4I/1ZrwxBsMbstyYTT/BAAQ6JgS7omfPQ1DU3x9+Xd MrTcR6yrjOv+Bxpnhe609OkOJgz7VyMoqUCQbNxj8zLyNMe3rjaX0YU9h3/5P1lso64amZ2FR7O AJKlFPP8M6YyGvnUAjY86HPY0t9FrAD7F43mVrT5VouCId6RP8lvEfPJEMZKZ6bo686WbCpPzzH BKJ/3Nm6GaRUpqQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-LSpam-Score: -3.3 (---) X-LSpam-Report: No, score=-3.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no At the moment the v4l2_subdev_enable/disable_streams() functions call fallback helpers to handle the case where the subdev only implements .s_stream(), and the main function handles the case where the subdev implements streams (V4L2_SUBDEV_FL_STREAMS, which implies .enable/disable_streams()). What is missing is support for subdevs which do not implement streams support, but do implement .enable/disable_streams(). Example cases of these subdevices are single-stream cameras, where using .enable/disable_streams() is not required but helps us remove the users of the legacy .s_stream(), and subdevices with multiple source pads (but single stream per pad), where .enable/disable_streams() allows the subdevice to control the enable/disable state per pad. The two single-streams cases (.s_stream() and .enable/disable_streams()) are very similar, and with small changes we can change the v4l2_subdev_enable/disable_streams() functions to support all three cases, without needing separate fallback functions. A few potentially problematic details, though: - For the single-streams cases we use sd->enabled_pads field, which limits the number of pads for the subdevice to 64. For simplicity I added the check for this limitation to the beginning of the function, and it also applies to the streams case. - The fallback functions only allowed the target pad to be a source pad. It is not very clear to me why this check was needed, but it was not needed in the streams case. However, I doubt the v4l2_subdev_enable/disable_streams() code has ever been tested with sink pads, so to be on the safe side, I added the same check to the v4l2_subdev_enable/disable_streams() functions. Signed-off-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 187 ++++++++++++++-------------------- 1 file changed, 79 insertions(+), 108 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 0d376d72ecc7..4a73886741f9 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2106,6 +2106,13 @@ static void v4l2_subdev_collect_streams(struct v4l2_subdev *sd, u64 *found_streams, u64 *enabled_streams) { + if (!(sd->flags & V4L2_SUBDEV_FL_STREAMS)) { + *found_streams = BIT_ULL(0); + if (sd->enabled_pads & BIT_ULL(pad)) + *enabled_streams = BIT_ULL(0); + return; + } + *found_streams = 0; *enabled_streams = 0; @@ -2127,6 +2134,14 @@ static void v4l2_subdev_set_streams_enabled(struct v4l2_subdev *sd, u32 pad, u64 streams_mask, bool enabled) { + if (!(sd->flags & V4L2_SUBDEV_FL_STREAMS)) { + if (enabled) + sd->enabled_pads |= BIT_ULL(pad); + else + sd->enabled_pads &= ~BIT_ULL(pad); + return; + } + for (unsigned int i = 0; i < state->stream_configs.num_configs; ++i) { struct v4l2_subdev_stream_config *cfg = &state->stream_configs.configs[i]; @@ -2136,51 +2151,6 @@ static void v4l2_subdev_set_streams_enabled(struct v4l2_subdev *sd, } } -static int v4l2_subdev_enable_streams_fallback(struct v4l2_subdev *sd, u32 pad, - u64 streams_mask) -{ - struct device *dev = sd->entity.graph_obj.mdev->dev; - int ret; - - /* - * The subdev doesn't implement pad-based stream enable, fall back - * to the .s_stream() operation. - */ - if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) - return -EOPNOTSUPP; - - /* - * .s_stream() means there is no streams support, so only allowed stream - * is the implicit stream 0. - */ - if (streams_mask != BIT_ULL(0)) - return -EOPNOTSUPP; - - /* - * We use a 64-bit bitmask for tracking enabled pads, so only subdevices - * with 64 pads or less can be supported. - */ - if (pad >= sizeof(sd->enabled_pads) * BITS_PER_BYTE) - return -EOPNOTSUPP; - - if (sd->enabled_pads & BIT_ULL(pad)) { - dev_dbg(dev, "pad %u already enabled on %s\n", - pad, sd->entity.name); - return -EALREADY; - } - - /* Start streaming when the first pad is enabled. */ - if (!sd->enabled_pads) { - ret = v4l2_subdev_call(sd, video, s_stream, 1); - if (ret) - return ret; - } - - sd->enabled_pads |= BIT_ULL(pad); - - return 0; -} - int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, u64 streams_mask) { @@ -2189,21 +2159,33 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, bool already_streaming; u64 enabled_streams; u64 found_streams; + bool use_s_stream; int ret; /* A few basic sanity checks first. */ if (pad >= sd->entity.num_pads) return -EINVAL; + if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) + return -EOPNOTSUPP; + + /* + * We use a 64-bit bitmask for tracking enabled pads, so only subdevices + * with 64 pads or less can be supported. + */ + if (pad >= sizeof(sd->enabled_pads) * BITS_PER_BYTE) + return -EOPNOTSUPP; + if (!streams_mask) return 0; /* Fallback on .s_stream() if .enable_streams() isn't available. */ - if (!v4l2_subdev_has_op(sd, pad, enable_streams)) - return v4l2_subdev_enable_streams_fallback(sd, pad, - streams_mask); + use_s_stream = !v4l2_subdev_has_op(sd, pad, enable_streams); - state = v4l2_subdev_lock_and_get_active_state(sd); + if (!use_s_stream) + state = v4l2_subdev_lock_and_get_active_state(sd); + else + state = NULL; /* * Verify that the requested streams exist and that they are not @@ -2231,9 +2213,18 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, already_streaming = v4l2_subdev_is_streaming(sd); - /* Call the .enable_streams() operation. */ - ret = v4l2_subdev_call(sd, pad, enable_streams, state, pad, - streams_mask); + if (!use_s_stream) { + /* Call the .enable_streams() operation. */ + ret = v4l2_subdev_call(sd, pad, enable_streams, state, pad, + streams_mask); + } else { + /* Start streaming when the first pad is enabled. */ + if (!already_streaming) + ret = v4l2_subdev_call(sd, video, s_stream, 1); + else + ret = 0; + } + if (ret) { dev_dbg(dev, "enable streams %u:%#llx failed: %d\n", pad, streams_mask, ret); @@ -2243,34 +2234,32 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, /* Mark the streams as enabled. */ v4l2_subdev_set_streams_enabled(sd, state, pad, streams_mask, true); - if (!already_streaming) + if (!use_s_stream && !already_streaming) v4l2_subdev_enable_privacy_led(sd); done: - v4l2_subdev_unlock_state(state); + if (!use_s_stream) + v4l2_subdev_unlock_state(state); return ret; } EXPORT_SYMBOL_GPL(v4l2_subdev_enable_streams); -static int v4l2_subdev_disable_streams_fallback(struct v4l2_subdev *sd, u32 pad, - u64 streams_mask) +int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, + u64 streams_mask) { struct device *dev = sd->entity.graph_obj.mdev->dev; + struct v4l2_subdev_state *state; + u64 enabled_streams; + u64 found_streams; + bool use_s_stream; int ret; - /* - * If the subdev doesn't implement pad-based stream enable, fall back - * to the .s_stream() operation. - */ - if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) - return -EOPNOTSUPP; + /* A few basic sanity checks first. */ + if (pad >= sd->entity.num_pads) + return -EINVAL; - /* - * .s_stream() means there is no streams support, so only allowed stream - * is the implicit stream 0. - */ - if (streams_mask != BIT_ULL(0)) + if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) return -EOPNOTSUPP; /* @@ -2280,46 +2269,16 @@ static int v4l2_subdev_disable_streams_fallback(struct v4l2_subdev *sd, u32 pad, if (pad >= sizeof(sd->enabled_pads) * BITS_PER_BYTE) return -EOPNOTSUPP; - if (!(sd->enabled_pads & BIT_ULL(pad))) { - dev_dbg(dev, "pad %u already disabled on %s\n", - pad, sd->entity.name); - return -EALREADY; - } - - /* Stop streaming when the last streams are disabled. */ - if (!(sd->enabled_pads & ~BIT_ULL(pad))) { - ret = v4l2_subdev_call(sd, video, s_stream, 0); - if (ret) - return ret; - } - - sd->enabled_pads &= ~BIT_ULL(pad); - - return 0; -} - -int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, - u64 streams_mask) -{ - struct device *dev = sd->entity.graph_obj.mdev->dev; - struct v4l2_subdev_state *state; - u64 enabled_streams; - u64 found_streams; - int ret; - - /* A few basic sanity checks first. */ - if (pad >= sd->entity.num_pads) - return -EINVAL; - if (!streams_mask) return 0; /* Fallback on .s_stream() if .disable_streams() isn't available. */ - if (!v4l2_subdev_has_op(sd, pad, disable_streams)) - return v4l2_subdev_disable_streams_fallback(sd, pad, - streams_mask); + use_s_stream = !v4l2_subdev_has_op(sd, pad, disable_streams); - state = v4l2_subdev_lock_and_get_active_state(sd); + if (!use_s_stream) + state = v4l2_subdev_lock_and_get_active_state(sd); + else + state = NULL; /* * Verify that the requested streams exist and that they are not @@ -2345,9 +2304,19 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, dev_dbg(dev, "disable streams %u:%#llx\n", pad, streams_mask); - /* Call the .disable_streams() operation. */ - ret = v4l2_subdev_call(sd, pad, disable_streams, state, pad, - streams_mask); + if (!use_s_stream) { + /* Call the .disable_streams() operation. */ + ret = v4l2_subdev_call(sd, pad, disable_streams, state, pad, + streams_mask); + } else { + /* Stop streaming when the last streams are disabled. */ + + if (!(sd->enabled_pads & ~BIT_ULL(pad))) + ret = v4l2_subdev_call(sd, video, s_stream, 0); + else + ret = 0; + } + if (ret) { dev_dbg(dev, "disable streams %u:%#llx failed: %d\n", pad, streams_mask, ret); @@ -2357,10 +2326,12 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, v4l2_subdev_set_streams_enabled(sd, state, pad, streams_mask, false); done: - if (!v4l2_subdev_is_streaming(sd)) - v4l2_subdev_disable_privacy_led(sd); + if (!use_s_stream) { + if (!v4l2_subdev_is_streaming(sd)) + v4l2_subdev_disable_privacy_led(sd); - v4l2_subdev_unlock_state(state); + v4l2_subdev_unlock_state(state); + } return ret; }