MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/devfreq/governor_powersave.c |
| 3 | * |
| 4 | * Copyright (C) 2011 Samsung Electronics |
| 5 | * MyungJoo Ham <myungjoo.ham@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/devfreq.h> |
Nishanth Menon | eff607f | 2012-10-29 15:01:46 -0500 | [diff] [blame] | 13 | #include <linux/module.h> |
Xiaoguang Chen | 0b7c328 | 2012-04-29 22:51:31 +0200 | [diff] [blame] | 14 | #include "governor.h" |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 15 | |
| 16 | static int devfreq_powersave_func(struct devfreq *df, |
| 17 | unsigned long *freq) |
| 18 | { |
| 19 | /* |
| 20 | * target callback should be able to get ceiling value as |
| 21 | * said in devfreq.h |
| 22 | */ |
MyungJoo Ham | 6530b9de | 2011-12-09 16:42:19 +0900 | [diff] [blame] | 23 | *freq = df->min_freq; |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 24 | return 0; |
| 25 | } |
| 26 | |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 27 | static int devfreq_powersave_handler(struct devfreq *devfreq, |
| 28 | unsigned int event, void *data) |
Xiaoguang Chen | 0b7c328 | 2012-04-29 22:51:31 +0200 | [diff] [blame] | 29 | { |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 30 | int ret = 0; |
| 31 | |
| 32 | if (event == DEVFREQ_GOV_START) { |
| 33 | mutex_lock(&devfreq->lock); |
| 34 | ret = update_devfreq(devfreq); |
| 35 | mutex_unlock(&devfreq->lock); |
| 36 | } |
| 37 | |
| 38 | return ret; |
Xiaoguang Chen | 0b7c328 | 2012-04-29 22:51:31 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Nishanth Menon | 1b5c1be | 2012-10-29 15:01:45 -0500 | [diff] [blame] | 41 | static struct devfreq_governor devfreq_powersave = { |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 42 | .name = "powersave", |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 43 | .get_target_freq = devfreq_powersave_func, |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 44 | .event_handler = devfreq_powersave_handler, |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 45 | }; |
Nishanth Menon | 83116e6 | 2012-10-29 15:01:44 -0500 | [diff] [blame] | 46 | |
| 47 | static int __init devfreq_powersave_init(void) |
| 48 | { |
| 49 | return devfreq_add_governor(&devfreq_powersave); |
| 50 | } |
| 51 | subsys_initcall(devfreq_powersave_init); |
| 52 | |
| 53 | static void __exit devfreq_powersave_exit(void) |
| 54 | { |
| 55 | int ret; |
| 56 | |
| 57 | ret = devfreq_remove_governor(&devfreq_powersave); |
| 58 | if (ret) |
| 59 | pr_err("%s: failed remove governor %d\n", __func__, ret); |
| 60 | |
| 61 | return; |
| 62 | } |
| 63 | module_exit(devfreq_powersave_exit); |
Nishanth Menon | eff607f | 2012-10-29 15:01:46 -0500 | [diff] [blame] | 64 | MODULE_LICENSE("GPL"); |