PCI: Simplify few things
Subsystems (5)
cover PCI: Simplify few things
Few code simplifications without functional impact. Not tested on hardware.
Best regards,
Krzysztof
---
Krzysztof Kozlowski (2):
PCI: dwc: dra7xx: Use syscon_regmap_lookup_by_phandle_args
PCI: dwc: layerscape: Use syscon_regmap_lookup_by_phandle_args
drivers/pci/controller/dwc/pci-dra7xx.c | 27 ++++++--------------------- drivers/pci/controller/dwc/pci-layerscape.c | 10 ++++------ 2 files changed, 10 insertions(+), 27 deletions(-)
---
base-commit: 2ddfbff29a2d45551e8c3e4f0c6b7c4618de24b7
change-id: 20250112-syscon-phandle-args-pci-d97537922ddd
Best regards,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>
PATCH 1/2 PCI: dwc: dra7xx: Use syscon_regmap_lookup_by_phandle_args
Use syscon_regmap_lookup_by_phandle_args() which is a wrapper over syscon_regmap_lookup_by_phandle() combined with getting the syscon argument. Except simpler code this annotates within one line that given phandle has arguments, so grepping for code would be easier.
There is also no real benefit in printing errors on missing syscon argument, because this is done just too late: runtime check on static/build-time data. Dtschema and Devicetree bindings offer the static/build-time check for this already.
--- drivers/pci/controller/dwc/pci-dra7xx.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-)
drivers/pci/controller/dwc/pci-dra7xx.c +6 -21
@@ -635,30 +635,20 @@ static int dra7xx_pcie_unaligned_memaccess(struct device *dev) {int ret;struct device_node *np = dev->of_node; -struct of_phandle_args args; +unsigned int args[2 ];struct regmap *regmap; - regmap =syscon_regmap_lookup_by_phandle (np, -"ti,syscon-unaligned-access" ); + regmap =syscon_regmap_lookup_by_phandle_args (np,"ti,syscon-unaligned-access" , +2 , args);if (IS_ERR (regmap)) {dev_dbg (dev,"can't get ti,syscon-unaligned-access\n" );return -EINVAL ; } - ret =of_parse_phandle_with_fixed_args (np,"ti,syscon-unaligned-access" , -2 ,0 , &args); -if (ret) { -dev_err (dev,"failed to parse ti,syscon-unaligned-access\n" ); -return ret; - } - - ret =regmap_update_bits (regmap, args.args[0 ], args.args[1 ], - args.args[1 ]); + ret =regmap_update_bits (regmap, args[0 ], args[1 ], args[1 ]);if (ret)dev_err (dev,"failed to enable unaligned access\n" ); -of_node_put (args.np); -return ret; }
@@ -671,18 +661,13 @@ static int dra7xx_pcie_configure_two_lane(struct device *dev,u32 mask;u32 val; - pcie_syscon =syscon_regmap_lookup_by_phandle (np,"ti,syscon-lane-sel" ); + pcie_syscon =syscon_regmap_lookup_by_phandle_args (np,"ti,syscon-lane-sel" , +1 , &pcie_reg);if (IS_ERR (pcie_syscon)) {dev_err (dev,"unable to get ti,syscon-lane-sel\n" );return -EINVAL ; } -if (of_property_read_u32_index (np,"ti,syscon-lane-sel" ,1 , - &pcie_reg)) { -dev_err (dev,"couldn't get lane selection reg offset\n" ); -return -EINVAL ; - } - mask = b1co_mode_sel_mask |PCIE_B0_B1_TSYNCEN ; val =PCIE_B1C0_MODE_SEL |PCIE_B0_B1_TSYNCEN ;regmap_update_bits (pcie_syscon, pcie_reg, mask, val);
Signature · 1 line
2.43.0
Re: [PATCH 1/2] PCI: dwc: dra7xx: Use syscon_regmap_lookup_by_phandle_args
Quoted 61 lines · Krzysztof Kozlowski
Use
syscon_regmap_lookup_by_phandle_args()which is a wrapper oversyscon_regmap_lookup_by_phandle()combined with getting the syscon argument. Except simpler code this annotates within one line that given phandle has arguments, so grepping for code would be easier.There is also no real benefit in printing errors on missing syscon argument, because this is done just too late: runtime check on static/build-time data. Dtschema and Devicetree bindings offer the static/build-time check for this already.
Signed-off-by Krzysztof Kozlowski <[email protected]>--- drivers/pci/controller/dwc/pci-dra7xx.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-)drivers/pci/controller/dwc/pci-dra7xx.c +6
-15@@ -635,30 +635,20 @@ static int dra7xx_pcie_unaligned_memaccess(struct device *dev) {int ret;struct device_node *np = dev->of_node; -struct of_phandle_args args; +unsigned int args[2 ];struct regmap *regmap; - regmap =syscon_regmap_lookup_by_phandle (np, -"ti,syscon-unaligned-access" ); + regmap =syscon_regmap_lookup_by_phandle_args (np,"ti,syscon-unaligned-access" , +2 , args);if (IS_ERR (regmap)) {dev_dbg (dev,"can't get ti,syscon-unaligned-access\n" );return -EINVAL ; } - ret =of_parse_phandle_with_fixed_args (np,"ti,syscon-unaligned-access" , -2 ,0 , &args); -if (ret) { -dev_err (dev,"failed to parse ti,syscon-unaligned-access\n" ); -return ret; - } - - ret =regmap_update_bits (regmap, args.args[0 ], args.args[1 ], - args.args[1 ]); + ret =regmap_update_bits (regmap, args[0 ], args[1 ], args[1 ]);if (ret)dev_err (dev,"failed to enable unaligned access\n" ); -of_node_put (args.np); -return ret; }@@ -671,18 +661,13 @@ static int dra7xx_pcie_configure_two_lane(struct device *dev,u32 mask;u32 val; - pcie_syscon =syscon_regmap_lookup_by_phandle (np,"ti,syscon-lane-sel" ); + pcie_syscon =syscon_regmap_lookup_by_phandle_args (np,"ti,syscon-lane-sel" , +1 , &pcie_reg);
drivers/pci/controller/dwc/pci-dra7xx.c static int dra7xx_pcie_configure_two_lane(struct device *dev, · line 684
Quoted 10 lines
drivers/pci/controller/dwc/pci-dra7xx.c +0
-5if (IS_ERR (pcie_syscon)) {dev_err (dev,"unable to get ti,syscon-lane-sel\n" );return -EINVAL ; } -if (of_property_read_u32_index (np,"ti,syscon-lane-sel" ,1 , - &pcie_reg)) { -dev_err (dev,"couldn't get lane selection reg offset\n" ); -return -EINVAL ; - }
Wow. I believe you that syscon_regmap_lookup_by_phandle_args() is equivalent to both:
- syscon_regmap_lookup_by_phandle() followed by
of_parse_phandle_with_fixed_args(), and
- syscon_regmap_lookup_by_phandle() followed by
of_property_read_u32_index()
but I can't say it's obvious to this syscon- and OF-naive reviewer, even after tracing a few layers in :)
Bjorn
PATCH 2/2 PCI: dwc: layerscape: Use syscon_regmap_lookup_by_phandle_args
In reply to Krzysztof KozlowskiUse syscon_regmap_lookup_by_phandle_args() which is a wrapper over syscon_regmap_lookup_by_phandle() combined with getting the syscon argument. Except simpler code this annotates within one line that given phandle has arguments, so grepping for code would be easier.
--- drivers/pci/controller/dwc/pci-layerscape.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/pci/controller/dwc/pci-layerscape.c +4 -6
@@ -329,7 +329,6 @@ static int ls_pcie_probe(struct platform_device *pdev)struct ls_pcie *pcie;struct resource *dbi_base;u32 index[2 ]; -int ret; pcie =devm_kzalloc (dev,sizeof (*pcie),GFP_KERNEL );if (!pcie)
@@ -355,16 +354,15 @@ static int ls_pcie_probe(struct platform_device *pdev) pcie->pf_lut_base = pci->dbi_base + pcie->drvdata->pf_lut_off;if (pcie->drvdata->scfg_support) { - pcie->scfg =syscon_regmap_lookup_by_phandle (dev->of_node,"fsl,pcie-scfg" ); + pcie->scfg = +syscon_regmap_lookup_by_phandle_args (dev->of_node, +"fsl,pcie-scfg" ,2 , + index);if (IS_ERR (pcie->scfg)) {dev_err (dev,"No syscfg phandle specified\n" );return PTR_ERR (pcie->scfg); } - ret =of_property_read_u32_array (dev->of_node,"fsl,pcie-scfg" , index,2 ); -if (ret) -return ret; - pcie->index = index[1 ]; }
Signature · 1 line
2.43.0
Re: [PATCH 2/2] PCI: dwc: layerscape: Use syscon_regmap_lookup_by_phandle_args
Quoted 6 lines · Krzysztof Kozlowski
Use
syscon_regmap_lookup_by_phandle_args()which is a wrapper oversyscon_regmap_lookup_by_phandle()combined with getting the syscon argument. Except simpler code this annotates within one line that given phandle has arguments, so grepping for code would be easier.Signed-off-by Krzysztof Kozlowski <[email protected]>
Quoted 41 lines
--- drivers/pci/controller/dwc/pci-layerscape.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/pci/controller/dwc/pci-layerscape.c +4
-7@@ -329,7 +329,6 @@ static int ls_pcie_probe(struct platform_device *pdev)struct ls_pcie *pcie;struct resource *dbi_base;u32 index[2 ]; -int ret; pcie =devm_kzalloc (dev,sizeof (*pcie),GFP_KERNEL );if (!pcie)@@ -355,16 +354,15 @@ static int ls_pcie_probe(struct platform_device *pdev) pcie->pf_lut_base = pci->dbi_base + pcie->drvdata->pf_lut_off;if (pcie->drvdata->scfg_support) { - pcie->scfg =syscon_regmap_lookup_by_phandle (dev->of_node,"fsl,pcie-scfg" ); + pcie->scfg = +syscon_regmap_lookup_by_phandle_args (dev->of_node, +"fsl,pcie-scfg" ,2 , + index);if (IS_ERR (pcie->scfg)) {dev_err (dev,"No syscfg phandle specified\n" );return PTR_ERR (pcie->scfg); } - ret =of_property_read_u32_array (dev->of_node,"fsl,pcie-scfg" , index,2 ); -if (ret) -return ret; - pcie->index = index[1 ]; } --2.43.0
RE: [PATCH 2/2] PCI: dwc: layerscape: Use syscon_regmap_lookup_by_phandle_args
In reply to Krzysztof KozlowskiQuoted 11 lines
From: Krzysztof Kozlowski <[email protected]>
Use
syscon_regmap_lookup_by_phandle_args()which is a wrapper oversyscon_regmap_lookup_by_phandle()combined with getting the syscon argument. Except simpler code this annotates within one line that given phandle has arguments, so grepping for code would be easier.Signed-off-by Krzysztof Kozlowski <[email protected]>--- drivers/pci/controller/dwc/pci-layerscape.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
Roy
Krzysztof Wilczyński
AppliedHello,
Quoted 2 lines
Few code simplifications without functional impact. Not tested on hardware.
Applied to controller/dwc for v6.14, thank you!
Krzysztof