]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
[media] via-camera: Add suspend/resume support
authorDaniel Drake <dsd@laptop.org>
Fri, 11 Feb 2011 21:15:02 +0000 (18:15 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 21 Mar 2011 23:32:37 +0000 (20:32 -0300)
Add suspend/resume support to the via-camera driver, so that the video
continues streaming over a suspend-resume cycle.

Originally implemented by Jon Corbet.

[mchehab@redhat.com: fix a small CodingStyle issue]
Signed-off-by: Daniel Drake <dsd@laptop.org>
Acked-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/via-camera.c

index 2f973cd5640869c9c62bc0d7b2885ae12b8f0b19..3f0146fcf752a84c5197832226521c83e6bb1b3c 100644 (file)
@@ -1246,6 +1246,62 @@ static const struct v4l2_ioctl_ops viacam_ioctl_ops = {
 /*
  * Power management.
  */
+#ifdef CONFIG_PM
+
+static int viacam_suspend(void *priv)
+{
+       struct via_camera *cam = priv;
+       enum viacam_opstate state = cam->opstate;
+
+       if (cam->opstate != S_IDLE) {
+               viacam_stop_engine(cam);
+               cam->opstate = state; /* So resume restarts */
+       }
+
+       return 0;
+}
+
+static int viacam_resume(void *priv)
+{
+       struct via_camera *cam = priv;
+       int ret = 0;
+
+       /*
+        * Get back to a reasonable operating state.
+        */
+       via_write_reg_mask(VIASR, 0x78, 0, 0x80);
+       via_write_reg_mask(VIASR, 0x1e, 0xc0, 0xc0);
+       viacam_int_disable(cam);
+       set_bit(CF_CONFIG_NEEDED, &cam->flags);
+       /*
+        * Make sure the sensor's power state is correct
+        */
+       if (cam->users > 0)
+               via_sensor_power_up(cam);
+       else
+               via_sensor_power_down(cam);
+       /*
+        * If it was operating, try to restart it.
+        */
+       if (cam->opstate != S_IDLE) {
+               mutex_lock(&cam->lock);
+               ret = viacam_configure_sensor(cam);
+               if (!ret)
+                       ret = viacam_config_controller(cam);
+               mutex_unlock(&cam->lock);
+               if (!ret)
+                       viacam_start_engine(cam);
+       }
+
+       return ret;
+}
+
+static struct viafb_pm_hooks viacam_pm_hooks = {
+       .suspend = viacam_suspend,
+       .resume = viacam_resume
+};
+
+#endif /* CONFIG_PM */
 
 /*
  * Setup stuff.
@@ -1369,6 +1425,14 @@ static __devinit int viacam_probe(struct platform_device *pdev)
                goto out_irq;
        video_set_drvdata(&cam->vdev, cam);
 
+#ifdef CONFIG_PM
+       /*
+        * Hook into PM events
+        */
+       viacam_pm_hooks.private = cam;
+       viafb_pm_register(&viacam_pm_hooks);
+#endif
+
        /* Power the sensor down until somebody opens the device */
        via_sensor_power_down(cam);
        return 0;