From ba3a12c7189e253f966cc204e428f7ed61cfe814 Mon Sep 17 00:00:00 2001 From: Jouni Hogander Date: Fri, 16 May 2008 13:57:12 +0300 Subject: [PATCH] PM: Add pm.c file for omap2 and omap3 common code Add pm.c file for common code and move handling of sleep_while_idle attribute and sleep_block to it. Signed-off-by: Jouni Hogander Signed-off-by: Tony Lindgren --- arch/arm/mach-omap2/Makefile | 2 + arch/arm/mach-omap2/pm.c | 91 ++++++++++++++++++++++++++++++++++++ arch/arm/mach-omap2/pm.h | 4 ++ arch/arm/mach-omap2/pm24xx.c | 49 +------------------ 4 files changed, 98 insertions(+), 48 deletions(-) create mode 100644 arch/arm/mach-omap2/pm.c diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile index 87815ced3ca..9ff50478d01 100644 --- a/arch/arm/mach-omap2/Makefile +++ b/arch/arm/mach-omap2/Makefile @@ -12,6 +12,8 @@ obj-$(CONFIG_ARCH_OMAP2) += sram24xx.o obj-$(CONFIG_ARCH_OMAP3) += sram34xx.o # Power Management +obj-$(CONFIG_PM) += pm.o + ifeq ($(CONFIG_ARCH_OMAP2),y) obj-$(CONFIG_PM) += pm24xx.o sleep24xx.o endif diff --git a/arch/arm/mach-omap2/pm.c b/arch/arm/mach-omap2/pm.c new file mode 100644 index 00000000000..55ed75b2d4a --- /dev/null +++ b/arch/arm/mach-omap2/pm.c @@ -0,0 +1,91 @@ +/* + * linux/arch/arm/mach-omap2/pm.c + * + * OMAP Power Management Common Routines + * + * Copyright (C) 2005 Texas Instruments, Inc. + * Copyright (C) 2006-2008 Nokia Corporation + * + * Written by: + * Richard Woodruff + * Tony Lindgren + * Juha Yrjola + * Amit Kucheria + * Igor Stoppa + * Jouni Hogander + * + * Based on pm.c for omap1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include + +#include +#include +#include + +#include "pm.h" + +unsigned short enable_dyn_sleep; +atomic_t sleep_block = ATOMIC_INIT(0); + +static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sprintf(buf, "%hu\n", enable_dyn_sleep); +} + +static ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t n) +{ + unsigned short value; + if (sscanf(buf, "%hu", &value) != 1 || + (value != 0 && value != 1)) { + printk(KERN_ERR "idle_sleep_store: Invalid value\n"); + return -EINVAL; + } + enable_dyn_sleep = value; + return n; +} + +static struct kobj_attribute sleep_while_idle_attr = + __ATTR(sleep_while_idle, 0644, idle_show, idle_store); + +void omap2_block_sleep(void) +{ + atomic_inc(&sleep_block); +} + +void omap2_allow_sleep(void) +{ + int i; + + i = atomic_dec_return(&sleep_block); + BUG_ON(i < 0); +} + +int __init omap_pm_init(void) +{ + int error = -1; + + if (cpu_is_omap24xx()) + error = omap2_pm_init(); + if (error) { + printk(KERN_ERR "omap2_pm_init failed: %d\n", error); + return error; + } + + /* disabled till drivers are fixed */ + enable_dyn_sleep = 0; + error = sysfs_create_file(power_kobj, &sleep_while_idle_attr.attr); + if (error) + printk(KERN_ERR "sysfs_create_file failed: %d\n", error); + + return error; +} + +late_initcall(omap_pm_init); diff --git a/arch/arm/mach-omap2/pm.h b/arch/arm/mach-omap2/pm.h index 541bf902398..15482ba7f49 100644 --- a/arch/arm/mach-omap2/pm.h +++ b/arch/arm/mach-omap2/pm.h @@ -13,6 +13,10 @@ * published by the Free Software Foundation. */ +extern int omap2_pm_init(void); +extern unsigned short enable_dyn_sleep; +extern atomic_t sleep_block; + #ifdef CONFIG_PM_DEBUG extern u32 omap2_read_32k_sync_counter(void); extern void omap2_pm_dump(int mode, int resume, unsigned int us); diff --git a/arch/arm/mach-omap2/pm24xx.c b/arch/arm/mach-omap2/pm24xx.c index 593f62947f6..7bb654f14e7 100644 --- a/arch/arm/mach-omap2/pm24xx.c +++ b/arch/arm/mach-omap2/pm24xx.c @@ -31,7 +31,6 @@ #include #include -#include #include #include #include @@ -61,30 +60,6 @@ static void (*omap2_sram_idle)(void); static void (*omap2_sram_suspend)(void __iomem *dllctrl); static void (*saved_idle)(void); -static unsigned short enable_dyn_sleep = 0; /* disabled till drivers are fixed */ - -static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr, - char *buf) -{ - return sprintf(buf, "%hu\n", enable_dyn_sleep); -} - -static ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t n) -{ - unsigned short value; - if (sscanf(buf, "%hu", &value) != 1 || - (value != 0 && value != 1)) { - printk(KERN_ERR "idle_sleep_store: Invalid value\n"); - return -EINVAL; - } - enable_dyn_sleep = value; - return n; -} - -static struct kobj_attribute sleep_while_idle_attr = - __ATTR(sleep_while_idle, 0644, idle_show, idle_store); - static struct clk *osc_ck, *emul_ck; static int omap2_fclks_active(void) @@ -112,21 +87,6 @@ static int omap2_irq_pending(void) return 0; } -static atomic_t sleep_block = ATOMIC_INIT(0); - -void omap2_block_sleep(void) -{ - atomic_inc(&sleep_block); -} - -void omap2_allow_sleep(void) -{ - int i; - - i = atomic_dec_return(&sleep_block); - BUG_ON(i < 0); -} - static void omap2_enter_full_retention(void) { u32 l, sleep_time = 0; @@ -519,10 +479,9 @@ static void __init prcm_setup_regs(void) WKUP_MOD, PM_WKEN); } -static int __init omap2_pm_init(void) +int __init omap2_pm_init(void) { u32 l; - int error; printk(KERN_INFO "Power Management for OMAP2 initializing\n"); l = __raw_readl(OMAP24XX_PRCM_REVISION); @@ -579,11 +538,5 @@ static int __init omap2_pm_init(void) suspend_set_ops(&omap_pm_ops); pm_idle = omap2_pm_idle; - error = sysfs_create_file(power_kobj, &sleep_while_idle_attr.attr); - if (error) - printk(KERN_ERR "sysfs_create_file failed: %d\n", error); - return 0; } - -late_initcall(omap2_pm_init); -- 2.41.1