Skip to content

Commit c7bef75

Browse files
jailuthrapelwell
authored andcommitted
media: imx335: Handle runtime PM in leaf functions
commit 34af620 upstream. Simplify .s_stream callback implementation by moving the runtime PM calls to the leaf functions. This patch should not affect any functionality. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jai Luthra <jai.luthra@ideasonboard.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
1 parent e7e3b59 commit c7bef75

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

drivers/media/i2c/imx335.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -919,13 +919,17 @@ static int imx335_start_streaming(struct imx335 *imx335)
919919
const struct imx335_reg_list *reg_list;
920920
int ret;
921921

922+
ret = pm_runtime_resume_and_get(imx335->dev);
923+
if (ret < 0)
924+
return ret;
925+
922926
/* Setup PLL */
923927
reg_list = &link_freq_reglist[__ffs(imx335->link_freq_bitmap)];
924928
ret = cci_multi_reg_write(imx335->cci, reg_list->regs,
925929
reg_list->num_of_regs, NULL);
926930
if (ret) {
927931
dev_err(imx335->dev, "%s failed to set plls\n", __func__);
928-
return ret;
932+
goto err_rpm_put;
929933
}
930934

931935
/* Write sensor mode registers */
@@ -934,53 +938,57 @@ static int imx335_start_streaming(struct imx335 *imx335)
934938
reg_list->num_of_regs, NULL);
935939
if (ret) {
936940
dev_err(imx335->dev, "fail to write initial registers\n");
937-
return ret;
941+
goto err_rpm_put;
938942
}
939943

940944
ret = imx335_set_framefmt(imx335);
941945
if (ret) {
942946
dev_err(imx335->dev, "%s failed to set frame format: %d\n",
943947
__func__, ret);
944-
return ret;
948+
goto err_rpm_put;
945949
}
946950

947951
/* Configure lanes */
948952
ret = cci_write(imx335->cci, IMX335_REG_LANEMODE,
949953
imx335->lane_mode, NULL);
950954
if (ret)
951-
return ret;
955+
goto err_rpm_put;
952956

953957
/* Setup handler will write actual exposure and gain */
954958
ret = __v4l2_ctrl_handler_setup(imx335->sd.ctrl_handler);
955959
if (ret) {
956960
dev_err(imx335->dev, "fail to setup handler\n");
957-
return ret;
961+
goto err_rpm_put;
958962
}
959963

960964
/* Start streaming */
961965
ret = cci_write(imx335->cci, IMX335_REG_MODE_SELECT,
962966
IMX335_MODE_STREAMING, NULL);
963967
if (ret) {
964968
dev_err(imx335->dev, "fail to start streaming\n");
965-
return ret;
969+
goto err_rpm_put;
966970
}
967971

968972
/* Initial regulator stabilization period */
969973
usleep_range(18000, 20000);
970974

971975
return 0;
976+
977+
err_rpm_put:
978+
pm_runtime_put(imx335->dev);
979+
980+
return ret;
972981
}
973982

974983
/**
975984
* imx335_stop_streaming() - Stop sensor stream
976985
* @imx335: pointer to imx335 device
977-
*
978-
* Return: 0 if successful, error code otherwise.
979986
*/
980-
static int imx335_stop_streaming(struct imx335 *imx335)
987+
static void imx335_stop_streaming(struct imx335 *imx335)
981988
{
982-
return cci_write(imx335->cci, IMX335_REG_MODE_SELECT,
983-
IMX335_MODE_STANDBY, NULL);
989+
cci_write(imx335->cci, IMX335_REG_MODE_SELECT,
990+
IMX335_MODE_STANDBY, NULL);
991+
pm_runtime_put(imx335->dev);
984992
}
985993

986994
/**
@@ -993,30 +1001,15 @@ static int imx335_stop_streaming(struct imx335 *imx335)
9931001
static int imx335_set_stream(struct v4l2_subdev *sd, int enable)
9941002
{
9951003
struct imx335 *imx335 = to_imx335(sd);
996-
int ret;
1004+
int ret = 0;
9971005

9981006
mutex_lock(&imx335->mutex);
9991007

1000-
if (enable) {
1001-
ret = pm_runtime_resume_and_get(imx335->dev);
1002-
if (ret)
1003-
goto error_unlock;
1004-
1008+
if (enable)
10051009
ret = imx335_start_streaming(imx335);
1006-
if (ret)
1007-
goto error_power_off;
1008-
} else {
1010+
else
10091011
imx335_stop_streaming(imx335);
1010-
pm_runtime_put(imx335->dev);
1011-
}
1012-
1013-
mutex_unlock(&imx335->mutex);
10141012

1015-
return 0;
1016-
1017-
error_power_off:
1018-
pm_runtime_put(imx335->dev);
1019-
error_unlock:
10201013
mutex_unlock(&imx335->mutex);
10211014

10221015
return ret;

0 commit comments

Comments
 (0)