xref: /OK3568_Linux_fs/kernel/drivers/devfreq/governor.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * governor.h - internal header for devfreq governors.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2011 Samsung Electronics
6*4882a593Smuzhiyun  *	MyungJoo Ham <myungjoo.ham@samsung.com>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * This header is for devfreq governors in drivers/devfreq/
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef _GOVERNOR_H
12*4882a593Smuzhiyun #define _GOVERNOR_H
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/devfreq.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define to_devfreq(DEV)	container_of((DEV), struct devfreq, dev)
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* Devfreq events */
19*4882a593Smuzhiyun #define DEVFREQ_GOV_START			0x1
20*4882a593Smuzhiyun #define DEVFREQ_GOV_STOP			0x2
21*4882a593Smuzhiyun #define DEVFREQ_GOV_UPDATE_INTERVAL		0x3
22*4882a593Smuzhiyun #define DEVFREQ_GOV_SUSPEND			0x4
23*4882a593Smuzhiyun #define DEVFREQ_GOV_RESUME			0x5
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define DEVFREQ_MIN_FREQ			0
26*4882a593Smuzhiyun #define DEVFREQ_MAX_FREQ			ULONG_MAX
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /**
29*4882a593Smuzhiyun  * struct devfreq_governor - Devfreq policy governor
30*4882a593Smuzhiyun  * @node:		list node - contains registered devfreq governors
31*4882a593Smuzhiyun  * @name:		Governor's name
32*4882a593Smuzhiyun  * @immutable:		Immutable flag for governor. If the value is 1,
33*4882a593Smuzhiyun  *			this governor is never changeable to other governor.
34*4882a593Smuzhiyun  * @interrupt_driven:	Devfreq core won't schedule polling work for this
35*4882a593Smuzhiyun  *			governor if value is set to 1.
36*4882a593Smuzhiyun  * @get_target_freq:	Returns desired operating frequency for the device.
37*4882a593Smuzhiyun  *			Basically, get_target_freq will run
38*4882a593Smuzhiyun  *			devfreq_dev_profile.get_dev_status() to get the
39*4882a593Smuzhiyun  *			status of the device (load = busy_time / total_time).
40*4882a593Smuzhiyun  *			If no_central_polling is set, this callback is called
41*4882a593Smuzhiyun  *			only with update_devfreq() notified by OPP.
42*4882a593Smuzhiyun  * @event_handler:      Callback for devfreq core framework to notify events
43*4882a593Smuzhiyun  *                      to governors. Events include per device governor
44*4882a593Smuzhiyun  *                      init and exit, opp changes out of devfreq, suspend
45*4882a593Smuzhiyun  *                      and resume of per device devfreq during device idle.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * Note that the callbacks are called with devfreq->lock locked by devfreq.
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun struct devfreq_governor {
50*4882a593Smuzhiyun 	struct list_head node;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	const char name[DEVFREQ_NAME_LEN];
53*4882a593Smuzhiyun 	const unsigned int immutable;
54*4882a593Smuzhiyun 	const unsigned int interrupt_driven;
55*4882a593Smuzhiyun 	int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
56*4882a593Smuzhiyun 	int (*event_handler)(struct devfreq *devfreq,
57*4882a593Smuzhiyun 				unsigned int event, void *data);
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun void devfreq_monitor_start(struct devfreq *devfreq);
61*4882a593Smuzhiyun void devfreq_monitor_stop(struct devfreq *devfreq);
62*4882a593Smuzhiyun void devfreq_monitor_suspend(struct devfreq *devfreq);
63*4882a593Smuzhiyun void devfreq_monitor_resume(struct devfreq *devfreq);
64*4882a593Smuzhiyun void devfreq_update_interval(struct devfreq *devfreq, unsigned int *delay);
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun int devfreq_add_governor(struct devfreq_governor *governor);
67*4882a593Smuzhiyun int devfreq_remove_governor(struct devfreq_governor *governor);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun int devfreq_update_status(struct devfreq *devfreq, unsigned long freq);
70*4882a593Smuzhiyun 
devfreq_update_stats(struct devfreq * df)71*4882a593Smuzhiyun static inline int devfreq_update_stats(struct devfreq *df)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun 	return df->profile->get_dev_status(df->dev.parent, &df->last_status);
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun #endif /* _GOVERNOR_H */
76