From: Samuel Holland Date: Sun, 22 Jan 2023 00:02:51 +0000 (-0600) Subject: clk: Allow clk_get_by_name() with NULL name X-Git-Tag: v2023.07~156^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2050f824e1367cb227d8e13a91c98577987fe413;p=platform%2Fkernel%2Fu-boot.git clk: Allow clk_get_by_name() with NULL name This allows devm_clock_get(dev, NULL) to work and get the first clock, which is common in code ported from Linux. Signed-off-by: Samuel Holland Reviewed-by: Sean Anderson Reviewed-by: Simon Glass Link: https://lore.kernel.org/r/20230122000252.53642-1-samuel@sholland.org --- diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 2f96355..dc3e9d6 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -399,16 +399,18 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk) int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk) { - int index; + int index = 0; debug("%s(node=%p, name=%s, clk=%p)\n", __func__, ofnode_get_name(node), name, clk); clk->dev = NULL; - index = ofnode_stringlist_search(node, "clock-names", name); - if (index < 0) { - debug("fdt_stringlist_search() failed: %d\n", index); - return index; + if (name) { + index = ofnode_stringlist_search(node, "clock-names", name); + if (index < 0) { + debug("fdt_stringlist_search() failed: %d\n", index); + return index; + } } return clk_get_by_index_nodev(node, index, clk); diff --git a/include/clk.h b/include/clk.h index 138766b..d912852 100644 --- a/include/clk.h +++ b/include/clk.h @@ -167,7 +167,7 @@ int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk); * clk_get_by_name() - Get/request a clock by name. * @dev: The client device. * @name: The name of the clock to request, within the client's list of - * clocks. + * clocks, or NULL to request the first clock in the list. * @clk: A pointer to a clock struct to initialize. * * This looks up and requests a clock. The name is relative to the client @@ -184,7 +184,7 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk); * clk_get_by_name_nodev - Get/request a clock by name without a device. * @node: The client ofnode. * @name: The name of the clock to request, within the client's list of - * clocks. + * clocks, or NULL to request the first clock in the list. * @clk: A pointer to a clock struct to initialize. * * Return: 0 if OK, or a negative error code. diff --git a/test/dm/clk.c b/test/dm/clk.c index 21997ed..f48de05 100644 --- a/test/dm/clk.c +++ b/test/dm/clk.c @@ -26,6 +26,11 @@ static int dm_test_clk_base(struct unit_test_state *uts) ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", &dev)); /* Get the same clk port in 2 different ways and compare */ + ut_assertok(clk_get_by_index(dev, 0, &clk_method1)); + ut_assertok(clk_get_by_name(dev, NULL, &clk_method2)); + ut_asserteq(clk_is_match(&clk_method1, &clk_method2), true); + ut_asserteq(clk_method1.id, clk_method2.id); + ut_assertok(clk_get_by_index(dev, 1, &clk_method1)); ut_assertok(clk_get_by_index_nodev(dev_ofnode(dev), 1, &clk_method2)); ut_asserteq(clk_is_match(&clk_method1, &clk_method2), true);