xref: /OK3568_Linux_fs/kernel/drivers/gpu/drm/lima/lima_devfreq.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* Copyright 2020 Martin Blumenstingl <martin.blumenstingl@googlemail.com> */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #ifndef __LIMA_DEVFREQ_H__
5*4882a593Smuzhiyun #define __LIMA_DEVFREQ_H__
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/spinlock.h>
8*4882a593Smuzhiyun #include <linux/ktime.h>
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun struct devfreq;
11*4882a593Smuzhiyun struct opp_table;
12*4882a593Smuzhiyun struct thermal_cooling_device;
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun struct lima_device;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun struct lima_devfreq {
17*4882a593Smuzhiyun 	struct devfreq *devfreq;
18*4882a593Smuzhiyun 	struct opp_table *clkname_opp_table;
19*4882a593Smuzhiyun 	struct opp_table *regulators_opp_table;
20*4882a593Smuzhiyun 	struct thermal_cooling_device *cooling;
21*4882a593Smuzhiyun 	bool opp_of_table_added;
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	ktime_t busy_time;
24*4882a593Smuzhiyun 	ktime_t idle_time;
25*4882a593Smuzhiyun 	ktime_t time_last_update;
26*4882a593Smuzhiyun 	int busy_count;
27*4882a593Smuzhiyun 	/*
28*4882a593Smuzhiyun 	 * Protect busy_time, idle_time, time_last_update and busy_count
29*4882a593Smuzhiyun 	 * because these can be updated concurrently, for example by the GP
30*4882a593Smuzhiyun 	 * and PP interrupts.
31*4882a593Smuzhiyun 	 */
32*4882a593Smuzhiyun 	spinlock_t lock;
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun int lima_devfreq_init(struct lima_device *ldev);
36*4882a593Smuzhiyun void lima_devfreq_fini(struct lima_device *ldev);
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun void lima_devfreq_record_busy(struct lima_devfreq *devfreq);
39*4882a593Smuzhiyun void lima_devfreq_record_idle(struct lima_devfreq *devfreq);
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun int lima_devfreq_resume(struct lima_devfreq *devfreq);
42*4882a593Smuzhiyun int lima_devfreq_suspend(struct lima_devfreq *devfreq);
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #endif
45