Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 2 | /* |
| 3 | * linux/drivers/devfreq/governor_powersave.c |
| 4 | * |
| 5 | * Copyright (C) 2011 Samsung Electronics |
| 6 | * MyungJoo Ham <myungjoo.ham@samsung.com> |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/devfreq.h> |
Nishanth Menon | eff607f | 2012-10-29 15:01:46 -0500 | [diff] [blame] | 10 | #include <linux/module.h> |
Xiaoguang Chen | 0b7c328f | 2012-04-29 22:51:31 +0200 | [diff] [blame] | 11 | #include "governor.h" |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 12 | |
| 13 | static int devfreq_powersave_func(struct devfreq *df, |
| 14 | unsigned long *freq) |
| 15 | { |
| 16 | /* |
| 17 | * target callback should be able to get ceiling value as |
| 18 | * said in devfreq.h |
| 19 | */ |
Matthias Kaehlcke | 6ff66e2 | 2018-08-03 13:05:10 -0700 | [diff] [blame] | 20 | *freq = DEVFREQ_MIN_FREQ; |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 21 | return 0; |
| 22 | } |
| 23 | |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 24 | static int devfreq_powersave_handler(struct devfreq *devfreq, |
| 25 | unsigned int event, void *data) |
Xiaoguang Chen | 0b7c328f | 2012-04-29 22:51:31 +0200 | [diff] [blame] | 26 | { |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 27 | int ret = 0; |
| 28 | |
| 29 | if (event == DEVFREQ_GOV_START) { |
| 30 | mutex_lock(&devfreq->lock); |
| 31 | ret = update_devfreq(devfreq); |
| 32 | mutex_unlock(&devfreq->lock); |
| 33 | } |
| 34 | |
| 35 | return ret; |
Xiaoguang Chen | 0b7c328f | 2012-04-29 22:51:31 +0200 | [diff] [blame] | 36 | } |
| 37 | |
Nishanth Menon | 1b5c1be | 2012-10-29 15:01:45 -0500 | [diff] [blame] | 38 | static struct devfreq_governor devfreq_powersave = { |
Chanwoo Choi | aa7c352 | 2017-10-23 10:32:12 +0900 | [diff] [blame] | 39 | .name = DEVFREQ_GOV_POWERSAVE, |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 40 | .get_target_freq = devfreq_powersave_func, |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 41 | .event_handler = devfreq_powersave_handler, |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 42 | }; |
Nishanth Menon | 83116e6 | 2012-10-29 15:01:44 -0500 | [diff] [blame] | 43 | |
| 44 | static int __init devfreq_powersave_init(void) |
| 45 | { |
| 46 | return devfreq_add_governor(&devfreq_powersave); |
| 47 | } |
| 48 | subsys_initcall(devfreq_powersave_init); |
| 49 | |
| 50 | static void __exit devfreq_powersave_exit(void) |
| 51 | { |
| 52 | int ret; |
| 53 | |
| 54 | ret = devfreq_remove_governor(&devfreq_powersave); |
| 55 | if (ret) |
| 56 | pr_err("%s: failed remove governor %d\n", __func__, ret); |
| 57 | |
| 58 | return; |
| 59 | } |
| 60 | module_exit(devfreq_powersave_exit); |
Nishanth Menon | eff607f | 2012-10-29 15:01:46 -0500 | [diff] [blame] | 61 | MODULE_LICENSE("GPL"); |