2 * linux/arch/arm/mach-omap2/pm.c
4 * OMAP Power Management Common Routines
6 * Copyright (C) 2005 Texas Instruments, Inc.
7 * Copyright (C) 2006-2008 Nokia Corporation
10 * Richard Woodruff <r-woodruff2@ti.com>
13 * Amit Kucheria <amit.kucheria@nokia.com>
14 * Igor Stoppa <igor.stoppa@nokia.com>
17 * Based on pm.c for omap1
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 2 as
21 * published by the Free Software Foundation.
24 #include <linux/suspend.h>
25 #include <linux/time.h>
26 #include <linux/platform_device.h>
27 #include <linux/device.h>
30 #include <asm/mach/time.h>
31 #include <asm/atomic.h>
33 #include <plat/powerdomain.h>
34 #include <plat/omapdev.h>
35 #include <plat/resource.h>
37 #include "prm-regbits-34xx.h"
40 atomic_t sleep_block
= ATOMIC_INIT(0);
42 static ssize_t
idle_show(struct kobject
*, struct kobj_attribute
*, char *);
43 static ssize_t
idle_store(struct kobject
*k
, struct kobj_attribute
*,
44 const char *buf
, size_t n
);
46 #ifdef CONFIG_OMAP_PM_SRF
47 static struct device dummy_sysfs_dev
;
48 static ssize_t
vdd_opp_show(struct kobject
*, struct kobj_attribute
*, char *);
49 static ssize_t
vdd_opp_store(struct kobject
*k
, struct kobj_attribute
*,
50 const char *buf
, size_t n
);
51 static struct kobj_attribute vdd1_opp_attr
=
52 __ATTR(vdd1_opp
, 0644, vdd_opp_show
, vdd_opp_store
);
54 static struct kobj_attribute vdd2_opp_attr
=
55 __ATTR(vdd2_opp
, 0644, vdd_opp_show
, vdd_opp_store
);
58 static ssize_t
idle_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
64 static ssize_t
idle_store(struct kobject
*kobj
, struct kobj_attribute
*attr
,
65 const char *buf
, size_t n
)
69 if (sscanf(buf
, "%hu", &value
) != 1 ||
70 (value
!= 0 && value
!= 1)) {
71 printk(KERN_ERR
"idle_store: Invalid value\n");
78 #ifdef CONFIG_OMAP_PM_SRF
79 static ssize_t
vdd_opp_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
82 if (attr
== &vdd1_opp_attr
)
83 return sprintf(buf
, "%hu\n", resource_get_level("vdd1_opp"));
84 else if (attr
== &vdd2_opp_attr
)
85 return sprintf(buf
, "%hu\n", resource_get_level("vdd2_opp"));
90 static ssize_t
vdd_opp_store(struct kobject
*kobj
, struct kobj_attribute
*attr
,
91 const char *buf
, size_t n
)
95 if (sscanf(buf
, "%hu", &value
) != 1)
98 if (attr
== &vdd1_opp_attr
) {
99 if (value
< 1 || value
> 5) {
100 printk(KERN_ERR
"vdd_opp_store: Invalid value\n");
103 resource_request("vdd1_opp", &dummy_sysfs_dev
, value
);
104 } else if (attr
== &vdd2_opp_attr
) {
105 if (value
< 2 || value
> 3) {
106 printk(KERN_ERR
"vdd_opp_store: Invalid value\n");
109 resource_request("vdd2_opp", &dummy_sysfs_dev
, value
);
117 void omap2_block_sleep(void)
119 atomic_inc(&sleep_block
);
122 void omap2_allow_sleep(void)
126 i
= atomic_dec_return(&sleep_block
);
130 unsigned get_last_off_on_transaction_id(struct device
*dev
)
132 struct platform_device
*pdev
= to_platform_device(dev
);
133 struct omapdev
*odev
= omapdev_find_pdev(pdev
);
134 struct powerdomain
*pwrdm
;
137 pwrdm
= omapdev_get_pwrdm(odev
);
139 return pwrdm
->state_counter
[0];
145 static int __init
omap_pm_init(void)
149 #ifdef CONFIG_OMAP_PM_SRF
150 error
= sysfs_create_file(power_kobj
,
151 &vdd1_opp_attr
.attr
);
153 printk(KERN_ERR
"sysfs_create_file failed: %d\n", error
);
156 error
= sysfs_create_file(power_kobj
,
157 &vdd2_opp_attr
.attr
);
159 printk(KERN_ERR
"sysfs_create_file failed: %d\n", error
);
166 late_initcall(omap_pm_init
);