@@ -1268,7 +1268,8 @@ static int imx477_set_ctrl(struct v4l2_ctrl *ctrl)
12681268 break ;
12691269 }
12701270
1271- pm_runtime_put (& client -> dev );
1271+ pm_runtime_mark_last_busy (& client -> dev );
1272+ pm_runtime_put_autosuspend (& client -> dev );
12721273
12731274 return ret ;
12741275}
@@ -1694,22 +1695,23 @@ static int imx477_set_stream(struct v4l2_subdev *sd, int enable)
16941695 }
16951696
16961697 if (enable ) {
1697- ret = pm_runtime_get_sync (& client -> dev );
1698- if (ret < 0 ) {
1699- pm_runtime_put_noidle (& client -> dev );
1698+ ret = pm_runtime_resume_and_get (& client -> dev );
1699+ if (ret < 0 )
17001700 goto err_unlock ;
1701- }
17021701
17031702 /*
17041703 * Apply default & customized values
17051704 * and then start streaming.
17061705 */
17071706 ret = imx477_start_streaming (imx477 );
1708- if (ret )
1709- goto err_rpm_put ;
1707+ if (ret ) {
1708+ pm_runtime_put_sync (& client -> dev );
1709+ goto err_unlock ;
1710+ }
17101711 } else {
17111712 imx477_stop_streaming (imx477 );
1712- pm_runtime_put (& client -> dev );
1713+ pm_runtime_mark_last_busy (& client -> dev );
1714+ pm_runtime_put_autosuspend (& client -> dev );
17131715 }
17141716
17151717 imx477 -> streaming = enable ;
@@ -1722,8 +1724,6 @@ static int imx477_set_stream(struct v4l2_subdev *sd, int enable)
17221724
17231725 return ret ;
17241726
1725- err_rpm_put :
1726- pm_runtime_put (& client -> dev );
17271727err_unlock :
17281728 mutex_unlock (& imx477 -> mutex );
17291729
@@ -2183,10 +2183,16 @@ static int imx477_probe(struct i2c_client *client)
21832183 /* Initialize default format */
21842184 imx477_set_default_format (imx477 );
21852185
2186- /* Enable runtime PM and turn off the device */
2186+ /*
2187+ * Enable runtime PM with 5s autosuspend. As the device has been powered
2188+ * manually, mark it as active, and increase the usage count without
2189+ * resuming the device.
2190+ */
21872191 pm_runtime_set_active (dev );
2192+ pm_runtime_get_noresume (dev );
21882193 pm_runtime_enable (dev );
2189- pm_runtime_idle (dev );
2194+ pm_runtime_set_autosuspend_delay (dev , 5000 );
2195+ pm_runtime_use_autosuspend (dev );
21902196
21912197 /* This needs the pm runtime to be registered. */
21922198 ret = imx477_init_controls (imx477 );
@@ -2215,6 +2221,9 @@ static int imx477_probe(struct i2c_client *client)
22152221 goto error_media_entity ;
22162222 }
22172223
2224+ pm_runtime_mark_last_busy (& client -> dev );
2225+ pm_runtime_put_autosuspend (& client -> dev );
2226+
22182227 return 0 ;
22192228
22202229error_media_entity :
@@ -2225,7 +2234,7 @@ static int imx477_probe(struct i2c_client *client)
22252234
22262235error_power_off :
22272236 pm_runtime_disable (& client -> dev );
2228- pm_runtime_set_suspended (& client -> dev );
2237+ pm_runtime_put_noidle (& client -> dev );
22292238 imx477_power_off (& client -> dev );
22302239
22312240 return ret ;
0 commit comments