From patchwork Mon Aug 17 14:35:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11718373 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6EBBB13B1 for ; Mon, 17 Aug 2020 14:32:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53E7820789 for ; Mon, 17 Aug 2020 14:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729047AbgHQOcK (ORCPT ); Mon, 17 Aug 2020 10:32:10 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:39663 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728989AbgHQOcJ (ORCPT ); Mon, 17 Aug 2020 10:32:09 -0400 X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 530EDC000A; Mon, 17 Aug 2020 14:32:06 +0000 (UTC) From: Jacopo Mondi To: linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Jacopo Mondi , Kieran Bingham , Laurent Pinchart , =?utf-8?q?Niklas_S?= =?utf-8?q?=C3=B6derlund?= , sakari.ailus@iki.fi, hverkuil@xs4all.nl, hyunk@xilinx.com, manivannan.sadhasivam@linaro.org Subject: [PATCH 1/4] media: i2c: max9286: Initialize try formats Date: Mon, 17 Aug 2020 16:35:37 +0200 Message-Id: <20200817143540.247340-2-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200817143540.247340-1-jacopo+renesas@jmondi.org> References: <20200817143540.247340-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Initialize try formats at device node open time by querying the format from the remote subdevices instead of hard-coding it. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/max9286.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) -- 2.27.0 diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index 47f280518fdb..7c292f2e2704 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -794,12 +794,29 @@ static void max9286_init_format(struct v4l2_mbus_framefmt *fmt) static int max9286_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh) { + struct max9286_priv *priv = sd_to_max9286(subdev); + struct device *dev = &priv->client->dev; struct v4l2_mbus_framefmt *format; - unsigned int i; + struct max9286_source *source; + + for_each_source(priv, source) { + struct v4l2_subdev_pad_config remote_config = {}; + unsigned int i = to_index(priv, source); + struct v4l2_subdev_format remote_fmt = { + .which = V4L2_SUBDEV_FORMAT_TRY, + .pad = 0, + }; + int ret; - for (i = 0; i < MAX9286_N_SINKS; i++) { format = v4l2_subdev_get_try_format(subdev, fh->pad, i); - max9286_init_format(format); + ret = v4l2_subdev_call(source->sd, pad, get_fmt, &remote_config, + &remote_fmt); + if (ret) { + dev_err(dev, "Unable get format on source %u\n", i); + return ret; + } + + *format = remote_fmt.format; } return 0; From patchwork Mon Aug 17 14:35:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11718377 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E3D1F14F6 for ; Mon, 17 Aug 2020 14:32:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C209120789 for ; Mon, 17 Aug 2020 14:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728989AbgHQOcM (ORCPT ); Mon, 17 Aug 2020 10:32:12 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:58411 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729049AbgHQOcM (ORCPT ); Mon, 17 Aug 2020 10:32:12 -0400 X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 6C83EC0006; Mon, 17 Aug 2020 14:32:08 +0000 (UTC) From: Jacopo Mondi To: linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Jacopo Mondi , Kieran Bingham , Laurent Pinchart , =?utf-8?q?Niklas_S?= =?utf-8?q?=C3=B6derlund?= , sakari.ailus@iki.fi, hverkuil@xs4all.nl, hyunk@xilinx.com, manivannan.sadhasivam@linaro.org Subject: [PATCH 2/4] media: i2c: max9286: Get format from remote ends Date: Mon, 17 Aug 2020 16:35:38 +0200 Message-Id: <20200817143540.247340-3-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200817143540.247340-1-jacopo+renesas@jmondi.org> References: <20200817143540.247340-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org The MAX9286 chip does not allow any modification to the image stream format it de-serializes from the GMSL bus to its MIPI CSI-2 output interface. For this reason, when the format is queried from on any of the MAX9286 pads, get the remote subdevice format and return it. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/max9286.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index 7c292f2e2704..e6a70dbd27df 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -742,8 +742,10 @@ static int max9286_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_format *format) { struct max9286_priv *priv = sd_to_max9286(sd); - struct v4l2_mbus_framefmt *cfg_fmt; + struct v4l2_subdev_format remote_fmt = {}; + struct device *dev = &priv->client->dev; unsigned int pad = format->pad; + int ret; /* * Multiplexed Stream Support: Support link validation by returning the @@ -754,12 +756,26 @@ static int max9286_get_fmt(struct v4l2_subdev *sd, if (pad == MAX9286_SRC_PAD) pad = __ffs(priv->bound_sources); - cfg_fmt = max9286_get_pad_format(priv, cfg, pad, format->which); - if (!cfg_fmt) - return -EINVAL; + if (format->which == V4L2_SUBDEV_FORMAT_TRY) { + mutex_lock(&priv->mutex); + format->format = *v4l2_subdev_get_try_format(&priv->sd, + cfg, pad); + mutex_unlock(&priv->mutex); + + return 0; + } + + remote_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; + remote_fmt.pad = 0; + ret = v4l2_subdev_call(priv->sources[pad].sd, pad, get_fmt, NULL, + &remote_fmt); + if (ret) { + dev_err(dev, "Unable get format on source %d\n", pad); + return ret; + } mutex_lock(&priv->mutex); - format->format = *cfg_fmt; + format->format = remote_fmt.format; mutex_unlock(&priv->mutex); return 0; From patchwork Mon Aug 17 14:35:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11718381 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63F1813B1 for ; Mon, 17 Aug 2020 14:32:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5529C207DA for ; Mon, 17 Aug 2020 14:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729049AbgHQOcO (ORCPT ); Mon, 17 Aug 2020 10:32:14 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:50277 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728780AbgHQOcO (ORCPT ); Mon, 17 Aug 2020 10:32:14 -0400 X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 83DC1C0005; Mon, 17 Aug 2020 14:32:10 +0000 (UTC) From: Jacopo Mondi To: linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Jacopo Mondi , Kieran Bingham , Laurent Pinchart , =?utf-8?q?Niklas_S?= =?utf-8?q?=C3=B6derlund?= , sakari.ailus@iki.fi, hverkuil@xs4all.nl, hyunk@xilinx.com, manivannan.sadhasivam@linaro.org Subject: [PATCH 3/4] media: i2c: max9286: Do not allow changing format Date: Mon, 17 Aug 2020 16:35:39 +0200 Message-Id: <20200817143540.247340-4-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200817143540.247340-1-jacopo+renesas@jmondi.org> References: <20200817143540.247340-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org As the MAX9286 chip does not allow changing the format of the video stream, always return the format retrieived from the remote subdevices when an attempt to change it is made. The -max9286_get_pad_format() format is now unsued, so remove it. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/max9286.c | 58 +++++++------------------------------ 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index e6a70dbd27df..a4e23396c4b6 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -689,54 +689,6 @@ static int max9286_enum_mbus_code(struct v4l2_subdev *sd, return 0; } -static struct v4l2_mbus_framefmt * -max9286_get_pad_format(struct max9286_priv *priv, - struct v4l2_subdev_pad_config *cfg, - unsigned int pad, u32 which) -{ - switch (which) { - case V4L2_SUBDEV_FORMAT_TRY: - return v4l2_subdev_get_try_format(&priv->sd, cfg, pad); - case V4L2_SUBDEV_FORMAT_ACTIVE: - return &priv->fmt[pad]; - default: - return NULL; - } -} - -static int max9286_set_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *format) -{ - struct max9286_priv *priv = sd_to_max9286(sd); - struct v4l2_mbus_framefmt *cfg_fmt; - - if (format->pad == MAX9286_SRC_PAD) - return -EINVAL; - - /* Refuse non YUV422 formats as we hardcode DT to 8 bit YUV422 */ - switch (format->format.code) { - case MEDIA_BUS_FMT_UYVY8_1X16: - case MEDIA_BUS_FMT_VYUY8_1X16: - case MEDIA_BUS_FMT_YUYV8_1X16: - case MEDIA_BUS_FMT_YVYU8_1X16: - break; - default: - format->format.code = MEDIA_BUS_FMT_UYVY8_1X16; - break; - } - - cfg_fmt = max9286_get_pad_format(priv, cfg, format->pad, format->which); - if (!cfg_fmt) - return -EINVAL; - - mutex_lock(&priv->mutex); - *cfg_fmt = format->format; - mutex_unlock(&priv->mutex); - - return 0; -} - static int max9286_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *format) @@ -781,6 +733,16 @@ static int max9286_get_fmt(struct v4l2_subdev *sd, return 0; } +static int max9286_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) +{ + if (format->pad == MAX9286_SRC_PAD) + return -EINVAL; + + return max9286_get_fmt(sd, cfg, format); +} + static const struct v4l2_subdev_video_ops max9286_video_ops = { .s_stream = max9286_s_stream, }; From patchwork Mon Aug 17 14:35:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11718387 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B0CA15E6 for ; Mon, 17 Aug 2020 14:32:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C24F20748 for ; Mon, 17 Aug 2020 14:32:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728666AbgHQOcR (ORCPT ); Mon, 17 Aug 2020 10:32:17 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:43685 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729053AbgHQOcQ (ORCPT ); Mon, 17 Aug 2020 10:32:16 -0400 X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 92BC8C0009; Mon, 17 Aug 2020 14:32:12 +0000 (UTC) From: Jacopo Mondi To: linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: Jacopo Mondi , Kieran Bingham , Laurent Pinchart , =?utf-8?q?Niklas_S?= =?utf-8?q?=C3=B6derlund?= , sakari.ailus@iki.fi, hverkuil@xs4all.nl, hyunk@xilinx.com, manivannan.sadhasivam@linaro.org Subject: [PATCH 4/4] media: i2c: max9286: Remove cached formats Date: Mon, 17 Aug 2020 16:35:40 +0200 Message-Id: <20200817143540.247340-5-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200817143540.247340-1-jacopo+renesas@jmondi.org> References: <20200817143540.247340-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Now that the image stream formats are retrieved from the remote sources there's no need to cache them in the driver structure. Remove the cached mbus frame formats and their initialization. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/max9286.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index a4e23396c4b6..97dfee767bbf 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -160,8 +160,6 @@ struct max9286_priv { struct v4l2_ctrl_handler ctrls; struct v4l2_ctrl *pixelrate; - struct v4l2_mbus_framefmt fmt[MAX9286_N_SINKS]; - /* Protects controls and fmt structures */ struct mutex mutex; @@ -758,18 +756,6 @@ static const struct v4l2_subdev_ops max9286_subdev_ops = { .pad = &max9286_pad_ops, }; -static void max9286_init_format(struct v4l2_mbus_framefmt *fmt) -{ - fmt->width = 1280; - fmt->height = 800; - fmt->code = MEDIA_BUS_FMT_UYVY8_1X16; - fmt->colorspace = V4L2_COLORSPACE_SRGB; - fmt->field = V4L2_FIELD_NONE; - fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; - fmt->quantization = V4L2_QUANTIZATION_DEFAULT; - fmt->xfer_func = V4L2_XFER_FUNC_DEFAULT; -} - static int max9286_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh) { struct max9286_priv *priv = sd_to_max9286(subdev); @@ -834,9 +820,6 @@ static int max9286_v4l2_register(struct max9286_priv *priv) /* Configure V4L2 for the MAX9286 itself */ - for (i = 0; i < MAX9286_N_SINKS; i++) - max9286_init_format(&priv->fmt[i]); - v4l2_i2c_subdev_init(&priv->sd, priv->client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;