Skip to content

Commit cb5e42b

Browse files
committed
media: i2c: imx500: release rpk on subdev close
The pm_runtime reference is held for as long as imx500->fw_network is populated. This means the cached rpk (plus the pm reference that blocks autosuspend) is present in the device state past userspace closing the subdev fd, until the next VIDIOC_S_CTRL cleared or replaced it. Add a .close internal op that calls imx500_clear_fw_network() when the last userspace handle on the subdev is released. Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent 95aec78 commit cb5e42b

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

drivers/media/i2c/imx500.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <media/v4l2-ctrls.h>
2323
#include <media/v4l2-device.h>
2424
#include <media/v4l2-event.h>
25+
#include <media/v4l2-fh.h>
2526
#include <media/v4l2-fwnode.h>
2627
#include <media/v4l2-mediabus.h>
2728

@@ -2331,6 +2332,26 @@ static const struct v4l2_ctrl_ops imx500_ctrl_ops = {
23312332
.s_ctrl = imx500_set_ctrl,
23322333
};
23332334

2335+
static int imx500_subdev_close(struct v4l2_subdev *sd,
2336+
struct v4l2_subdev_fh *fh)
2337+
{
2338+
struct imx500 *imx500 = to_imx500(sd);
2339+
/*
2340+
* Release the cached rpk when the last userspace handle on the subdev
2341+
* is closed. This also drops the pm_runtime reference ta taken in the
2342+
* NETWORK_FW_FD branch of imx500_set_ctrl(), so the device can
2343+
* autosuspend between sessions.
2344+
*/
2345+
if (v4l2_fh_is_singular(&fh->vfh))
2346+
imx500_clear_fw_network(imx500);
2347+
2348+
return 0;
2349+
}
2350+
2351+
static const struct v4l2_subdev_internal_ops imx500_internal_ops = {
2352+
.close = imx500_subdev_close,
2353+
};
2354+
23342355
static const struct v4l2_ctrl_config imx500_notify_gains_ctrl = {
23352356
.ops = &imx500_ctrl_ops,
23362357
.id = V4L2_CID_NOTIFY_GAINS,
@@ -3632,6 +3653,7 @@ static int imx500_probe(struct i2c_client *client)
36323653
goto error_power_off;
36333654

36343655
/* Initialize subdev */
3656+
imx500->sd.internal_ops = &imx500_internal_ops;
36353657
imx500->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
36363658
V4L2_SUBDEV_FL_HAS_EVENTS;
36373659
imx500->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;

0 commit comments

Comments
 (0)