cmd: bind: Use device sequence instead for driver bind/unbind

Currently uclass index is used for bind/unbind which ignores alias
sequence numbering. Use device sequence number instead as it's
the number explicitly set in the DT.

Also update documentation to use sequence number.

Signed-off-by: Zixun LI <admin@hifiphile.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Zixun LI
2024-08-02 11:28:13 +02:00
committed by Tom Rini
parent 2d76e724b4
commit 56274888fc
3 changed files with 36 additions and 36 deletions

View File

@@ -10,8 +10,8 @@
#include <dm/root.h> #include <dm/root.h>
#include <dm/uclass-internal.h> #include <dm/uclass-internal.h>
static int bind_by_class_index(const char *uclass, int index, static int bind_by_class_seq(const char *uclass, int seq,
const char *drv_name) const char *drv_name)
{ {
static enum uclass_id uclass_id; static enum uclass_id uclass_id;
struct udevice *dev; struct udevice *dev;
@@ -31,9 +31,9 @@ static int bind_by_class_index(const char *uclass, int index,
return -EINVAL; return -EINVAL;
} }
ret = uclass_find_device(uclass_id, index, &parent); ret = uclass_find_device_by_seq(uclass_id, seq, &parent);
if (!parent || ret) { if (!parent || ret) {
printf("Cannot find device %d of class %s\n", index, uclass); printf("Cannot find device %d of class %s\n", seq, uclass);
return ret; return ret;
} }
@@ -47,7 +47,7 @@ static int bind_by_class_index(const char *uclass, int index,
return 0; return 0;
} }
static int find_dev(const char *uclass, int index, struct udevice **devp) static int find_dev(const char *uclass, int seq, struct udevice **devp)
{ {
static enum uclass_id uclass_id; static enum uclass_id uclass_id;
int rc; int rc;
@@ -58,21 +58,21 @@ static int find_dev(const char *uclass, int index, struct udevice **devp)
return -EINVAL; return -EINVAL;
} }
rc = uclass_find_device(uclass_id, index, devp); rc = uclass_find_device_by_seq(uclass_id, seq, devp);
if (!*devp || rc) { if (!*devp || rc) {
printf("Cannot find device %d of class %s\n", index, uclass); printf("Cannot find device %d of class %s\n", seq, uclass);
return rc; return rc;
} }
return 0; return 0;
} }
static int unbind_by_class_index(const char *uclass, int index) static int unbind_by_class_seq(const char *uclass, int seq)
{ {
int ret; int ret;
struct udevice *dev; struct udevice *dev;
ret = find_dev(uclass, index, &dev); ret = find_dev(uclass, seq, &dev);
if (ret) if (ret)
return ret; return ret;
@@ -91,8 +91,8 @@ static int unbind_by_class_index(const char *uclass, int index)
return 0; return 0;
} }
static int unbind_child_by_class_index(const char *uclass, int index, static int unbind_child_by_class_seq(const char *uclass, int seq,
const char *drv_name) const char *drv_name)
{ {
struct udevice *parent; struct udevice *parent;
int ret; int ret;
@@ -104,7 +104,7 @@ static int unbind_child_by_class_index(const char *uclass, int index,
return -ENOENT; return -ENOENT;
} }
ret = find_dev(uclass, index, &parent); ret = find_dev(uclass, seq, &parent);
if (ret) if (ret)
return ret; return ret;
@@ -217,19 +217,19 @@ static int do_bind_unbind(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_USAGE; return CMD_RET_USAGE;
ret = unbind_by_node_path(argv[1]); ret = unbind_by_node_path(argv[1]);
} else if (!by_node && bind) { } else if (!by_node && bind) {
int index = (argc > 2) ? dectoul(argv[2], NULL) : 0; int seq = (argc > 2) ? dectoul(argv[2], NULL) : 0;
if (argc != 4) if (argc != 4)
return CMD_RET_USAGE; return CMD_RET_USAGE;
ret = bind_by_class_index(argv[1], index, argv[3]); ret = bind_by_class_seq(argv[1], seq, argv[3]);
} else if (!by_node && !bind) { } else if (!by_node && !bind) {
int index = (argc > 2) ? dectoul(argv[2], NULL) : 0; int seq = (argc > 2) ? dectoul(argv[2], NULL) : 0;
if (argc == 3) if (argc == 3)
ret = unbind_by_class_index(argv[1], index); ret = unbind_by_class_seq(argv[1], seq);
else if (argc == 4) else if (argc == 4)
ret = unbind_child_by_class_index(argv[1], index, ret = unbind_child_by_class_seq(argv[1], seq,
argv[3]); argv[3]);
else else
return CMD_RET_USAGE; return CMD_RET_USAGE;
} }
@@ -244,17 +244,17 @@ U_BOOT_CMD(
bind, 4, 0, do_bind_unbind, bind, 4, 0, do_bind_unbind,
"Bind a device to a driver", "Bind a device to a driver",
"<node path> <driver>\n" "<node path> <driver>\n"
"bind <class> <index> <driver>\n" "bind <class> <seq> <driver>\n"
"Use 'dm tree' to list all devices registered in the driver model,\n" "Use 'dm tree' to list all devices registered in the driver model,\n"
"their path, class, index and current driver.\n" "their path, class, sequence and current driver.\n"
); );
U_BOOT_CMD( U_BOOT_CMD(
unbind, 4, 0, do_bind_unbind, unbind, 4, 0, do_bind_unbind,
"Unbind a device from a driver", "Unbind a device from a driver",
"<node path>\n" "<node path>\n"
"unbind <class> <index>\n" "unbind <class> <seq>\n"
"unbind <class> <index> <driver>\n" "unbind <class> <seq> <driver>\n"
"Use 'dm tree' to list all devices registered in the driver model,\n" "Use 'dm tree' to list all devices registered in the driver model,\n"
"their path, class, index and current driver.\n" "their path, class, sequence and current driver.\n"
); );

View File

@@ -12,7 +12,7 @@ Synopsis
:: ::
bind <node path> <driver> bind <node path> <driver>
bind <class> <index> <driver> bind <class> <seq> <driver>
Description Description
----------- -----------
@@ -30,8 +30,8 @@ node path
class class
device class name device class name
index seq
index of the parent device in the device class sequence number of the parent device in the device class
driver driver
device driver name device driver name
@@ -46,7 +46,7 @@ using the two alternative bind syntaxes.
.. code-block:: .. code-block::
=> dm tree => dm tree
Class Index Probed Driver Name Class Seq Probed Driver Name
----------------------------------------------------------- -----------------------------------------------------------
root 0 [ + ] root_driver root_driver root 0 [ + ] root_driver root_driver
... ...
@@ -75,13 +75,13 @@ using the two alternative bind syntaxes.
=> date => date
Cannot find RTC: err=-19 Cannot find RTC: err=-19
=> dm tree => dm tree
Class Index Probed Driver Name Class Seq Probed Driver Name
----------------------------------------------------------- -----------------------------------------------------------
root 0 [ + ] root_driver root_driver root 0 [ + ] root_driver root_driver
... ...
=> bind /pl031@9010000 rtc-pl031 => bind /pl031@9010000 rtc-pl031
=> dm tree => dm tree
Class Index Probed Driver Name Class Seq Probed Driver Name
----------------------------------------------------------- -----------------------------------------------------------
root 0 [ + ] root_driver root_driver root 0 [ + ] root_driver root_driver
... ...

View File

@@ -12,8 +12,8 @@ Synopsis
:: ::
unbind <node path> unbind <node path>
unbind <class> <index> unbind <class> <seq>
unbind <class> <index> <driver> unbind <class> <seq> <driver>
Description Description
----------- -----------
@@ -27,8 +27,8 @@ node path
class class
device class name device class name
index seq
index of the device in the device class sequence number of the device in the device class
driver driver
device driver name device driver name
@@ -43,7 +43,7 @@ using the three alternative unbind syntaxes.
.. code-block:: .. code-block::
=> dm tree => dm tree
Class Index Probed Driver Name Class Seq Probed Driver Name
----------------------------------------------------------- -----------------------------------------------------------
root 0 [ + ] root_driver root_driver root 0 [ + ] root_driver root_driver
... ...
@@ -70,7 +70,7 @@ using the three alternative unbind syntaxes.
} }
=> unbind /pl031@9010000 => unbind /pl031@9010000
=> dm tree => dm tree
Class Index Probed Driver Name Class Seq Probed Driver Name
----------------------------------------------------------- -----------------------------------------------------------
root 0 [ + ] root_driver root_driver root 0 [ + ] root_driver root_driver
... ...
@@ -78,7 +78,7 @@ using the three alternative unbind syntaxes.
Cannot find a device with path /pl031@9010000 Cannot find a device with path /pl031@9010000
=> bind /pl031@9010000 rtc-pl031 => bind /pl031@9010000 rtc-pl031
=> dm tree => dm tree
Class Index Probed Driver Name Class Seq Probed Driver Name
----------------------------------------------------------- -----------------------------------------------------------
root 0 [ + ] root_driver root_driver root 0 [ + ] root_driver root_driver
... ...