xref: /OK3568_Linux_fs/kernel/drivers/devfreq/governor_powersave.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  linux/drivers/devfreq/governor_powersave.c
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 2011 Samsung Electronics
6*4882a593Smuzhiyun  *	MyungJoo Ham <myungjoo.ham@samsung.com>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/devfreq.h>
10*4882a593Smuzhiyun #include <linux/module.h>
11*4882a593Smuzhiyun #include "governor.h"
12*4882a593Smuzhiyun 
devfreq_powersave_func(struct devfreq * df,unsigned long * freq)13*4882a593Smuzhiyun static int devfreq_powersave_func(struct devfreq *df,
14*4882a593Smuzhiyun 				  unsigned long *freq)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun 	/*
17*4882a593Smuzhiyun 	 * target callback should be able to get ceiling value as
18*4882a593Smuzhiyun 	 * said in devfreq.h
19*4882a593Smuzhiyun 	 */
20*4882a593Smuzhiyun 	*freq = DEVFREQ_MIN_FREQ;
21*4882a593Smuzhiyun 	return 0;
22*4882a593Smuzhiyun }
23*4882a593Smuzhiyun 
devfreq_powersave_handler(struct devfreq * devfreq,unsigned int event,void * data)24*4882a593Smuzhiyun static int devfreq_powersave_handler(struct devfreq *devfreq,
25*4882a593Smuzhiyun 				unsigned int event, void *data)
26*4882a593Smuzhiyun {
27*4882a593Smuzhiyun 	int ret = 0;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	if (event == DEVFREQ_GOV_START) {
30*4882a593Smuzhiyun 		mutex_lock(&devfreq->lock);
31*4882a593Smuzhiyun 		ret = update_devfreq(devfreq);
32*4882a593Smuzhiyun 		mutex_unlock(&devfreq->lock);
33*4882a593Smuzhiyun 	}
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	return ret;
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun static struct devfreq_governor devfreq_powersave = {
39*4882a593Smuzhiyun 	.name = DEVFREQ_GOV_POWERSAVE,
40*4882a593Smuzhiyun 	.get_target_freq = devfreq_powersave_func,
41*4882a593Smuzhiyun 	.event_handler = devfreq_powersave_handler,
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
devfreq_powersave_init(void)44*4882a593Smuzhiyun static int __init devfreq_powersave_init(void)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun 	return devfreq_add_governor(&devfreq_powersave);
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun subsys_initcall(devfreq_powersave_init);
49*4882a593Smuzhiyun 
devfreq_powersave_exit(void)50*4882a593Smuzhiyun static void __exit devfreq_powersave_exit(void)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun 	int ret;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	ret = devfreq_remove_governor(&devfreq_powersave);
55*4882a593Smuzhiyun 	if (ret)
56*4882a593Smuzhiyun 		pr_err("%s: failed remove governor %d\n", __func__, ret);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	return;
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun module_exit(devfreq_powersave_exit);
61*4882a593Smuzhiyun MODULE_LICENSE("GPL");
62