From patchwork Fri Jul 31 14:02:37 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 38515 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6VE6s5F008192 for ; Fri, 31 Jul 2009 14:06:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751730AbZGaOGw (ORCPT ); Fri, 31 Jul 2009 10:06:52 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751807AbZGaOGw (ORCPT ); Fri, 31 Jul 2009 10:06:52 -0400 Received: from ey-out-2122.google.com ([74.125.78.25]:13440 "EHLO ey-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751730AbZGaOGv (ORCPT ); Fri, 31 Jul 2009 10:06:51 -0400 Received: by ey-out-2122.google.com with SMTP id 9so570195eyd.37 for ; Fri, 31 Jul 2009 07:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:date:message-id :in-reply-to:references:subject; bh=vzIHr5OvOiehNjAwvrdRPLHSZ/JiDnK16o649iaaBTM=; b=fhEOi7J0MTfpO6xiAdhGifB6VBUvH9ys5XR+EuMmeuw6aPvO9lmlL/qMX4PPWqivr3 iXJ2S3Vl3wao6A18Qd7RDCj8ChYDMfsgTBPpgPhXPXvToSNqesdB6vxwpLIDq1/E+2wv BLwmw44YJtaZpNtJIsNniaiLJ+KPMqsUQ+tuI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:date:message-id:in-reply-to:references:subject; b=FL0iecqMCQ4TvvA1+fZywZ5yXIGpPbfQV83jHODTz3MzUY6nTKi6kMvmn5TWgeGFh0 nGOmbm+CLHFLI9GnVt2WfZCrGoOKwP7pFOLu2N+xo0omn1IsDAP9lkUaHs+r5tOyvC4y jd2cwLq6tkg08NsX6WCf9r1cCaB7JetyyL3Ws= Received: by 10.216.20.197 with SMTP id p47mr532243wep.13.1249049212056; Fri, 31 Jul 2009 07:06:52 -0700 (PDT) Received: from rx1.opensource.se (210-225-125-011.jp.fiberphone.net [210.225.125.11]) by mx.google.com with ESMTPS id 7sm4193565eyg.15.2009.07.31.07.06.46 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 31 Jul 2009 07:06:49 -0700 (PDT) From: Magnus Damm To: linux-pm@lists.linux-foundation.org Cc: linux-sh@vger.kernel.org, gregkh@suse.de, rjw@sisk.pl, lethal@linux-sh.org, stern@rowland.harvard.edu, pavel@ucw.cz, Magnus Damm Date: Fri, 31 Jul 2009 23:02:37 +0900 Message-Id: <20090731140237.11351.48881.sendpatchset@rx1.opensource.se> In-Reply-To: <20090731140158.11351.26021.sendpatchset@rx1.opensource.se> References: <20090731140158.11351.26021.sendpatchset@rx1.opensource.se> Subject: [PATCH 03/04] uio: Runtime PM changes for UIO driver Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org From: Magnus Damm This patch modifies the uio_pdrv_genirq driver to support Runtime PM. The power management implementation simply runtime resumes the device at open() time and runtime suspends it at release() time. The user space driver is responsible for re-initializing the hardware after open(). Signed-off-by: Magnus Damm --- drivers/uio/uio_pdrv_genirq.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0001/drivers/uio/uio_pdrv_genirq.c +++ work/drivers/uio/uio_pdrv_genirq.c 2009-07-31 00:54:10.000000000 +0900 @@ -20,6 +20,7 @@ #include #include #include +#include #define DRIVER_NAME "uio_pdrv_genirq" @@ -27,8 +28,27 @@ struct uio_pdrv_genirq_platdata { struct uio_info *uioinfo; spinlock_t lock; unsigned long flags; + struct platform_device *pdev; }; +static int uio_pdrv_genirq_open(struct uio_info *info, struct inode *inode) +{ + struct uio_pdrv_genirq_platdata *priv = info->priv; + + /* Wait until the Runtime PM code has woken up the device */ + pm_runtime_get_sync(&priv->pdev->dev); + return 0; +} + +static int uio_pdrv_genirq_release(struct uio_info *info, struct inode *inode) +{ + struct uio_pdrv_genirq_platdata *priv = info->priv; + + /* Tell the Runtime PM code that the device has become idle */ + pm_runtime_put_sync(&priv->pdev->dev); + return 0; +} + static irqreturn_t uio_pdrv_genirq_handler(int irq, struct uio_info *dev_info) { struct uio_pdrv_genirq_platdata *priv = dev_info->priv; @@ -97,6 +117,7 @@ static int uio_pdrv_genirq_probe(struct priv->uioinfo = uioinfo; spin_lock_init(&priv->lock); priv->flags = 0; /* interrupt is enabled to begin with */ + priv->pdev = pdev; uiomem = &uioinfo->mem[0]; @@ -136,8 +157,17 @@ static int uio_pdrv_genirq_probe(struct uioinfo->irq_flags |= IRQF_DISABLED; uioinfo->handler = uio_pdrv_genirq_handler; uioinfo->irqcontrol = uio_pdrv_genirq_irqcontrol; + uioinfo->open = uio_pdrv_genirq_open; + uioinfo->release = uio_pdrv_genirq_release; uioinfo->priv = priv; + /* Enable Runtime PM for this device: + * Starts in suspended state to allow the hardware to be turned off + * by default. The Runtime PM bus code will power on the hardware and + * enable clocks at open() during the call to pm_runtime_get_sync(). + */ + pm_runtime_enable(&pdev->dev); + ret = uio_register_device(&pdev->dev, priv->uioinfo); if (ret) { dev_err(&pdev->dev, "unable to register uio device\n"); @@ -157,16 +187,40 @@ static int uio_pdrv_genirq_remove(struct struct uio_pdrv_genirq_platdata *priv = platform_get_drvdata(pdev); uio_unregister_device(priv->uioinfo); + pm_runtime_disable(&pdev->dev); kfree(priv); return 0; } +static int uio_pdrv_genirq_runtime_nop(struct device *dev) +{ + /* Runtime PM callback shared between ->runtime_suspend() + * and ->runtime_resume(). Simply returns success. + * + * In this driver pm_runtime_get() and pm_runtime_put_sync() + * are used at open() and release() time. This allows the + * Runtime PM code to turn off power to the device while the + * device is unused, ie before open() and after release(). + * + * This Runtime PM callback does not need to save or restore + * any registers since user space will reinitialize all the + * hardware registers after open(). + */ + return 0; +} + +static struct dev_pm_ops uio_pdrv_genirq_dev_pm_ops = { + .runtime_suspend = uio_pdrv_genirq_runtime_nop, + .runtime_resume = uio_pdrv_genirq_runtime_nop, +}; + static struct platform_driver uio_pdrv_genirq = { .probe = uio_pdrv_genirq_probe, .remove = uio_pdrv_genirq_remove, .driver = { .name = DRIVER_NAME, .owner = THIS_MODULE, + .pm = &uio_pdrv_genirq_dev_pm_ops, }, };