From patchwork Fri Feb 11 21:15:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Drake X-Patchwork-Id: 550901 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1BLkWgi029103 for ; Fri, 11 Feb 2011 21:46:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758085Ab1BKVqa (ORCPT ); Fri, 11 Feb 2011 16:46:30 -0500 Received: from queueout02-winn.ispmail.ntl.com ([81.103.221.56]:44959 "EHLO queueout02-winn.ispmail.ntl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758012Ab1BKVq3 (ORCPT ); Fri, 11 Feb 2011 16:46:29 -0500 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20110211211505.PCBF26766.mtaout01-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com>; Fri, 11 Feb 2011 21:15:05 +0000 Received: from zog.reactivated.net ([86.14.215.141]) by aamtaout03-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20110211211505.BRPA28282.aamtaout03-winn.ispmail.ntl.com@zog.reactivated.net>; Fri, 11 Feb 2011 21:15:05 +0000 Received: by zog.reactivated.net (Postfix, from userid 1000) id D6D8E9D401D; Fri, 11 Feb 2011 21:15:02 +0000 (GMT) From: Daniel Drake To: mchehab@infradead.org Cc: linux-media@vger.kernel.org Cc: corbet@lwn.net Cc: dilinger@queued.net Subject: [PATCH] via-camera: Add suspend/resume support Message-Id: <20110211211502.D6D8E9D401D@zog.reactivated.net> Date: Fri, 11 Feb 2011 21:15:02 +0000 (GMT) X-Cloudmark-Analysis: v=1.1 cv=JvdXmxIgLJv2/GthKqHpGJEEHukvLcvELVXUanXFreg= c=1 sm=0 a=mgRYuABsyjsA:10 a=Op-mwl0xAAAA:8 a=ZTSgvQBVZW6deWXW-WQA:9 a=cfmwf9Xd6eb3u-reJjAA:7 a=4aTnkxe-t2TjiOdc780z0BTwK_oA:4 a=d4CUUju0HPYA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 11 Feb 2011 21:46:34 +0000 (UTC) diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c index 2f973cd..f307e5f 100644 --- a/drivers/media/video/via-camera.c +++ b/drivers/media/video/via-camera.c @@ -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;