From eaca75040bc9a1841d8ee710bf1f2c2b96b5cd82 Mon Sep 17 00:00:00 2001 From: Shunzhou Jiang Date: Wed, 9 Jan 2019 17:42:52 +0800 Subject: [PATCH] mailbox: mailbox: add chip performance info read from efuse [2/2] PD#SWPL-4035 Problem: cpu driver need read efuse data Solution: add interface to read data Verify: g12a_skt Change-Id: Ia5d74c3fa057d06426b4277652e508714400a30f Signed-off-by: Shunzhou Jiang --- drivers/amlogic/mailbox/scpi_protocol.c | 88 +++++++++++++++++++++++++ include/linux/amlogic/scpi_protocol.h | 11 +++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/drivers/amlogic/mailbox/scpi_protocol.c b/drivers/amlogic/mailbox/scpi_protocol.c index 20f05c10b454..22883ee98e59 100644 --- a/drivers/amlogic/mailbox/scpi_protocol.c +++ b/drivers/amlogic/mailbox/scpi_protocol.c @@ -60,6 +60,42 @@ enum scpi_error_codes { SCPI_ERR_MAX }; +static int scpi_freq_map_table[] = { + 0, + 0, + 1200, + 1300, + 1400, + 1500, + 1600, + 1700, + 1800, + 1900, + 2000, + 2100, + 2200, + 2300, + 2400, + 0 +}; +static int scpi_volt_map_table[] = { + 0, + 0, + 900, + 910, + 920, + 930, + 940, + 950, + 960, + 970, + 980, + 990, + 1000, + 1010, + 1020, + 0 +}; struct scpi_data_buf { int client_id; @@ -559,3 +595,55 @@ u8 scpi_get_ethernet_calc(void) return buf.eth_calc; } EXPORT_SYMBOL_GPL(scpi_get_ethernet_calc); + +int scpi_get_cpuinfo(enum scpi_get_pfm_type type, u32 *freq, u32 *vol) +{ + struct scpi_data_buf sdata; + struct mhu_data_buf mdata; + u8 index = 0; + int ret; + + struct __packed { + u32 status; + u8 pfm_info[4]; + } buf; + + SCPI_SETUP_DBUF(sdata, mdata, SCPI_CL_NONE, + SCPI_CMD_GET_CPUINFO, index, buf); + if (scpi_execute_cmd(&sdata)) + return -EPERM; + + switch (type) { + case SCPI_CPUINFO_VERSION: + ret = buf.pfm_info[0]; + break; + case SCPI_CPUINFO_CLUSTER0: + index = (buf.pfm_info[1] >> 4) & 0xf; + *freq = scpi_freq_map_table[index]; + index = buf.pfm_info[1] & 0xf; + *vol = scpi_volt_map_table[index]; + ret = 0; + break; + case SCPI_CPUINFO_CLUSTER1: + index = (buf.pfm_info[2] >> 4) & 0xf; + *freq = scpi_freq_map_table[index]; + index = buf.pfm_info[2] & 0xf; + *vol = scpi_volt_map_table[index]; + ret = 0; + break; + case SCPI_CPUINFO_SLT: + index = (buf.pfm_info[3] >> 4) & 0xf; + *freq = scpi_freq_map_table[index]; + index = buf.pfm_info[3] & 0xf; + *vol = scpi_volt_map_table[index]; + ret = 0; + break; + default: + *freq = 0; + *vol = 0; + ret = -1; + break; + }; + return ret; +} +EXPORT_SYMBOL_GPL(scpi_get_cpuinfo); diff --git a/include/linux/amlogic/scpi_protocol.h b/include/linux/amlogic/scpi_protocol.h index 771b2bfbb255..c886ce4f522e 100644 --- a/include/linux/amlogic/scpi_protocol.h +++ b/include/linux/amlogic/scpi_protocol.h @@ -68,12 +68,21 @@ enum scpi_std_cmd { SCPI_CMD_WAKEUP_REASON_GET = 0x30, SCPI_CMD_WAKEUP_REASON_CLR = 0X31, SCPI_CMD_GET_ETHERNET_CALC = 0x32, + SCPI_CMD_GET_CPUINFO = 0x33, SCPI_CMD_GET_CEC1 = 0xB4, SCPI_CMD_GET_CEC2 = 0xB5, SCPI_CMD_COUNT }; +enum scpi_get_pfm_type { + SCPI_CPUINFO_CLUSTER0, + SCPI_CPUINFO_CLUSTER1, + SCPI_CPUINFO_VERSION, + SCPI_CPUINFO_SLT, + SCPI_CPUINFO_NUMS +}; + struct scpi_opp_entry { u32 freq_hz; u32 volt_mv; @@ -85,7 +94,6 @@ struct scpi_dvfs_info { struct scpi_opp_entry *opp; } __packed; - unsigned long scpi_clk_get_val(u16 clk_id); int scpi_clk_set_val(u16 clk_id, unsigned long rate); int scpi_dvfs_get_idx(u8 domain); @@ -101,4 +109,5 @@ int scpi_get_wakeup_reason(u32 *wakeup_reason); int scpi_clr_wakeup_reason(void); int scpi_get_cec_val(enum scpi_std_cmd index, u32 *p_cec); u8 scpi_get_ethernet_calc(void); +int scpi_get_cpuinfo(enum scpi_get_pfm_type type, u32 *freq, u32 *vol); #endif /*_SCPI_PROTOCOL_H_*/