Linux_SDK_V1.4.2

Signed-off-by: thead_admin <occ_thead@service.alibaba.com>
This commit is contained in:
thead_admin
2023-12-24 02:32:32 +00:00
committed by Han Gao/Revy/Rabenda
parent e17ac7bab2
commit d4c68ef2c1
164 changed files with 1943 additions and 24540 deletions

View File

@@ -65,7 +65,7 @@ static int light_vosys_clk_probe(struct platform_device *pdev)
gates[LIGHT_CLKGEN_MIPIDSI1_CFG_CLK] = thead_clk_light_gate("clkgen_mipidsi1_cfg_clk", NULL, gate_base + 0x50, 16);
gates[LIGHT_CLKGEN_MIPIDSI0_REFCLK] = thead_clk_light_gate("clkgen_mipidsi0_refclk", NULL, gate_base + 0x50, 17);
gates[LIGHT_CLKGEN_MIPIDSI1_REFCLK] = thead_clk_light_gate("clkgen_mipidsi1_refclk", NULL, gate_base + 0x50, 18);
gates[LIGHT_CLKGEN_GPU_CORE_CLK] = thead_clk_light_gate("clkgen_gpu_core_clk", NULL, gate_base + 0x50, 3);
gates[LIGHT_CLKGEN_GPU_CORE_CLK] = thead_clk_light_gate("clkgen_gpu_core_clk", "vosys_aclk_m", gate_base + 0x50, 3);
gates[LIGHT_CLKGEN_GPU_CFG_ACLK] = thead_clk_light_gate("clkgen_gpu_cfg_aclk", NULL, gate_base + 0x50, 4);
gates[LIGHT_CLKGEN_DPU_HCLK] = thead_clk_light_gate("clkgen_dpu_hclk", NULL, gate_base + 0x50, 7);
gates[LIGHT_CLKGEN_DPU_ACLK] = thead_clk_light_gate("clkgen_dpu_aclk", NULL, gate_base + 0x50, 8);

View File

@@ -35,7 +35,8 @@ static int light_vpsys_clk_probe(struct platform_device *pdev)
return PTR_ERR(gate_base);
// DIV & CDE
gates[LIGHT_VPSYS_G2D_CCLK_DIV] = thead_clk_light_divider("light_vpsys_g2d_cclk_div", "video_pll_foutvco", gate_base + 0x30, 0, 4, 4, MUX_TYPE_DIV, 3, 9);
gates[LIGHT_VPSYS_G2D_CCLK_DIV] = thead_clk_light_divider("light_vpsys_g2d_cclk_div", "video_pll_foutvco", gate_base + 0x30, 0, 4, 4, MUX_TYPE_DIV, 3, 15);
gates[LIGHT_VPSYS_DEC_CCLK_DIV] = thead_clk_light_divider("light_vpsys_dec_cclk_div", "video_pll_foutvco", gate_base + 0x24, 0, 4, 4, MUX_TYPE_DIV, 4, 15);
/* G2D clock configuration : Completed the upward configuration of CCLK */
gates[LIGHT_VPSYS_G2D_PCLK] = thead_clk_light_gate_shared("clkgen_vpsys_g2d_pclk", NULL,
@@ -51,11 +52,12 @@ static int light_vpsys_clk_probe(struct platform_device *pdev)
gates[LIGHT_VPSYS_FCE_ACLK] = thead_clk_light_gate_shared("clkgen_vpsys_fce_aclk", NULL,
gate_base + 0x20, 2, &share_cnt_fce_clk_en);
/* VENC&VDEC clock configuration : Completed the upward configuration of CCLK */
gates[LIGHT_VPSYS_VDEC_ACLK] = thead_clk_light_gate("clkgen_vdec_aclk", NULL, gate_base + 0x20, 4);
gates[LIGHT_VPSYS_VDEC_CCLK] = thead_clk_light_gate("clkgen_vdec_cclk", NULL, gate_base + 0x20, 5);
gates[LIGHT_VPSYS_VDEC_CCLK] = thead_clk_light_gate("clkgen_vdec_cclk", "light_vpsys_dec_cclk_div", gate_base + 0x20, 5);
gates[LIGHT_VPSYS_VDEC_PCLK] = thead_clk_light_gate("clkgen_vdec_pclk", NULL, gate_base + 0x20, 6);
gates[LIGHT_VPSYS_VENC_CCLK] = thead_clk_light_gate("clkgen_venc_cclk", NULL, gate_base + 0x20, 8);
gates[LIGHT_VPSYS_VENC_CCLK] = thead_clk_light_gate("clkgen_venc_cclk", "clkgen_vpsys_venc_cclk", gate_base + 0x20, 8);
gates[LIGHT_VPSYS_VENC_PCLK] = thead_clk_light_gate("clkgen_venc_pclk", NULL, gate_base + 0x20, 9);
gates[LIGHT_VPSYS_VENC_ACLK] = thead_clk_light_gate("clkgen_venc_aclk", NULL, gate_base + 0x20, 7);

View File

@@ -240,6 +240,15 @@ static int light_cpufreq_suspend(struct cpufreq_policy *policy)
return ret;
}
/*
* skip to siwtch pll during reboot process
*/
mutex_lock(&cpufreq_lock);
if (cpufreq_denied) {
pr_debug("Denied to switch CPU PLL temporarily on reboot\n");
mutex_unlock(&cpufreq_lock);
return 0;
}
/*
* Only CPU PLL0 would be active after STR resume. We should switch
* CPU PLL to be PLL0 after policy stopped.
@@ -247,12 +256,36 @@ static int light_cpufreq_suspend(struct cpufreq_policy *policy)
if (_light_get_pllid() == LIGHT_CPU_PLL_IDX(1))
_light_switch_pllid(LIGHT_CPU_PLL_IDX(0), policy->suspend_freq);
/*
* switch pll1 to min_freq, as pll1 also needs to be a known value
* or unexpected errors would come out during recovery.
*/
clk_prepare_enable(clks[LIGHT_CPU_PLL1_FOUTPOSTDIV].clk);
clk_set_rate(clks[LIGHT_CPU_PLL1_FOUTPOSTDIV].clk, min_freq * 1000);
clk_disable_unprepare(clks[LIGHT_CPU_PLL1_FOUTPOSTDIV].clk);
mutex_unlock(&cpufreq_lock);
return 0;
}
static int light_cpufreq_resume(struct cpufreq_policy *policy)
{
return 0;
int ret;
ret = __cpufreq_driver_target(policy, min_freq, CPUFREQ_RELATION_H);
if (ret)
pr_err("%s: unable to set restore-freq: %u. err: %d\n",
__func__, min_freq, ret);
/*
* CPU PLL0 with 300M would be active after STR resume. As we switch CPU PLL
* to PLL0 with highest frequency when suspend, switch PLL0 with right one
* after resume.
*/
mutex_lock(&cpufreq_lock);
if(_light_get_pllid() == LIGHT_CPU_PLL_IDX(1))
_light_switch_pllid(LIGHT_CPU_PLL_IDX(0), min_freq);
mutex_unlock(&cpufreq_lock);
return ret;
}
static int light_cpufreq_init(struct cpufreq_policy *policy)

View File

@@ -872,6 +872,7 @@ dma_chan_prep_dma_memcpy(struct dma_chan *dchan, dma_addr_t dst_adr,
goto err_desc_get;
desc->chan = chan;
chan->direction = DMA_MEM_TO_MEM;
num = 0;
desc->length = 0;
while (len) {

View File

@@ -14,7 +14,8 @@
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#define MAX_RX_TIMEOUT (msecs_to_jiffies(300))
/* wait for response for 3000ms instead of 300ms (fix me pls)*/
#define MAX_RX_TIMEOUT (msecs_to_jiffies(3000))
#define MAX_TX_TIMEOUT (msecs_to_jiffies(500))
struct light_aon_chan {

View File

@@ -16823,9 +16823,32 @@ gckHARDWARE_SetClock(
gctUINT32 core = Core;
gctUINT32 mcScale = MCScale;
gctUINT32 shScale = SHScale;
gceCHIPPOWERSTATE statesStored,state;
gcmkHEADER();
gckHARDWARE_QueryPowerState(
Hardware, &statesStored
);
switch(statesStored)
{
case gcvPOWER_OFF:
state = gcvPOWER_OFF_BROADCAST;
break;
case gcvPOWER_IDLE:
state = gcvPOWER_IDLE_BROADCAST;
break;
case gcvPOWER_SUSPEND:
state = gcvPOWER_SUSPEND_BROADCAST;
break;
case gcvPOWER_ON:
state = gcvPOWER_ON_AUTO;
break;
default:
state = statesStored;
break;
}
status = gckOS_QueryOption(Hardware->os, "powerManagement", &powerManagement);
if (gcmIS_ERROR(status))
{
@@ -16838,9 +16861,7 @@ gckHARDWARE_SetClock(
Hardware, gcvFALSE
));
gcmkPRINT("Warning: Power management status will be changed forever!\n");
}
gcmkONERROR(gckHARDWARE_SetPowerState(
Hardware, gcvPOWER_ON_AUTO
));
@@ -16977,6 +16998,15 @@ gckHARDWARE_SetClock(
globalAcquired = gcvFALSE;
gcmkFOOTER_NO();
if (powerManagement)
{
gcmkONERROR(gckHARDWARE_EnablePowerManagement(
Hardware, gcvTRUE
));
}
gckHARDWARE_SetPowerState(
Hardware, state
);
return gcvSTATUS_OK;
@@ -16990,7 +17020,6 @@ OnError:
}
gcmkFOOTER_NO();
return status;
}

View File

@@ -599,7 +599,6 @@ struct _gckKERNEL
gcsTIMER timers[8];
gctUINT32 timeOut;
#if gcdDVFS
gckDVFS dvfs;
#endif
@@ -662,6 +661,12 @@ struct _gckKERNEL
gctSEMAPHORE preemptSema;
gcePREEMPTION_MODE preemptionMode;
#endif
gctUINT64 cur_on;
gctUINT64 cur_idel;
gctUINT64 cur_off;
gctUINT64 cur_suspend;
gctUINT64 cur_load;
unsigned int cur_freq;
};
struct _FrequencyHistory

View File

@@ -61,6 +61,17 @@
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/io.h>
#include <linux/clk.h>
#include <linux/devfreq.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/pm_opp.h>
#include <linux/platform_device.h>
#include <linux/devfreq-event.h>
#include <linux/export.h>
#include <linux/of.h>
#include <linux/regulator/consumer.h>
#define _GC_OBJ_ZONE gcvZONE_DEVICE
@@ -312,137 +323,36 @@ int gc_load_show(void* m, void* data)
{
int len = 0;
gctUINT32 i = 0;
gceSTATUS status = gcvSTATUS_OK;
gckGALDEVICE device = galDevice;
gceCHIPPOWERSTATE statesStored, state;
gctUINT32 load[gcvCORE_3D_MAX + 1] = {0};
gctUINT32 hi_total_cycle_count[gcvCORE_3D_MAX + 1] = {0};
gctUINT32 hi_total_idle_cycle_count[gcvCORE_3D_MAX + 1] = {0};
static gctBOOL profilerEnable[gcvCORE_3D_MAX + 1] = {gcvFALSE};
#ifdef CONFIG_DEBUG_FS
void* ptr = m;
#else
char* ptr = (char*)m;
#endif
if (!device)
if (!device) {
return -ENXIO;
for (i = 0; i <= gcvCORE_3D_MAX; i++)
{
if (device->kernels[i])
{
if (device->kernels[i]->hardware)
{
gckHARDWARE Hardware = device->kernels[i]->hardware;
gctBOOL powerManagement = Hardware->options.powerManagement;
if (powerManagement)
{
gcmkONERROR(gckHARDWARE_EnablePowerManagement(
Hardware, gcvFALSE
));
}
gcmkONERROR(gckHARDWARE_QueryPowerState(
Hardware, &statesStored
));
gcmkONERROR(gckHARDWARE_SetPowerState(
Hardware, gcvPOWER_ON_AUTO
));
if (!profilerEnable[i])
{
gcmkONERROR(gckHARDWARE_SetGpuProfiler(
Hardware,
gcvTRUE
));
gcmkONERROR(gckHARDWARE_InitProfiler(Hardware));
profilerEnable[i] = gcvTRUE;
}
Hardware->waitCount = 200 * 100;
}
}
}
for (i = 0; i <= gcvCORE_3D_MAX; i++)
{
if (device->kernels[i])
for (i = 0; i <= gcvCORE_2D_MAX; i++)
{
if (device->kernels[i]->hardware)
if (device->kernels[i])
{
gcmkONERROR(gckHARDWARE_CleanCycleCount(device->kernels[i]->hardware));
}
}
}
for (i = 0; i <= gcvCORE_3D_MAX; i++)
{
if (device->kernels[i])
{
if (device->kernels[i]->hardware)
{
gcmkONERROR(gckHARDWARE_QueryCycleCount(device->kernels[i]->hardware, &hi_total_cycle_count[i], &hi_total_idle_cycle_count[i]));
}
}
}
for (i = 0; i <= gcvCORE_3D_MAX; i++)
{
if (device->kernels[i])
{
if (device->kernels[i]->hardware)
{
gckHARDWARE Hardware = device->kernels[i]->hardware;
gctBOOL powerManagement = Hardware->options.powerManagement;
switch(statesStored)
if (device->kernels[i]->hardware)
{
case gcvPOWER_OFF:
state = gcvPOWER_OFF_BROADCAST;
break;
case gcvPOWER_IDLE:
state = gcvPOWER_IDLE_BROADCAST;
break;
case gcvPOWER_SUSPEND:
state = gcvPOWER_SUSPEND_BROADCAST;
break;
case gcvPOWER_ON:
state = gcvPOWER_ON_AUTO;
break;
default:
state = statesStored;
break;
}
Hardware->waitCount = 200;
if (powerManagement)
{
gcmkONERROR(gckHARDWARE_EnablePowerManagement(
Hardware, gcvTRUE
));
}
gcmkONERROR(gckHARDWARE_SetPowerState(
Hardware, state
));
load[i] = (hi_total_cycle_count[i] - hi_total_idle_cycle_count[i]) * 100 / hi_total_cycle_count[i];
len += fs_printf(ptr, "core : %d\n", i);
len += fs_printf(ptr + len, "load : %d%%\n",load[i]);
len += fs_printf(ptr + len, "load : %d%%\n",device->kernels[i]->cur_load);
len += fs_printf(ptr + len, "\n");
}
}
}
}
OnError:
return len;
}
@@ -2419,6 +2329,154 @@ _StopPreemptThread(
}
#endif
/******************************************************************************\
******************************* G2D Devfreq support START***********************
\******************************************************************************/
static int gc_df_target(struct device * dev, unsigned long *freq, u32 flags) {
int i = 0;
gctUINT32 _freq = 64;
gckHARDWARE hardware;
gckGALDEVICE device = galDevice;
struct dev_pm_opp *opp;
opp = devfreq_recommended_opp(dev, freq, flags);
if (IS_ERR(opp)) {
dev_info(dev, "Failed to find opp for %lu Hz\n", *freq);
return PTR_ERR(opp);
}
dev_pm_opp_put(opp);
switch (*freq)
{
case 396000000:
_freq = 64;
break;
case 198000000:
_freq = 32;
break;
case 99000000:
_freq = 16;
break;
case 49500000:
_freq = 8;
break;
default:
break;
}
for(i = 0; i < gcvCORE_2D_MAX; i++) {
if(device->kernels[i]) {
hardware = device->kernels[i]->hardware;
if(hardware->clockState) {
gckHARDWARE_SetClock(hardware, i, _freq, _freq);
device->kernels[i]->cur_freq = *freq;
}
}
}
return 0;
}
static int gc_df_status(struct device *dev, struct devfreq_dev_status *stat) {
gckGALDEVICE device = galDevice;
gckKERNEL kernel = _GetValidKernel(device);
gctUINT64 on = 0;
gctUINT64 off = 0;
gctUINT64 idle = 0;
gctUINT64 suspend = 0;
int i = 0;
gckHARDWARE_QueryStateTimer(kernel->hardware, &on, &off, &idle, &suspend);
for(i = 0; i < gcvCORE_2D_MAX; i++) {
if(device->kernels[i]) {
stat->current_frequency = device->kernels[i]->cur_freq;
stat->busy_time = on - device->kernels[i]->cur_on;
stat->total_time = on - device->kernels[i]->cur_on +
idle - device->kernels[i]->cur_idel +
suspend - device->kernels[i]->cur_suspend +
off - device->kernels[i]->cur_off;
device->kernels[i]->cur_load = stat->busy_time * 100 / stat->total_time;
device->kernels[i]->cur_on = on;
device->kernels[i]->cur_idel = idle;
device->kernels[i]->cur_suspend = suspend;
device->kernels[i]->cur_off = off;
}
}
return 0;
}
static int gc_df_get_cur_freq(struct device *dev, unsigned long *freq) {
int i = 0;
gckGALDEVICE device = galDevice;
for(i = 0; i < gcvCORE_2D_MAX; i++) {
if(device->kernels[i]) {
*freq = device->kernels[i]->cur_freq;
}
}
return 0;
}
struct devfreq_simple_ondemand_data galcore_gov_data;
static struct devfreq_dev_profile gc_df_profile = {
.polling_ms = 500,
.target = gc_df_target,
.get_dev_status = gc_df_status,
.get_cur_freq = gc_df_get_cur_freq,
};
gceSTATUS
g2d_EnableDevfreq(void) {
gceSTATUS status = gcvSTATUS_OK;
struct clk *new_clk;
int ret = 0;
gckGALDEVICE device = galDevice;
int i = 0;
ret = dev_pm_opp_of_add_table(galcore_device);
if(ret) {
gcmkPRINT("add table failed \n");
}
new_clk = devm_clk_get(galcore_device, "cclk");
clk_set_rate(new_clk, 792000000);
for(i = 0; i < gcvCORE_2D_MAX; i++) {
if(device->kernels[i]) {
device->kernels[i]->cur_freq = clk_get_rate(new_clk) / 2;
device->kernels[i]->cur_idel = 0;
device->kernels[i]->cur_off = 0;
device->kernels[i]->cur_on = 0;
device->kernels[i]->cur_suspend = 0;
device->kernels[i]->cur_load = 0;
gc_df_profile.initial_freq = device->kernels[i]->cur_freq;
}
}
galcore_gov_data.upthreshold = 80;
galcore_gov_data.downdifferential = 5;
galDevice->g2d_devfreq = devm_devfreq_add_device(galcore_device, &gc_df_profile, DEVFREQ_GOV_SIMPLE_ONDEMAND, &galcore_gov_data);
if(IS_ERR(galDevice->g2d_devfreq)) {
gcmkPRINT("Errot: init devgreq %lx\n", (unsigned long)galcore_device);
status = gcvSTATUS_NOT_SUPPORTED;
}
return status;
}
/******************************************************************************\
******************************* G2D Devfreq support END ************************
\******************************************************************************/
/*******************************************************************************
**
** gckGALDEVICE_Construct
@@ -2788,6 +2846,8 @@ gckGALDEVICE_Construct(
/* Return pointer to the device. */
*Device = galDevice = device;
g2d_EnableDevfreq();
devfreq_suspend_device(galDevice->g2d_devfreq);
OnError:
if (gcmIS_ERROR(status))
@@ -3064,6 +3124,7 @@ gckGALDEVICE_Destroy(
/* Free the device. */
kfree(Device);
}
gcmkFOOTER_NO();
@@ -3218,5 +3279,4 @@ gckGALDEVICE_Stop(
OnError:
gcmkFOOTER();
return status;
}
}

View File

@@ -150,6 +150,11 @@ typedef struct _gckGALDEVICE
/* gctsOs object for trust application. */
gctaOS taos;
/*Number of devices opened*/
atomic_t openNum;
/*object of devfreq add device*/
struct devfreq *g2d_devfreq;
#if gcdENABLE_DRM
void * drm;
#endif

View File

@@ -62,7 +62,8 @@
#include "gc_hal_driver.h"
#include <linux/platform_device.h>
#include <linux/devfreq.h>
#include <linux/devfreq-event.h>
/* Zone used for header/footer. */
#define _GC_OBJ_ZONE gcvZONE_DRIVER
@@ -821,6 +822,8 @@ static int drv_open(
filp->private_data = data;
/* Success. */
atomic_inc_return(&galDevice->openNum);
devfreq_resume_device(galDevice->g2d_devfreq);
gcmkFOOTER_NO();
return 0;
}
@@ -887,6 +890,9 @@ static int drv_release(
kfree(data);
filp->private_data = NULL;
if(atomic_dec_return(&galDevice->openNum) == 0) {
devfreq_suspend_device(galDevice->g2d_devfreq);
}
/* Success. */
ret = 0;
@@ -1523,6 +1529,7 @@ static int gpu_suspend(struct platform_device *dev, pm_message_t state)
status = gckHARDWARE_SetPowerState(device->kernels[i]->hardware, gcvPOWER_OFF);
}
if (gcmIS_ERROR(status))
{
return -1;

View File

@@ -648,7 +648,9 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)
* Anytime TX_ABRT is set, the contents of the tx/rx
* buffers are flushed. Make sure to skip them.
*/
regmap_write(dev->map, DW_IC_INTR_MASK, 0);
if (!dev->dw_i2c_enable_dma) {
regmap_write(dev->map, DW_IC_INTR_MASK, 0);
}
goto tx_aborted;
}

View File

@@ -36,12 +36,14 @@
/* clock divider for speed */
#define GMAC_CLKDIV_125M (GMAC_CLK_PLLOUT_250M / GMAC_GMII_RGMII_RATE)
#define GMAC_CLKDIV_25M (GMAC_CLK_PLLOUT_250M / GMAC_MII_RATE)
#define GMAC_PTP_CLK_RATE 50000000 //50MHz
struct thead_dwmac_ops {
void (*set_clk_source)(struct plat_stmmacenet_data *plat_dat);
void (*set_clk_pll)(struct plat_stmmacenet_data *plat_dat);
void (*set_clk_div)(struct plat_stmmacenet_data *plat_dat, unsigned int speed);
void (*enable_clk)(struct plat_stmmacenet_data *plat_dat);
void (*set_ptp_div)(struct plat_stmmacenet_data *plat_dat,unsigned int ptp_clk_rate);
};
struct thead_dwmac_priv_data {
@@ -352,6 +354,35 @@ static void thead_dwmac_light_set_clk_div(struct plat_stmmacenet_data *plat_dat,
}
}
static void thead_dwmac_light_set_ptp_clk_div(struct plat_stmmacenet_data *plat_dat,unsigned int ptp_clk_rate)
{
unsigned int div;
unsigned int reg;
struct thead_dwmac_priv_data *thead_plat_dat = plat_dat->bsp_priv;
void __iomem *gmac_clk_reg = thead_plat_dat->gmac_clk_reg;
unsigned long src_freq = thead_plat_dat->gmac_pll_clk_freq;
if (gmac_clk_reg == NULL)
return;
if(!ptp_clk_rate || !src_freq)
{
pr_warn("invalid gmac pll freq %lu or ptp_clk_rate %d\n", src_freq,ptp_clk_rate);
return;
}
/* disable clk_div */
reg = readl(gmac_clk_reg + GMAC_CLK_CFG5);
reg &= ~BIT(31);
writel(reg, gmac_clk_reg + GMAC_CLK_CFG5);
div = src_freq / ptp_clk_rate;
writel(div,gmac_clk_reg + GMAC_CLK_CFG5);
/* enable clk_div */
reg = div | BIT(31);
writel(reg, gmac_clk_reg + GMAC_CLK_CFG5);
return ;
}
/* enable gmac clock */
static void thead_dwmac_ice_enable_clk(struct plat_stmmacenet_data *plat_dat)
{
@@ -659,6 +690,8 @@ int thead_dwmac_clk_init(struct platform_device *pdev, void *bsp_priv)
if (thead_plat_dat->ops->enable_clk)
thead_plat_dat->ops->enable_clk(plat_dat);
if (thead_plat_dat->ops->set_ptp_div)
thead_plat_dat->ops->set_ptp_div(plat_dat,plat_dat->clk_ptp_rate);
//thead_dwmac_dump_priv_reg(pdev,bsp_priv);
return ret;
}
@@ -770,6 +803,8 @@ static int thead_dwmac_probe(struct platform_device *pdev)
if (ret)
goto err_remove_config_dt;
plat_dat->clk_ptp_rate = GMAC_PTP_CLK_RATE;
ret = thead_dwmac_clk_enable(pdev, plat_dat->bsp_priv);
if (ret)
goto err_remove_config_dt;
@@ -932,6 +967,7 @@ static struct thead_dwmac_ops thead_ice_dwmac_data = {
static struct thead_dwmac_ops thead_light_dwmac_data = {
.set_clk_div = thead_dwmac_light_set_clk_div,
.enable_clk = thead_dwmac_light_enable_clk,
.set_ptp_div = thead_dwmac_light_set_ptp_clk_div,
};
static const struct of_device_id thead_dwmac_match[] = {

View File

@@ -738,6 +738,7 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
struct timespec64 now;
u32 sec_inc = 0;
u64 temp = 0;
int ret;
if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
return -EOPNOTSUPP;
@@ -761,14 +762,26 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
*/
temp = (u64)(temp << 32);
priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
ret = stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
if(ret < 0)
{
netdev_warn(priv->dev,
"failed to config PTP addend: %pe\n",
ERR_PTR(ret));
return ret;
}
/* initialize system time */
ktime_get_real_ts64(&now);
/* lower 32 bits of tv_sec are safe until y2106 */
stmmac_init_systime(priv, priv->ptpaddr, (u32)now.tv_sec, now.tv_nsec);
ret = stmmac_init_systime(priv, priv->ptpaddr, (u32)now.tv_sec, now.tv_nsec);
if(ret < 0)
{
netdev_warn(priv->dev,
"failed to init systime: %pe\n",
ERR_PTR(ret));
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(stmmac_init_tstamp_counter);
@@ -3840,10 +3853,10 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
if(likely(!buf->rx_skbuff)){
len = stmmac_get_rx_buf_frsize(priv);
skb = netdev_alloc_skb(priv->dev, len);
skb = __netdev_alloc_skb(priv->dev, len, gfp);
if (!skb){
//priv->dev->stats.rx_dropped += (1ul<<32);
netdev_err(priv->dev, "%s: dalloc_skb failed,dirty ring %d :\n", __func__,dirty);
netdev_dbg(priv->dev, "%s: dalloc_skb failed,dirty ring %d :\n", __func__,dirty);
break;
}
if(stmmac_get_skb_dma_addr(priv,skb,&buf->addr) < 0){

View File

@@ -129,7 +129,7 @@ CONFIG_PNO_SUPPORT = n
CONFIG_PNO_SET_DEBUG = n
CONFIG_AP_WOWLAN = n
######### Notify SDIO Host Keep Power During Syspend ##########
CONFIG_RTW_SDIO_PM_KEEP_POWER = y
CONFIG_RTW_SDIO_PM_KEEP_POWER = n
###################### MP HW TX MODE FOR VHT #######################
CONFIG_MP_VHT_HW_TX_MODE = n
###################### ROAMING #####################################
@@ -1189,9 +1189,9 @@ EXTRA_CFLAGS += -DRTW_SUSPEND_TYPE=$(CONFIG_SUSPEND_TYPE)
ifeq ($(CONFIG_WOW_STA_MIX), y)
EXTRA_CFLAGS += -DRTW_WOW_STA_MIX
endif
ifeq ($(CONFIG_SDIO_HCI), y)
EXTRA_CFLAGS += -DCONFIG_RTW_SDIO_PM_KEEP_POWER
endif
# ifeq ($(CONFIG_SDIO_HCI), y)
# EXTRA_CFLAGS += -DCONFIG_RTW_SDIO_PM_KEEP_POWER
# endif
endif
ifeq ($(CONFIG_AP_WOWLAN), y)
@@ -1199,9 +1199,9 @@ EXTRA_CFLAGS += -DCONFIG_AP_WOWLAN
ifeq ($(CONFIG_AP_MODE), n)
EXTRA_CFLAGS += -DCONFIG_AP_MODE
endif
ifeq ($(CONFIG_SDIO_HCI), y)
EXTRA_CFLAGS += -DCONFIG_RTW_SDIO_PM_KEEP_POWER
endif
# ifeq ($(CONFIG_SDIO_HCI), y)
# EXTRA_CFLAGS += -DCONFIG_RTW_SDIO_PM_KEEP_POWER
# endif
endif
ifeq ($(CONFIG_LAYER2_ROAMING), y)

View File

@@ -5162,7 +5162,7 @@ int rtw_suspend_normal(_adapter *padapter)
if ((rtw_hal_check_ips_status(padapter) == _TRUE)
|| (adapter_to_pwrctl(padapter)->rf_pwrstate == rf_off))
RTW_PRINT("%s: ### ERROR #### driver in IPS ####ERROR###!!!\n", __FUNCTION__);
RTW_PRINT("%s: driver in IPS!!!\n", __FUNCTION__);
#ifdef CONFIG_CONCURRENT_MODE

View File

@@ -90,7 +90,7 @@ static int light_suspend_prepare(void)
int ret;
aon_pm_ctrl->suspend_flag = true;
struct light_aon_msg_pm_ctrl msg = {0};
ret = light_require_state_pm_ctrl(&msg, LIGHT_AON_MISC_FUNC_REQUIRE_STR, false);
ret = light_require_state_pm_ctrl(&msg, LIGHT_AON_MISC_FUNC_REQUIRE_STR, true);
if (ret) {
pr_err("[%s,%d]failed to initiate Suspend to Ram process to AON subsystem\n",__func__, __LINE__);
return ret;
@@ -98,9 +98,15 @@ static int light_suspend_prepare(void)
return 0;
}
static void light_resume_wake(void)
static void light_resume_finish(void)
{
int ret;
aon_pm_ctrl->suspend_flag = false;
struct light_aon_msg_pm_ctrl msg = {0};
ret = light_require_state_pm_ctrl(&msg, LIGHT_AON_MISC_FUNC_RESUME_STR, true);
if (ret) {
pr_err("[%s,%d]failed to clear lowpower state\n",__func__, __LINE__);
}
}
static int thead_cpuhp_offline(unsigned int cpu)
@@ -111,7 +117,7 @@ static int thead_cpuhp_offline(unsigned int cpu)
struct light_aon_msg_pm_ctrl msg = {0};
msg.rpc.cpu_info.cpu_id = (u16)cpu;
msg.rpc.cpu_info.status = 0;
ret = light_require_state_pm_ctrl(&msg, LIGHT_AON_MISC_FUNC_CPUHP, false);
ret = light_require_state_pm_ctrl(&msg, LIGHT_AON_MISC_FUNC_CPUHP, true);
if (ret) {
pr_info("failed to notify aon subsys with cpuhp...%08x\n", ret);
return ret;
@@ -128,7 +134,7 @@ static int thead_cpuhp_online(unsigned int cpu)
struct light_aon_msg_pm_ctrl msg = {0};
msg.rpc.cpu_info.cpu_id = (u16)cpu;
msg.rpc.cpu_info.status = 1;
ret = light_require_state_pm_ctrl(&msg, LIGHT_AON_MISC_FUNC_CPUHP, false);
ret = light_require_state_pm_ctrl(&msg, LIGHT_AON_MISC_FUNC_CPUHP, true);
if (ret) {
pr_info("[%s,%d]failed to bring up aon subsys with cpuhp...%08x\n", __func__, __LINE__, ret);
return ret;
@@ -146,7 +152,37 @@ static const struct platform_suspend_ops light_suspend_ops = {
.enter = light_suspend_enter,
.valid = suspend_valid_only_mem,
.prepare_late = light_suspend_prepare,
.wake = light_resume_wake,
.finish = light_resume_finish,
};
#define C906_RESET_REG 0xfffff4403c
static void boot_audio(void) {
uint64_t *v_addr = ioremap(C906_RESET_REG, 4);
if(!v_addr) {
printk("io remap failed\r\n");
return;
}
writel(0x37, (volatile void *)v_addr);
writel(0x3f, (volatile void *)v_addr);
iounmap(C906_RESET_REG);
}
//this is called after dpm_suspend_end,before snapshot
static int light_hibernation_pre_snapshot(void)
{
return 0;
}
//called before dpm_resume_start after slave cores up
static void light_hibernation_platform_finish(void)
{
boot_audio();
return;
}
static const struct platform_hibernation_ops light_hibernation_allmode_ops = {
.pre_snapshot = light_hibernation_pre_snapshot,
.finish = light_hibernation_platform_finish,
};
static int light_pm_probe(struct platform_device *pdev)
@@ -161,13 +197,15 @@ static int light_pm_probe(struct platform_device *pdev)
aon_pm_ctrl = pm_ctrl;
ret = light_aon_get_handle(&(aon_pm_ctrl->ipc_handle));
if (ret == -EPROBE_DEFER) {
pr_err("[%s, %d]failed to register ipc_handler.\n",__func__, __LINE__);
if (ret == -EPROBE_DEFER)
return ret;
}
suspend_set_ops(&light_suspend_ops);
/*only save BSS and data section for audio*/
hibernate_register_nosave_region(__phys_to_pfn(0x32000000), __phys_to_pfn(0x36600000));
hibernation_set_allmode_ops(&light_hibernation_allmode_ops);
ret = cpuhp_setup_state_nocalls(CPUHP_BP_PREPARE_DYN, "soc/thead:online",
thead_cpuhp_online,
thead_cpuhp_offline);

View File

@@ -6,6 +6,7 @@
#include <linux/device.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/freezer.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -23,6 +24,8 @@ struct optee_call_waiter {
struct completion c;
};
struct kref sess_refcount = KREF_INIT(1);
static void optee_cq_wait_init(struct optee_call_queue *cq,
struct optee_call_waiter *w)
{
@@ -51,7 +54,12 @@ static void optee_cq_wait_init(struct optee_call_queue *cq,
static void optee_cq_wait_for_completion(struct optee_call_queue *cq,
struct optee_call_waiter *w)
{
wait_for_completion(&w->c);
/*
* wait_for_completion but allow hibernation/suspend
* to freeze the waiting task
*/
while (wait_for_completion_interruptible(&w->c))
try_to_freeze();
mutex_lock(&cq->mutex);
@@ -273,6 +281,7 @@ int optee_open_session(struct tee_context *ctx,
mutex_lock(&ctxdata->mutex);
list_add(&sess->list_node, &ctxdata->sess_list);
mutex_unlock(&ctxdata->mutex);
kref_get(&sess_refcount);
} else {
kfree(sess);
}
@@ -293,6 +302,15 @@ out:
return rc;
}
static void session_release(struct kref *ref)
{
}
void session_put(void)
{
kref_put(&sess_refcount, session_release);
}
int optee_close_session(struct tee_context *ctx, u32 session)
{
struct optee_context_data *ctxdata = ctx->data;
@@ -320,6 +338,9 @@ int optee_close_session(struct tee_context *ctx, u32 session)
optee_do_call_with_arg(ctx, msg_parg);
tee_shm_free(shm);
session_put();
return 0;
}

View File

@@ -15,6 +15,7 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/suspend.h>
#include <linux/tee_drv.h>
#include <linux/types.h>
#include <linux/uaccess.h>
@@ -265,6 +266,8 @@ static int optee_open(struct tee_context *ctx)
return 0;
}
extern void session_put(void);
static void optee_release(struct tee_context *ctx)
{
struct optee_context_data *ctxdata = ctx->data;
@@ -301,6 +304,7 @@ static void optee_release(struct tee_context *ctx)
arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION;
arg->session = sess->session_id;
optee_do_call_with_arg(ctx, parg);
session_put();
}
kfree(sess);
}
@@ -606,6 +610,8 @@ static optee_invoke_fn *get_invoke_func(struct device *dev)
return ERR_PTR(-EINVAL);
}
extern struct kref sess_refcount;
static int optee_remove(struct platform_device *pdev)
{
struct optee *optee = platform_get_drvdata(pdev);
@@ -763,6 +769,47 @@ err:
return rc;
}
#ifdef CONFIG_PM
#ifdef CONFIG_SUSPEND
static int __maybe_unused tee_driver_suspend(struct device *dev)
{
int ret = 0;
unsigned int ref_count;
if (pm_suspend_target_state == PM_SUSPEND_MEM) {
pr_info("STR mode suspend in\r\n");
return 0;
} else {
ref_count = kref_read(&sess_refcount);
if (ref_count > 1) {
pr_info("tee_driver_suspend failed[%d] \r\n", ref_count);
ret = -1;
} else {
pr_info("tee_driver_suspend success[%d] \r\n", ref_count);
ret = 0;
}
}
return ret;
}
static int __maybe_unused tee_driver_resume(struct device *dev)
{
int ret = 0;
return ret;
}
#else
#define tee_driver_suspend NULL
#define tee_driver_resume NULL
#endif
static const struct dev_pm_ops tee_driver_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(tee_driver_suspend, tee_driver_resume)
};
#endif
static const struct of_device_id optee_dt_match[] = {
{ .compatible = "linaro,optee-tz" },
{},
@@ -775,10 +822,15 @@ static struct platform_driver optee_driver = {
.driver = {
.name = "optee",
.of_match_table = optee_dt_match,
#ifdef CONFIG_PM
.pm = &tee_driver_pm_ops,
#endif
},
};
module_platform_driver(optee_driver);
MODULE_AUTHOR("Linaro");
MODULE_DESCRIPTION("OP-TEE driver");
MODULE_VERSION("1.0");

View File

@@ -7,6 +7,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/freezer.h>
#include <linux/i2c.h>
#include <linux/io.h>
#include <linux/slab.h>
@@ -46,7 +47,6 @@ static void handle_rpc_func_cmd_get_time(struct optee_msg_arg *arg)
ktime_get_real_ts64(&ts);
arg->params[0].u.value.a = ts.tv_sec;
arg->params[0].u.value.b = ts.tv_nsec;
arg->ret = TEEC_SUCCESS;
return;
bad:
@@ -171,7 +171,12 @@ static void wq_sleep(struct optee_wait_queue *wq, u32 key)
struct wq_entry *w = wq_entry_get(wq, key);
if (w) {
wait_for_completion(&w->c);
/*
* wait_for_completion but allow hibernation/suspend
* to freeze the waiting task
*/
while (wait_for_completion_interruptible(&w->c))
try_to_freeze();
mutex_lock(&wq->mu);
list_del(&w->link);
mutex_unlock(&wq->mu);

View File

@@ -3,6 +3,7 @@
* Copyright (c) 2015, Linaro Limited
*/
#include <linux/device.h>
#include <linux/freezer.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include "optee_private.h"
@@ -141,6 +142,7 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
req->ret = TEEC_ERROR_COMMUNICATION;
break;
}
try_to_freeze();
}
ret = req->ret;