From patchwork Tue Apr 16 13:55:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631885 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 6F99B128398; Tue, 16 Apr 2024 13:55:27 +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=1713275728; cv=none; b=uLk+RpYfI6YZGndph/7Z56LlmFk2purRyBAn2eQqqRRj2PIpBqclK/zB7PYumWymLl61Qty2NsjIzHkU6oBKBLOCWEFNRs6bCZv1k4SkgqYJe29bF7ClzTjP1zv7fXUDTzSoaeoSm0L/4r4DBHb0bxC3c56p9j3IJfRHmzaLJJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275728; c=relaxed/simple; bh=HDDQMoAu1J/nqy54T1qbzKVRZVUdd5vlToKPN3OlY38=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bO6YoH+CAorcgmxsHA7lZYIpDcMX7aCafP14m+5yBOCQv3hqX8c2brikoOhr0FwkdR38QUljPBzOmGCJyVYRnyofabp0NUKUogk0EDv4jjuUCvpYnWp66I+YY8DMDoLcsf1SpzfBmMQ8OZD1X1UvMjIEuLmiucFUaqRE7vckNiY= 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=a7EI6CAC; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="a7EI6CAC" 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 1FF18E0C; Tue, 16 Apr 2024 15:54:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275679; bh=HDDQMoAu1J/nqy54T1qbzKVRZVUdd5vlToKPN3OlY38=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=a7EI6CACsqLunUDEnSPpIU4SfR+wgzOUvX6YdGZPhfC6Y4qVwDgG9RYW9gmmg+5Ft mkYqLhAULJSuNqIuorpZ2o20bZrcBpgmuOey5Jtq1RFzGQ51TFzZ9aUC7VlfEcLRn+ ER2wKztvgzALZYSn+YAiLbtQHfKh5TGfxkOt2l7o= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:04 +0300 Subject: [PATCH v5 01/10] 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: <20240416-enable-streams-impro-v5-1-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=1985; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=HDDQMoAu1J/nqy54T1qbzKVRZVUdd5vlToKPN3OlY38=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNIYoTxjUiNWqxEKS5D3N9kKWEU+csS6oTBA lt2AfmvtpuJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSAAKCRD6PaqMvJYe 9RtLEACNAd54didoxkE1V2UMhayPIb36iZSRoUG+xPUGVuqEzeQMDBGVH3qpbxOyH7Xb+D6DruQ gN8Ngl/AcVT9Y0mz5GLVuWl4+VJqrgTSF0RQR5X1f38DcZHE6kj0TwekQyOPqP5nuL34zvENr8q JnxNw1DFo9RCXo9MDohCs6o3WM8RXM6I1Rw19SWWmNDK61tjQOjLYXYpWNIGE+gSC1BfCizs5xu +yr6BM+KVNMOTA6QdjhfFVDcRM9U4TzxC1xECbciLBggxlpHA65Vr+cd1g+JGZksQFmylpnaI6a CQc5XUR3k7Gx9SbZHydlCnA/BAstB18c6IpHdsv+4eMaLsqqrOJk2avv71LoTIUZEa3rwg9Wh66 PWYLgo+y4jPOoAi04gYRlEivZPLHH+yCx0fb/ABDO9lgQJCPAt3VySuIDhVINx6pAxpH4dS2Hr0 WtkG4kCb/U4nJT6Ud+69wGtZ3UKWzoIYzyyHqex1fHIaVSUBwnV25dJEv9EmN1LFZPY4fprLZ4H 0MqaZXyTz98D1prl2mEItdc26N08ZYHmtRW6onBNKOsPJFwwHIfTVxKEgrydQiwupeI2TXIx85Q iZz4YKXf8QoXRK3Jnqh4YZEqYVC5tU8KMnUQ/rzClTOlfcw4FM0vF4PLrvU7znkQg5KCIu+RLPp mcNUlQX7zo5dKiA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 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. Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- 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 Tue Apr 16 13:55:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631887 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 2691D12D1F4; Tue, 16 Apr 2024 13:55:29 +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=1713275731; cv=none; b=pE07URz5Mmqy9Xi85pGVPVT0v1CRC7YB+YTGzASD4A5OAn9pJ9KBS4FKxlW832HqFMyoUXTnpJvnS9AnkclihkYGa0cp7n5OT20P94bdeywdiIK79Rj2gCyz4lNaN3s1DmClxp/TAi8dXEYbg69usSrYe93J+ve8UdTYVLBdOrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275731; c=relaxed/simple; bh=upwohULj/Oms0C2fpFjxKliuZKRIVz3n+cZk2HiI8Fw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hoM3/BZnAsh67SguEMvjPXqVu8BWZR0znx1EGywzhCxjbAEQLt4VjspcyjNsT1pFEuuwOwNz//WLCB6YduM0fHMXpOqC1YOk1Ym5UV7CNkzb0jy+JQ10wjyqHPmrhhyD7wYLlGduSdgs7JHNz2CoCvJQ4wJE5mlt/DR0Xdbn6M0= 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=Sm9JEdJA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Sm9JEdJA" 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 A3A58161B; Tue, 16 Apr 2024 15:54:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275680; bh=upwohULj/Oms0C2fpFjxKliuZKRIVz3n+cZk2HiI8Fw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Sm9JEdJAnUcpKa/S0/SJbUkvr/ofPHJm38EfFABmw0eMaqwyeRm/J7htX5wC+ngUY NXXW9/I1gv25pcSXXbBakfiwwanzqFtaRcjioy+HPxozA48Cb+Dj+Qg2Amc+/+Tqss OUJyeDBqa2nVXau5uOU0kC3kwUwd2BhrNlQyaMNY= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:05 +0300 Subject: [PATCH v5 02/10] 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: <20240416-enable-streams-impro-v5-2-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=1377; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=upwohULj/Oms0C2fpFjxKliuZKRIVz3n+cZk2HiI8Fw=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNJR06bdREDrMnRdSGsw8YD2ijhAjZk3Yxls svGIbgOq/2JAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSQAKCRD6PaqMvJYe 9Ur/D/4/6mjhKSHmgdwiMAA1sGprHBWPdYOfMcq+xPrKLGYegOWArat2B7o6OJ3spWVaoqKUIdG CPN6FrMzLwMyCQOgPP/q8MnaoGWcCR+jw68CSzc7IIrr9eSyYEJ05QlqdG/lCicmL6giVQKBBAn NaJzjzYjBrgyWgpxD88wrtmkUi7KtCcsYt8KV4UoUkzxdgyh/1SuM+cTu5Hy9qVEFmR5LL/ANca 8zOz++/eXkflXIRQDmsg3sDbMVyQxcThVgcon/h9ZQc6dDgxzvw18BTw8fMWnUiR+hiIjUC+nFf w/fE+bHsnKwT+rBfQG41Z0yjEIUNpTmel25iT8OnyWbTvMbWhs9SnkS4S4feTHa8u9IId5rg+DN vI1dggVvHbO+/HkjuZqDKVBXINHHeZextV4XpbWeg6RH5bZsfM57QEP4ySX8uX+vu0knu9Jkl39 Wra02tc6BW1FuDV0aoedykvZkp5A/Azf4OXAB3CFhk8Cv+aPzM6fabWdSwViobNycseoUmZm0Me 1KVnUlX2NJacbFyjh6yvnSjmeuOFDC3hf2YA3oxodrL4e0YfmSE0K9gf9SU7pun+iqxh6qg8RYl zPdMiyGlp9ykbqIvd5zzszr918+Xd2Y4U0N9cr1SQhaf3U6FN2/7aWb0ir1NN/oFyOvf3TGEtQQ EkvV0PjHmjvbY8w== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 Use v4l2_subdev_has_op() in v4l2_subdev_enable/disable_streams() instead of open coding the same. Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- 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 Tue Apr 16 13:55:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631886 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 19C6212D1EF; Tue, 16 Apr 2024 13:55:30 +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=1713275731; cv=none; b=PZu8iIIZc1Mncot4DCZIZCqY63gjA8a0KYrozy+wSZb6wLF/+isUHr6zt6+KAdT64yWG3IDkXxZcbpG+169w6GWc3/fYpgfAxO6Njlm1B/QPLjFmM99uDgAX6jJEnYc1YoU0zpSYrbm45UQhOOJvI/qLD5GepSTOyFT66wVpktA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275731; c=relaxed/simple; bh=Z0RyfSEDzUrNB+KTFQ++Lirh0TD9nIjn5FaVBuc0a8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t2+yBEZdHl9DSZQpYrz/9n1FfLakyXYQ1PpNRp5ujBid0G78lPS1dBWohfjgt6aHlE4+JZhYQMtOoBHtTixPWkKUHJqu71P5Bksq8o9rTOhTDuJvMUlXfBL5FnLUd8BdW8R2ulNfXd67dqO2DJSMz5y22yNpQ6HrAMWLK/u3W1U= 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=OPOI/WQS; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OPOI/WQS" 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 328671653; Tue, 16 Apr 2024 15:54:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275680; bh=Z0RyfSEDzUrNB+KTFQ++Lirh0TD9nIjn5FaVBuc0a8A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OPOI/WQShm6Hc783Fx3BCpG3TEMDOk9AU+JnMMCeMKbQsyfr6XxEDwZcn6ksdsNUR JyEtYylsjqiDxtfEfel/Tn0hwGyvvgotrXjf/Y76lFXIUjMzQnHW5C20PBSJpQhXjO muwyflVhPArqwa/YdTPJ7UjzEG0M6YLsSN3dOK1E= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:06 +0300 Subject: [PATCH v5 03/10] 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: <20240416-enable-streams-impro-v5-3-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=2250; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=Z0RyfSEDzUrNB+KTFQ++Lirh0TD9nIjn5FaVBuc0a8A=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNJKFZLenFRr4w8dYUXbgGXSNB1DawZHYwoQ ZKeun7oR+mJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSQAKCRD6PaqMvJYe 9WCNEAClmM9DATCx3xKGwjD7/0+7eD36TAZf37HH47tU/a5yr4AWXIn46PdCiA8sHT7LL9O3/6U 8LJOSKXst6twC9/PVui2CAm/UOlwGD3SSTSKkiV2Qx8p7gR7vDXxO+AKH3xu0FgXjW+s5rotD36 LqvuUfNBJm8sux2w6Jj8VZxak3ZGP79kJ22QhbhT93vjkMmE3/W010BPvhEBTwuq1/e/iRnVmDm b6D2fPeScGbkIytAVu389gZXCTOoGlW/hz2OQwVHm+8HsUmRyEPfBEqhKtmSSkfOiw6cQtQjGjj 0En4XhdCdnjtC/1NQDWSw0UWPxKk/0sqsdTTkNmaQtFZUgwE4aDnuft8vwO/VAtMOaFPcyj8ans gxLWKaTHgsd7PBTi3VWtmXbSk3OyrXQCFqWMa//kn6FcaV6qltVvX1U1+9qaFxIKauDcy8bGB3x jZ9qVzaZenqoc/bbv0hptuNBOra3m/zlBwHL+Bzg0k+L4wST/TbbNhbI0+Dv6teb83zUyKqaID4 ipGRHq2gsVJ8AH6bUOqsg269PGvum8QpF/QhHLkUlH0CdUDQ3Hb9e64MY66RVQGRMAj+S6ZPY75 tGQEb7Zkp1B7ge4NjfaNBS6t3bTpRYf9K/Tb14u1yLCq+JSihbXSoo6h8ECTgwmMfy3iCA+prRm oLMWwfc7PQ7s41A== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 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. Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- 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 Tue Apr 16 13:55:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631888 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 0973812E1E8; Tue, 16 Apr 2024 13:55:32 +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=1713275734; cv=none; b=WXPBBw9lBohW5Ve7F2FtprzgtSQn1a0QM2yTzoaRfPfe5OQjTOpCfP65hjGKMvw6/K7OTmP+p1yqKdjlYH5b6dRiNyKgn6azz464Dx/1ydb1zAcTY++NnINgq/nkEhE4KePGSHNQ0NBBrf8OKAL/DgsRuk6RuoOkvW6KBb8KX+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275734; c=relaxed/simple; bh=NLCsfA0/1jawAaRZjCj1kEooc2FTLF/KVL46Xk47Xt8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tFIQCDqsbWuXNTXhshyS+GKN4aneCPF4itANO5kjzsSL8pYxjK3mbi53JnFPIrLEk60m+3i52pJXv8wSZuRBV7yp5c/rl8r/L1uG5cvF/ZCRxzKMZ7aUpSQSI7vgvggEC4U27SqqXzHT8Oga1zpwj/9fJTPRfLiaYLtL7a7KiO8= 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=NIliTIPH; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NIliTIPH" 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 B94B816F9; Tue, 16 Apr 2024 15:54:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275681; bh=NLCsfA0/1jawAaRZjCj1kEooc2FTLF/KVL46Xk47Xt8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NIliTIPHes8MtlEHA7MhxC/kbzLqeotcrlS/UpASA92zhUy5AEflrwkfbhez47njI JkXAdm9QuMbtKgC1jZRs8UVichTyM0QaLBgEbhJEaUDf6Zx/d7q859hpB4G9YfTZE4 6dKirAwGOB35qfoowZJ1hjko66c7QumoWU5ZF7co= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:07 +0300 Subject: [PATCH v5 04/10] 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: <20240416-enable-streams-impro-v5-4-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=2934; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=NLCsfA0/1jawAaRZjCj1kEooc2FTLF/KVL46Xk47Xt8=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNJNCTMlYddG5HW+h+gJCRYhx/YapiwhSX+f 2LzF5knjCqJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSQAKCRD6PaqMvJYe 9c4AEACa/1vIyHsGoKDXKTgNCbqDiOuIZ3qlHOHdCDyncQR7A8pmIci5VkATKGr4shdoaY6ASnj 4mjubq5RoQJlEAEJ1ZdtT3dcq1pFety2bHA5Yn2AO+5VnDhA+YXpPy2xbcwlQ+yeyN3QES7qFhg 328srCay8+GbqjYLKXJ+sFA720dyU/9MWJM0EBtoKNLYpJ/ouXdNz3HjHMcdKIhKW+HY18+edbK oVapeyrtSzGwh5AFAm+Ed5WPfKu7/TY7up0ognDjBIi87nHyb8fPyCch50GOMoxMVN3oECRCESX yEpPzWNLJQpUSnSDjpjdJ70suVrsjcjCB3f0iaTOEi/KZx8ejDqQTEA/3E5rdHPimXgWJM6u4xK 1xm+Sv/Dz4beLTkCBA5XHpSgRQYdkSWtr+XQUG/fCJ1Jqv5PGETXkFkZ2/H6D14dUA3DqJ+FZed JlPRlfPXBhMJsqpsZlweDCF0hcxNYCWP1z+rU6Unjm4Mx/vhYPv7uh+flPsgE191YqLyMNqd1C1 17QQ423ETYZ1hWK2nHGYMouNXpvkyrgtmhhNkCNZkj4wr+EVhmpWv2wCppHtTSuH2IBxeIQ9B+7 09KOZiv9ylMcA45LP0qhZF8UfXgY53FnEYHxmT82zOBoc4xmBVFWyGh0OfxcDZqnD5WWup2ADsF SELiu9xCnrrfcRA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 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, 's_stream_enabled', for call_s_stream(). Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- 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..941cf7be22c3 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->s_stream_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->s_stream_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..b3c3777db464 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. + * @s_stream_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 s_stream_enabled; }; From patchwork Tue Apr 16 13:55:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631889 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 2D09912EBC3; Tue, 16 Apr 2024 13:55:32 +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=1713275734; cv=none; b=l671lZ15UVWnO5mff3C90sVpUv8gJgGygJ3OUrRd+sb7zleh4lz2h1yWxTkjIoJlq3TeFzsRwKI8v0uG3N279Z+W0c65s/DzQSqg4z+zHgwkR/+tSD1y0rOqfoSY8uHUG5btGXH/uMc+Cnss9KUbnUu1OmI9WqqwvjRLW2QPVQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275734; c=relaxed/simple; bh=aCnDspzZEt06MUge756JFr8IcUIbBzfpqoQOxbjW9DY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CnRHDKZGpnkvTBZkokse/fIilih9BAViAXhxaykdFJmY4eVgK9umjrCGhxThhtDHQMZnHA7haYSLYhPTyfOzjMi0dsmqA1x/mr3IWYlh3XixI/GsBQ32SToWFqFQgfbpggtXrZXs0/yaz2catD2WWbZjh6MiAaWeYecwWJDRjus= 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=fpLHr/F6; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fpLHr/F6" 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 4C7A517E1; Tue, 16 Apr 2024 15:54:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275681; bh=aCnDspzZEt06MUge756JFr8IcUIbBzfpqoQOxbjW9DY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fpLHr/F6mFO2zcqzEcQUUfaL7D6DHvePzFuY75nUE1sB7WBQdg114laVAtWk4O/TT Y74V1QSNwuoYJEO0PNMl5iDfOI9MJuuU7cMWUZEs8n6QjF8bEpOFBA38gUCh4xqFdq yablaWYsrvvDnjy61T9kz/ZOC1bha9WEeupqny44= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:08 +0300 Subject: [PATCH v5 05/10] 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: <20240416-enable-streams-impro-v5-5-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=6465; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=aCnDspzZEt06MUge756JFr8IcUIbBzfpqoQOxbjW9DY=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNKbSA1XGIJ8FSBO34fBCKDS+SxoW7Clyk6C OvApYenHkqJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSgAKCRD6PaqMvJYe 9XSxEACLSgbq+KW35VrqO48IBygrp7IaLhhexhzzMHFienaPxDh4VsOfwcDl/ME5i9Pxi8+4/nl 3TpEZySSqGyqnlEASHLQac++kx31Lr1eL30kFxA7yYFOXkKZ2K38SWqYzCebvtrq+s6gPGHimT1 WmPbu78uRunyOydInEu/9eBprBO5jD+tWRJqVRJU9CqyeSgc78VqjOp340kPKzFrDrqbYjYpXPI 7pgvVVI8Owo35hXOeEyIyp8WHuKzhp97yJCMlJjxYjzX+FzcWJDZKdhJi3+6v1a0rF+mdRny3ar BgelVeS4yxSQ77khH0jpZOxqQTTyJM2NhtBaVsUrIvRAsuzx4TX+w358XJO0SJaJOwbe8vaKs7y XZLxIx1pJSFSnUz5ABJSDngAv9umyhU6FKLrg5df7NZbCC+PYFIqf4OiuBfGWGtSym9WBy6iQHU B5VfzXlniMvF7ZPAh7Iau/Ihz72lX9UZOkQHXr8DXCohns+uLqdCo+ggYi5XvMRlvvIgvdrrn+s QHfPlsBPkviQJ9ijd5d4RHOlzhnq8EHxuCcJJe6/SvsEh4QJxa+xF53Knqox9dDHYEtQk7AJU+u MVfRhbeyPU/R3GHzDGECjh3JdUKbOQq6OT7Ozj4VhojdAJs80eOIGWeLTvjcuLKeSnYuGvpY26u 98bOpcdr1AnYL0Q== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 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. Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- 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 941cf7be22c3..3824159bbe79 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 the 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 the 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 b3c3777db464..ddf22d7e5b9d 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. * @s_stream_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 s_stream_enabled; }; From patchwork Tue Apr 16 13:55:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631890 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 EF3A012F5BE; Tue, 16 Apr 2024 13:55:35 +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=1713275737; cv=none; b=MGfMo+OMxRPGdWq3afY9NvmuSZ4DZK7j5q5feUIDUm9hKrYbMDaHPEC8TpCDq0DAezNaxCz9ojGkEOZHW5BMY2krKxA/oqgrAOrE+ild1OkTZQ4CzFepNrN368fIh6uMuC44xMhcMi86yUcobqB1IE3syDBkfrHcglSrzxVxiRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275737; c=relaxed/simple; bh=cRX39UhcoIccSBN5un+izWragJ2sRwImSu+ClyYCk+Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j6109bSmeSlVjIROtQcTE0abDhFCuISbgzNnR9uadFemk1WdufU9mnFba/EN+s78FU7BACUJfDm2x2wdOpjHW2ALlN5zmqmgFTA87DGSG63/Giz95pB/0KaqpkEwYT8aG4Wn50LWL8fBZdBf1WsQM7akLDaFKVZSp1PT1fmpFZ8= 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=hkXWXt8z; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hkXWXt8z" 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 D24CC1815; Tue, 16 Apr 2024 15:54:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275682; bh=cRX39UhcoIccSBN5un+izWragJ2sRwImSu+ClyYCk+Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hkXWXt8zlTAcP0Ct1DT6+v02P1V+2HnzHzikOoMyphOJSENWoq1DknT4O1XkU+FiY juyqtOlK8rtxKkEuu937xsI1lfS4idfHKCXTJmfqV1ajURcR5NP/8vEmq38ZpkLK/f DMPRzjPyie8dnFJoNni9qC10GguOI/P2pF9SSfqU= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:09 +0300 Subject: [PATCH v5 06/10] 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: <20240416-enable-streams-impro-v5-6-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=2517; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=cRX39UhcoIccSBN5un+izWragJ2sRwImSu+ClyYCk+Y=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNKY+/f4U++TZ/6q7+Oz34nkh6wfdiaWkDEC VXeCH9WQhKJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSgAKCRD6PaqMvJYe 9eHTEACTjp5bxGMWCkP9l3Qkfb0g01SUGrCqYv0cjXYhjcdg2pWQ+BWkGPqwkxujNj10/b89r7+ +82si6CSZFya4+EbSJ12s+8qydnYwlLjLir3tVsk5BIRh7+/sPulMjn0ehaebJ4avmVMTyTal5n lUGcq2Z1mnARVfdTMnrfBC+wihrM/XYlYK+mXyxY130a1AYVEZQ/x1t7K2SNnxRuGJ0h1fTE+nn 8GPfEDsrPDHSF5WWaK2LyWMM0obIZXNJRC+GUgreJxiwSjxTqx95wySFcreQRQLpovMjHWC7VVG 2DdXR15jc8R07e34yXiVSKCMGt/vCKrHaRx/70YTrUFvCE81mpgtesAjQjErz8PShYbA8EyqBzr LckDF6/cYfQJsZV4pKGy5dmXu7+mnQBUYQv+fM2L1vXgIhq5aG1fdIaK9CSSoUB2KgjcfswSETq tyEAo/nUsSO/KyrkjhHk8fJAMsaIieg67uIjOA/MmpGCZLzEXp26vHbfo6BclvBZcM3y0cDRaQs Hz/QDl9zOKirrq/dgXsr3sWEx655LHHMoH19v0ki13V1Xz2n/4dJhpf44OO5lXy6vBeCYJ1dv4T mOfxmeah5tDYIEqMb5V5z5kDuTMGOgRnADeXE6QHY+ME3HQZGc3KlsDyXFI1VfZEcVvZ3iMQVmy 5ytH4lr3fm7zYSg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 Add a helper function which returns whether the subdevice is streaming, i.e. if .s_stream or .enable_streams has been called successfully. Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- 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 3824159bbe79..06f87b15dadb 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->s_stream_enabled; + + if (!(sd->flags & V4L2_SUBDEV_FL_STREAMS)) + return !!sd->enabled_pads; + + state = v4l2_subdev_get_locked_active_state(sd); + + 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 ddf22d7e5b9d..dabe1b5dfe4a 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 Tue Apr 16 13:55:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631891 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 528B812FB0D; Tue, 16 Apr 2024 13:55:36 +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=1713275737; cv=none; b=f+JaSrvzWapxTo6RWAc/yZCTXjAj9gIVOFw1buj+JzdLQEIWBDFBf4JK9mUQtG/8mULiosM8cYEFVhKIGoGsD2GKWiDY59xz7wI64Xyh3u2gng1rkVF/6h2s9qK3rQKoAhESomacyUv7hja92T1Rs/otlsJDlTCtjQdMUdezGwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275737; c=relaxed/simple; bh=2Xt7vzkAHQK8ZH9kkym8FF4Sl2cd7jU/rDWfYtxbPXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J4+4dcBAN9uo9RF4FFdOsbNLyHZOkGw6dVxKZBwVosL6QsAOJ/S85W2ChYXBA+RbEkJK3Gm6/sJ9vWAiwYzUWD1wfzQnAbN2J7kCoN9PjuYqSGnbmpCRiU1iCT+B14USyHSMgnCHVgqw6RGNJ/U5pZplq+qnBDBhee/wSa8McGA= 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=pfLDiZ1x; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pfLDiZ1x" 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 63D55182C; Tue, 16 Apr 2024 15:54:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275682; bh=2Xt7vzkAHQK8ZH9kkym8FF4Sl2cd7jU/rDWfYtxbPXE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pfLDiZ1xeS2l7ZzFos01HA+KcpPn24S2E40qXoQ27tKpIoDCm6Ei+WNDXAVA0C9lM NL9dyZfEaQ5qDiOpI/3plrnMS2Koi/0/pTqiTe9HyfTwzj+R6919laHZXxmsJTXQPo 9ywk6rfwNuA3jpNwcr0kImmU3GMQcIqW4+rC1RZo= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:10 +0300 Subject: [PATCH v5 07/10] 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: <20240416-enable-streams-impro-v5-7-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=1883; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=2Xt7vzkAHQK8ZH9kkym8FF4Sl2cd7jU/rDWfYtxbPXE=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNLsOPDzuFpeh5ek3IJvpM3cY/ZP5oOJgV48 dD49YzsuYaJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSwAKCRD6PaqMvJYe 9RsAD/9tiZRNwDIVZ3csZFK2PaVl/OKV+Vbwps3JrVhrxh+B5GA2qLUTjUxdlbYWDtRtDMjGw0c Uo80BDp8Ee/eJlXjc7jm5ML9heR8+Nb2f0qz2q3q6/QMBfG4mTZuJJc60fCVPtDojpN4mZT5187 vQderY70wevn0FD84QvBvMjT0RHNnDxoWqobvkbpAD6OnF2+IOIT3aHwPVMPCfkjQosN6C3qhap nmTMUaFMtDe+7U+f6KOm+puFoLtp0OMuuxvL4b01mWK8gnZce8cKHw7yAw94I9DvIlrEWlNCjyC RDTfvToFsy+LJ1n+I+5rXHQG0nwywk/E91GC0lGPwxQC/hHDn7SQ6orslVQqV097FFdELTDn5pD lEgROWgSiRhx7OV9xgj2sywvYSNvStNhICao7Z0+FZaPn1TqkzGzqDHfzFnvmT1FUAj+va/BbD1 txlV3snEqsUS359UOzElfXM48bqlXOeYcBYgZSJBKWgq5MA3IsFn24h5xluHwkSKlSHod6i4+1E ABgltG0hxVFzzNMnp67T6ToXqJRHgFC7vU/6Pm8qDz3nlKmIqUYYm92DONhNTJ7j6Y/olJNUFvn cP0Hl1mkUzz6wSQrjYEJmj2yzIKkwI/ks/BcZMSObavMpzyr2BMf4ZuVtE+9AuHxCR/T6obtyKS tgzPkZZ9Zo6RQsg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 We support camera privacy leds with the .s_stream() operation, in call_s_stream(), but we don't have that support when the subdevice implements .enable/disable_streams() operations. 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. Reviewed-by: Umang Jain Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- 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 06f87b15dadb..38388b223564 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 Tue Apr 16 13:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631892 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 B655D130A4A; Tue, 16 Apr 2024 13:55:38 +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=1713275740; cv=none; b=l5+ubETXduhQnQJQf+Sd4pJJxmZ+TzjVhEl/Zgz6EFpxI/+kWgbWaDunL1XNlcHA0fZU7WJ9OxxsaFUgr6xgWOQjI/Mw+st8kUxYV7KlLCALtEBt62FYkCZB0/Hwp0M5frYAdtLWBv9+zIdPwjLg6RxsiXgLzphW7UlAXjdBZPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275740; c=relaxed/simple; bh=P5Mk1MbOCA+IjWUrNTqMU+A9EoigwOcf3/o12ANGKQI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DUAaQhJ0vn8MXQRjhmOkWZzxBJgXcBqn182rKzGJBjd3GpWie905li1pPs7fDP5VbWcsYzpdFwmOiEScMlPT1Dhr5A5Y5App4CjWniuodzdrKRn+sC977MFMSCcPtQHrppAykzIKlXL1WNCN3HlcWMuQ68EX5rIxgkzwYM2rKC8= 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=BhzDoCFt; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BhzDoCFt" 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 E62BBDFB; Tue, 16 Apr 2024 15:54:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275683; bh=P5Mk1MbOCA+IjWUrNTqMU+A9EoigwOcf3/o12ANGKQI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BhzDoCFtAMooJYRPtOc1cKj5n+NSNhUNnF5lko69i6XDLtSCigDf0nzS63360dkZq 8fPXvNK2LJNLSrtvSvvOcEAtPJK2syhK5cMV5KINRKYQZjLG9OnmQEa7iHE/YpZDVy WT2uSc1H+3TGUiObLrqSFaiQweFVDmnLlSJy/C2M= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:11 +0300 Subject: [PATCH v5 08/10] 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: <20240416-enable-streams-impro-v5-8-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=6440; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=P5Mk1MbOCA+IjWUrNTqMU+A9EoigwOcf3/o12ANGKQI=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNLLizQ+TtDj3TZwPD2c/LO0GhP+Gv67LkCT VVV0+7M0xWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSwAKCRD6PaqMvJYe 9duwD/9w/YtnJJ2MSM+B1AAdaJtN7q/ULVukNgh0FW4qQIX7rtku/rN8FpYB0ceGnr9NO5R80Q8 CyELfeSioivwZCBntBXWpP3R6EWNmez+FRBt8PsM6Mv7S2JiYl62CwxER7tIPTWLcYJ24f8GqC1 QPwyw94jMaHi1/90oVEhTZo2WKiErs7L6kJYW4eBeeBlK85rM1xnpn9LUgKrFIx1wgiSASlrFkK S48g6SME/qUDZevT/G+hU6gKM7AbGZEb5Rhwn4fCWWBC0bzHN982jlP71O4vNG8g1DzxT6uST1q h9dWy7QZ0S5uzIPPDfSb9dJd42p/OyyhKtF3Hzq84jv9bh2jrlgxYctN9j4dWVDp1PqBwHUe8BP GMWQlEeSt5FgxPmyMmnFstYaLS9ZAX2IroPnfDmIuF4VwnlrUoQLb3HFxSr8cAhCbVFQDhgw0YR CY/UYWBD0At0Y1WvzdJE2nYw6lMPsdyxpvLbAjx6W+It7+dSzV1KxkL36VXoDJx0O1viJGYkw5/ CXpZgof9amnEIxjueB/uVbfbFKIB1owoyo2LXJEXDagjxVdSiz0I8rwBXZL9HENLwCErxeX6zZ9 b/8Hrjjve+jlCy4DO2I2mbwgAcQ78PhEMaKEeOpBnpKKRc9AoXIjUVnOhErqG32P/JW1d+WGS/4 /Bz9Yyktys53hWQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 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. Reviewed-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- 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 38388b223564..e45fd42da1e3 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 Tue Apr 16 13:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631893 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 3BA1D130A64; Tue, 16 Apr 2024 13:55:39 +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=1713275740; cv=none; b=GdxGNDVz5JyJMk0eUM2LM6lc2QaM4uBtjgyPJ4NI4uyO1PJWDO4xlsoQgwl/d71I2U4JOSMCpAQx+5FjcmdWVjYH04rI3AL/8Sjsj1pr+wQ5ACn4BFgZY2T+rrV13keEvhzqkbFFhTAe0OvfV7ej/8d48LbBwQe5/Y19rBx79lU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275740; c=relaxed/simple; bh=DT8uUZrrFm88CNYEqCHYMCeA6zSqjEyTf1Ae5xlz9mM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nSIGjY7HVBDy/PlDsJqN06a8YmkIFMhI7L49wtk5bz7lkXOUx9aKyE60KM8WTsoEr/EqjHimitJNTleq+3QWYwqdnfynXW+2AcllnoGwwfQj0JJuwYyx5AMr2yMQkthbCUf5UUKihV/fv35S5ENtTujLq8bQIFQ063SUDjqqFeA= 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=fHOC0edD; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fHOC0edD" 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 78E14182D; Tue, 16 Apr 2024 15:54:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275683; bh=DT8uUZrrFm88CNYEqCHYMCeA6zSqjEyTf1Ae5xlz9mM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fHOC0edD8m5Vng87U61KU+nuyLc8YLf/jd8MlduVBft19H4Fm/oIH/ANYI1ACUlCK lz+Fpxom4Jt+c1nxCXz9lmK97l3dBbHxPycn4iWGJVfUJ5zTuI1mhuYujDjBSMhSEb 6jMFFKyGaaMK7PMdNHQjUgpmpBIF7D4gsuvS0/qw= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:12 +0300 Subject: [PATCH v5 09/10] 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: <20240416-enable-streams-impro-v5-9-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=10481; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=DT8uUZrrFm88CNYEqCHYMCeA6zSqjEyTf1Ae5xlz9mM=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNLqUuqEVhxfJWhYjlA/0RJQkQEtD1iwxFiq pKevKQDW++JAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DSwAKCRD6PaqMvJYe 9R+HD/4r6GvNZCfeX5SpzrfctB4Ldaiyxyc7DUN82SFzqAWaq11H5raBsUpg6WXpijxrohH6l+l mPd00rNb58AGtD6b2OfCeyZ44uyq7/NDSgsP+dd+W2RTnIbaLk8eJ4sQnxtSQDOCAjs0VZ+dLzL 7hVSrbUl+yC7cGJ52mVrjUKOCZc6S63FUo6hWgdJA9SAyVvJoKCYrADeuuDMSFObxUBLWXpEj/3 P7y5aa+lVSvGATzWWuhmhn72/2I64Sn3dm9L0oyaEBTMokQHo4xL9COpT71fpUGSsez2HF/vh6w /eUIfFRyzIDDCMx+kV3exj0U8HQwU/ZMJJstWMTijB2h+V+W5WMzoXf1Xd0z7n1fvxXJQJKElCh mTmAXcW1Jmc42FpffMojEcHnKJWzvQ0aF7pmtflmuN19W5OjegulJTJGAi8GR3e7T+NEj7NNATm r3fLF6TmzqZ7KbOhoarf0vuzDp7+T34ex84cPjttsVJvObNQARl5KCmAh5L/C+NG3jSG5xoahXe SQz5Sf8RtVmqZmpHK5JEqAaZKiuWy/pFtQBfVUjnGwPNlbqAmmbpqeKemePoVMHp4yShe7Fq113 BYKcx209hKx45KkQFwPgAhrjFckGkgf5PwEknM6Vgdvu28ipym7EA2m3ZPY8qdH4kf+enZ6b07y aE1AbvoXpK7x8Gg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 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 Reviewed-by: Laurent Pinchart --- 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 e45fd42da1e3..10406acfb9d0 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); + *enabled_streams = + (sd->enabled_pads & BIT_ULL(pad)) ? BIT_ULL(0) : 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 the 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 the 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; } From patchwork Tue Apr 16 13:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631894 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 B46BA130E54; Tue, 16 Apr 2024 13:55:41 +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=1713275743; cv=none; b=h+y+0pEv7nA50fFwM4BfzAp8jEnrXmy7bV+9U9fG07zAcySGqg/7BCORXCqgLMuHdaf+l4YU0489AnrdLixhcjpbjSyx7tM6S9kK8WtbBcaK2pz0PkXOTK3I8jnpHFcOSfB5Zpq+hIqwyhCGgfyFaqAhWJTW5ZiW5ce5kIT2+RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713275743; c=relaxed/simple; bh=1wu/BK+2ztMZUnU+g/BX76ZgWTlvg5EcPsauJIsorW4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BAuTD3wpjJIQmcMC5tP/4eZX6igRej7f9rmOF7H0A7Q7KRSJ3PIwWuIMA3PzbmuWH5I/YQyGtyX6g8KE5jHgnoBkJkLiMEtWcfdME0iH+SwWvRLKLZyNy1POX4QPxn6t42jMPh6XxgieswTYLFqoy5shcZjvRmjma2zt54V75TA= 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=Lv/w8geP; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Lv/w8geP" 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 07CDB18A1; Tue, 16 Apr 2024 15:54:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713275684; bh=1wu/BK+2ztMZUnU+g/BX76ZgWTlvg5EcPsauJIsorW4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Lv/w8gePurxhHhlv7SKb/4d8A71LsgLchQn4nD+nZmTT+nnsX1CnMmJiaQ+rYlONI Pq7n2etPjwEScyL3degXb9S7w5cIc2BPeLV2ftxJAO61Lc+yzOApQkN9lT2tABpR1o /iJh9JLlqPQHrhkKcl6Sx3IUu3pvssZzwUczAdGI= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 16:55:13 +0300 Subject: [PATCH v5 10/10] media: subdev: Support non-routing subdevs in v4l2_subdev_s_stream_helper() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240416-enable-streams-impro-v5-10-bd5fcea49388@ideasonboard.com> References: <20240416-enable-streams-impro-v5-0-bd5fcea49388@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v5-0-bd5fcea49388@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=1654; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=1wu/BK+2ztMZUnU+g/BX76ZgWTlvg5EcPsauJIsorW4=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHoNMiihKFDcdIAi4MVBaivGWYkMLuW4PLytqP NKJ4mhvfUqJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh6DTAAKCRD6PaqMvJYe 9RXID/9+bo7Oknnxx9zbRab4/UaVin5kFEwMDbUvrtznOu77IyduVJ1Y6/LvBisRF9TpiH5pPe1 sYcG8nH57Tbg8+1fq0SA4OkupzvJSIF6UmrPLLLp4UFq4AJVTuzJVWTZqP0wevi221MoZvJi9Z2 +NWWqQn7APRa1XkUlKYLPvf/xLxjvI2hrJH+Q2kX+vY6tGVcQWpqFE9Pv+0EhAyaj8lzr2M2deh DUu/mHAtnwmpu59DGtrvbSTsd30XfXSgd8jpg+98GuRqiuH/qH1EW1kPsw2CutiOhveTcHt4SBH vVJKryuNKACwQlr1Xy3SeJci1CBtzzsYBr4vaiFFdttnn3tNTNOlkAhFv7aakn9bdFgQGhXwHcg 81VnRS62sRWA0HhBstjBrWJ9OMmHY/NC2Af7Ss4QaA0RL4wxk5DmkwLs3QLjPWyP5plMPk+2mgB AB+j3u81iyED5p4l2NJNc9mz8QL+Ry1k0wjzoE5CiNhXiA+XUefqh70QEARNDrg2qgb4uSil1Ts kMf4v+cFarv2dAxBcgcNf7gIF++O8uxxLbPIupM11XA8BShm+RMxVuHMAo6RYAdd3yBRdjYX7sU 9ZWuLfvKERv4SjvMTA+LPKI/51XOqjDXBJLiD22Q93u7/GC3Qx4tFl4PcdyKLEcgCXGi7noAtN8 KaWDqd+5ba+BCyA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 At the moment v4l2_subdev_s_stream_helper() only works for subdevices that support routing. As enable/disable_streams now also works for subdevices without routing, improve v4l2_subdev_s_stream_helper() to do the same. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 10406acfb9d0..64f52376ca7b 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2360,15 +2360,24 @@ int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable) if (WARN_ON(pad_index == -1)) return -EINVAL; - /* - * As there's a single source pad, just collect all the source streams. - */ - state = v4l2_subdev_lock_and_get_active_state(sd); + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + /* + * As there's a single source pad, just collect all the source + * streams. + */ + state = v4l2_subdev_lock_and_get_active_state(sd); - for_each_active_route(&state->routing, route) - source_mask |= BIT_ULL(route->source_stream); + for_each_active_route(&state->routing, route) + source_mask |= BIT_ULL(route->source_stream); - v4l2_subdev_unlock_state(state); + v4l2_subdev_unlock_state(state); + } else { + /* + * For non-streams subdevices, there's a single implicit stream + * per pad. + */ + source_mask = BIT_ULL(0); + } if (enable) return v4l2_subdev_enable_streams(sd, pad_index, source_mask);