mailbox: mailbox: add chip performance info read from efuse [2/2]
authorShunzhou Jiang <shunzhou.jiang@amlogic.com>
Wed, 9 Jan 2019 09:42:52 +0000 (17:42 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Wed, 27 Feb 2019 07:45:26 +0000 (23:45 -0800)
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 <shunzhou.jiang@amlogic.com>
drivers/amlogic/mailbox/scpi_protocol.c
include/linux/amlogic/scpi_protocol.h

index 20f05c1..22883ee 100644 (file)
@@ -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);
index 771b2bf..c886ce4 100644 (file)
@@ -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_*/