Skip to content

Commit

Permalink
Add S3 interface for virtio camera
Browse files Browse the repository at this point in the history
The IPU have not suppoert the S3, so, the virito camera should enumlate
the S3 event for all FE & BE, this patch add S3 interface to emulate the
suspend and resume for virito camera frontend.

Test done:
Method 1 using cmd:
adb shell
cmd car_service suspend
acrnd -t -d 2  resume

Method 2 using button press:
suspend and resume using power button press

virtio camera could work after these step.

Tracked-On: OAM-128871
Signed-off-by: Chenli Wei <[email protected]>
  • Loading branch information
weichenli-intel authored and simonami99 committed Jan 2, 2025
1 parent dd0da2e commit 8ff22fe
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
63 changes: 63 additions & 0 deletions drivers/media/platform/virtio/virtio-camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,63 @@ static void virtio_camera_remove(struct virtio_device *vdev)
vdev->config->del_vqs(vdev);
}

#ifdef CONFIG_PM

int virtio_camera_freeze(struct virtio_device *dev) {
struct virtio_camera *vcam = dev->priv;
struct virtio_camera_video *vnode;
struct virtio_camera_ctrl_req *vcam_req;
int err;
int i;

for (i = 0; i < vcam->config.num_virtual_cameras; i++) {
vnode = &vcam->virtual_cameras[i].vnodes[0];
vnode->sequence = 0;
vcam_req = virtio_camera_create_req(VIRTIO_CAMERA_CMD_FREEZE);
if (unlikely(vcam_req == NULL)) {
pr_err("virtio-camera: vnode%d fail to init stream_on-req, no mem.\n",
vnode->idx);
return -ENOMEM;
}

err = vcam_vq_request(vnode, vcam_req, NULL, 0, false);
if (err)
pr_err("virtio-camera: vnode%d freeze failed, err response.\n",
vnode->idx);
kfree(vcam_req);
}
pr_err("virtio-camera: freeze for S3\n");
return err;
};

int virtio_camera_restore(struct virtio_device *dev) {
struct virtio_camera *vcam = dev->priv;
struct virtio_camera_video *vnode;
struct virtio_camera_ctrl_req *vcam_req;
int err;
int i;

for (i = 0; i < vcam->config.num_virtual_cameras; i++) {
vnode = &vcam->virtual_cameras[i].vnodes[0];
vnode->sequence = 0;
vcam_req = virtio_camera_create_req(VIRTIO_CAMERA_CMD_RESTORE);
if (unlikely(vcam_req == NULL)) {
pr_err("virtio-camera: vnode%d fail to init stream_on-req, no mem.\n",
vnode->idx);
return -ENOMEM;
}

err = vcam_vq_request(vnode, vcam_req, NULL, 0, false);
if (err)
pr_err("virtio-camera: vnode%d restore failed, err response.\n",
vnode->idx);
kfree(vcam_req);
}
pr_err("virtio-camera: restore for S3\n");
return err;
};
#endif

static const unsigned int features[] = {
/* none */
};
Expand All @@ -1078,8 +1135,14 @@ static struct virtio_driver virtio_camera_driver = {
.probe = virtio_camera_probe,
.remove = virtio_camera_remove,
.driver.name = "virtio-camera",

.id_table = id_table,
#ifdef CONFIG_PM
.freeze = virtio_camera_freeze,
.restore = virtio_camera_restore,
#endif
};

module_virtio_driver(virtio_camera_driver);

MODULE_AUTHOR("Dmitry Osipenko <[email protected]>");
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/linux/virtio_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum virtio_camera_ctrl_type {
VIRTIO_CAMERA_CMD_FILE_OPEN,
VIRTIO_CAMERA_CMD_FILE_CLOSE,
VIRTIO_CAMERA_CMD_ENUM_INTV,
VIRTIO_CAMERA_CMD_FREEZE,
VIRTIO_CAMERA_CMD_RESTORE,

VIRTIO_CAMERA_CMD_RESP_OK_NODATA = 0x100,

Expand Down

0 comments on commit 8ff22fe

Please sign in to comment.