-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmali_g610_overclock.h
More file actions
219 lines (192 loc) · 8.3 KB
/
mali_g610_overclock.h
File metadata and controls
219 lines (192 loc) · 8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* Mali G610 MP4 Overclocking Header
*
* This header defines advanced overclocking parameters and register
* definitions for the Mali G610 MP4 GPU on RK3588.
*
* WARNING: These are experimental overclocking parameters that may
* cause system instability, increased heat, or hardware damage.
* Use at your own risk!
*
* Author: Arm-Pi Tweaker Project
* License: GPL v2
*/
#ifndef MALI_G610_OVERCLOCK_H
#define MALI_G610_OVERCLOCK_H
// Mali G610 MP4 GPU specifications
#define MALI_G610_MP4_CORES 4
#define MALI_G610_DEFAULT_MAX_FREQ 1000000000UL // 1.0 GHz
#define MALI_G610_SAFE_MAX_FREQ 1100000000UL // 1.1 GHz (10% overclock)
#define MALI_G610_EXTREME_MAX_FREQ 1200000000UL // 1.2 GHz (20% overclock)
#define MALI_G610_INSANE_MAX_FREQ 1300000000UL // 1.3 GHz (30% overclock)
// Voltage levels for different frequency ranges (in microvolts)
#define MALI_G610_VOLTAGE_MIN 800000 // 0.8V minimum
#define MALI_G610_VOLTAGE_NOMINAL 1000000 // 1.0V nominal
#define MALI_G610_VOLTAGE_HIGH 1100000 // 1.1V high performance
#define MALI_G610_VOLTAGE_EXTREME 1200000 // 1.2V extreme overclock
#define MALI_G610_VOLTAGE_DANGER 1300000 // 1.3V dangerous level
// Thermal limits (in millidegree Celsius)
#define MALI_G610_THERMAL_SAFE 80000 // 80°C safe operating temp
#define MALI_G610_THERMAL_THROTTLE 85000 // 85°C throttling point
#define MALI_G610_THERMAL_CRITICAL 90000 // 90°C critical temp
#define MALI_G610_THERMAL_EMERGENCY 95000 // 95°C emergency shutdown
// Advanced overclocking profiles
struct mali_g610_oc_profile {
const char *name;
unsigned long freq;
unsigned long voltage;
unsigned int thermal_limit;
unsigned int mem_freq_boost; // Memory frequency boost percentage
unsigned int shader_boost; // Shader clock boost
bool voltage_scaling; // Enable dynamic voltage scaling
bool thermal_throttling; // Enable thermal throttling
};
// Predefined overclocking profiles
static const struct mali_g610_oc_profile oc_profiles[] = {
{
.name = "stock",
.freq = MALI_G610_DEFAULT_MAX_FREQ,
.voltage = MALI_G610_VOLTAGE_NOMINAL,
.thermal_limit = MALI_G610_THERMAL_SAFE,
.mem_freq_boost = 0,
.shader_boost = 0,
.voltage_scaling = true,
.thermal_throttling = true,
},
{
.name = "mild_oc",
.freq = 1050000000UL, // 1.05 GHz
.voltage = MALI_G610_VOLTAGE_NOMINAL + 50000,
.thermal_limit = MALI_G610_THERMAL_SAFE,
.mem_freq_boost = 5,
.shader_boost = 0,
.voltage_scaling = true,
.thermal_throttling = true,
},
{
.name = "moderate_oc",
.freq = MALI_G610_SAFE_MAX_FREQ,
.voltage = MALI_G610_VOLTAGE_HIGH,
.thermal_limit = MALI_G610_THERMAL_THROTTLE,
.mem_freq_boost = 10,
.shader_boost = 5,
.voltage_scaling = true,
.thermal_throttling = true,
},
{
.name = "aggressive_oc",
.freq = MALI_G610_EXTREME_MAX_FREQ,
.voltage = MALI_G610_VOLTAGE_EXTREME,
.thermal_limit = MALI_G610_THERMAL_CRITICAL,
.mem_freq_boost = 15,
.shader_boost = 10,
.voltage_scaling = false, // Fixed voltage for stability
.thermal_throttling = true,
},
{
.name = "extreme_oc",
.freq = MALI_G610_INSANE_MAX_FREQ,
.voltage = MALI_G610_VOLTAGE_DANGER,
.thermal_limit = MALI_G610_THERMAL_EMERGENCY,
.mem_freq_boost = 20,
.shader_boost = 15,
.voltage_scaling = false,
.thermal_throttling = false, // Disabled for maximum performance
},
};
// RK3588 CRU (Clock and Reset Unit) registers for GPU clock control
#define RK3588_CRU_BASE 0xfd7c0000
#define RK3588_CRU_CLKSEL_CON59 0x1ec // GPU clock select
#define RK3588_CRU_CLKGATE_CON31 0x27c // GPU clock gate
#define RK3588_CRU_SOFTRST_CON31 0x77c // GPU soft reset
// GPU clock divider settings
#define GPU_CLK_DIV_MASK 0x1f
#define GPU_CLK_DIV_SHIFT 0
#define GPU_CLK_SEL_MASK 0x3
#define GPU_CLK_SEL_SHIFT 5
// Memory controller registers for GPU memory optimization
#define RK3588_PMU_GRF_BASE 0xfd58a000
#define RK3588_PMU_GRF_SOC_CON2 0x10
#define GPU_MEM_PRIORITY_MASK 0x7
#define GPU_MEM_PRIORITY_SHIFT 12
// Performance monitoring unit (PMU) registers
#define MALI_G610_PMU_BASE 0xfb000000
#define MALI_G610_GPU_STATUS 0x00
#define MALI_G610_GPU_READY 0x04
#define MALI_G610_GPU_COMMAND 0x08
#define MALI_G610_GPU_FAULT_STATUS 0x0c
// Job manager registers
#define MALI_G610_JOB_CONTROL_BASE 0x1000
#define MALI_G610_JOB_IRQ_STATUS 0x00
#define MALI_G610_JOB_IRQ_CLEAR 0x04
#define MALI_G610_JOB_IRQ_MASK 0x08
// Memory management unit registers
#define MALI_G610_MMU_BASE 0x2000
#define MALI_G610_MMU_IRQ_STATUS 0x00
#define MALI_G610_MMU_IRQ_CLEAR 0x04
#define MALI_G610_MMU_IRQ_MASK 0x08
// Shader core registers (per core)
#define MALI_G610_SHADER_BASE(core) (0x20000 + (core) * 0x4000)
#define MALI_G610_SHADER_READY 0x00
#define MALI_G610_SHADER_PRESENT 0x04
#define MALI_G610_SHADER_OUTPUT_READY 0x08
// Tiler registers
#define MALI_G610_TILER_BASE 0x1000
#define MALI_G610_TILER_PRESENT 0x00
#define MALI_G610_TILER_READY 0x04
#define MALI_G610_TILER_OUTPUT_READY 0x08
// L2 cache registers
#define MALI_G610_L2_BASE 0x2000
#define MALI_G610_L2_PRESENT 0x00
#define MALI_G610_L2_READY 0x04
#define MALI_G610_L2_CONFIG 0x08
// Advanced overclocking function prototypes
int mali_g610_apply_overclock_profile(const struct mali_g610_oc_profile *profile);
int mali_g610_set_custom_frequency(unsigned long freq, unsigned long voltage);
int mali_g610_enable_thermal_protection(bool enable);
int mali_g610_boost_memory_frequency(unsigned int boost_percent);
int mali_g610_adjust_shader_clocks(unsigned int boost_percent);
int mali_g610_configure_power_management(bool aggressive);
// Register access macros
#define mali_reg_read(base, offset) readl((void __iomem *)((base) + (offset)))
#define mali_reg_write(base, offset, val) writel((val), (void __iomem *)((base) + (offset)))
// Clock manipulation macros
#define GPU_CLK_SET_DIV(div) (((div) & GPU_CLK_DIV_MASK) << GPU_CLK_DIV_SHIFT)
#define GPU_CLK_SET_SEL(sel) (((sel) & GPU_CLK_SEL_MASK) << GPU_CLK_SEL_SHIFT)
// Voltage scaling helpers
#define VOLTAGE_TO_UV(mv) ((mv) * 1000)
#define UV_TO_VOLTAGE(uv) ((uv) / 1000)
// Temperature conversion
#define MILLIC_TO_C(mc) ((mc) / 1000)
#define C_TO_MILLIC(c) ((c) * 1000)
// Safety macros
#define IS_SAFE_VOLTAGE(uv) ((uv) >= MALI_G610_VOLTAGE_MIN && (uv) <= MALI_G610_VOLTAGE_EXTREME)
#define IS_SAFE_FREQUENCY(hz) ((hz) <= MALI_G610_EXTREME_MAX_FREQ)
#define IS_SAFE_TEMPERATURE(mc) ((mc) <= MALI_G610_THERMAL_CRITICAL)
// Debugging and monitoring
#ifdef DEBUG
#define mali_debug(fmt, ...) pr_debug("Mali G610 OC: " fmt, ##__VA_ARGS__)
#else
#define mali_debug(fmt, ...) do { } while (0)
#endif
#define mali_info(fmt, ...) pr_info("Mali G610 OC: " fmt, ##__VA_ARGS__)
#define mali_warn(fmt, ...) pr_warn("Mali G610 OC: " fmt, ##__VA_ARGS__)
#define mali_err(fmt, ...) pr_err("Mali G610 OC: " fmt, ##__VA_ARGS__)
// Feature flags
#define MALI_G610_FEATURE_DVFS BIT(0) // Dynamic voltage/frequency scaling
#define MALI_G610_FEATURE_THERMAL BIT(1) // Thermal monitoring
#define MALI_G610_FEATURE_BOOST BIT(2) // Performance boost
#define MALI_G610_FEATURE_MEMORY_OC BIT(3) // Memory overclocking
#define MALI_G610_FEATURE_SHADER_OC BIT(4) // Shader overclocking
// Hardware revision detection
#define MALI_G610_REV_R0P0 0x0600
#define MALI_G610_REV_R0P1 0x0601
#define MALI_G610_REV_R1P0 0x0610
// Error codes
#define MALI_G610_SUCCESS 0
#define MALI_G610_ERR_INVALID_FREQ -1
#define MALI_G610_ERR_INVALID_VOLTAGE -2
#define MALI_G610_ERR_THERMAL_LIMIT -3
#define MALI_G610_ERR_HARDWARE_FAULT -4
#define MALI_G610_ERR_NOT_SUPPORTED -5
#endif /* MALI_G610_OVERCLOCK_H */