From patchwork Thu Feb 4 00:19:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 76869 X-Patchwork-Delegate: khilman@deeprootsystems.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o140JLUc004783 for ; Thu, 4 Feb 2010 00:19:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932329Ab0BDATT (ORCPT ); Wed, 3 Feb 2010 19:19:19 -0500 Received: from mail-iw0-f201.google.com ([209.85.223.201]:63014 "EHLO mail-iw0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758000Ab0BDATS (ORCPT ); Wed, 3 Feb 2010 19:19:18 -0500 Received: by mail-iw0-f201.google.com with SMTP id 39so2324202iwn.1 for ; Wed, 03 Feb 2010 16:19:17 -0800 (PST) Received: by 10.231.157.83 with SMTP id a19mr664719ibx.41.1265242757044; Wed, 03 Feb 2010 16:19:17 -0800 (PST) Received: from localhost (deeprootsystems.com [216.254.16.51]) by mx.google.com with ESMTPS id 23sm7996597iwn.15.2010.02.03.16.19.16 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 03 Feb 2010 16:19:16 -0800 (PST) From: Kevin Hilman To: linux-omap@vger.kernel.org Subject: [PATCH/RFC 2/2] OMAP: PM: initial runtime PM support Date: Wed, 3 Feb 2010 16:19:11 -0800 Message-Id: <1265242751-12199-3-git-send-email-khilman@deeprootsystems.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1265242751-12199-1-git-send-email-khilman@deeprootsystems.com> References: <1265242751-12199-1-git-send-email-khilman@deeprootsystems.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 04 Feb 2010 00:19:21 +0000 (UTC) diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile index dba44a1..16ba8fc 100644 --- a/arch/arm/mach-omap2/Makefile +++ b/arch/arm/mach-omap2/Makefile @@ -55,6 +55,12 @@ obj-$(CONFIG_PM_DEBUG) += pm-debug.o AFLAGS_sleep24xx.o :=-Wa,-march=armv6 AFLAGS_sleep34xx.o :=-Wa,-march=armv7-a +# Runtime PM support +obj-$(CONFIG_PM_RUNTIME) += pm_runtime.o +ifeq ($(CONFIG_PM_VERBOSE),y) +CFLAGS_pm_runtime.o += -DDEBUG +endif + endif # PRCM diff --git a/arch/arm/mach-omap2/pm_runtime.c b/arch/arm/mach-omap2/pm_runtime.c new file mode 100644 index 0000000..4bd1b9a --- /dev/null +++ b/arch/arm/mach-omap2/pm_runtime.c @@ -0,0 +1,119 @@ +/* + * Runtime PM support code for OMAP + * + * Author: Kevin Hilman, Deep Root Systems, LLC + * + * Copyright (C) 2010 Texas Instruments, Inc. + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ +#include +#include +#include +#include +#include +#include + +#include +#include + +int platform_pm_runtime_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct omap_device *odev = to_omap_device(pdev); + int ret = 0; + + if (WARN_ON(!omap_device_is_valid(odev))) + return -ENODEV; + + dev_dbg(dev, "%s\n", __func__); + + if (dev->driver->pm && dev->driver->pm->runtime_suspend) + ret = dev->driver->pm->runtime_suspend(dev); + if (!ret) + omap_device_idle(pdev); + + return ret; +}; + +int platform_pm_runtime_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct omap_device *odev = to_omap_device(pdev); + int ret = 0; + + if (WARN_ON(!omap_device_is_valid(odev))) + return -ENODEV; + + dev_dbg(dev, "%s\n", __func__); + + omap_device_enable(pdev); + + /* + * TODO: only call drivers runtime_resume hook if + * device has lost context. + */ + if (dev->driver->pm && dev->driver->pm->runtime_resume) + if (omap_device_has_lost_context(pdev)) + ret = dev->driver->pm->runtime_resume(dev); + + return ret; +}; + +int platform_pm_runtime_idle(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct omap_device *odev = to_omap_device(pdev); + int ret; + + if (WARN_ON(!omap_device_is_valid(odev))) + return -ENODEV; + + ret = pm_runtime_suspend(dev); + dev_dbg(dev, "%s [%d] \n", __func__, ret); + + return 0; +}; + +static int platform_bus_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *dev = data; + struct platform_device *pdev = to_platform_device(dev); + struct omap_device *odev = to_omap_device(pdev); + + if (!omap_device_is_valid(odev)) + return -ENODEV; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + dev_dbg(dev, "BUS_NOTIFY_ADD_DEVICE"); + break; + case BUS_NOTIFY_BOUND_DRIVER: + dev_dbg(dev, "BUS_NOTIFY_BOUND_DRIVER"); + break; + case BUS_NOTIFY_UNBOUND_DRIVER: + dev_dbg(dev, "BUS_NOTIFY_UNBOUND_DRIVER"); + break; + case BUS_NOTIFY_DEL_DEVICE: + dev_dbg(dev, "BUS_NOTIFY_DEL_DEVICE"); + break; + default: + dev_dbg(dev, "Unknown"); + } + + return 0; +} + +static struct notifier_block platform_bus_notifier = { + .notifier_call = platform_bus_notify +}; + +static int __init omap_pm_runtime_init(void) +{ + bus_register_notifier(&platform_bus_type, &platform_bus_notifier); + return 0; +} +core_initcall(omap_pm_runtime_init);