Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: adv7180: Only validate format in querystd

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>

authored by

Niklas Söderlund and committed by
Hans Verkuil
91c5d7c8 df2cd073

+16 -21
+16 -21
drivers/media/i2c/adv7180.c
··· 388 388 static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) 389 389 { 390 390 struct adv7180_state *state = to_state(sd); 391 - int err = mutex_lock_interruptible(&state->mutex); 392 - if (err) 393 - return err; 391 + int ret; 394 392 395 - if (state->streaming) { 396 - err = -EBUSY; 397 - goto unlock; 398 - } 393 + guard(mutex)(&state->mutex); 399 394 400 - err = adv7180_set_video_standard(state, 401 - ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM); 402 - if (err) 403 - goto unlock; 395 + /* 396 + * We can't sample the standard if the device is streaming as that would 397 + * interfere with the capture session as the VID_SEL reg is touched. 398 + */ 399 + if (state->streaming) 400 + return -EBUSY; 404 401 402 + /* Set the standard to autodetect PAL B/G/H/I/D, NTSC J or SECAM */ 403 + ret = adv7180_set_video_standard(state, 404 + ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM); 405 + if (ret) 406 + return ret; 407 + 408 + /* Allow some time for the autodetection to run. */ 405 409 msleep(100); 406 - __adv7180_status(state, NULL, std); 407 410 408 - err = v4l2_std_to_adv7180(state->curr_norm); 409 - if (err < 0) 410 - goto unlock; 411 - 412 - err = adv7180_set_video_standard(state, err); 413 - 414 - unlock: 415 - mutex_unlock(&state->mutex); 416 - return err; 411 + return __adv7180_status(state, NULL, std); 417 412 } 418 413 419 414 static int adv7180_s_routing(struct v4l2_subdev *sd, u32 input,