1 /*************************************************************************/ /*!
2 @Title System Configuration
3 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @License Dual MIT/GPLv2
6 The contents of this file are subject to the MIT license as set out below.
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 Alternatively, the contents of this file may be used under the terms of
19 the GNU General Public License Version 2 ("GPL") in which case the provisions
20 of GPL are applicable instead of those above.
22 If you wish to allow use of your version of this file only under the terms of
23 GPL, and not to allow others to use your version of this file under the terms
24 of the MIT license, indicate your decision by deleting the provisions above
25 and replace them with the notice and other provisions required by GPL as set
26 out in the file called "GPL-COPYING" included in this distribution. If you do
27 not delete the provisions above, a recipient may use your version of this file
28 under the terms of either the MIT license or GPL.
30 This License is also included in this distribution in the file called
33 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 @Description System Configuration functions
41 */ /**************************************************************************/
43 #if defined(SUPPORT_ION)
45 #endif /* defined(SUPPORT_ION) */
47 #include <linux/hardirq.h>
48 #include <linux/clk.h>
49 #include <linux/clk-private.h>
51 #include <linux/clk/sunxi_name.h>
52 #include <linux/clk/sunxi.h>
53 #include <linux/platform_device.h>
54 #include <linux/regulator/consumer.h>
55 #include <linux/delay.h>
56 #include <mach/irqs.h>
57 #include <mach/hardware.h>
58 #include <mach/platform.h>
59 #include <mach/sys_config.h>
61 #include "sunxi_init.h"
62 #include "pvrsrv_device.h"
63 #include "syscommon.h"
65 #ifdef CONFIG_CPU_BUDGET_THERMAL
66 #include <linux/cpu_budget_cooling.h>
67 static int Is_powernow = 0;
68 #endif /* CONFIG_CPU_BUDGET_THERMAL */
70 static const IMG_OPP asOPPTable[] =
100 #define LEVEL_COUNT (sizeof(asOPPTable) / sizeof(asOPPTable[0]))
102 #define AXI_CLK_FREQ 320
103 #define GPU_CTRL "gpuctrl"
105 static struct clk *gpu_core_clk = NULL;
106 static struct clk *gpu_mem_clk = NULL;
107 static struct clk *gpu_axi_clk = NULL;
108 static struct clk *gpu_pll_clk = NULL;
109 static struct clk *gpu_ctrl_clk = NULL;
110 static struct regulator *rgx_regulator = NULL;
111 static char *regulator_id = "axp22_dcdc2";
113 #if defined(PVR_DVFS)
114 #define DEFAULT_MIN_VL_LEVEL 0
116 #define DEFAULT_MIN_VL_LEVEL 4
119 static IMG_UINT32 min_vf_level_val = DEFAULT_MIN_VL_LEVEL;
120 static IMG_UINT32 max_vf_level_val = LEVEL_COUNT - 1;
122 static PVRSRV_DEVICE_CONFIG* gpsDevConfig = NULL;
124 long int GetConfigFreq(IMG_VOID)
126 return asOPPTable[min_vf_level_val].ui32Freq*1000*1000;
129 IMG_UINT32 AwClockFreqGet(IMG_HANDLE hSysData)
131 return (IMG_UINT32)clk_get_rate(gpu_core_clk);
134 static IMG_VOID AssertGpuResetSignal(IMG_VOID)
136 if(sunxi_periph_reset_assert(gpu_core_clk))
138 PVR_DPF((PVR_DBG_ERROR, "Failed to pull down gpu reset!"));
140 if(sunxi_periph_reset_assert(gpu_ctrl_clk))
142 PVR_DPF((PVR_DBG_ERROR, "Failed to pull down gpu control reset!"));
146 static IMG_VOID DeAssertGpuResetSignal(IMG_VOID)
148 if(sunxi_periph_reset_deassert(gpu_ctrl_clk))
150 PVR_DPF((PVR_DBG_ERROR, "Failed to release gpu control reset!"));
152 if(sunxi_periph_reset_deassert(gpu_core_clk))
154 PVR_DPF((PVR_DBG_ERROR, "Failed to release gpu reset!"));
158 static IMG_VOID RgxEnableClock(IMG_VOID)
160 if(gpu_core_clk->enable_count == 0)
162 if(clk_prepare_enable(gpu_pll_clk))
164 PVR_DPF((PVR_DBG_ERROR, "Failed to enable pll9 clock!"));
166 if(clk_prepare_enable(gpu_core_clk))
168 PVR_DPF((PVR_DBG_ERROR, "Failed to enable core clock!"));
170 if(clk_prepare_enable(gpu_mem_clk))
172 PVR_DPF((PVR_DBG_ERROR, "Failed to enable mem clock!"));
174 if(clk_prepare_enable(gpu_axi_clk))
176 PVR_DPF((PVR_DBG_ERROR, "Failed to enable axi clock!"));
178 if(clk_prepare_enable(gpu_ctrl_clk))
180 PVR_DPF((PVR_DBG_ERROR, "Failed to enable ctrl clock!"));
185 static IMG_VOID RgxDisableClock(IMG_VOID)
187 if(gpu_core_clk->enable_count == 1)
189 clk_disable_unprepare(gpu_ctrl_clk);
190 clk_disable_unprepare(gpu_axi_clk);
191 clk_disable_unprepare(gpu_mem_clk);
192 clk_disable_unprepare(gpu_core_clk);
193 clk_disable_unprepare(gpu_pll_clk);
197 static IMG_VOID RgxEnablePower(IMG_VOID)
199 if(!regulator_is_enabled(rgx_regulator))
201 regulator_enable(rgx_regulator);
205 static IMG_VOID RgxDisablePower(IMG_VOID)
207 if(regulator_is_enabled(rgx_regulator))
209 regulator_disable(rgx_regulator);
213 void SetVoltage(IMG_UINT32 ui32Volt)
215 if(regulator_set_voltage(rgx_regulator, ui32Volt*1000, ui32Volt*1000) != 0)
217 PVR_DPF((PVR_DBG_ERROR, "Failed to set gpu power voltage!"));
221 static void SetClkVal(const char clk_name[], int freq)
223 struct clk *clk = NULL;
225 if(!strcmp(clk_name, "pll"))
229 else if(!strcmp(clk_name, "core"))
233 else if(!strcmp(clk_name, "mem"))
242 if(clk_set_rate(clk, freq*1000*1000))
248 if(clk == gpu_pll_clk)
250 /* delay for gpu pll stability */
257 void SetFrequency(IMG_UINT32 ui32Frequency)
259 SetClkVal("pll", (int) ui32Frequency);
262 static void ParseFexPara(void)
264 script_item_u regulator_id_fex, min_vf_level, max_vf_level;
265 if(SCIRPT_ITEM_VALUE_TYPE_STR == script_get_item("rgx_para", "regulator_id", ®ulator_id_fex))
267 regulator_id = regulator_id_fex.str;
270 if(SCIRPT_ITEM_VALUE_TYPE_INT == script_get_item("rgx_para", "min_vf_level", &min_vf_level))
272 if((min_vf_level.val >= 0 && min_vf_level.val < LEVEL_COUNT))
274 min_vf_level_val = min_vf_level.val;
282 if(SCIRPT_ITEM_VALUE_TYPE_INT == script_get_item("rgx_para", "max_vf_level", &max_vf_level))
284 if(max_vf_level.val >= min_vf_level_val && max_vf_level.val < LEVEL_COUNT)
286 max_vf_level_val = max_vf_level.val;
297 min_vf_level_val = DEFAULT_MIN_VL_LEVEL;
299 regulator_id = "axp22_dcdc2";
303 PVRSRV_ERROR AwPrePowerState(PVRSRV_DEV_POWER_STATE eNewPowerState, PVRSRV_DEV_POWER_STATE eCurrentPowerState, IMG_BOOL bForced)
305 return AwSysPrePowerState(eNewPowerState);
308 PVRSRV_ERROR AwPostPowerState(PVRSRV_DEV_POWER_STATE eNewPowerState, PVRSRV_DEV_POWER_STATE eCurrentPowerState, IMG_BOOL bForced)
310 return AwSysPostPowerState(eNewPowerState);
313 PVRSRV_ERROR AwSysPrePowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
315 if(eNewPowerState == PVRSRV_SYS_POWER_STATE_ON)
321 /* set external isolation invalid */
322 writel(0, SUNXI_R_PRCM_VBASE + GPU_PWROFF_GATING);
324 DeAssertGpuResetSignal();
328 /* set delay for internal power stability */
329 writel(0x100, SUNXI_GPU_CTRL_VBASE + 0x18);
335 PVRSRV_ERROR AwSysPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
337 if(eNewPowerState == PVRSRV_SYS_POWER_STATE_OFF)
341 AssertGpuResetSignal();
343 /* set external isolation valid */
344 writel(1, SUNXI_R_PRCM_VBASE + GPU_PWROFF_GATING);
352 #ifdef CONFIG_CPU_BUDGET_THERMAL
353 static void RgxDvfsChange(int vf_level, int up_flag)
355 #if defined (PVR_DVFS)
356 IMG_DVFS_DEVICE_CFG *psDVFSDeviceCfg = &gpsDevConfig->sDVFS.sDVFSDeviceCfg;
357 psDVFSDeviceCfg->ui32FreqMax = asOPPTable[vf_level].ui32Freq;
360 err = PVRSRVDevicePreClockSpeedChange(0, IMG_TRUE, NULL);
365 SetVoltage(asOPPTable[vf_level].ui32Volt);
366 SetClkVal("pll", asOPPTable[vf_level].ui32Freq);
370 SetClkVal("pll", asOPPTable[vf_level].ui32Freq);
371 SetVoltage(asOPPTable[vf_level].ui32Volt);
373 PVRSRVDevicePostClockSpeedChange(0, IMG_TRUE, NULL);
378 static int rgx_throttle_notifier_call(struct notifier_block *nfb, unsigned long mode, void *cmd)
380 int retval = NOTIFY_DONE;
381 if(mode == BUDGET_GPU_THROTTLE && Is_powernow)
383 RgxDvfsChange(min_vf_level_val, 0);
388 if(cmd && (*(int *)cmd) == 1 && !Is_powernow)
390 RgxDvfsChange(max_vf_level_val, 0);
393 else if(cmd && (*(int *)cmd) == 0 && Is_powernow)
395 RgxDvfsChange(min_vf_level_val, 0);
403 static struct notifier_block rgx_throttle_notifier = {
404 .notifier_call = rgx_throttle_notifier_call,
406 #endif /* CONFIG_CPU_BUDGET_THERMAL */
408 IMG_VOID RgxSunxiDeInit(IMG_VOID)
410 #ifdef CONFIG_CPU_BUDGET_THERMAL
411 unregister_budget_cooling_notifier(&rgx_throttle_notifier);
412 #endif /* CONFIG_CPU_BUDGET_THERMAL */
413 regulator_put(rgx_regulator);
414 rgx_regulator = NULL;
417 void RgxSunxiInit(PVRSRV_DEVICE_CONFIG* psDevConfig)
419 IMG_UINT32 vf_level_val;
423 rgx_regulator = regulator_get(NULL, regulator_id);
424 if (IS_ERR(rgx_regulator))
426 PVR_DPF((PVR_DBG_ERROR, "Failed to get rgx regulator!"));
427 rgx_regulator = NULL;
431 gpu_core_clk = clk_get(NULL, GPUCORE_CLK);
432 gpu_mem_clk = clk_get(NULL, GPUMEM_CLK);
433 gpu_axi_clk = clk_get(NULL, GPUAXI_CLK);
434 gpu_pll_clk = clk_get(NULL, PLL9_CLK);
435 gpu_ctrl_clk = clk_get(NULL, GPU_CTRL);
437 gpsDevConfig = psDevConfig;
439 #if defined(PVR_DVFS)
440 gpsDevConfig->sDVFS.sDVFSDeviceCfg.pasOPPTable = asOPPTable;
441 gpsDevConfig->sDVFS.sDVFSDeviceCfg.ui32OPPTableSize = LEVEL_COUNT;
442 gpsDevConfig->sDVFS.sDVFSDeviceCfg.ui32FreqMin = asOPPTable[min_vf_level_val].ui32Freq;
443 gpsDevConfig->sDVFS.sDVFSDeviceCfg.ui32FreqMax = asOPPTable[max_vf_level_val].ui32Freq;
444 gpsDevConfig->sDVFS.sDVFSDeviceCfg.pfnSetFrequency = SetFrequency;
445 gpsDevConfig->sDVFS.sDVFSDeviceCfg.pfnSetVoltage = SetVoltage;
448 vf_level_val = min_vf_level_val;
450 SetVoltage(asOPPTable[vf_level_val].ui32Volt);
452 SetClkVal("pll", asOPPTable[vf_level_val].ui32Freq);
453 SetClkVal("core", asOPPTable[vf_level_val].ui32Freq);
454 SetClkVal("mem", asOPPTable[vf_level_val].ui32Freq);
455 SetClkVal("axi", AXI_CLK_FREQ);
457 (void) AwSysPrePowerState(PVRSRV_SYS_POWER_STATE_ON);
459 #ifdef CONFIG_CPU_BUDGET_THERMAL
460 register_budget_cooling_notifier(&rgx_throttle_notifier);
461 #endif /* CONFIG_CPU_BUDGET_THERMAL */