]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: adv7180: Only validate format in querystd
authorNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Thu, 28 Aug 2025 16:06:54 +0000 (18:06 +0200)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Thu, 4 Sep 2025 08:06:13 +0000 (10:06 +0200)
The .querystd callback should not program the device with the detected
standard, it should only report the standard to user-space. User-space
may then use .s_std to set the standard, if it wants to use it.

All that is required of .querystd is to setup the auto detection of
standards and report its findings.

While at it add some documentation on why this can't happen while
streaming and improve the error handling using a scoped guard.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/i2c/adv7180.c

index 75d453ab169126520aa9931017f76893ef8da24f..378f4e6af12cbaed46408989c5aa9d8d9f8e6354 100644 (file)
@@ -388,32 +388,27 @@ static inline struct adv7180_state *to_state(struct v4l2_subdev *sd)
 static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
 {
        struct adv7180_state *state = to_state(sd);
-       int err = mutex_lock_interruptible(&state->mutex);
-       if (err)
-               return err;
-
-       if (state->streaming) {
-               err = -EBUSY;
-               goto unlock;
-       }
+       int ret;
 
-       err = adv7180_set_video_standard(state,
-                       ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM);
-       if (err)
-               goto unlock;
+       guard(mutex)(&state->mutex);
 
-       msleep(100);
-       __adv7180_status(state, NULL, std);
+       /*
+        * We can't sample the standard if the device is streaming as that would
+        * interfere with the capture session as the VID_SEL reg is touched.
+        */
+       if (state->streaming)
+               return -EBUSY;
 
-       err = v4l2_std_to_adv7180(state->curr_norm);
-       if (err < 0)
-               goto unlock;
+       /* Set the standard to autodetect PAL B/G/H/I/D, NTSC J or SECAM */
+       ret = adv7180_set_video_standard(state,
+                                        ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM);
+       if (ret)
+               return ret;
 
-       err = adv7180_set_video_standard(state, err);
+       /* Allow some time for the autodetection to run. */
+       msleep(100);
 
-unlock:
-       mutex_unlock(&state->mutex);
-       return err;
+       return __adv7180_status(state, NULL, std);
 }
 
 static int adv7180_s_routing(struct v4l2_subdev *sd, u32 input,