]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm: mvebu: a38x: serdes: Move non-serdes PCIe code to pci_mvebu.c
authorPali Rohár <pali@kernel.org>
Tue, 21 Dec 2021 11:20:19 +0000 (12:20 +0100)
committerStefan Roese <sr@denx.de>
Fri, 14 Jan 2022 06:47:57 +0000 (07:47 +0100)
As explained in commit 3bedbcc3aa18 ("arm: mvebu: a38x: serdes: Don't
overwrite read-only SAR PCIe registers") it is required to set Maximum Link
Width bits of PCIe Root Port Link Capabilities Register depending of number
of used serdes lanes. As this register is part of PCIe address space and
not serdes address space, move it into pci_mvebu.c driver.

Read number of PCIe lanes from DT property "num-lanes" which is used also
by other PCIe controller drivers in Linux kernel. If this property is
absent then it defaults to 1. This property needs to be set to 4 for every
mvebu board which use PEX_ROOT_COMPLEX_X4 or PEX_BUS_MODE_X4.

Enabling of PCIe port needs to be done afer all registers in PCIe address
space are properly configure. For this purpose use new mvebu-reset driver
(part of system-controller) and remove this code from serdes code.

Because some PCIe ports cannot be enabled individually, it is required to
first setup all PCIe ports and then enable them.

This change contains also all required "num-lanes" and "resets" DTS
properties, to make pci_mvebu.c driver work correctly.

Signed-off-by: Pali Rohár <pali@kernel.org>
15 files changed:
arch/arm/dts/armada-375.dtsi
arch/arm/dts/armada-380.dtsi
arch/arm/dts/armada-385.dtsi
arch/arm/dts/armada-xp-98dx3236.dtsi
arch/arm/dts/armada-xp-mv78230.dtsi
arch/arm/dts/armada-xp-mv78260.dtsi
arch/arm/dts/armada-xp-mv78460.dtsi
arch/arm/dts/armada-xp-synology-ds414.dts
arch/arm/dts/armada-xp-theadorable.dts
arch/arm/mach-mvebu/serdes/a38x/Makefile
arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.c [deleted file]
arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.h [deleted file]
arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c
drivers/pci/Kconfig
drivers/pci/pci_mvebu.c

index fdf2d6dbdc8416cece93cc751132c904bfddaf69..ff0ad7a9c7fd8bfb8b9afd4607d40ab67d33ec68 100644 (file)
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 5>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <1>;
                                clocks = <&gateclk 6>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
index cff1269f3fbfd14f3b43da67f5ef9909b17c8d5d..f3d7f4b27ddb41ad603742120946ec3c747644e7 100644 (file)
@@ -73,6 +73,7 @@
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 8>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
@@ -92,6 +93,7 @@
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 5>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <2>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 6>;
+                               resets = <&systemc 0 2>;
                                status = "disabled";
                        };
                };
index f0022d10c7159d2d1f1102dfcee844fdc040d931..581a7d9beac322534cb77685cf14717cf839f3d4 100644 (file)
@@ -78,6 +78,7 @@
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 8>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
@@ -97,6 +98,7 @@
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 5>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <2>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 6>;
+                               resets = <&systemc 0 2>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <3>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 7>;
+                               resets = <&systemc 0 3>;
                                status = "disabled";
                        };
                };
index 8369de79afa299e748b95d304ec423b13c78f349..1a48ff3c61621685c32f48943b4d921eacaf3b2f 100644 (file)
@@ -85,6 +85,7 @@
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 5>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
                };
index 8558bf6bb54c603c16b8a5a987c991413e3297c8..63d7f48cf456a2a4d11ec4ecf0f4b59c4c432a8e 100644 (file)
@@ -92,6 +92,7 @@
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 5>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <1>;
                                clocks = <&gateclk 6>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <2>;
                                clocks = <&gateclk 7>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <3>;
                                clocks = <&gateclk 8>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 9>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
                };
index 2d85fe8ac327296420e1050228e88fa0df48d79a..5dc413dd14bec2d9fc1b8b2061216788141655a6 100644 (file)
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 5>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <1>;
                                clocks = <&gateclk 6>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <2>;
                                clocks = <&gateclk 7>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <3>;
                                clocks = <&gateclk 8>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 9>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <1>;
                                clocks = <&gateclk 10>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <2>;
                                clocks = <&gateclk 11>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <3>;
                                clocks = <&gateclk 12>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <2>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 26>;
+                               resets = <&systemc 0 2>;
                                status = "disabled";
                        };
                };
index 230a3fd36b3048937c760784ec2fd619f49f9bdb..6fbd0ce215ff90075a771242a5b0b985cd942891 100644 (file)
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 5>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <1>;
                                clocks = <&gateclk 6>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <2>;
                                clocks = <&gateclk 7>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <0>;
                                marvell,pcie-lane = <3>;
                                clocks = <&gateclk 8>;
+                               resets = <&systemc 0 0>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 9>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <1>;
                                clocks = <&gateclk 10>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <2>;
                                clocks = <&gateclk 11>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <1>;
                                marvell,pcie-lane = <3>;
                                clocks = <&gateclk 12>;
+                               resets = <&systemc 0 1>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <2>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 26>;
+                               resets = <&systemc 0 2>;
                                status = "disabled";
                        };
 
                                marvell,pcie-port = <3>;
                                marvell,pcie-lane = <0>;
                                clocks = <&gateclk 27>;
+                               resets = <&systemc 0 3>;
                                status = "disabled";
                        };
                };
index 861967cd7e8728124f0e336819bf4c034b930a56..35909e3c69c6c3098b55ce1422bca5b67537fac7 100644 (file)
        pcie@1,0 {
                /* Port 0, Lane 0 */
                status = "okay";
+               num-lanes = <4>;
        };
 
        /*
index 24cc1cc5278edf59877d2e7f7d48e056ac3ab37f..a06a65af158733d27d32fd4b02593fc379c5391e 100644 (file)
        pcie@9,0 {
                /* Port 2, Lane 0 */
                status = "okay";
+               num-lanes = <4>;
        };
 };
index 917fc1350ce53ef2b1141a10f8da59b021868eb1..5a70b3759667fdb45e4b35a355f3386f6930116c 100644 (file)
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0+
 
-obj-$(CONFIG_SPL_BUILD)        = ctrl_pex.o
 obj-$(CONFIG_SPL_BUILD)        += high_speed_env_spec.o
 obj-$(CONFIG_SPL_BUILD)        += high_speed_env_spec-38x.o
 obj-$(CONFIG_SPL_BUILD)        += seq_exec.o
diff --git a/arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.c b/arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.c
deleted file mode 100644 (file)
index b3cbddf..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) Marvell International Ltd. and its affiliates
- */
-
-#include <common.h>
-#include <spl.h>
-#include <asm/io.h>
-#include <asm/arch/cpu.h>
-#include <asm/arch/soc.h>
-#include <linux/bitops.h>
-#include <linux/delay.h>
-
-#include "ctrl_pex.h"
-#include "sys_env_lib.h"
-
-int hws_pex_config(const struct serdes_map *serdes_map, u8 count)
-{
-       enum serdes_type serdes_type;
-       u32 idx, tmp;
-
-       DEBUG_INIT_FULL_S("\n### hws_pex_config ###\n");
-
-       tmp = reg_read(SOC_CONTROL_REG1);
-       tmp &= ~0x03;
-
-       for (idx = 0; idx < count; idx++) {
-               serdes_type = serdes_map[idx].serdes_type;
-               if ((serdes_type != PEX0) &&
-                   ((serdes_map[idx].serdes_mode == PEX_ROOT_COMPLEX_X4) ||
-                    (serdes_map[idx].serdes_mode == PEX_END_POINT_X4))) {
-                       /* for PEX by4 - relevant for the first port only */
-                       continue;
-               }
-
-               switch (serdes_type) {
-               case PEX0:
-                       tmp |= 0x1 << PCIE0_ENABLE_OFFS;
-                       break;
-               case PEX1:
-                       tmp |= 0x1 << PCIE1_ENABLE_OFFS;
-                       break;
-               case PEX2:
-                       tmp |= 0x1 << PCIE2_ENABLE_OFFS;
-                       break;
-               case PEX3:
-                       tmp |= 0x1 << PCIE3_ENABLE_OFFS;
-                       break;
-               default:
-                       break;
-               }
-       }
-
-       reg_write(SOC_CONTROL_REG1, tmp);
-
-       return MV_OK;
-}
diff --git a/arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.h b/arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.h
deleted file mode 100644 (file)
index abdbe3c..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Copyright (C) Marvell International Ltd. and its affiliates
- */
-
-#ifndef _CTRL_PEX_H
-#define _CTRL_PEX_H
-
-#include <pci.h>
-#include "high_speed_env_spec.h"
-
-/* Direct access to PEX0 Root Port's PCIe Capability structure */
-#define PEX0_RP_PCIE_CFG_OFFSET                (0x00080000 + 0x60)
-
-/* SOC_CONTROL_REG1 fields */
-#define PCIE0_ENABLE_OFFS              0
-#define PCIE0_ENABLE_MASK              (0x1 << PCIE0_ENABLE_OFFS)
-#define PCIE1_ENABLE_OFFS              1
-#define PCIE1_ENABLE_MASK              (0x1 << PCIE1_ENABLE_OFFS)
-#define PCIE2_ENABLE_OFFS              2
-#define PCIE2_ENABLE_MASK              (0x1 << PCIE2_ENABLE_OFFS)
-#define PCIE3_ENABLE_OFFS              3
-#define PCIE4_ENABLE_MASK              (0x1 << PCIE3_ENABLE_OFFS)
-
-int hws_pex_config(const struct serdes_map *serdes_map, u8 count);
-
-#endif
index 9ba60b57aac8f432ff650465d8cbf4fafdb760a5..2e467b546d5f81b9255c9cb51a8beccb90853dbc 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "high_speed_env_spec.h"
 #include "sys_env_lib.h"
-#include "ctrl_pex.h"
 
 /*
  * serdes_seq_db - holds all serdes sequences, their size and the
@@ -1555,9 +1554,6 @@ int hws_power_up_serdes_lanes(struct serdes_map *serdes_map, u8 count)
                   After finish the Power_up sequence for all lanes,
                   the lanes should be released from reset state.       */
                CHECK_STATUS(hws_pex_tx_config_seq(serdes_map, count));
-
-               /* PEX configuration */
-               CHECK_STATUS(hws_pex_config(serdes_map, count));
        }
 
        /* USB2 configuration */
@@ -1743,21 +1739,6 @@ int serdes_power_up_ctrl(u32 serdes_num, int serdes_power_up,
                                else
                                        reg_data &= ~0x4000;
                                reg_write(SOC_CONTROL_REG1, reg_data);
-
-                               /*
-                                * Set Maximum Link Width to X1 or X4 in Root
-                                * Port's PCIe Link Capability register.
-                                * This register is read-only but if is not set
-                                * correctly then access to PCI config space of
-                                * endpoint card behind this Root Port does not
-                                * work.
-                                */
-                               reg_data = reg_read(PEX0_RP_PCIE_CFG_OFFSET +
-                                                   PCI_EXP_LNKCAP);
-                               reg_data &= ~PCI_EXP_LNKCAP_MLW;
-                               reg_data |= (is_pex_by1 ? 1 : 4) << 4;
-                               reg_write(PEX0_RP_PCIE_CFG_OFFSET +
-                                         PCI_EXP_LNKCAP, reg_data);
                        }
 
                        CHECK_STATUS(mv_seq_exec(serdes_num, PEX_POWER_UP_SEQ));
index 42f8cb6be0dcdd1a8f11f98c6e6d1f3bc1fa890c..630d6e6cc5ee8d608b40a18fbe3818908bb59037 100644 (file)
@@ -265,6 +265,7 @@ config PCI_MVEBU
        bool "Enable Armada XP/38x PCIe driver"
        depends on ARCH_MVEBU
        select MISC
+       select DM_RESET
        help
          Say Y here if you want to enable PCIe controller support on
          Armada XP/38x SoCs.
index 55cde2dd83e51502606fb3ba97d9b89910fffce2..b3ea034a2847b32e7bb35646805ec5dda9c6cd51 100644 (file)
@@ -18,6 +18,7 @@
 #include <dm/lists.h>
 #include <dm/of_access.h>
 #include <pci.h>
+#include <reset.h>
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/soc.h>
@@ -74,6 +75,7 @@ struct mvebu_pcie {
        u32 intregs;
        u32 port;
        u32 lane;
+       bool is_x4;
        int devfn;
        u32 lane_mask;
        int first_busno;
@@ -379,7 +381,30 @@ static void mvebu_pcie_setup_wins(struct mvebu_pcie *pcie)
 /* Only enable PCIe link, do not setup it */
 static int mvebu_pcie_enable_link(struct mvebu_pcie *pcie, ofnode node)
 {
-       /* PCIe link is currently automatically enabled in SerDes code */
+       struct reset_ctl rst;
+       int ret;
+
+       ret = reset_get_by_index_nodev(node, 0, &rst);
+       if (ret == -ENOENT) {
+               return 0;
+       } else if (ret < 0) {
+               printf("%s: cannot get reset controller: %d\n", pcie->name, ret);
+               return ret;
+       }
+
+       ret = reset_request(&rst);
+       if (ret) {
+               printf("%s: cannot request reset controller: %d\n", pcie->name, ret);
+               return ret;
+       }
+
+       ret = reset_deassert(&rst);
+       reset_free(&rst);
+       if (ret) {
+               printf("%s: cannot enable PCIe port: %d\n", pcie->name, ret);
+               return ret;
+       }
+
        return 0;
 }
 
@@ -392,6 +417,18 @@ static void mvebu_pcie_setup_link(struct mvebu_pcie *pcie)
        reg = readl(pcie->base + PCIE_CTRL_OFF);
        reg |= PCIE_CTRL_RC_MODE;
        writel(reg, pcie->base + PCIE_CTRL_OFF);
+
+       /*
+        * Set Maximum Link Width to X1 or X4 in Root Port's PCIe Link
+        * Capability register. This register is defined by PCIe specification
+        * as read-only but this mvebu controller has it as read-write and must
+        * be set to number of SerDes PCIe lanes (1 or 4). If this register is
+        * not set correctly then link with endpoint card is not established.
+        */
+       reg = readl(pcie->base + PCIE_CAPAB_OFF + PCI_EXP_LNKCAP);
+       reg &= ~PCI_EXP_LNKCAP_MLW;
+       reg |= (pcie->is_x4 ? 4 : 1) << 4;
+       writel(reg, pcie->base + PCIE_CAPAB_OFF + PCI_EXP_LNKCAP);
 }
 
 static int mvebu_pcie_probe(struct udevice *dev)
@@ -582,6 +619,7 @@ static int mvebu_pcie_port_parse_dt(ofnode node, ofnode parent, struct mvebu_pci
 {
        struct fdt_pci_addr pci_addr;
        const u32 *addr;
+       u32 num_lanes;
        int ret = 0;
        int len;
 
@@ -597,6 +635,9 @@ static int mvebu_pcie_port_parse_dt(ofnode node, ofnode parent, struct mvebu_pci
 
        sprintf(pcie->name, "pcie%d.%d", pcie->port, pcie->lane);
 
+       if (!ofnode_read_u32(node, "num-lanes", &num_lanes) && num_lanes == 4)
+               pcie->is_x4 = true;
+
        /* devfn is in bits [15:8], see PCI_DEV usage */
        ret = ofnode_read_pci_addr(node, FDT_PCI_SPACE_CONFIG, "reg", &pci_addr);
        if (ret < 0) {