mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-09 20:32:04 +09:00
RK3368 Scpi: add Scpi version check
Signed-off-by: Tang Yun ping <typ@rock-chips.com>
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SCPI_VERSION 0x01000000 /* version: 1.0.0.0 */
|
#define SCPI_VERSION 0x01000001 /* version: 1.0.0.0 */
|
||||||
|
|
||||||
enum scpi_error_codes {
|
enum scpi_error_codes {
|
||||||
SCPI_SUCCESS = 0, /* Success */
|
SCPI_SUCCESS = 0, /* Success */
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ struct scpi_data_buf {
|
|||||||
int timeout_ms;
|
int timeout_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct scpi_mcu_ver {
|
||||||
|
u32 scpi_ver;
|
||||||
|
char mcu_ver[16];
|
||||||
|
};
|
||||||
|
|
||||||
static int high_priority_cmds[] = {
|
static int high_priority_cmds[] = {
|
||||||
SCPI_CMD_GET_CSS_PWR_STATE,
|
SCPI_CMD_GET_CSS_PWR_STATE,
|
||||||
SCPI_CMD_CFG_PWR_STATE_STAT,
|
SCPI_CMD_CFG_PWR_STATE_STAT,
|
||||||
@@ -424,23 +429,29 @@ int scpi_get_sensor_value(u16 sensor, u32 *val)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(scpi_get_sensor_value);
|
EXPORT_SYMBOL_GPL(scpi_get_sensor_value);
|
||||||
|
|
||||||
static int scpi_get_version(u32 old, u32 *ver)
|
static int scpi_get_version(u32 old, struct scpi_mcu_ver *ver)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
struct scpi_data_buf sdata;
|
struct scpi_data_buf sdata;
|
||||||
struct rockchip_mbox_msg mdata;
|
struct rockchip_mbox_msg mdata;
|
||||||
struct __packed {
|
struct __packed {
|
||||||
u32 status;
|
u32 status;
|
||||||
u32 ver;
|
struct scpi_mcu_ver version;
|
||||||
} buf;
|
} buf;
|
||||||
int ret;
|
|
||||||
|
|
||||||
|
memset(&buf, 0, sizeof(buf));
|
||||||
SCPI_SETUP_DBUF(sdata, mdata, SCPI_CL_SYS, SCPI_SYS_GET_VERSION,
|
SCPI_SETUP_DBUF(sdata, mdata, SCPI_CL_SYS, SCPI_SYS_GET_VERSION,
|
||||||
old, buf);
|
old, buf);
|
||||||
|
|
||||||
ret = scpi_execute_cmd(&sdata);
|
ret = scpi_execute_cmd(&sdata);
|
||||||
if (ret)
|
if (ret) {
|
||||||
*ver = buf.ver;
|
pr_err("get scpi version from MCU failed, ret=%d\n", ret);
|
||||||
|
goto OUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(ver, &(buf.version), sizeof(*ver));
|
||||||
|
|
||||||
|
OUT:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,24 +685,12 @@ static int mobx_scpi_probe(struct platform_device *pdev)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int retry = 3;
|
int retry = 3;
|
||||||
u32 ver = 0;
|
|
||||||
int check_version = 0; /*0: not check version, 1: check version*/
|
|
||||||
int val = 0;
|
int val = 0;
|
||||||
|
struct scpi_mcu_ver mcu_ver;
|
||||||
|
int check_version = 1; /*0: not check version, 1: check version*/
|
||||||
|
|
||||||
the_scpi_device = &pdev->dev;
|
the_scpi_device = &pdev->dev;
|
||||||
|
|
||||||
while ((retry--) && (check_version != 0)) {
|
|
||||||
ret = scpi_get_version(SCPI_VERSION, &ver);
|
|
||||||
if ((ret == 0) && (ver == SCPI_VERSION))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((retry <= 0) && (check_version != 0)) {
|
|
||||||
dev_err(&pdev->dev, "Failed to get scpi version\n");
|
|
||||||
ret = -EIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* try to get mboxes chan nums from DT */
|
/* try to get mboxes chan nums from DT */
|
||||||
if (of_property_read_u32((&pdev->dev)->of_node, "chan-nums", &val)) {
|
if (of_property_read_u32((&pdev->dev)->of_node, "chan-nums", &val)) {
|
||||||
dev_err(&pdev->dev, "parse mboxes chan-nums failed\n");
|
dev_err(&pdev->dev, "parse mboxes chan-nums failed\n");
|
||||||
@@ -701,8 +700,27 @@ static int mobx_scpi_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
max_chan_num = val;
|
max_chan_num = val;
|
||||||
|
|
||||||
dev_info(&pdev->dev,
|
/* try to check up with SCPI version from MCU */
|
||||||
"Scpi initialize, version: 0x%x, chan nums: %d\n", ver, val);
|
while ((retry--) && (check_version != 0)) {
|
||||||
|
memset(&mcu_ver, 0, sizeof(mcu_ver));
|
||||||
|
|
||||||
|
ret = scpi_get_version(SCPI_VERSION, &mcu_ver);
|
||||||
|
if ((ret == 0) && (mcu_ver.scpi_ver == SCPI_VERSION))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((retry <= 0) && (check_version != 0)) {
|
||||||
|
dev_err(&pdev->dev,
|
||||||
|
"Scpi verison not match:kernel ver:0x%x, MCU ver:0x%x, ret=%d\n",
|
||||||
|
SCPI_VERSION, mcu_ver.scpi_ver, ret);
|
||||||
|
ret = -EIO;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_info(&pdev->dev, "Scpi initialize, version: 0x%x, chan nums: %d\n",
|
||||||
|
mcu_ver.scpi_ver, val);
|
||||||
|
dev_info(&pdev->dev, "MCU version: %s\n", mcu_ver.mcu_ver);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
exit:
|
exit:
|
||||||
the_scpi_device = NULL;
|
the_scpi_device = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user