Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

@@ -0,0 +1,35 @@
#
# (C) COPYRIGHT 2012-2013, 2016-2017 ARM Limited. All rights reserved.
#
# This program is free software and is provided to you under the terms of the
# GNU General Public License version 2 as published by the Free Software
# Foundation, and any use by you of this program is subject to the terms
# of such GNU licence.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# SPDX-License-Identifier: GPL-2.0
#
#
include $(src)/Kbuild-mtk-custom-env
mali_kbase-y += \
$(MALI_PLATFORM_DIR)/mali_kbase_config_mt6873.o \
$(MALI_PLATFORM_DIR)/mali_kbase_cpu_mt6873.o \
# mali_kbase_platform_fake.o
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/base/power/include
ifeq ($(CONFIG_MTK_TINYSYS_SSPM_SUPPORT), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(CONFIG_MTK_PLATFORM)
endif
@@ -0,0 +1,265 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <mali_kbase.h>
#include <mali_kbase_defs.h>
#include <mali_kbase_config.h>
#include "mali_kbase_cpu_mt6873.h"
#include "mali_kbase_config_platform.h"
#include "platform/mtk_platform_common.h"
#include "ged_dvfs.h"
#include "mtk_gpufreq.h"
#include "mtk_idle.h"
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
#include <mtk_gpu_power_sspm_ipi.h>
#endif
#define MALI_TAG "[GPU/MALI]"
#define mali_pr_info(fmt, args...) pr_info(MALI_TAG"[INFO]"fmt, ##args)
#define mali_pr_debug(fmt, args...) pr_debug(MALI_TAG"[DEBUG]"fmt, ##args)
DEFINE_MUTEX(g_mfg_lock);
//FIXME
static int g_curFreqID;
static int g_is_suspend;
enum gpu_dvfs_status_step {
GPU_DVFS_STATUS_STEP_1 = 0x1,
GPU_DVFS_STATUS_STEP_2 = 0x2,
GPU_DVFS_STATUS_STEP_3 = 0x3,
GPU_DVFS_STATUS_STEP_4 = 0x4,
GPU_DVFS_STATUS_STEP_5 = 0x5,
GPU_DVFS_STATUS_STEP_6 = 0x6,
GPU_DVFS_STATUS_STEP_7 = 0x7,
GPU_DVFS_STATUS_STEP_8 = 0x8,
GPU_DVFS_STATUS_STEP_9 = 0x9,
GPU_DVFS_STATUS_STEP_A = 0xA,
GPU_DVFS_STATUS_STEP_B = 0xB,
GPU_DVFS_STATUS_STEP_C = 0xC,
GPU_DVFS_STATUS_STEP_D = 0xD,
GPU_DVFS_STATUS_STEP_E = 0xE,
GPU_DVFS_STATUS_STEP_F = 0xF,
};
static inline void gpu_dvfs_status_footprint(enum gpu_dvfs_status_step step)
{
#ifdef CONFIG_MTK_RAM_CONSOLE
aee_rr_rec_gpu_dvfs_status(step |
(aee_rr_curr_gpu_dvfs_status() & 0xF0));
#endif
}
static inline void gpu_dvfs_status_reset_footprint(void)
{
#ifdef CONFIG_MTK_RAM_CONSOLE
aee_rr_rec_gpu_dvfs_status(0);
#endif
}
static int pm_callback_power_on_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup()) {
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
return 1;
}
if (!mt_gpufreq_power_ctl_en()) {
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
ged_dvfs_gpu_clock_switch_notify(1);
return 1;
}
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_ON)
return 0;
mali_pr_debug("@%s: power on ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_1);
if (g_is_suspend == 1) {
mali_pr_info("@%s: discard powering on since GPU is suspended\n", __func__);
return 0;
}
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_ON, CG_ON, MTCMOS_ON, BUCK_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_2);
mt_gpufreq_set_timestamp();
/* set a flag to enable GPU DVFS */
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_3);
/* resume frequency */
mtk_set_mt_gpufreq_target(g_curFreqID);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_4);
#ifdef ENABLE_COMMON_DVFS
ged_dvfs_gpu_clock_switch_notify(1);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_5);
return 1;
}
static void pm_callback_power_off_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup())
return;
if (!mt_gpufreq_power_ctl_en())
return;
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_OFF)
return;
mali_pr_debug("@%s: power off ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_6);
#ifdef ENABLE_COMMON_DVFS
ged_dvfs_gpu_clock_switch_notify(0);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_7);
/* set a flag to disable GPU DVFS */
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_8);
/* suspend frequency */
g_curFreqID = mtk_get_ged_dvfs_last_commit_idx();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_9);
/* check MFG bus if idle */
mt_gpufreq_check_bus_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_A);
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_OFF, CG_OFF, MTCMOS_OFF, BUCK_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_B);
}
static int pm_callback_power_on(struct kbase_device *kbdev)
{
int ret = 0;
mutex_lock(&g_mfg_lock);
ret = pm_callback_power_on_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
MTKGPUPower_model_resume();
#endif
return ret;
}
static void pm_callback_power_off(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
MTKGPUPower_model_suspend();
#endif
pm_callback_power_off_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_suspend(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_ON) {
pm_callback_power_off_nolock(kbdev);
mali_pr_info("@%s: force powering off GPU\n", __func__);
}
g_is_suspend = 1;
mali_pr_info("@%s: gpu_suspend\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_E);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_resume(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
g_is_suspend = 0;
mali_pr_info("@%s: gpu_resume\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_F);
mutex_unlock(&g_mfg_lock);
}
struct kbase_pm_callback_conf pm_callbacks = {
.power_on_callback = pm_callback_power_on,
.power_off_callback = pm_callback_power_off,
.power_suspend_callback = pm_callback_power_suspend,
.power_resume_callback = pm_callback_power_resume,
};
#ifndef CONFIG_OF
static struct kbase_io_resources io_resources = {
.job_irq_number = 68,
.mmu_irq_number = 69,
.gpu_irq_number = 70,
.io_memory_region = {
.start = 0xFC010000,
.end = 0xFC010000 + (4096 * 4) - 1
}
};
#endif
static struct kbase_platform_config versatile_platform_config = {
#ifndef CONFIG_OF
.io_resources = &io_resources
#endif
};
struct kbase_platform_config *kbase_get_platform_config(void)
{
return &versatile_platform_config;
}
int kbase_platform_early_init(void)
{
/* Nothing needed at this stage */
return 0;
}
int mtk_platform_init(struct kbase_device *kbdev)
{
if (!kbdev) {
mali_pr_info("@%s: input parameter is NULL\n", __func__);
return -1;
}
gpu_dvfs_status_reset_footprint();
//FIXME
g_is_suspend = -1;
mali_pr_info("@%s: initialize successfully\n", __func__);
return 0;
}
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "mali_kbase_cpu_mt6873.h"
/**
* Maximum frequency GPU will be clocked at. Given in kHz.
* This must be specified as there is no default value.
*
* Attached value: number in kHz
* Default value: NA
*/
#define GPU_FREQ_KHZ_MAX kbase_get_platform_max_freq()
/**
* Minimum frequency GPU will be clocked at. Given in kHz.
* This must be specified as there is no default value.
*
* Attached value: number in kHz
* Default value: NA
*/
#define GPU_FREQ_KHZ_MIN kbase_get_platform_min_freq()
/**
* CPU_SPEED_FUNC - A pointer to a function that calculates the CPU clock
*
* CPU clock speed of the platform is in MHz - see kbase_cpu_clk_speed_func
* for the function prototype.
*
* Attached value: A kbase_cpu_clk_speed_func.
* Default Value: NA
*/
#define CPU_SPEED_FUNC (&kbase_get_vexpress_cpu_clock_speed)
/**
* GPU_SPEED_FUNC - A pointer to a function that calculates the GPU clock
*
* GPU clock speed of the platform in MHz - see kbase_gpu_clk_speed_func
* for the function prototype.
*
* Attached value: A kbase_gpu_clk_speed_func.
* Default Value: NA
*/
#define GPU_SPEED_FUNC (NULL)
/**
* Power management configuration
*
* Attached value: pointer to @ref kbase_pm_callback_conf
* Default value: See @ref kbase_pm_callback_conf
*/
#define POWER_MANAGEMENT_CALLBACKS (&pm_callbacks)
/**
* Platform specific configuration functions
*
* Attached value: pointer to @ref kbase_platform_funcs_conf
* Default value: See @ref kbase_platform_funcs_conf
*/
#define PLATFORM_FUNCS (NULL)
extern struct kbase_pm_callback_conf pm_callbacks;
@@ -0,0 +1,273 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/io.h>
#include <mali_kbase.h>
#include "mali_kbase_cpu_mt6873.h"
#define HZ_IN_MHZ (1000000)
#define CORETILE_EXPRESS_A9X4_SCC_START (0x100E2000)
#define MOTHERBOARD_SYS_CFG_START (0x10000000)
#define SYS_CFGDATA_OFFSET (0x000000A0)
#define SYS_CFGCTRL_OFFSET (0x000000A4)
#define SYS_CFGSTAT_OFFSET (0x000000A8)
#define SYS_CFGCTRL_START_BIT_VALUE (1 << 31)
#define READ_REG_BIT_VALUE (0 << 30)
#define DCC_DEFAULT_BIT_VALUE (0 << 26)
#define SYS_CFG_OSC_FUNC_BIT_VALUE (1 << 20)
#define SITE_DEFAULT_BIT_VALUE (1 << 16)
#define BOARD_STACK_POS_DEFAULT_BIT_VALUE (0 << 12)
#define DEVICE_DEFAULT_BIT_VALUE (2 << 0)
#define SYS_CFG_COMPLETE_BIT_VALUE (1 << 0)
#define SYS_CFG_ERROR_BIT_VALUE (1 << 1)
#define FEED_REG_BIT_MASK (0x0F)
#define FCLK_PA_DIVIDE_BIT_SHIFT (0x03)
#define FCLK_PB_DIVIDE_BIT_SHIFT (0x07)
#define FCLK_PC_DIVIDE_BIT_SHIFT (0x0B)
#define AXICLK_PA_DIVIDE_BIT_SHIFT (0x0F)
#define AXICLK_PB_DIVIDE_BIT_SHIFT (0x13)
/* the following three values used for reading
* HBI value of the LogicTile daughterboard
*/
#define VE_MOTHERBOARD_PERIPHERALS_SMB_CS7 (0x10000000)
#define VE_SYS_PROC_ID1_OFFSET (0x00000088)
#define VE_LOGIC_TILE_HBI_MASK (0x00000FFF)
#define IS_SINGLE_BIT_SET(val, pos) (val&(1<<pos))
/**
* Values used for determining the GPU frequency based on the LogicTile type
* Used by the function kbase_get_platform_logic_tile_type
*/
#define VE_VIRTEX6_GPU_FREQ_MIN 5000
#define VE_VIRTEX6_GPU_FREQ_MAX 5000
#define VE_VIRTEX7_GPU_FREQ_MIN 40000
#define VE_VIRTEX7_GPU_FREQ_MAX 40000
#define VE_DEFAULT_GPU_FREQ_MIN 5000
#define VE_DEFAULT_GPU_FREQ_MAX 5000
#define CPU_CLOCK_SPEED_UNDEFINED (0)
static u32 cpu_clock_speed = CPU_CLOCK_SPEED_UNDEFINED;
static DEFINE_RAW_SPINLOCK(syscfg_lock);
/**
* kbase_get_vendor_specific_cpu_clock_speed -Retrieves the CPU clock speed
* @cpu_clock - the value of CPU clock speed in MHz
*
* Returns 0 on success, error code otherwise.
*
* The implementation is platform specific.
*/
int kbase_get_vexpress_cpu_clock_speed(u32 *cpu_clock)
{
int err = 0;
u32 reg_val = 0;
u32 osc2_value = 0;
u32 pa_divide = 0;
u32 pb_divide = 0;
u32 pc_divide = 0;
void __iomem *syscfg_reg = NULL;
void __iomem *scc_reg = NULL;
if (CPU_CLOCK_SPEED_UNDEFINED != cpu_clock_speed) {
*cpu_clock = cpu_clock_speed;
return 0;
}
/* Init the value in case something goes wrong */
*cpu_clock = 0;
/* Map CPU register into virtual memory */
syscfg_reg = ioremap(MOTHERBOARD_SYS_CFG_START, 0x1000);
if (syscfg_reg == NULL) {
err = -EIO;
goto syscfg_reg_map_failed;
}
scc_reg = ioremap(CORETILE_EXPRESS_A9X4_SCC_START, 0x1000);
if (scc_reg == NULL) {
err = -EIO;
goto scc_reg_map_failed;
}
raw_spin_lock(&syscfg_lock);
/* Read SYS regs - OSC2 */
reg_val = readl(syscfg_reg + SYS_CFGCTRL_OFFSET);
/* Check if there is any other undergoing request */
if (reg_val & SYS_CFGCTRL_START_BIT_VALUE) {
err = -EBUSY;
goto ongoing_request;
}
/* Reset the CGFGSTAT reg */
writel(0, (syscfg_reg + SYS_CFGSTAT_OFFSET));
writel(SYS_CFGCTRL_START_BIT_VALUE | READ_REG_BIT_VALUE |
DCC_DEFAULT_BIT_VALUE |
SYS_CFG_OSC_FUNC_BIT_VALUE |
SITE_DEFAULT_BIT_VALUE |
BOARD_STACK_POS_DEFAULT_BIT_VALUE |
DEVICE_DEFAULT_BIT_VALUE,
(syscfg_reg + SYS_CFGCTRL_OFFSET));
/* Wait for the transaction to complete */
while (!(readl(syscfg_reg + SYS_CFGSTAT_OFFSET) &
SYS_CFG_COMPLETE_BIT_VALUE))
;
/* Read SYS_CFGSTAT Register to get the status of submitted
* transaction
*/
reg_val = readl(syscfg_reg + SYS_CFGSTAT_OFFSET);
if (reg_val & SYS_CFG_ERROR_BIT_VALUE) {
/* Error while setting register */
err = -EIO;
goto set_reg_error;
}
osc2_value = readl(syscfg_reg + SYS_CFGDATA_OFFSET);
/* Read the SCC CFGRW0 register */
reg_val = readl(scc_reg);
/*
* Select the appropriate feed:
* CFGRW0[0] - CLKOB
* CFGRW0[1] - CLKOC
* CFGRW0[2] - FACLK (CLK)B FROM AXICLK PLL)
*/
/* Calculate the FCLK */
if (IS_SINGLE_BIT_SET(reg_val, 0)) {
/* CFGRW0[0] - CLKOB */
/* CFGRW0[6:3] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PA_DIVIDE_BIT_SHIFT)) >>
FCLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[10:7] */
pb_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PB_DIVIDE_BIT_SHIFT)) >>
FCLK_PB_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pb_divide + 1);
} else if (IS_SINGLE_BIT_SET(reg_val, 1)) {
/* CFGRW0[1] - CLKOC */
/* CFGRW0[6:3] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PA_DIVIDE_BIT_SHIFT)) >>
FCLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[14:11] */
pc_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PC_DIVIDE_BIT_SHIFT)) >>
FCLK_PC_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pc_divide + 1);
} else if (IS_SINGLE_BIT_SET(reg_val, 2)) {
/* CFGRW0[2] - FACLK */
/* CFGRW0[18:15] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
AXICLK_PA_DIVIDE_BIT_SHIFT)) >>
AXICLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[22:19] */
pb_divide = ((reg_val & (FEED_REG_BIT_MASK <<
AXICLK_PB_DIVIDE_BIT_SHIFT)) >>
AXICLK_PB_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pb_divide + 1);
} else {
err = -EIO;
}
set_reg_error:
ongoing_request:
raw_spin_unlock(&syscfg_lock);
*cpu_clock /= HZ_IN_MHZ;
if (!err)
cpu_clock_speed = *cpu_clock;
iounmap(scc_reg);
scc_reg_map_failed:
iounmap(syscfg_reg);
syscfg_reg_map_failed:
return err;
}
/**
* kbase_get_platform_logic_tile_type - determines which LogicTile type
* is used by Versatile Express
*
* When platform_config build parameter is specified as vexpress, i.e.,
* platform_config=vexpress, GPU frequency may vary dependent on the
* particular platform. The GPU frequency depends on the LogicTile type.
*
* This function determines which LogicTile type is used by the platform by
* reading the HBI value of the daughterboard which holds the LogicTile:
*
* 0x217 HBI0217 Virtex-6
* 0x192 HBI0192 Virtex-5
* 0x247 HBI0247 Virtex-7
*
* Return: HBI value of the logic tile daughterboard, zero if not accessible
*/
static u32 kbase_get_platform_logic_tile_type(void)
{
void __iomem *syscfg_reg = NULL;
u32 sys_procid1 = 0;
syscfg_reg = ioremap(VE_MOTHERBOARD_PERIPHERALS_SMB_CS7 + VE_SYS_PROC_ID1_OFFSET, 4);
if (NULL != syscfg_reg) {
sys_procid1 = readl(syscfg_reg);
iounmap(syscfg_reg);
}
return sys_procid1 & VE_LOGIC_TILE_HBI_MASK;
}
u32 kbase_get_platform_min_freq(void)
{
u32 ve_logic_tile = kbase_get_platform_logic_tile_type();
switch (ve_logic_tile) {
case 0x217:
/* Virtex 6, HBI0217 */
return VE_VIRTEX6_GPU_FREQ_MIN;
case 0x247:
/* Virtex 7, HBI0247 */
return VE_VIRTEX7_GPU_FREQ_MIN;
default:
/* all other logic tiles, i.e., Virtex 5 HBI0192
* or unsuccessful reading from the platform -
* fall back to some default value
*/
return VE_DEFAULT_GPU_FREQ_MIN;
}
}
u32 kbase_get_platform_max_freq(void)
{
u32 ve_logic_tile = kbase_get_platform_logic_tile_type();
switch (ve_logic_tile) {
case 0x217:
/* Virtex 6, HBI0217 */
return VE_VIRTEX6_GPU_FREQ_MAX;
case 0x247:
/* Virtex 7, HBI0247 */
return VE_VIRTEX7_GPU_FREQ_MAX;
default:
/* all other logic tiles, i.e., Virtex 5 HBI0192
* or unsuccessful reading from the platform -
* fall back to some default value
*/
return VE_DEFAULT_GPU_FREQ_MAX;
}
}
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _KBASE_CPU_VEXPRESS_H_
#define _KBASE_CPU_VEXPRESS_H_
/**
* Versatile Express implementation of @ref kbase_cpu_clk_speed_func.
*/
int kbase_get_vexpress_cpu_clock_speed(u32 *cpu_clock);
/**
* Get the minimum GPU frequency for the attached logic tile
*/
u32 kbase_get_platform_min_freq(void);
/**
* Get the maximum GPU frequency for the attached logic tile
*/
u32 kbase_get_platform_max_freq(void);
#endif /* _KBASE_CPU_VEXPRESS_H_ */
@@ -0,0 +1,35 @@
#
# (C) COPYRIGHT 2012-2013, 2016-2017 ARM Limited. All rights reserved.
#
# This program is free software and is provided to you under the terms of the
# GNU General Public License version 2 as published by the Free Software
# Foundation, and any use by you of this program is subject to the terms
# of such GNU licence.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# SPDX-License-Identifier: GPL-2.0
#
#
include $(src)/Kbuild-mtk-custom-env
mali_kbase-y += \
$(MALI_PLATFORM_DIR)/mali_kbase_config_mt6873.o \
$(MALI_PLATFORM_DIR)/mali_kbase_cpu_mt6873.o \
# mali_kbase_platform_fake.o
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/base/power/include
ifeq ($(CONFIG_MTK_TINYSYS_SSPM_SUPPORT), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(CONFIG_MTK_PLATFORM)
endif
@@ -0,0 +1,265 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <mali_kbase.h>
#include <mali_kbase_defs.h>
#include <mali_kbase_config.h>
#include "mali_kbase_cpu_mt6873.h"
#include "mali_kbase_config_platform.h"
#include "platform/mtk_platform_common.h"
#include "ged_dvfs.h"
#include "mtk_gpufreq.h"
#include "mtk_idle.h"
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
#include <mtk_gpu_power_sspm_ipi.h>
#endif
#define MALI_TAG "[GPU/MALI]"
#define mali_pr_info(fmt, args...) pr_info(MALI_TAG"[INFO]"fmt, ##args)
#define mali_pr_debug(fmt, args...) pr_debug(MALI_TAG"[DEBUG]"fmt, ##args)
DEFINE_MUTEX(g_mfg_lock);
//FIXME
static int g_curFreqID;
static int g_is_suspend;
enum gpu_dvfs_status_step {
GPU_DVFS_STATUS_STEP_1 = 0x1,
GPU_DVFS_STATUS_STEP_2 = 0x2,
GPU_DVFS_STATUS_STEP_3 = 0x3,
GPU_DVFS_STATUS_STEP_4 = 0x4,
GPU_DVFS_STATUS_STEP_5 = 0x5,
GPU_DVFS_STATUS_STEP_6 = 0x6,
GPU_DVFS_STATUS_STEP_7 = 0x7,
GPU_DVFS_STATUS_STEP_8 = 0x8,
GPU_DVFS_STATUS_STEP_9 = 0x9,
GPU_DVFS_STATUS_STEP_A = 0xA,
GPU_DVFS_STATUS_STEP_B = 0xB,
GPU_DVFS_STATUS_STEP_C = 0xC,
GPU_DVFS_STATUS_STEP_D = 0xD,
GPU_DVFS_STATUS_STEP_E = 0xE,
GPU_DVFS_STATUS_STEP_F = 0xF,
};
static inline void gpu_dvfs_status_footprint(enum gpu_dvfs_status_step step)
{
#ifdef CONFIG_MTK_RAM_CONSOLE
aee_rr_rec_gpu_dvfs_status(step |
(aee_rr_curr_gpu_dvfs_status() & 0xF0));
#endif
}
static inline void gpu_dvfs_status_reset_footprint(void)
{
#ifdef CONFIG_MTK_RAM_CONSOLE
aee_rr_rec_gpu_dvfs_status(0);
#endif
}
static int pm_callback_power_on_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup()) {
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
return 1;
}
if (!mt_gpufreq_power_ctl_en()) {
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
ged_dvfs_gpu_clock_switch_notify(1);
return 1;
}
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_ON)
return 0;
mali_pr_debug("@%s: power on ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_1);
if (g_is_suspend == 1) {
mali_pr_info("@%s: discard powering on since GPU is suspended\n", __func__);
return 0;
}
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_ON, CG_ON, MTCMOS_ON, BUCK_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_2);
mt_gpufreq_set_timestamp();
/* set a flag to enable GPU DVFS */
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_3);
/* resume frequency */
mtk_set_mt_gpufreq_target(g_curFreqID);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_4);
#ifdef ENABLE_COMMON_DVFS
ged_dvfs_gpu_clock_switch_notify(1);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_5);
return 1;
}
static void pm_callback_power_off_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup())
return;
if (!mt_gpufreq_power_ctl_en())
return;
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_OFF)
return;
mali_pr_debug("@%s: power off ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_6);
#ifdef ENABLE_COMMON_DVFS
ged_dvfs_gpu_clock_switch_notify(0);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_7);
/* set a flag to disable GPU DVFS */
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_8);
/* suspend frequency */
g_curFreqID = mtk_get_ged_dvfs_last_commit_idx();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_9);
/* check MFG bus if idle */
mt_gpufreq_check_bus_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_A);
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_OFF, CG_OFF, MTCMOS_OFF, BUCK_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_B);
}
static int pm_callback_power_on(struct kbase_device *kbdev)
{
int ret = 0;
mutex_lock(&g_mfg_lock);
ret = pm_callback_power_on_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
MTKGPUPower_model_resume();
#endif
return ret;
}
static void pm_callback_power_off(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
MTKGPUPower_model_suspend();
#endif
pm_callback_power_off_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_suspend(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_ON) {
pm_callback_power_off_nolock(kbdev);
mali_pr_info("@%s: force powering off GPU\n", __func__);
}
g_is_suspend = 1;
mali_pr_info("@%s: gpu_suspend\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_E);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_resume(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
g_is_suspend = 0;
mali_pr_info("@%s: gpu_resume\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_F);
mutex_unlock(&g_mfg_lock);
}
struct kbase_pm_callback_conf pm_callbacks = {
.power_on_callback = pm_callback_power_on,
.power_off_callback = pm_callback_power_off,
.power_suspend_callback = pm_callback_power_suspend,
.power_resume_callback = pm_callback_power_resume,
};
#ifndef CONFIG_OF
static struct kbase_io_resources io_resources = {
.job_irq_number = 68,
.mmu_irq_number = 69,
.gpu_irq_number = 70,
.io_memory_region = {
.start = 0xFC010000,
.end = 0xFC010000 + (4096 * 4) - 1
}
};
#endif
static struct kbase_platform_config versatile_platform_config = {
#ifndef CONFIG_OF
.io_resources = &io_resources
#endif
};
struct kbase_platform_config *kbase_get_platform_config(void)
{
return &versatile_platform_config;
}
int kbase_platform_early_init(void)
{
/* Nothing needed at this stage */
return 0;
}
int mtk_platform_init(struct kbase_device *kbdev)
{
if (!kbdev) {
mali_pr_info("@%s: input parameter is NULL\n", __func__);
return -1;
}
gpu_dvfs_status_reset_footprint();
//FIXME
g_is_suspend = -1;
mali_pr_info("@%s: initialize successfully\n", __func__);
return 0;
}
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "mali_kbase_cpu_mt6873.h"
/**
* Maximum frequency GPU will be clocked at. Given in kHz.
* This must be specified as there is no default value.
*
* Attached value: number in kHz
* Default value: NA
*/
#define GPU_FREQ_KHZ_MAX kbase_get_platform_max_freq()
/**
* Minimum frequency GPU will be clocked at. Given in kHz.
* This must be specified as there is no default value.
*
* Attached value: number in kHz
* Default value: NA
*/
#define GPU_FREQ_KHZ_MIN kbase_get_platform_min_freq()
/**
* CPU_SPEED_FUNC - A pointer to a function that calculates the CPU clock
*
* CPU clock speed of the platform is in MHz - see kbase_cpu_clk_speed_func
* for the function prototype.
*
* Attached value: A kbase_cpu_clk_speed_func.
* Default Value: NA
*/
#define CPU_SPEED_FUNC (&kbase_get_vexpress_cpu_clock_speed)
/**
* GPU_SPEED_FUNC - A pointer to a function that calculates the GPU clock
*
* GPU clock speed of the platform in MHz - see kbase_gpu_clk_speed_func
* for the function prototype.
*
* Attached value: A kbase_gpu_clk_speed_func.
* Default Value: NA
*/
#define GPU_SPEED_FUNC (NULL)
/**
* Power management configuration
*
* Attached value: pointer to @ref kbase_pm_callback_conf
* Default value: See @ref kbase_pm_callback_conf
*/
#define POWER_MANAGEMENT_CALLBACKS (&pm_callbacks)
/**
* Platform specific configuration functions
*
* Attached value: pointer to @ref kbase_platform_funcs_conf
* Default value: See @ref kbase_platform_funcs_conf
*/
#define PLATFORM_FUNCS (NULL)
extern struct kbase_pm_callback_conf pm_callbacks;
@@ -0,0 +1,273 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/io.h>
#include <mali_kbase.h>
#include "mali_kbase_cpu_mt6873.h"
#define HZ_IN_MHZ (1000000)
#define CORETILE_EXPRESS_A9X4_SCC_START (0x100E2000)
#define MOTHERBOARD_SYS_CFG_START (0x10000000)
#define SYS_CFGDATA_OFFSET (0x000000A0)
#define SYS_CFGCTRL_OFFSET (0x000000A4)
#define SYS_CFGSTAT_OFFSET (0x000000A8)
#define SYS_CFGCTRL_START_BIT_VALUE (1 << 31)
#define READ_REG_BIT_VALUE (0 << 30)
#define DCC_DEFAULT_BIT_VALUE (0 << 26)
#define SYS_CFG_OSC_FUNC_BIT_VALUE (1 << 20)
#define SITE_DEFAULT_BIT_VALUE (1 << 16)
#define BOARD_STACK_POS_DEFAULT_BIT_VALUE (0 << 12)
#define DEVICE_DEFAULT_BIT_VALUE (2 << 0)
#define SYS_CFG_COMPLETE_BIT_VALUE (1 << 0)
#define SYS_CFG_ERROR_BIT_VALUE (1 << 1)
#define FEED_REG_BIT_MASK (0x0F)
#define FCLK_PA_DIVIDE_BIT_SHIFT (0x03)
#define FCLK_PB_DIVIDE_BIT_SHIFT (0x07)
#define FCLK_PC_DIVIDE_BIT_SHIFT (0x0B)
#define AXICLK_PA_DIVIDE_BIT_SHIFT (0x0F)
#define AXICLK_PB_DIVIDE_BIT_SHIFT (0x13)
/* the following three values used for reading
* HBI value of the LogicTile daughterboard
*/
#define VE_MOTHERBOARD_PERIPHERALS_SMB_CS7 (0x10000000)
#define VE_SYS_PROC_ID1_OFFSET (0x00000088)
#define VE_LOGIC_TILE_HBI_MASK (0x00000FFF)
#define IS_SINGLE_BIT_SET(val, pos) (val&(1<<pos))
/**
* Values used for determining the GPU frequency based on the LogicTile type
* Used by the function kbase_get_platform_logic_tile_type
*/
#define VE_VIRTEX6_GPU_FREQ_MIN 5000
#define VE_VIRTEX6_GPU_FREQ_MAX 5000
#define VE_VIRTEX7_GPU_FREQ_MIN 40000
#define VE_VIRTEX7_GPU_FREQ_MAX 40000
#define VE_DEFAULT_GPU_FREQ_MIN 5000
#define VE_DEFAULT_GPU_FREQ_MAX 5000
#define CPU_CLOCK_SPEED_UNDEFINED (0)
static u32 cpu_clock_speed = CPU_CLOCK_SPEED_UNDEFINED;
static DEFINE_RAW_SPINLOCK(syscfg_lock);
/**
* kbase_get_vendor_specific_cpu_clock_speed -Retrieves the CPU clock speed
* @cpu_clock - the value of CPU clock speed in MHz
*
* Returns 0 on success, error code otherwise.
*
* The implementation is platform specific.
*/
int kbase_get_vexpress_cpu_clock_speed(u32 *cpu_clock)
{
int err = 0;
u32 reg_val = 0;
u32 osc2_value = 0;
u32 pa_divide = 0;
u32 pb_divide = 0;
u32 pc_divide = 0;
void __iomem *syscfg_reg = NULL;
void __iomem *scc_reg = NULL;
if (CPU_CLOCK_SPEED_UNDEFINED != cpu_clock_speed) {
*cpu_clock = cpu_clock_speed;
return 0;
}
/* Init the value in case something goes wrong */
*cpu_clock = 0;
/* Map CPU register into virtual memory */
syscfg_reg = ioremap(MOTHERBOARD_SYS_CFG_START, 0x1000);
if (syscfg_reg == NULL) {
err = -EIO;
goto syscfg_reg_map_failed;
}
scc_reg = ioremap(CORETILE_EXPRESS_A9X4_SCC_START, 0x1000);
if (scc_reg == NULL) {
err = -EIO;
goto scc_reg_map_failed;
}
raw_spin_lock(&syscfg_lock);
/* Read SYS regs - OSC2 */
reg_val = readl(syscfg_reg + SYS_CFGCTRL_OFFSET);
/* Check if there is any other undergoing request */
if (reg_val & SYS_CFGCTRL_START_BIT_VALUE) {
err = -EBUSY;
goto ongoing_request;
}
/* Reset the CGFGSTAT reg */
writel(0, (syscfg_reg + SYS_CFGSTAT_OFFSET));
writel(SYS_CFGCTRL_START_BIT_VALUE | READ_REG_BIT_VALUE |
DCC_DEFAULT_BIT_VALUE |
SYS_CFG_OSC_FUNC_BIT_VALUE |
SITE_DEFAULT_BIT_VALUE |
BOARD_STACK_POS_DEFAULT_BIT_VALUE |
DEVICE_DEFAULT_BIT_VALUE,
(syscfg_reg + SYS_CFGCTRL_OFFSET));
/* Wait for the transaction to complete */
while (!(readl(syscfg_reg + SYS_CFGSTAT_OFFSET) &
SYS_CFG_COMPLETE_BIT_VALUE))
;
/* Read SYS_CFGSTAT Register to get the status of submitted
* transaction
*/
reg_val = readl(syscfg_reg + SYS_CFGSTAT_OFFSET);
if (reg_val & SYS_CFG_ERROR_BIT_VALUE) {
/* Error while setting register */
err = -EIO;
goto set_reg_error;
}
osc2_value = readl(syscfg_reg + SYS_CFGDATA_OFFSET);
/* Read the SCC CFGRW0 register */
reg_val = readl(scc_reg);
/*
* Select the appropriate feed:
* CFGRW0[0] - CLKOB
* CFGRW0[1] - CLKOC
* CFGRW0[2] - FACLK (CLK)B FROM AXICLK PLL)
*/
/* Calculate the FCLK */
if (IS_SINGLE_BIT_SET(reg_val, 0)) {
/* CFGRW0[0] - CLKOB */
/* CFGRW0[6:3] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PA_DIVIDE_BIT_SHIFT)) >>
FCLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[10:7] */
pb_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PB_DIVIDE_BIT_SHIFT)) >>
FCLK_PB_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pb_divide + 1);
} else if (IS_SINGLE_BIT_SET(reg_val, 1)) {
/* CFGRW0[1] - CLKOC */
/* CFGRW0[6:3] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PA_DIVIDE_BIT_SHIFT)) >>
FCLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[14:11] */
pc_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PC_DIVIDE_BIT_SHIFT)) >>
FCLK_PC_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pc_divide + 1);
} else if (IS_SINGLE_BIT_SET(reg_val, 2)) {
/* CFGRW0[2] - FACLK */
/* CFGRW0[18:15] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
AXICLK_PA_DIVIDE_BIT_SHIFT)) >>
AXICLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[22:19] */
pb_divide = ((reg_val & (FEED_REG_BIT_MASK <<
AXICLK_PB_DIVIDE_BIT_SHIFT)) >>
AXICLK_PB_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pb_divide + 1);
} else {
err = -EIO;
}
set_reg_error:
ongoing_request:
raw_spin_unlock(&syscfg_lock);
*cpu_clock /= HZ_IN_MHZ;
if (!err)
cpu_clock_speed = *cpu_clock;
iounmap(scc_reg);
scc_reg_map_failed:
iounmap(syscfg_reg);
syscfg_reg_map_failed:
return err;
}
/**
* kbase_get_platform_logic_tile_type - determines which LogicTile type
* is used by Versatile Express
*
* When platform_config build parameter is specified as vexpress, i.e.,
* platform_config=vexpress, GPU frequency may vary dependent on the
* particular platform. The GPU frequency depends on the LogicTile type.
*
* This function determines which LogicTile type is used by the platform by
* reading the HBI value of the daughterboard which holds the LogicTile:
*
* 0x217 HBI0217 Virtex-6
* 0x192 HBI0192 Virtex-5
* 0x247 HBI0247 Virtex-7
*
* Return: HBI value of the logic tile daughterboard, zero if not accessible
*/
static u32 kbase_get_platform_logic_tile_type(void)
{
void __iomem *syscfg_reg = NULL;
u32 sys_procid1 = 0;
syscfg_reg = ioremap(VE_MOTHERBOARD_PERIPHERALS_SMB_CS7 + VE_SYS_PROC_ID1_OFFSET, 4);
if (NULL != syscfg_reg) {
sys_procid1 = readl(syscfg_reg);
iounmap(syscfg_reg);
}
return sys_procid1 & VE_LOGIC_TILE_HBI_MASK;
}
u32 kbase_get_platform_min_freq(void)
{
u32 ve_logic_tile = kbase_get_platform_logic_tile_type();
switch (ve_logic_tile) {
case 0x217:
/* Virtex 6, HBI0217 */
return VE_VIRTEX6_GPU_FREQ_MIN;
case 0x247:
/* Virtex 7, HBI0247 */
return VE_VIRTEX7_GPU_FREQ_MIN;
default:
/* all other logic tiles, i.e., Virtex 5 HBI0192
* or unsuccessful reading from the platform -
* fall back to some default value
*/
return VE_DEFAULT_GPU_FREQ_MIN;
}
}
u32 kbase_get_platform_max_freq(void)
{
u32 ve_logic_tile = kbase_get_platform_logic_tile_type();
switch (ve_logic_tile) {
case 0x217:
/* Virtex 6, HBI0217 */
return VE_VIRTEX6_GPU_FREQ_MAX;
case 0x247:
/* Virtex 7, HBI0247 */
return VE_VIRTEX7_GPU_FREQ_MAX;
default:
/* all other logic tiles, i.e., Virtex 5 HBI0192
* or unsuccessful reading from the platform -
* fall back to some default value
*/
return VE_DEFAULT_GPU_FREQ_MAX;
}
}
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _KBASE_CPU_VEXPRESS_H_
#define _KBASE_CPU_VEXPRESS_H_
/**
* Versatile Express implementation of @ref kbase_cpu_clk_speed_func.
*/
int kbase_get_vexpress_cpu_clock_speed(u32 *cpu_clock);
/**
* Get the minimum GPU frequency for the attached logic tile
*/
u32 kbase_get_platform_min_freq(void);
/**
* Get the maximum GPU frequency for the attached logic tile
*/
u32 kbase_get_platform_max_freq(void);
#endif /* _KBASE_CPU_VEXPRESS_H_ */
@@ -0,0 +1,35 @@
#
# (C) COPYRIGHT 2012-2013, 2016-2017 ARM Limited. All rights reserved.
#
# This program is free software and is provided to you under the terms of the
# GNU General Public License version 2 as published by the Free Software
# Foundation, and any use by you of this program is subject to the terms
# of such GNU licence.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# SPDX-License-Identifier: GPL-2.0
#
#
include $(src)/Kbuild-mtk-custom-env
mali_kbase-y += \
$(MALI_PLATFORM_DIR)/mali_kbase_config_mt6873.o \
$(MALI_PLATFORM_DIR)/mali_kbase_cpu_mt6873.o \
# mali_kbase_platform_fake.o
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/base/power/include
ifeq ($(CONFIG_MTK_TINYSYS_SSPM_SUPPORT), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(CONFIG_MTK_PLATFORM)
endif
@@ -0,0 +1,265 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <mali_kbase.h>
#include <mali_kbase_defs.h>
#include <mali_kbase_config.h>
#include "mali_kbase_cpu_mt6873.h"
#include "mali_kbase_config_platform.h"
#include "platform/mtk_platform_common.h"
#include "ged_dvfs.h"
#include "mtk_gpufreq.h"
#include "mtk_idle.h"
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
#include <mtk_gpu_power_sspm_ipi.h>
#endif
#define MALI_TAG "[GPU/MALI]"
#define mali_pr_info(fmt, args...) pr_info(MALI_TAG"[INFO]"fmt, ##args)
#define mali_pr_debug(fmt, args...) pr_debug(MALI_TAG"[DEBUG]"fmt, ##args)
DEFINE_MUTEX(g_mfg_lock);
//FIXME
static int g_curFreqID;
static int g_is_suspend;
enum gpu_dvfs_status_step {
GPU_DVFS_STATUS_STEP_1 = 0x1,
GPU_DVFS_STATUS_STEP_2 = 0x2,
GPU_DVFS_STATUS_STEP_3 = 0x3,
GPU_DVFS_STATUS_STEP_4 = 0x4,
GPU_DVFS_STATUS_STEP_5 = 0x5,
GPU_DVFS_STATUS_STEP_6 = 0x6,
GPU_DVFS_STATUS_STEP_7 = 0x7,
GPU_DVFS_STATUS_STEP_8 = 0x8,
GPU_DVFS_STATUS_STEP_9 = 0x9,
GPU_DVFS_STATUS_STEP_A = 0xA,
GPU_DVFS_STATUS_STEP_B = 0xB,
GPU_DVFS_STATUS_STEP_C = 0xC,
GPU_DVFS_STATUS_STEP_D = 0xD,
GPU_DVFS_STATUS_STEP_E = 0xE,
GPU_DVFS_STATUS_STEP_F = 0xF,
};
static inline void gpu_dvfs_status_footprint(enum gpu_dvfs_status_step step)
{
#ifdef CONFIG_MTK_RAM_CONSOLE
aee_rr_rec_gpu_dvfs_status(step |
(aee_rr_curr_gpu_dvfs_status() & 0xF0));
#endif
}
static inline void gpu_dvfs_status_reset_footprint(void)
{
#ifdef CONFIG_MTK_RAM_CONSOLE
aee_rr_rec_gpu_dvfs_status(0);
#endif
}
static int pm_callback_power_on_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup()) {
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
return 1;
}
if (!mt_gpufreq_power_ctl_en()) {
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
ged_dvfs_gpu_clock_switch_notify(1);
return 1;
}
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_ON)
return 0;
mali_pr_debug("@%s: power on ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_1);
if (g_is_suspend == 1) {
mali_pr_info("@%s: discard powering on since GPU is suspended\n", __func__);
return 0;
}
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_ON, CG_ON, MTCMOS_ON, BUCK_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_2);
mt_gpufreq_set_timestamp();
/* set a flag to enable GPU DVFS */
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_3);
/* resume frequency */
mtk_set_mt_gpufreq_target(g_curFreqID);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_4);
#ifdef ENABLE_COMMON_DVFS
ged_dvfs_gpu_clock_switch_notify(1);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_5);
return 1;
}
static void pm_callback_power_off_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup())
return;
if (!mt_gpufreq_power_ctl_en())
return;
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_OFF)
return;
mali_pr_debug("@%s: power off ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_6);
#ifdef ENABLE_COMMON_DVFS
ged_dvfs_gpu_clock_switch_notify(0);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_7);
/* set a flag to disable GPU DVFS */
mtk_set_vgpu_power_on_flag(MTK_VGPU_POWER_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_8);
/* suspend frequency */
g_curFreqID = mtk_get_ged_dvfs_last_commit_idx();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_9);
/* check MFG bus if idle */
mt_gpufreq_check_bus_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_A);
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_OFF, CG_OFF, MTCMOS_OFF, BUCK_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_B);
}
static int pm_callback_power_on(struct kbase_device *kbdev)
{
int ret = 0;
mutex_lock(&g_mfg_lock);
ret = pm_callback_power_on_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
MTKGPUPower_model_resume();
#endif
return ret;
}
static void pm_callback_power_off(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
#ifdef CONFIG_MTK_GPU_SWPM_SUPPORT
MTKGPUPower_model_suspend();
#endif
pm_callback_power_off_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_suspend(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
if (mtk_get_vgpu_power_on_flag() == MTK_VGPU_POWER_ON) {
pm_callback_power_off_nolock(kbdev);
mali_pr_info("@%s: force powering off GPU\n", __func__);
}
g_is_suspend = 1;
mali_pr_info("@%s: gpu_suspend\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_E);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_resume(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
g_is_suspend = 0;
mali_pr_info("@%s: gpu_resume\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_F);
mutex_unlock(&g_mfg_lock);
}
struct kbase_pm_callback_conf pm_callbacks = {
.power_on_callback = pm_callback_power_on,
.power_off_callback = pm_callback_power_off,
.power_suspend_callback = pm_callback_power_suspend,
.power_resume_callback = pm_callback_power_resume,
};
#ifndef CONFIG_OF
static struct kbase_io_resources io_resources = {
.job_irq_number = 68,
.mmu_irq_number = 69,
.gpu_irq_number = 70,
.io_memory_region = {
.start = 0xFC010000,
.end = 0xFC010000 + (4096 * 4) - 1
}
};
#endif
static struct kbase_platform_config versatile_platform_config = {
#ifndef CONFIG_OF
.io_resources = &io_resources
#endif
};
struct kbase_platform_config *kbase_get_platform_config(void)
{
return &versatile_platform_config;
}
int kbase_platform_early_init(void)
{
/* Nothing needed at this stage */
return 0;
}
int mtk_platform_init(struct kbase_device *kbdev)
{
if (!kbdev) {
mali_pr_info("@%s: input parameter is NULL\n", __func__);
return -1;
}
gpu_dvfs_status_reset_footprint();
//FIXME
g_is_suspend = -1;
mali_pr_info("@%s: initialize successfully\n", __func__);
return 0;
}
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "mali_kbase_cpu_mt6873.h"
/**
* Maximum frequency GPU will be clocked at. Given in kHz.
* This must be specified as there is no default value.
*
* Attached value: number in kHz
* Default value: NA
*/
#define GPU_FREQ_KHZ_MAX kbase_get_platform_max_freq()
/**
* Minimum frequency GPU will be clocked at. Given in kHz.
* This must be specified as there is no default value.
*
* Attached value: number in kHz
* Default value: NA
*/
#define GPU_FREQ_KHZ_MIN kbase_get_platform_min_freq()
/**
* CPU_SPEED_FUNC - A pointer to a function that calculates the CPU clock
*
* CPU clock speed of the platform is in MHz - see kbase_cpu_clk_speed_func
* for the function prototype.
*
* Attached value: A kbase_cpu_clk_speed_func.
* Default Value: NA
*/
#define CPU_SPEED_FUNC (&kbase_get_vexpress_cpu_clock_speed)
/**
* GPU_SPEED_FUNC - A pointer to a function that calculates the GPU clock
*
* GPU clock speed of the platform in MHz - see kbase_gpu_clk_speed_func
* for the function prototype.
*
* Attached value: A kbase_gpu_clk_speed_func.
* Default Value: NA
*/
#define GPU_SPEED_FUNC (NULL)
/**
* Power management configuration
*
* Attached value: pointer to @ref kbase_pm_callback_conf
* Default value: See @ref kbase_pm_callback_conf
*/
#define POWER_MANAGEMENT_CALLBACKS (&pm_callbacks)
/**
* Platform specific configuration functions
*
* Attached value: pointer to @ref kbase_platform_funcs_conf
* Default value: See @ref kbase_platform_funcs_conf
*/
#define PLATFORM_FUNCS (NULL)
extern struct kbase_pm_callback_conf pm_callbacks;
@@ -0,0 +1,273 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/io.h>
#include <mali_kbase.h>
#include "mali_kbase_cpu_mt6873.h"
#define HZ_IN_MHZ (1000000)
#define CORETILE_EXPRESS_A9X4_SCC_START (0x100E2000)
#define MOTHERBOARD_SYS_CFG_START (0x10000000)
#define SYS_CFGDATA_OFFSET (0x000000A0)
#define SYS_CFGCTRL_OFFSET (0x000000A4)
#define SYS_CFGSTAT_OFFSET (0x000000A8)
#define SYS_CFGCTRL_START_BIT_VALUE (1 << 31)
#define READ_REG_BIT_VALUE (0 << 30)
#define DCC_DEFAULT_BIT_VALUE (0 << 26)
#define SYS_CFG_OSC_FUNC_BIT_VALUE (1 << 20)
#define SITE_DEFAULT_BIT_VALUE (1 << 16)
#define BOARD_STACK_POS_DEFAULT_BIT_VALUE (0 << 12)
#define DEVICE_DEFAULT_BIT_VALUE (2 << 0)
#define SYS_CFG_COMPLETE_BIT_VALUE (1 << 0)
#define SYS_CFG_ERROR_BIT_VALUE (1 << 1)
#define FEED_REG_BIT_MASK (0x0F)
#define FCLK_PA_DIVIDE_BIT_SHIFT (0x03)
#define FCLK_PB_DIVIDE_BIT_SHIFT (0x07)
#define FCLK_PC_DIVIDE_BIT_SHIFT (0x0B)
#define AXICLK_PA_DIVIDE_BIT_SHIFT (0x0F)
#define AXICLK_PB_DIVIDE_BIT_SHIFT (0x13)
/* the following three values used for reading
* HBI value of the LogicTile daughterboard
*/
#define VE_MOTHERBOARD_PERIPHERALS_SMB_CS7 (0x10000000)
#define VE_SYS_PROC_ID1_OFFSET (0x00000088)
#define VE_LOGIC_TILE_HBI_MASK (0x00000FFF)
#define IS_SINGLE_BIT_SET(val, pos) (val&(1<<pos))
/**
* Values used for determining the GPU frequency based on the LogicTile type
* Used by the function kbase_get_platform_logic_tile_type
*/
#define VE_VIRTEX6_GPU_FREQ_MIN 5000
#define VE_VIRTEX6_GPU_FREQ_MAX 5000
#define VE_VIRTEX7_GPU_FREQ_MIN 40000
#define VE_VIRTEX7_GPU_FREQ_MAX 40000
#define VE_DEFAULT_GPU_FREQ_MIN 5000
#define VE_DEFAULT_GPU_FREQ_MAX 5000
#define CPU_CLOCK_SPEED_UNDEFINED (0)
static u32 cpu_clock_speed = CPU_CLOCK_SPEED_UNDEFINED;
static DEFINE_RAW_SPINLOCK(syscfg_lock);
/**
* kbase_get_vendor_specific_cpu_clock_speed -Retrieves the CPU clock speed
* @cpu_clock - the value of CPU clock speed in MHz
*
* Returns 0 on success, error code otherwise.
*
* The implementation is platform specific.
*/
int kbase_get_vexpress_cpu_clock_speed(u32 *cpu_clock)
{
int err = 0;
u32 reg_val = 0;
u32 osc2_value = 0;
u32 pa_divide = 0;
u32 pb_divide = 0;
u32 pc_divide = 0;
void __iomem *syscfg_reg = NULL;
void __iomem *scc_reg = NULL;
if (CPU_CLOCK_SPEED_UNDEFINED != cpu_clock_speed) {
*cpu_clock = cpu_clock_speed;
return 0;
}
/* Init the value in case something goes wrong */
*cpu_clock = 0;
/* Map CPU register into virtual memory */
syscfg_reg = ioremap(MOTHERBOARD_SYS_CFG_START, 0x1000);
if (syscfg_reg == NULL) {
err = -EIO;
goto syscfg_reg_map_failed;
}
scc_reg = ioremap(CORETILE_EXPRESS_A9X4_SCC_START, 0x1000);
if (scc_reg == NULL) {
err = -EIO;
goto scc_reg_map_failed;
}
raw_spin_lock(&syscfg_lock);
/* Read SYS regs - OSC2 */
reg_val = readl(syscfg_reg + SYS_CFGCTRL_OFFSET);
/* Check if there is any other undergoing request */
if (reg_val & SYS_CFGCTRL_START_BIT_VALUE) {
err = -EBUSY;
goto ongoing_request;
}
/* Reset the CGFGSTAT reg */
writel(0, (syscfg_reg + SYS_CFGSTAT_OFFSET));
writel(SYS_CFGCTRL_START_BIT_VALUE | READ_REG_BIT_VALUE |
DCC_DEFAULT_BIT_VALUE |
SYS_CFG_OSC_FUNC_BIT_VALUE |
SITE_DEFAULT_BIT_VALUE |
BOARD_STACK_POS_DEFAULT_BIT_VALUE |
DEVICE_DEFAULT_BIT_VALUE,
(syscfg_reg + SYS_CFGCTRL_OFFSET));
/* Wait for the transaction to complete */
while (!(readl(syscfg_reg + SYS_CFGSTAT_OFFSET) &
SYS_CFG_COMPLETE_BIT_VALUE))
;
/* Read SYS_CFGSTAT Register to get the status of submitted
* transaction
*/
reg_val = readl(syscfg_reg + SYS_CFGSTAT_OFFSET);
if (reg_val & SYS_CFG_ERROR_BIT_VALUE) {
/* Error while setting register */
err = -EIO;
goto set_reg_error;
}
osc2_value = readl(syscfg_reg + SYS_CFGDATA_OFFSET);
/* Read the SCC CFGRW0 register */
reg_val = readl(scc_reg);
/*
* Select the appropriate feed:
* CFGRW0[0] - CLKOB
* CFGRW0[1] - CLKOC
* CFGRW0[2] - FACLK (CLK)B FROM AXICLK PLL)
*/
/* Calculate the FCLK */
if (IS_SINGLE_BIT_SET(reg_val, 0)) {
/* CFGRW0[0] - CLKOB */
/* CFGRW0[6:3] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PA_DIVIDE_BIT_SHIFT)) >>
FCLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[10:7] */
pb_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PB_DIVIDE_BIT_SHIFT)) >>
FCLK_PB_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pb_divide + 1);
} else if (IS_SINGLE_BIT_SET(reg_val, 1)) {
/* CFGRW0[1] - CLKOC */
/* CFGRW0[6:3] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PA_DIVIDE_BIT_SHIFT)) >>
FCLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[14:11] */
pc_divide = ((reg_val & (FEED_REG_BIT_MASK <<
FCLK_PC_DIVIDE_BIT_SHIFT)) >>
FCLK_PC_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pc_divide + 1);
} else if (IS_SINGLE_BIT_SET(reg_val, 2)) {
/* CFGRW0[2] - FACLK */
/* CFGRW0[18:15] */
pa_divide = ((reg_val & (FEED_REG_BIT_MASK <<
AXICLK_PA_DIVIDE_BIT_SHIFT)) >>
AXICLK_PA_DIVIDE_BIT_SHIFT);
/* CFGRW0[22:19] */
pb_divide = ((reg_val & (FEED_REG_BIT_MASK <<
AXICLK_PB_DIVIDE_BIT_SHIFT)) >>
AXICLK_PB_DIVIDE_BIT_SHIFT);
*cpu_clock = osc2_value * (pa_divide + 1) / (pb_divide + 1);
} else {
err = -EIO;
}
set_reg_error:
ongoing_request:
raw_spin_unlock(&syscfg_lock);
*cpu_clock /= HZ_IN_MHZ;
if (!err)
cpu_clock_speed = *cpu_clock;
iounmap(scc_reg);
scc_reg_map_failed:
iounmap(syscfg_reg);
syscfg_reg_map_failed:
return err;
}
/**
* kbase_get_platform_logic_tile_type - determines which LogicTile type
* is used by Versatile Express
*
* When platform_config build parameter is specified as vexpress, i.e.,
* platform_config=vexpress, GPU frequency may vary dependent on the
* particular platform. The GPU frequency depends on the LogicTile type.
*
* This function determines which LogicTile type is used by the platform by
* reading the HBI value of the daughterboard which holds the LogicTile:
*
* 0x217 HBI0217 Virtex-6
* 0x192 HBI0192 Virtex-5
* 0x247 HBI0247 Virtex-7
*
* Return: HBI value of the logic tile daughterboard, zero if not accessible
*/
static u32 kbase_get_platform_logic_tile_type(void)
{
void __iomem *syscfg_reg = NULL;
u32 sys_procid1 = 0;
syscfg_reg = ioremap(VE_MOTHERBOARD_PERIPHERALS_SMB_CS7 + VE_SYS_PROC_ID1_OFFSET, 4);
if (NULL != syscfg_reg) {
sys_procid1 = readl(syscfg_reg);
iounmap(syscfg_reg);
}
return sys_procid1 & VE_LOGIC_TILE_HBI_MASK;
}
u32 kbase_get_platform_min_freq(void)
{
u32 ve_logic_tile = kbase_get_platform_logic_tile_type();
switch (ve_logic_tile) {
case 0x217:
/* Virtex 6, HBI0217 */
return VE_VIRTEX6_GPU_FREQ_MIN;
case 0x247:
/* Virtex 7, HBI0247 */
return VE_VIRTEX7_GPU_FREQ_MIN;
default:
/* all other logic tiles, i.e., Virtex 5 HBI0192
* or unsuccessful reading from the platform -
* fall back to some default value
*/
return VE_DEFAULT_GPU_FREQ_MIN;
}
}
u32 kbase_get_platform_max_freq(void)
{
u32 ve_logic_tile = kbase_get_platform_logic_tile_type();
switch (ve_logic_tile) {
case 0x217:
/* Virtex 6, HBI0217 */
return VE_VIRTEX6_GPU_FREQ_MAX;
case 0x247:
/* Virtex 7, HBI0247 */
return VE_VIRTEX7_GPU_FREQ_MAX;
default:
/* all other logic tiles, i.e., Virtex 5 HBI0192
* or unsuccessful reading from the platform -
* fall back to some default value
*/
return VE_DEFAULT_GPU_FREQ_MAX;
}
}
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _KBASE_CPU_VEXPRESS_H_
#define _KBASE_CPU_VEXPRESS_H_
/**
* Versatile Express implementation of @ref kbase_cpu_clk_speed_func.
*/
int kbase_get_vexpress_cpu_clock_speed(u32 *cpu_clock);
/**
* Get the minimum GPU frequency for the attached logic tile
*/
u32 kbase_get_platform_min_freq(void);
/**
* Get the maximum GPU frequency for the attached logic tile
*/
u32 kbase_get_platform_max_freq(void);
#endif /* _KBASE_CPU_VEXPRESS_H_ */
@@ -0,0 +1,35 @@
#
# (C) COPYRIGHT 2012-2013, 2016-2017, 2020 ARM Limited. All rights reserved.
#
# This program is free software and is provided to you under the terms of the
# GNU General Public License version 2 as published by the Free Software
# Foundation, and any use by you of this program is subject to the terms
# of such GNU licence.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# SPDX-License-Identifier: GPL-2.0
#
#
include $(src)/Kbuild-mtk-custom-env
mali_kbase-y += \
$(MALI_PLATFORM_DIR)/mali_kbase_config_mt6873.o
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/base/power/include
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/include/mt-plat
ifeq ($(CONFIG_MTK_TINYSYS_SSPM_SUPPORT), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(CONFIG_MTK_PLATFORM)
endif
@@ -0,0 +1,262 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <mali_kbase.h>
#include <mali_kbase_defs.h>
#include <mali_kbase_config.h>
#include "mali_kbase_config_platform.h"
#include "platform/mtk_platform_common.h"
#include "ged_dvfs.h"
#include "mtk_gpufreq.h"
#include "mtk_idle.h"
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
//#include <mtk_gpu_power_sspm_ipi.h>
#endif
#define MALI_TAG "[GPU/MALI]"
#define mali_pr_info(fmt, args...) pr_info(MALI_TAG"[INFO]"fmt, ##args)
#define mali_pr_debug(fmt, args...) pr_debug(MALI_TAG"[DEBUG]"fmt, ##args)
DEFINE_MUTEX(g_mfg_lock);
//FIXME
static int g_curFreqID;
static int g_is_suspend;
enum gpu_dvfs_status_step {
GPU_DVFS_STATUS_STEP_1 = 0x1,
GPU_DVFS_STATUS_STEP_2 = 0x2,
GPU_DVFS_STATUS_STEP_3 = 0x3,
GPU_DVFS_STATUS_STEP_4 = 0x4,
GPU_DVFS_STATUS_STEP_5 = 0x5,
GPU_DVFS_STATUS_STEP_6 = 0x6,
GPU_DVFS_STATUS_STEP_7 = 0x7,
GPU_DVFS_STATUS_STEP_8 = 0x8,
GPU_DVFS_STATUS_STEP_9 = 0x9,
GPU_DVFS_STATUS_STEP_A = 0xA,
GPU_DVFS_STATUS_STEP_B = 0xB,
GPU_DVFS_STATUS_STEP_C = 0xC,
GPU_DVFS_STATUS_STEP_D = 0xD,
GPU_DVFS_STATUS_STEP_E = 0xE,
GPU_DVFS_STATUS_STEP_F = 0xF,
};
static inline void gpu_dvfs_status_footprint(enum gpu_dvfs_status_step step)
{
#if IS_ENABLED(CONFIG_MTK_RAM_CONSOLE)
aee_rr_rec_gpu_dvfs_status(step |
(aee_rr_curr_gpu_dvfs_status() & 0xF0));
#endif
}
static inline void gpu_dvfs_status_reset_footprint(void)
{
#if IS_ENABLED(CONFIG_MTK_RAM_CONSOLE)
aee_rr_rec_gpu_dvfs_status(0);
#endif
}
static int pm_callback_power_on_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup()) {
mtk_common_pm_mfg_active();
return 1;
}
if (!mt_gpufreq_power_ctl_en()) {
mtk_common_pm_mfg_active();
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(1);
#endif
return 1;
}
if (mtk_common_pm_is_mfg_active())
return 0;
mali_pr_debug("@%s: power on ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_1);
if (g_is_suspend == 1) {
mali_pr_info("@%s: discard powering on since GPU is suspended\n", __func__);
return 0;
}
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_ON, CG_ON, MTCMOS_ON, BUCK_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_2);
mt_gpufreq_set_timestamp();
/* set a flag to enable GPU DVFS */
mtk_common_pm_mfg_active();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_3);
/* resume frequency */
mtk_common_gpufreq_commit(g_curFreqID);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_4);
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(1);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_5);
return 1;
}
static void pm_callback_power_off_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup())
return;
if (!mt_gpufreq_power_ctl_en())
return;
if (!mtk_common_pm_is_mfg_active())
return;
mali_pr_debug("@%s: power off ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_6);
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(0);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_7);
/* set a flag to disable GPU DVFS */
mtk_common_pm_mfg_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_8);
/* suspend frequency */
g_curFreqID = mtk_common_ged_dvfs_get_last_commit_idx();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_9);
/* check MFG bus if idle */
mt_gpufreq_check_bus_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_A);
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_OFF, CG_OFF, MTCMOS_OFF, BUCK_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_B);
}
static int pm_callback_power_on(struct kbase_device *kbdev)
{
int ret = 0;
mutex_lock(&g_mfg_lock);
ret = pm_callback_power_on_nolock(kbdev);
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
// MTKGPUPower_model_resume();
#endif
mutex_unlock(&g_mfg_lock);
return ret;
}
static void pm_callback_power_off(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
// MTKGPUPower_model_suspend();
#endif
pm_callback_power_off_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_suspend(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
if (mtk_common_pm_is_mfg_active()) {
pm_callback_power_off_nolock(kbdev);
mali_pr_info("@%s: force powering off GPU\n", __func__);
}
g_is_suspend = 1;
mali_pr_info("@%s: gpu_suspend\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_E);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_resume(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
g_is_suspend = 0;
mali_pr_info("@%s: gpu_resume\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_F);
mutex_unlock(&g_mfg_lock);
}
struct kbase_pm_callback_conf pm_callbacks = {
.power_on_callback = pm_callback_power_on,
.power_off_callback = pm_callback_power_off,
.power_suspend_callback = pm_callback_power_suspend,
.power_resume_callback = pm_callback_power_resume,
};
#ifndef CONFIG_OF
static struct kbase_io_resources io_resources = {
.job_irq_number = 68,
.mmu_irq_number = 69,
.gpu_irq_number = 70,
.io_memory_region = {
.start = 0xFC010000,
.end = 0xFC010000 + (4096 * 4) - 1
}
};
#endif /* CONFIG_OF */
static struct kbase_platform_config versatile_platform_config = {
#ifndef CONFIG_OF
.io_resources = &io_resources
#endif
};
struct kbase_platform_config *kbase_get_platform_config(void)
{
return &versatile_platform_config;
}
int mtk_platform_device_init(struct kbase_device *kbdev)
{
if (!kbdev) {
mali_pr_info("@%s: kbdev is NULL\n", __func__);
return -1;
}
gpu_dvfs_status_reset_footprint();
//FIXME
g_is_suspend = -1;
mali_pr_info("@%s: initialize successfully\n", __func__);
return 0;
}
void mtk_platform_device_term(struct kbase_device *kbdev) { }
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/**
* Power management configuration
*
* Attached value: pointer to @ref kbase_pm_callback_conf
* Default value: See @ref kbase_pm_callback_conf
*/
#define POWER_MANAGEMENT_CALLBACKS (&pm_callbacks)
/**
* Platform specific configuration functions
*
* Attached value: pointer to @ref kbase_platform_funcs_conf
* Default value: See @ref kbase_platform_funcs_conf
*/
#define PLATFORM_FUNCS (NULL)
extern struct kbase_pm_callback_conf pm_callbacks;
@@ -0,0 +1,39 @@
#
# (C) COPYRIGHT 2012-2013, 2016-2017, 2020 ARM Limited. All rights reserved.
#
# This program is free software and is provided to you under the terms of the
# GNU General Public License version 2 as published by the Free Software
# Foundation, and any use by you of this program is subject to the terms
# of such GNU licence.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# SPDX-License-Identifier: GPL-2.0
#
#
include $(src)/Kbuild-mtk-custom-env
mali_kbase-y += \
platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_mt6873.o
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/base/power/include
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/include/mt-plat
ifeq ($(CONFIG_MTK_TINYSYS_SSPM_SUPPORT), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(CONFIG_MTK_PLATFORM)
endif
# /*set interval to 9600-10000us */
ccflags-y += -DDEFAULT_PM_POWEROFF_TICK_SHADER=25
@@ -0,0 +1,262 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <mali_kbase.h>
#include <mali_kbase_defs.h>
#include <mali_kbase_config.h>
#include "mali_kbase_config_platform.h"
#include "platform/mtk_platform_common.h"
#include "ged_dvfs.h"
#include "mtk_gpufreq.h"
#include "mtk_idle.h"
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
//#include <mtk_gpu_power_sspm_ipi.h>
#endif
#define MALI_TAG "[GPU/MALI]"
#define mali_pr_info(fmt, args...) pr_info(MALI_TAG"[INFO]"fmt, ##args)
#define mali_pr_debug(fmt, args...) pr_debug(MALI_TAG"[DEBUG]"fmt, ##args)
DEFINE_MUTEX(g_mfg_lock);
//FIXME
static int g_curFreqID;
static int g_is_suspend;
enum gpu_dvfs_status_step {
GPU_DVFS_STATUS_STEP_1 = 0x1,
GPU_DVFS_STATUS_STEP_2 = 0x2,
GPU_DVFS_STATUS_STEP_3 = 0x3,
GPU_DVFS_STATUS_STEP_4 = 0x4,
GPU_DVFS_STATUS_STEP_5 = 0x5,
GPU_DVFS_STATUS_STEP_6 = 0x6,
GPU_DVFS_STATUS_STEP_7 = 0x7,
GPU_DVFS_STATUS_STEP_8 = 0x8,
GPU_DVFS_STATUS_STEP_9 = 0x9,
GPU_DVFS_STATUS_STEP_A = 0xA,
GPU_DVFS_STATUS_STEP_B = 0xB,
GPU_DVFS_STATUS_STEP_C = 0xC,
GPU_DVFS_STATUS_STEP_D = 0xD,
GPU_DVFS_STATUS_STEP_E = 0xE,
GPU_DVFS_STATUS_STEP_F = 0xF,
};
static inline void gpu_dvfs_status_footprint(enum gpu_dvfs_status_step step)
{
#if IS_ENABLED(CONFIG_MTK_RAM_CONSOLE)
aee_rr_rec_gpu_dvfs_status(step |
(aee_rr_curr_gpu_dvfs_status() & 0xF0));
#endif
}
static inline void gpu_dvfs_status_reset_footprint(void)
{
#if IS_ENABLED(CONFIG_MTK_RAM_CONSOLE)
aee_rr_rec_gpu_dvfs_status(0);
#endif
}
static int pm_callback_power_on_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup()) {
mtk_common_pm_mfg_active();
return 1;
}
if (!mt_gpufreq_power_ctl_en()) {
mtk_common_pm_mfg_active();
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(1);
#endif
return 1;
}
if (mtk_common_pm_is_mfg_active())
return 0;
mali_pr_debug("@%s: power on ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_1);
if (g_is_suspend == 1) {
mali_pr_info("@%s: discard powering on since GPU is suspended\n", __func__);
return 0;
}
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_ON, CG_ON, MTCMOS_ON, BUCK_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_2);
mt_gpufreq_set_timestamp();
/* set a flag to enable GPU DVFS */
mtk_common_pm_mfg_active();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_3);
/* resume frequency */
mtk_common_gpufreq_commit(g_curFreqID);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_4);
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(1);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_5);
return 1;
}
static void pm_callback_power_off_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup())
return;
if (!mt_gpufreq_power_ctl_en())
return;
if (!mtk_common_pm_is_mfg_active())
return;
mali_pr_debug("@%s: power off ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_6);
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(0);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_7);
/* set a flag to disable GPU DVFS */
mtk_common_pm_mfg_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_8);
/* suspend frequency */
g_curFreqID = mtk_common_ged_dvfs_get_last_commit_idx();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_9);
/* check MFG bus if idle */
mt_gpufreq_check_bus_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_A);
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_OFF, CG_OFF, MTCMOS_OFF, BUCK_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_B);
}
static int pm_callback_power_on(struct kbase_device *kbdev)
{
int ret = 0;
mutex_lock(&g_mfg_lock);
ret = pm_callback_power_on_nolock(kbdev);
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
// MTKGPUPower_model_resume();
#endif
mutex_unlock(&g_mfg_lock);
return ret;
}
static void pm_callback_power_off(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
// MTKGPUPower_model_suspend();
#endif
pm_callback_power_off_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_suspend(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
if (mtk_common_pm_is_mfg_active()) {
pm_callback_power_off_nolock(kbdev);
mali_pr_info("@%s: force powering off GPU\n", __func__);
}
g_is_suspend = 1;
mali_pr_info("@%s: gpu_suspend\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_E);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_resume(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
g_is_suspend = 0;
mali_pr_info("@%s: gpu_resume\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_F);
mutex_unlock(&g_mfg_lock);
}
struct kbase_pm_callback_conf pm_callbacks = {
.power_on_callback = pm_callback_power_on,
.power_off_callback = pm_callback_power_off,
.power_suspend_callback = pm_callback_power_suspend,
.power_resume_callback = pm_callback_power_resume,
};
#ifndef CONFIG_OF
static struct kbase_io_resources io_resources = {
.job_irq_number = 68,
.mmu_irq_number = 69,
.gpu_irq_number = 70,
.io_memory_region = {
.start = 0xFC010000,
.end = 0xFC010000 + (4096 * 4) - 1
}
};
#endif /* CONFIG_OF */
static struct kbase_platform_config versatile_platform_config = {
#ifndef CONFIG_OF
.io_resources = &io_resources
#endif
};
struct kbase_platform_config *kbase_get_platform_config(void)
{
return &versatile_platform_config;
}
int mtk_platform_device_init(struct kbase_device *kbdev)
{
if (!kbdev) {
mali_pr_info("@%s: kbdev is NULL\n", __func__);
return -1;
}
gpu_dvfs_status_reset_footprint();
//FIXME
g_is_suspend = -1;
mali_pr_info("@%s: initialize successfully\n", __func__);
return 0;
}
void mtk_platform_device_term(struct kbase_device *kbdev) { }
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/**
* Power management configuration
*
* Attached value: pointer to @ref kbase_pm_callback_conf
* Default value: See @ref kbase_pm_callback_conf
*/
#define POWER_MANAGEMENT_CALLBACKS (&pm_callbacks)
/**
* Platform specific configuration functions
*
* Attached value: pointer to @ref kbase_platform_funcs_conf
* Default value: See @ref kbase_platform_funcs_conf
*/
#define PLATFORM_FUNCS (NULL)
extern struct kbase_pm_callback_conf pm_callbacks;
@@ -0,0 +1,39 @@
#
# (C) COPYRIGHT 2012-2013, 2016-2017, 2020 ARM Limited. All rights reserved.
#
# This program is free software and is provided to you under the terms of the
# GNU General Public License version 2 as published by the Free Software
# Foundation, and any use by you of this program is subject to the terms
# of such GNU licence.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# SPDX-License-Identifier: GPL-2.0
#
#
include $(src)/Kbuild-mtk-custom-env
mali_kbase-y += \
platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_mt6873.o
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/base/power/include
ccflags-y += \
-I$(srctree)/drivers/misc/mediatek/include/mt-plat
ifeq ($(CONFIG_MTK_TINYSYS_SSPM_SUPPORT), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/v2/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(CONFIG_MTK_PLATFORM)
endif
# /*set interval to 9600-10000us */
ccflags-y += -DDEFAULT_PM_POWEROFF_TICK_SHADER=25
@@ -0,0 +1,263 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <mali_kbase.h>
#include <mali_kbase_defs.h>
#include <mali_kbase_config.h>
#include "mali_kbase_config_platform.h"
#include "platform/mtk_platform_common.h"
#include "ged_dvfs.h"
#include "mtk_gpufreq.h"
#include "mtk_idle.h"
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
//#include <mtk_gpu_power_sspm_ipi.h>
#endif
#define MALI_TAG "[GPU/MALI]"
#define mali_pr_info(fmt, args...) pr_info(MALI_TAG"[INFO]"fmt, ##args)
#define mali_pr_debug(fmt, args...) pr_debug(MALI_TAG"[DEBUG]"fmt, ##args)
DEFINE_MUTEX(g_mfg_lock);
//FIXME
static int g_curFreqID;
static int g_is_suspend;
enum gpu_dvfs_status_step {
GPU_DVFS_STATUS_STEP_1 = 0x1,
GPU_DVFS_STATUS_STEP_2 = 0x2,
GPU_DVFS_STATUS_STEP_3 = 0x3,
GPU_DVFS_STATUS_STEP_4 = 0x4,
GPU_DVFS_STATUS_STEP_5 = 0x5,
GPU_DVFS_STATUS_STEP_6 = 0x6,
GPU_DVFS_STATUS_STEP_7 = 0x7,
GPU_DVFS_STATUS_STEP_8 = 0x8,
GPU_DVFS_STATUS_STEP_9 = 0x9,
GPU_DVFS_STATUS_STEP_A = 0xA,
GPU_DVFS_STATUS_STEP_B = 0xB,
GPU_DVFS_STATUS_STEP_C = 0xC,
GPU_DVFS_STATUS_STEP_D = 0xD,
GPU_DVFS_STATUS_STEP_E = 0xE,
GPU_DVFS_STATUS_STEP_F = 0xF,
};
static inline void gpu_dvfs_status_footprint(enum gpu_dvfs_status_step step)
{
#if IS_ENABLED(CONFIG_MTK_RAM_CONSOLE)
aee_rr_rec_gpu_dvfs_status(step |
(aee_rr_curr_gpu_dvfs_status() & 0xF0));
#endif
}
static inline void gpu_dvfs_status_reset_footprint(void)
{
#if IS_ENABLED(CONFIG_MTK_RAM_CONSOLE)
aee_rr_rec_gpu_dvfs_status(0);
#endif
}
static int pm_callback_power_on_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup()) {
mtk_common_pm_mfg_active();
return 1;
}
if (!mt_gpufreq_power_ctl_en()) {
mtk_common_pm_mfg_active();
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(1);
#endif
return 1;
}
if (mtk_common_pm_is_mfg_active())
return 0;
mali_pr_debug("@%s: power on ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_1);
if (g_is_suspend == 1) {
mali_pr_info("@%s: discard powering on since GPU is suspended\n", __func__);
return 0;
}
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_ON, CG_ON, MTCMOS_ON, BUCK_ON);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_2);
mt_gpufreq_set_timestamp();
/* set a flag to enable GPU DVFS */
mtk_common_pm_mfg_active();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_3);
/* resume frequency */
mtk_common_gpufreq_commit(g_curFreqID);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_4);
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(1);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_5);
return 1;
}
static void pm_callback_power_off_nolock(struct kbase_device *kbdev)
{
if (mt_gpufreq_bringup())
return;
if (!mt_gpufreq_power_ctl_en())
return;
if (!mtk_common_pm_is_mfg_active())
return;
mali_pr_debug("@%s: power off ...\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_6);
#if IS_ENABLED(CONFIG_MALI_MIDGARD_DVFS) && IS_ENABLED(CONFIG_MTK_GPU_COMMON_DVFS)
ged_dvfs_gpu_clock_switch_notify(0);
#endif
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_7);
/* set a flag to disable GPU DVFS */
mtk_common_pm_mfg_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_8);
/* suspend frequency */
g_curFreqID = mtk_common_ged_dvfs_get_last_commit_idx();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_9);
/* check MFG bus if idle */
mt_gpufreq_check_bus_idle();
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_A);
/* on,off/ SWCG(BG3D)/ MTCMOS/ BUCK */
mt_gpufreq_power_control(POWER_OFF, CG_OFF, MTCMOS_OFF, BUCK_OFF);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_B);
}
static int pm_callback_power_on(struct kbase_device *kbdev)
{
int ret = 0;
mutex_lock(&g_mfg_lock);
ret = pm_callback_power_on_nolock(kbdev);
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
// MTKGPUPower_model_resume();
#endif
mutex_unlock(&g_mfg_lock);
return ret;
}
static void pm_callback_power_off(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
#if IS_ENABLED(CONFIG_MTK_GPU_SWPM_SUPPORT)
// MTKGPUPower_model_suspend();
#endif
pm_callback_power_off_nolock(kbdev);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_suspend(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
if (mtk_common_pm_is_mfg_active()) {
pm_callback_power_off_nolock(kbdev);
mali_pr_info("@%s: force powering off GPU\n", __func__);
}
g_is_suspend = 1;
mali_pr_info("@%s: gpu_suspend\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_E);
mutex_unlock(&g_mfg_lock);
}
static void pm_callback_power_resume(struct kbase_device *kbdev)
{
mutex_lock(&g_mfg_lock);
g_is_suspend = 0;
mali_pr_info("@%s: gpu_resume\n", __func__);
gpu_dvfs_status_footprint(GPU_DVFS_STATUS_STEP_F);
mutex_unlock(&g_mfg_lock);
}
struct kbase_pm_callback_conf pm_callbacks = {
.power_on_callback = pm_callback_power_on,
.power_off_callback = pm_callback_power_off,
.power_suspend_callback = pm_callback_power_suspend,
.power_resume_callback = pm_callback_power_resume,
};
#ifndef CONFIG_OF
static struct kbase_io_resources io_resources = {
.job_irq_number = 68,
.mmu_irq_number = 69,
.gpu_irq_number = 70,
.io_memory_region = {
.start = 0xFC010000,
.end = 0xFC010000 + (4096 * 4) - 1
}
};
#endif /* CONFIG_OF */
static struct kbase_platform_config versatile_platform_config = {
#ifndef CONFIG_OF
.io_resources = &io_resources
#endif
};
struct kbase_platform_config *kbase_get_platform_config(void)
{
return &versatile_platform_config;
}
int mtk_platform_device_init(struct kbase_device *kbdev)
{
if (!kbdev) {
mali_pr_info("@%s: kbdev is NULL\n", __func__);
return -1;
}
gpu_dvfs_status_reset_footprint();
//FIXME
g_is_suspend = -1;
mali_pr_info("@%s: initialize successfully\n", __func__);
return 0;
}
void mtk_platform_device_term(struct kbase_device *kbdev) { }
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/**
* Power management configuration
*
* Attached value: pointer to @ref kbase_pm_callback_conf
* Default value: See @ref kbase_pm_callback_conf
*/
#define POWER_MANAGEMENT_CALLBACKS (&pm_callbacks)
/**
* Platform specific configuration functions
*
* Attached value: pointer to @ref kbase_platform_funcs_conf
* Default value: See @ref kbase_platform_funcs_conf
*/
#define PLATFORM_FUNCS (NULL)
extern struct kbase_pm_callback_conf pm_callbacks;