18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* Copyright (c) 2016 The Linux Foundation. All rights reserved. 38c2ecf20Sopenharmony_ci */ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/pm_opp.h> 68c2ecf20Sopenharmony_ci#include "a5xx_gpu.h" 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* 98c2ecf20Sopenharmony_ci * The GPMU data block is a block of shared registers that can be used to 108c2ecf20Sopenharmony_ci * communicate back and forth. These "registers" are by convention with the GPMU 118c2ecf20Sopenharmony_ci * firwmare and not bound to any specific hardware design 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define AGC_INIT_BASE REG_A5XX_GPMU_DATA_RAM_BASE 158c2ecf20Sopenharmony_ci#define AGC_INIT_MSG_MAGIC (AGC_INIT_BASE + 5) 168c2ecf20Sopenharmony_ci#define AGC_MSG_BASE (AGC_INIT_BASE + 7) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define AGC_MSG_STATE (AGC_MSG_BASE + 0) 198c2ecf20Sopenharmony_ci#define AGC_MSG_COMMAND (AGC_MSG_BASE + 1) 208c2ecf20Sopenharmony_ci#define AGC_MSG_PAYLOAD_SIZE (AGC_MSG_BASE + 3) 218c2ecf20Sopenharmony_ci#define AGC_MSG_PAYLOAD(_o) ((AGC_MSG_BASE + 5) + (_o)) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define AGC_POWER_CONFIG_PRODUCTION_ID 1 248c2ecf20Sopenharmony_ci#define AGC_INIT_MSG_VALUE 0xBABEFACE 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* AGC_LM_CONFIG (A540+) */ 278c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG (136/4) 288c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG_GPU_VERSION_SHIFT 17 298c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG_ENABLE_GPMU_ADAPTIVE 1 308c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG_THROTTLE_DISABLE (2 << 8) 318c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG_ISENSE_ENABLE (1 << 4) 328c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG_ENABLE_ERROR (3 << 4) 338c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG_LLM_ENABLED (1 << 16) 348c2ecf20Sopenharmony_ci#define AGC_LM_CONFIG_BCL_DISABLED (1 << 24) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define AGC_LEVEL_CONFIG (140/4) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic struct { 398c2ecf20Sopenharmony_ci uint32_t reg; 408c2ecf20Sopenharmony_ci uint32_t value; 418c2ecf20Sopenharmony_ci} a5xx_sequence_regs[] = { 428c2ecf20Sopenharmony_ci { 0xB9A1, 0x00010303 }, 438c2ecf20Sopenharmony_ci { 0xB9A2, 0x13000000 }, 448c2ecf20Sopenharmony_ci { 0xB9A3, 0x00460020 }, 458c2ecf20Sopenharmony_ci { 0xB9A4, 0x10000000 }, 468c2ecf20Sopenharmony_ci { 0xB9A5, 0x040A1707 }, 478c2ecf20Sopenharmony_ci { 0xB9A6, 0x00010000 }, 488c2ecf20Sopenharmony_ci { 0xB9A7, 0x0E000904 }, 498c2ecf20Sopenharmony_ci { 0xB9A8, 0x10000000 }, 508c2ecf20Sopenharmony_ci { 0xB9A9, 0x01165000 }, 518c2ecf20Sopenharmony_ci { 0xB9AA, 0x000E0002 }, 528c2ecf20Sopenharmony_ci { 0xB9AB, 0x03884141 }, 538c2ecf20Sopenharmony_ci { 0xB9AC, 0x10000840 }, 548c2ecf20Sopenharmony_ci { 0xB9AD, 0x572A5000 }, 558c2ecf20Sopenharmony_ci { 0xB9AE, 0x00000003 }, 568c2ecf20Sopenharmony_ci { 0xB9AF, 0x00000000 }, 578c2ecf20Sopenharmony_ci { 0xB9B0, 0x10000000 }, 588c2ecf20Sopenharmony_ci { 0xB828, 0x6C204010 }, 598c2ecf20Sopenharmony_ci { 0xB829, 0x6C204011 }, 608c2ecf20Sopenharmony_ci { 0xB82A, 0x6C204012 }, 618c2ecf20Sopenharmony_ci { 0xB82B, 0x6C204013 }, 628c2ecf20Sopenharmony_ci { 0xB82C, 0x6C204014 }, 638c2ecf20Sopenharmony_ci { 0xB90F, 0x00000004 }, 648c2ecf20Sopenharmony_ci { 0xB910, 0x00000002 }, 658c2ecf20Sopenharmony_ci { 0xB911, 0x00000002 }, 668c2ecf20Sopenharmony_ci { 0xB912, 0x00000002 }, 678c2ecf20Sopenharmony_ci { 0xB913, 0x00000002 }, 688c2ecf20Sopenharmony_ci { 0xB92F, 0x00000004 }, 698c2ecf20Sopenharmony_ci { 0xB930, 0x00000005 }, 708c2ecf20Sopenharmony_ci { 0xB931, 0x00000005 }, 718c2ecf20Sopenharmony_ci { 0xB932, 0x00000005 }, 728c2ecf20Sopenharmony_ci { 0xB933, 0x00000005 }, 738c2ecf20Sopenharmony_ci { 0xB96F, 0x00000001 }, 748c2ecf20Sopenharmony_ci { 0xB970, 0x00000003 }, 758c2ecf20Sopenharmony_ci { 0xB94F, 0x00000004 }, 768c2ecf20Sopenharmony_ci { 0xB950, 0x0000000B }, 778c2ecf20Sopenharmony_ci { 0xB951, 0x0000000B }, 788c2ecf20Sopenharmony_ci { 0xB952, 0x0000000B }, 798c2ecf20Sopenharmony_ci { 0xB953, 0x0000000B }, 808c2ecf20Sopenharmony_ci { 0xB907, 0x00000019 }, 818c2ecf20Sopenharmony_ci { 0xB927, 0x00000019 }, 828c2ecf20Sopenharmony_ci { 0xB947, 0x00000019 }, 838c2ecf20Sopenharmony_ci { 0xB967, 0x00000019 }, 848c2ecf20Sopenharmony_ci { 0xB987, 0x00000019 }, 858c2ecf20Sopenharmony_ci { 0xB906, 0x00220001 }, 868c2ecf20Sopenharmony_ci { 0xB926, 0x00220001 }, 878c2ecf20Sopenharmony_ci { 0xB946, 0x00220001 }, 888c2ecf20Sopenharmony_ci { 0xB966, 0x00220001 }, 898c2ecf20Sopenharmony_ci { 0xB986, 0x00300000 }, 908c2ecf20Sopenharmony_ci { 0xAC40, 0x0340FF41 }, 918c2ecf20Sopenharmony_ci { 0xAC41, 0x03BEFED0 }, 928c2ecf20Sopenharmony_ci { 0xAC42, 0x00331FED }, 938c2ecf20Sopenharmony_ci { 0xAC43, 0x021FFDD3 }, 948c2ecf20Sopenharmony_ci { 0xAC44, 0x5555AAAA }, 958c2ecf20Sopenharmony_ci { 0xAC45, 0x5555AAAA }, 968c2ecf20Sopenharmony_ci { 0xB9BA, 0x00000008 }, 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* 1008c2ecf20Sopenharmony_ci * Get the actual voltage value for the operating point at the specified 1018c2ecf20Sopenharmony_ci * frequency 1028c2ecf20Sopenharmony_ci */ 1038c2ecf20Sopenharmony_cistatic inline uint32_t _get_mvolts(struct msm_gpu *gpu, uint32_t freq) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci struct drm_device *dev = gpu->dev; 1068c2ecf20Sopenharmony_ci struct msm_drm_private *priv = dev->dev_private; 1078c2ecf20Sopenharmony_ci struct platform_device *pdev = priv->gpu_pdev; 1088c2ecf20Sopenharmony_ci struct dev_pm_opp *opp; 1098c2ecf20Sopenharmony_ci u32 ret = 0; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci opp = dev_pm_opp_find_freq_exact(&pdev->dev, freq, true); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci if (!IS_ERR(opp)) { 1148c2ecf20Sopenharmony_ci ret = dev_pm_opp_get_voltage(opp) / 1000; 1158c2ecf20Sopenharmony_ci dev_pm_opp_put(opp); 1168c2ecf20Sopenharmony_ci } 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci return ret; 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* Setup thermal limit management */ 1228c2ecf20Sopenharmony_cistatic void a530_lm_setup(struct msm_gpu *gpu) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); 1258c2ecf20Sopenharmony_ci struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu); 1268c2ecf20Sopenharmony_ci unsigned int i; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci /* Write the block of sequence registers */ 1298c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(a5xx_sequence_regs); i++) 1308c2ecf20Sopenharmony_ci gpu_write(gpu, a5xx_sequence_regs[i].reg, 1318c2ecf20Sopenharmony_ci a5xx_sequence_regs[i].value); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* Hard code the A530 GPU thermal sensor ID for the GPMU */ 1348c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_TEMP_SENSOR_ID, 0x60007); 1358c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_DELTA_TEMP_THRESHOLD, 0x01); 1368c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_TEMP_SENSOR_CONFIG, 0x01); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci /* Until we get clock scaling 0 is always the active power level */ 1398c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_GPMU_VOLTAGE, 0x80000000 | 0); 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_BASE_LEAKAGE, a5xx_gpu->lm_leakage); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci /* The threshold is fixed at 6000 for A530 */ 1448c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_GPMU_PWR_THRESHOLD, 0x80000000 | 6000); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_BEC_ENABLE, 0x10001FFF); 1478c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GDPM_CONFIG1, 0x00201FF1); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci /* Write the voltage table */ 1508c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_BEC_ENABLE, 0x10001FFF); 1518c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GDPM_CONFIG1, 0x201FF1); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_STATE, 1); 1548c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_COMMAND, AGC_POWER_CONFIG_PRODUCTION_ID); 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci /* Write the max power - hard coded to 5448 for A530 */ 1578c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(0), 5448); 1588c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(1), 1); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci /* 1618c2ecf20Sopenharmony_ci * For now just write the one voltage level - we will do more when we 1628c2ecf20Sopenharmony_ci * can do scaling 1638c2ecf20Sopenharmony_ci */ 1648c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(2), _get_mvolts(gpu, gpu->fast_rate)); 1658c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(3), gpu->fast_rate / 1000000); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD_SIZE, 4 * sizeof(uint32_t)); 1688c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_INIT_MSG_MAGIC, AGC_INIT_MSG_VALUE); 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#define PAYLOAD_SIZE(_size) ((_size) * sizeof(u32)) 1728c2ecf20Sopenharmony_ci#define LM_DCVS_LIMIT 1 1738c2ecf20Sopenharmony_ci#define LEVEL_CONFIG ~(0x303) 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic void a540_lm_setup(struct msm_gpu *gpu) 1768c2ecf20Sopenharmony_ci{ 1778c2ecf20Sopenharmony_ci struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); 1788c2ecf20Sopenharmony_ci u32 config; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci /* The battery current limiter isn't enabled for A540 */ 1818c2ecf20Sopenharmony_ci config = AGC_LM_CONFIG_BCL_DISABLED; 1828c2ecf20Sopenharmony_ci config |= adreno_gpu->rev.patchid << AGC_LM_CONFIG_GPU_VERSION_SHIFT; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci /* For now disable GPMU side throttling */ 1858c2ecf20Sopenharmony_ci config |= AGC_LM_CONFIG_THROTTLE_DISABLE; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* Until we get clock scaling 0 is always the active power level */ 1888c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_GPMU_VOLTAGE, 0x80000000 | 0); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci /* Fixed at 6000 for now */ 1918c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_GPMU_PWR_THRESHOLD, 0x80000000 | 6000); 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_STATE, 0x80000001); 1948c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_COMMAND, AGC_POWER_CONFIG_PRODUCTION_ID); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(0), 5448); 1978c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(1), 1); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(2), _get_mvolts(gpu, gpu->fast_rate)); 2008c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(3), gpu->fast_rate / 1000000); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(AGC_LM_CONFIG), config); 2038c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD(AGC_LEVEL_CONFIG), LEVEL_CONFIG); 2048c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_MSG_PAYLOAD_SIZE, 2058c2ecf20Sopenharmony_ci PAYLOAD_SIZE(AGC_LEVEL_CONFIG + 1)); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci gpu_write(gpu, AGC_INIT_MSG_MAGIC, AGC_INIT_MSG_VALUE); 2088c2ecf20Sopenharmony_ci} 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* Enable SP/TP cpower collapse */ 2118c2ecf20Sopenharmony_cistatic void a5xx_pc_init(struct msm_gpu *gpu) 2128c2ecf20Sopenharmony_ci{ 2138c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_PWR_COL_INTER_FRAME_CTRL, 0x7F); 2148c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_PWR_COL_BINNING_CTRL, 0); 2158c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_PWR_COL_INTER_FRAME_HYST, 0xA0080); 2168c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_PWR_COL_STAGGER_DELAY, 0x600040); 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci/* Enable the GPMU microcontroller */ 2208c2ecf20Sopenharmony_cistatic int a5xx_gpmu_init(struct msm_gpu *gpu) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); 2238c2ecf20Sopenharmony_ci struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu); 2248c2ecf20Sopenharmony_ci struct msm_ringbuffer *ring = gpu->rb[0]; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci if (!a5xx_gpu->gpmu_dwords) 2278c2ecf20Sopenharmony_ci return 0; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci /* Turn off protected mode for this operation */ 2308c2ecf20Sopenharmony_ci OUT_PKT7(ring, CP_SET_PROTECTED_MODE, 1); 2318c2ecf20Sopenharmony_ci OUT_RING(ring, 0); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci /* Kick off the IB to load the GPMU microcode */ 2348c2ecf20Sopenharmony_ci OUT_PKT7(ring, CP_INDIRECT_BUFFER_PFE, 3); 2358c2ecf20Sopenharmony_ci OUT_RING(ring, lower_32_bits(a5xx_gpu->gpmu_iova)); 2368c2ecf20Sopenharmony_ci OUT_RING(ring, upper_32_bits(a5xx_gpu->gpmu_iova)); 2378c2ecf20Sopenharmony_ci OUT_RING(ring, a5xx_gpu->gpmu_dwords); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci /* Turn back on protected mode */ 2408c2ecf20Sopenharmony_ci OUT_PKT7(ring, CP_SET_PROTECTED_MODE, 1); 2418c2ecf20Sopenharmony_ci OUT_RING(ring, 1); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci a5xx_flush(gpu, ring, true); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci if (!a5xx_idle(gpu, ring)) { 2468c2ecf20Sopenharmony_ci DRM_ERROR("%s: Unable to load GPMU firmware. GPMU will not be active\n", 2478c2ecf20Sopenharmony_ci gpu->name); 2488c2ecf20Sopenharmony_ci return -EINVAL; 2498c2ecf20Sopenharmony_ci } 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci if (adreno_is_a530(adreno_gpu)) 2528c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_WFI_CONFIG, 0x4014); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci /* Kick off the GPMU */ 2558c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_CM3_SYSRESET, 0x0); 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci /* 2588c2ecf20Sopenharmony_ci * Wait for the GPMU to respond. It isn't fatal if it doesn't, we just 2598c2ecf20Sopenharmony_ci * won't have advanced power collapse. 2608c2ecf20Sopenharmony_ci */ 2618c2ecf20Sopenharmony_ci if (spin_usecs(gpu, 25, REG_A5XX_GPMU_GENERAL_0, 0xFFFFFFFF, 2628c2ecf20Sopenharmony_ci 0xBABEFACE)) 2638c2ecf20Sopenharmony_ci DRM_ERROR("%s: GPMU firmware initialization timed out\n", 2648c2ecf20Sopenharmony_ci gpu->name); 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci if (!adreno_is_a530(adreno_gpu)) { 2678c2ecf20Sopenharmony_ci u32 val = gpu_read(gpu, REG_A5XX_GPMU_GENERAL_1); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci if (val) 2708c2ecf20Sopenharmony_ci DRM_ERROR("%s: GPMU firmware initialization failed: %d\n", 2718c2ecf20Sopenharmony_ci gpu->name, val); 2728c2ecf20Sopenharmony_ci } 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci return 0; 2758c2ecf20Sopenharmony_ci} 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci/* Enable limits management */ 2788c2ecf20Sopenharmony_cistatic void a5xx_lm_enable(struct msm_gpu *gpu) 2798c2ecf20Sopenharmony_ci{ 2808c2ecf20Sopenharmony_ci struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci /* This init sequence only applies to A530 */ 2838c2ecf20Sopenharmony_ci if (!adreno_is_a530(adreno_gpu)) 2848c2ecf20Sopenharmony_ci return; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GDPM_INT_MASK, 0x0); 2878c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GDPM_INT_EN, 0x0A); 2888c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_GPMU_VOLTAGE_INTR_EN_MASK, 0x01); 2898c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_TEMP_THRESHOLD_INTR_EN_MASK, 0x50000); 2908c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_THROTTLE_UNMASK_FORCE_CTRL, 0x30000); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci gpu_write(gpu, REG_A5XX_GPMU_CLOCK_THROTTLE_CTRL, 0x011); 2938c2ecf20Sopenharmony_ci} 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ciint a5xx_power_init(struct msm_gpu *gpu) 2968c2ecf20Sopenharmony_ci{ 2978c2ecf20Sopenharmony_ci struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); 2988c2ecf20Sopenharmony_ci int ret; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci /* Not all A5xx chips have a GPMU */ 3018c2ecf20Sopenharmony_ci if (adreno_is_a510(adreno_gpu)) 3028c2ecf20Sopenharmony_ci return 0; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci /* Set up the limits management */ 3058c2ecf20Sopenharmony_ci if (adreno_is_a530(adreno_gpu)) 3068c2ecf20Sopenharmony_ci a530_lm_setup(gpu); 3078c2ecf20Sopenharmony_ci else if (adreno_is_a540(adreno_gpu)) 3088c2ecf20Sopenharmony_ci a540_lm_setup(gpu); 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci /* Set up SP/TP power collpase */ 3118c2ecf20Sopenharmony_ci a5xx_pc_init(gpu); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci /* Start the GPMU */ 3148c2ecf20Sopenharmony_ci ret = a5xx_gpmu_init(gpu); 3158c2ecf20Sopenharmony_ci if (ret) 3168c2ecf20Sopenharmony_ci return ret; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci /* Start the limits management */ 3198c2ecf20Sopenharmony_ci a5xx_lm_enable(gpu); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci return 0; 3228c2ecf20Sopenharmony_ci} 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_civoid a5xx_gpmu_ucode_init(struct msm_gpu *gpu) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); 3278c2ecf20Sopenharmony_ci struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu); 3288c2ecf20Sopenharmony_ci struct drm_device *drm = gpu->dev; 3298c2ecf20Sopenharmony_ci uint32_t dwords = 0, offset = 0, bosize; 3308c2ecf20Sopenharmony_ci unsigned int *data, *ptr, *cmds; 3318c2ecf20Sopenharmony_ci unsigned int cmds_size; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci if (adreno_is_a510(adreno_gpu)) 3348c2ecf20Sopenharmony_ci return; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci if (a5xx_gpu->gpmu_bo) 3378c2ecf20Sopenharmony_ci return; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci data = (unsigned int *) adreno_gpu->fw[ADRENO_FW_GPMU]->data; 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci /* 3428c2ecf20Sopenharmony_ci * The first dword is the size of the remaining data in dwords. Use it 3438c2ecf20Sopenharmony_ci * as a checksum of sorts and make sure it matches the actual size of 3448c2ecf20Sopenharmony_ci * the firmware that we read 3458c2ecf20Sopenharmony_ci */ 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci if (adreno_gpu->fw[ADRENO_FW_GPMU]->size < 8 || 3488c2ecf20Sopenharmony_ci (data[0] < 2) || (data[0] >= 3498c2ecf20Sopenharmony_ci (adreno_gpu->fw[ADRENO_FW_GPMU]->size >> 2))) 3508c2ecf20Sopenharmony_ci return; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci /* The second dword is an ID - look for 2 (GPMU_FIRMWARE_ID) */ 3538c2ecf20Sopenharmony_ci if (data[1] != 2) 3548c2ecf20Sopenharmony_ci return; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci cmds = data + data[2] + 3; 3578c2ecf20Sopenharmony_ci cmds_size = data[0] - data[2] - 2; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci /* 3608c2ecf20Sopenharmony_ci * A single type4 opcode can only have so many values attached so 3618c2ecf20Sopenharmony_ci * add enough opcodes to load the all the commands 3628c2ecf20Sopenharmony_ci */ 3638c2ecf20Sopenharmony_ci bosize = (cmds_size + (cmds_size / TYPE4_MAX_PAYLOAD) + 1) << 2; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci ptr = msm_gem_kernel_new_locked(drm, bosize, 3668c2ecf20Sopenharmony_ci MSM_BO_UNCACHED | MSM_BO_GPU_READONLY, gpu->aspace, 3678c2ecf20Sopenharmony_ci &a5xx_gpu->gpmu_bo, &a5xx_gpu->gpmu_iova); 3688c2ecf20Sopenharmony_ci if (IS_ERR(ptr)) 3698c2ecf20Sopenharmony_ci return; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci msm_gem_object_set_name(a5xx_gpu->gpmu_bo, "gpmufw"); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci while (cmds_size > 0) { 3748c2ecf20Sopenharmony_ci int i; 3758c2ecf20Sopenharmony_ci uint32_t _size = cmds_size > TYPE4_MAX_PAYLOAD ? 3768c2ecf20Sopenharmony_ci TYPE4_MAX_PAYLOAD : cmds_size; 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci ptr[dwords++] = PKT4(REG_A5XX_GPMU_INST_RAM_BASE + offset, 3798c2ecf20Sopenharmony_ci _size); 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci for (i = 0; i < _size; i++) 3828c2ecf20Sopenharmony_ci ptr[dwords++] = *cmds++; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci offset += _size; 3858c2ecf20Sopenharmony_ci cmds_size -= _size; 3868c2ecf20Sopenharmony_ci } 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci msm_gem_put_vaddr(a5xx_gpu->gpmu_bo); 3898c2ecf20Sopenharmony_ci a5xx_gpu->gpmu_dwords = dwords; 3908c2ecf20Sopenharmony_ci} 391