diff --git a/src/commonlib/include/commonlib/mipi/cmd.h b/src/commonlib/include/commonlib/mipi/cmd.h index 17e0aeda89..ad3c5a7fb4 100644 --- a/src/commonlib/include/commonlib/mipi/cmd.h +++ b/src/commonlib/include/commonlib/mipi/cmd.h @@ -5,6 +5,7 @@ #include #include +#include #include /* Definitions for cmd in panel_command */ @@ -52,4 +53,10 @@ typedef enum cb_err (*mipi_cmd_func_t)(enum mipi_dsi_transaction type, const u8 enum cb_err mipi_panel_parse_commands(const void *buf, mipi_cmd_func_t cmd_func, void *user_data); +/* + * Parse a command array and calculate the array length, including the trailing + * PANEL_CMD_END. If the array begins with PANEL_CMD_END, 0 will be returned. + */ +size_t mipi_panel_get_commands_len(const void *buf); + #endif /* __COMMONLIB_MIPI_CMD_H__ */ diff --git a/src/commonlib/mipi/cmd.c b/src/commonlib/mipi/cmd.c index 4e5a638d9b..fa52d21c08 100644 --- a/src/commonlib/mipi/cmd.c +++ b/src/commonlib/mipi/cmd.c @@ -78,3 +78,36 @@ enum cb_err mipi_panel_parse_commands(const void *buf, mipi_cmd_func_t cmd_func, return CB_SUCCESS; } + +size_t mipi_panel_get_commands_len(const void *buf) +{ + const void *const buf_start = buf; + const struct panel_command *command = buf; + + if (command->cmd == PANEL_CMD_END) + return 0; + + for (; command->cmd != PANEL_CMD_END; command = buf) { + buf += sizeof(*command); + + switch (command->cmd) { + case PANEL_CMD_DELAY: + /* + * For PANEL_CMD_DELAY, the command->len should not be + * counted for buf. + */ + break; + case PANEL_CMD_GENERIC: + case PANEL_CMD_DCS: + buf += command->len; + break; + default: + printk(BIOS_ERR, "%s: Unknown command code: %d.\n", + __func__, command->cmd); + return 0; + } + } + + /* Add 1 byte for PANEL_CMD_END. */ + return buf - buf_start + 1; +}