Skip to content

Commit c64ef7e

Browse files
nunojsabebarino
authored andcommitted
clk: clk-axi-clkgen: make sure to enable the AXI bus clock
In order to access the registers of the HW, we need to make sure that the AXI bus clock is enabled. Hence let's increase the number of clocks by one. In order to keep backward compatibility and make sure old DTs still work we check if clock-names is available or not. If it is, then we can disambiguate between really having the AXI clock or a parent clock and so we can enable the bus clock. If not, we fallback to what was done before and don't explicitly enable the AXI bus clock. Note that if clock-names is given, the axi clock must be the last one in the phandle array (also enforced in the DT bindings) so that we can reuse as much code as possible. Fixes: 0e646c5 ("clk: Add axi-clkgen driver") Signed-off-by: Nuno Sa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 47f3f5a commit c64ef7e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

drivers/clk/clk-axi-clkgen.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/platform_device.h>
10+
#include <linux/clk.h>
1011
#include <linux/clk-provider.h>
1112
#include <linux/slab.h>
1213
#include <linux/io.h>
@@ -512,6 +513,7 @@ static int axi_clkgen_probe(struct platform_device *pdev)
512513
struct clk_init_data init;
513514
const char *parent_names[2];
514515
const char *clk_name;
516+
struct clk *axi_clk;
515517
unsigned int i;
516518
int ret;
517519

@@ -528,8 +530,24 @@ static int axi_clkgen_probe(struct platform_device *pdev)
528530
return PTR_ERR(axi_clkgen->base);
529531

530532
init.num_parents = of_clk_get_parent_count(pdev->dev.of_node);
531-
if (init.num_parents < 1 || init.num_parents > 2)
532-
return -EINVAL;
533+
534+
axi_clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk");
535+
if (!IS_ERR(axi_clk)) {
536+
if (init.num_parents < 2 || init.num_parents > 3)
537+
return -EINVAL;
538+
539+
init.num_parents -= 1;
540+
} else {
541+
/*
542+
* Legacy... So that old DTs which do not have clock-names still
543+
* work. In this case we don't explicitly enable the AXI bus
544+
* clock.
545+
*/
546+
if (PTR_ERR(axi_clk) != -ENOENT)
547+
return PTR_ERR(axi_clk);
548+
if (init.num_parents < 1 || init.num_parents > 2)
549+
return -EINVAL;
550+
}
533551

534552
for (i = 0; i < init.num_parents; i++) {
535553
parent_names[i] = of_clk_get_parent_name(pdev->dev.of_node, i);

0 commit comments

Comments
 (0)