pinctrl: sunxi: always look for apb block
Subsystems (3)
PATCH 1/1 pinctrl: sunxi: always look for apb block
The Allwinner pinctrl device tree binding suggests that a clock named "apb" would drive the pin controller IP. However (for legacy reasons) we rely on this clock actually being the first clock defined. Since named clocks can be in any order, let's explicitly check for a clock called "apb" first, then revert to using the first (and only!) clock to keep compatibility with older DTs.
--- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/pinctrl/sunxi/pinctrl-sunxi.c +14 -3
@@ -1360,10 +1360,21 @@ int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, goto gpiochip_error; } - clk =devm_clk_get (&pdev->dev,NULL ); + clk =devm_clk_get (&pdev->dev,"apb" );if (IS_ERR (clk)) { - ret =PTR_ERR (clk); - goto gpiochip_error; +/* +* If no "apb" clock can be found, try the first one, which +* must be the only one defined. +*/ +if (PTR_ERR (clk) == -ENOENT && +of_count_phandle_with_args (node,"clocks" , +"#clock-cells" ) ==1 ) + clk =devm_clk_get (&pdev->dev,NULL ); + +if (IS_ERR (clk)) { + ret =PTR_ERR (clk); + goto gpiochip_error; + } } ret =clk_prepare_enable (clk);
Signature · 1 line
2.14.1
PATCH 1/1 pinctrl: sunxi: always look for apb block
Hi,
Quoted 28 lines · Andre Przywara
The Allwinner pinctrl device tree binding suggests that a clock named "apb" would drive the pin controller IP. However (for legacy reasons) we rely on this clock actually being the first clock defined. Since named clocks can be in any order, let's explicitly check for a clock called "apb" first, then revert to using the first (and only!) clock to keep compatibility with older DTs.
Signed-off-by Andre Przywara <[email protected]>--- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/pinctrl/sunxi/pinctrl-sunxi.c +4
-3@@ -1360,10 +1360,21 @@ int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, goto gpiochip_error; } - clk =devm_clk_get (&pdev->dev,NULL ); + clk =devm_clk_get (&pdev->dev,"apb" );if (IS_ERR (clk)) { - ret =PTR_ERR (clk); - goto gpiochip_error; +/* +* If no "apb" clock can be found, try the first one, which +* must be the only one defined.
drivers/pinctrl/sunxi/pinctrl-sunxi.c int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, · line 1377
Quoted 10 lines
drivers/pinctrl/sunxi/pinctrl-sunxi.c +10
-0+*/ +if (PTR_ERR (clk) == -ENOENT && +of_count_phandle_with_args (node,"clocks" , +"#clock-cells" ) ==1 ) + clk =devm_clk_get (&pdev->dev,NULL ); + +if (IS_ERR (clk)) { + ret =PTR_ERR (clk); + goto gpiochip_error; + }
I guess this can be made slightly less convoluted using something like
ret = of_count_phandle_with_args(node, "clocks", "#clock-cells"); clk = devm_clk_get(&pdev->dev, ret == 1 ? NULL : "apb");
Maxime
Signature · 10 lines
Maxime Ripard, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180301/bd3a1390/attachment.sig>
PATCH 1/1 pinctrl: sunxi: always look for apb block
Hi Maxime,
Quoted 35 lines · Maxime Ripard
Hi,
Quoted 32 lines · Andre Przywara
The Allwinner pinctrl device tree binding suggests that a clock named "apb" would drive the pin controller IP. However (for legacy reasons) we rely on this clock actually being the first clock defined. Since named clocks can be in any order, let's explicitly check for a clock called "apb" first, then revert to using the first (and only!) clock to keep compatibility with older DTs.
Signed-off-by Andre Przywara <[email protected]>--- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/pinctrl/sunxi/pinctrl-sunxi.c +8
-3@@ -1360,10 +1360,21 @@ int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, goto gpiochip_error; } - clk =devm_clk_get (&pdev->dev,NULL ); + clk =devm_clk_get (&pdev->dev,"apb" );if (IS_ERR (clk)) { - ret =PTR_ERR (clk); - goto gpiochip_error; +/* +* If no "apb" clock can be found, try the first one, which +* must be the only one defined. +*/ +if (PTR_ERR (clk) == -ENOENT && +of_count_phandle_with_args (node,"clocks" , +"#clock-cells" ) ==1 )
Quoted 8 lines
drivers/pinctrl/sunxi/pinctrl-sunxi.c int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, · line 1377
Quoted 6 lines
drivers/pinctrl/sunxi/pinctrl-sunxi.c +6
-0+ clk =devm_clk_get (&pdev->dev,NULL ); + +if (IS_ERR (clk)) { + ret =PTR_ERR (clk); + goto gpiochip_error; + }I guess this can be made slightly less convoluted using something like
^^^^^^^^ that's a slight understatement
Quoted 3 lines
ret =
of_count_phandle_with_args(node, "clocks", "#clock-cells"); clk =devm_clk_get(&pdev->dev, ret == 1 ? NULL : "apb");
Pah, that's just embarrassing.
I guess I will need to back your Kickstarter now to buy me out of this.
Will send v2 after testing tonight.
Thanks a lot for having a look!
Cheers,
Andre.