commonlib/mipi/cmd: Add mipi_panel_get_commands_len()

Introduce a helper function mipi_panel_get_commands_len() to calculate
the MIPI panel commands array length.

BUG=b:474187570
TEST=emerge-jedi coreboot
BRANCH=skywalker

Change-Id: I3fef37144f6856057b44415caf578629a35fe573
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/90773
Reviewed-by: Chen-Tsung Hsieh <chentsung@google.com>
Reviewed-by: Yidi Lin <yidilin@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Yu-Ping Wu 2026-01-16 08:38:02 +08:00 committed by Yu-Ping Wu
commit d110cf4669
2 changed files with 40 additions and 0 deletions

View file

@ -5,6 +5,7 @@
#include <commonlib/bsd/cb_err.h>
#include <commonlib/mipi/dsi.h>
#include <stddef.h>
#include <stdint.h>
/* 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__ */

View file

@ -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;
}