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