From patchwork Tue Apr 16 10:40:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631676 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 D1B366BB30; Tue, 16 Apr 2024 10:40:34 +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=1713264036; cv=none; b=Q/81IwdelGRc0olX+N2hd2RbnZmErFY5lNZvGl+LqPfoow+mtlBhh/xQJM07Q5G+kWtfy52uCcgXBd/0xDeqDLOhpgp+gDLtQVn5gQ4u1vMIZNnI4yh4v2orItLd2xBVpI352eWyhCiC4hGuW5QOzURckRgbcjH9Y7vDKPBEzWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264036; c=relaxed/simple; bh=HDDQMoAu1J/nqy54T1qbzKVRZVUdd5vlToKPN3OlY38=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=quCwuWCSd+Syv3NXpQ1Fh0+V7+O6SjiW3ytW5j7Z78JBC345VCzUsLJalj6JPfIMXIBRZrwot7VlON1BhFeO6+L+P2vLrvUzXHilFIvr2uve+lLvyNU7n1V8/D4vhalTWqSN6skVgfxx+usdsG63y0tGDY1La7tsB2Yh5V9KdCo= 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=V+01Wog9; 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="V+01Wog9" 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 6BF23512; Tue, 16 Apr 2024 12:39:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263986; bh=HDDQMoAu1J/nqy54T1qbzKVRZVUdd5vlToKPN3OlY38=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=V+01Wog9qx5wk0Evoh0a4pso0baxb0geOks8d/TY+SXn+sAXJXLQS4oqWgojPKnxT LxSWE580TTzmq+bOMu+Bg/Ge0odW0pUpmR3HlRucfIDf3Jrm0vklam5Y8fZq/4z7G1 VvdW3HFxofwzszh6kqNU6R4s4vLA90l/hlw0z6Yw= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:00 +0300 Subject: [PATCH v4 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-v4-1-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWccoO/zUzeu292dIBDfL5cEr7SrC5ATD9bW 07zSM55xiGJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VnAAKCRD6PaqMvJYe 9dhGD/4l52Unx5JsLj8n+Dzm271E+4Qb1qmdI5H0E4E97+NQf51kUTpiRaw/j/kXCFmzCo10Foe GsvR1gRQ0YN82bp1bCsSEV4IxKA9vrxksq0m9MGrb5VYJsVuT/1zPBENS7AQB9qRFDgnt1wnsSr 5quPmulgL8R90OkQXQNxHu41YFjrVLQlaMwU7FHWKIZbTtoCLH57zkphkSA5nVrFwGOf+TnCXOS SaTjrnJhtr//LqfXfpoSh7y3q3wu5U0sN9PmfwAtgO7VIAh6oGG4UKaBgONd7ecw3B2FX/2wuAs 1EwZ4zgApaC42JX4h/JZJ0RVsumSzOv7jUPHvflx0HEGcrXu0gNJ39iVXLEcvR76h39B1hvMrNA GIFJ6hA4Ox9ChHaC0iehF3+Y0qyrd0AMY5WpLJRYm9ZfmeApXUs3z6O01bHeMh/HMZH0igZXv+C Qv6PDWX9ZZN9BMUhLZKuaIjOqwEluwVbjJdR8yWChgy1AQ0T4SRROjTPyDFJIRrZx7chTiBP+1Y x6w01RVdTj+C0vwDksudrcGP8chvvxdIfmGw2Vrms7NgP4XXUMaX8ysfNFddOfLPxke+dRKVtuT KH09E6NxkkiY/xoL44aWsgXyu88oHiRbzSU7rNT/qkIDSsl8uw6nqpeV9igr1NpTeSSLxCiEQiK +Q0S8GWzuDoSs2A== 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 10:40:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631677 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 4C00A1292E1; Tue, 16 Apr 2024 10:40:37 +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=1713264038; cv=none; b=af9IhzqrHTDKJw2qJKwU4SxFooGDzRyEg+YiA2/C20bMIIT+KK5S9XaXEllac2qQ/g+9fPhoDrhtTYk+4cqUGOne0juQmS7U+NaY2Qc/aM/uzEhiblw0KIXw+6gGUn3jmC1sv9Lxi+5+TndWpAeM1t50tLjDIl3f+tew5i60PqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264038; c=relaxed/simple; bh=upwohULj/Oms0C2fpFjxKliuZKRIVz3n+cZk2HiI8Fw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=amSoiuiLmdd0FFhchGpn9TbOtVFw3RThE3N4Fen4gHptNG8s9vJ76KvLS45gQ6AdI2caodZgsT0QJP8HtY18TXeYqKOZWBfuNZf+54lbnWmvwvSHV7iseOWc3IzVKT2CfACrIEuACmaMghGlnEof0KOGlvN+a6/xY6yOoVd7+9c= 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=Y4FNa0Vr; 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="Y4FNa0Vr" 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 EFE559A8; Tue, 16 Apr 2024 12:39:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263987; bh=upwohULj/Oms0C2fpFjxKliuZKRIVz3n+cZk2HiI8Fw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Y4FNa0VrhfHnChqt5xBQp0qQ0lCW0EAxQYen4M8xsKQjqJ1w/PA+40UTMhDQr3T4K /TADJxobu2APzMPN0bofZVwpyA/rzwzlO9iK+jNM6IUpZLqLVzuv45Bm3DrV3si/2z 2sTjqmo/BtV5IWhNZ2hIv9VxMhwgn2ji3ASo/ewE= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:01 +0300 Subject: [PATCH v4 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-v4-2-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWcrXh9RytYRmyYC9WgDwVahPJP3rl7YgnVU LweDlMeYWiJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VnAAKCRD6PaqMvJYe 9Xq1EACYQKb0R/YVkx2Xn1fg/n2Z4oLrRYoJGN9WyyVx5c9CwPr8GIBqOYgzjN6lpuNZUmFmMsj azzEMrcmI4+pfPT7WPv+nyJO+kjHD8lXh0ofQmvgNvKj9BGfzhRUSsiMZNDKDNoa+Qf2zK/UV47 qBF5s5AmP40zNVxUc+sFehkrUY9jl47GAUZEXo/3EkMXBa3qR/+l7/CB3LwiRdeDeMNVKrc2ZW7 Fnveio2ZQXf5rWsD3x5J8aO0jJ6SdZlaGe7msSRB2apDOOOMjuZ6w8jsZ9kOQPqe9ArCszxViQo wLXArjPi1ZTf9te7nErrr/lONXZ6bY/8jAQXKrl9tgDhzWxhgu5mbchlH/gnDfdG2KKr5/BHj2B /ZTMl01LU6rt1mbG/Je59k4O8uAsny2Ry9Xq4MEDueltkcdh6cGHeJFLpsu0m38/e0LbHe+MslT g1YpS71af8PaL4yLNhAihYv6ysMYbG7qQcQA+OtcpztkuVbvreE0ewRR8dESapOAH6TnAc1yXiB qvu41ihm81kotQ+r6o2P9yP43OixCNgt4mf2l0N0VIM+mcr6x8Fc2+TS2Y2mPRRow/ELI5zhfv9 AF03UPOU3y5WNWuYOp9qCuBiJJ0FRAhoxUDNQDLg4YloIlz+veH6nuUTXj6Ly+5evdko+T5z1xf qOMnZS3X8zeKuUw== 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 10:40:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631678 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 98E3E1292FB; Tue, 16 Apr 2024 10:40:37 +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=1713264039; cv=none; b=jMKX71PZNk3y6LDBQQWjxnjirpE9Kk+8++8PeYhN5D9DW1yL1L/90SSprSEGvqknWmjJTWLGEVTbDQkeR9qTIuITBnJhKgOtsj1MlEbcr6kwC0EYNV1jTlR+H8D2BmHGi7JEdvTFAYdklUnXh4NFl9E935cS1HsUdAx4w83pg1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264039; c=relaxed/simple; bh=Z0RyfSEDzUrNB+KTFQ++Lirh0TD9nIjn5FaVBuc0a8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cJAOsOnXwTNV8RWoCEtm73/sCCD5vKM1SZWE7kW8ygwpZ/T6Q2fS2UttQ/vWWVRN52yVGxnOSXBylg92uAVKcnvM+W7EJiAq4V6qMKGi5vPvZaHIsVQYdxy/LYduvtYY+SVoQyNojzkG3SJi0UgmR1L6IWtv4vveId9c2AuE7Pc= 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=dRFq/lmw; 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="dRFq/lmw" 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 7DB1EDFB; Tue, 16 Apr 2024 12:39:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263987; bh=Z0RyfSEDzUrNB+KTFQ++Lirh0TD9nIjn5FaVBuc0a8A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dRFq/lmwkYuEJr0hgJmz8pLXj5dZW73qnyQEZZHYJy6nwbQ03mNv3TP2V/4sqQhuG 3N0DzLk/jo6TJqBvQVzqpqOb2JMJeab8psw20Mz05gd1LP03ccAfSAQvavHVIfShcg FZcaF2ji4okO5gGUgVLoSAeK2z02UpJWMgUmDWkg= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:02 +0300 Subject: [PATCH v4 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-v4-3-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWczp0NVOXeX7PWRhsOYe9eSxPpZupNvdBoE oY7C/WF7tSJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VnAAKCRD6PaqMvJYe 9WO0D/0Us/wOh4WFnUkSRkZR+1R7scfpyMLbCJNRInths96aUjRlsRE73QpkA6akOtmU4TZ8Yek eGI04oA8TTk1T/4gOHyH6uncwqqruP1FGkgiai2+NjvPVxp8BFqTzqva55QnRc51vIgViyLt9lg 3lVqE96DOnXjyyF6o8c/BV4+qrbAlOwMqK6Fh1G8raLZOAN0xXkCA7wodhBDDt5qdyM45WFCvEl QGpowpZP00XkLZsw1Xx1VLGi6irqDg0BNbCpC4NmBQmU0lPDOtW35GTa08gWupzAkfHp7aBg7Sw 5WtgWcZxFPjSWnbfyw7j1JgRYWX1MWC04cu0rnwzd/d7V6n9D8ODkzjoSd+hj7pIugPWxTY+CbN ikDQxREjxMmBuHrMQ378GkMxVejXah/QndhMiFWFeKYuNuMjJ2HsmxtMW7a6Oz/7QO2CVtr2p/D C1KtDhH3t38lU3TQO0+O9tzx1eFDCGN1cgcBHMumosFqCKq0iFFMYrh/m5EN5A8cmhw9sf0zkPg +FPO2C8U02uqD9QyaazKj20Q85kZdAfWhtFaUmBmUCHaQoVVKBO+gaM3LueeplyFk1ETjmwRAjN EFOHKcUJEFQhdoBJP/tmipyieZKMuQiDlX6OKzbVGJPl/rvmLrkl5RbF7Jy1j+keOE97jSLshUs Oy3bU/q2+r7FzZw== 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 10:40:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13631679 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 3BACD12A17B; Tue, 16 Apr 2024 10:40:40 +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=1713264041; cv=none; b=dhBgxxSdh4vaPW21oU1aY3jIQXCuJI4589YuyAE5JnZAcwT4+P//2yTs8W0hifHnI6u0/sUjcaM4tNBP0vqvgQiw4UdDKMhj9Kb2SmghV8ul7wKnhNlUBoj69TrSe2EWKUz3qSz4ojdCLLLuqz8YRyHJeWhH6B7LgZWStaWJ6bU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264041; c=relaxed/simple; bh=NLCsfA0/1jawAaRZjCj1kEooc2FTLF/KVL46Xk47Xt8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=thF9Eods3zw7q/Nd783zNmLhVQge3v6CLKJhZHf4qtIn5BZSi9KVBGvnSCVHt3ydlX7hMZyDy8NEqdOO4A9w/ToDk8kVWsHHy7YZJQ2z22xh2vpfscn3w4q5ygTJmobxcKiwehz2kVHmSqsgmmQTnNO3hLOBovpBiOIVmjia5To= 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=XijPJ+Vf; 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="XijPJ+Vf" 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 0BDE5E0C; Tue, 16 Apr 2024 12:39:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263988; bh=NLCsfA0/1jawAaRZjCj1kEooc2FTLF/KVL46Xk47Xt8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XijPJ+Vf+Vi4TJRN730/BSACDzhIO4yI1f02r31bBGO2M+2d48bFB6mp7RGBzU0fG YhSi62w8UEgk4EfMUjr3ddvwsucuazE9C0w6o7y9XeYa2j4EN8U8aZdJt7G/Hp1xqM 2jLuhH6xz/XEMgQUHbZB0uC4FQu3wektagcFW55U= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:03 +0300 Subject: [PATCH v4 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-v4-4-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWdCVINE/MGQEgrvq115qaGw8B4C4LcnMpC/ hNsw88UC8KJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VnQAKCRD6PaqMvJYe 9d5gD/4wFR12lEGv7sSZhHI8F4kotv+d3sQ+9Bsn5ddMy/Hjf7ET8FWDLUonzGRC1gzlIdfzQ7f vcrpNPKnu0irrKHvzItbvVSLwlL9vCN/CYlMbt6b/epQ3leGlpN7npX1DWlf9NBC4we7K3B9yzR 6LPLwWv0deO2oGoIX87Ffr786QMApeXOXx0vjLgifFZ5yLxkNvRtabPMGgh+3b+0rueC6WmDFaK G1EsSxelv7Im1/SHkSuNHR0OzySp41iNgWgfMZ6tEPDO5/RPxWQZhrIXnXU9iPJKBDzbZFbQ9Hn 2gPm1Djm6hxoDIkR+x0rP+HL4L7zS3RjoYC74FNHKalnVIr1popuoEtqXwCWSe32upAc2JaHGCx Z15YjKK4v6cGt2kctPse5p9Xs/BVZY9k29uekvU0e1tiw4fpHMv/c++T0zh9ZhmbJtvDnw8DCiA D/VPYpLP/KGrsxodFr19WKuxWO3W2sGInM29/WxsaNKbE/qrhXYU9Je3KL7oig2dGup8jKDLJmu 650rYZJPHh9Dv1BztBIa1wYYu0X/DTuI4BXw9DrNjTcZQ+feRhgbzB5BYyTvs5C4Wb7nA85lfT+ IQjkrjNVn3ZK6kaf21mcGKkugC4Q5xDDrrjT5yLNqBtPW0/1GRwg3iXTxPAdwwIFHi55gQZYlci 1Sb/ygA/BsIe7VA== 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 10:40: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: 13631680 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 B61AC129A7F; Tue, 16 Apr 2024 10:40:40 +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=1713264042; cv=none; b=hvPyaQN3MOdnhiKq5q2SKtSXt1JPmFhPT8c9cc4Bab+gGJPN64fgYt/w8MdiG8lb9KOzpr+X6GIcvNrO42GE1WEDrEWJsGwUlEMiC9iZaRpKiVWOPq3J+ee36fruWDOZjH2vxg4lmoK2OheF8w7+P05MIEwAKK8/B9+ugpyiPng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264042; c=relaxed/simple; bh=aCnDspzZEt06MUge756JFr8IcUIbBzfpqoQOxbjW9DY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JGvGQqYNfNA7xeZ4owK+DKpp9oj32eKGKOGL8nDHJ9PUXA+bCxz7FxGekxQUuOy8mNRnlYY6pT4AZB+mN9F8FdrRyc33TZf+R9yDE0ELv3cKgAvnv7c1xL/aUZOQWY7iIGoA4yej90HbcvQj2np/iHNuRBMJUkCF+JygfvuEgwM= 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=XmEnps++; 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="XmEnps++" 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 90E1114B1; Tue, 16 Apr 2024 12:39:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263988; bh=aCnDspzZEt06MUge756JFr8IcUIbBzfpqoQOxbjW9DY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XmEnps++cuRr6tTj0yWBvff7NsDnPqCEAvR8ZrfGguyIzFHcII781aahukpNebq/Y t+aYIEET7YSYss/IUgwwZ4ODGDZf6qwD6RS3azxB2lu3Gqn1RguVJEw4Y0fQUX/zO5 4BRCTlMejb1ElgOKP+6srDQxMFzNWIMK0gk6xEx0= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:04 +0300 Subject: [PATCH v4 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-v4-5-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWdkpZoVKvlDBKFD7J+e3JAbQuzfNE0MWqmj 9LbE8iznHqJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VnQAKCRD6PaqMvJYe 9S6HD/9swy39lykKEsaNM6moCjlnpz050Utrg3KafWu+mBN1dfieZ9BNnDzX2GEVn96tTlkMab1 iHEYSrczPNgq8wKtOgPP3CG6EcY7hpRtxLEzcO5nZqwTga5gPNIACFzzUlb58V7b9Sz3R4Bvp5a NXgrGZ1K03I4plePCtYiFgbc73iPd3HbLzeCrgg9FpIVrmb5Xy4RR+NiFkdg0ToB+9R2jAOHlMm 4Xx4cFNk7xmC7Co1HE72FWXeoCRf5abvOOlMI9q9mgnb9PWI358eoDHov2ujrGeDR9wgT3oE5XX dE4SSw3uWraq7Vy11nm4nXEnkze4Og5IH5JLyKTCAqV0IMbDwCOz+K10NFxl8YJ5UkjT9/IWRu/ juHoecSWlyNSOr/W8S0ebua1SMO2b3skWxRBas814/Z2GsO+NE1WP9ZkW5po3mbEeF+1RQNbTxf bsP/0/PQVhpgeNX1MzyWSB3bzr9zr7xvxaugCgsgVtNqmeX0CFWlAGPOXQycefLClXHxDUrCSh1 7csXdMpX3E9h5/2W+UGlgttigLFJOD++fQbgEphASMRfG5ik9VB2Q2HVGGVEazS7QC6v+Ja0KDS npae+3FGDjkGby+UeyizvVHaJdLxWxgzXuinGRrEqm9oR9wSjz5XHYD+Z1wtrT0FzLN5XkPETZd lRv6C++WQbm6K0w== 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 10:40: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: 13631681 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 2E3C712BE9D; Tue, 16 Apr 2024 10:40: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=1713264044; cv=none; b=Q1Udb4xLgKG0vMD6U8Jnce/UtvdrZsCVwrAglLhSN+V5p6ny359w/bqnJ2xMfLVzwMIlBZ2ky1p5mM8PPil83t2RzZejTl9955hDGO9SoG4VRsBBAgs6SMVUzgBYLhWxkA5hNqqEvyd7aiYn1X+CxfuQh8hyZ/bfMlUgl/tY9Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264044; 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=SgUxcFremw1sChBnRVAMuSBDYRypj1TJnvXbTj6+NiZlAnt+A+OjFr9e0TG94DzsYCcxJrR4B9s0/t6hRFVJH/24nDSatTvRFnjSFr2lEfShw/kJHisf1t+s2vnALpVNL5gdVGUYiXVfZp2ywNRhjWLtvkHy528NOujpRx17LZM= 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=pOMciXaG; 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="pOMciXaG" 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 20DB3161B; Tue, 16 Apr 2024 12:39:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263989; bh=cRX39UhcoIccSBN5un+izWragJ2sRwImSu+ClyYCk+Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pOMciXaGl5oggMRyuy7Tj9JkWTJQJIYc8uBddCuGU94yhUmCpjuD18SY4An+FCvUM iaHC6d1ls4KtO39ejTV78De3uFo0dcPbWVm/EeXjSk8rxALu3aA985nDVY5bs3z/rn Tk02Up1TGgLGHqIVL4S5shoVA4sLuVB722D2qGQI= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:05 +0300 Subject: [PATCH v4 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-v4-6-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWdseU1u4Li7mA1LDngERmXrEF9+dLG7o/av GUgK2wtpYyJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VnQAKCRD6PaqMvJYe 9dWAD/sEmuZrk2hyE7S5LztAMjdkjkKXyYssWbJH6UR2QaYv+LvXZlc0HP3/6JGj8qQm9epFnia LGn55OXUtsgzUfNfJcInrWkd+U3/90BlhWWcSeUVnRWlPMNqwk+2UdfM/RnPPb1wReO+kN+LJn9 dKlF0Ce7BYHDmyhCNjMllr2JHa+KhpqOj6NgMXF9lzx3osFYJy/ojAAxMAUokpTRgEjZmrMe8ld 4vF2esJwfBTfy8v8T2DCbKsB95ZgAIBPKNIj7Rco7sz9UX9TZYba9gyrL2LFRsZqk8cy2xcr03V n6Jx+978CHyyGkWU4BmpMv7hwEgKFORf0JpFFcfEYTBw8Owg95Jbbge2c1dzuVATPf2ol0bS5Ft pd3nzQlj4pCo9PNww3gsCGeGJF1Cp6lvPc3PoVqqzRZx5qEqMS5sIIgGCoLgXB+uj2UAxa7iIwG SSgGl8GVGqu0NKv477iiQXryHy9wHrgwQvqHaks+AxnS2Cz+iBmQjr+ep069RCCzM6sNgncd6Eh ZwDknrxM9mhDQnLoxkST0kdntIXdgu/K9sRqC9a8RKpacaNEj9wUUtQJFeIN7EgwcMN5wDCBL4/ xAOpPwmGUfwUX1YWg0If88EgwL1Vp37cj3C9MZ49otR0WlvJrFI20h4PhxEaDNAscMEyRkbW53H 8CtP3mqBadXE6FQ== 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 10:40: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: 13631682 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 9DBE912BEA4; Tue, 16 Apr 2024 10:40:43 +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=1713264045; cv=none; b=phf1pUBmZa+UEwHEl184I8M8PcbXnCS1r8WFPIm1w+4hQr01yL8ktQaQi774ql8uD4RE10BrXES/nITp3quOHeleTEoAKbaGGM9G0jZxAvsABbZi3VCVdAHASDLlkKSqvOjpmcKxL+K/+75RMFzP/GicjbA7HQdxTDJysSEwKBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264045; c=relaxed/simple; bh=2Xt7vzkAHQK8ZH9kkym8FF4Sl2cd7jU/rDWfYtxbPXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cmGDXb1APD7e/JCw5MleaKLKk3i5o9qnPYEwbI8O79ouaH6e2NqZfZJeqE+RgwM793WZ/Jj7xUlFo8gcpDGcsXQkK2t9qNZ5Z4Y9ZzJlfL928SIflwdhZZdAwkd405pcGAaGpJtH7ZESe44dLfQit4gZ5z+4zrF5ksSOOg/ddnc= 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=O4NiWO3/; 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="O4NiWO3/" 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 A35F51653; Tue, 16 Apr 2024 12:39:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263990; bh=2Xt7vzkAHQK8ZH9kkym8FF4Sl2cd7jU/rDWfYtxbPXE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=O4NiWO3/OLfzbf2vmOoQrI1zmhHI4C7CMpXddAJ5mgZg6OfMXBczz0oJpa87PUVqy jCz20tjcZ+1GkFNSCmE/hbZvn76lw1UQqsOfY9GdXhtgUC0xg1tFghfUnxZYEjRoR/ huGJDAt8Wlptd7pbKiVLcS32f2F0gZPTpVe+LgYU= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:06 +0300 Subject: [PATCH v4 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-v4-7-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWeaGr6cyHEo/rgUE7p8tfeqlUMV2SZ6g2Tl SYHKSUcCOOJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VngAKCRD6PaqMvJYe 9f7TD/0UZ/r8/b+fzMMvzj2UuD8gfJPMgZi/LFLlsJAZNDS110+CDuTLKtMYW09gKZotPlX3uAF SEcCkuRy7Ct9TVT2CwcQ+ULpziOFyVYdbW87W+tNl1p9BwXjp80BF2HgtJv1pODeu2VijMD2HKx OTbpC60ed8q3lYAdr+hz/kN39xblOmybimFBAuEN7tDNO682WSBxoWfLrZa8o0UGtblJeusdm6g Z/Ugtng2ENup3d4EhbBE5MJJeQCZz/WnFgv0xiSZ/Ah+c9Jaa9JH008fc4gdih5JCVfERvC5ty8 cJ/MYHb2s/lhpJxHGknq5r/XQ0XOs9i9kqWNlDS4IyiFrufO2RNdN3BNQ5pCJz0Yi4Cc4I88vWd 9P4l4FNCWs7gd324whUExFqAPQFu2D1WywkeHfLG1k4nu+H05lpJAaXj7lA8ljzE9WCRQe18zo/ gOQzMAUMDAE4aZyrBJwqHUMpg8uwWtBIb3e2QYjGhNeyono3ICoVPCN5GK2t24YwiOWfTMjHzdw Ua5IhLwCXjb+iAEAWHm5ba8IgFt6NQACEi3A/y7av0ejMaxjWg1pPh41WgGbEPhKRfmzZ8RTohc ato3MUXad+Q81yBVOnYJwqOmHz6TZVaJ4CQw8r1lXFUcTdOz7o0NHZdRBMmsYvUIO3Mw0PRTwHz ff0pv6Da1elhtEw== 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 --- 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 10:40: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: 13631683 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 9442012C478; Tue, 16 Apr 2024 10:40: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=1713264048; cv=none; b=TDHkd293wok3ghODfh5RxDJb/6/ard+2+7ZA90mh4IVaNp2V4bX9WtR6ZNzN8knk+isRZPOq/EYg5ToCn9lsqwA6xTCDiIqsJdfrJbs713REU5eLEyoMGC2TAIOu6j4laFIXcHhzv0eO35Nu+gjFMZHXfLVBRj1w129GSnr+U9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264048; 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=mQsn3xQ4mBxpsfPVOV6Acwzrke3BFahWbaP/BYKgLIReHM8EKkBaGu4Sik5+NNWn5L3tqVnHk/VxVL/DK/bK/wqnjHrSTCQKN88td+TpV9XZpPQ74cVRHd+Vqp96MNMQZhCZLSezPw6glKhONFhnTXMhwXlS95BxDqfDoD7PQO0= 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=GIEhihUE; 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="GIEhihUE" 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 2FF2817E1; Tue, 16 Apr 2024 12:39:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263990; bh=P5Mk1MbOCA+IjWUrNTqMU+A9EoigwOcf3/o12ANGKQI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GIEhihUEZri/VqvuAK0z+NoLiKxHjEuY1h6ypPe3xYSY5wpufbLuASB/4yCk7wUMa PIwjLayfaHOr9+pcu/HFk9Q3cWOEhYBwm2h9RYnG4sNiG69uJf027isFBMWupOkHAo SNU/zRDIZ3hmPeEO3zcWh697Jl4MquCohjDDrjyg= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:07 +0300 Subject: [PATCH v4 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-v4-8-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWeRsGMjnG7FWQVe6yFYHUSrlXyTjpN4PglE 6ruXycVeCuJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VngAKCRD6PaqMvJYe 9U77D/9J+/2I0xDp4N06MXQHbAcYXddmlerqBFZ33A1AEs6EgtFbTNgrUjG2t/3LLNzCkt0xGEi 2koo9IQc+1yxsA3e7EX0Pkskmbbj3HwElKVJ8SdbIZWnNudFMNYCbKfNSQe61U2UHBi2+baLcSK NNFNNk31a0WyGrS7wmBRbog5i7oXPkVCsWN1CMvyCmOlN5rY8DZqgttJuTVJtGHXbkRVvQmYHe4 5YOOrB3aShPA/9CenW86BTYol38cA5Simo9U/hyURMhio1A+JNntFd4+MkfTSPn9np4aPZcMHuT ROQtXdJhg2YOfg2bPKzMyUPo0DN8KvIZ8DgKZAWVdWsaX0eMgH8pizQ1SORassMsiRrjjRdT961 Pgdr+jbp1vZJwDI2hIR+0vDIDshIO/ybEMNxe1PBVZkReRSuJZzBLbZT67u6NPosHbg2QeIFneb GML27AmvvQfwBizLYOL4MLY6uClbaHc0eX1czOs+0TguCwb1Hcu0lElP86v9sqCxzeSvbe8zqCU wEcw3qCfYkzkCsNOGvNiClZampAj3uw8tJMIgQ2ZE8pP/X2QBIq3N0nxZ3m0tvfv7uPmKicewSB CUD8+H2w6RCMFV+YMaWvgD74mc78KBRfvXeBmwzpgoBMdwD4zWkyF5AhyFvGUrvjKAXr7pw/m9s B0bRCGAAFFHMLIw== 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 10:40: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: 13631684 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 6E71A12BEBF; Tue, 16 Apr 2024 10:40:46 +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=1713264049; cv=none; b=ZPukpr3EK+K3rZGj8u1gj3y02KTPgb8/p2qRoHI1fGb9tbZmCCv46g3Em2EOW9089ewcfDvPJv/ls/wNg3BVIq5Pb6wFdZgzcHd5ZASk01nv+e00pJaCDMfaKoaNmCXNFRbgbyDvgh9abmxGx/KAWSTIMDSVaPTX9WPZORqejUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264049; c=relaxed/simple; bh=I7FJRoxmg13/uSTJeBjTcd/3nfaPZV8Nz+fLKzo8qDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hPLiUIq0FOVi2RlNwmjUD3j18fT/TOqnTVTFia7FwTeQrwPwcZcA7phV39A40P5PjHcbF0+lRXdJDjKNT/C9UCQNwHSfy6M+RkywLZ0qV2FJnTViST0P+VpPzi5rO07L4T1BDn59P6ZV7i5v24Vh7UvABTfrfGwBfcPCHlr/u9c= 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=S/qm1612; 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="S/qm1612" 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 B3BBC1815; Tue, 16 Apr 2024 12:39:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263991; bh=I7FJRoxmg13/uSTJeBjTcd/3nfaPZV8Nz+fLKzo8qDw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=S/qm1612CGyAutla4Wobre4e8if1hCiXMfpENTEudiRor/pXZKF44JhiTP+RmiEsx ZI5bTnNVmdROCLteReo7GvVu/W8sg7tXc/bmwLREMI1VBMpASlNyokrCnWRbFS0QQ3 uiRjSrjbLmidOjv+dqYUfKbJGQ6GIyrOXhJtYM0E= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:08 +0300 Subject: [PATCH v4 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-v4-9-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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=10478; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=I7FJRoxmg13/uSTJeBjTcd/3nfaPZV8Nz+fLKzo8qDw=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWeE0gcnoVskz2Occk6xDHCJ+aAffyGjmTMy JSshY+xDI6JAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VngAKCRD6PaqMvJYe 9WpED/4hMbREKSdseJBCUQWmhMTWDLG4C8mtLH+gIfIHVgML2CVP2dS0Pe56b7Lxa/22/R/tYOx 2nJxpzSqWY040EKT69PmFXdBKcA77XWbQ/oxewT2VqE2i40Dfyqj4ijREY1rHp+k4uitRS+B1EV 21ETJO70VuqlR8MlEGnYcn6/T3BQONuE6cS2X+SUIF6GpX2JdHpYYwV3+wQTY9Iw10AkwTzdJlg A2HQ8VBsk38+CpgDETppUnc+oml6I3F/5uS9TvU1NDsjm2frkN0u8Z2eFUWBtEbw801QVVT+KJ3 JDA4m/x/rdl73fmpMAJgz1LDfK3LgFdm26Wq/0PyhUD9CGR8m9noIVxCUze8J368J/VXjKqDdjd HtnHce3TeOQ3XwKoq8vAt5japrXK9CRMVb5VkNoaXAGvDSFYHffTL39JjF+Pd/RvzNi0w10czQd CmycC+gc6Dy7SXqKwSh1DLyckajnVfrrEI7jy8XGezP3uMRxDNkyLqe+O3zh1+f2+7APbvLcuk7 tKv1nssOZ6UvHYWYYXXE9bPa1s2VdwZ9N0rfSS3oyCja8A7ITsdzlomMxzLRsY45aLcNKcOcA2A w7OUiwNeOxaX29hjou4fdCdn/21v8q4KD7axzNm48244ilZqEZ01e8CldDjBJTJXsjeGVxrnu+U Do7AyhzjaSBA0tw== 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 --- 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..1c6b305839a1 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2106,6 +2106,13 @@ static void v4l2_subdev_collect_streams(struct v4l2_subdev *sd, u64 *found_streams, u64 *enabled_streams) { + if (!(sd->flags & V4L2_SUBDEV_FL_STREAMS)) { + *found_streams = BIT_ULL(0); + if (sd->enabled_pads & BIT_ULL(pad)) + *enabled_streams = BIT_ULL(0); + return; + } + *found_streams = 0; *enabled_streams = 0; @@ -2127,6 +2134,14 @@ static void v4l2_subdev_set_streams_enabled(struct v4l2_subdev *sd, u32 pad, u64 streams_mask, bool enabled) { + if (!(sd->flags & V4L2_SUBDEV_FL_STREAMS)) { + if (enabled) + sd->enabled_pads |= BIT_ULL(pad); + else + sd->enabled_pads &= ~BIT_ULL(pad); + return; + } + for (unsigned int i = 0; i < state->stream_configs.num_configs; ++i) { struct v4l2_subdev_stream_config *cfg = &state->stream_configs.configs[i]; @@ -2136,51 +2151,6 @@ static void v4l2_subdev_set_streams_enabled(struct v4l2_subdev *sd, } } -static int v4l2_subdev_enable_streams_fallback(struct v4l2_subdev *sd, u32 pad, - u64 streams_mask) -{ - struct device *dev = sd->entity.graph_obj.mdev->dev; - int ret; - - /* - * The subdev doesn't implement pad-based stream enable, fall back - * to the .s_stream() operation. - */ - if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) - return -EOPNOTSUPP; - - /* - * .s_stream() means there is no streams support, so 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 10:40: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: 13631685 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 728F612C52E; Tue, 16 Apr 2024 10:40:49 +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=1713264050; cv=none; b=O9hKL/Cg5iOO1nRaYkzHQIE9R2t9e9OYrNacHsObLLXx7qeab0AOxI7vLCHIiW/y/euY7AOxMtdk3143x4WwlFyfU7lPslSQFJ+Drx0qg09vHZN/uwyv7I37hk3mpYaU8OrjeVAH9ED+KP9ugBN1Ou018xD1atxuII0EWUK1AM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713264050; c=relaxed/simple; bh=QUIXIag+hvRWU9wlTolKXQYXe77jOaP6Mj5YCsZs9Zc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hIyAQD6CXRoJDNa9/L6eJ3PEIEdElQPCkYIXpxlzPa6cacnd9qmeaIXGt+7VRL1tjOc8ZGpmXifQOA9+B2qhNapGVRVNjaugA2C2Y2JoQmzPWC8nj51/jG7yErlTRihYk1MGnehJhWcRdYi3r/CRetJ+MbHC3tjwSl/R4eOfc/c= 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=NjpCdpFi; 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="NjpCdpFi" 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 4B5A6182C; Tue, 16 Apr 2024 12:39:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713263991; bh=QUIXIag+hvRWU9wlTolKXQYXe77jOaP6Mj5YCsZs9Zc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NjpCdpFiMwS0gNFsuxj//3lohX3iXQVfDZesK4TsEzTw7sBjOEXSieLOurtpAVJdL GgOxdBO6lrXj4cSnbuXmxaeaLd4Ns5JbBn9WoyFSLEmZetB6DzDaVcNC2NjY0eYUS5 tsFppbQOt4n+ggmWVJf+plcFMymtFgWDz6NUeq1Q= From: Tomi Valkeinen Date: Tue, 16 Apr 2024 13:40:09 +0300 Subject: [PATCH v4 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-v4-10-1d370c9c2b6d@ideasonboard.com> References: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@ideasonboard.com> In-Reply-To: <20240416-enable-streams-impro-v4-0-1d370c9c2b6d@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=QUIXIag+hvRWU9wlTolKXQYXe77jOaP6Mj5YCsZs9Zc=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmHlWfylPU98r1DfMzWnp5XPdsM7x3jcGm55fmu 3WFK1ZKWJyJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZh5VnwAKCRD6PaqMvJYe 9StoD/4jhv+3mq5r5K6QD+xjUDEJLRdnOyPw6IzIk19CNTR3GEvBlSFVprQVe4sUED4TcWLHAKn 89mk0Y7Tw3vwuJv0iqwjcwELpLhiLjaKuSQdxImu+0EootKR2SYfAXQ++vQPiNvibNXv2En6AUQ V7MwvxCNp8oVVF7hen4GeKH8NBBoo1wQRcneau1f8L3wBHk+0KEaAITdvsrt6GuJqJ5AEL9qTEj xWoEdV2gZRftWcxVaX8YfUStSrt0+fA/JedtstbIGOme/MmX4TXrCUcfGYYZyz4GUHSU37LZtrF TpSnsEfv7Ly8uPpkcEMd8pviLKWSB2ccBZjaAIcmYwCcLB2FWMNGQsvPAFesWXT+UDmvtcjRYfs Du8k0auZ7od4ykI2uymA3iYUzRvyLr/a8+5FKSJeFMzje8Eo0jzm1mzZhZv3kPO/NBWKZsLxLlo Bb36lW5zfWYsrx27Qn0wHgET+sdqw2dTdQInhVMvYU/6JaWXtyMQ67qpmhbUMeuutDbe8lW4nrH RUXE0DYvirvG836FzqU9SiqCOutsPp+oPZ+VU62oYBwaTljm5maEMJbs87YAlyyYqd0SYsegruV 9h9bTKwjKz8e2TWZgYhmx07YJ6YQXa03vsPrblGUTz85m2+KKSQBJltoiF3xmT7aITBT0Op/Zhy FDZcHF8DPSH/Utg== 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 --- 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 1c6b305839a1..83ebcde54a34 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(1); + } if (enable) return v4l2_subdev_enable_streams(sd, pad_index, source_mask);