Skip to content

Commit f209e0a

Browse files
XenuIsWatchingnashif
authored andcommitted
drivers: i3c: shell: add getmxds helper
Add a shell command for the CCC GETMXDS. Signed-off-by: Ryan McClelland <[email protected]>
1 parent 10a0f01 commit f209e0a

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

drivers/i3c/i3c_shell.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,81 @@ static int cmd_i3c_ccc_setvendor_bc(const struct shell *shell_ctx, size_t argc,
16571657
return ret;
16581658
}
16591659

1660+
/* i3c ccc getmxds <device> <target> [<defining byte>] */
1661+
static int cmd_i3c_ccc_getmxds(const struct shell *shell_ctx, size_t argc, char **argv)
1662+
{
1663+
const struct device *dev, *tdev;
1664+
struct i3c_device_desc *desc;
1665+
union i3c_ccc_getmxds mxds;
1666+
enum i3c_ccc_getmxds_fmt fmt;
1667+
enum i3c_ccc_getmxds_defbyte defbyte = GETMXDS_FORMAT_3_INVALID;
1668+
int ret;
1669+
1670+
dev = device_get_binding(argv[ARGV_DEV]);
1671+
if (!dev) {
1672+
shell_error(shell_ctx, "I3C: Device driver %s not found.", argv[ARGV_DEV]);
1673+
return -ENODEV;
1674+
}
1675+
tdev = device_get_binding(argv[ARGV_TDEV]);
1676+
if (!tdev) {
1677+
shell_error(shell_ctx, "I3C: Device driver %s not found.", argv[ARGV_TDEV]);
1678+
return -ENODEV;
1679+
}
1680+
desc = get_i3c_attached_desc_from_dev_name(dev, tdev->name);
1681+
if (!desc) {
1682+
shell_error(shell_ctx, "I3C: Device %s not attached to bus.", tdev->name);
1683+
return -ENODEV;
1684+
}
1685+
1686+
if (!(desc->bcr & I3C_BCR_MAX_DATA_SPEED_LIMIT)) {
1687+
shell_error(shell_ctx, "I3C: Device %s does not support max data speed limit",
1688+
desc->dev->name);
1689+
return -ENOTSUP;
1690+
}
1691+
1692+
/* If there is a defining byte, then it is assumed to be Format 3 */
1693+
if (argc > 3) {
1694+
fmt = GETMXDS_FORMAT_3;
1695+
defbyte = strtol(argv[3], NULL, 16);
1696+
if (defbyte != GETMXDS_FORMAT_3_CRHDLY || defbyte != GETMXDS_FORMAT_3_WRRDTURN) {
1697+
shell_error(shell_ctx, "Invalid defining byte.");
1698+
return -EINVAL;
1699+
}
1700+
} else {
1701+
fmt = GETMXDS_FORMAT_2;
1702+
}
1703+
1704+
ret = i3c_ccc_do_getmxds(desc, &mxds, fmt, defbyte);
1705+
if (ret < 0) {
1706+
shell_error(shell_ctx, "I3C: unable to send CCC GETMXDS.");
1707+
return ret;
1708+
}
1709+
1710+
if (fmt == GETMXDS_FORMAT_3) {
1711+
if (defbyte == GETMXDS_FORMAT_3_WRRDTURN) {
1712+
shell_print(shell_ctx,
1713+
"WRRDTURN: maxwr 0x%02x; maxrd 0x%02x; maxrdturn 0x%06x",
1714+
mxds.fmt3.wrrdturn[0], mxds.fmt3.wrrdturn[1],
1715+
sys_get_le24(&mxds.fmt3.wrrdturn[2]));
1716+
/* Update values in descriptor */
1717+
desc->maxwr = mxds.fmt3.wrrdturn[0];
1718+
desc->maxrd = mxds.fmt3.wrrdturn[1];
1719+
desc->max_read_turnaround = sys_get_le24(&mxds.fmt3.wrrdturn[2]);
1720+
} else if (defbyte == GETMXDS_FORMAT_3_CRHDLY) {
1721+
shell_print(shell_ctx, "CRHDLY1: 0x%02x", mxds.fmt3.crhdly1);
1722+
}
1723+
} else {
1724+
shell_print(shell_ctx, "GETMXDS: maxwr 0x%02x; maxrd 0x%02x; maxrdturn 0x%06x",
1725+
mxds.fmt2.maxwr, mxds.fmt2.maxrd, sys_get_le24(mxds.fmt2.maxrdturn));
1726+
/* Update values in descriptor */
1727+
desc->maxwr = mxds.fmt2.maxwr;
1728+
desc->maxrd = mxds.fmt2.maxrd;
1729+
desc->max_read_turnaround = sys_get_le24(mxds.fmt2.maxrdturn);
1730+
}
1731+
1732+
return ret;
1733+
}
1734+
16601735
static int cmd_i3c_attach(const struct shell *shell_ctx, size_t argc, char **argv)
16611736
{
16621737
const struct device *dev, *tdev;
@@ -2075,6 +2150,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
20752150
"Send CCC GETCAPS\n"
20762151
"Usage: ccc getcaps <device> <target> [<defining byte>]",
20772152
cmd_i3c_ccc_getcaps, 3, 1),
2153+
SHELL_CMD_ARG(getmxds, &dsub_i3c_device_attached_name,
2154+
"Send CCC GETMXDS\n"
2155+
"Usage: ccc getmxds <device> <target> [<defining byte>]",
2156+
cmd_i3c_ccc_getmxds, 3, 1),
20782157
SHELL_CMD_ARG(getvendor, &dsub_i3c_device_attached_name,
20792158
"Send CCC GETVENDOR\n"
20802159
"Usage: ccc getvendor <device> <target> <id> [<defining byte>]",

0 commit comments

Comments
 (0)