From 4f9e5b7cfa3a3cf4ab3d97aec73362e11791f8e6 Mon Sep 17 00:00:00 2001 From: Ryan McClelland Date: Thu, 12 Sep 2024 16:35:41 -0700 Subject: [PATCH] drivers: i3c: shell: add ibi shell commands This adds ibi commands for hot-join, controller request, and target interrupt request. Signed-off-by: Ryan McClelland --- drivers/i3c/i3c_shell.c | 109 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/drivers/i3c/i3c_shell.c b/drivers/i3c/i3c_shell.c index c2197ae7e9fb5c0..96a1223fb35135b 100644 --- a/drivers/i3c/i3c_shell.c +++ b/drivers/i3c/i3c_shell.c @@ -2029,6 +2029,89 @@ static int cmd_i3c_i2c_scan(const struct shell *shell_ctx, size_t argc, char **a return 0; } +#ifdef I3C_USE_IBI +/* i3c ibi hj */ +static void cmd_i3c_ibi_hj(const struct shell *shell_ctx, size_t argc, char **argv) +{ + const struct device *dev; + struct i3c_ibi request; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(shell_ctx, "I3C: Device driver %s not found.", argv[ARGV_DEV]); + return -ENODEV; + } + + request.ibi_type = I3C_IBI_HOTJOIN; + ret = i3c_ibi_raise(dev, &request); + if (ret != 0) { + shell_error(shell_ctx, "I3C: Unable to issue IBI HJ"); + return ret; + } + + shell_print(shell_ctx, "I3C: Issued IBI HJ"); +} + +/* i3c ibi cr */ +static void cmd_i3c_ibi_cr(const struct shell *shell_ctx, size_t argc, char **argv) +{ + const struct device *dev; + struct i3c_ibi request; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(shell_ctx, "I3C: Device driver %s not found.", argv[ARGV_DEV]); + return -ENODEV; + } + + request.ibi_type = I3C_IBI_CONTROLLER_ROLE_REQUEST; + ret = i3c_ibi_raise(dev, &request); + if (ret != 0) { + shell_error(shell_ctx, "I3C: Unable to issue IBI CR"); + return ret; + } + + shell_print(shell_ctx, "I3C: Issued IBI CR"); +} + +/* i3c ibi tir []*/ +static void cmd_i3c_ibi_tir(const struct shell *shell_ctx, size_t argc, char **argv) +{ + const struct device *dev; + struct i3c_ibi request; + uint16_t data_length; + char **data; + uint8_t buf[MAX_I3C_BYTES]; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(shell_ctx, "I3C: Device driver %s not found.", argv[ARGV_DEV]); + return -ENODEV; + } + + data = argv[3]; + data_length = argc - 3; + for (i = 0; i < data_length; i++) { + buf[i] = (uint8_t)strtol(data[i], NULL, 16); + } + + request.ibi_type = I3C_IBI_TARGET_INTR; + request.payload = buf; + request.payload_len = data_length; + + ret = i3c_ibi_raise(dev, &request); + if (ret != 0) { + shell_error(shell_ctx, "I3C: Unable to issue IBI TIR"); + return ret; + } + + shell_print(shell_ctx, "I3C: Issued IBI TIR"); +} +#endif + static void i3c_device_list_target_name_get(size_t idx, struct shell_static_entry *entry) { if (idx < ARRAY_SIZE(i3c_list)) { @@ -2071,6 +2154,26 @@ static void i3c_device_name_get(size_t idx, struct shell_static_entry *entry) SHELL_DYNAMIC_CMD_CREATE(dsub_i3c_device_name, i3c_device_name_get); +#ifdef I3C_USE_IBI +/* L2 I3C IBI Shell Commands*/ +SHELL_STATIC_SUBCMD_SET_CREATE( + sub_i3c_ibi_cmds, + SHELL_CMD_ARG(hj, &dsub_i3c_device_name, + "Send IBI HJ\n" + "Usage: ibi hj ", + cmd_i3c_ibi_hj, 2, 0), + SHELL_CMD_ARG(tir, &dsub_i3c_device_name, + "Send IBI TIR\n" + "Usage: ibi tir []", + cmd_i3c_ibi_tir, 2, MAX_I3C_BYTES), + SHELL_CMD_ARG(cr, &dsub_i3c_device_name, + "Send IBI CR\n" + "Usage: ibi cr ", + cmd_i3c_ibi_cr, 2, 0), + SHELL_SUBCMD_SET_END /* Array terminated. */ +); +#endif + /* L2 I3C CCC Shell Commands*/ SHELL_STATIC_SUBCMD_SET_CREATE( sub_i3c_ccc_cmds, @@ -2276,6 +2379,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE( "Send I3C CCC\n" "Usage: ccc ", NULL, 3, 0), +#ifdef I3C_USE_IBI + SHELL_CMD_ARG(ibi, &sub_i3c_ibi_cmds, + "Send I3C IBI\n" + "Usage: ibi ", + NULL, 3, 0), +#endif SHELL_SUBCMD_SET_END /* Array terminated. */ );