From c8817de47e2b6cd584b1f61b39596cacb6936ba7 Mon Sep 17 00:00:00 2001 From: Dilip Kota Date: Thu, 21 May 2015 17:49:36 +0530 Subject: [PATCH] devfreq: devfreq_spdm: Scale parameters to and from TZ driver Send all the frequency performance levels in KHz units to TZ driver and convert all the bandwidth recommendations to Bytes/s from Kbytes/s to accomodate change in the syscall interface calls to TZ SPDM driver. Change-Id: I209ea0583fdd43f78f51793d7818ea5afd5959c7 Signed-off-by: Dilip Kota Signed-off-by: Girish Mahadevan --- drivers/devfreq/devfreq_spdm.c | 18 +++++++++++++++++- drivers/devfreq/devfreq_spdm.h | 2 ++ drivers/devfreq/governor_spdm_bw_hyp.c | 7 +++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/devfreq/devfreq_spdm.c b/drivers/devfreq/devfreq_spdm.c index 28ae33ead793..f8ef5eda08ea 100644 --- a/drivers/devfreq/devfreq_spdm.c +++ b/drivers/devfreq/devfreq_spdm.c @@ -70,7 +70,7 @@ static int change_bw(struct device *dev, unsigned long *freq, u32 flags) update_thresholds: desc.arg[0] = SPDM_CMD_ENABLE; desc.arg[1] = data->spdm_client; - desc.arg[2] = clk_get_rate(data->cci_clk); + desc.arg[2] = (clk_get_rate(data->cci_clk)) / 1000; ext_status = spdm_ext_call(&desc, 3); if (ext_status) pr_err("External command %u failed with error %u", @@ -302,6 +302,8 @@ static int probe(struct platform_device *pdev) { struct spdm_data *data = 0; int ret = -EINVAL; + struct spdm_args desc = { { 0 } }; + int ext_status = 0; data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -315,6 +317,20 @@ static int probe(struct platform_device *pdev) if (ret) goto bad_of; + desc.arg[0] = SPDM_CMD_GET_VERSION; + ext_status = spdm_ext_call(&desc, 1); + if (ext_status) { + pr_err("%s:External command %u failed with error %u\n", + __func__, (int)desc.arg[0], ext_status); + goto bad_of; + } + + if (desc.ret[0] < SPDM_TZ_VERSION) { + pr_err("%s: Version mismatch expected 0x%x got 0x%x", __func__, + SPDM_TZ_VERSION, (int)desc.arg[0]); + goto bad_of; + } + data->bus_scale_client_id = msm_bus_scale_register_client(data->pdata); if (!data->bus_scale_client_id) { ret = -EINVAL; diff --git a/drivers/devfreq/devfreq_spdm.h b/drivers/devfreq/devfreq_spdm.h index 9db5c1187f3f..c68f81cf8d4e 100644 --- a/drivers/devfreq/devfreq_spdm.h +++ b/drivers/devfreq/devfreq_spdm.h @@ -89,7 +89,9 @@ extern void spdm_remove_debugfs(struct spdm_data *data); #define SPDM_HYP_FNID 5 #define SPDM_SCM_SVC_ID 0x9 #define SPDM_SCM_CMD_ID 0x4 +#define SPDM_TZ_VERSION 0x20000 /* TZ SPDM driver version */ /* SPDM CMD ID's for hypervisor/SCM */ +#define SPDM_CMD_GET_VERSION 0 #define SPDM_CMD_GET_BW_ALL 1 #define SPDM_CMD_GET_BW_SPECIFIC 2 #define SPDM_CMD_ENABLE 3 diff --git a/drivers/devfreq/governor_spdm_bw_hyp.c b/drivers/devfreq/governor_spdm_bw_hyp.c index 575621606100..e5e179931811 100644 --- a/drivers/devfreq/governor_spdm_bw_hyp.c +++ b/drivers/devfreq/governor_spdm_bw_hyp.c @@ -88,7 +88,8 @@ static irqreturn_t threaded_isr(int irq, void *dev_id) devfreq_monitor_suspend(data->devfreq); mutex_lock(&data->devfreq->lock); data->action = SPDM_UP; - data->new_bw = desc.ret[1] >> 6; + data->new_bw = + (desc.ret[1] * 1000) >> 6; update_devfreq(data->devfreq); data->action = SPDM_DOWN; mutex_unlock(&data->devfreq->lock); @@ -113,6 +114,7 @@ static int gov_spdm_hyp_target_bw(struct devfreq *devfreq, unsigned long *freq, int usage; struct spdm_args desc = { { 0 } }; int ext_status = 0; + u64 bw_ret; if (!devfreq || !devfreq->profile || !devfreq->profile->get_dev_status) return ret; @@ -134,7 +136,8 @@ static int gov_spdm_hyp_target_bw(struct devfreq *devfreq, unsigned long *freq, if (ext_status) pr_err("External command %u failed with error %u", (int)desc.arg[0], ext_status); - *freq = desc.ret[0] >> 6; + bw_ret = desc.ret[0] * 1000; + *freq = bw_ret >> 6; } return 0;