25
25
#include <linux/slab.h>
26
26
#include <linux/pm_qos.h>
27
27
#include <linux/gaming_control.h>
28
-
28
+ #include <soc/samsung/cal-if.h>
29
+ #include <soc/samsung/exynos-cpu_hotplug.h>
30
+ #include <dt-bindings/clock/exynos9810.h>
31
+ #include "../soc/samsung/cal-if/exynos9810/cmucal-vclk.h"
32
+ #include "../soc/samsung/cal-if/exynos9810/cmucal-node.h"
33
+
34
+ extern unsigned long arg_cpu_max_c1 ;
35
+ extern unsigned long arg_cpu_min_c1 ;
36
+ extern unsigned long arg_cpu_max_c2 ;
37
+ extern unsigned long arg_cpu_min_c2 ;
38
+ extern unsigned long arg_gpu_min ;
39
+ extern unsigned long arg_gpu_max ;
40
+ extern int exynos_cpufreq_update_volt_table (void );
29
41
extern void exynos_cpufreq_set_gaming_mode (void );
30
42
31
43
/* PM QoS implementation */
@@ -43,9 +55,13 @@ static unsigned int min_big_freq = 1469000;
43
55
static unsigned int max_big_freq = 2886000 ;
44
56
static unsigned int min_gpu_freq = 598000 ;
45
57
static unsigned int max_gpu_freq = 598000 ;
58
+ static unsigned int custom_little_freq , custom_little_voltage , custom_big_freq , custom_big_voltage , custom_gpu_freq , custom_gpu_voltage = 0 ;
59
+ static unsigned int back_little_freq , back_little_voltage , back_big_freq , back_big_voltage , back_gpu_freq , back_gpu_voltage = 0 ;
46
60
static int nr_running_games = 0 ;
47
61
static bool always_on = 0 ;
48
62
static bool battery_idle = 0 ;
63
+ static bool gaming_mode_initialized = 0 ;
64
+
49
65
bool gaming_mode ;
50
66
51
67
char games_list [GAME_LIST_LENGTH ] = {0 };
@@ -55,25 +71,169 @@ pid_t games_pid[NUM_SUPPORTED_RUNNING_GAMES] = {
55
71
56
72
static inline void set_gaming_mode (bool mode , bool force )
57
73
{
74
+ unsigned int little_max , little_min , big_max , big_min , gpu_max , gpu_min ;
75
+
58
76
if (always_on )
59
77
mode = 1 ;
60
78
61
79
if (mode == gaming_mode && !force )
62
80
return ;
63
81
else
64
82
gaming_mode = mode ;
65
-
83
+
84
+ if (!mode )
85
+ gaming_mode_initialized = 0 ;
86
+
87
+ little_max = max_little_freq ;
88
+ little_min = min_little_freq ;
89
+ big_max = max_big_freq ;
90
+ big_min = min_big_freq ;
91
+ gpu_max = max_gpu_freq ;
92
+ gpu_min = min_gpu_freq ;
93
+
94
+ if (custom_little_freq ) {
95
+ if (custom_little_freq <= arg_cpu_min_c1 )
96
+ little_max = little_min = arg_cpu_min_c1 ;
97
+ else if (custom_little_freq >= arg_cpu_max_c1 )
98
+ little_max = little_min = arg_cpu_max_c1 ;
99
+ }
100
+
101
+ if (!back_little_freq )
102
+ back_little_freq = little_max ;
103
+
104
+ if (custom_little_voltage && mode && !back_little_voltage ) {
105
+ back_little_voltage = fvmap_read (DVFS_CPUCL0 , READ_VOLT , back_little_freq );
106
+ fvmap_patch (DVFS_CPUCL0 , back_little_freq , custom_little_voltage );
107
+ } else if (!mode && back_little_voltage ) {
108
+ fvmap_patch (DVFS_CPUCL0 , back_little_freq , back_little_voltage );
109
+ back_little_freq = back_little_voltage = 0 ;
110
+ }
111
+
112
+ if (custom_big_freq ) {
113
+ if (custom_big_freq <= arg_cpu_min_c2 )
114
+ big_max = big_min = arg_cpu_min_c2 ;
115
+ else if (custom_big_freq >= arg_cpu_max_c2 )
116
+ big_max = big_min = arg_cpu_max_c2 ;
117
+ }
118
+
119
+ if (!back_big_freq )
120
+ back_big_freq = big_max ;
121
+
122
+ if (custom_big_voltage && mode && !back_big_voltage ) {
123
+ back_big_voltage = fvmap_read (DVFS_CPUCL1 , READ_VOLT , back_big_freq );
124
+ fvmap_patch (DVFS_CPUCL1 , back_big_freq , custom_big_voltage );
125
+ } else if (!mode && back_big_voltage ) {
126
+ fvmap_patch (DVFS_CPUCL1 , back_big_freq , back_big_voltage );
127
+ back_big_freq = back_big_voltage = 0 ;
128
+ }
129
+
130
+ if (custom_gpu_freq ) {
131
+ if (custom_gpu_freq <= arg_gpu_min )
132
+ gpu_max = gpu_min = arg_gpu_min ;
133
+ else if (custom_gpu_freq >= arg_gpu_max )
134
+ gpu_max = gpu_min = arg_gpu_max ;
135
+ }
136
+
137
+ if (!back_gpu_freq )
138
+ back_gpu_freq = gpu_max ;
139
+
140
+ if (custom_gpu_voltage && mode && !back_gpu_voltage ) {
141
+ back_gpu_voltage = gpex_clock_get_voltage (back_gpu_freq );
142
+ fvmap_patch (DVFS_G3D , back_gpu_freq , custom_gpu_voltage );
143
+ } else if (!mode && back_gpu_voltage ) {
144
+ fvmap_patch (DVFS_G3D , back_gpu_freq , back_gpu_voltage );
145
+ back_gpu_freq = back_gpu_voltage = 0 ;
146
+ }
147
+
148
+ gpex_clock_update_config_data_from_dt ();
149
+ exynos_cpufreq_update_volt_table ();
66
150
exynos_cpufreq_set_gaming_mode ();
67
151
68
152
pm_qos_update_request (& gaming_control_min_int_qos , mode && min_int_freq ? min_int_freq : PM_QOS_DEVICE_THROUGHPUT_DEFAULT_VALUE );
69
153
pm_qos_update_request (& gaming_control_min_mif_qos , mode && min_mif_freq ? min_mif_freq : PM_QOS_BUS_THROUGHPUT_DEFAULT_VALUE );
70
- pm_qos_update_request (& gaming_control_min_little_qos , mode && min_little_freq ? min_little_freq : PM_QOS_CLUSTER0_FREQ_MIN_DEFAULT_VALUE );
71
- pm_qos_update_request (& gaming_control_max_little_qos , mode && max_little_freq ? max_little_freq : PM_QOS_CLUSTER0_FREQ_MAX_DEFAULT_VALUE );
72
- pm_qos_update_request (& gaming_control_min_big_qos , mode && min_big_freq ? min_big_freq : PM_QOS_CLUSTER1_FREQ_MIN_DEFAULT_VALUE );
73
- pm_qos_update_request (& gaming_control_max_big_qos , mode && max_big_freq ? max_big_freq : PM_QOS_CLUSTER1_FREQ_MAX_DEFAULT_VALUE );
74
-
75
- gpu_custom_max_clock (mode ? max_gpu_freq : 0 );
76
- gpu_custom_min_clock (mode ? min_gpu_freq : 0 );
154
+ pm_qos_update_request (& gaming_control_min_little_qos , mode && little_min ? little_min : PM_QOS_CLUSTER0_FREQ_MIN_DEFAULT_VALUE );
155
+ pm_qos_update_request (& gaming_control_max_little_qos , mode && little_max ? little_max : PM_QOS_CLUSTER0_FREQ_MAX_DEFAULT_VALUE );
156
+ pm_qos_update_request (& gaming_control_min_big_qos , mode && big_min ? big_min : PM_QOS_CLUSTER1_FREQ_MIN_DEFAULT_VALUE );
157
+ pm_qos_update_request (& gaming_control_max_big_qos , mode && big_max ? big_max : PM_QOS_CLUSTER1_FREQ_MAX_DEFAULT_VALUE );
158
+
159
+ gpu_custom_max_clock (mode ? gpu_max : 0 );
160
+ gpu_custom_min_clock (mode ? gpu_min : 0 );
161
+
162
+ if (mode )
163
+ gaming_mode_initialized = 1 ;
164
+
165
+ if (custom_little_freq ) {
166
+ __cal_dfs_set_rate (ACPM_DVFS_CPUCL0 , mode ? custom_little_freq : little_max );
167
+ __cal_dfs_set_rate (VCLK_CLUSTER0 , (mode ? custom_little_freq : little_max ) * 1000 );
168
+ __cal_dfs_set_rate (PLL_CPUCL0 , (mode ? custom_little_freq : little_max ) * 1000 );
169
+ }
170
+
171
+ if (custom_big_freq ) {
172
+ __cal_dfs_set_rate (ACPM_DVFS_CPUCL1 , mode ? custom_big_freq : big_max );
173
+ __cal_dfs_set_rate (VCLK_CLUSTER1 , (mode ? custom_big_freq : big_max ) * 1000 );
174
+ __cal_dfs_set_rate (PLL_CPUCL1 , (mode ? custom_big_freq : big_max ) * 1000 );
175
+ }
176
+
177
+ if (custom_gpu_freq ) {
178
+ __cal_dfs_set_rate (ACPM_DVFS_G3D , mode ? custom_gpu_freq : gpu_max );
179
+ __cal_dfs_set_rate (VCLK_GPU , (mode ? custom_gpu_freq : gpu_max ) * 1000 );
180
+ __cal_dfs_set_rate (PLL_G3D , (mode ? custom_gpu_freq : gpu_max ) * 1000 );
181
+ }
182
+ }
183
+
184
+ unsigned long cal_dfs_check_gaming_mode (unsigned int id ) {
185
+ unsigned long ret = 0 ;
186
+
187
+ if (!gaming_mode_initialized )
188
+ return ret ;
189
+
190
+ switch (id ) {
191
+ /* LITTLE */
192
+ case ACPM_DVFS_CPUCL0 :
193
+ ret = custom_little_freq ;
194
+ break ;
195
+ /* BIG */
196
+ case ACPM_DVFS_CPUCL1 :
197
+ ret = custom_big_freq ;
198
+ break ;
199
+ /* GPU */
200
+ case ACPM_DVFS_G3D :
201
+ ret = custom_gpu_freq ;
202
+ break ;
203
+ default :
204
+ break ;
205
+ }
206
+
207
+ return ret ;
208
+ }
209
+
210
+ int fake_freq_gaming (int id ) {
211
+ int ret = 0 ;
212
+
213
+ if (!gaming_mode )
214
+ return ret ;
215
+
216
+ switch (id ) {
217
+ /* LITTLE */
218
+ case ACPM_DVFS_CPUCL0 :
219
+ case DVFS_CPUCL0 :
220
+ ret = back_little_freq ;
221
+ break ;
222
+ /* BIG */
223
+ case ACPM_DVFS_CPUCL1 :
224
+ case DVFS_CPUCL1 :
225
+ ret = back_big_freq ;
226
+ break ;
227
+ /* GPU */
228
+ case ACPM_DVFS_G3D :
229
+ case DVFS_G3D :
230
+ ret = back_gpu_freq ;
231
+ break ;
232
+ default :
233
+ break ;
234
+ }
235
+
236
+ return ret ;
77
237
}
78
238
79
239
bool battery_idle_gaming (void ) {
@@ -250,6 +410,12 @@ attr_value(min_big_freq);
250
410
attr_value (max_big_freq );
251
411
attr_value (min_gpu_freq );
252
412
attr_value (max_gpu_freq );
413
+ attr_value (custom_little_freq );
414
+ attr_value (custom_little_voltage );
415
+ attr_value (custom_big_freq );
416
+ attr_value (custom_big_voltage );
417
+ attr_value (custom_gpu_freq );
418
+ attr_value (custom_gpu_voltage );
253
419
254
420
static ssize_t version_show (struct kobject * kobj ,
255
421
struct kobj_attribute * attr , char * buf )
@@ -276,6 +442,12 @@ static struct attribute *gaming_control_attributes[] = {
276
442
& max_big_freq_attribute .attr ,
277
443
& min_gpu_freq_attribute .attr ,
278
444
& max_gpu_freq_attribute .attr ,
445
+ & custom_little_freq_attribute .attr ,
446
+ & custom_little_voltage_attribute .attr ,
447
+ & custom_big_freq_attribute .attr ,
448
+ & custom_big_voltage_attribute .attr ,
449
+ & custom_gpu_freq_attribute .attr ,
450
+ & custom_gpu_voltage_attribute .attr ,
279
451
NULL
280
452
};
281
453
0 commit comments