8d885c8e83f2ee94e8914a6795caf110cf8c28fc
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / platform / rk / mali_kbase_dvfs.h
1 /* drivers/gpu/midgard/platform/rk/mali_kbase_dvfs.h
2  *
3  * Rockchip SoC Mali-T764 DVFS driver
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software FoundatIon.
8  */
9
10 /**
11  * @file mali_kbase_dvfs.h
12  * DVFS
13  * 声明 平台相关的 mali_dvfs_facility 对外提供的接口, 比如初始化, 设置 gpu_clk_freq, ...
14  * 但这里 并没有 实现良好封装. 
15  *
16  * .DP : mali_dvfs_facility : platform_dependent_part 中对 mali(gpu) DVFS 功能的具体实现.
17  */
18
19 #ifndef _KBASE_DVFS_H_
20 #define _KBASE_DVFS_H_
21
22 /* Frequency that DVFS clock frequency decisions should be made */
23 #define KBASE_PM_DVFS_FREQUENCY                 100
24
25 #define MALI_DVFS_KEEP_STAY_CNT 10
26
27 /**
28  * 一个门限, 当 counter_of_requests_to_jump_up_in_dvfs_level_table 到达该 value 的时候,
29  * 才执行具体的将 current_dvfs_level 上跳的操作. 
30  */
31 #define MALI_DVFS_UP_TIME_INTERVAL 1
32
33 /**
34  * 一个门限, 当 counter_of_requests_to_jump_down_in_dvfs_level_table 到达该 value 的时候,
35  * 才执行具体的将 current_dvfs_level 下跳的操作. 
36  */
37 #define MALI_DVFS_DOWN_TIME_INTERVAL 2
38
39 /**
40  * @see kbase_platform_dvfs_enable.
41  */
42 #define MALI_DVFS_CURRENT_FREQ 0
43
44 #if 0
45 #define MALI_DVFS_BL_CONFIG_FREQ 500
46 #define MALI_DVFS_START_FREQ 400
47 #endif
48
49 /**
50  * mali_dvfs_level_t, 某 mali_dvfs_level (功耗层级) 的具体配置信息. 
51  */
52 typedef struct _mali_dvfs_info {
53         /** 使用的电压.         .Q : 目前实际不起作用? */
54         unsigned int voltage;
55         /** 
56          * gpu_clock_freq. 当前 level 使用的 GPU 时钟频率. 以 KHz 为单位. 
57          */
58         unsigned int clock;
59         /** 
60          * 若 current_calculated_utilisation 低于本成员, 将可能下跳到 mali_dvfs_level_table 中, 临近的低功耗 mali_dvfs_level. 
61          */
62         int min_threshold;
63         /** 
64          * 若 current_calculated_utilisation 高于本成员, 将可能上跳到 mali_dvfs_level_table 中, 临近的高功耗 mali_dvfs_level. 
65          */
66         int max_threshold;
67         /** 
68          * total_time_in_this_level : gpu 停留在当前 level 上的 累计时间. 以 jiffy 为单位.
69          */
70         unsigned long long time;
71 } mali_dvfs_info;
72
73 #define MALI_KHZ 1000
74 extern mali_dvfs_info *p_mali_dvfs_infotbl;
75 extern unsigned int MALI_DVFS_STEP;
76 #ifdef CONFIG_MALI_MIDGARD_DVFS
77 #define CONFIG_MALI_MIDGARD_FREQ_LOCK
78 #endif
79
80 /**
81  * 将 gpu_clk 设置为 'freq', 'freq' 以 KHz 为单位. 
82  */
83 void kbase_platform_dvfs_set_clock(struct kbase_device *kbdev, int freq);
84
85 /**
86  * 命令 dvfs_module 为 gpu 配置 'level' 指定的 dvfs_level, 并具体生效.
87  * @param level
88  *      待使用的 mali_dvfs_level 在 mali_dvfs_level_table 中的 index.
89  */
90 void kbase_platform_dvfs_set_level(struct kbase_device *kbdev, int level);
91
92 /**
93  * 检索 mali_dvfs_level_table, 返回其中 gpu_clock_freq 精确是 'freq' 的 level_item 的 index.
94  * 若没有找到, 返回 -1.
95  * 'freq' 以 KHz 为单位.
96  */
97 int kbase_platform_dvfs_get_level(int freq);
98
99 #ifdef CONFIG_MALI_MIDGARD_DVFS
100 /**
101  * 初始化 mali_dvfs_facility.
102  */
103 int kbase_platform_dvfs_init(struct kbase_device *dev);
104
105 /**
106  * 中止化 mali_dvfs_facility.
107  */
108 void kbase_platform_dvfs_term(void);
109 /*int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation);*/
110 /*int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation,u32 util_gl_share, u32 util_cl_share[2]);*/
111
112 /**
113  * 返回当前 mali_dvfs 是否是开启, 即 common_parts 是否会回调通知 dvfs_event.
114  */
115 int kbase_platform_dvfs_get_enable_status(void);
116
117 /**
118  * 使能或者禁用 dvfs, 并将 gpu_clk 设置为 'freq'(最接近的 允许的 clk).
119  * 若 'freq' 是 MALI_DVFS_CURRENT_FREQ, 则 "不" 改变当前的 gpu_clk_freq.
120  */
121 int kbase_platform_dvfs_enable(bool enable, int freq);
122
123 /**
124  * 返回 mali(gpu) 当前(最近的) utilisation.
125  */
126 int kbase_platform_dvfs_get_utilisation(void);
127 #endif
128
129 /**
130  * 返回 current_dvfs_level 在 mali_dvfs_level_table 中的 index.
131  */
132 int mali_get_dvfs_current_level(void);
133
134 /**
135  * 返回当前 dvfs_level_upper_limit 的 gpu_clk_freq, 以 KHz 为单位.
136  * 若没有设置, 返回 -1.
137  */
138 int mali_get_dvfs_upper_locked_freq(void);
139 /**
140  * 返回当前 dvfs_level_lower_limit 的 gpu_clk_freq, 以 KHz 为单位.
141  * 若没有设置, 返回 -1.
142  */
143 int mali_get_dvfs_under_locked_freq(void);
144
145 /**
146  * 将 'level' 设置为当前的 dvfs_level_upper_limit..
147  * 这里用 "freq_lock" 不贴切.
148  * @return 
149  *      若成功, 返回 0.
150  *      否则, 返回其他 value.
151  */
152 int mali_dvfs_freq_lock(int level);
153 /**
154  * 清除当前的 dvfs_level_upper_limit 设置. 
155  */
156 void mali_dvfs_freq_unlock(void);
157 /**
158  * 将 'level' 设置为当前的 dvfs_level_lower_limit.
159  * @return 
160  *      若成功, 返回 0.
161  *      否则, 返回其他 value.
162  */
163 int mali_dvfs_freq_under_lock(int level);
164 /**
165  * 清除当前的 dvfs_level_lower_limit 设置. 
166  */
167 void mali_dvfs_freq_under_unlock(void);
168
169 // @see 'time_in_state' in mali_kbase_platform.c.
170 ssize_t show_time_in_state(struct device *dev, struct device_attribute *attr, char *buf);
171 ssize_t set_time_in_state(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
172
173 #endif                          /* _KBASE_DVFS_H_ */