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

media: i2c: imx415: Replace streaming flag with runtime PM check

The streaming flag in the driver private structure is used for the sole
purpose of gating register writes when setting a V4L2 control. This is
better handled by checking if the sensor is powered up using the runtime
PM API. Do so and drop the streaming flag.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Sakari Ailus: Runtime PM put when setting analgue gain.]
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Laurent Pinchart and committed by
Hans Verkuil
b2b5905a 165457e6

+16 -18
+16 -18
drivers/media/i2c/imx415.c
··· 353 353 354 354 const struct imx415_clk_params *clk_params; 355 355 356 - bool streaming; 357 - 358 356 struct v4l2_subdev subdev; 359 357 struct media_pad pad; 360 358 ··· 540 542 struct v4l2_subdev_state *state; 541 543 unsigned int vmax; 542 544 unsigned int flip; 545 + int ret; 543 546 544 - if (!sensor->streaming) 547 + if (!pm_runtime_get_if_in_use(sensor->dev)) 545 548 return 0; 546 549 547 550 state = v4l2_subdev_get_locked_active_state(&sensor->subdev); ··· 553 554 /* clamp the exposure value to VMAX. */ 554 555 vmax = format->height + sensor->vblank->cur.val; 555 556 ctrl->val = min_t(int, ctrl->val, vmax); 556 - return imx415_write(sensor, IMX415_SHR0, vmax - ctrl->val); 557 + ret = imx415_write(sensor, IMX415_SHR0, vmax - ctrl->val); 558 + break; 557 559 558 560 case V4L2_CID_ANALOGUE_GAIN: 559 561 /* analogue gain in 0.3 dB step size */ 560 - return imx415_write(sensor, IMX415_GAIN_PCG_0, ctrl->val); 562 + ret = imx415_write(sensor, IMX415_GAIN_PCG_0, ctrl->val); 563 + break; 561 564 562 565 case V4L2_CID_HFLIP: 563 566 case V4L2_CID_VFLIP: 564 567 flip = (sensor->hflip->val << IMX415_HREVERSE_SHIFT) | 565 568 (sensor->vflip->val << IMX415_VREVERSE_SHIFT); 566 - return imx415_write(sensor, IMX415_REVERSE, flip); 569 + ret = imx415_write(sensor, IMX415_REVERSE, flip); 570 + break; 567 571 568 572 case V4L2_CID_TEST_PATTERN: 569 - return imx415_set_testpattern(sensor, ctrl->val); 573 + ret = imx415_set_testpattern(sensor, ctrl->val); 574 + break; 570 575 571 576 default: 572 - return -EINVAL; 577 + ret = -EINVAL; 578 + break; 573 579 } 580 + 581 + pm_runtime_put(sensor->dev); 582 + 583 + return ret; 574 584 } 575 585 576 586 static const struct v4l2_ctrl_ops imx415_ctrl_ops = { ··· 774 766 pm_runtime_mark_last_busy(sensor->dev); 775 767 pm_runtime_put_autosuspend(sensor->dev); 776 768 777 - sensor->streaming = false; 778 - 779 769 goto unlock; 780 770 } 781 771 ··· 784 778 ret = imx415_setup(sensor, state); 785 779 if (ret) 786 780 goto err_pm; 787 - 788 - /* 789 - * Set streaming to true to ensure __v4l2_ctrl_handler_setup() will set 790 - * the controls. The flag is reset to false further down if an error 791 - * occurs. 792 - */ 793 - sensor->streaming = true; 794 781 795 782 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls); 796 783 if (ret < 0) ··· 806 807 * likely has no other chance to recover. 807 808 */ 808 809 pm_runtime_put_sync(sensor->dev); 809 - sensor->streaming = false; 810 810 811 811 goto unlock; 812 812 }