From 991759196faa74b2e7df1cb8e87820f4ec7285f8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 16 Dec 2020 21:20:29 -0700 Subject: [PATCH] dm: Drop the unused arg in uclass_find_device_by_seq() Now that there is only one sequence number (rather than both requested and assigned ones) we can simplify this function. Also update its caller to simplify the logic. Signed-off-by: Simon Glass --- arch/arm/mach-k3/am6_init.c | 2 +- arch/arm/mach-k3/j721e_init.c | 2 +- arch/arm/mach-k3/sysfw-loader.c | 2 +- drivers/core/device.c | 16 ++++------ drivers/core/uclass.c | 22 +++++--------- drivers/spi/spi-uclass.c | 4 +-- drivers/usb/host/usb-uclass.c | 4 +-- include/dm/device.h | 18 ++++-------- include/dm/uclass-internal.h | 18 ++++-------- net/eth-uclass.c | 2 +- test/dm/bus.c | 16 +++++----- test/dm/test-fdt.c | 52 ++++++++++++++++----------------- 12 files changed, 64 insertions(+), 94 deletions(-) diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c index 603834e507..0fed5aec59 100644 --- a/arch/arm/mach-k3/am6_init.c +++ b/arch/arm/mach-k3/am6_init.c @@ -208,7 +208,7 @@ void board_init_f(ulong dummy) * firmware (SYSFW) image for various purposes and SYSFW depends on us * to initialize its pin settings. */ - ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev); + ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev); if (!ret) pinctrl_select_state(dev, "default"); diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c index a36e4ed603..0201690f93 100644 --- a/arch/arm/mach-k3/j721e_init.c +++ b/arch/arm/mach-k3/j721e_init.c @@ -167,7 +167,7 @@ void board_init_f(ulong dummy) * firmware (SYSFW) image for various purposes and SYSFW depends on us * to initialize its pin settings. */ - ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev); + ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev); if (!ret) pinctrl_select_state(dev, "default"); diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c index 78c158c63f..708d9c8508 100644 --- a/arch/arm/mach-k3/sysfw-loader.c +++ b/arch/arm/mach-k3/sysfw-loader.c @@ -223,7 +223,7 @@ static void *k3_sysfw_get_spi_addr(void) int ret; ret = uclass_find_device_by_seq(UCLASS_SPI, CONFIG_SF_DEFAULT_BUS, - true, &dev); + &dev); if (ret) return NULL; diff --git a/drivers/core/device.c b/drivers/core/device.c index e8435b8ba4..b878a4d4b6 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -647,15 +647,15 @@ int device_get_child_count(const struct udevice *parent) return count; } -int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, - bool find_req_seq, struct udevice **devp) +int device_find_child_by_seq(const struct udevice *parent, int seq, + struct udevice **devp) { struct udevice *dev; *devp = NULL; list_for_each_entry(dev, &parent->child_head, sibling_node) { - if (dev->sqq == seq_or_req_seq) { + if (dev->sqq == seq) { *devp = dev; return 0; } @@ -671,14 +671,8 @@ int device_get_child_by_seq(const struct udevice *parent, int seq, int ret; *devp = NULL; - ret = device_find_child_by_seq(parent, seq, false, &dev); - if (ret == -ENODEV) { - /* - * We didn't find it in probed devices. See if there is one - * that will request this seq if probed. - */ - ret = device_find_child_by_seq(parent, seq, true, &dev); - } + ret = device_find_child_by_seq(parent, seq, &dev); + return device_get_device_tail(dev, ret, devp); } diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 78765e548e..42c9ba5828 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -288,25 +288,23 @@ int uclass_find_next_free_req_seq(struct uclass *uc) return max + 1; } -int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, - bool find_req_seq, struct udevice **devp) +int uclass_find_device_by_seq(enum uclass_id id, int seq, struct udevice **devp) { struct uclass *uc; struct udevice *dev; int ret; *devp = NULL; - log_debug("%d %d\n", find_req_seq, seq_or_req_seq); - if (seq_or_req_seq == -1) + log_debug("%d\n", seq); + if (seq == -1) return -ENODEV; ret = uclass_get(id, &uc); if (ret) return ret; uclass_foreach_dev(dev, uc) { - log_debug(" - %d %d '%s'\n", - dev->req_seq, dev_seq(dev), dev->name); - if (dev_seq(dev) == seq_or_req_seq) { + log_debug(" - %d '%s'\n", dev->sqq, dev->name); + if (dev->sqq == seq) { *devp = dev; log_debug(" - found\n"); return 0; @@ -466,14 +464,8 @@ int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp) int ret; *devp = NULL; - ret = uclass_find_device_by_seq(id, seq, false, &dev); - if (ret == -ENODEV) { - /* - * We didn't find it in probed devices. See if there is one - * that will request this seq if probed. - */ - ret = uclass_find_device_by_seq(id, seq, true, &dev); - } + ret = uclass_find_device_by_seq(id, seq, &dev); + return uclass_get_device_tail(dev, ret, devp); } diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 9dd32ab333..f3b8ffad42 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -273,7 +273,7 @@ int spi_cs_is_valid(unsigned int busnum, unsigned int cs) struct udevice *bus; int ret; - ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, false, &bus); + ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, &bus); if (ret) { debug("%s: No bus %d\n", __func__, busnum); return ret; @@ -302,7 +302,7 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, struct udevice *bus, *dev; int ret; - ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, false, &bus); + ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, &bus); if (ret) { debug("%s: No bus %d\n", __func__, busnum); return ret; diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index fee92c9d77..a2bd7436f4 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -394,7 +394,7 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp) int ret; /* Find the old device and remove it */ - ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev); + ret = uclass_find_device_by_seq(UCLASS_USB, 0, &dev); if (ret) return ret; ret = device_remove(dev, DM_REMOVE_NORMAL); @@ -417,7 +417,7 @@ int usb_remove_ehci_gadget(struct ehci_ctrl **ctlrp) int ret; /* Find the old device and remove it */ - ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev); + ret = uclass_find_device_by_seq(UCLASS_USB, 0, &dev); if (ret) return ret; ret = device_remove(dev, DM_REMOVE_NORMAL); diff --git a/include/dm/device.h b/include/dm/device.h index 15731d6c27..75f75497c5 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -452,24 +452,16 @@ int device_get_child_count(const struct udevice *parent); /** * device_find_child_by_seq() - Find a child device based on a sequence * - * This searches for a device with the given seq or req_seq. - * - * For seq, if an active device has this sequence it will be returned. - * If there is no such device then this will return -ENODEV. - * - * For req_seq, if a device (whether activated or not) has this req_seq - * value, that device will be returned. This is a strong indication that - * the device will receive that sequence when activated. + * This searches for a device with the given seq. * * @parent: Parent device - * @seq_or_req_seq: Sequence number to find (0=first) - * @find_req_seq: true to find req_seq, false to find seq + * @seq: Sequence number to find (0=first) * @devp: Returns pointer to device (there is only one per for each seq). * Set to NULL if none is found - * @return 0 if OK, -ve on error + * @return 0 if OK, -ENODEV if not found */ -int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, - bool find_req_seq, struct udevice **devp); +int device_find_child_by_seq(const struct udevice *parent, int seq, + struct udevice **devp); /** * device_get_child_by_seq() - Get a child device based on a sequence diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index 2c21871e0f..9c23d3f223 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -103,25 +103,17 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name, /** * uclass_find_device_by_seq() - Find uclass device based on ID and sequence * - * This searches for a device with the given seq or req_seq. - * - * For seq, if an active device has this sequence it will be returned. - * If there is no such device then this will return -ENODEV. - * - * For req_seq, if a device (whether activated or not) has this req_seq - * value, that device will be returned. This is a strong indication that - * the device will receive that sequence when activated. + * This searches for a device with the given seq. * * The device is NOT probed, it is merely returned. * * @id: ID to look up - * @seq_or_req_seq: Sequence number to find (0=first) - * @find_req_seq: true to find req_seq, false to find seq + * @seq: Sequence number to find (0=first) * @devp: Returns pointer to device (there is only one per for each seq) - * @return 0 if OK, -ve on error + * @return 0 if OK, -ENODEV if not found */ -int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, - bool find_req_seq, struct udevice **devp); +int uclass_find_device_by_seq(enum uclass_id id, int seq, + struct udevice **devp); /** * uclass_find_device_by_of_offset() - Find a uclass device by device tree node diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 4eee0113eb..e2d6731975 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -232,7 +232,7 @@ static int on_ethaddr(const char *name, const char *value, enum env_op op, /* look for an index after "eth" */ index = simple_strtoul(name + 3, NULL, 10); - retval = uclass_find_device_by_seq(UCLASS_ETH, index, false, &dev); + retval = uclass_find_device_by_seq(UCLASS_ETH, index, &dev); if (!retval) { struct eth_pdata *pdata = dev->plat; switch (op) { diff --git a/test/dm/bus.c b/test/dm/bus.c index 77555e5293..60ddb1d6b1 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -156,17 +156,17 @@ static int dm_test_bus_children_funcs(struct unit_test_state *uts) ut_asserteq_str("c-test@5", dev->name); /* Device with sequence number 0 should be accessible */ - ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, true, &dev)); - ut_assertok(device_find_child_by_seq(bus, 0, true, &dev)); + ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, &dev)); + ut_assertok(device_find_child_by_seq(bus, 0, &dev)); ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); - ut_asserteq(0, device_find_child_by_seq(bus, 0, false, &dev)); + ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev)); ut_assertok(device_get_child_by_seq(bus, 0, &dev)); ut_assert(dev->flags & DM_FLAG_ACTIVATED); - ut_asserteq(0, device_find_child_by_seq(bus, 0, false, &dev)); + ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev)); /* There is no device with sequence number 2 */ - ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, false, &dev)); - ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, true, &dev)); + ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, &dev)); + ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, &dev)); ut_asserteq(-ENODEV, device_get_child_by_seq(bus, 2, &dev)); /* Looking for something that is not a child */ @@ -220,7 +220,7 @@ static int dm_test_bus_children_iterators(struct unit_test_state *uts) ut_asserteq_ptr(dev, NULL); /* Move to the next child without using device_find_first_child() */ - ut_assertok(device_find_child_by_seq(bus, 5, true, &dev)); + ut_assertok(device_find_child_by_seq(bus, 5, &dev)); ut_asserteq_str("c-test@5", dev->name); ut_assertok(device_find_next_child(&dev)); ut_asserteq_str("c-test@0", dev->name); @@ -245,7 +245,7 @@ static int test_bus_parent_data(struct unit_test_state *uts) ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); /* Check that parent data is allocated */ - ut_assertok(device_find_child_by_seq(bus, 0, true, &dev)); + ut_assertok(device_find_child_by_seq(bus, 0, &dev)); ut_asserteq_ptr(NULL, dev_get_parent_priv(dev)); ut_assertok(device_get_child_by_seq(bus, 0, &dev)); parent_data = dev_get_parent_priv(dev); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 87e09f19cd..5f443bdb6c 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -348,11 +348,11 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts) struct udevice *dev; /* A few basic santiy tests */ - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, &dev)); ut_asserteq_str("b-test", dev->name); ut_asserteq(3, dev_seq(dev)); - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, &dev)); ut_asserteq_str("a-test", dev->name); ut_asserteq(8, dev_seq(dev)); @@ -360,11 +360,11 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts) * This device has no alias so gets the next value after all available * aliases. The last alias is testfdt12 */ - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 13, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 13, &dev)); ut_asserteq_str("d-test", dev->name); ut_asserteq(13, dev_seq(dev)); - ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9, true, + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9, &dev)); ut_asserteq_ptr(NULL, dev); @@ -395,22 +395,22 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts) ut_asserteq(15, dev_seq(dev)); /* And we should still have holes in our sequence numbers */ - ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 0, true, + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 0, &dev)); - ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 1, true, + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 1, &dev)); - ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 2, true, + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 2, &dev)); - ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 4, true, + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 4, &dev)); - ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7, true, + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7, &dev)); - ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9, true, + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9, &dev)); ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 10, - true, &dev)); + &dev)); ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 11, - true, &dev)); + &dev)); return 0; } @@ -636,30 +636,30 @@ static int dm_test_fdt_translation(struct unit_test_state *uts) fdt32_t dma_addr[2]; /* Some simple translations */ - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); ut_asserteq_str("dev@0,0", dev->name); ut_asserteq(0x8000, dev_read_addr(dev)); - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev)); ut_asserteq_str("dev@1,100", dev->name); ut_asserteq(0x9000, dev_read_addr(dev)); - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, &dev)); ut_asserteq_str("dev@2,200", dev->name); ut_asserteq(0xA000, dev_read_addr(dev)); /* No translation for busses with #size-cells == 0 */ - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, &dev)); ut_asserteq_str("dev@42", dev->name); ut_asserteq(0x42, dev_read_addr(dev)); /* dma address translation */ - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); dma_addr[0] = cpu_to_be32(0); dma_addr[1] = cpu_to_be32(0); ut_asserteq(0x10000000, dev_translate_dma_address(dev, dma_addr)); - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev)); dma_addr[0] = cpu_to_be32(1); dma_addr[1] = cpu_to_be32(0x100); ut_asserteq(0x20000000, dev_translate_dma_address(dev, dma_addr)); @@ -677,7 +677,7 @@ static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts) ut_assertok(uclass_first_device_err(UCLASS_GPIO, &gpio)); ut_assertnull(devfdt_get_addr_ptr(gpio)); - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); ptr = devfdt_get_addr_ptr(dev); ut_asserteq_ptr((void *)0x8000, ptr); @@ -692,7 +692,7 @@ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts) fdt_addr_t addr; void *paddr; - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); addr = devfdt_get_addr(dev); ut_asserteq(0x8000, addr); @@ -713,7 +713,7 @@ static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts) fdt_size_t size; void *paddr; - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); addr = devfdt_get_addr_size_index(dev, 0, &size); ut_asserteq(0x8000, addr); @@ -735,7 +735,7 @@ static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts) fdt_size_t size; void *paddr; - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); addr = devfdt_get_addr_size_name(dev, "sandbox-dummy-0", &size); ut_asserteq(0x8000, addr); @@ -756,7 +756,7 @@ static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts) fdt_addr_t addr; void *paddr; - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); addr = dev_read_addr(dev); ut_asserteq(0x8000, addr); @@ -777,7 +777,7 @@ static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts) fdt_size_t size; void *paddr; - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); addr = dev_read_addr_size_index(dev, 0, &size); ut_asserteq(0x8000, addr); @@ -799,7 +799,7 @@ static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts) fdt_size_t size; void *paddr; - ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); addr = dev_read_addr_size_name(dev, "sandbox-dummy-0", &size); ut_asserteq(0x8000, addr); @@ -834,7 +834,7 @@ static int dm_test_fdt_livetree_writing(struct unit_test_state *uts) device_bind_driver_to_node(dm_root(), "usb_sandbox", "usb@2", node, &dev); - ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 2, true, &dev)); + ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 2, &dev)); /* Test string property setting */