blob: 4746af2435b0224ddb5a80526f96e30ff2bab711 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
MyungJoo Hamce26c5b2011-10-02 00:19:34 +02002/*
3 * linux/drivers/devfreq/governor_powersave.c
4 *
5 * Copyright (C) 2011 Samsung Electronics
6 * MyungJoo Ham <myungjoo.ham@samsung.com>
MyungJoo Hamce26c5b2011-10-02 00:19:34 +02007 */
8
9#include <linux/devfreq.h>
Nishanth Menoneff607f2012-10-29 15:01:46 -050010#include <linux/module.h>
Xiaoguang Chen0b7c328f2012-04-29 22:51:31 +020011#include "governor.h"
MyungJoo Hamce26c5b2011-10-02 00:19:34 +020012
13static 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 Kaehlcke6ff66e22018-08-03 13:05:10 -070020 *freq = DEVFREQ_MIN_FREQ;
MyungJoo Hamce26c5b2011-10-02 00:19:34 +020021 return 0;
22}
23
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020024static int devfreq_powersave_handler(struct devfreq *devfreq,
25 unsigned int event, void *data)
Xiaoguang Chen0b7c328f2012-04-29 22:51:31 +020026{
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020027 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 Chen0b7c328f2012-04-29 22:51:31 +020036}
37
Nishanth Menon1b5c1be2012-10-29 15:01:45 -050038static struct devfreq_governor devfreq_powersave = {
Chanwoo Choiaa7c3522017-10-23 10:32:12 +090039 .name = DEVFREQ_GOV_POWERSAVE,
MyungJoo Hamce26c5b2011-10-02 00:19:34 +020040 .get_target_freq = devfreq_powersave_func,
Rajagopal Venkat7e6fdd42012-10-26 01:50:09 +020041 .event_handler = devfreq_powersave_handler,
MyungJoo Hamce26c5b2011-10-02 00:19:34 +020042};
Nishanth Menon83116e62012-10-29 15:01:44 -050043
44static int __init devfreq_powersave_init(void)
45{
46 return devfreq_add_governor(&devfreq_powersave);
47}
48subsys_initcall(devfreq_powersave_init);
49
50static 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}
60module_exit(devfreq_powersave_exit);
Nishanth Menoneff607f2012-10-29 15:01:46 -050061MODULE_LICENSE("GPL");