pci: pcie_dw_qcom: fix clock/power-domain bring-up ordering
PATCH 1/1 pci: pcie_dw_qcom: fix clock/power-domain bring-up ordering
From: Senthilkumar <[email protected]>
Two probe-ordering issues in qcom_pcie_parse_dt():
- clk_get_bulk() aborts and releases everything already fetched as soon as one clock (e.g. a not-yet-registered PHY pipe clock) fails to resolve, even clocks needed earlier such as ones gating PARF access.
- The power domain may not be enabled yet via driver model auto-enable, and PARF access while it is off aborts.
Instead, fetch each clock individually, tolerating -ENODEV/-ENOENT for clocks enabled later by their own provider, and explicitly turn the power domain on before any PARF access.
--- drivers/pci/pcie_dw_qcom.c | 43 ++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-)
drivers/pci/pcie_dw_qcom.c +39 -4
@@ -13,6 +13,7 @@#include <asm/io.h> #include <asm-generic/gpio.h> #include <dm/device_compat.h> +#include <dm/devres.h> #include <linux/iopoll.h> #include <linux/delay.h> #include <linux/log2.h>
@@ -415,6 +416,7 @@ static const char *qcom_pcie_vregs[NUM_SUPPLIES] = {static int qcom_pcie_parse_dt (struct udevice *dev) {struct qcom_pcie *priv =dev_get_priv (dev); +struct power_domain pd;int vreg, ret; priv->dw.dbi_base =dev_read_addr_name_ptr (dev,"dbi" );
@@ -448,10 +450,43 @@ static int qcom_pcie_parse_dt(struct udevice *dev)return ret; } - ret =clk_get_bulk (dev, &priv->clks); -if (ret) { -dev_err (dev,"failed to get clocks (%d)\n" , ret); -return ret; +/* +* clk_get_bulk() aborts on the first unresolved clock (e.g. +* a not-yet-registered PHY pipe clock), dropping clocks +* fetched earlier too. Instead, fetch one clock at a time, +* skipping ones not yet available (-ENODEV/-ENOENT), which +* are expected to be enabled by their own provider later. +*/ +int count =dev_count_phandle_with_args (dev,"clocks" , +"#clock-cells" ,0 ); +int idx; + + priv->clks.count =0 ; +if (count >0 ) { + priv->clks.clks =devm_kcalloc (dev, count, +sizeof (struct clk ), +GFP_KERNEL ); +if (!priv->clks.clks) +return -ENOMEM ; + +for (idx =0 ; idx < count; idx++) { + ret =clk_get_by_index (dev, idx, + &priv->clks.clks[priv->clks.count]); +if (!ret) { + priv->clks.count++; + }else if (ret != -ENODEV && ret != -ENOENT ) { +dev_err (dev,"failed to get clock %d (%d)\n" , + idx, ret); +return ret; + } + } + } + +/* Ensure the power domain is on before any PARF register access */ +if (!power_domain_get_by_index (dev, &pd,0 )) { + ret =power_domain_on (&pd); +if (ret && ret != -ENOSYS ) +dev_warn (dev,"failed to enable power domain (%d)\n" , ret); } ret =generic_phy_get_by_index (dev,0 , &priv->phy);
base-commit: 3973f3c4d24df75ca90d7c0a9f03e5e5c9b48f32
Signature · 2 lines
Best regards Sumit Singh Dhami
Quoted 9 lines · Sumit Singh Dhami
From: Senthilkumar <[email protected]>
Two probe-ordering issues in
qcom_pcie_parse_dt():-
clk_get_bulk()aborts and releases everything already fetched as soon as one clock (e.g. a not-yet-registered PHY pipe clock) fails to resolve, even clocks needed earlier such as ones gating PARF access.
Quoted 6 lines
- The power domain may not be enabled yet via driver model auto-enable, and PARF access while it is off aborts.
Instead, fetch each clock individually, tolerating -ENODEV/-ENOENT for clocks enabled later by their own provider, and explicitly turn the power domain on before any PARF access.
Sorry I don't understand the problem, which clock is missing ? why do you need to ignore -ENODEV/-ENOENT ? how will you get those clocks after the pcie controller probe ?
Split out the Power Domain change, and explain better why it should be enabled so early.
Thanks,
Neil
Quoted 77 lines
Signed-off-by Senthilkumar <[email protected]>Signed-off-by Sumit Singh Dhami <[email protected]>--- drivers/pci/pcie_dw_qcom.c | 43 ++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-)drivers/pci/pcie_dw_qcom.c +39
-4@@ -13,6 +13,7 @@#include <asm/io.h> #include <asm-generic/gpio.h> #include <dm/device_compat.h> +#include <dm/devres.h> #include <linux/iopoll.h> #include <linux/delay.h> #include <linux/log2.h> @@ -415,6 +416,7 @@ static const char *qcom_pcie_vregs[NUM_SUPPLIES] = {static int qcom_pcie_parse_dt (struct udevice *dev) {struct qcom_pcie *priv =dev_get_priv (dev); +struct power_domain pd;int vreg, ret; priv->dw.dbi_base =dev_read_addr_name_ptr (dev,"dbi" );@@ -448,10 +450,43 @@ static int qcom_pcie_parse_dt(struct udevice *dev)return ret; } - ret =clk_get_bulk (dev, &priv->clks); -if (ret) { -dev_err (dev,"failed to get clocks (%d)\n" , ret); -return ret; +/* +* clk_get_bulk() aborts on the first unresolved clock (e.g. +* a not-yet-registered PHY pipe clock), dropping clocks +* fetched earlier too. Instead, fetch one clock at a time, +* skipping ones not yet available (-ENODEV/-ENOENT), which +* are expected to be enabled by their own provider later. +*/ +int count =dev_count_phandle_with_args (dev,"clocks" , +"#clock-cells" ,0 ); +int idx; + + priv->clks.count =0 ; +if (count >0 ) { + priv->clks.clks =devm_kcalloc (dev, count, +sizeof (struct clk ), +GFP_KERNEL ); +if (!priv->clks.clks) +return -ENOMEM ; + +for (idx =0 ; idx < count; idx++) { + ret =clk_get_by_index (dev, idx, + &priv->clks.clks[priv->clks.count]); +if (!ret) { + priv->clks.count++; + }else if (ret != -ENODEV && ret != -ENOENT ) { +dev_err (dev,"failed to get clock %d (%d)\n" , + idx, ret); +return ret; + } + } + } + +/* Ensure the power domain is on before any PARF register access */ +if (!power_domain_get_by_index (dev, &pd,0 )) { + ret =power_domain_on (&pd); +if (ret && ret != -ENOSYS ) +dev_warn (dev,"failed to enable power domain (%d)\n" , ret); } ret =generic_phy_get_by_index (dev,0 , &priv->phy);base-commit:
3973f3c4d24df75ca90d7c0a9f03e5e5c9b48f32