diff mbox series

[RFC/RFT,v2,10/11] PCI: rockchip: add a lane-map to rockchip pcie driver

Message ID 20220426132139.26761-11-linux@fw-web.de (mailing list archive)
State New
Headers show
Series RK3568 PCIe V3 support | expand

Commit Message

Frank Wunderlich April 26, 2022, 1:21 p.m. UTC
From: Frank Wunderlich <frank-w@public-files.de>

Add a basic lane-map to define which PCIe lanes should be
used with this controller.

Rockchip driver uses this for bifurcation (true/false) based
on lanes should be splitted across controllers or not.

On rk3568 there are 2 PCIe Controllers which share PCIe lanes.

pcie3x1: pcie@fe270000 //lane1 when using 1+1
pcie3x2: pcie@fe280000 //lane0 when using 1+1

This ends up in one Controller (pcie3x1) uses lane-map = <0 1>; and
the other lane-map = <1 0>; (pcie3x2)

This means there are 2 lanes (count of numbers), one (by position)
is mapped to the first controller, the other one is used on the other
controller.

In this driver the lane-map is simply converted to the bifurcation
bool instead of direct mapping a specific lane to a controller.

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
v2:
- new patch
---
 drivers/pci/controller/dwc/pcie-dw-rockchip.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Bjorn Helgaas April 26, 2022, 4:07 p.m. UTC | #1
The subject line should be "PCI: rockchip-dwc: Add ..." so there's no
need to mention "rockchip" again.  No need to mention "pcie driver"
either,  because that's obvious from the context, so just something
like:

  PCI: rockchip-dwc: Add lane-map support

On Tue, Apr 26, 2022 at 03:21:38PM +0200, Frank Wunderlich wrote:
> From: Frank Wunderlich <frank-w@public-files.de>
> 
> Add a basic lane-map to define which PCIe lanes should be
> used with this controller.
> 
> Rockchip driver uses this for bifurcation (true/false) based
> on lanes should be splitted across controllers or not.
> 
> On rk3568 there are 2 PCIe Controllers which share PCIe lanes.
> 
> pcie3x1: pcie@fe270000 //lane1 when using 1+1
> pcie3x2: pcie@fe280000 //lane0 when using 1+1
> 
> This ends up in one Controller (pcie3x1) uses lane-map = <0 1>; and
> the other lane-map = <1 0>; (pcie3x2)
> 
> This means there are 2 lanes (count of numbers), one (by position)
> is mapped to the first controller, the other one is used on the other
> controller.
> 
> In this driver the lane-map is simply converted to the bifurcation
> bool instead of direct mapping a specific lane to a controller.
> 
> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
> ---
> v2:
> - new patch
> ---
>  drivers/pci/controller/dwc/pcie-dw-rockchip.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index 79e909df241c..21cb697a5be1 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -60,6 +60,7 @@ struct rockchip_pcie {
>  	struct regulator                *vpcie3v3;
>  	struct irq_domain		*irq_domain;
>  	bool				bifurcation;
> +	u32				lane_map[2];
>  };
>  
>  static int rockchip_pcie_readl_apb(struct rockchip_pcie *rockchip,
> @@ -293,8 +294,10 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  	struct rockchip_pcie *rockchip;
> +	unsigned int lanecnt = 0;
>  	struct pcie_port *pp;
>  	int ret;
> +	int len;
>  
>  	rockchip = devm_kzalloc(dev, sizeof(*rockchip), GFP_KERNEL);
>  	if (!rockchip)
> @@ -327,8 +330,16 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> -	if (device_property_read_bool(dev, "bifurcation"))
> -		rockchip->bifurcation = true;

Skip adding the "bifurcation" DT support completely if you can.

> +	len = of_property_read_variable_u32_array(dev->of_node, "lane-map", rockchip->lane_map,
> +						  2, ARRAY_SIZE(rockchip->lane_map));
> +
> +	for (int i = 0; i < len; i++)
> +		if (rockchip->lane_map[i])
> +			lanecnt++;
> +
> +	rockchip->bifurcation = ((lanecnt > 0) && (lanecnt != len));
> +
> +	dev_info(dev, "bifurcation: %s\n", rockchip->bifurcation ? "true" : "false");
>  
>  	ret = rockchip_pcie_phy_init(rockchip);
>  	if (ret)
> -- 
> 2.25.1
> 
> 
> -- 
> linux-phy mailing list
> linux-phy@lists.infradead.org
> https://lists.infradead.org/mailman/listinfo/linux-phy
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index 79e909df241c..21cb697a5be1 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -60,6 +60,7 @@  struct rockchip_pcie {
 	struct regulator                *vpcie3v3;
 	struct irq_domain		*irq_domain;
 	bool				bifurcation;
+	u32				lane_map[2];
 };
 
 static int rockchip_pcie_readl_apb(struct rockchip_pcie *rockchip,
@@ -293,8 +294,10 @@  static int rockchip_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct rockchip_pcie *rockchip;
+	unsigned int lanecnt = 0;
 	struct pcie_port *pp;
 	int ret;
+	int len;
 
 	rockchip = devm_kzalloc(dev, sizeof(*rockchip), GFP_KERNEL);
 	if (!rockchip)
@@ -327,8 +330,16 @@  static int rockchip_pcie_probe(struct platform_device *pdev)
 		}
 	}
 
-	if (device_property_read_bool(dev, "bifurcation"))
-		rockchip->bifurcation = true;
+	len = of_property_read_variable_u32_array(dev->of_node, "lane-map", rockchip->lane_map,
+						  2, ARRAY_SIZE(rockchip->lane_map));
+
+	for (int i = 0; i < len; i++)
+		if (rockchip->lane_map[i])
+			lanecnt++;
+
+	rockchip->bifurcation = ((lanecnt > 0) && (lanecnt != len));
+
+	dev_info(dev, "bifurcation: %s\n", rockchip->bifurcation ? "true" : "false");
 
 	ret = rockchip_pcie_phy_init(rockchip);
 	if (ret)