From nobody Wed Aug 26 17:02:21 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50DBF3D9695 for ; Wed, 8 Jul 2026 14:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783522177; cv=none; b=S25apL8GifbpHJ/XEyhUxpaiD1BjWKRvb6jqT7ZvWPpI0sdDCV+O4Rx9MqF4vLKU+YOe494asH07n6IJ4VS2QO/gpRrKHSHUqJpTn/vVzil92wJ2bwGcVF9FRKGYLHKOVuqlCLOSgrpc6qeTClZUPfvWZT7TQ3+t1wEkWFL3YnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783522177; c=relaxed/simple; bh=Bz7eJTYlg7hqzpgB6a7cBQj2bdP5kz+HsAA3ZbNHcBo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i32SoQqt3fUBXmzBSbISEYzwMQTWKpv40FWjQv3bI8GJPA5ESFEVOGISJVT4gufyRur2YZ/EmblCu01F9I2p7XY6FFRHcDF3cnYRoAZWVamfMc4Qi3K/pUVbaRI0yGZ8gpN7dmUFZJTmhXZxPy20WysXfa3OTOwO0N8FjVBi4Nw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=S3WrMUSs; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="S3WrMUSs" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-493bb510ce4so5404765e9.1 for ; Wed, 08 Jul 2026 07:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1783522164; x=1784126964; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xu15ctzjcOqhJZV80dUKUk3i6OKtSm5BmBQWERl2TsU=; b=S3WrMUSsr6NF7NSraftk3R3Sb2pCyRBCHoFARhJVHZ4heQgY0XNg7e1JXs8ArhLae/ CT4W/kfy/IlkJjmjTpWGSQZTsV3+2xNCG7pHm5KbdIZmN7W9cLXk47okdzFpDADgi0Jl sIb9KAGnyeyrcuVkOVAWAtn3XSsQCcoRq6Rc2k5VzGDUxYCsGleZ58MZwvFOdlAUZnRk e6QBkAvVogl+tNV2KECu6aUfVuD+7IqpowYJROgS6/nwxQVHVdNdCkmo0bcsx0z8DYF2 1K+vWvF3jJ8UV7C6vaNv05/Pd9fe2r8pw5fXzlN07DLil/J2U25FepqbtoUuXs3dXTj4 NNFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783522164; x=1784126964; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xu15ctzjcOqhJZV80dUKUk3i6OKtSm5BmBQWERl2TsU=; b=Ux0ofoD8wbmUer7XqCBRtFTh2ZqSm7Qy9CRyHr3wjOrGtxw2lEjZq301RyUdrSWht+ GNuv2udK6xrGRP9TDNT1k73EOt72SEE68tWTKeEnOeF/IISB1CSH1ppldFam4SPoG1TB 5LXrIj54vX/Ker62FW1ExfIinfmgVzR3Jq8wLXnDnVKQPgE3MqwrwsTookhyNtgt1Qwe H66BcEZsywo3qwdYNcyBhOjA6B4Fg/xdIvcTawwjcCrgiQV9b0u8v1FNw/SjwxpBs3SS Ieq89pF/t4PDO1jgaNkjkNKwxSOpKRqjCv9QfK3XGHvW5wAa/sX5/bYBs9WWOMK7EuYm 710g== X-Forwarded-Encrypted: i=1; AHgh+RpZ8JvE9TNJT0gKUV8vlh8d3cjB+CrHNF1x5ECW+yfDzvZ8824kEbyQwNxQ8AYsNh31x16dwm8AgSc1bWc=@vger.kernel.org X-Gm-Message-State: AOJu0YwZ9iqKbY3rhAICbHOswo8YrxJaY70XlKf+vY0/mkWGP6UKJnKX Ysr9Cv0OXIlgvqw/a3MRJx6Uzi7FgXsO0Q+Y/Wk4pw7lDdYvHJHOWSWHrX9oGk0mu9M= X-Gm-Gg: AfdE7cnHqMYkOVTgfhg6gooavaajuZG0SXL22IZl1ynT9Gj6L0P+2biugD0t8/n9lEp vtwWQ+ou89WvbXoovygbP97E69Rv2vcw56/t9ZCs7nhdxAHhfxGJMDiKhrfDVrZ4ewv2VQM64K/ B+3fT1WnLLdxIcVr0Y3yH4i8pW2yc1e3e/vGDz+9viqcywvapGvPvaL/y13Z0flfdo7LKLpAggf 88aeYJM1BTqdebH966OaJIh2lFfLYyR2B37jB6GFPffAMVRuS37OHXuE4j66aPS/HdCP4A+Vdkq qyP+mR/6yVEb+qFRwBjtOXvyZhJEbBN6a79W00lmepmZWA6htc0ExiZQPLB8mDNcV8amGPqnonQ D6VAsVmjRPlbUCHXUr3HbyUH3xEfR8gPwyV3OXQSFcADJyKkrNWmJH088TI/bJu7XjM+xioArSb 8EFbYemMq5d3oUmRXWqUaIjN7z4uZUaKRN0pAjP6s3Thikf94oW9Ax/uu6T7ohYfpx X-Received: by 2002:a05:600c:4505:b0:493:bfea:2780 with SMTP id 5b1f17b1804b1-493e68b83aemr31299685e9.9.1783522164323; Wed, 08 Jul 2026 07:49:24 -0700 (PDT) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-493e0fbd355sm135363315e9.13.2026.07.08.07.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 07:49:23 -0700 (PDT) From: Dave Stevenson Date: Wed, 08 Jul 2026 15:48:55 +0100 Subject: [PATCH v3 19/20] media: imx355: Switch to using the subdev state Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260708-media-imx355-v3-19-9df386a623d7@raspberrypi.com> References: <20260708-media-imx355-v3-0-9df386a623d7@raspberrypi.com> In-Reply-To: <20260708-media-imx355-v3-0-9df386a623d7@raspberrypi.com> To: Sakari Ailus , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Richard Acayan Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, David Heidelberg , Jacopo Mondi , devicetree@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 The subdev state is now preferred rather than handling crop and format within the driver state, so switch the driver to using it. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx355.c | 180 +++++++++++++----------------------------= ---- 1 file changed, 50 insertions(+), 130 deletions(-) diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c index 2be665b5b453..ee012efe25bf 100644 --- a/drivers/media/i2c/imx355.c +++ b/drivers/media/i2c/imx355.c @@ -179,13 +179,6 @@ struct imx355 { struct imx355_hwcfg *hwcfg; const struct imx355_clk_params *clk_params; =20 - /* - * Mutex for serialized access: - * Protect sensor set pad format and start/stop streaming safely. - * Protect access to sensor v4l2 controls. - */ - struct mutex mutex; - struct gpio_desc *reset_gpio; struct regulator_bulk_data *supplies; }; @@ -593,46 +586,23 @@ static u32 imx355_get_format_code(struct imx355 *imx3= 55) { MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SBGGR10_1X10, }, }; =20 - lockdep_assert_held(&imx355->mutex); code =3D codes[imx355->vflip->val][imx355->hflip->val]; =20 return code; } =20 -/* Open sub-device */ -static int imx355_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) -{ - struct imx355 *imx355 =3D to_imx355(sd); - struct v4l2_mbus_framefmt *try_fmt =3D - v4l2_subdev_state_get_format(fh->state, 0); - struct v4l2_rect *crop =3D v4l2_subdev_state_get_crop(fh->state, 0); - - mutex_lock(&imx355->mutex); - - /* Initialize try_fmt */ - try_fmt->width =3D imx355->cur_mode->width; - try_fmt->height =3D imx355->cur_mode->height; - try_fmt->code =3D imx355_get_format_code(imx355); - try_fmt->field =3D V4L2_FIELD_NONE; - try_fmt->format.colorspace =3D V4L2_COLORSPACE_RAW; - try_fmt->format.ycbcr_enc =3D V4L2_YCBCR_ENC_601; - try_fmt->format.quantization =3D V4L2_QUANTIZATION_FULL_RANGE; - try_fmt->format.xfer_func =3D V4L2_XFER_FUNC_NONE; - - *crop =3D imx355->cur_mode->crop; - - mutex_unlock(&imx355->mutex); - - return 0; -} - static int imx355_set_ctrl(struct v4l2_ctrl *ctrl) { struct imx355 *imx355 =3D container_of(ctrl->handler, struct imx355, ctrl_handler); + const struct v4l2_mbus_framefmt *format =3D NULL; + struct v4l2_subdev_state *state; s64 max; int ret; =20 + state =3D v4l2_subdev_get_locked_active_state(&imx355->sd); + format =3D v4l2_subdev_state_get_format(state, 0); + /* Propagate change of current control to all related controls */ switch (ctrl->id) { case V4L2_CID_VBLANK: @@ -705,9 +675,7 @@ static int imx355_enum_mbus_code(struct v4l2_subdev *sd, if (code->index > 0) return -EINVAL; =20 - mutex_lock(&imx355->mutex); code->code =3D imx355_get_format_code(imx355); - mutex_unlock(&imx355->mutex); =20 return 0; } @@ -721,12 +689,9 @@ static int imx355_enum_frame_size(struct v4l2_subdev *= sd, if (fse->index >=3D ARRAY_SIZE(supported_modes)) return -EINVAL; =20 - mutex_lock(&imx355->mutex); if (fse->code !=3D imx355_get_format_code(imx355)) { - mutex_unlock(&imx355->mutex); return -EINVAL; } - mutex_unlock(&imx355->mutex); =20 fse->min_width =3D supported_modes[fse->index].width; fse->max_width =3D fse->min_width; @@ -750,36 +715,6 @@ static void imx355_update_pad_format(struct imx355 *im= x355, fmt->format.xfer_func =3D V4L2_XFER_FUNC_NONE; } =20 -static int imx355_do_get_pad_format(struct imx355 *imx355, - struct v4l2_subdev_state *sd_state, - struct v4l2_subdev_format *fmt) -{ - struct v4l2_mbus_framefmt *framefmt; - - if (fmt->which =3D=3D V4L2_SUBDEV_FORMAT_TRY) { - framefmt =3D v4l2_subdev_state_get_format(sd_state, fmt->pad); - fmt->format =3D *framefmt; - } else { - imx355_update_pad_format(imx355, imx355->cur_mode, fmt); - } - - return 0; -} - -static int imx355_get_pad_format(struct v4l2_subdev *sd, - struct v4l2_subdev_state *sd_state, - struct v4l2_subdev_format *fmt) -{ - struct imx355 *imx355 =3D to_imx355(sd); - int ret; - - mutex_lock(&imx355->mutex); - ret =3D imx355_do_get_pad_format(imx355, sd_state, fmt); - mutex_unlock(&imx355->mutex); - - return ret; -} - static int imx355_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, @@ -788,12 +723,11 @@ imx355_set_pad_format(struct v4l2_subdev *sd, struct imx355 *imx355 =3D to_imx355(sd); const struct imx355_mode *mode; struct v4l2_mbus_framefmt *framefmt; + struct v4l2_rect *crop; s32 vblank_def; s64 h_blank; u32 height; =20 - mutex_lock(&imx355->mutex); - /* * Only one bayer order is supported. * It depends on the flip settings. @@ -805,16 +739,17 @@ imx355_set_pad_format(struct v4l2_subdev *sd, width, height, fmt->format.width, fmt->format.height); imx355_update_pad_format(imx355, mode, fmt); - if (fmt->which =3D=3D V4L2_SUBDEV_FORMAT_TRY) { - framefmt =3D v4l2_subdev_state_get_format(sd_state, fmt->pad); - *framefmt =3D fmt->format; - - crop =3D v4l2_subdev_state_get_crop(sd_state, 0); - crop->width =3D mode->crop.width; - crop->height =3D mode->crop.height; - crop->left =3D mode->crop.left; - crop->top =3D mode->crop.top; - } else { + framefmt =3D v4l2_subdev_state_get_format(sd_state, 0); + + *framefmt =3D fmt->format; + + crop =3D v4l2_subdev_state_get_crop(sd_state, 0); + crop->width =3D mode->crop.width; + crop->height =3D mode->crop.height; + crop->left =3D mode->crop.left; + crop->top =3D mode->crop.top; + + if (fmt->which =3D=3D V4L2_SUBDEV_FORMAT_ACTIVE) { imx355->cur_mode =3D mode; /* Update limits and set FPS to default */ height =3D imx355->cur_mode->height; @@ -833,41 +768,17 @@ imx355_set_pad_format(struct v4l2_subdev *sd, h_blank, 1, h_blank); } =20 - mutex_unlock(&imx355->mutex); - return 0; } =20 -static void -__imx355_get_pad_crop(struct imx355 *imx355, - struct v4l2_subdev_state *sd_state, unsigned int pad, - enum v4l2_subdev_format_whence which, struct v4l2_rect *r) -{ - switch (which) { - case V4L2_SUBDEV_FORMAT_TRY: - *r =3D *v4l2_subdev_state_get_crop(sd_state, pad); - break; - case V4L2_SUBDEV_FORMAT_ACTIVE: - *r =3D imx355->cur_mode->crop; - break; - } -} - static int imx355_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_selection *sel) { switch (sel->target) { - case V4L2_SEL_TGT_CROP: { - struct imx355 *imx355 =3D to_imx355(sd); - - mutex_lock(&imx355->mutex); - __imx355_get_pad_crop(imx355, sd_state, sel->pad, sel->which, - &sel->r); - mutex_unlock(&imx355->mutex); - + case V4L2_SEL_TGT_CROP: + sel->r =3D *v4l2_subdev_state_get_crop(sd_state, 0); return 0; - } case V4L2_SEL_TGT_CROP_DEFAULT: case V4L2_SEL_TGT_CROP_BOUNDS: case V4L2_SEL_TGT_NATIVE_SIZE: @@ -882,6 +793,21 @@ static int imx355_get_selection(struct v4l2_subdev *sd, return -EINVAL; } =20 +static int imx355_entity_init_state(struct v4l2_subdev *subdev, + struct v4l2_subdev_state *sd_state) +{ + struct v4l2_subdev_format fmt =3D { }; + + fmt.which =3D sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTI= VE; + fmt.format.code =3D MEDIA_BUS_FMT_SRGGB10_1X10; + fmt.format.width =3D supported_modes[0].width; + fmt.format.height =3D supported_modes[0].height; + + imx355_set_pad_format(subdev, sd_state, &fmt); + + return 0; +} + /* Start streaming */ static int imx355_start_streaming(struct imx355 *imx355) { @@ -969,12 +895,10 @@ static int imx355_set_stream(struct v4l2_subdev *sd, = int enable) struct imx355 *imx355 =3D to_imx355(sd); int ret =3D 0; =20 - mutex_lock(&imx355->mutex); - if (enable) { ret =3D pm_runtime_resume_and_get(imx355->dev); if (ret < 0) - goto err_unlock; + return ret; =20 /* * Apply default & customized values @@ -992,14 +916,10 @@ static int imx355_set_stream(struct v4l2_subdev *sd, = int enable) __v4l2_ctrl_grab(imx355->vflip, enable); __v4l2_ctrl_grab(imx355->hflip, enable); =20 - mutex_unlock(&imx355->mutex); - return ret; =20 err_rpm_put: pm_runtime_put_autosuspend(imx355->dev); -err_unlock: - mutex_unlock(&imx355->mutex); =20 return ret; } @@ -1033,7 +953,7 @@ static const struct v4l2_subdev_video_ops imx355_video= _ops =3D { =20 static const struct v4l2_subdev_pad_ops imx355_pad_ops =3D { .enum_mbus_code =3D imx355_enum_mbus_code, - .get_fmt =3D imx355_get_pad_format, + .get_fmt =3D v4l2_subdev_get_fmt, .set_fmt =3D imx355_set_pad_format, .enum_frame_size =3D imx355_enum_frame_size, .get_selection =3D imx355_get_selection, @@ -1050,7 +970,7 @@ static const struct media_entity_operations imx355_sub= dev_entity_ops =3D { }; =20 static const struct v4l2_subdev_internal_ops imx355_internal_ops =3D { - .open =3D imx355_open, + .init_state =3D imx355_entity_init_state, }; =20 static int imx355_power_off(struct device *dev) @@ -1116,7 +1036,6 @@ static int imx355_init_controls(struct imx355 *imx355) if (ret) return ret; =20 - ctrl_hdlr->lock =3D &imx355->mutex; imx355->link_freq =3D v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx355_ctrl_ops, V4L2_CID_LINK_FREQ, 0, 0, &imx355->hwcfg->link_freq_menu); @@ -1265,8 +1184,6 @@ static int imx355_probe(struct i2c_client *client) =20 imx355->dev =3D &client->dev; =20 - mutex_init(&imx355->mutex); - imx355->regmap =3D devm_cci_regmap_init_i2c(client, 16); if (IS_ERR(imx355->regmap)) return dev_err_probe(imx355->dev, PTR_ERR(imx355->regmap), @@ -1295,7 +1212,7 @@ static int imx355_probe(struct i2c_client *client) &imx355->supplies); if (ret) { dev_err_probe(imx355->dev, ret, "could not get regulators"); - goto error_probe; + return ret; } =20 imx355->reset_gpio =3D devm_gpiod_get_optional(imx355->dev, "reset", @@ -1303,7 +1220,7 @@ static int imx355_probe(struct i2c_client *client) if (IS_ERR(imx355->reset_gpio)) { ret =3D dev_err_probe(imx355->dev, PTR_ERR(imx355->reset_gpio), "failed to get gpios"); - goto error_probe; + return ret; } =20 /* Initialize subdev */ @@ -1312,13 +1229,12 @@ static int imx355_probe(struct i2c_client *client) imx355->hwcfg =3D imx355_get_hwcfg(imx355); if (!imx355->hwcfg) { dev_err(imx355->dev, "failed to get hwcfg"); - ret =3D -ENODEV; - goto error_probe; + return -ENODEV; } =20 ret =3D imx355_power_on(imx355->dev); if (ret) - goto error_probe; + return ret; =20 /* Check module identity */ ret =3D imx355_identify_module(imx355); @@ -1351,6 +1267,13 @@ static int imx355_probe(struct i2c_client *client) goto error_handler_free; } =20 + imx355->sd.state_lock =3D imx355->ctrl_handler.lock; + ret =3D v4l2_subdev_init_finalize(&imx355->sd); + if (ret < 0) { + dev_err_probe(imx355->dev, ret, "subdev init error\n"); + goto error_handler_free; + } + /* * Device is already turned on by i2c-core with ACPI domain PM. * Enable runtime PM and turn off the device. @@ -1371,6 +1294,7 @@ static int imx355_probe(struct i2c_client *client) pm_runtime_disable(imx355->dev); pm_runtime_set_suspended(imx355->dev); pm_runtime_dont_use_autosuspend(imx355->dev); + v4l2_subdev_cleanup(&imx355->sd); media_entity_cleanup(&imx355->sd.entity); =20 error_handler_free: @@ -1379,9 +1303,6 @@ static int imx355_probe(struct i2c_client *client) error_power_off: imx355_power_off(imx355->dev); =20 -error_probe: - mutex_destroy(&imx355->mutex); - return ret; } =20 @@ -1391,6 +1312,7 @@ static void imx355_remove(struct i2c_client *client) struct imx355 *imx355 =3D to_imx355(sd); =20 v4l2_async_unregister_subdev(sd); + v4l2_subdev_cleanup(sd); media_entity_cleanup(&sd->entity); v4l2_ctrl_handler_free(sd->ctrl_handler); =20 @@ -1402,8 +1324,6 @@ static void imx355_remove(struct i2c_client *client) } =20 pm_runtime_dont_use_autosuspend(imx355->dev); - - mutex_destroy(&imx355->mutex); } =20 static const struct acpi_device_id imx355_acpi_ids[] __maybe_unused =3D { --=20 2.34.1