local_t dfs_ret pwrctrl_dfs_cmd_rqqos(s32_t qos_id, u32_t req_value, s32_t* req_id)
{
    union mca_udata_req req;
    union mca_udata_rsp rsp;

    /*printk(KERN_NOTICE "%s qos_id:%d req_value:%d\n", __FUNCTION__, qos_id, req_value);*/
    if(!req_id)
        return RET_ERR_PARAM_NULL;

    req.dfs_rqqos_req.qos_id    = qos_id;
    req.dfs_rqqos_req.req_value = req_value;
    req.dfs_rqqos_req.core_id   = DFS_CORE_ACPU;

    if(mca_send(MCA_CMD_DFS_RQQOS, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
    {
        printk(KERN_NOTICE "%s error!!! mailbox timeout req_id:%d\n", __FUNCTION__, *req_id);
        return RET_ERR_CONNECT_FAIL;
    }

    if(0 == rsp.dfs_rqqos_rsp.ret)
    {
        *req_id = rsp.dfs_rqqos_rsp.req_id;
    }

    /*printk(KERN_NOTICE "%s req_id:%d\n", __FUNCTION__, rsp.dfs_rqqos_rsp.req_id);*/

    return rsp.dfs_rqqos_rsp.ret;
}
local_t dfs_ret pwrctrl_dfs_cmd_rlqos(s32_t qos_id, s32_t* req_id)
{
    union mca_udata_req req;
    union mca_udata_rsp rsp;

    if(!req_id)
        return RET_ERR_PARAM_NULL;

    /*printk(KERN_NOTICE "%s qos_id:%d req_id:%d\n", __FUNCTION__, qos_id, *req_id);*/
    req.dfs_rlqos_req.qos_id  = qos_id;
    req.dfs_rlqos_req.req_id  = *req_id;
    req.dfs_rlqos_req.core_id = DFS_CORE_ACPU;

    if(mca_send(MCA_CMD_DFS_RLQOS, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
    {
        printk(KERN_NOTICE "%s error!!! mailbox timeout req_id:%d\n", __FUNCTION__, *req_id);
        *req_id = DFS_INVALID_ID;
	return RET_ERR_CONNECT_FAIL;
    }

    *req_id = rsp.dfs_rlqos_rsp.req_id;

    /*printk(KERN_NOTICE "%s req_id:%d ret:%d\n", __FUNCTION__, *req_id, rsp.dfs_rlqos_rsp.ret);*/
    return rsp.dfs_rlqos_rsp.ret;
}
/*****************************************************************************

 函 数 名  : pwrctrl_dfs_cmd_rlqos
 功能描述  : 释放DFS QoS
 输入参数  : qos_id - QoS ID
             req_id - 请求ID
 输出参数  : 无
 返 回 值  : DFS_RET_OK - Success
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2012年8月15日
    作    者   : 黄星宇 212111
    修改内容   : 新生成函数

*****************************************************************************/
local_t dfs_ret pwrctrl_dfs_cmd_rlqos(s32_t qos_id, s32_t* req_id)
{
    union mca_udata_req req = {0};
    union mca_udata_rsp rsp = {0};

    if(!req_id)
        return RET_ERR_PARAM_NULL;

    printk(KERN_NOTICE "%s qos_id:%d req_id:%d\n", __FUNCTION__, qos_id, *req_id);
    req.dfs_rlqos_req.qos_id = qos_id;
    req.dfs_rlqos_req.req_id = *req_id;

    if(mca_send(MCA_CMD_DFS_RLQOS, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
    {
        /*w00176398 just workaround*/
        *req_id = DFS_INVALID_ID;
        printk(KERN_NOTICE "%s error!!! mailbox timeout req_id:%d\n", __FUNCTION__, *req_id);
        return RET_ERR_CONNECT_FAIL;
    }

    *req_id = rsp.dfs_rlqos_rsp.req_id;

    printk(KERN_NOTICE "%s req_id:%d ret:%d\n", __FUNCTION__, *req_id, rsp.dfs_rlqos_rsp.ret);
    return rsp.dfs_rlqos_rsp.ret;
}
int test_mca_cmd(MCA_CMD_ID cmd_id,s32_t qos_id, u32_t req_value,int time_out)
{
    union mca_udata_req req;
    union mca_udata_rsp rsp;
    s32_t buf[32] = {0};
    s32_t* req_id = &buf[0];

    if(!req_id)
        return RET_ERR_PARAM_NULL;

    req.dfs_rqqos_req.qos_id    = qos_id;
    req.dfs_rqqos_req.req_value = req_value;
    req.dfs_rqqos_req.core_id   = 2;

    if(-1 == mca_send(cmd_id , req, &rsp, time_out))
    {
        printk("mca_send failed!!!\n");
        return RET_ERR;
    }
    *req_id = rsp.dfs_rqqos_rsp.req_id;

    printk("req_id:%d\n",*req_id);
    
    return rsp.dfs_rqqos_rsp.ret;
}
local_t dfs_ret pwrctrl_dfs_cmd_set_policy(s32_t policy_id, void *policy_buf, unsigned int len)
{
#if 0
    union mca_udata_req req;
    union mca_udata_rsp rsp;

    if(len > POLICY_MAX_TOTAL_SIZE)
    {
        printk(KERN_ERR "%s policy_id:%d len:%d exceed max value(%d) error!!!\n", __FUNCTION__, policy_id, len, POLICY_MAX_TOTAL_SIZE);
        return -1;
    }

    printk(KERN_NOTICE "%s policy_id:%d len:%d\n", __FUNCTION__, policy_id, len);

    req.dfs_setpli_req.policy_id = policy_id;
    memcpy(req.dfs_setpli_req.pli_buf, policy_buf, len);

    if(mca_send(MCA_CMD_DFS_SETPLI, &req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
        return RET_ERR_CONNECT_FAIL;

    printk(KERN_NOTICE "%s ret:%d\n", __FUNCTION__, rsp.dfs_setpli_rsp.ret);
    return rsp.dfs_setpli_rsp.ret;
#endif
    unsigned int poli_id = 0;
    unsigned int cur_poli_addr = 0;

    if(NULL == policy_buf)
    {
        printk(KERN_ERR "%s policy buf is null,policy_id:%d len:%d!!!\n", __FUNCTION__, policy_id, len);
        return -1;
    }

    poli_id = *(unsigned int *)policy_buf;

    printk(KERN_INFO"%s policy_id:%d set policy:%d!!!\n", __FUNCTION__, policy_id, poli_id);

    if(DFS_POLICY_ID_DDR == policy_id)
    {
        cur_poli_addr = (unsigned int)ioremap(DDR_POLICY_CUR_POLICY, 0x1000);
    }
    else
    {
        printk(KERN_ERR"pwrctrl_dfs_cmd_set_policy don't support %d\n", policy_id);
        return 0;
    }

    writel(poli_id, cur_poli_addr);

    return 0;
}
/*****************************************************************************
 函 数 名  : pwrctrl_dfs_cmd_unlock
 功能描述  : 解锁频DFS QoS
 输入参数  : dev_id - Dev ID
 输出参数  : 无
 返 回 值  : DFS_RET_OK - Success
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2013年4月26日
    作    者   : 王振伟 176398
    修改内容   : 新生成函数

*****************************************************************************/
local_t dfs_ret pwrctrl_dfs_cmd_unlock(s32_t dev_id)
{
    union mca_udata_req req = {0};
    union mca_udata_rsp rsp = {0};

    printk(KERN_NOTICE "%s dev_id:%d\n", __FUNCTION__, dev_id);
    req.dfs_unlock_req.dev_id = dev_id;

    if(mca_send(MCA_CMD_DFS_UNLOCK, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
        return RET_ERR_CONNECT_FAIL;

    printk(KERN_NOTICE "%s ret:%d\n", __FUNCTION__, rsp.dfs_unlock_rsp.ret);
    return rsp.dfs_unlock_rsp.ret;
}
local_t dfs_ret pwrctrl_dfs_cmd_current(s32_t dev_id, u32_t *prof_id)
{
    union mca_udata_req req = {0};
    union mca_udata_rsp rsp = {0};

    PRINT_PWC_DBG(PWC_SWITCH_DEBPT, "%s dev_id:%d\n", __FUNCTION__, dev_id);
    req.dfs_current_req.dev_id = dev_id;

    if(mca_send(MCA_CMD_DFS_CURRENT, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
        return RET_ERR_CONNECT_FAIL;

    *prof_id = rsp.dfs_current_rsp.prof_id;

    PRINT_PWC_DBG(PWC_SWITCH_DEBPT, "%s prof_id:%d ret:%d\n", __FUNCTION__, *prof_id, rsp.dfs_current_rsp.ret);
    return rsp.dfs_current_rsp.ret;
}
/*****************************************************************************
 函 数 名  : pwrctrl_dfs_cmd_udqos
 功能描述  : 更新DFS QoS
 输入参数  : qos_id - QoS ID
             req_id - 请求ID
 输出参数  : 无
 返 回 值  : DFS_RET_OK - Success
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2012年8月15日
    作    者   : 黄星宇 212111
    修改内容   : 新生成函数

*****************************************************************************/
local_t dfs_ret pwrctrl_dfs_cmd_udqos(s32_t qos_id, s32_t req_id, u32_t req_value)
{
    union mca_udata_req req = {0};
    union mca_udata_rsp rsp = {0};

    printk(KERN_NOTICE "%s qos_id:%d req_id:%d req_value:%d\n", __FUNCTION__,
        qos_id, req_id, req_value);
    req.dfs_udqos_req.qos_id    = qos_id;
    req.dfs_udqos_req.req_id    = req_id;
    req.dfs_udqos_req.req_value = req_value;

    if(mca_send(MCA_CMD_DFS_UDQOS, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
        return RET_ERR_CONNECT_FAIL;
    printk(KERN_NOTICE "%s ret:%d\n", __FUNCTION__, rsp.dfs_udqos_rsp.ret);
    return rsp.dfs_udqos_rsp.ret;
}
local_t dfs_ret pwrctrl_dfs_cmd_lock(s32_t dev_id, u32_t prof_id)
{
    union mca_udata_req req;
    union mca_udata_rsp rsp;

    /*printk(KERN_NOTICE "%s dev_id:%d prof_id:%d\n", __FUNCTION__, dev_id, prof_id);*/
    req.dfs_lock_req.dev_id = dev_id;
    req.dfs_lock_req.prof_id = prof_id;

    if(mca_send(MCA_CMD_DFS_LOCK, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
    {
        printk(KERN_NOTICE "%s error!!! mailbox timeout dev_id:%d\n", __FUNCTION__, dev_id);
        return RET_ERR_CONNECT_FAIL;
    }
    /*printk(KERN_NOTICE "%s ret:%d\n", __FUNCTION__, rsp.dfs_lock_rsp.ret);*/
    return rsp.dfs_lock_rsp.ret;
}
local_t dfs_ret pwrctrl_dfs_cmd_set_profile(s32_t dev_id, void *profile_buf, unsigned int len)
{
    union mca_udata_req req;
    union mca_udata_rsp rsp;

    if(len > PROFILE_MAX_TOTAL_SIZE)
    {
        printk(KERN_ERR "%s dev_id:%d len:%d exceed max value(%d) error!!!\n", __FUNCTION__, dev_id, len, PROFILE_MAX_TOTAL_SIZE);
        return -1;
    }

    printk(KERN_NOTICE "%s dev_id:%d len:%d\n", __FUNCTION__, dev_id, len);
    req.dfs_set_prof_req.dev_id = dev_id;
    memcpy(req.dfs_set_prof_req.prof_buf, profile_buf, len);

    if(mca_send(MCA_CMD_DFS_SETPROFILE, &req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
        return RET_ERR_CONNECT_FAIL;
    printk(KERN_NOTICE "%s ret:%d\n", __FUNCTION__, rsp.dfs_set_prof_rsp.ret);
    return rsp.dfs_set_prof_rsp.ret;
}
local_t dfs_ret pwrctrl_dfs_cmd_udqos(s32_t qos_id, s32_t req_id, u32_t req_value)
{
    union mca_udata_req req;
    union mca_udata_rsp rsp;

    /*printk(KERN_NOTICE "%s qos_id:%d req_id:%d req_value:%d\n", __FUNCTION__,
        qos_id, req_id, req_value);*/
    req.dfs_udqos_req.qos_id    = qos_id;
    req.dfs_udqos_req.req_id    = req_id;
    req.dfs_udqos_req.req_value = req_value;
    req.dfs_udqos_req.core_id   = DFS_CORE_ACPU;
    memset((void*)&rsp, 0x0, sizeof(union mca_udata_rsp));
    if(mca_send(MCA_CMD_DFS_UDQOS, req, &rsp, 0))
    {
        printk(KERN_NOTICE "%s error!!! mailbox timeout req_id:%d\n", __FUNCTION__, req_id);
        return RET_ERR_CONNECT_FAIL;
    }
    /*printk(KERN_NOTICE "%s ret:%d\n", __FUNCTION__, rsp.dfs_udqos_rsp.ret);*/
    return rsp.dfs_udqos_rsp.ret;
}
static ssize_t mcadev_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
{
    union mca_udata_rsp* rsp_buf = filp->private_data;
    struct mcadev_wblock  wblock;

    memset(&wblock, 0, sizeof(struct mcadev_wblock));

    if(!rsp_buf)
        return -EFAULT;

	if (count > sizeof(struct mcadev_wblock))
	    return -EINVAL;

    if (copy_from_user(&wblock, buf, count))
		return -EFAULT;
#if 0
    if(mca_send(wblock.cmd_id, wblock.udata, rsp_buf, MCADEV_WRITE_TIME_OUT));
        return -EFAULT;
#endif
	return count;
}
void test_mca_cmd(s32_t qos_id, u32_t req_value)
{
    union mca_udata_req req = {0};
    union mca_udata_rsp rsp = {0};
    s32_t buf[32] = {0};
    s32_t* req_id = &buf[0];

    if(!req_id)
        return RET_ERR_PARAM_NULL;

    req.dfs_rqqos_req.qos_id    = qos_id;
    req.dfs_rqqos_req.req_value = req_value;

    if(-1 == mca_send(MCA_CMD_DFS_RQQOS, req, &rsp, 100000))
    {
        printk("mca_send failed!!!\n");
        return;
    }
    *req_id = rsp.dfs_rqqos_rsp.req_id;

    printk("req_id:%d\n",*req_id);
}
/*****************************************************************************
 函 数 名  : pwrctrl_dfs_cmd_set_policy
 功能描述  : 设置DFS QoS policy
 输入参数  : policy_id - policy ID
             policy_buf - policy buffer
 输出参数  : 无
 返 回 值  : DFS_RET_OK - Success
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2013年4月26日
    作    者   : 王振伟 176398
    修改内容   : 新生成函数

*****************************************************************************/
local_t dfs_ret pwrctrl_dfs_cmd_set_policy(s32_t policy_id, void *policy_buf, unsigned int len)
{
    union mca_udata_req req = {0};
    union mca_udata_rsp rsp = {0};

    if(len > POLICY_MAX_TOTAL_SIZE)
    {
        printk(KERN_ERR "%s policy_id:%d len:%d exceed max value(%d) error!!!\n", __FUNCTION__, policy_id, len, POLICY_MAX_TOTAL_SIZE);
        return -1;
    }
    
    printk(KERN_NOTICE "%s policy_id:%d len:%d\n", __FUNCTION__, policy_id, len);

    req.dfs_setpli_req.policy_id = policy_id;
    memcpy(req.dfs_setpli_req.pli_buf, policy_buf, len);

    if(mca_send(MCA_CMD_DFS_SETPLI, req, &rsp, PWRCTRL_DFS_CMD_TIMEOUT))
        return RET_ERR_CONNECT_FAIL;

    printk(KERN_NOTICE "%s ret:%d\n", __FUNCTION__, rsp.dfs_setpli_rsp.ret);
    return rsp.dfs_setpli_rsp.ret;
}