[PATCH v5 09/12] cmd: Add i3c command support.

Maniyam, Dinesh dinesh.maniyam at altera.com
Tue Jul 15 04:08:55 CEST 2025



> -----Original Message-----
> From: Heiko Schocher <hs at denx.de>
> Sent: Saturday, 12 July 2025 4:17 pm
> To: Maniyam, Dinesh <dinesh.maniyam at altera.com>; u-boot at lists.denx.de
> Cc: Marek <marex at denx.de>; Simon <simon.k.r.goldschmidt at gmail.com>;
> Simon Glass <sjg at chromium.org>; Tom Rini <trini at konsulko.com>; Dario
> Binacchi <dario.binacchi at amarulasolutions.com>; Ilias Apalodimas
> <ilias.apalodimas at linaro.org>; Heinrich Schuchardt <xypron.glpk at gmx.de>;
> Jerome Forissier <jerome.forissier at linaro.org>; Mattijs Korpershoek
> <mkorpershoek at baylibre.com>; Ibai Erkiaga <ibai.erkiaga-elorza at amd.com>;
> Michal Simek <michal.simek at amd.com>; Dmitry Rokosov
> <ddrokosov at salutedevices.com>; Jonas Karlman <jonas at kwiboo.se>; Sebastian
> Reichel <sebastian.reichel at collabora.com>; Tingting Meng
> <tingting.meng at altera.com>; Chee, Tien Fong <tien.fong.chee at altera.com>;
> Hea, Kok Kiang <kok.kiang.hea at altera.com>; Ng, Boon Khai
> <boon.khai.ng at altera.com>; Yuslaimi, Alif Zakuan
> <alif.zakuan.yuslaimi at altera.com>; Hazim
> <muhammad.hazim.izzat.zamri at altera.com>; Lim, Jit Loon
> <jit.loon.lim at altera.com>
> Subject: Re: [PATCH v5 09/12] cmd: Add i3c command support.
> 
> [CAUTION: This email is from outside your organization. Unless you trust the
> sender, do not click on links or open attachments as it may be a fraudulent email
> attempting to steal your information and/or compromise your computer.]
> 
> Hello Dinesh,
> 
> sorry for late reply...
> 

No problem, thanks for the review.

> On 13.05.25 12:19, dinesh.maniyam at altera.com wrote:
> > From: Dinesh Maniyam <dinesh.maniyam at altera.com>
> >
> > Add i3c command file to support select, get i3c device target list,
> > read and write operation.
> >
> > Signed-off-by: Dinesh Maniyam <dinesh.maniyam at altera.com>
> > ---
> >   cmd/Kconfig                        |   6 +
> >   cmd/Makefile                       |   1 +
> >   cmd/i3c.c                          | 261 +++++++++++++++++++++++++++++
> >   doc/usage/cmd/i3c.rst              | 146 ++++++++++++++++
> >   doc/usage/index.rst                |   1 +
> >   drivers/i3c/master/dw-i3c-master.c |  35 +++-
> >   include/dw-i3c.h                   |   2 +
> >   include/i3c.h                      |  28 +++-
> >   8 files changed, 478 insertions(+), 2 deletions(-)
> >   create mode 100644 cmd/i3c.c
> >   create mode 100644 doc/usage/cmd/i3c.rst
> 
> [...]
> 
> > diff --git a/cmd/i3c.c b/cmd/i3c.c
> > new file mode 100644
> > index 00000000000..7d2bde714cd
> > --- /dev/null
> > +++ b/cmd/i3c.c
> > @@ -0,0 +1,261 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2025 Altera Corporation <www.altera.com>  */
> > +
> > +#include <bootretry.h>
> > +#include <cli.h>
> > +#include <command.h>
> > +#include <console.h>
> > +#include <dm.h>
> > +#include <dw-i3c.h>
> > +#include <edid.h>
> > +#include <errno.h>
> > +#include <hexdump.h>
> > +#include <log.h>
> > +#include <malloc.h>
> > +#include <asm/byteorder.h>
> > +#include <linux/compiler.h>
> > +#include <linux/delay.h>
> > +#include <u-boot/crc.h>
> > +#include <linux/i3c/master.h>
> > +#include <linux/printk.h>
> > +#include <linux/types.h>
> > +
> > +static struct udevice *currdev;
> > +static struct udevice *prevdev;
> > +static struct dw_i3c_master *master;
> > +
> > +static void low_to_high_bytes(void *data, size_t size) {
> > +     u8 *byte_data = data;
> > +     size_t start = 0;
> > +     size_t end = size - 1;
> > +
> > +     while (start < end) {
> > +             u8 temp = byte_data[start];
> > +
> > +             byte_data[start] = byte_data[end];
> > +             byte_data[end] = temp;
> > +             start++;
> > +             end--;
> > +     }
> > +}
> > +
> > +static int handle_i3c_select(const char *name) {
> > +     struct uclass *uc;
> > +     struct udevice *dev_list;
> > +     int ret = uclass_get_device_by_name(UCLASS_I3C, name, &currdev);
> > +
> > +     if (ret) {
> > +             currdev = prevdev;
> > +             if (!currdev) {
> > +                     ret = uclass_get(UCLASS_I3C, &uc);
> > +                     if (ret)
> > +                             return CMD_RET_FAILURE;
> > +
> > +                     uclass_foreach_dev(dev_list, uc)
> > +                             printf("%s (%s)\n", dev_list->name,
> > + dev_list->driver->name);
> > +
> > +                     printf("i3c: Host controller not initialized: %s\n", name);
> > +                     return CMD_RET_FAILURE;
> > +             }
> > +     } else {
> > +             master = dev_get_priv(currdev);
> > +             printf("i3c: Current controller: %s\n", currdev->name);
> > +             prevdev = currdev;
> > +     }
> > +
> > +     return CMD_RET_SUCCESS;
> > +}
> > +
> > +static int handle_i3c_list(void)
> > +{
> > +     struct uclass *uc;
> > +     struct udevice *dev_list;
> > +     int ret = uclass_get(UCLASS_I3C, &uc);
> > +
> > +     if (ret)
> > +             return CMD_RET_FAILURE;
> > +
> > +     uclass_foreach_dev(dev_list, uc)
> > +             printf("%s (%s)\n", dev_list->name,
> > + dev_list->driver->name);
> > +
> > +     return CMD_RET_SUCCESS;
> > +}
> > +
> > +static int handle_i3c_current(void)
> > +{
> > +     if (!currdev)
> > +             printf("i3c: No current controller selected\n");
> > +     else
> > +             printf("i3c: Current controller: %s\n", currdev->name);
> > +
> > +     return CMD_RET_SUCCESS;
> > +}
> > +
> > +static int handle_i3c_device_list(void) {
> > +     if (!master) {
> > +             printf("i3c: No controller active\n");
> > +             return CMD_RET_FAILURE;
> > +     }
> > +
> > +     for (int i = 0; i < master->num_i3cdevs; i++) {
> > +             struct i3c_device_info *info = &master->i3cdev[i]->info;
> > +
> > +             printf("Device %d:\n", i);
> > +             printf("  Static Address  : 0x%02X\n", info->static_addr);
> > +             printf("  Dynamic Address : 0x%X\n", info->dyn_addr);
> > +             printf("  PID             : %016llx\n", info->pid);
> > +             printf("  BCR             : 0x%X\n", info->bcr);
> > +             printf("  DCR             : 0x%X\n", info->dcr);
> > +             printf("  Max Read DS     : 0x%X\n", info->max_read_ds);
> > +             printf("  Max Write DS    : 0x%X\n", info->max_write_ds);
> > +             printf("\n");
> > +     }
> > +
> > +     return CMD_RET_SUCCESS;
> > +}
> > +
> > +static int handle_i3c_write(int argc, char *const argv[]) {
> > +     if (argc < 5)
> > +             return CMD_RET_USAGE;
> > +
> > +     if (!currdev) {
> > +             printf("i3c: No I3C controller selected\n");
> > +             return CMD_RET_FAILURE;
> > +     }
> > +
> > +     u32 mem_addr = hextoul(argv[2], NULL);
> > +     u32 num_bytes = hextoul(argv[3], NULL);
> > +     u32 dev_num_val = hextoul(argv[4], NULL);
> 
> Please move the variable declaration to top of the function. Please fix this for all
> appearances, thanks!
> 
> bye,
> Heiko
> --

Sure, I will fix this.

Regards
Dinesh

> DENX Software Engineering GmbH, Managing Director: Johanna Denk, Tabea Lutz
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de


More information about the U-Boot mailing list