From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D339C433F5 for ; Thu, 16 Sep 2021 13:24:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A25061216 for ; Thu, 16 Sep 2021 13:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240034AbhIPNZo (ORCPT ); Thu, 16 Sep 2021 09:25:44 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:37444 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240001AbhIPNZo (ORCPT ); Thu, 16 Sep 2021 09:25:44 -0400 Received: from [192.168.1.111] (91-158-153-130.elisa-laajakaista.fi [91.158.153.130]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A8E122A5; Thu, 16 Sep 2021 15:24:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1631798662; bh=Fu1G/WPOhBrmTBfQ12HXAPQcyYKkM5vMmmliW1bndvg=; h=To:Cc:References:From:Subject:Date:In-Reply-To:From; b=bF9218Mi/qG57NFF0OBVlbKrjQZ1J9DoixH61WpCJgFzCPoJGTsuPHB3ctGkRwRmg S4g7dAE35ByVXGGpla1QQtv814xonKXq7gn8v9QjYMHLVrtxZl44o2BYdSvCRjEr8J lkuMwDvRWYPQ0jEnEUQ2ZCGPh352wGFDJ80Sn1cE= To: Jacopo Mondi Cc: linux-media@vger.kernel.org, sakari.ailus@linux.intel.com, Jacopo Mondi , Laurent Pinchart , niklas.soderlund+renesas@ragnatech.se, Mauro Carvalho Chehab , Hans Verkuil , Pratyush Yadav , Lokesh Vutla References: <20210830110116.488338-1-tomi.valkeinen@ideasonboard.com> <20210830110116.488338-4-tomi.valkeinen@ideasonboard.com> <20210913114154.ovffxjoghgdud4js@uno.localdomain> <0733ae28-bcd9-6dc8-fb6a-0fa43beb1191@ideasonboard.com> <20210913133841.nck65h2ft4hfnbg5@uno.localdomain> <656577a3-b783-0272-4809-20169b84e891@ideasonboard.com> <20210916130752.bsdhq3xpsatdfl4a@uno.localdomain> From: Tomi Valkeinen Subject: Re: [PATCH v8 03/36] media: subdev: add 'which' to subdev state Message-ID: Date: Thu, 16 Sep 2021 16:24:19 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210916130752.bsdhq3xpsatdfl4a@uno.localdomain> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Hi, On 16/09/2021 16:07, Jacopo Mondi wrote: > Also note that operations like s_stream do not take a state as > parameter. The driver has to fetch it from the subdev anyway > (this in reply to the idea of having the active state as parameter vs > retrieving it from the subdev if ACTIVE) > > While porting the R-Car drivers on top of this series I found myself > in the need to (in the s_stream call chain) > > static int rcsi2_start_receiver(struct rcar_csi2 *priv) > { > const struct v4l2_subdev_state *state = priv->subdev.state; > const struct v4l2_subdev_stream_configs *configs = &state->stream_configs; > > ... > > /* > * Configure field handling inspecting the formats of the > * single sink pad streams. > */ > for (i = 0; i < configs->num_configs; ++i) { > const struct v4l2_subdev_stream_config *config = configs->configs; > if (config->pad != RCAR_CSI2_SINK) > continue; > > if (config->fmt.field != V4L2_FIELD_ALTERNATE) > continue; > > fld |= FLD_DET_SEL(1); > fld |= FLD_FLD_EN(config->stream); > > /* PAL vs NTSC. */ > if (config->fmt.height == 240) > fld |= FLD_FLD_NUM(0); > else > fld |= FLD_FLD_NUM(1); > } > > ... > > } > > Am I doing it wrong, or is this a case for the subdev to have to > directly access sd->state ? In s_stream path you should: state = v4l2_subdev_lock_active_state(sd); v4l2_subdev_unlock_state(state); If you already have the state, e.g. in set_fmt: state = v4l2_subdev_validate_and_lock_state(sd, state); v4l2_subdev_unlock_state(state); Accessing the stream_configs directly is fine but not that nice. I did think about some helpers, perhaps for_each_stream_config(), but I didn't add that as I didn't have the need. There's v4l2_state_get_stream_format() which can be used in many cases, but we probably need something else if you need to iterate over all the configs. Tomi