From: 黄涛 Date: Thu, 24 Apr 2014 03:35:05 +0000 (+0800) Subject: ARM: rockchip: add pm policy api X-Git-Tag: firefly_0821_release~5446 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=89259626f10d407b40d3ab1bd6230caf379a45fb;p=firefly-linux-kernel-4.4.55.git ARM: rockchip: add pm policy api --- diff --git a/arch/arm/mach-rockchip/rockchip_pm.c b/arch/arm/mach-rockchip/rockchip_pm.c index 0ae52e633ff6..48834b054128 100644 --- a/arch/arm/mach-rockchip/rockchip_pm.c +++ b/arch/arm/mach-rockchip/rockchip_pm.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include "pm.h" @@ -558,4 +560,60 @@ void __init rockchip_suspend_init(void) return; } +static enum rockchip_pm_policy pm_policy; +static BLOCKING_NOTIFIER_HEAD(policy_notifier_list); +int rockchip_pm_policy_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&policy_notifier_list, nb); +} + +int rockchip_pm_policy_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&policy_notifier_list, nb); +} + +static int rockchip_pm_policy_notify(void) +{ + return blocking_notifier_call_chain(&policy_notifier_list, + pm_policy, NULL); +} + +enum rockchip_pm_policy rockchip_pm_get_policy(void) +{ + return pm_policy; +} + +int rockchip_pm_set_policy(enum rockchip_pm_policy policy) +{ + if (policy < ROCKCHIP_PM_NR_POLICYS && policy != pm_policy) { + printk(KERN_INFO "pm policy %d -> %d\n", pm_policy, policy); + pm_policy = policy; + rockchip_pm_policy_notify(); + } + + return 0; +} + +static unsigned int policy; + +static int set_policy(const char *val, const struct kernel_param *kp) +{ + int ret; + + ret = param_set_uint(val, kp); + if (ret < 0) + return ret; + + rockchip_pm_set_policy(policy); + policy = rockchip_pm_get_policy(); + + return 0; +} + +static struct kernel_param_ops policy_param_ops = { + .set = set_policy, + .get = param_get_uint, +}; + +module_param_cb(policy, &policy_param_ops, &policy, 0600); diff --git a/include/linux/rockchip/common.h b/include/linux/rockchip/common.h index c61d19079c97..b61e522886fb 100644 --- a/include/linux/rockchip/common.h +++ b/include/linux/rockchip/common.h @@ -1,6 +1,8 @@ #ifndef __MACH_ROCKCHIP_COMMON_H #define __MACH_ROCKCHIP_COMMON_H +#include + #define RK_DEVICE(VIRT,PHYS,SIZE) \ { \ .virtual = (unsigned long)(VIRT), \ @@ -38,4 +40,16 @@ extern void rockchip_restart_get_boot_mode(const char *cmd, u32 *flag, u32 *mode extern void __init rockchip_suspend_init(void); extern void __init rockchip_ion_reserve(void); +enum rockchip_pm_policy { + ROCKCHIP_PM_POLICY_PERFORMANCE = 0, + ROCKCHIP_PM_POLICY_NORMAL, + ROCKCHIP_PM_POLICY_POWERSAVE, + ROCKCHIP_PM_NR_POLICYS, +}; + +extern enum rockchip_pm_policy rockchip_pm_get_policy(void); +extern int rockchip_pm_set_policy(enum rockchip_pm_policy policy); +extern int rockchip_pm_policy_register_notifier(struct notifier_block *nb); +extern int rockchip_pm_policy_unregister_notifier(struct notifier_block *nb); + #endif