From patchwork Wed Apr 24 15:39: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: 792194 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 73866537E9; Wed, 24 Apr 2024 15:39:42 +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=1713973183; cv=none; b=MudKDx3Nd2J9pBmyKy4H2k6PsGTPGZju09MH0eLtVbftP0UgXIW/n5iIayXUH9t1QAXGPafeQccxvRZmHm4PgHilipRXvhUTsUs77Gygd8tTeGvldhBuk6n/sie4pUDLKBZ1a7lfWhP+81GFuRgfWtGnR1O7D7h6oua3okco36s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973183; c=relaxed/simple; bh=23+0yDyOWieu/OvqCnq30wt6Gy8zITnht47Y9cnyRBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Yc72L//dxY4UcpCcN3alIQstB4J0XGQdxRUHgCFgQPzbY3lnd/8eQe5wi+6w0jIsZh7PV8hdGWb+U7eue8YlT4G+WC6N2TrsqSB6+beiP2Hn6EO4QiuFgdJbAHIps8f6cUr5taOi0M+ODkh71lDe7Hb9jZqtSjWIOGe/hkKtlRI= 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=l6kT5UEI; 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="l6kT5UEI" 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 B208582A; Wed, 24 Apr 2024 17:38:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973129; bh=23+0yDyOWieu/OvqCnq30wt6Gy8zITnht47Y9cnyRBI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=l6kT5UEIr5z4wboZG2u4xduokf3VY9YNP2jHz5c1f7MWnfSpK3jveJabtOwAES7Ew GxP2MbLSbCXwTZPkscoiYZIkKoUTDcgnANAZJdm+sjfg2fRlEFhzKFEeubwCTgbsss ECHaVuoy7XMx7mdjZmE5R8buVcHwjwQz3bC/voB4= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:04 +0300 Subject: [PATCH v6 01/11] 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: <20240424-enable-streams-impro-v6-1-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=2038; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=23+0yDyOWieu/OvqCnq30wt6Gy8zITnht47Y9cnyRBI=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe3dx/jb6pAhJovrc5ZPCvTIdE9XH5hWVQg6 tiVaXMQ59GJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZikntwAKCRD6PaqMvJYe 9S6XD/9JTdPIoBtpzJFndCfeS/N1WwDLvHTF+hdnm3CkW1IYpjvQfAoThvFmJXgCvB3rfOzf4KA TxSV9AGnM7hcCIWx/BOtCrZEcYRVIymHzIToJLMNwmySWq3S0UXwZUsxEDDSXyKG9i7ZfLQ6Q/R OH1hQ+W4DhISCrcVyaQU4mxA/fflIU3yy1s4zr3RK8AtL/gm0EhX/kCFjW9kNAbX3+Iou1bt+Dq sjX9YjpbQHNMBG5RnZM+CmdkAc2HFH/glUgaD9BHgte/v3CfZUPD7PYbltIWOVzqtDeZdHwzXbQ oI26BHw2IyTGQnuxA0mVJQ9VqbqgPiTyQglPAb/h8LftS6n5boBb2WJmkGzQe7d/sZk/QqfVRNz NQR+cXC277TGLAEAlvjWywwBE+KS6z5yabKWN2+5ImgoIMu+XnNHdRnHPBtQzUw/xvHOEDMpgiG HNc8nWnt/NNaGDCh9aeOx19EoI8Txrc2Clwe1a+EZXVZ88fBQQX37E1B2jBi5amgaKsv4DAVYWQ ARsBiMLfZmR2kuTvh5WITkA+iI0lwaQc7dWnLZhNXpkPmG2QoN0n/Jt9bK8AGLde9PRmVAR2R5a dyDs0bl1gp0cByKwuuSpWKgC5q9TVkDkqqW/hRkywMsKUNRya024tj3dvs0IP1y+URK88cT2c3P bp75HPqBvvXuxgA== 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 Tested-by: Umang Jain 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 2d67ec54569a..b4f0b89412eb 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 && @@ -452,15 +469,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 24 15:39: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: 791727 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 CF15D16130A; Wed, 24 Apr 2024 15:39:44 +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=1713973186; cv=none; b=G5gv6IPPOk/pVjZKLrL7opSBXzYLGefLy/4VgNiLTf3j4tdHE2CjonUXvVF4MfZwLVEwqW/iMAQRZxL69A/F3Cd7u9CiQPJc4zTN3NJIcQdCaD27GWfB6Q8Ba4R+/Wzxya1HlDW8PPkgh9MElNVWNpv5m9OOHfSu/E0BQl02yDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973186; c=relaxed/simple; bh=RJfbMLL/yKyWu/90gD0XpUO0Mc8MFKIN0wtjUrMDl/A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aqrAMauxF9RJlX2JZVXwimkvJtqlH0TAjZZ4RoyL5NCLrawId2mruJ19tWym4G4pFf2+XvAwGXjCaEgpB9ENT48PbGR6HgcmZosNsAOAWCU+ZnGOV8NNMBD2bFev0ujhA0rYwK/8qDyWFYvavU0Ac3D9Bgw0sEEgtModwSH85AQ= 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=dAqep8IX; 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="dAqep8IX" 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 4108CEA5; Wed, 24 Apr 2024 17:38:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973129; bh=RJfbMLL/yKyWu/90gD0XpUO0Mc8MFKIN0wtjUrMDl/A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dAqep8IXLyLA9pGiwtl77R9tFIduLr3OudELiBluViwBksM1gkSlpRpRjmXLTLK56 v3D7Q1T6TvXf+wqRzRBkZUiThP9C9uvQOhH6tgcb6dTF2rqQ9sMWsU50QvC9f9/paz gZiJtZAVOboUtyZqMECQibKRRCSRtkoBfOij7cEc= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:05 +0300 Subject: [PATCH v6 02/11] 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: <20240424-enable-streams-impro-v6-2-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=1430; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=RJfbMLL/yKyWu/90gD0XpUO0Mc8MFKIN0wtjUrMDl/A=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe4euivBY7SGfPRQf5UQ+RUMJP2n/tRx7nIT tvNKQYBeKiJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuAAKCRD6PaqMvJYe 9UGBEACTUlzu+/VSUo8SQ+reD00zp+/GrmbCO9iW5lW5apJdQq/odX5pcgxqews8LaMLwBQ3HkZ 8Jgqjjm0zQtC0NyPN8CGJ+3HFPTEFMDj3JElVDTlt/bIkcp5dElW8BljFlYAerddErdaASt78Ea pqRoKs2CaK8LJ4EcxSWOxdT6d0WgwVNMIW93bdjSLgbXr/H8sf1WHTf89yztgkCI5QkrD83OFB3 5ckkRLaRfG6lnrnAX3NfueM92LpUw152hkmMx9MQlLNPfMfXyKWClolHfgVXG8WzHfQA7jqXaku aGcV/s2SKTziBI4QYoTsvw5uDwtGSJjhVmTHM9bCxEjJTL0N77YTocWp1NM9dH2jTDT1IO/TZCS utz+ifIkZyiOg7J1R7rRKHKiUvBxrjHKi2D6OJjqEZ7Zr1NqCO6YxAnEX9UvTRc7wSl8P1seNqu FvUSz2npzwjyUUwPxb2YbJkQgJM5WGzS+bw6pnpnXZr6rAuYAhZ07JoVQdxuEwwZvxyE4Uj2ygb mpLjOqH0rq6RlWpRj1l9RPlloFXh+2Wfzx+nIf3ZHM8KRS/J9QbMuwigcR8qC2T9LEr1JaSVOmo u1mzAetjmWZcDCF7EpsiWACQRF+EaOgFpDb40mFDjUOIjeb763ql+k5f578Kb3AXuuqg2uzvtT2 Va5nGM/ULJABsGA== 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 Tested-by: Umang Jain 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 b4f0b89412eb..2c5a9b0029dc 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2168,7 +2168,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); @@ -2285,7 +2285,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 24 15:39: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: 792193 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 52B3D161321; Wed, 24 Apr 2024 15:39:45 +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=1713973186; cv=none; b=L6Fp2BA7zQXRK9TsltFQkmyJsJBj1VtQAmLCqZ38pqrGWXglVsalaSgYRoiJKmjOAHx0/bF38c4UnoOjukbD9ZL09dwLPe4zE0Cbbo+vfXJCGuOC8eqjP9P5Mn91lxC3CA+gpNmkjKuZ2Wnlgr+fEAfeleYEs0SJvyN06wfiJVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973186; c=relaxed/simple; bh=1/kHOf5FrW6WAf4IYNC9B2o8lBngcUMkOHJ0ykXalqk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C5CoaRLsR+PFSg9siTCHJrT97RPLPgK03tlCit0c735Tj5vPemAtykkUJEVqhCCaJq13RoMvvfl3kc/IYnB45pXZr7nF1jN856YFEXBoHq+eLMkZ+BtpNgsPSvo1cVXkHKGZBPzfmGerW2FBxSREUz9s3FShGttKngJYBgP2t5s= 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=NphYIdd6; 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="NphYIdd6" 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 C5618EBB; Wed, 24 Apr 2024 17:38:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973130; bh=1/kHOf5FrW6WAf4IYNC9B2o8lBngcUMkOHJ0ykXalqk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NphYIdd6U88HgP/5UpLF+FYYGe/eOTYIuSygHwJK1vu06JWpLmPckmVnujJvgajbj yOf6KK/N7LyHt1OlG17TJQvtcVY8mtJzavHgT66lQCywXZWhXteLFyF2l2LnVyzL/e nnLDyXu4zvRdWK7wfQuyX219Laxlsz8c9hoPDzqA= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:06 +0300 Subject: [PATCH v6 03/11] 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: <20240424-enable-streams-impro-v6-3-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=2303; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=1/kHOf5FrW6WAf4IYNC9B2o8lBngcUMkOHJ0ykXalqk=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe4W8AXguIHqcnj7KU6Rzbv73B8iYfAZQjg9 UbfIfm5msuJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuAAKCRD6PaqMvJYe 9QiPD/4+ilJ3v9bEY8t1McImzO4ggZX0aBhFQD2CiApZ7H0qsqVap2dSPVAskqlj3swmjn6dNwz LdKvDveEnHBqzfray8cy4FUEZvf+1nmCB/Aw2xmyCtGY/sBA7S/435Y6fnDcwKZgQfhOxJw3rQO N3NKIAMiOt1rd8v2LlJvTV34VzTLWzcegxUKpOyH5xTDIVGm2IxJmIaKeO5IQLxUfdc5ZbvN9SV YuiHKClKU48I0VLouYTK9J5HUTj/K56UQGKuvKX4ydP6owtSPN1yQOjsJhoXnxCPp33ERmvWq6k U2jzyifm40wC7LunSg0VhnD1P74f4mPh+oncoCvrPynePjWmW0yB2sv3lLdmWtojl2rA9ehNzhd irvG0s93DgIdGtl2W6kifHjvr3sQHF7/UN3Du6oToZ7YxTURyLOm15pTwx/b9i23RuTgGSaIxxp r0zuIQhqJa02C7LKWCDxkvjzJ8yq9akc7IneX6Yv6cYcCk5UlX02qR7djDh7ZmUbDoMq4ifJagg mdOt4YqPGvhwGhZSeLAICXIKER+pPXSuDgM8jaCgRDpKfaoOWejqxrjp8IeZVcbWUKIQ0nqUJeY tXHMF94AumkZf8H/ZO7E90VY10wAbNXFIxQHmawbre1eyLGQBUy2VhwLDOgQKv0BIEhi5SHDXkz oK6EkyIgEsU+8Bg== 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 Tested-by: Umang Jain 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 2c5a9b0029dc..b67456944ae1 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1568,6 +1568,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 24 15:39: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: 791726 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 98602168B0D; Wed, 24 Apr 2024 15:39:47 +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=1713973189; cv=none; b=MYZquPfO3x8EI4zOsR0xdGeJa1cBomVKFwIVgyp/zuL3ap/kZq696h35ITipWLyZXO9ZLjeM6H0kVg2czGnRQLD8ozwHEe1l33Vl/CC9kwznyTqpGNRXpHyXUDWj5WdE1fNNXQTeSL/arluGW8EjHz83RrXtJeNdjx0gGuJ2l1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973189; c=relaxed/simple; bh=2lIFxBLgwCJzX5JrJ3/dXenO++e9t4kzGOzXSqGAN/o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SCCBX5zYVG0mbXTUnhY3Ri4je4+gRui0MIykO36xsB6uHcFoEUTuqHFo8soxHVwqCXhCUYpA4bWRQSUI+KPkGXzG7GkWnz5JVZAzlCnaRFQK+yRe7cWMOsuj6igtiY/x2mgdRHNS6Sqfcr0udNPDdKbTMARtf70l106pIJBiiUQ= 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=my6h65mM; 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="my6h65mM" 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 539EF114D; Wed, 24 Apr 2024 17:38:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973130; bh=2lIFxBLgwCJzX5JrJ3/dXenO++e9t4kzGOzXSqGAN/o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=my6h65mM4YVeZ9DcZm4YoLe3/YS+PeBmoNi6UXiO3u8YvtCjcLwTyxA3JFPp2mXBo hcqYZBr0lP+8PV/HnT5P+GsqdKLTIhNLbd2FioSrTv4kVoPj7JhV/TCfuR/IlXxL/0 k+zk2AnMhMS0BEoUqh13GsQSYhHOtTxbRUDUVlYQ= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:07 +0300 Subject: [PATCH v6 04/11] 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: <20240424-enable-streams-impro-v6-4-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=2987; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=2lIFxBLgwCJzX5JrJ3/dXenO++e9t4kzGOzXSqGAN/o=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe4sc8wfidWhB2GG2M6RILegC+TQevaNNhab dQZRlGNKcaJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuAAKCRD6PaqMvJYe 9aLCEACRi/seeMGW9AvVX9LT8jHeKozD4kCJw21DoEjh1WWjy8JgvbeiAW1wGV5jA1S3a5oC642 wZ0WaF20j23YGoC/ZF3CRsDLKnQZAZPzwjHbudmvzD6Tl5HDoydjQsfyLLOmi4Qi+H/Ej5muUKc CHwrxZPjHrdfE2GuMvo7QoKhOmZde3H0VSKt3v3AuXGasf59JLe7dA17AOyRdpAKCjyVRuhDYM9 0iGOmnxTpUpFCQ43SUk30hSB7Fm6l8g1qTfMxVzsVVxhT/aDB0K5c+9w6ngADuebmeJcvh4eqy4 uDsnJUzm3jIlWwWvT4VMYWFgPISZlFnmFeo4Oj2VDR8r06E7BaHq2UDZedAtx4d1qjZHyo3WuE7 Aeqiu7svtawo4hLQPN8ZZ3WExMxkBmYSCefHx3fNrtqfu26PzkjFyC8U3ok/gVOl/Drs5N+UgvN JAYzCP0I+dmC84rB/W/Ve311uLv3zhfDdc2WTL3TEPcNGS+4s4urYUDF6pQLLq0mTclieUT4m/N dBFdzueVPBkPP8Z2HkXqAIB2X/Cn0BFmEH7grERP4M95MqjoBGxGvcIwBDwXLIcu7EMC9YTDg9j I1XZhuY04Ht5xVnT8PQ+Wf0kJ6q92j5zXVUQqdQ8zXMSY/O2RysFevIo/enVoiUM/aWTfiaqhtz H2T2EazNaCpkwmw== 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 Tested-by: Umang Jain 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 b67456944ae1..6bc983973d3b 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -451,12 +451,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); @@ -467,7 +463,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 1af16b16f0bf..dccf693c680e 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 Wed Apr 24 15:39: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: 792192 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 44E4616C44D; Wed, 24 Apr 2024 15:39:48 +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=1713973190; cv=none; b=pya4HrQbeWFp2Ovq/ksbXxDwtJERBDe1+mEPdUKTmt0C5i/lmddLKESuQx3W4CiV9MaUqMhR/UTzZA3FKP8XtbQFI13ZZCqVywCjwg4hpJ2wAQ1pGJ47VGSYJzWA/gW8H/Di//7cBEKiserfrvKOOa3pB0pHGnyIN6Ok7xJdu08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973190; c=relaxed/simple; bh=vonbAZwpKs55afW9NwP5UYcsN67kIrk5jv4ZWnMEBZc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uKi04k+cDhR60Cq4ibuf4j0cpU5GCn9dQ+6lC5BGdjbicMv09gKmhDqLG5xEAj4fc4n8ykwesaHWxYo1ZXBk92Fd3+Wc5/nY9ZW8X448Ba5r6NdqqSkQOFIaHSm4PIT2XF9X2bbRom8Fkx9kgXE/lF4XS98EEIj9v4pNPSjo2WU= 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=LnpZv/PV; 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="LnpZv/PV" 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 D83181153; Wed, 24 Apr 2024 17:38:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973131; bh=vonbAZwpKs55afW9NwP5UYcsN67kIrk5jv4ZWnMEBZc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LnpZv/PVZtENUIqONBREVrVXdAOjEpoFTyoX8EPefEOR1inuJYYbbpq/iE68rL39N rEcmp/W5SKzm27DpyIijwh0z/sKe/2ozqDEy0iGHkGpEX9F7Ql7qKJVnHHDSEv6mxp oJ6H2gyKiBiQ0k8NwvyIFgqPytZ1uJpvGIKX4MaU= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:08 +0300 Subject: [PATCH v6 05/11] 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: <20240424-enable-streams-impro-v6-5-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=6518; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=vonbAZwpKs55afW9NwP5UYcsN67kIrk5jv4ZWnMEBZc=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe5ob7QwXAD/arnLrpp1puVabDqK5QAE9zdq gmFzcQgMlWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuQAKCRD6PaqMvJYe 9d9PD/9kQWfsuuACDVkQ3iScj386RQZ4j3AEQ9XVlRKwoWMIEiHpkP0LdoqGG0Wf8z7OPs4BSt5 FBB/gOQmkZNm2h/B9L3NYSPIR2CssW1AeF4TrPvb/aieXMPO5yTu2zEdeO2NweY0mBLcwO3TX0m xapW8RApSpGOm7+E9uKxCuEa5NIxq10eiCBTYeAl7HULXdMFtmRy+le+Z7GrSRccYGhOVMHezxm +T2A+zr8YHAU2hzh9aa/s0WabC1rgAjiOtf8l3mIWEZ8Bn6Mj5DC/Jf+qY93rsk6i0EifdIodLQ bmrrom10RFhIHXzwe3D4u4FlscDyB1AL3O6jYevyalbtl7UE39GvD0SfD7cD7InAWXtPeg9fqQx wbE2602ml2+5IV9IMCcOjf6Rv4+V0bMJHXbokc50eARrgC4bhZvMHbusxJcuvOO/r8wvIFhY1Tw r8VX5C3oKhocTrxWyoVWrBF8yu21kTts42tzXte5b7jCG+7Cy2IiwYzfDQYI3bwsDVLEfHRSLgJ 2FIWpBAq311WnKIHOsaDErvKI6H/RrhzK+AzVJT5hSE6pJSESS/FlcQzhvfk/HYu+H6CF23KGBu UoNpYRFnwl1COyE6LDD1eYVCPmUXgRjRXLNqIAGljbJXDj+N6/lKWi5qoXmxHLOD1m79dJtEJR+ lnWfD3FXLsarh3g== 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 Tested-by: Umang Jain 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 6bc983973d3b..3fe3de5abead 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2139,37 +2139,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; } @@ -2256,37 +2262,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 dccf693c680e..37c623f39dae 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 Wed Apr 24 15:39: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: 791725 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 7D88E16C6A5; Wed, 24 Apr 2024 15:39:50 +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=1713973191; cv=none; b=Ba0kwxHXkMQvDkD/0ctbjvt3Z1+kWO4rd+/wLSqe4Wkeoz2BGYwMavjFxkAbhwlaYfVVkJ+611fjaORijmxF46Mxq1LDlO5/OQ/tlwotynFC9gzAHcByBGbQ3ueKFh2RZIwB5crz8kIqL3ieByyuDTE15iAYfj2sgWFKWlXTDFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973191; c=relaxed/simple; bh=Y7RThHdyMFn/yhjyiR2IHCWsmk/FspUZdx/Zb4T64cU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hl0xAWTfboxsvsmHQhsYPocIrog0aMSaqv3dVa+/iXHxYUX9LxLdIHHJOZFAhnAlW41iFLp66KYm3s7ueaIQiiNPUJQhv0iThdDrxqFIA1pJyIi46l/BnEz/wXvlbtqRf0gCjJ2KAsLnFzNm3UfUpV9X1X0EiRHxzk5js+UNO1o= 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=cXFXJ3Hj; 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="cXFXJ3Hj" 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 6914C11D6; Wed, 24 Apr 2024 17:38:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973131; bh=Y7RThHdyMFn/yhjyiR2IHCWsmk/FspUZdx/Zb4T64cU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cXFXJ3HjlZQCgsaRswt/PYFSo0kiq+afHKXi7o2DVZbPqMQMullGI6g2DSSyQz/Q9 0AeSC9nM5pzKNCjfKtkwkK89b4/Z2EA0a2MWW97Vi1gjBNvN3A5Wqav6X8iCVBQRAG iEPWDYfHU03wKdqJmsfhUquhDix2dTvIElVHP+68= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:09 +0300 Subject: [PATCH v6 06/11] 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: <20240424-enable-streams-impro-v6-6-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=2570; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=Y7RThHdyMFn/yhjyiR2IHCWsmk/FspUZdx/Zb4T64cU=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe5s8/tI8TZotW9XtUv+1mx0N9jJXbI26HSG Me8ibyKRE6JAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuQAKCRD6PaqMvJYe 9U2SD/9McekwdJRK+hWs8Zn6acpNUs+dl4eZQbyZAze/uoAkE/f4/aUnkCCuta7s2kmD8Q/ewtN K4WC1n2tZEEGa7mDKq2HSncda3ycxsqN9WIYwC1ddA80zGAoib2wTcUTtsJVzeKEYOUJwFNKXG4 /pAmbMXvLbc+aJM8PWJbgSnojfqDdcBaykY5O4ANID00ZjtsMUz6GhX+lXhe0ievC/kCPgtLit6 0Rtlu80RKqtqSQhPu4iDum5kA7tkC6gK2k/0TfroZJfQV9GgIZD/w2QIcMw77Ad7nGTHhXPOuZg JqmSBO0HiM8buYOjIPGh7Qv+SiVo8KzyayzFdaaZOVSh2VDc8+T+dXUPiSAydXaggYJWqShWCCO cTBip5UK/9/ttMfpCg4ebIaVnZc96L9XVIY+gG938Q+fp92fvIKLjbz+vym3Z4PY0hs7F/S0Pvv N1LpnUhWdexbjcDQFPo3dQGulcUxnMdKZDT98rQV+Q6yx1LEFRiGXAX/Fwpmrb6eZ3iCrTMHkAq lVqk6a5Yy3uoHB3ozA+DWCKQDoE/paCZ18jNFXQVFa95o4icWoNi+hL77ajc14NWvr88K/IBJCr 6UKIGaY/arVO7b2CNYnwL3btWIQ4KUrHV/SGz6HRMDgFh6ZjwEQc4QJdO25t2FjTks8joBZTp8E HxEgPjdo/oRJAbQ== 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 Tested-by: Umang Jain 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 3fe3de5abead..c877646047d1 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2454,6 +2454,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 37c623f39dae..14a3c91cce93 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 24 15:39: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: 792191 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 5FBE316D33D; Wed, 24 Apr 2024 15:39:51 +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=1713973192; cv=none; b=M9dbtJ0J06Q3kGKkD5tF/QEbT2xXUDeOA4lDGcHox3N+X6tC06r0KFIr3GuVG0IXOZWUZA+errIhFy3V2zQM4mhvE9wU+yY47lDlcabCugRb43nlgKK0Rm0ybAiaOIfpe+L++8JO3V1lzXdx91rNPsQc3vWXex7Duq9wDyBVA7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973192; c=relaxed/simple; bh=IbgxalRH2aEt5+CNdN2EX6VC5JVtrkI/ABbL9thJcYE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Wl7rF2i9I5qHrzeb7/YA9QNpQwkVzchuAbefevgw3ZTAmwgDx65URc2rehZ2Ur6DBGjBMhgXWAZSxHSahnDjZDD572LK40XOAu6SYiGod4l6OojJQTzxe+U88PJOEFTZI9MFwrC64Yf2RALnbZ02wKr32kM8jsm/2KZIRVyrehw= 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=qH2WZs4C; 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="qH2WZs4C" 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 EC16F674; Wed, 24 Apr 2024 17:38:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973132; bh=IbgxalRH2aEt5+CNdN2EX6VC5JVtrkI/ABbL9thJcYE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qH2WZs4CfcddMW2bmH4ocU6luHYV7W7GfY3p2+NZ8WGKmPSeqzNiED8lwEwALDbHo oJikQScRegfnifVFzEFh8DbJQ4WN/U/BLWtLYb/25mOKoaBM4GsCuFco6J+o0M4L74 tM/IYBnBqqdCf+Tp+LFXe+Rlf0J5w/VlBIHkXBB0= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:10 +0300 Subject: [PATCH v6 07/11] 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: <20240424-enable-streams-impro-v6-7-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=2003; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=IbgxalRH2aEt5+CNdN2EX6VC5JVtrkI/ABbL9thJcYE=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe5xSH6Hsr5N6TnHgduziiXK6oY5fcNjtQmB TWVl2G8XGeJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuQAKCRD6PaqMvJYe 9Th6D/0dPo0hYOUn/R7lRuxs29cSzr+VXkOc+mIbITeGAASfFo3AEOUhiWYWYixzIl9gy2C+jvA gLbhLVLnVhCkbxfZLBzXx5rQmfKfBGVRajeYRzUErsLk+ZjqjY/QJWW32IYHuWKIlt/ghOt+LqN OLN15RwIgKsGjXldA0UtgGRnu7PANxYMYMNZs6UpCWy7dOAsV9Yd0zTNXWjRjRMYjVDYv06BdHd jHP1TVbEhmQEUaCbIa9uoGt4FoITLhsxEIf3G643Bk3xucgMI9NcuzxpNkyDwSvK0RCnImqPQX5 h1OiJGEpW6Vsb6ikY26svjY+3nfRJIl6hFR7VsQhX+1RVI9VbL4b/oj8vsNe8LdlLP1cePBtroB mtGdhWWkKV7HXaLhU0ExS68j3j1rVthaCcgMCrF0fB00YdWlXdn/RbNPeaNRO3PT424R4dvihBD nFnk8IXN9OBke92RWDplndV1+Wpl8tfTRbKCDbHUUUBkR5UfO3BxrzXV73RY2bvVY2LQDLFkt6g OZmzwmBtyU4ZG/xdQCQg/scaUhnC4mCDsQ6+MGiZ+4B0u4YjwLK7BkLiO536C3Tq6ozdVV9p7Gc arPwuqIR+FZGYm/nfnFA45evHZmH6I9rofc8YQZgaCWAZlyL7aKIyTk1zFSaeU2UTrv7t8fgm/v J/XwlVl2dgMBfHA== 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 Reviewed-by: Laurent Pinchart Tested-by: Umang Jain Signed-off-by: Tomi Valkeinen --- 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 c877646047d1..7d0343e8480b 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2185,6 +2185,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; @@ -2233,6 +2234,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); @@ -2251,6 +2254,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); @@ -2375,6 +2381,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 24 15:39: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: 791724 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 64C9616D4FF; Wed, 24 Apr 2024 15:39:53 +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=1713973195; cv=none; b=FT9d64+3iOEvISPdLz/8ihU1+QX38GTzT6ESCF3UjuE/UwHG3KdUxh4pqY3MrVoN+YLDHRc8dfbsXMkPKkg/36vU76sL0jEasWFetxbkc7Ze84KuTWxBLLxzo5kWdgElDLcHREZ182xvV1RoFHJv4OOBKQCRN2wwF2lEK7XgzYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973195; c=relaxed/simple; bh=SCpfcNeSlufEzUBR6PXLvSnUQtGIKEEZh8CT6DWaZPA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N+0hYc7FbUKs0PiKP8CUDT0Sc7h7829GICLOpVqImk7yczx7buP77p+7HwQyBRrfjQzOJcMqR/aZMx+2ViYauNCVwSJB7swL33r76wg5HBw8mihun5irxk8sdp098Yq0ZRxyNb/Ns6LJgKUt8GxbxAwoTnDkOcXxgnEnBOM+1u4= 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=fufNphZp; 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="fufNphZp" 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 7B27982A; Wed, 24 Apr 2024 17:38:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973132; bh=SCpfcNeSlufEzUBR6PXLvSnUQtGIKEEZh8CT6DWaZPA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fufNphZpqHSA2jRN7tn3mxxzhy9GZFe8EQRFiBP+BFGD1eFdPue41FSNmUQcfEgNL Db/+f3r5FbMRo6IOK+JOiuEnpKKl5A3EtK1tDDI5IgEtM3cG5cIqs2cbeRY1VqEF2v Cyr+8o8nSYaq6CnFva7001FhFLYfFD/rW/VOfwN8= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:11 +0300 Subject: [PATCH v6 08/11] 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: <20240424-enable-streams-impro-v6-8-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=6497; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=SCpfcNeSlufEzUBR6PXLvSnUQtGIKEEZh8CT6DWaZPA=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe6M6pFmjzVBidJbZHR5oknlHUkFT7GnuVyn DzYlLv4OvKJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknugAKCRD6PaqMvJYe 9QEEEACIQIZoYaynszMwGP/VL8gywnUGsU0mEWZ2fWlsJabz9KLZjvU8MalOZypBCr6xKiU52fp XZwPPRwZDEjx+3n0bEHvQ+qXLECzQAM/3F8n5OlGGmSNFDst9vU9hwELsIp806qE0JYH0juZ8Md 5f3JeEuHYPo+WxKpzewWJRsSvWe++myIsR/saen22Tx+SCe7m1xeH88FhoWsKWgiyfmI+LYCR84 KvCt0KpOTwP1qDuix6+BWxtagoz4Zagt0f7CMYunNEFt1x/i0v/q+Lmm/Adep+7vRzSwW5/Ng3z 78GNAmbypxI0R+nRPYd/C6fOnBojkdWclyPZiGjpeOmRpZcmdrBtjTR9KYtEp4wY+EsKkf4/9ma W8YOjBujzG3f9be6z9p8qyhyBqRFoEbZO8P0WU88krWR58Q9eiIcwlf0dfxpXueG3A1cJ4OQSJv y9EpYEnYZSldb1Gl3K+cj3f5p6wlOja8dFFrS5axtzFixuWah5mZ9FquMjjsrN5H++2RzDRtvcn tJXR1UVYEXK6u7JemtJ39mM50jP10e2AjbKVOjMlcablwCJnNuL6SKHB8/s99sxmfpTKgwUcmKN F9Ncq6VSwhPIsX1w9ITdsR5GWLlPYFaRRqVCDMwzeTG7olNHMNURTJL9VRHhcPqLlBIJLcaB8Ux Ivi8mzpyENRn5kw== 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 Tested-by: Umang Jain 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 7d0343e8480b..98629fa6de49 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2135,6 +2135,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) { @@ -2186,8 +2222,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. */ @@ -2208,22 +2244,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", @@ -2232,6 +2255,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 = -EALREADY; + goto done; + } + dev_dbg(dev, "enable streams %u:%#llx\n", pad, streams_mask); already_streaming = v4l2_subdev_is_streaming(sd); @@ -2246,13 +2276,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); @@ -2314,8 +2338,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. */ @@ -2336,22 +2360,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", @@ -2360,6 +2371,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 = -EALREADY; + goto done; + } + dev_dbg(dev, "disable streams %u:%#llx\n", pad, streams_mask); /* Call the .disable_streams() operation. */ @@ -2371,14 +2389,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 24 15:39: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: 792190 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 1242416D9AF; Wed, 24 Apr 2024 15:39:54 +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=1713973195; cv=none; b=ZdPTWPEbeQXrQ5W8krm1DON0Oz2VCZ6Arv2zHDUn2ruJGBdp2t4kIrRR3C5IsWaJ32zdGi7lCKskdKtfB9xN2v4fAkN1wQu60vlzu3xwwNWSAYSROmY89QI4qSmfJ2nFu2eLQ1GOfVi4kG/Q9GtB/TEGacLnHdVNxlqX0tLheZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973195; c=relaxed/simple; bh=pRFDkZbp0x8t5qt9VYf1wG+iyvJvLslpuDjA4BhzFHo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=drlahy8NfthE1SF7hrjbjC0uN/9d6rGT2lwpVH80gfoW45iidjLR3B+b8AVgYT+uB4e80v3yi3CALi9epPNKAXQ5X4s8nwBVYzsQ7eqLQr+cWQy3fad5EEFymL/j0Ep3Ojfx+It+H1MyyX39kBMqOSn0UdfwFLLK6BfuSGKgch4= 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=csWWoQsM; 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="csWWoQsM" 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 09700149B; Wed, 24 Apr 2024 17:38:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973133; bh=pRFDkZbp0x8t5qt9VYf1wG+iyvJvLslpuDjA4BhzFHo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=csWWoQsMh19bt4caqYa5wRAfar5ptIn4+YDrV1GyYXsdZB41gI2fhwnuX2u0YKsI7 HQUcYerb9bn1k8HgJoMYCkdGt6jpiruprVR5L6sb53Azc1UZ8C19velgnB8MfAqWFD M0Y6ZyrAdv608jnMJ8gTQ038Qf9OrZeJFUNG8M+k= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:12 +0300 Subject: [PATCH v6 09/11] 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: <20240424-enable-streams-impro-v6-9-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=10901; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=pRFDkZbp0x8t5qt9VYf1wG+iyvJvLslpuDjA4BhzFHo=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe6REjgSapIg2he+87ar3oPFER1O+z8GfAAl WFVlbkjuRCJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknugAKCRD6PaqMvJYe 9U2OEACWAKf7DG0o0APTc9a4eMNVWe6IttJk/Dp2ie108WZbTngTanUoRKmijmceYGiUEYUUEnJ CIYp7/QQEOJ/wOdcoWhJ4oE95J33XJMQxpB+/nYO4Eaj++VVgjqlGaYqL65es46MwwmdzTEAQoT iLzzPfBFSjLcW8Du7+HJ/O/qP7d+ymN1+l73xU4S29n2wyxE5Gt7/rKkf1MHy36xFovitFfJ+g1 Ci6vADc4lhx7/99YeJZi6S0JLtqEWgeTIEZudiM3Mhbwd6kYo5EF4+H42sABBw6g6WLn7z8ij/O vw25BIovg1d0fCYpjp9/DYykL1Ksf31CdK9EU50JuDWhAs0ExpRiOS/CF6hKx2PvGlkAd7jFtV4 PFNTtnq8tXLIScIBwFPMK+ilKA8OAwKQoij2KzVpvo3yc9I1xUYpH32P3/mHMKrgIFwpeLRMnsV L3OLGhgF1wgywnQaraX20UodmtRDqNJ+EhTvQsH3jksRqFjijZ+pyCF8r8lPIUHmT5DZQQJAUXi nYSLsoUj0EOc9jSnAlv/vQUybElGMErM0o3cPrsUcNcsz18KDA+nQslgXWv7RkDWTQLZe3lWSoF xUgCGlyQRsnnILPGkERUYGVkUqMG7l9GSgKkNSKbEw+A/nCRoR8h58xZ7jgPLxhxK0J0C2sEHtV TE74Va8gePePogA== 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. Reviewed-by: Laurent Pinchart Tested-by: Umang Jain Signed-off-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 194 +++++++++++++++------------------- 1 file changed, 86 insertions(+), 108 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 98629fa6de49..72085027e213 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2141,6 +2141,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; @@ -2162,6 +2169,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]; @@ -2171,51 +2186,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) { @@ -2224,21 +2194,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 @@ -2266,9 +2248,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); @@ -2278,34 +2269,39 @@ 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) + /* + * TODO: When all the drivers have been changed to use + * v4l2_subdev_enable_streams() and v4l2_subdev_disable_streams(), + * instead of calling .s_stream() operation directly, we can remove + * the privacy LED handling from call_s_stream() and do it here + * for all cases. + */ + 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; /* @@ -2315,46 +2311,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 @@ -2380,9 +2346,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); @@ -2392,10 +2368,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 Wed Apr 24 15:39: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: 791723 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 73E6516DEB4; Wed, 24 Apr 2024 15:39:56 +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=1713973197; cv=none; b=V6i1D6qipDqEXGQ1GpRaxdIbLyQlabDsTMShG1Vua+t3syDWvjgxoRtr9W1jPf6UvheRKX2+jEZOOJtTB1MxsARQaN45XCrXybPJU4UuwtRcozBKal/Us9oyit+mkug2ZoeJUrNszgriyz/QgOMSlVFyWtbWgvxlTxgy3mNdk8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973197; c=relaxed/simple; bh=5DKjJyyR0OoaCs/8PCRwa3HDhSGZM6mtxvJpyyRJgCQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=frPGmn5VGD1vxHFTB5qiOvRKy2uCI+XVtcFSJ+YDZ5FtyVqbrEO+MXAco5GJdmw1XC6dfZhWN5HDYzlY3/4RmuiKVthxypNOphXGpVZg5ilMp70VnSqzOkc1lliHz8z3HyE8KigW3kunf/PpuocEsLNKx27aE5i/kiGaF/IG8HM= 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=qC0uEe/J; 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="qC0uEe/J" 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 8CC4019A6; Wed, 24 Apr 2024 17:38:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973133; bh=5DKjJyyR0OoaCs/8PCRwa3HDhSGZM6mtxvJpyyRJgCQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qC0uEe/JGyWd8Byx+e4HHemoiXipetI7Eak47eSvV748UUW6y7RsVIAlYvAmeyxoO ny1IwB1l62d2r1Num6vzmt9lknF0NUwTmMbHJZ+MN8cgcC2PuIfpvGUZE4eYLA220r 5n5FTnz8dNTmPDRJk2zcF4kzD2lZuPpVT1M+rl2Y= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:13 +0300 Subject: [PATCH v6 10/11] 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: <20240424-enable-streams-impro-v6-10-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=1774; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=5DKjJyyR0OoaCs/8PCRwa3HDhSGZM6mtxvJpyyRJgCQ=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe7f3XINYH15cBKkGtiF2+EuMuX58KWA0gcw qpbFQnYvbKJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuwAKCRD6PaqMvJYe 9WKHD/9J//5kHLUPZPHMsS8OJ8YPINRTfsoih5h6PuPBzrYjYnzTEVFqAL8gTBtYci5RfNTNQcE jYHVSWk5bRYh5LXH/HXrlhNsKfoW3T4v5ulaUMmVB8+U3+M6z/cIZGONsNW8ld+WkNDs3LZHIdz adIcAT+SCL/922dW797eryHl/q8C3bMQ9PEkhmTVL8lCulozKgEJUvOaCM0XzTxxGe8wqHSlvNv dfpvfeBFJEDecv6r1PgBdaltpv5/feByEg3gtaS13Gcm8JMiLtTzv4PpC9UEEpjYN4UtkLVAU/Z imjPq+/0N3g3yigDWi+N6IvwdyLdYWlFfLfe/dEeXzLcqOsIwfZO4zR2U5fIM6sSVmeSV1slRoY NCTNIGNPfHfiGZXWvSaOz1Cr7Sw8BH/ZqXNT4Bmjkr0KSIcydBV0+bFq7a63ySI/W1yTXpU0NOS 35vQaMlmQE2QT9MBzi+zfn03nwSzgSdVMxxRWKlX85k6/fC+QR54zGEs1lLtgZW6DBgVaemwgZQ O8oa5Wa1OxuhX0ZWfiWgmVM3jkLbBsI1eiUeW2DfYFEIfaoqn6w5mzj7CifPW97XjboiT8oTQfn CKFelE73TdDpvPpyUpnhFm4sVFCw9gkadl/xWfgm95RiIubkj8g6rWPyVQLkoWjmo3tWd56pgsO UTvsUfFX5PRXVYg== 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. Reviewed-by: Laurent Pinchart Tested-by: Umang Jain Signed-off-by: Tomi Valkeinen --- 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 72085027e213..88cfa5e0157a 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2402,15 +2402,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); From patchwork Wed Apr 24 15:39:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 792189 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 1357F16DEC2; Wed, 24 Apr 2024 15:39:57 +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=1713973198; cv=none; b=KyFnZYlhlX+MAnb5sYlsT9SNWtoka+W11mQSBMianfa+qugxp3ye1H7K5wok4GUGtazpd9t1eOpSJA4yn6fdUfgQGzotQeM32Wbq87g3is8CdrkPM+3YvwoyVaaoyKUpBuS9JCINCWnmEOSvEUhhPLCVFiTFMK7ULqWm/iI45DI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973198; c=relaxed/simple; bh=WBMpiZjgIfVXMrAcPx9NMWoDfmhP6hduabqP+C8jHwc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=im1eR/5Myt0oUkgrn8jvn2naoqdyuH8JJmUfUyQI93y6IbxxFi+6RmqZ4DTJPTjVY6PUGJVfiXXWCEcAGJ0HOTu29CbNvKAgkxeijOn1uY6hcP6REqunV5Cwqch55qXGhgmgi7u69q4+J2OjzzPQBs6iDvRq1WGUVl7HVQ1nbsc= 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=c6U5Oiae; 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="c6U5Oiae" 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 1D3931A76; Wed, 24 Apr 2024 17:38:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713973134; bh=WBMpiZjgIfVXMrAcPx9NMWoDfmhP6hduabqP+C8jHwc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=c6U5OiaeE/4nz3Wy/b9sVijUWKmC2rwkGomfuKKo3T6MCZ9MBZxcHr+tIDEUihEeH tDw2YrIUnKMDsXOSxUk/PNF93QQLW2m8PPVEC4KZ1/jGVzN7VQYQ+dj3SdeyWBdyad 0vfALqUI6lCT0wD73xdo+nRp0ifj+TCcMiSCnDP4= From: Tomi Valkeinen Date: Wed, 24 Apr 2024 18:39:14 +0300 Subject: [PATCH v6 11/11] media: subdev: Improve s_stream documentation Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240424-enable-streams-impro-v6-11-5fb14c20147d@ideasonboard.com> References: <20240424-enable-streams-impro-v6-0-5fb14c20147d@ideasonboard.com> In-Reply-To: <20240424-enable-streams-impro-v6-0-5fb14c20147d@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=1300; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=WBMpiZjgIfVXMrAcPx9NMWoDfmhP6hduabqP+C8jHwc=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmKSe7I8p1ChuqaCLjjiaOJvojo8lVOAeEpHbV0 FKbocEAZ5OJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZiknuwAKCRD6PaqMvJYe 9XO7D/4u0G8IgN0GzozUuG5SvVM9Vd12LaqK0UlDz0ysAujEGCxqcQeL3eoS9zsseMOTF5DHnoM /DwlrnVKFUb3FKsH5/Lsad1unFpgB1u1O7PHjo2O8ftRSEO2aAs2oTK42AHuSShyjsO/U7ecWMZ NSu8w32Vu5sGNs2pMmQOMUqpk3QcE+KLS+w4tmt4zz+oAJ3LVVBpVR39ozD4PvcKeTvDX0RSXUw 0m7UGkBt2+xEBvNTq4swlTUnMPF+nLnAQPbkD0reyLGiGJv0V3cBlz9uFH1T3OqYv77f6XLXnSf prol02yBZOBYO7p7dVClUhtsk0QaBa2q2QF0HqiOTvJiE1wAHhYygb4GTkvGR5ncnCQSoitnQhN XIh81eSuaiJxt1QHM0V0Z5E2UU8J0h4rMOzM3iskNcJxKLUhg6bGs9Pesqzv3X9IBGANH3iD3Mz CmL7+kEFH0I4n96rZuZtciXfK59s1SVbvCKHA02lstXz0FcQdWX5+8rGn99ncZb3+7jwDL72yQ7 lKDg7zEUAiXInLjnHQaX8dqSMZ9V7PkaHRismbqjritGnCNLiMYyM7fspAPT2G92hCFKd/dSeTA ADrw0CQOR11DCKimUeyVCQE//OxmRCnWlCv88g7gy8713+tXmnJVVERl5RoS/qbTBcgY0Vc1atg dlfZrST00X80iSA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 Now that enable/disable_streams operations are available for single-stream subdevices too, there's no reason to use the old s_stream operation on new drivers. Extend the documentation reflecting this. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- include/media/v4l2-subdev.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 14a3c91cce93..99564a2ef71c 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -450,6 +450,15 @@ enum v4l2_subdev_pre_streamon_flags { * already started or stopped subdev. Also see call_s_stream wrapper in * v4l2-subdev.c. * + * New drivers should instead implement &v4l2_subdev_pad_ops.enable_streams + * and &v4l2_subdev_pad_ops.disable_streams operations, and use + * v4l2_subdev_s_stream_helper for the &v4l2_subdev_video_ops.s_stream + * operation to support legacy users. + * + * Drivers should also not call the .s_stream() subdev operation directly, + * but use the v4l2_subdev_enable_streams() and + * v4l2_subdev_disable_streams() helpers. + * * @g_pixelaspect: callback to return the pixelaspect ratio. * * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev