From patchwork Wed May 27 10:06:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 26420 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 n4RA8vkd022527 for ; Wed, 27 May 2009 10:10:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759005AbZE0KKA (ORCPT ); Wed, 27 May 2009 06:10:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758952AbZE0KKA (ORCPT ); Wed, 27 May 2009 06:10:00 -0400 Received: from mail-pz0-f177.google.com ([209.85.222.177]:39797 "EHLO mail-pz0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758598AbZE0KJ7 (ORCPT ); Wed, 27 May 2009 06:09:59 -0400 Received: by pzk7 with SMTP id 7so3550907pzk.33 for ; Wed, 27 May 2009 03:10:00 -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=n8IR1TpmesNyoiQTLfY+O0i38qp+TotJIk8SjW8X5C8=; b=oPxIWAGLq1RHpyjojx1D7qGHLw15Ru6hCgg2NomNofDrjmOlQ8Lb8WKRS17Zq3BBm8 gms2CB9UiVvLBhYEs7UXsqLf68Ynu+JdKVllN8j4cuS0Ot5+/RmRP++JK4xPkqb5+zeb aqgwd5DrTP+ROCvvfGIwZ0ovKN8imHGdyipyw= 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=CYheU3A/WZTjdeUsO9A6msUHx01vCADWJOAABHm7WNx2JGEx8JKzDSNUhiyUdZwrfP oW4r0XNyg7170xw4Q4jvf0nq4HPYc0/CWRsp5bM6cDxFU2qlIRUk+eoDVdETGxZtmU75 iuUsYvyB5s3agrmHs3V9PkrYFloOmIbNtenJE= Received: by 10.143.18.16 with SMTP id v16mr3119953wfi.142.1243419000893; Wed, 27 May 2009 03:10:00 -0700 (PDT) Received: from rx1.opensource.se (210.5.32.202.bf.2iij.net [202.32.5.210]) by mx.google.com with ESMTPS id k2sm2906399rvb.10.2009.05.27.03.09.58 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 27 May 2009 03:10:00 -0700 (PDT) From: Magnus Damm To: linux-pm@lists.linux-foundation.org Cc: paul@pwsan.com, linux-sh@vger.kernel.org, khilman@deeprootsystems.com, gregkh@suse.de, rjw@sisk.pl, lethal@linux-sh.org, stern@rowland.harvard.edu, Magnus Damm Date: Wed, 27 May 2009 19:06:50 +0900 Message-Id: <20090527100650.29671.82139.sendpatchset@rx1.opensource.se> In-Reply-To: <20090527100625.29671.43166.sendpatchset@rx1.opensource.se> References: <20090527100625.29671.43166.sendpatchset@rx1.opensource.se> Subject: [PATCH 03/04] PM: Add platform bus runtime dev_pm_ops Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org From: Magnus Damm Wrap the platform device bus dev_pm_ops to allow runtime pm and regular suspend and resume to coexist. Platform device data is extended with flags that allow us to keep track of which dev_pm_ops that has been called. Basically, if a device has been frozen by the runtime pm code, don't call ->freeze() again when hibernating. Architecture code can use platform_runtime_dev_pm_ops to call driver dev_pm_ops associated with a certain device. Enable with CONFIG_HAVE_PLATFORM_DEVICE_RUNTIME_PM. Signed-off-by: Magnus Damm --- This is a bit of a hack, any better way to wrap dev_pm_ops? arch/Kconfig | 3 drivers/base/platform.c | 193 ++++++++++++++++++++++++++++++++++++++- include/linux/platform_device.h | 8 + 3 files changed, 203 insertions(+), 1 deletion(-) -- 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 --- 0003/arch/Kconfig +++ work/arch/Kconfig 2009-05-26 21:22:17.000000000 +0900 @@ -118,3 +118,6 @@ config HAVE_PLATFORM_DEVICE_ARCHDATA config HAVE_PLATFORM_DEVICE_IDLE_WAKEUP bool + +config HAVE_PLATFORM_DEVICE_RUNTIME_PM + bool --- 0001/drivers/base/platform.c +++ work/drivers/base/platform.c 2009-05-27 17:31:06.000000000 +0900 @@ -962,12 +962,203 @@ static struct dev_pm_ops platform_dev_pm #endif /* !CONFIG_PM_SLEEP */ +#ifdef CONFIG_HAVE_PLATFORM_DEVICE_RUNTIME_PM + +#define DEV_PM_OP_PREPARE offsetof(struct dev_pm_ops, prepare) +#define DEV_PM_OP_COMPLETE offsetof(struct dev_pm_ops, complete) +#define DEV_PM_OP_SUSPEND offsetof(struct dev_pm_ops, suspend) +#define DEV_PM_OP_RESUME offsetof(struct dev_pm_ops, resume) +#define DEV_PM_OP_FREEZE offsetof(struct dev_pm_ops, freeze) +#define DEV_PM_OP_THAW offsetof(struct dev_pm_ops, thaw) +#define DEV_PM_OP_POWEROFF offsetof(struct dev_pm_ops, poweroff) +#define DEV_PM_OP_RESTORE offsetof(struct dev_pm_ops, restore) +#define DEV_PM_OP_SUSPEND_NOIRQ offsetof(struct dev_pm_ops, suspend_noirq) +#define DEV_PM_OP_RESUME_NOIRQ offsetof(struct dev_pm_ops, resume_noirq) +#define DEV_PM_OP_FREEZE_NOIRQ offsetof(struct dev_pm_ops, freeze_noirq) +#define DEV_PM_OP_THAW_NOIRQ offsetof(struct dev_pm_ops, thaw_noirq) +#define DEV_PM_OP_POWEROFF_NOIRQ offsetof(struct dev_pm_ops, poweroff_noirq) +#define DEV_PM_OP_RESTORE_NOIRQ offsetof(struct dev_pm_ops, restore_noirq) + +static DEFINE_SPINLOCK(platform_runtime_lock); + +static int platform_runtime_call_op(struct device *dev, unsigned int op) +{ + struct dev_pm_ops *dev_pm_ops = PLATFORM_PM_OPS_PTR; + void **vp = (void **)dev_pm_ops; + int (*int_op)(struct device *); + + if (dev_pm_ops) { + if (op == DEV_PM_OP_COMPLETE) { + if (dev_pm_ops->complete) + dev_pm_ops->complete(dev); + } else { + int_op = vp[op / sizeof(void *)]; + if (int_op) + return int_op(dev); + } + } + + return 0; +} + +static int platform_runtime_call_once(struct device *dev, + unsigned int op) +{ + struct platform_device *pdev = to_platform_device(dev); + unsigned long flags; + int bit, bit_op, is_suspend, ret; + + ret = 0; + is_suspend = 0; + + switch (op) { + case DEV_PM_OP_COMPLETE: + bit_op = DEV_PM_OP_PREPARE; + break; + case DEV_PM_OP_RESUME: + bit_op = DEV_PM_OP_SUSPEND; + break; + case DEV_PM_OP_THAW: + bit_op = DEV_PM_OP_FREEZE; + break; + case DEV_PM_OP_RESTORE: + bit_op = DEV_PM_OP_POWEROFF; + break; + case DEV_PM_OP_RESUME_NOIRQ: + bit_op = DEV_PM_OP_SUSPEND_NOIRQ; + break; + case DEV_PM_OP_THAW_NOIRQ: + bit_op = DEV_PM_OP_FREEZE_NOIRQ; + break; + case DEV_PM_OP_RESTORE_NOIRQ: + bit_op = DEV_PM_OP_POWEROFF_NOIRQ; + break; + default: + bit_op = op; + is_suspend = 1; + } + + bit = bit_op / sizeof(void *); + + spin_lock_irqsave(&platform_runtime_lock, flags); + + if (test_bit(bit, &pdev->runtime_flags) != is_suspend) { + ret = platform_runtime_call_op(dev, op); + + if (!ret) { + if (is_suspend) + __set_bit(bit, &pdev->runtime_flags); + else + __clear_bit(bit, &pdev->runtime_flags); + } + } + + spin_unlock_irqrestore(&platform_runtime_lock, flags); + + return ret; +} + +static int platform_runtime_prepare(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_PREPARE); +} + +static void platform_runtime_complete(struct device *dev) +{ + platform_runtime_call_once(dev, DEV_PM_OP_COMPLETE); +} + +static int platform_runtime_suspend(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_SUSPEND); +} + +static int platform_runtime_resume(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_RESUME); +} + +static int platform_runtime_freeze(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_FREEZE); +} + +static int platform_runtime_thaw(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_THAW); +} + +static int platform_runtime_poweroff(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_POWEROFF); +} + +static int platform_runtime_restore(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_RESTORE); +} + +static int platform_runtime_suspend_noirq(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_SUSPEND_NOIRQ); +} + +static int platform_runtime_resume_noirq(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_RESUME_NOIRQ); +} + +static int platform_runtime_freeze_noirq(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_FREEZE_NOIRQ); +} + +static int platform_runtime_thaw_noirq(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_THAW_NOIRQ); +} + +static int platform_runtime_poweroff_noirq(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_POWEROFF_NOIRQ); +} + +static int platform_runtime_restore_noirq(struct device *dev) +{ + return platform_runtime_call_once(dev, DEV_PM_OP_RESTORE_NOIRQ); +} + +struct dev_pm_ops platform_runtime_dev_pm_ops = { + .prepare = platform_runtime_prepare, + .complete = platform_runtime_complete, + .suspend = platform_runtime_suspend, + .resume = platform_runtime_resume, + .freeze = platform_runtime_freeze, + .thaw = platform_runtime_thaw, + .poweroff = platform_runtime_poweroff, + .restore = platform_runtime_restore, + .suspend_noirq = platform_runtime_suspend_noirq, + .resume_noirq = platform_runtime_resume_noirq, + .freeze_noirq = platform_runtime_freeze_noirq, + .thaw_noirq = platform_runtime_thaw_noirq, + .poweroff_noirq = platform_runtime_poweroff_noirq, + .restore_noirq = platform_runtime_restore_noirq, +}; + +#define PLATFORM_RUNTIME_PM_OPS_PTR (&platform_runtime_dev_pm_ops) + +#else /* !CONFIG_HAVE_PLATFORM_DEVICE_RUNTIME_PM */ + +#define PLATFORM_RUNTIME_PM_OPS_PTR PLATFORM_PM_OPS_PTR + +#endif /* !CONFIG_HAVE_PLATFORM_DEVICE_RUNTIME_PM */ + struct bus_type platform_bus_type = { .name = "platform", .dev_attrs = platform_dev_attrs, .match = platform_match, .uevent = platform_uevent, - .pm = PLATFORM_PM_OPS_PTR, + .pm = PLATFORM_RUNTIME_PM_OPS_PTR, }; EXPORT_SYMBOL_GPL(platform_bus_type); --- 0003/include/linux/platform_device.h +++ work/include/linux/platform_device.h 2009-05-26 21:22:17.000000000 +0900 @@ -27,6 +27,10 @@ struct platform_device { /* arch specific additions */ struct pdev_archdata archdata; #endif +#ifdef CONFIG_HAVE_PLATFORM_DEVICE_RUNTIME_PM + unsigned long runtime_flags; +#endif + }; #define platform_get_device_id(pdev) ((pdev)->id_entry) @@ -65,6 +69,10 @@ static inline void platform_device_idle( static inline void platform_device_wakeup(struct platform_device *pdev) {} #endif +#ifdef CONFIG_HAVE_PLATFORM_DEVICE_RUNTIME_PM +extern struct dev_pm_ops platform_runtime_dev_pm_ops; +#endif + struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *);